npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rewrite-shrinkwrap-urls

v1.1.0

Published

Rewrite URLs in npm-shrinkwrap.json or package-lock.json

Downloads

21

Readme

rewrite-shrinkwrap-urls

Rewrite URLs in npm-shrinkwrap.json or package-lock.json

Build Status Coverage Status Greenkeeper badge

Sometimes it's necessary to update the "resolved" URLs in an npm-shrinkwrap.json file or a package-lock.json file - for instance, when you want to point all packages to a private npm registry like npm Enterprise.

This package provides a tool to do just that. It comes with a convenient CLI, but it can be easily used as a module in some other grander logic as well.

Install and Usage

CLI

Install as global (binary) module:

$ npm install -g rewrite-shrinkwrap-urls

View help content:

$ rewrite-shrinkwrap-urls --help
Usage: rewrite-shrinkwrap-urls [npm-shrinkwrap.json] -r <registry> [options]

Arguments:
  [npm-shrinkwrap.json]  The input shrinkwrap file containing urls to
                         rewrite. You can omit this if --stdin is used.
                         [file] [default: npm-shrinkwrap.json]

Required:
  -r, --registry <registry>  Base URL of the registry to point URLs at
                             [required] [string]

Options:
  -f, --file <output>  Path of file to write modified shrinkwrap to,
                       defaults to input file
                       [file]

  -i, --stdin          Read shrinkwrap file contents from stdin
                       [boolean]

  -o, --stdout         Write modified shrinkwrap content to stdout instead
                       of file
                       [boolean]

  -p, --public         Use public registry style URLs. Omit this flag when
                       rewriting to npm Enterprise.
                       [boolean]

  -s, --spaces <num>   Number of spaces per JSON indent of output
                       [number] [default: 2]

  -m, --from           Sync the "from" field with the "resolved" field
                       (both will be the rewritten URL)
                       [boolean]

  -h, --help           Show help
                       [commands: help] [boolean]

  -v, --version        Show version number
                       [commands: version] [boolean]

Rewrite all URLs in the current directory's npm-shrinkwrap.json, pointing to the private registry at https://private-registry:

$ rewrite-shrinkwrap-urls -r https://private-registry

The equivalent command for a package-lock.json file would be:

$ rewrite-shrinkwrap-urls package-lock.json -r https://private-registry

Read npm-shrinkwrap-OLD.json and write the modified content to npm-shrinkwrap-NEW.json:

$ rewrite-shrinkwrap-urls npm-shrinkwrap-OLD.json -r https://private-registry -f npm-shrinkwrap-NEW.json

Read shrinkwrap file from stdin and output the modified content to stdout:

$ rewrite-shrinkwrap-urls -r localhost:8080 -i < npm-shrinkwrap.json
$ cat npm-shrinkwrap.json | rewrite-shrinkwrap-urls -r localhost:8080 -

Module

Install to local node_modules directory and add dependency to package.json:

$ npm install --save rewrite-shrinkwrap-urls

Use the module to synchronously modify an object in-place:

// require the module
var rewriteShrinkwrapUrls = require('rewrite-shrinkwrap-urls')

// read shrinkwrap object into memory
var shrinkwrap = JSON.parse(require('fs').readFileSync('npm-shrinkwrap.json', { encoding: 'utf8' }))

// modify the shrinkwrap object synchronously
rewriteShrinkwrapUrls(shrinkwrap, { newBaseUrl: 'https://private-registry' })

// do something with shrinkwrap
console.log(shrinkwrap)

API

rewriteShrinkwrapUrls(shrinkwrap, opts)

Arguments

  • shrinkwrap: object

    Content from a shrinkwrap or package-lock file, as an object in memory.

  • opts: object

    Options object.

Options

  • newBaseUrl: string

    Base URL of new registry to point package URLs at. Default is 'http://localhost:8080'.

  • public: boolean

    Whether to use public registry style URLs or not. A public registry tarball URL looks like https://registry.npmjs.org/through/-/through-2.3.8.tgz while a private registry tarball URL looks like http://localhost:8080/t/through/_attachments/through-2.3.8.tgz. Default is false (use private registry URL style).

  • transformer: function

    A function that will be called for each modified URL, allowing any custom check or modification to be done. The default function simply returns the newUrl.

    Arguments:

    • newUrl: string
    • oldUrl: string
    • packageName: string
    • version: string

    Returns the desired URL as a string

  • syncFrom: boolean

    Whether to sync the "from" field with the "resolved" field for each dependency in the shrinkwrap content. Syncing them means that both fields will updated/rewritten to the new URL.

License

ISC © Contributors