• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1fetch-package-metadata
2----------------------
3
4    const fetchPackageMetadata = require("npm/lib/fetch-package-metadata")
5    fetchPackageMetadata(spec, contextdir, callback)
6
7This will get package metadata (and if possible, ONLY package metadata) for
8a specifier as passed to `npm install` et al, eg `npm@next` or `npm@^2.0.3`
9
10## fetchPackageMetadata(*spec*, *contextdir*, *tracker*, *callback*)
11
12* *spec* **string** | **object** -- The package specifier, can be anything npm can
13  understand (see [realize-package-specifier]), or it can be the result from
14  realize-package-specifier or npm-package-arg (for non-local deps).
15
16* *contextdir* **string** -- The directory from which relative paths to
17  local packages should be resolved.
18
19* *tracker* **object** -- **(optional)** An are-we-there-yet tracker group as
20  provided by `npm.log.newGroup()`.
21
22* *callback* **function (er, package)** -- Called when the package information
23  has been loaded. `package` is the object for of the `package.json`
24  matching the requested spec.  In the case of named packages, it comes from
25  the registry and thus may not exactly match what's found in the associated
26  tarball.
27
28[realize-package-specifier]: (https://github.com/npm/realize-package-specifier)
29
30In the case of tarballs and git repos, it will use the cache to download
31them in order to get the package metadata.  For named packages, only the
32metadata is downloaded (eg https://registry.npmjs.org/package).  For local
33directories, the package.json is read directly.  For local tarballs, the
34tarball is streamed in memory and just the package.json is extracted from
35it.  (Due to the nature of tars, having the package.json early in the file
36will result in it being loaded faster– the extractor short-circuits the
37uncompress/untar streams as best as it can.)
38