libnpmpublish
Programmatic API for the bits behind npm publish and unpublish
Last updated a year ago by gar .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ npm install libnpmpublish 
SYNC missed versions from official npm registry.

libnpmpublish

npm version license CI - libnpmpublish

libnpmpublish is a Node.js library for programmatically publishing and unpublishing npm packages. Give it a manifest as an object and a tarball as a Buffer, and it'll put them on the registry for you.

Table of Contents

Example

const { publish, unpublish } = require('libnpmpublish')

Install

$ npm install libnpmpublish

API

opts for libnpmpublish commands

libnpmpublish uses npm-registry-fetch. Most options are passed through directly to that library, so please refer to its own opts documentation for options that can be passed in.

A couple of options of note:

  • opts.defaultTag - registers the published package with the given tag, defaults to latest.

  • opts.access - tells the registry whether this package should be published as public or restricted. Only applies to scoped packages. Defaults to public.

  • opts.token - can be passed in and will be used as the authentication token for the registry. For other ways to pass in auth details, see the n-r-f docs.

  • opts.provenance - when running in a supported CI environment, will trigger the generation of a signed provenance statement to be published alongside the package. Mutually exclusive with the provenanceFile option.

  • opts.provenanceFile - specifies the path to an externally-generated provenance statement to be published alongside the package. Mutually exclusive with the provenance option. The specified file should be a Sigstore Bundle containing a DSSE-packaged provenance statement.

> libpub.publish(manifest, tarData, [opts]) -> Promise

Sends the package represented by the manifest and tarData to the configured registry.

manifest should be the parsed package.json for the package being published (which can also be the manifest pulled from a packument, a git repo, tarball, etc.)

tarData is a Buffer of the tarball being published.

If opts.npmVersion is passed in, it will be used as the _npmVersion field in the outgoing packument. You may put your own user-agent string in there to identify your publishes.

If opts.algorithms is passed in, it should be an array of hashing algorithms to generate integrity hashes for. The default is ['sha512'], which means you end up with dist.integrity = 'sha512-deadbeefbadc0ffee'. Any algorithm supported by your current node version is allowed -- npm clients that do not support those algorithms will simply ignore the unsupported hashes.

Example
// note that pacote.manifest() and pacote.tarball() can also take
// any spec that npm can install.  a folder shown here, since that's
// far and away the most common use case.
const path = '/a/path/to/your/source/code'
const pacote = require('pacote') // see: http://npm.im/pacote
const manifest = await pacote.manifest(path)
const tarData = await pacote.tarball(path)
await libpub.publish(manifest, tarData, {
  npmVersion: 'my-pub-script@1.0.2',
  token: 'my-auth-token-here'
}, opts)
// Package has been published to the npm registry.

> libpub.unpublish(spec, [opts]) -> Promise

Unpublishes spec from the appropriate registry. The registry in question may have its own limitations on unpublishing.

spec should be either a string, or a valid npm-package-arg parsed spec object. For legacy compatibility reasons, only tag and version specs will work as expected. range specs will fail silently in most cases.

Example
await libpub.unpublish('lodash', { token: 'i-am-the-worst'})
//
// `lodash` has now been unpublished, along with all its versions

Current Tags

  • 7.5.2                                ...           backport (10 months ago)
  • 9.0.9                                ...           latest (7 months ago)
  • 9.0.0-pre.0                                ...           prerelease (a year ago)

57 Versions

  • 9.0.9                                ...           7 months ago
  • 9.0.8                                ...           7 months ago
  • 9.0.7                                ...           8 months ago
  • 9.0.6                                ...           8 months ago
  • 9.0.5                                ...           9 months ago
  • 7.5.2                                ...           10 months ago
  • 9.0.4                                ...           a year ago
  • 9.0.3                                ...           a year ago
  • 9.0.2                                ...           a year ago
  • 7.5.1                                ...           a year ago
  • 9.0.1                                ...           a year ago
  • 9.0.0                                ...           a year ago
  • 9.0.0-pre.0                                ...           a year ago
  • 8.0.0                                ...           a year ago
  • 7.5.0                                ...           a year ago
  • 7.4.0                                ...           2 years ago
  • 7.3.0                                ...           2 years ago
  • 7.2.0                                ...           2 years ago
  • 7.1.4                                ...           2 years ago
  • 7.1.3                                ...           2 years ago
  • 7.1.2                                ...           2 years ago
  • 7.1.1                                ...           2 years ago
  • 7.1.0                                ...           2 years ago
  • 7.0.8                                ...           2 years ago
  • 7.0.6                                ...           2 years ago
  • 7.0.5                                ...           2 years ago
  • 7.0.4                                ...           2 years ago
  • 7.0.3                                ...           2 years ago
  • 7.0.2                                ...           2 years ago
  • 7.0.1                                ...           2 years ago
  • 7.0.0                                ...           2 years ago
  • 7.0.0-pre.4                                ...           2 years ago
  • 7.0.0-pre.3                                ...           2 years ago
  • 7.0.0-pre.2                                ...           2 years ago
  • 7.0.0-pre.1                                ...           2 years ago
  • 7.0.0-pre.0                                ...           2 years ago
  • 6.0.5                                ...           2 years ago
  • 6.0.4                                ...           3 years ago
  • 6.0.3                                ...           3 years ago
  • 6.0.2                                ...           3 years ago
  • 6.0.1                                ...           3 years ago
  • 6.0.0                                ...           3 years ago
  • 5.0.1                                ...           3 years ago
  • 5.0.0                                ...           3 years ago
  • 4.0.2                                ...           4 years ago
  • 4.0.1                                ...           4 years ago
  • 4.0.0                                ...           4 years ago
  • 3.0.2                                ...           4 years ago
  • 3.0.1                                ...           5 years ago
  • 3.0.0                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.1.3                                ...           5 years ago
  • 1.1.2                                ...           5 years ago
  • 1.1.1                                ...           6 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (8)
Dev Dependencies (7)

© 2010 - cnpmjs.org x YWFE | Home | YWFE