mirror of
https://github.com/zhigang1992/npm.git
synced 2026-01-12 22:49:19 +08:00
npm-package-arg@2.0.1
This commit is contained in:
14
node_modules/npm-package-arg/npa.js
generated
vendored
14
node_modules/npm-package-arg/npa.js
generated
vendored
@@ -6,6 +6,9 @@ var path = require("path")
|
||||
|
||||
module.exports = npa
|
||||
|
||||
var isWindows = process.platform === "win32" || global.FAKE_WINDOWS
|
||||
var slashRe = isWindows ? /\\|\// : /\//
|
||||
|
||||
var parseName = /^(?:@([^\/]+?)\/)?([^\/]+?)$/
|
||||
var nameAt = /^(@([^\/]+?)\/)?([^\/]+?)@/
|
||||
var debug = util.debuglog ? util.debuglog("npa")
|
||||
@@ -58,6 +61,15 @@ function npa (arg) {
|
||||
|
||||
var urlparse = url.parse(arg)
|
||||
debug("urlparse", urlparse)
|
||||
|
||||
// windows paths look like urls
|
||||
// don't be fooled!
|
||||
if (isWindows && urlparse && urlparse.protocol &&
|
||||
urlparse.protocol.match(/^[a-zA-Z]:$/)) {
|
||||
debug("windows url-ish local path", urlparse)
|
||||
urlparse = {}
|
||||
}
|
||||
|
||||
if (urlparse.protocol) {
|
||||
return parseUrl(res, arg, urlparse)
|
||||
}
|
||||
@@ -87,7 +99,7 @@ function npa (arg) {
|
||||
} else if (range) {
|
||||
res.spec = range
|
||||
res.type = "range"
|
||||
} else if (/\//.test(arg)) {
|
||||
} else if (slashRe.test(arg)) {
|
||||
parseLocal(res, arg)
|
||||
} else {
|
||||
res.type = "tag"
|
||||
|
||||
32
node_modules/npm-package-arg/package.json
generated
vendored
32
node_modules/npm-package-arg/package.json
generated
vendored
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "npm-package-arg",
|
||||
"version": "2.0.0",
|
||||
"version": "2.0.1",
|
||||
"description": "Parse the things that can be arguments to `npm install`",
|
||||
"main": "npa.js",
|
||||
"directories": {
|
||||
@@ -29,28 +29,10 @@
|
||||
"url": "https://github.com/npm/npm-package-arg/issues"
|
||||
},
|
||||
"homepage": "https://github.com/npm/npm-package-arg",
|
||||
"gitHead": "e8b8d15b13bc254c64702a265668d35bb1cc27e0",
|
||||
"_id": "npm-package-arg@2.0.0",
|
||||
"_shasum": "b573aa01f3405c085564dfec930e8acc199bee08",
|
||||
"_from": "npm-package-arg@>=2.0.0-0 <2.1.0-0",
|
||||
"_npmVersion": "1.4.16",
|
||||
"_npmUser": {
|
||||
"name": "isaacs",
|
||||
"email": "i@izs.me"
|
||||
},
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "isaacs",
|
||||
"email": "i@izs.me"
|
||||
},
|
||||
{
|
||||
"name": "othiym23",
|
||||
"email": "ogd@aoaioxxysz.net"
|
||||
}
|
||||
],
|
||||
"dist": {
|
||||
"shasum": "b573aa01f3405c085564dfec930e8acc199bee08",
|
||||
"tarball": "http://registry.npmjs.org/npm-package-arg/-/npm-package-arg-2.0.0.tgz"
|
||||
},
|
||||
"_resolved": "https://registry.npmjs.org/npm-package-arg/-/npm-package-arg-2.0.0.tgz"
|
||||
"readme": "# npm-package-arg\n\nParse the things that can be arguments to `npm install`\n\nTakes an argument like `foo@1.2`, or `foo@user/foo`, or\n`http://x.com/foo.tgz`, or `git+https://github.com/user/foo`, and\nfigures out what type of thing it is.\n\n## USAGE\n\n```javascript\nvar assert = require(\"assert\")\nvar npa = require(\"npm-package-arg\")\n\n// Pass in the descriptor, and it'll return an object\nvar parsed = npa(\"foo@1.2\")\n\n// Returns an object like:\n// {\n// name: \"foo\", // The bit in front of the @\n// type: \"range\", // the type of descriptor this is\n// spec: \"1.2\" // the specifier for this descriptor\n// }\n\n// Completely unreasonable invalid garbage throws an error\n// Make sure you wrap this in a try/catch if you have not\n// already sanitized the inputs!\nassert.throws(function() {\n npa(\"this is not \\0 a valid package name or url\")\n})\n```\n\nFor more examples, see the test file.\n\n## Result Objects\n\nThe objects that are returned by npm-package-arg contain the following\nfields:\n\n* `name` - If known, the `name` field expected in the resulting pkg.\n* `type` - One of the following strings:\n * `git` - A git repo\n * `github` - A github shorthand, like `user/project`\n * `tag` - A tagged version, like `\"foo@latest\"`\n * `version` - A specific version number, like `\"foo@1.2.3\"`\n * `range` - A version range, like `\"foo@2.x\"`\n * `local` - A local file or folder path\n * `remote` - An http url (presumably to a tgz)\n* `spec` - The \"thing\". URL, the range, git repo, etc.\n* `raw` - The original un-modified string that was provided.\n* `rawSpec` - The part after the `name@...`, as it was originally\n provided.\n* `scope` - If a name is something like `@org/module` then the `scope`\n field will be set to `org`. If it doesn't have a scoped name, then\n scope is `null`.\n",
|
||||
"readmeFilename": "README.md",
|
||||
"gitHead": "543239e7db293cea99ac366050dd96c6cc55879c",
|
||||
"_id": "npm-package-arg@2.0.1",
|
||||
"_shasum": "73340bbb51cdf7656ac0bfa4fd18c16db245ba58",
|
||||
"_from": "npm-package-arg@latest"
|
||||
}
|
||||
|
||||
41
node_modules/npm-package-arg/test/windows.js
generated
vendored
Normal file
41
node_modules/npm-package-arg/test/windows.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
global.FAKE_WINDOWS = true
|
||||
|
||||
var npa = require("../npa.js")
|
||||
var test = require("tap").test
|
||||
var path = require("path")
|
||||
|
||||
var cases = {
|
||||
"C:\\x\\y\\z": {
|
||||
raw: 'C:\\x\\y\\z',
|
||||
scope: null,
|
||||
name: null,
|
||||
rawSpec: 'C:\\x\\y\\z',
|
||||
spec: path.resolve('C:\\x\\y\\z'),
|
||||
type: 'local'
|
||||
},
|
||||
"foo@C:\\x\\y\\z": {
|
||||
raw: 'foo@C:\\x\\y\\z',
|
||||
scope: null,
|
||||
name: 'foo',
|
||||
rawSpec: 'C:\\x\\y\\z',
|
||||
spec: path.resolve('C:\\x\\y\\z'),
|
||||
type: 'local'
|
||||
},
|
||||
"foo@/foo/bar/baz": {
|
||||
raw: 'foo@/foo/bar/baz',
|
||||
scope: null,
|
||||
name: 'foo',
|
||||
rawSpec: '/foo/bar/baz',
|
||||
spec: path.resolve('/foo/bar/baz'),
|
||||
type: 'local'
|
||||
}
|
||||
}
|
||||
|
||||
test("parse a windows path", function (t) {
|
||||
Object.keys(cases).forEach(function (c) {
|
||||
var expect = cases[c]
|
||||
var actual = npa(c)
|
||||
t.same(actual, expect, c)
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
@@ -66,7 +66,7 @@
|
||||
"nopt": "~3.0.1",
|
||||
"npm-cache-filename": "~1.0.1",
|
||||
"npm-install-checks": "~1.0.2",
|
||||
"npm-package-arg": "~2.0.0",
|
||||
"npm-package-arg": "~2.0.1",
|
||||
"npm-registry-client": "~3.0.2",
|
||||
"npm-user-validate": "~0.1.0",
|
||||
"npmconf": "~2.0.3",
|
||||
|
||||
Reference in New Issue
Block a user