1 realize-package-specifier
2 -------------------------
4 Parse a package specifier, peeking at the disk to differentiate between
5 local tarballs, directories and named modules. This implements the logic
6 used by `npm install` and `npm cache` to determine where to get packages
10 var realizePackageSpecifier = require("realize-package-specifier")
11 realizePackageSpecifier("foo.tar.gz", ".", function (err, package) {
18 * realizePackageSpecifier(*spec*, [*where*,] *callback*)
20 Parses *spec* using `npm-package-arg` and then uses stat to check to see if
21 it refers to a local tarball or package directory. Stats are done relative
22 to *where*. If it does then the local module is loaded. If it doesn't then
23 target is left as a remote package specifier. Package directories are
24 recognized by the presence of a package.json in them.
26 *spec* -- a package specifier, like: `foo@1.2`, or `foo@user/foo`, or
27 `http://x.com/foo.tgz`, or `git+https://github.com/user/foo`
29 *where* (optional, default: .) -- The directory in which we should look for
30 local tarballs or package directories.
32 *callback* function(*err*, *result*) -- Called once we've determined what
33 kind of specifier this is. The *result* object will be very like the one
34 returned by `npm-package-arg` except with three differences: 1) There's a
35 new type of `directory`. 2) The `local` type only refers to tarballs. 2)
36 For all `local` and `directory` type results spec will contain the full path of
41 The full definition of the result object is:
43 * `name` - If known, the `name` field expected in the resulting pkg.
44 * `type` - One of the following strings:
46 * `hosted` - A hosted project, from github, bitbucket or gitlab. Originally
47 either a full url pointing at one of these services or a shorthand like
48 `user/project` or `github:user/project` for github or `bitbucket:user/project`
50 * `tag` - A tagged version, like `"foo@latest"`
51 * `version` - A specific version number, like `"foo@1.2.3"`
52 * `range` - A version range, like `"foo@2.x"`
53 * `local` - A local file path
54 * `directory` - A local package directory
55 * `remote` - An http url (presumably to a tgz)
56 * `spec` - The "thing". URL, the range, git repo, etc.
57 * `hosted` - If type=hosted this will be an object with the following keys:
58 * `type` - github, bitbucket or gitlab
59 * `ssh` - The ssh path for this git repo
60 * `sshurl` - The ssh URL for this git repo
61 * `https` - The HTTPS URL for this git repo
62 * `directUrl` - The URL for the package.json in this git repo
63 * `raw` - The original un-modified string that was provided.
64 * `rawSpec` - The part after the `name@...`, as it was originally
66 * `scope` - If a name is something like `@org/module` then the `scope`
67 field will be set to `org`. If it doesn't have a scoped name, then