Package Exports
- libnpmpublish
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (libnpmpublish) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
libnpmpublish
libnpmpublish
is a Node.js library for
programmatically publishing and unpublishing npm packages. It takes care
of packing tarballs from source code and putting it up on a nice 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 for those in a hurry:
opts.defaultTag
- registers the published package with the given tag, defaults tolatest
.opts.access
- tells the registry whether this package should be published as public or restricted. Only applies to scoped packages, which default to restricted.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.
> libpub.publish(path, pkgJson, [opts]) -> Promise
Packs a tarball located in path
and publishes to the appropriate configured registry. pkgJson
should be
the parsed package.json
for the package that is being published.
If opts.npmVersion
is passed in, it will be used as the _npmVersion
field in
the outgoing packument. It's recommended you add your own user agent string in
there!
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
const path = '/a/path/to/your/source/code'
await libpub.publish(path, {
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, and the world
// devolves into utter chaos.
//
// That, or we all go home to our friends and/or family and have a nice time
// doing nothing having to do with programming or JavaScript and realize our
// lives are just so much happier now, and we just can't understand why we ever
// got so into this JavaScript thing but damn did it pay well. I guess you'll
// settle for gardening or something.