Snippet Path

NPM snippets

Authors

Publish all dependencies to a private registry

  1. Set custom registry using .npmrc
  2. Install packages online first and generate package-lock.json or yarn.lock files.
  3. Parse lock files and npm publish $RESOLVED_URL for each package in lock file where $RESOLVED_URL is the resolved url of the package inside the lock file.
powershell
$file = [System.IO.File]::ReadAllText("$(pwd)/yarn.lock")
$matches = ([regex]'resolved "(.*)"').Matches($file)
$matches | % { npm publish $_.Groups[1].Value }

Output list of deps url

powershell
$file = [System.IO.File]::ReadAllText("$(pwd)/yarn.lock")
$matches = ([regex]'resolved "(.*)"').Matches($file)
$paths = $matches | % { $_.Groups[1].Value }
$paths | out-file paths.list

Modify package and gzip+tar it

Sometimes packages have publishConfig inside their package.json file and can't be easily republished. One workaround is to download the tgz file and remove the publishConfig property.

shell
# extract the archive file ($PACKAGE_NAME.tgz) to $PACKAGE_NAME folder
cd $PACKAGE_NAME
tar -cvzf $PACKAGE_NAME.tgz package
npm publish $PACKAGE_NAME.tgz