Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- node/node_modules/npm/node_modules/@npmcli/agent/package.json +60 -0
- node/node_modules/npm/node_modules/@npmcli/arborist/LICENSE.md +20 -0
- node/node_modules/npm/node_modules/@npmcli/arborist/README.md +315 -0
- node/node_modules/npm/node_modules/@npmcli/arborist/package.json +99 -0
- node/node_modules/npm/node_modules/@npmcli/config/LICENSE +15 -0
- node/node_modules/npm/node_modules/@npmcli/config/README.md +226 -0
- node/node_modules/npm/node_modules/@npmcli/config/lib/env-replace.js +16 -0
- node/node_modules/npm/node_modules/@npmcli/config/lib/errors.js +23 -0
- node/node_modules/npm/node_modules/@npmcli/config/lib/index.js +1034 -0
- node/node_modules/npm/node_modules/@npmcli/config/lib/nerf-dart.js +18 -0
- node/node_modules/npm/node_modules/@npmcli/config/lib/parse-field.js +86 -0
- node/node_modules/npm/node_modules/@npmcli/config/lib/set-envs.js +113 -0
- node/node_modules/npm/node_modules/@npmcli/config/package.json +57 -0
- node/node_modules/npm/node_modules/@npmcli/fs/LICENSE.md +20 -0
- node/node_modules/npm/node_modules/@npmcli/fs/lib/common/get-options.js +20 -0
- node/node_modules/npm/node_modules/@npmcli/fs/lib/common/node.js +9 -0
- node/node_modules/npm/node_modules/@npmcli/fs/lib/cp/LICENSE +15 -0
- node/node_modules/npm/node_modules/@npmcli/fs/lib/cp/errors.js +129 -0
- node/node_modules/npm/node_modules/@npmcli/fs/lib/cp/index.js +22 -0
- node/node_modules/npm/node_modules/@npmcli/fs/lib/cp/polyfill.js +428 -0
- node/node_modules/npm/node_modules/@npmcli/fs/lib/index.js +13 -0
- node/node_modules/npm/node_modules/@npmcli/fs/lib/move-file.js +78 -0
- node/node_modules/npm/node_modules/@npmcli/fs/lib/readdir-scoped.js +20 -0
- node/node_modules/npm/node_modules/@npmcli/fs/lib/with-temp-dir.js +39 -0
- node/node_modules/npm/node_modules/@npmcli/fs/package.json +54 -0
- node/node_modules/npm/node_modules/@npmcli/git/LICENSE +15 -0
- node/node_modules/npm/node_modules/@npmcli/git/lib/clone.js +172 -0
- node/node_modules/npm/node_modules/@npmcli/git/lib/errors.js +36 -0
- node/node_modules/npm/node_modules/@npmcli/git/lib/find.js +15 -0
- node/node_modules/npm/node_modules/@npmcli/git/lib/index.js +9 -0
- node/node_modules/npm/node_modules/@npmcli/git/lib/is-clean.js +6 -0
- node/node_modules/npm/node_modules/@npmcli/git/lib/is.js +4 -0
- node/node_modules/npm/node_modules/@npmcli/git/lib/lines-to-revs.js +147 -0
- node/node_modules/npm/node_modules/@npmcli/git/lib/make-error.js +33 -0
- node/node_modules/npm/node_modules/@npmcli/git/lib/opts.js +57 -0
- node/node_modules/npm/node_modules/@npmcli/git/lib/revs.js +22 -0
- node/node_modules/npm/node_modules/@npmcli/git/lib/spawn.js +44 -0
- node/node_modules/npm/node_modules/@npmcli/git/lib/utils.js +3 -0
- node/node_modules/npm/node_modules/@npmcli/git/lib/which.js +18 -0
- node/node_modules/npm/node_modules/@npmcli/git/package.json +58 -0
- node/node_modules/npm/node_modules/@npmcli/installed-package-contents/LICENSE +15 -0
- node/node_modules/npm/node_modules/@npmcli/installed-package-contents/README.md +109 -0
- node/node_modules/npm/node_modules/@npmcli/installed-package-contents/bin/index.js +44 -0
- node/node_modules/npm/node_modules/@npmcli/installed-package-contents/lib/index.js +181 -0
- node/node_modules/npm/node_modules/@npmcli/installed-package-contents/package.json +52 -0
- node/node_modules/npm/node_modules/@npmcli/map-workspaces/LICENSE.md +20 -0
- node/node_modules/npm/node_modules/@npmcli/map-workspaces/lib/index.js +226 -0
- node/node_modules/npm/node_modules/@npmcli/map-workspaces/package.json +61 -0
- node/node_modules/npm/node_modules/@npmcli/metavuln-calculator/LICENSE +15 -0
- node/node_modules/npm/node_modules/@npmcli/metavuln-calculator/lib/advisory.js +435 -0
node/node_modules/npm/node_modules/@npmcli/agent/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@npmcli/agent",
|
| 3 |
+
"version": "4.0.0",
|
| 4 |
+
"description": "the http/https agent used by the npm cli",
|
| 5 |
+
"main": "lib/index.js",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"gencerts": "bash scripts/create-cert.sh",
|
| 8 |
+
"test": "tap",
|
| 9 |
+
"lint": "npm run eslint",
|
| 10 |
+
"postlint": "template-oss-check",
|
| 11 |
+
"template-oss-apply": "template-oss-apply --force",
|
| 12 |
+
"lintfix": "npm run eslint -- --fix",
|
| 13 |
+
"snap": "tap",
|
| 14 |
+
"posttest": "npm run lint",
|
| 15 |
+
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
|
| 16 |
+
},
|
| 17 |
+
"author": "GitHub Inc.",
|
| 18 |
+
"license": "ISC",
|
| 19 |
+
"bugs": {
|
| 20 |
+
"url": "https://github.com/npm/agent/issues"
|
| 21 |
+
},
|
| 22 |
+
"homepage": "https://github.com/npm/agent#readme",
|
| 23 |
+
"files": [
|
| 24 |
+
"bin/",
|
| 25 |
+
"lib/"
|
| 26 |
+
],
|
| 27 |
+
"engines": {
|
| 28 |
+
"node": "^20.17.0 || >=22.9.0"
|
| 29 |
+
},
|
| 30 |
+
"templateOSS": {
|
| 31 |
+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
| 32 |
+
"version": "4.25.0",
|
| 33 |
+
"publish": "true"
|
| 34 |
+
},
|
| 35 |
+
"dependencies": {
|
| 36 |
+
"agent-base": "^7.1.0",
|
| 37 |
+
"http-proxy-agent": "^7.0.0",
|
| 38 |
+
"https-proxy-agent": "^7.0.1",
|
| 39 |
+
"lru-cache": "^11.2.1",
|
| 40 |
+
"socks-proxy-agent": "^8.0.3"
|
| 41 |
+
},
|
| 42 |
+
"devDependencies": {
|
| 43 |
+
"@npmcli/eslint-config": "^5.0.0",
|
| 44 |
+
"@npmcli/template-oss": "4.25.0",
|
| 45 |
+
"minipass-fetch": "^4.0.1",
|
| 46 |
+
"nock": "^14.0.3",
|
| 47 |
+
"socksv5": "^0.0.6",
|
| 48 |
+
"tap": "^16.3.0"
|
| 49 |
+
},
|
| 50 |
+
"repository": {
|
| 51 |
+
"type": "git",
|
| 52 |
+
"url": "git+https://github.com/npm/agent.git"
|
| 53 |
+
},
|
| 54 |
+
"tap": {
|
| 55 |
+
"nyc-arg": [
|
| 56 |
+
"--exclude",
|
| 57 |
+
"tap-snapshots/**"
|
| 58 |
+
]
|
| 59 |
+
}
|
| 60 |
+
}
|
node/node_modules/npm/node_modules/@npmcli/arborist/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!-- This file is automatically added by @npmcli/template-oss. Do not edit. -->
|
| 2 |
+
|
| 3 |
+
ISC License
|
| 4 |
+
|
| 5 |
+
Copyright npm, Inc.
|
| 6 |
+
|
| 7 |
+
Permission to use, copy, modify, and/or distribute this
|
| 8 |
+
software for any purpose with or without fee is hereby
|
| 9 |
+
granted, provided that the above copyright notice and this
|
| 10 |
+
permission notice appear in all copies.
|
| 11 |
+
|
| 12 |
+
THE SOFTWARE IS PROVIDED "AS IS" AND NPM DISCLAIMS ALL
|
| 13 |
+
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
| 14 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
|
| 15 |
+
EVENT SHALL NPM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
| 16 |
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 17 |
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
| 18 |
+
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
| 19 |
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
|
| 20 |
+
USE OR PERFORMANCE OF THIS SOFTWARE.
|
node/node_modules/npm/node_modules/@npmcli/arborist/README.md
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# @npmcli/arborist
|
| 2 |
+
|
| 3 |
+
[](https://npm.im/@npmcli/arborist)
|
| 4 |
+
[](https://npm.im/@npmcli/arborist)
|
| 5 |
+
[](https://github.com/npm/cli/actions/workflows/ci-npmcli-arborist.yml)
|
| 6 |
+
|
| 7 |
+
Inspect and manage `node_modules` trees.
|
| 8 |
+
|
| 9 |
+

|
| 10 |
+
|
| 11 |
+
There's more documentation [in the docs
|
| 12 |
+
folder](https://github.com/npm/cli/tree/latest/workspaces/arborist/docs).
|
| 13 |
+
|
| 14 |
+
## USAGE
|
| 15 |
+
|
| 16 |
+
```js
|
| 17 |
+
const Arborist = require('@npmcli/arborist')
|
| 18 |
+
|
| 19 |
+
const arb = new Arborist({
|
| 20 |
+
// options object
|
| 21 |
+
|
| 22 |
+
// where we're doing stuff. defaults to cwd.
|
| 23 |
+
path: '/path/to/package/root',
|
| 24 |
+
|
| 25 |
+
// url to the default registry. defaults to npm's default registry
|
| 26 |
+
registry: 'https://registry.npmjs.org',
|
| 27 |
+
|
| 28 |
+
// scopes can be mapped to a different registry
|
| 29 |
+
'@foo:registry': 'https://registry.foo.com/',
|
| 30 |
+
|
| 31 |
+
// Auth can be provided in a couple of different ways. If none are
|
| 32 |
+
// provided, then requests are anonymous, and private packages will 404.
|
| 33 |
+
// Arborist doesn't do anything with these, it just passes them down
|
| 34 |
+
// the chain to pacote and npm-registry-fetch.
|
| 35 |
+
|
| 36 |
+
// Safest: a bearer token provided by a registry:
|
| 37 |
+
// 1. an npm auth token, used with the default registry
|
| 38 |
+
token: 'deadbeefcafebad',
|
| 39 |
+
// 2. an alias for the same thing:
|
| 40 |
+
_authToken: 'deadbeefcafebad',
|
| 41 |
+
|
| 42 |
+
// insecure options:
|
| 43 |
+
// 3. basic auth, username:password, base64 encoded
|
| 44 |
+
auth: 'aXNhYWNzOm5vdCBteSByZWFsIHBhc3N3b3Jk',
|
| 45 |
+
// 4. username and base64 encoded password
|
| 46 |
+
username: 'isaacs',
|
| 47 |
+
password: 'bm90IG15IHJlYWwgcGFzc3dvcmQ=',
|
| 48 |
+
|
| 49 |
+
// auth configs can also be scoped to a given registry with this
|
| 50 |
+
// rather unusual pattern:
|
| 51 |
+
'//registry.foo.com:token': 'blahblahblah',
|
| 52 |
+
'//basic.auth.only.foo.com:_auth': 'aXNhYWNzOm5vdCBteSByZWFsIHBhc3N3b3Jk',
|
| 53 |
+
'//registry.foo.com:always-auth': true,
|
| 54 |
+
})
|
| 55 |
+
|
| 56 |
+
// READING
|
| 57 |
+
|
| 58 |
+
// returns a promise. reads the actual contents of node_modules
|
| 59 |
+
arb.loadActual().then(tree => {
|
| 60 |
+
// tree is also stored at arb.virtualTree
|
| 61 |
+
})
|
| 62 |
+
|
| 63 |
+
// read just what the package-lock.json/npm-shrinkwrap says
|
| 64 |
+
// This *also* loads the yarn.lock file, but that's only relevant
|
| 65 |
+
// when building the ideal tree.
|
| 66 |
+
arb.loadVirtual().then(tree => {
|
| 67 |
+
// tree is also stored at arb.virtualTree
|
| 68 |
+
// now arb.virtualTree is loaded
|
| 69 |
+
// this fails if there's no package-lock.json or package.json in the folder
|
| 70 |
+
// note that loading this way should only be done if there's no
|
| 71 |
+
// node_modules folder
|
| 72 |
+
})
|
| 73 |
+
|
| 74 |
+
// OPTIMIZING AND DESIGNING
|
| 75 |
+
|
| 76 |
+
// build an ideal tree from the package.json and various lockfiles.
|
| 77 |
+
arb.buildIdealTree(options).then(() => {
|
| 78 |
+
// next step is to reify that ideal tree onto disk.
|
| 79 |
+
// options can be:
|
| 80 |
+
// rm: array of package names to remove at top level
|
| 81 |
+
// add: Array of package specifiers to add at the top level. Each of
|
| 82 |
+
// these will be resolved with pacote.manifest if the name can't be
|
| 83 |
+
// determined from the spec. (Eg, `github:foo/bar` vs `foo@somespec`.)
|
| 84 |
+
// The dep will be saved in the location where it already exists,
|
| 85 |
+
// (or pkg.dependencies) unless a different saveType is specified.
|
| 86 |
+
// saveType: Save added packages in a specific dependency set.
|
| 87 |
+
// - null (default) Wherever they exist already, or 'dependencies'
|
| 88 |
+
// - prod: definitely in 'dependencies'
|
| 89 |
+
// - optional: in 'optionalDependencies'
|
| 90 |
+
// - dev: devDependencies
|
| 91 |
+
// - peer: save in peerDependencies, and remove any optional flag from
|
| 92 |
+
// peerDependenciesMeta if one exists
|
| 93 |
+
// - peerOptional: save in peerDependencies, and add a
|
| 94 |
+
// peerDepsMeta[name].optional flag
|
| 95 |
+
// saveBundle: add newly added deps to the bundleDependencies list
|
| 96 |
+
// update: Either `true` to just go ahead and update everything, or an
|
| 97 |
+
// object with any or all of the following fields:
|
| 98 |
+
// - all: boolean. set to true to just update everything
|
| 99 |
+
// - names: names of packages update (like `npm update foo`)
|
| 100 |
+
// prune: boolean, default true. Prune extraneous nodes from the tree.
|
| 101 |
+
// preferDedupe: prefer to deduplicate packages if possible, rather than
|
| 102 |
+
// choosing a newer version of a dependency. Defaults to false, ie,
|
| 103 |
+
// always try to get the latest and greatest deps.
|
| 104 |
+
// legacyBundling: Nest every dep under the node requiring it, npm v2 style.
|
| 105 |
+
// No unnecessary deduplication. Default false.
|
| 106 |
+
|
| 107 |
+
// At the end of this process, arb.idealTree is set.
|
| 108 |
+
})
|
| 109 |
+
|
| 110 |
+
// WRITING
|
| 111 |
+
|
| 112 |
+
// Make the idealTree be the thing that's on disk
|
| 113 |
+
arb.reify({
|
| 114 |
+
// write the lockfile(s) back to disk, and package.json with any updates
|
| 115 |
+
// defaults to 'true'
|
| 116 |
+
save: true,
|
| 117 |
+
}).then(() => {
|
| 118 |
+
// node modules has been written to match the idealTree
|
| 119 |
+
})
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
## DATA STRUCTURES
|
| 123 |
+
|
| 124 |
+
A `node_modules` tree is a logical graph of dependencies overlaid on a
|
| 125 |
+
physical tree of folders.
|
| 126 |
+
|
| 127 |
+
A `Node` represents a package folder on disk, either at the root of the
|
| 128 |
+
package, or within a `node_modules` folder. The physical structure of the
|
| 129 |
+
folder tree is represented by the `node.parent` reference to the containing
|
| 130 |
+
folder, and `node.children` map of nodes within its `node_modules`
|
| 131 |
+
folder, where the key in the map is the name of the folder in
|
| 132 |
+
`node_modules`, and the value is the child node.
|
| 133 |
+
|
| 134 |
+
A node without a parent is a top of tree.
|
| 135 |
+
|
| 136 |
+
A `Link` represents a symbolic link to a package on disk. This can be a
|
| 137 |
+
symbolic link to a package folder within the current tree, or elsewhere on
|
| 138 |
+
disk. The `link.target` is a reference to the actual node. Links differ
|
| 139 |
+
from Nodes in that dependencies are resolved from the _target_ location,
|
| 140 |
+
rather than from the link location.
|
| 141 |
+
|
| 142 |
+
An `Edge` represents a dependency relationship. Each node has an `edgesIn`
|
| 143 |
+
set, and an `edgesOut` map. Each edge has a `type` which specifies what
|
| 144 |
+
kind of dependency it represents: `'prod'` for regular dependencies,
|
| 145 |
+
`'peer'` for peerDependencies, `'dev'` for devDependencies, and
|
| 146 |
+
`'optional'` for optionalDependencies. `edge.from` is a reference to the
|
| 147 |
+
node that has the dependency, and `edge.to` is a reference to the node that
|
| 148 |
+
requires the dependency.
|
| 149 |
+
|
| 150 |
+
As nodes are moved around in the tree, the graph edges are automatically
|
| 151 |
+
updated to point at the new module resolution targets. In other words,
|
| 152 |
+
`edge.from`, `edge.name`, and `edge.spec` are immutable; `edge.to` is
|
| 153 |
+
updated automatically when a node's parent changes.
|
| 154 |
+
|
| 155 |
+
### class Node
|
| 156 |
+
|
| 157 |
+
All arborist trees are `Node` objects. A `Node` refers
|
| 158 |
+
to a package folder, which may have children in `node_modules`.
|
| 159 |
+
|
| 160 |
+
* `node.name` The name of this node's folder in `node_modules`.
|
| 161 |
+
* `node.parent` Physical parent node in the tree. The package in whose
|
| 162 |
+
`node_modules` folder this package lives. Null if node is top of tree.
|
| 163 |
+
|
| 164 |
+
Setting `node.parent` will automatically update `node.location` and all
|
| 165 |
+
graph edges affected by the move.
|
| 166 |
+
|
| 167 |
+
* `node.meta` A `Shrinkwrap` object which looks up `resolved` and
|
| 168 |
+
`integrity` values for all modules in this tree. Only relevant on `root`
|
| 169 |
+
nodes.
|
| 170 |
+
|
| 171 |
+
* `node.children` Map of packages located in the node's `node_modules`
|
| 172 |
+
folder.
|
| 173 |
+
* `node.package` The contents of this node's `package.json` file.
|
| 174 |
+
* `node.path` File path to this package. If the node is a link, then this
|
| 175 |
+
is the path to the link, not to the link target. If the node is _not_ a
|
| 176 |
+
link, then this matches `node.realpath`.
|
| 177 |
+
* `node.realpath` The full real filepath on disk where this node lives.
|
| 178 |
+
* `node.location` A slash-normalized relative path from the root node to
|
| 179 |
+
this node's path.
|
| 180 |
+
* `node.isLink` Whether this represents a symlink. Always `false` for Node
|
| 181 |
+
objects, always `true` for Link objects.
|
| 182 |
+
* `node.isRoot` True if this node is a root node. (Ie, if `node.root ===
|
| 183 |
+
node`.)
|
| 184 |
+
* `node.root` The root node where we are working. If not assigned to some
|
| 185 |
+
other value, resolves to the node itself. (Ie, the root node's `root`
|
| 186 |
+
property refers to itself.)
|
| 187 |
+
* `node.isTop` True if this node is the top of its tree (ie, has no
|
| 188 |
+
`parent`, false otherwise).
|
| 189 |
+
* `node.top` The top node in this node's tree. This will be equal to
|
| 190 |
+
`node.root` for simple trees, but link targets will frequently be outside
|
| 191 |
+
of (or nested somewhere within) a `node_modules` hierarchy, and so will
|
| 192 |
+
have a different `top`.
|
| 193 |
+
* `node.dev`, `node.optional`, `node.devOptional`, `node.peer`, Indicators
|
| 194 |
+
as to whether this node is a dev, optional, and/or peer dependency.
|
| 195 |
+
These flags are relevant when pruning dependencies out of the tree or
|
| 196 |
+
deciding what to reify. See **Package Dependency Flags** below for
|
| 197 |
+
explanations.
|
| 198 |
+
* `node.edgesOut` Edges in the dependency graph indicating nodes that this
|
| 199 |
+
node depends on, which resolve its dependencies.
|
| 200 |
+
* `node.edgesIn` Edges in the dependency graph indicating nodes that depend
|
| 201 |
+
on this node.
|
| 202 |
+
|
| 203 |
+
* `extraneous` True if this package is not required by any other for any
|
| 204 |
+
reason. False for top of tree.
|
| 205 |
+
|
| 206 |
+
* `node.resolve(name)` Identify the node that will be returned when code
|
| 207 |
+
in this package runs `require(name)`
|
| 208 |
+
|
| 209 |
+
* `node.errors` Array of errors encountered while parsing package.json or
|
| 210 |
+
version specifiers.
|
| 211 |
+
|
| 212 |
+
### class Link
|
| 213 |
+
|
| 214 |
+
Link objects represent a symbolic link within the `node_modules` folder.
|
| 215 |
+
They have most of the same properties and methods as `Node` objects, with a
|
| 216 |
+
few differences.
|
| 217 |
+
|
| 218 |
+
* `link.target` A Node object representing the package that the link
|
| 219 |
+
references. If this is a Node already present within the tree, then it
|
| 220 |
+
will be the same object. If it's outside of the tree, then it will be
|
| 221 |
+
treated as the top of its own tree.
|
| 222 |
+
* `link.isLink` Always true.
|
| 223 |
+
* `link.children` This is always an empty map, since links don't have their
|
| 224 |
+
own children directly.
|
| 225 |
+
|
| 226 |
+
### class Edge
|
| 227 |
+
|
| 228 |
+
Edge objects represent a dependency relationship a package node to the
|
| 229 |
+
point in the tree where the dependency will be loaded. As nodes are moved
|
| 230 |
+
within the tree, Edges automatically update to point to the appropriate
|
| 231 |
+
location.
|
| 232 |
+
|
| 233 |
+
* `new Edge({ from, type, name, spec })` Creates a new edge with the
|
| 234 |
+
specified fields. After instantiation, none of the fields can be
|
| 235 |
+
changed directly.
|
| 236 |
+
* `edge.from` The node that has the dependency.
|
| 237 |
+
* `edge.type` The type of dependency. One of `'prod'`, `'dev'`, `'peer'`,
|
| 238 |
+
or `'optional'`.
|
| 239 |
+
* `edge.name` The name of the dependency. Ie, the key in the
|
| 240 |
+
relevant `package.json` dependencies object.
|
| 241 |
+
* `edge.spec` The specifier that is required. This can be a version,
|
| 242 |
+
range, tag name, git url, or tarball URL. Any specifier allowed by npm
|
| 243 |
+
is supported.
|
| 244 |
+
* `edge.to` Automatically set to the node in the tree that matches the
|
| 245 |
+
`name` field.
|
| 246 |
+
* `edge.valid` True if `edge.to` satisfies the specifier.
|
| 247 |
+
* `edge.error` A string indicating the type of error if there is a problem,
|
| 248 |
+
or `null` if it's valid. Values, in order of precedence:
|
| 249 |
+
* `DETACHED` Indicates that the edge has been detached from its
|
| 250 |
+
`edge.from` node, typically because a new edge was created when a
|
| 251 |
+
dependency specifier was modified.
|
| 252 |
+
* `MISSING` Indicates that the dependency is unmet. Note that this is
|
| 253 |
+
_not_ set for unmet dependencies of the `optional` type.
|
| 254 |
+
* `PEER LOCAL` Indicates that a `peerDependency` is found in the
|
| 255 |
+
node's local `node_modules` folder, and the node is not the top of
|
| 256 |
+
the tree. This violates the `peerDependency` contract, because it
|
| 257 |
+
means that the dependency is not a peer.
|
| 258 |
+
* `INVALID` Indicates that the dependency does not satisfy `edge.spec`.
|
| 259 |
+
* `edge.reload()` Re-resolve to find the appropriate value for `edge.to`.
|
| 260 |
+
Called automatically from the `Node` class when the tree is mutated.
|
| 261 |
+
|
| 262 |
+
### Package Dependency Flags
|
| 263 |
+
|
| 264 |
+
The dependency type of a node can be determined efficiently by looking at
|
| 265 |
+
the `dev`, `optional`, and `devOptional` flags on the node object. These
|
| 266 |
+
are updated by arborist when necessary whenever the tree is modified in
|
| 267 |
+
such a way that the dependency graph can change, and are relevant when
|
| 268 |
+
pruning nodes from the tree.
|
| 269 |
+
|
| 270 |
+
| extraneous | peer | dev | optional | devOptional | meaning | prune? |
|
| 271 |
+
|:----------:|:----:|:---:|:--------:|:----------------:|:-------------------------------------------------------------------------------------------------|:-------------------------------------------------------|
|
| 272 |
+
| | | | | | production dep | never |
|
| 273 |
+
| X | N/A | N/A | N/A | N/A | nothing depends on this, it is trash | always |
|
| 274 |
+
| | | X | | X<br>not in lock | devDependency, or only depended<br>on by devDependencies | if pruning dev |
|
| 275 |
+
| | | | X | X<br>not in lock | optionalDependency, or only depended<br>on by optionalDeps | if pruning optional |
|
| 276 |
+
| | | X | X | X<br>not in lock | Optional dependency of dep(s) in the<br>dev hierarchy | if pruning EITHER<br>dev OR optional |
|
| 277 |
+
| | | | | X<br>in lock | BOTH a non-optional dep within the<br>dev hierarchy, AND a dep within<br>the optional hierarchy | if pruning BOTH<br>dev AND optional |
|
| 278 |
+
| | X | | | | peer dependency, or only depended<br>on by peer dependencies | if pruning peers |
|
| 279 |
+
| | X | X | | X<br>not in lock | peer dependency of dev node hierarchy | if pruning peer OR<br>dev deps |
|
| 280 |
+
| | X | | X | X<br>not in lock | peer dependency of optional nodes, or<br>peerOptional dep | if pruning peer OR<br>optional deps |
|
| 281 |
+
| | X | X | X | X<br>not in lock | peer optional deps of the dev dep hierarchy | if pruning peer OR<br>optional OR dev |
|
| 282 |
+
| | X | | | X<br>in lock | BOTH a non-optional peer dep within the<br>dev hierarchy, AND a peer optional dep | if pruning peer deps OR:<br>BOTH optional AND dev deps |
|
| 283 |
+
|
| 284 |
+
* If none of these flags are set, then the node is required by the
|
| 285 |
+
dependency and/or peerDependency hierarchy. It should not be pruned.
|
| 286 |
+
* If _both_ `node.dev` and `node.optional` are set, then the node is an
|
| 287 |
+
optional dependency of one of the packages in the devDependency
|
| 288 |
+
hierarchy. It should be pruned if _either_ dev or optional deps are
|
| 289 |
+
being removed.
|
| 290 |
+
* If `node.dev` is set, but `node.optional` is not, then the node is
|
| 291 |
+
required in the devDependency hierarchy. It should be pruned if dev
|
| 292 |
+
dependencies are being removed.
|
| 293 |
+
* If `node.optional` is set, but `node.dev` is not, then the node is
|
| 294 |
+
required in the optionalDependency hierarchy. It should be pruned if
|
| 295 |
+
optional dependencies are being removed.
|
| 296 |
+
* If `node.devOptional` is set, then the node is a (non-optional)
|
| 297 |
+
dependency within the devDependency hierarchy, _and_ a dependency
|
| 298 |
+
within the `optionalDependency` hierarchy. It should be pruned if
|
| 299 |
+
_both_ dev and optional dependencies are being removed.
|
| 300 |
+
* If `node.peer` is set, then all the same semantics apply as above, except
|
| 301 |
+
that the dep is brought in by a peer dep at some point, rather than a
|
| 302 |
+
normal non-peer dependency.
|
| 303 |
+
|
| 304 |
+
Note: `devOptional` is only set in the shrinkwrap/package-lock file if
|
| 305 |
+
_neither_ `dev` nor `optional` are set, as it would be redundant.
|
| 306 |
+
|
| 307 |
+
## BIN
|
| 308 |
+
|
| 309 |
+
Arborist ships with a cli that can be used to run arborist specific commands outside of the context of the npm CLI. This script is currently not part of the public API and is subject to breaking changes outside of major version bumps.
|
| 310 |
+
|
| 311 |
+
To see the usage run:
|
| 312 |
+
|
| 313 |
+
```
|
| 314 |
+
npx @npmcli/arborist --help
|
| 315 |
+
```
|
node/node_modules/npm/node_modules/@npmcli/arborist/package.json
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@npmcli/arborist",
|
| 3 |
+
"version": "9.4.3",
|
| 4 |
+
"description": "Manage node_modules trees",
|
| 5 |
+
"dependencies": {
|
| 6 |
+
"@gar/promise-retry": "^1.0.0",
|
| 7 |
+
"@isaacs/string-locale-compare": "^1.1.0",
|
| 8 |
+
"@npmcli/fs": "^5.0.0",
|
| 9 |
+
"@npmcli/installed-package-contents": "^4.0.0",
|
| 10 |
+
"@npmcli/map-workspaces": "^5.0.0",
|
| 11 |
+
"@npmcli/metavuln-calculator": "^9.0.2",
|
| 12 |
+
"@npmcli/name-from-folder": "^4.0.0",
|
| 13 |
+
"@npmcli/node-gyp": "^5.0.0",
|
| 14 |
+
"@npmcli/package-json": "^7.0.0",
|
| 15 |
+
"@npmcli/query": "^5.0.0",
|
| 16 |
+
"@npmcli/redact": "^4.0.0",
|
| 17 |
+
"@npmcli/run-script": "^10.0.0",
|
| 18 |
+
"bin-links": "^6.0.0",
|
| 19 |
+
"cacache": "^20.0.1",
|
| 20 |
+
"common-ancestor-path": "^2.0.0",
|
| 21 |
+
"hosted-git-info": "^9.0.0",
|
| 22 |
+
"json-stringify-nice": "^1.1.4",
|
| 23 |
+
"lru-cache": "^11.2.1",
|
| 24 |
+
"minimatch": "^10.0.3",
|
| 25 |
+
"nopt": "^9.0.0",
|
| 26 |
+
"npm-install-checks": "^8.0.0",
|
| 27 |
+
"npm-package-arg": "^13.0.0",
|
| 28 |
+
"npm-pick-manifest": "^11.0.1",
|
| 29 |
+
"npm-registry-fetch": "^19.0.0",
|
| 30 |
+
"pacote": "^21.0.2",
|
| 31 |
+
"parse-conflict-json": "^5.0.1",
|
| 32 |
+
"proc-log": "^6.0.0",
|
| 33 |
+
"proggy": "^4.0.0",
|
| 34 |
+
"promise-all-reject-late": "^1.0.0",
|
| 35 |
+
"promise-call-limit": "^3.0.1",
|
| 36 |
+
"semver": "^7.3.7",
|
| 37 |
+
"ssri": "^13.0.0",
|
| 38 |
+
"treeverse": "^3.0.0",
|
| 39 |
+
"walk-up-path": "^4.0.0"
|
| 40 |
+
},
|
| 41 |
+
"devDependencies": {
|
| 42 |
+
"@npmcli/eslint-config": "^5.0.1",
|
| 43 |
+
"@npmcli/mock-registry": "^1.0.0",
|
| 44 |
+
"@npmcli/template-oss": "4.29.0",
|
| 45 |
+
"benchmark": "^2.1.4",
|
| 46 |
+
"minify-registry-metadata": "^4.0.0",
|
| 47 |
+
"nock": "^13.3.3",
|
| 48 |
+
"tap": "^16.3.8",
|
| 49 |
+
"tar-stream": "^3.0.0",
|
| 50 |
+
"tcompare": "^5.0.6"
|
| 51 |
+
},
|
| 52 |
+
"scripts": {
|
| 53 |
+
"test": "tap",
|
| 54 |
+
"posttest": "npm run lint",
|
| 55 |
+
"snap": "tap",
|
| 56 |
+
"test-proxy": "ARBORIST_TEST_PROXY=1 tap --snapshot",
|
| 57 |
+
"lint": "npm run eslint",
|
| 58 |
+
"lintfix": "npm run eslint -- --fix",
|
| 59 |
+
"benchmark": "node scripts/benchmark.js",
|
| 60 |
+
"benchclean": "rm -rf scripts/benchmark/*/",
|
| 61 |
+
"postlint": "template-oss-check",
|
| 62 |
+
"template-oss-apply": "template-oss-apply --force",
|
| 63 |
+
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
|
| 64 |
+
},
|
| 65 |
+
"repository": {
|
| 66 |
+
"type": "git",
|
| 67 |
+
"url": "git+https://github.com/npm/cli.git",
|
| 68 |
+
"directory": "workspaces/arborist"
|
| 69 |
+
},
|
| 70 |
+
"author": "GitHub Inc.",
|
| 71 |
+
"license": "ISC",
|
| 72 |
+
"files": [
|
| 73 |
+
"bin/",
|
| 74 |
+
"lib/"
|
| 75 |
+
],
|
| 76 |
+
"main": "lib/index.js",
|
| 77 |
+
"bin": {
|
| 78 |
+
"arborist": "bin/index.js"
|
| 79 |
+
},
|
| 80 |
+
"tap": {
|
| 81 |
+
"after": "test/fixtures/cleanup.js",
|
| 82 |
+
"test-env": [
|
| 83 |
+
"LC_ALL=sk"
|
| 84 |
+
],
|
| 85 |
+
"timeout": "720",
|
| 86 |
+
"nyc-arg": [
|
| 87 |
+
"--exclude",
|
| 88 |
+
"tap-snapshots/**"
|
| 89 |
+
]
|
| 90 |
+
},
|
| 91 |
+
"engines": {
|
| 92 |
+
"node": "^20.17.0 || >=22.9.0"
|
| 93 |
+
},
|
| 94 |
+
"templateOSS": {
|
| 95 |
+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
| 96 |
+
"version": "4.29.0",
|
| 97 |
+
"content": "../../scripts/template-oss/index.js"
|
| 98 |
+
}
|
| 99 |
+
}
|
node/node_modules/npm/node_modules/@npmcli/config/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The ISC License
|
| 2 |
+
|
| 3 |
+
Copyright (c) npm, Inc.
|
| 4 |
+
|
| 5 |
+
Permission to use, copy, modify, and/or distribute this software for any
|
| 6 |
+
purpose with or without fee is hereby granted, provided that the above
|
| 7 |
+
copyright notice and this permission notice appear in all copies.
|
| 8 |
+
|
| 9 |
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
| 10 |
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
| 11 |
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
| 12 |
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 13 |
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 14 |
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
| 15 |
+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
node/node_modules/npm/node_modules/@npmcli/config/README.md
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# `@npmcli/config`
|
| 2 |
+
|
| 3 |
+
Configuration management for the npm cli.
|
| 4 |
+
|
| 5 |
+
This module is the spiritual descendant of [`npmconf`](http://npm.im/npmconf), and the code that once lived in npm's
|
| 6 |
+
`lib/config/` folder.
|
| 7 |
+
|
| 8 |
+
It does the management of configuration files that npm uses, but importantly, does _not_ define all the configuration defaults or types, as those parts make more sense to live within the npm CLI itself.
|
| 9 |
+
|
| 10 |
+
The only exceptions:
|
| 11 |
+
|
| 12 |
+
- The `prefix` config value has some special semantics, setting the local prefix if specified on the CLI options and not in global mode, or the global prefix otherwise.
|
| 13 |
+
- The `project` config file is loaded based on the local prefix (which can only be set by the CLI config options, and otherwise defaults to a walk up the folder tree to the first parent containing a `node_modules` folder, `package.json` file, or `package-lock.json` file.)
|
| 14 |
+
- The `userconfig` value, as set by the environment and CLI (defaulting to
|
| 15 |
+
`~/.npmrc`, is used to load user configs.
|
| 16 |
+
- The `globalconfig` value, as set by the environment, CLI, and
|
| 17 |
+
`userconfig` file (defaulting to `$PREFIX/etc/npmrc`) is used to load global configs.
|
| 18 |
+
- A `builtin` config, read from a `npmrc` file in the root of the npm project itself, overrides all defaults.
|
| 19 |
+
|
| 20 |
+
The resulting hierarchy of configs:
|
| 21 |
+
|
| 22 |
+
- CLI switches.
|
| 23 |
+
eg `--some-key=some-value` on the command line.
|
| 24 |
+
These are parsed by [`nopt`](http://npm.im/nopt), which is not a great choice, but it's the one that npm has used forever, and changing it will be difficult.
|
| 25 |
+
- Environment variables.
|
| 26 |
+
eg `npm_config_some_key=some_value` in the environment.
|
| 27 |
+
There is no way at this time to modify this prefix.
|
| 28 |
+
- INI-formatted project configs.
|
| 29 |
+
eg `some-key = some-value` in the
|
| 30 |
+
`localPrefix` folder (ie, the `cwd`, or its nearest parent that contains either a `node_modules` folder or `package.json` file.)
|
| 31 |
+
- INI-formatted userconfig file.
|
| 32 |
+
eg `some-key = some-value` in `~/.npmrc`.
|
| 33 |
+
The `userconfig` config value can be overridden by the `cli`, `env`, or
|
| 34 |
+
`project` configs to change this value.
|
| 35 |
+
- INI-formatted globalconfig file.
|
| 36 |
+
eg `some-key = some-value` in the `globalPrefix` folder, which is inferred by looking at the location of the node executable, or the `prefix` setting in the `cli`, `env`, `project`, or `userconfig`.
|
| 37 |
+
The `globalconfig` value at any of those levels can override this.
|
| 38 |
+
- INI-formatted builtin config file.
|
| 39 |
+
eg `some-key = some-value` in `/usr/local/lib/node_modules/npm/npmrc`.
|
| 40 |
+
This is not configurable, and is determined by looking in the `npmPath` folder.
|
| 41 |
+
- Default values (passed in by npm when it loads this module).
|
| 42 |
+
|
| 43 |
+
## USAGE
|
| 44 |
+
|
| 45 |
+
```js
|
| 46 |
+
const Config = require('@npmcli/config')
|
| 47 |
+
const { shorthands, definitions, flatten } = require('@npmcli/config/lib/definitions')
|
| 48 |
+
|
| 49 |
+
const conf = new Config({
|
| 50 |
+
// path to the npm module being run
|
| 51 |
+
npmPath: resolve(__dirname, '..'),
|
| 52 |
+
definitions,
|
| 53 |
+
shorthands,
|
| 54 |
+
flatten,
|
| 55 |
+
// optional, defaults to process.argv
|
| 56 |
+
// argv: [] <- if you are using this package in your own cli
|
| 57 |
+
// and don't want to have colliding argv
|
| 58 |
+
argv: process.argv,
|
| 59 |
+
// optional, defaults to process.env
|
| 60 |
+
env: process.env,
|
| 61 |
+
// optional, defaults to process.execPath
|
| 62 |
+
execPath: process.execPath,
|
| 63 |
+
// optional, defaults to process.platform
|
| 64 |
+
platform: process.platform,
|
| 65 |
+
// optional, defaults to process.cwd()
|
| 66 |
+
cwd: process.cwd(),
|
| 67 |
+
})
|
| 68 |
+
|
| 69 |
+
// emits log events on the process object
|
| 70 |
+
// see `proc-log` for more info
|
| 71 |
+
process.on('log', (level, ...args) => {
|
| 72 |
+
console.log(level, ...args)
|
| 73 |
+
})
|
| 74 |
+
|
| 75 |
+
// returns a promise that fails if config loading fails, and
|
| 76 |
+
// resolves when the config object is ready for action
|
| 77 |
+
conf.load().then(() => {
|
| 78 |
+
conf.validate()
|
| 79 |
+
console.log('loaded ok! some-key = ' + conf.get('some-key'))
|
| 80 |
+
}).catch(er => {
|
| 81 |
+
console.error('error loading configs!', er)
|
| 82 |
+
})
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
## API
|
| 86 |
+
|
| 87 |
+
The `Config` class is the sole export.
|
| 88 |
+
|
| 89 |
+
```js
|
| 90 |
+
const Config = require('@npmcli/config')
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
### static `Config.typeDefs`
|
| 94 |
+
|
| 95 |
+
The type definitions passed to `nopt` for CLI option parsing and known configuration validation.
|
| 96 |
+
|
| 97 |
+
### constructor `new Config(options)`
|
| 98 |
+
|
| 99 |
+
Options:
|
| 100 |
+
|
| 101 |
+
- `types` Types of all known config values.
|
| 102 |
+
Note that some are effectively given semantic value in the config loading process itself.
|
| 103 |
+
- `shorthands` An object mapping a shorthand value to an array of CLI arguments that replace it.
|
| 104 |
+
- `defaults` Default values for each of the known configuration keys.
|
| 105 |
+
These should be defined for all configs given a type, and must be valid.
|
| 106 |
+
- `npmPath` The path to the `npm` module, for loading the `builtin` config file.
|
| 107 |
+
- `cwd` Optional, defaults to `process.cwd()`, used for inferring the
|
| 108 |
+
`localPrefix` and loading the `project` config.
|
| 109 |
+
- `platform` Optional, defaults to `process.platform`.
|
| 110 |
+
Used when inferring the `globalPrefix` from the `execPath`, since this is done differently on Windows.
|
| 111 |
+
- `execPath` Optional, defaults to `process.execPath`.
|
| 112 |
+
Used to infer the
|
| 113 |
+
`globalPrefix`.
|
| 114 |
+
- `env` Optional, defaults to `process.env`.
|
| 115 |
+
Source of the environment variables for configuration.
|
| 116 |
+
- `argv` Optional, defaults to `process.argv`.
|
| 117 |
+
Source of the CLI options used for configuration.
|
| 118 |
+
|
| 119 |
+
Returns a `config` object, which is not yet loaded.
|
| 120 |
+
|
| 121 |
+
Fields:
|
| 122 |
+
|
| 123 |
+
- `config.globalPrefix` The prefix for `global` operations.
|
| 124 |
+
Set by the
|
| 125 |
+
`prefix` config value, or defaults based on the location of the
|
| 126 |
+
`execPath` option.
|
| 127 |
+
- `config.localPrefix` The prefix for `local` operations.
|
| 128 |
+
Set by the
|
| 129 |
+
`prefix` config value on the CLI only, or defaults to either the `cwd` or its nearest ancestor containing a `node_modules` folder or `package.json` file.
|
| 130 |
+
- `config.sources` A read-only `Map` of the file (or a comment, if no file found, or relevant) to the config level loaded from that source.
|
| 131 |
+
- `config.data` A `Map` of config level to `ConfigData` objects.
|
| 132 |
+
These objects should not be modified directly under any circumstances.
|
| 133 |
+
- `source` The source where this data was loaded from.
|
| 134 |
+
- `raw` The raw data used to generate this config data, as it was parsed initially from the environment, config file, or CLI options.
|
| 135 |
+
- `data` The data object reflecting the inheritance of configs up to this point in the chain.
|
| 136 |
+
- `loadError` Any errors encountered that prevented the loading of this config data.
|
| 137 |
+
- `config.list` A list sorted in priority of all the config data objects in the prototype chain.
|
| 138 |
+
`config.list[0]` is the `cli` level,
|
| 139 |
+
`config.list[1]` is the `env` level, and so on.
|
| 140 |
+
- `cwd` The `cwd` param
|
| 141 |
+
- `env` The `env` param
|
| 142 |
+
- `argv` The `argv` param
|
| 143 |
+
- `execPath` The `execPath` param
|
| 144 |
+
- `platform` The `platform` param
|
| 145 |
+
- `defaults` The `defaults` param
|
| 146 |
+
- `shorthands` The `shorthands` param
|
| 147 |
+
- `types` The `types` param
|
| 148 |
+
- `npmPath` The `npmPath` param
|
| 149 |
+
- `globalPrefix` The effective `globalPrefix`
|
| 150 |
+
- `localPrefix` The effective `localPrefix`
|
| 151 |
+
- `prefix` If `config.get('global')` is true, then `globalPrefix`, otherwise `localPrefix`
|
| 152 |
+
- `home` The user's home directory, found by looking at `env.HOME` or calling `os.homedir()`.
|
| 153 |
+
- `loaded` A boolean indicating whether or not configs are loaded
|
| 154 |
+
- `valid` A getter that returns `true` if all the config objects are valid.
|
| 155 |
+
Any data objects that have been modified with `config.set(...)` will be re-evaluated when `config.valid` is read.
|
| 156 |
+
|
| 157 |
+
### `config.load()`
|
| 158 |
+
|
| 159 |
+
Load configuration from the various sources of information.
|
| 160 |
+
|
| 161 |
+
Returns a `Promise` that resolves when configuration is loaded, and fails if a fatal error is encountered.
|
| 162 |
+
|
| 163 |
+
### `config.find(key)`
|
| 164 |
+
|
| 165 |
+
Find the effective place in the configuration levels a given key is set.
|
| 166 |
+
Returns one of: `cli`, `env`, `project`, `user`, `global`, `builtin`, or
|
| 167 |
+
`default`.
|
| 168 |
+
|
| 169 |
+
Returns `null` if the key is not set.
|
| 170 |
+
|
| 171 |
+
### `config.get(key, where = 'cli')`
|
| 172 |
+
|
| 173 |
+
Load the given key from the config stack.
|
| 174 |
+
|
| 175 |
+
### `config.set(key, value, where = 'cli')`
|
| 176 |
+
|
| 177 |
+
Set the key to the specified value, at the specified level in the config stack.
|
| 178 |
+
|
| 179 |
+
### `config.delete(key, where = 'cli')`
|
| 180 |
+
|
| 181 |
+
Delete the configuration key from the specified level in the config stack.
|
| 182 |
+
|
| 183 |
+
### `config.validate(where)`
|
| 184 |
+
|
| 185 |
+
Verify that all known configuration options are set to valid values, and log a warning if they are invalid.
|
| 186 |
+
|
| 187 |
+
Invalid auth options will cause this method to throw an error with a `code` property of `ERR_INVALID_AUTH`, and a `problems` property listing the specific concerns with the current configuration.
|
| 188 |
+
|
| 189 |
+
If `where` is not set, then all config objects are validated.
|
| 190 |
+
|
| 191 |
+
Returns `true` if all configs are valid.
|
| 192 |
+
|
| 193 |
+
Note that it's usually enough (and more efficient) to just check
|
| 194 |
+
`config.valid`, since each data object is marked for re-evaluation on every
|
| 195 |
+
`config.set()` operation.
|
| 196 |
+
|
| 197 |
+
### `config.repair(problems)`
|
| 198 |
+
|
| 199 |
+
Accept an optional array of problems (as thrown by `config.validate()`) and perform the necessary steps to resolve them.
|
| 200 |
+
If no problems are provided, this method will call `config.validate()` internally to retrieve them.
|
| 201 |
+
|
| 202 |
+
Note that you must `await config.save('user')` in order to persist the changes.
|
| 203 |
+
|
| 204 |
+
### `config.isDefault(key)`
|
| 205 |
+
|
| 206 |
+
Returns `true` if the value is coming directly from the default definitions, if the current value for the key config is coming from any other source, returns `false`.
|
| 207 |
+
|
| 208 |
+
This method can be used for avoiding or tweaking default values, e.g:
|
| 209 |
+
|
| 210 |
+
> Given a global default definition of foo='foo' it's possible to read that value such as:
|
| 211 |
+
>
|
| 212 |
+
> ```js
|
| 213 |
+
> const save = config.get('foo')
|
| 214 |
+
> ```
|
| 215 |
+
>
|
| 216 |
+
> Now in a different place of your app it's possible to avoid using the `foo` default value, by checking to see if the current config value is currently one that was defined by the default definitions:
|
| 217 |
+
>
|
| 218 |
+
> ```js
|
| 219 |
+
> const save = config.isDefault('foo') ? 'bar' : config.get('foo')
|
| 220 |
+
> ```
|
| 221 |
+
|
| 222 |
+
### `config.save(where)`
|
| 223 |
+
|
| 224 |
+
Save the config file specified by the `where` param.
|
| 225 |
+
Must be one of
|
| 226 |
+
`project`, `user`, `global`, `builtin`.
|
node/node_modules/npm/node_modules/@npmcli/config/lib/env-replace.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// replace any ${ENV} values with the appropriate environ.
|
| 2 |
+
// optional "?" modifier can be used like this: ${ENV?} so in case of the variable being not defined, it evaluates into empty string.
|
| 3 |
+
|
| 4 |
+
const envExpr = /(?<!\\)(\\*)\$\{([^${}?]+)(\?)?\}/g
|
| 5 |
+
|
| 6 |
+
module.exports = (f, env) => f.replace(envExpr, (orig, esc, name, modifier) => {
|
| 7 |
+
const fallback = modifier === '?' ? '' : `$\{${name}}`
|
| 8 |
+
const val = env[name] !== undefined ? env[name] : fallback
|
| 9 |
+
|
| 10 |
+
// consume the escape chars that are relevant.
|
| 11 |
+
if (esc.length % 2) {
|
| 12 |
+
return orig.slice((esc.length + 1) / 2)
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
return (esc.slice(esc.length / 2)) + val
|
| 16 |
+
})
|
node/node_modules/npm/node_modules/@npmcli/config/lib/errors.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
class ErrInvalidAuth extends Error {
|
| 4 |
+
constructor (problems) {
|
| 5 |
+
let message = 'Invalid auth configuration found: '
|
| 6 |
+
message += problems.map((problem) => {
|
| 7 |
+
// istanbul ignore else
|
| 8 |
+
if (problem.action === 'delete') {
|
| 9 |
+
return `\`${problem.key}\` is not allowed in ${problem.where} config`
|
| 10 |
+
} else if (problem.action === 'rename') {
|
| 11 |
+
return `\`${problem.from}\` must be renamed to \`${problem.to}\` in ${problem.where} config`
|
| 12 |
+
}
|
| 13 |
+
}).join(', ')
|
| 14 |
+
message += '\nPlease run `npm config fix` to repair your configuration.`'
|
| 15 |
+
super(message)
|
| 16 |
+
this.code = 'ERR_INVALID_AUTH'
|
| 17 |
+
this.problems = problems
|
| 18 |
+
}
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
module.exports = {
|
| 22 |
+
ErrInvalidAuth,
|
| 23 |
+
}
|
node/node_modules/npm/node_modules/@npmcli/config/lib/index.js
ADDED
|
@@ -0,0 +1,1034 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// TODO: set the scope config from package.json or explicit cli config
|
| 2 |
+
const { walkUp } = require('walk-up-path')
|
| 3 |
+
const ini = require('ini')
|
| 4 |
+
const nopt = require('nopt')
|
| 5 |
+
const { log, time } = require('proc-log')
|
| 6 |
+
|
| 7 |
+
const { resolve, dirname, join } = require('node:path')
|
| 8 |
+
const { homedir } = require('node:os')
|
| 9 |
+
const {
|
| 10 |
+
readFile,
|
| 11 |
+
writeFile,
|
| 12 |
+
chmod,
|
| 13 |
+
unlink,
|
| 14 |
+
stat,
|
| 15 |
+
mkdir,
|
| 16 |
+
} = require('node:fs/promises')
|
| 17 |
+
|
| 18 |
+
// TODO global-prefix and local-prefix are set by lib/set-envs.js. This may not be the best way to persist those, if we even want to persist them (see set-envs.js)
|
| 19 |
+
const internalEnv = [
|
| 20 |
+
'npm-version',
|
| 21 |
+
'global-prefix',
|
| 22 |
+
'local-prefix',
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
const fileExists = (...p) => stat(resolve(...p))
|
| 26 |
+
.then((st) => st.isFile())
|
| 27 |
+
.catch(() => false)
|
| 28 |
+
|
| 29 |
+
const dirExists = (...p) => stat(resolve(...p))
|
| 30 |
+
.then((st) => st.isDirectory())
|
| 31 |
+
.catch(() => false)
|
| 32 |
+
|
| 33 |
+
const hasOwnProperty = (obj, key) =>
|
| 34 |
+
Object.prototype.hasOwnProperty.call(obj, key)
|
| 35 |
+
|
| 36 |
+
const typeDefs = require('./type-defs.js')
|
| 37 |
+
const nerfDart = require('./nerf-dart.js')
|
| 38 |
+
const envReplace = require('./env-replace.js')
|
| 39 |
+
const parseField = require('./parse-field.js')
|
| 40 |
+
const setEnvs = require('./set-envs.js')
|
| 41 |
+
|
| 42 |
+
// types that can be saved back to
|
| 43 |
+
const confFileTypes = new Set([
|
| 44 |
+
'global',
|
| 45 |
+
'user',
|
| 46 |
+
'project',
|
| 47 |
+
])
|
| 48 |
+
|
| 49 |
+
const confTypes = new Set([
|
| 50 |
+
'default',
|
| 51 |
+
'builtin',
|
| 52 |
+
...confFileTypes,
|
| 53 |
+
'env',
|
| 54 |
+
'cli',
|
| 55 |
+
])
|
| 56 |
+
|
| 57 |
+
class Config {
|
| 58 |
+
#loaded = false
|
| 59 |
+
#flatten
|
| 60 |
+
// populated the first time we flatten the object
|
| 61 |
+
#flatOptions = null
|
| 62 |
+
#warnings = []
|
| 63 |
+
|
| 64 |
+
static get typeDefs () {
|
| 65 |
+
return typeDefs
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
constructor ({
|
| 69 |
+
definitions,
|
| 70 |
+
shorthands,
|
| 71 |
+
flatten,
|
| 72 |
+
nerfDarts = [],
|
| 73 |
+
npmPath,
|
| 74 |
+
|
| 75 |
+
// options just to override in tests, mostly
|
| 76 |
+
env = process.env,
|
| 77 |
+
argv = process.argv,
|
| 78 |
+
platform = process.platform,
|
| 79 |
+
execPath = process.execPath,
|
| 80 |
+
cwd = process.cwd(),
|
| 81 |
+
excludeNpmCwd = false,
|
| 82 |
+
warn = true,
|
| 83 |
+
}) {
|
| 84 |
+
this.nerfDarts = nerfDarts
|
| 85 |
+
this.definitions = definitions
|
| 86 |
+
// turn the definitions into nopt's weirdo syntax
|
| 87 |
+
const { types, defaults, deprecated } = getTypesFromDefinitions(definitions)
|
| 88 |
+
this.deprecated = deprecated
|
| 89 |
+
|
| 90 |
+
this.#flatten = flatten
|
| 91 |
+
this.types = types
|
| 92 |
+
this.shorthands = shorthands
|
| 93 |
+
this.defaults = defaults
|
| 94 |
+
|
| 95 |
+
this.npmPath = npmPath
|
| 96 |
+
this.npmBin = join(this.npmPath, 'bin/npm-cli.js')
|
| 97 |
+
this.argv = argv
|
| 98 |
+
this.env = env
|
| 99 |
+
this.execPath = execPath
|
| 100 |
+
this.platform = platform
|
| 101 |
+
this.cwd = cwd
|
| 102 |
+
this.excludeNpmCwd = excludeNpmCwd
|
| 103 |
+
|
| 104 |
+
// set when we load configs
|
| 105 |
+
this.globalPrefix = null
|
| 106 |
+
this.localPrefix = null
|
| 107 |
+
this.localPackage = null
|
| 108 |
+
|
| 109 |
+
// defaults to env.HOME, but will always be *something*
|
| 110 |
+
this.home = null
|
| 111 |
+
|
| 112 |
+
// set up the prototype chain of config objects
|
| 113 |
+
const wheres = [...confTypes]
|
| 114 |
+
this.data = new Map()
|
| 115 |
+
let parent = null
|
| 116 |
+
for (const where of wheres) {
|
| 117 |
+
this.data.set(where, parent = new ConfigData(parent))
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
this.data.set = () => {
|
| 121 |
+
throw new Error('cannot change internal config data structure')
|
| 122 |
+
}
|
| 123 |
+
this.data.delete = () => {
|
| 124 |
+
throw new Error('cannot change internal config data structure')
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
this.sources = new Map([])
|
| 128 |
+
|
| 129 |
+
for (const { data } of this.data.values()) {
|
| 130 |
+
this.list.unshift(data)
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
this.#loaded = false
|
| 134 |
+
this.warn = warn
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
get list () {
|
| 138 |
+
const list = []
|
| 139 |
+
for (const { data } of this.data.values()) {
|
| 140 |
+
list.unshift(data)
|
| 141 |
+
}
|
| 142 |
+
return list
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
get loaded () {
|
| 146 |
+
return this.#loaded
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
get prefix () {
|
| 150 |
+
return this.#get('global') ? this.globalPrefix : this.localPrefix
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
// return the location where key is found.
|
| 154 |
+
find (key) {
|
| 155 |
+
if (!this.loaded) {
|
| 156 |
+
throw new Error('call config.load() before reading values')
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
// have to look in reverse order
|
| 160 |
+
const entries = [...this.data.entries()]
|
| 161 |
+
for (let i = entries.length - 1; i > -1; i--) {
|
| 162 |
+
const [where, { data }] = entries[i]
|
| 163 |
+
if (hasOwnProperty(data, key)) {
|
| 164 |
+
return where
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
return null
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
get (key, where) {
|
| 171 |
+
if (!this.loaded) {
|
| 172 |
+
throw new Error('call config.load() before reading values')
|
| 173 |
+
}
|
| 174 |
+
return this.#get(key, where)
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
// we need to get values sometimes, so use this internal one to do so
|
| 178 |
+
// while in the process of loading.
|
| 179 |
+
#get (key, where = null) {
|
| 180 |
+
if (where !== null && !confTypes.has(where)) {
|
| 181 |
+
throw new Error('invalid config location param: ' + where)
|
| 182 |
+
}
|
| 183 |
+
const { data } = this.data.get(where || 'cli')
|
| 184 |
+
return where === null || hasOwnProperty(data, key) ? data[key] : undefined
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
set (key, val, where = 'cli') {
|
| 188 |
+
if (!this.loaded) {
|
| 189 |
+
throw new Error('call config.load() before setting values')
|
| 190 |
+
}
|
| 191 |
+
if (!confTypes.has(where)) {
|
| 192 |
+
throw new Error('invalid config location param: ' + where)
|
| 193 |
+
}
|
| 194 |
+
this.#checkDeprecated(key)
|
| 195 |
+
const { data, raw } = this.data.get(where)
|
| 196 |
+
data[key] = val
|
| 197 |
+
if (['global', 'user', 'project'].includes(where)) {
|
| 198 |
+
raw[key] = val
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
// this is now dirty, the next call to this.valid will have to check it
|
| 202 |
+
this.data.get(where)[_valid] = null
|
| 203 |
+
|
| 204 |
+
// the flat options are invalidated, regenerate next time they're needed
|
| 205 |
+
this.#flatOptions = null
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
get flat () {
|
| 209 |
+
if (this.#flatOptions) {
|
| 210 |
+
return this.#flatOptions
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
// create the object for flat options passed to deps
|
| 214 |
+
const timeEnd = time.start('config:load:flatten')
|
| 215 |
+
this.#flatOptions = {}
|
| 216 |
+
// walk from least priority to highest
|
| 217 |
+
for (const { data } of this.data.values()) {
|
| 218 |
+
this.#flatten(data, this.#flatOptions)
|
| 219 |
+
}
|
| 220 |
+
this.#flatOptions.nodeBin = this.execPath
|
| 221 |
+
this.#flatOptions.npmBin = this.npmBin
|
| 222 |
+
timeEnd()
|
| 223 |
+
|
| 224 |
+
return this.#flatOptions
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
delete (key, where = 'cli') {
|
| 228 |
+
if (!this.loaded) {
|
| 229 |
+
throw new Error('call config.load() before deleting values')
|
| 230 |
+
}
|
| 231 |
+
if (!confTypes.has(where)) {
|
| 232 |
+
throw new Error('invalid config location param: ' + where)
|
| 233 |
+
}
|
| 234 |
+
const { data, raw } = this.data.get(where)
|
| 235 |
+
delete data[key]
|
| 236 |
+
if (['global', 'user', 'project'].includes(where)) {
|
| 237 |
+
delete raw[key]
|
| 238 |
+
}
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
async load () {
|
| 242 |
+
if (this.loaded) {
|
| 243 |
+
throw new Error('attempting to load npm config multiple times')
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
// first load the defaults, which sets the global prefix
|
| 247 |
+
this.loadDefaults()
|
| 248 |
+
|
| 249 |
+
// next load the builtin config, as this sets new effective defaults
|
| 250 |
+
await this.loadBuiltinConfig()
|
| 251 |
+
|
| 252 |
+
// cli and env are not async, and can set the prefix, relevant to project
|
| 253 |
+
this.loadCLI()
|
| 254 |
+
this.loadEnv()
|
| 255 |
+
|
| 256 |
+
// next project config, which can affect userconfig location
|
| 257 |
+
await this.loadProjectConfig()
|
| 258 |
+
|
| 259 |
+
// then user config, which can affect globalconfig location
|
| 260 |
+
await this.loadUserConfig()
|
| 261 |
+
|
| 262 |
+
// last but not least, global config file
|
| 263 |
+
await this.loadGlobalConfig()
|
| 264 |
+
|
| 265 |
+
// set this before calling setEnvs, so that we don't have to share
|
| 266 |
+
// private attributes, as that module also does a bunch of get operations
|
| 267 |
+
this.#loaded = true
|
| 268 |
+
|
| 269 |
+
// set proper globalPrefix now that everything is loaded
|
| 270 |
+
this.globalPrefix = this.get('prefix')
|
| 271 |
+
|
| 272 |
+
this.setEnvs()
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
loadDefaults () {
|
| 276 |
+
this.loadGlobalPrefix()
|
| 277 |
+
this.loadHome()
|
| 278 |
+
|
| 279 |
+
const defaultsObject = {
|
| 280 |
+
...this.defaults,
|
| 281 |
+
prefix: this.globalPrefix,
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
try {
|
| 285 |
+
// This does not have an actual definition because this is not user definable
|
| 286 |
+
defaultsObject['npm-version'] = require(join(this.npmPath, 'package.json')).version
|
| 287 |
+
} catch {
|
| 288 |
+
// in some weird state where the passed in npmPath does not have a package.json
|
| 289 |
+
// this will never happen in npm, but is guarded here in case this is consumed
|
| 290 |
+
// in other ways + tests
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
this.#loadObject(defaultsObject, 'default', 'default values')
|
| 294 |
+
|
| 295 |
+
const { data } = this.data.get('default')
|
| 296 |
+
|
| 297 |
+
// if the prefix is set on cli, env, or userconfig, then we need to
|
| 298 |
+
// default the globalconfig file to that location, instead of the default
|
| 299 |
+
// global prefix. It's weird that `npm get globalconfig --prefix=/foo`
|
| 300 |
+
// returns `/foo/etc/npmrc`, but better to not change it at this point.
|
| 301 |
+
// define a custom getter, but turn into a normal prop
|
| 302 |
+
// if we set it. otherwise it can't be set on child objects
|
| 303 |
+
Object.defineProperty(data, 'globalconfig', {
|
| 304 |
+
get: () => resolve(this.#get('prefix'), 'etc/npmrc'),
|
| 305 |
+
set (value) {
|
| 306 |
+
Object.defineProperty(data, 'globalconfig', {
|
| 307 |
+
value,
|
| 308 |
+
configurable: true,
|
| 309 |
+
writable: true,
|
| 310 |
+
enumerable: true,
|
| 311 |
+
})
|
| 312 |
+
},
|
| 313 |
+
configurable: true,
|
| 314 |
+
enumerable: true,
|
| 315 |
+
})
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
loadHome () {
|
| 319 |
+
this.home = this.env.HOME || homedir()
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
loadGlobalPrefix () {
|
| 323 |
+
if (this.globalPrefix) {
|
| 324 |
+
throw new Error('cannot load default global prefix more than once')
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
if (this.env.PREFIX) {
|
| 328 |
+
this.globalPrefix = this.env.PREFIX
|
| 329 |
+
} else if (this.platform === 'win32') {
|
| 330 |
+
// c:\node\node.exe --> prefix=c:\node\
|
| 331 |
+
this.globalPrefix = dirname(this.execPath)
|
| 332 |
+
} else {
|
| 333 |
+
// /usr/local/bin/node --> prefix=/usr/local
|
| 334 |
+
this.globalPrefix = dirname(dirname(this.execPath))
|
| 335 |
+
|
| 336 |
+
// destdir only is respected on Unix
|
| 337 |
+
if (this.env.DESTDIR) {
|
| 338 |
+
this.globalPrefix = join(this.env.DESTDIR, this.globalPrefix)
|
| 339 |
+
}
|
| 340 |
+
}
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
loadEnv () {
|
| 344 |
+
const conf = Object.create(null)
|
| 345 |
+
for (const [envKey, envVal] of Object.entries(this.env)) {
|
| 346 |
+
if (!/^npm_config_/i.test(envKey) || envVal === '') {
|
| 347 |
+
continue
|
| 348 |
+
}
|
| 349 |
+
let key = envKey.slice('npm_config_'.length)
|
| 350 |
+
if (!key.startsWith('//')) { // don't normalize nerf-darted keys
|
| 351 |
+
key = key.replace(/(?!^)_/g, '-') // don't replace _ at the start of the key
|
| 352 |
+
.toLowerCase()
|
| 353 |
+
}
|
| 354 |
+
conf[key] = envVal
|
| 355 |
+
}
|
| 356 |
+
this.#loadObject(conf, 'env', 'environment')
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
loadCLI () {
|
| 360 |
+
for (const s of Object.keys(this.shorthands)) {
|
| 361 |
+
if (s.length > 1 && this.argv.includes(`-${s}`)) {
|
| 362 |
+
log.warn(`-${s} is not a valid single-hyphen cli flag and will be removed in the future`)
|
| 363 |
+
}
|
| 364 |
+
}
|
| 365 |
+
nopt.invalidHandler = (k, val, type) =>
|
| 366 |
+
this.invalidHandler(k, val, type, 'command line options', 'cli')
|
| 367 |
+
nopt.unknownHandler = (k, next) => this.unknownHandler(k, next)
|
| 368 |
+
nopt.abbrevHandler = this.abbrevHandler
|
| 369 |
+
const conf = nopt(this.types, this.shorthands, this.argv)
|
| 370 |
+
nopt.invalidHandler = null
|
| 371 |
+
nopt.unknownHandler = null
|
| 372 |
+
this.parsedArgv = conf.argv
|
| 373 |
+
delete conf.argv
|
| 374 |
+
this.#loadObject(conf, 'cli', 'command line options')
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
get valid () {
|
| 378 |
+
for (const [where, { valid }] of this.data.entries()) {
|
| 379 |
+
if (valid === false || valid === null && !this.validate(where)) {
|
| 380 |
+
return false
|
| 381 |
+
}
|
| 382 |
+
}
|
| 383 |
+
return true
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
validate (where) {
|
| 387 |
+
if (!where) {
|
| 388 |
+
let valid = true
|
| 389 |
+
const authProblems = []
|
| 390 |
+
|
| 391 |
+
for (const entryWhere of this.data.keys()) {
|
| 392 |
+
// no need to validate our defaults, we know they're fine
|
| 393 |
+
// cli was already validated when parsed the first time
|
| 394 |
+
if (entryWhere === 'default' || entryWhere === 'builtin' || entryWhere === 'cli') {
|
| 395 |
+
continue
|
| 396 |
+
}
|
| 397 |
+
const ret = this.validate(entryWhere)
|
| 398 |
+
valid = valid && ret
|
| 399 |
+
|
| 400 |
+
if (['global', 'user', 'project'].includes(entryWhere)) {
|
| 401 |
+
// after validating everything else, we look for old auth configs we no longer support
|
| 402 |
+
// if these keys are found, we build up a list of them and the appropriate action and
|
| 403 |
+
// attach it as context on the thrown error
|
| 404 |
+
|
| 405 |
+
// first, keys that should be removed
|
| 406 |
+
for (const key of ['_authtoken', '-authtoken']) {
|
| 407 |
+
if (this.get(key, entryWhere)) {
|
| 408 |
+
authProblems.push({ action: 'delete', key, where: entryWhere })
|
| 409 |
+
}
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
// NOTE we pull registry without restricting to the current 'where' because we want to
|
| 413 |
+
// suggest scoping things to the registry they would be applied to, which is the default
|
| 414 |
+
// regardless of where it was defined
|
| 415 |
+
const nerfedReg = nerfDart(this.get('registry'))
|
| 416 |
+
// keys that should be nerfed but currently are not
|
| 417 |
+
for (const key of ['_auth', '_authToken', 'username', '_password']) {
|
| 418 |
+
if (this.get(key, entryWhere)) {
|
| 419 |
+
// username and _password must both exist in the same file to be recognized correctly
|
| 420 |
+
if (key === 'username' && !this.get('_password', entryWhere)) {
|
| 421 |
+
authProblems.push({ action: 'delete', key, where: entryWhere })
|
| 422 |
+
} else if (key === '_password' && !this.get('username', entryWhere)) {
|
| 423 |
+
authProblems.push({ action: 'delete', key, where: entryWhere })
|
| 424 |
+
} else {
|
| 425 |
+
authProblems.push({
|
| 426 |
+
action: 'rename',
|
| 427 |
+
from: key,
|
| 428 |
+
to: `${nerfedReg}:${key}`,
|
| 429 |
+
where: entryWhere,
|
| 430 |
+
})
|
| 431 |
+
}
|
| 432 |
+
}
|
| 433 |
+
}
|
| 434 |
+
}
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
if (authProblems.length) {
|
| 438 |
+
const { ErrInvalidAuth } = require('./errors.js')
|
| 439 |
+
throw new ErrInvalidAuth(authProblems)
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
return valid
|
| 443 |
+
} else {
|
| 444 |
+
const obj = this.data.get(where)
|
| 445 |
+
obj[_valid] = true
|
| 446 |
+
|
| 447 |
+
nopt.invalidHandler = (k, val, type) =>
|
| 448 |
+
this.invalidHandler(k, val, type, obj.source, where)
|
| 449 |
+
|
| 450 |
+
nopt.clean(obj.data, this.types, typeDefs)
|
| 451 |
+
|
| 452 |
+
nopt.invalidHandler = null
|
| 453 |
+
return obj[_valid]
|
| 454 |
+
}
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
// fixes problems identified by validate(), accepts the 'problems' property from a thrown
|
| 458 |
+
// ErrInvalidAuth to avoid having to check everything again
|
| 459 |
+
repair (problems) {
|
| 460 |
+
if (!problems) {
|
| 461 |
+
try {
|
| 462 |
+
this.validate()
|
| 463 |
+
} catch (err) {
|
| 464 |
+
// coverage skipped here because we don't need to test re-throwing an error
|
| 465 |
+
// istanbul ignore next
|
| 466 |
+
if (err.code !== 'ERR_INVALID_AUTH') {
|
| 467 |
+
throw err
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
problems = err.problems
|
| 471 |
+
} finally {
|
| 472 |
+
if (!problems) {
|
| 473 |
+
problems = []
|
| 474 |
+
}
|
| 475 |
+
}
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
for (const problem of problems) {
|
| 479 |
+
// coverage disabled for else branch because it doesn't do anything and shouldn't
|
| 480 |
+
// istanbul ignore else
|
| 481 |
+
if (problem.action === 'delete') {
|
| 482 |
+
this.delete(problem.key, problem.where)
|
| 483 |
+
} else if (problem.action === 'rename') {
|
| 484 |
+
const raw = this.data.get(problem.where).raw?.[problem.from]
|
| 485 |
+
const calculated = this.get(problem.from, problem.where)
|
| 486 |
+
this.set(problem.to, raw || calculated, problem.where)
|
| 487 |
+
this.delete(problem.from, problem.where)
|
| 488 |
+
}
|
| 489 |
+
}
|
| 490 |
+
}
|
| 491 |
+
|
| 492 |
+
// Returns true if the value is coming directly from the source defined
|
| 493 |
+
// in default definitions, if the current value for the key config is
|
| 494 |
+
// coming from any other different source, returns false
|
| 495 |
+
isDefault (key) {
|
| 496 |
+
const [defaultType, ...types] = [...confTypes]
|
| 497 |
+
const defaultData = this.data.get(defaultType).data
|
| 498 |
+
|
| 499 |
+
return hasOwnProperty(defaultData, key)
|
| 500 |
+
&& types.every(type => {
|
| 501 |
+
const typeData = this.data.get(type).data
|
| 502 |
+
return !hasOwnProperty(typeData, key)
|
| 503 |
+
})
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
invalidHandler (k, val, type, source, where) {
|
| 507 |
+
const typeDescription = require('./type-description.js')
|
| 508 |
+
log.warn(
|
| 509 |
+
'invalid config',
|
| 510 |
+
k + '=' + JSON.stringify(val),
|
| 511 |
+
`set in ${source}`
|
| 512 |
+
)
|
| 513 |
+
this.data.get(where)[_valid] = false
|
| 514 |
+
|
| 515 |
+
if (Array.isArray(type)) {
|
| 516 |
+
if (type.includes(typeDefs.url.type)) {
|
| 517 |
+
type = typeDefs.url.type
|
| 518 |
+
} else {
|
| 519 |
+
/* istanbul ignore if - no actual configs matching this, but
|
| 520 |
+
* path types SHOULD be handled this way, like URLs, for the
|
| 521 |
+
* same reason */
|
| 522 |
+
if (type.includes(typeDefs.path.type)) {
|
| 523 |
+
type = typeDefs.path.type
|
| 524 |
+
}
|
| 525 |
+
}
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
const typeDesc = typeDescription(type)
|
| 529 |
+
const mustBe = typeDesc
|
| 530 |
+
.filter(m => m !== undefined && m !== Array)
|
| 531 |
+
const msg = 'Must be' + this.#getOneOfKeywords(mustBe, typeDesc)
|
| 532 |
+
const desc = mustBe.length === 1 ? mustBe[0]
|
| 533 |
+
: [...new Set(mustBe.map(n => typeof n === 'string' ? n : JSON.stringify(n)))].join(', ')
|
| 534 |
+
log.warn('invalid config', msg, desc)
|
| 535 |
+
}
|
| 536 |
+
|
| 537 |
+
abbrevHandler (short, long) {
|
| 538 |
+
log.warn(`Expanding --${short} to --${long}. This will stop working in the next major version of npm.`)
|
| 539 |
+
}
|
| 540 |
+
|
| 541 |
+
unknownHandler (key, next) {
|
| 542 |
+
if (next) {
|
| 543 |
+
this.queueWarning(`unknown:${next}`, `"${next}" is being parsed as a normal command line argument.`)
|
| 544 |
+
}
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
#getOneOfKeywords (mustBe, typeDesc) {
|
| 548 |
+
let keyword
|
| 549 |
+
if (mustBe.length === 1 && typeDesc.includes(Array)) {
|
| 550 |
+
keyword = ' one or more'
|
| 551 |
+
} else if (mustBe.length > 1 && typeDesc.includes(Array)) {
|
| 552 |
+
keyword = ' one or more of:'
|
| 553 |
+
} else if (mustBe.length > 1) {
|
| 554 |
+
keyword = ' one of:'
|
| 555 |
+
} else {
|
| 556 |
+
keyword = ''
|
| 557 |
+
}
|
| 558 |
+
return keyword
|
| 559 |
+
}
|
| 560 |
+
|
| 561 |
+
#loadObject (obj, where, source, er = null) {
|
| 562 |
+
// obj is the raw data read from the file
|
| 563 |
+
const conf = this.data.get(where)
|
| 564 |
+
if (conf.source) {
|
| 565 |
+
const m = `double-loading "${where}" configs from ${source}, ` +
|
| 566 |
+
`previously loaded from ${conf.source}`
|
| 567 |
+
throw new Error(m)
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
if (this.sources.has(source)) {
|
| 571 |
+
const m = `double-loading config "${source}" as "${where}", ` +
|
| 572 |
+
`previously loaded as "${this.sources.get(source)}"`
|
| 573 |
+
throw new Error(m)
|
| 574 |
+
}
|
| 575 |
+
|
| 576 |
+
conf.source = source
|
| 577 |
+
this.sources.set(source, where)
|
| 578 |
+
if (er) {
|
| 579 |
+
conf.loadError = er
|
| 580 |
+
if (er.code !== 'ENOENT') {
|
| 581 |
+
log.verbose('config', `error loading ${where} config`, er)
|
| 582 |
+
}
|
| 583 |
+
} else {
|
| 584 |
+
conf.raw = obj
|
| 585 |
+
outer: for (const [key, value] of Object.entries(obj)) {
|
| 586 |
+
const k = envReplace(key, this.env)
|
| 587 |
+
const v = this.parseField(value, k)
|
| 588 |
+
if (where !== 'default') {
|
| 589 |
+
this.#checkDeprecated(k)
|
| 590 |
+
if (this.definitions[key]?.exclusive) {
|
| 591 |
+
for (const exclusive of this.definitions[key].exclusive) {
|
| 592 |
+
if (!this.isDefault(exclusive)) {
|
| 593 |
+
// when loading from env, skip only if sibling was explicitly set via CLI
|
| 594 |
+
if (where === 'env') {
|
| 595 |
+
const cliData = this.data.get('cli').data
|
| 596 |
+
if (Object.hasOwn(cliData, exclusive)) {
|
| 597 |
+
continue outer
|
| 598 |
+
}
|
| 599 |
+
}
|
| 600 |
+
throw new TypeError(`--${key} cannot be provided when using --${exclusive}`)
|
| 601 |
+
}
|
| 602 |
+
}
|
| 603 |
+
}
|
| 604 |
+
}
|
| 605 |
+
if (where !== 'default' || key === 'npm-version') {
|
| 606 |
+
this.checkUnknown(where, key)
|
| 607 |
+
}
|
| 608 |
+
conf.data[k] = v
|
| 609 |
+
}
|
| 610 |
+
}
|
| 611 |
+
}
|
| 612 |
+
|
| 613 |
+
checkUnknown (where, key) {
|
| 614 |
+
if (!this.definitions[key]) {
|
| 615 |
+
if (internalEnv.includes(key)) {
|
| 616 |
+
return
|
| 617 |
+
}
|
| 618 |
+
const hint = where !== 'cli'
|
| 619 |
+
? ' See `npm help npmrc` for supported config options.'
|
| 620 |
+
: ''
|
| 621 |
+
if (!key.includes(':')) {
|
| 622 |
+
this.queueWarning(key, `Unknown ${where} config "${where === 'cli' ? '--' : ''}${key}". This will stop working in the next major version of npm.${hint}`)
|
| 623 |
+
return
|
| 624 |
+
}
|
| 625 |
+
const baseKey = key.split(':').pop()
|
| 626 |
+
if (!this.definitions[baseKey] && !this.nerfDarts.includes(baseKey)) {
|
| 627 |
+
this.queueWarning(baseKey, `Unknown ${where} config "${baseKey}" (${key}). This will stop working in the next major version of npm.${hint}`)
|
| 628 |
+
}
|
| 629 |
+
}
|
| 630 |
+
}
|
| 631 |
+
|
| 632 |
+
#checkDeprecated (key) {
|
| 633 |
+
if (this.deprecated[key]) {
|
| 634 |
+
log.warn('config', key, this.deprecated[key])
|
| 635 |
+
}
|
| 636 |
+
}
|
| 637 |
+
|
| 638 |
+
// Parse a field, coercing it to the best type available.
|
| 639 |
+
parseField (f, key, listElement = false) {
|
| 640 |
+
return parseField(f, key, this, listElement)
|
| 641 |
+
}
|
| 642 |
+
|
| 643 |
+
async #loadFile (file, type) {
|
| 644 |
+
// only catch the error from readFile, not from the loadObject call
|
| 645 |
+
log.silly('config', `load:file:${file}`)
|
| 646 |
+
await readFile(file, 'utf8').then(
|
| 647 |
+
data => {
|
| 648 |
+
const parsedConfig = ini.parse(data)
|
| 649 |
+
if (type === 'project' && parsedConfig.prefix) {
|
| 650 |
+
// Log error if prefix is mentioned in project .npmrc
|
| 651 |
+
/* eslint-disable-next-line max-len */
|
| 652 |
+
log.error('config', `prefix cannot be changed from project config: ${file}.`)
|
| 653 |
+
}
|
| 654 |
+
return this.#loadObject(parsedConfig, type, file)
|
| 655 |
+
},
|
| 656 |
+
er => this.#loadObject(null, type, file, er)
|
| 657 |
+
)
|
| 658 |
+
}
|
| 659 |
+
|
| 660 |
+
loadBuiltinConfig () {
|
| 661 |
+
return this.#loadFile(resolve(this.npmPath, 'npmrc'), 'builtin')
|
| 662 |
+
}
|
| 663 |
+
|
| 664 |
+
async loadProjectConfig () {
|
| 665 |
+
// the localPrefix can be set by the CLI config, but otherwise is
|
| 666 |
+
// found by walking up the folder tree. either way, we load it before
|
| 667 |
+
// we return to make sure localPrefix is set
|
| 668 |
+
await this.loadLocalPrefix()
|
| 669 |
+
|
| 670 |
+
// if we have not detected a local package json yet, try now that we
|
| 671 |
+
// have a local prefix
|
| 672 |
+
if (this.localPackage == null) {
|
| 673 |
+
this.localPackage = await fileExists(this.localPrefix, 'package.json')
|
| 674 |
+
}
|
| 675 |
+
|
| 676 |
+
if (this.#get('global') === true || this.#get('location') === 'global') {
|
| 677 |
+
this.data.get('project').source = '(global mode enabled, ignored)'
|
| 678 |
+
this.sources.set(this.data.get('project').source, 'project')
|
| 679 |
+
return
|
| 680 |
+
}
|
| 681 |
+
|
| 682 |
+
const projectFile = resolve(this.localPrefix, '.npmrc')
|
| 683 |
+
// if we're in the ~ directory, and there happens to be a node_modules
|
| 684 |
+
// folder (which is not TOO uncommon, it turns out), then we can end
|
| 685 |
+
// up loading the "project" config where the "userconfig" will be,
|
| 686 |
+
// which causes some calamities. So, we only load project config if
|
| 687 |
+
// it doesn't match what the userconfig will be.
|
| 688 |
+
if (projectFile !== this.#get('userconfig')) {
|
| 689 |
+
return this.#loadFile(projectFile, 'project')
|
| 690 |
+
} else {
|
| 691 |
+
this.data.get('project').source = '(same as "user" config, ignored)'
|
| 692 |
+
this.sources.set(this.data.get('project').source, 'project')
|
| 693 |
+
}
|
| 694 |
+
}
|
| 695 |
+
|
| 696 |
+
async loadLocalPrefix () {
|
| 697 |
+
const cliPrefix = this.#get('prefix', 'cli')
|
| 698 |
+
if (cliPrefix) {
|
| 699 |
+
this.localPrefix = cliPrefix
|
| 700 |
+
return
|
| 701 |
+
}
|
| 702 |
+
|
| 703 |
+
const cliWorkspaces = this.#get('workspaces', 'cli')
|
| 704 |
+
const isGlobal = this.#get('global') || this.#get('location') === 'global'
|
| 705 |
+
|
| 706 |
+
for (const p of walkUp(this.cwd)) {
|
| 707 |
+
// HACK: this is an option set in tests to stop the local prefix from being set
|
| 708 |
+
// on tests that are created inside the npm repo
|
| 709 |
+
if (this.excludeNpmCwd && p === this.npmPath) {
|
| 710 |
+
break
|
| 711 |
+
}
|
| 712 |
+
|
| 713 |
+
const hasPackageJson = await fileExists(p, 'package.json')
|
| 714 |
+
|
| 715 |
+
if (!this.localPrefix && (hasPackageJson || await dirExists(p, 'node_modules'))) {
|
| 716 |
+
this.localPrefix = p
|
| 717 |
+
this.localPackage = hasPackageJson
|
| 718 |
+
|
| 719 |
+
// if workspaces are disabled, or we're in global mode, return now
|
| 720 |
+
if (cliWorkspaces === false || isGlobal) {
|
| 721 |
+
return
|
| 722 |
+
}
|
| 723 |
+
|
| 724 |
+
// otherwise, continue the loop
|
| 725 |
+
continue
|
| 726 |
+
}
|
| 727 |
+
|
| 728 |
+
if (this.localPrefix && hasPackageJson) {
|
| 729 |
+
const pkgJson = require('@npmcli/package-json')
|
| 730 |
+
// if we already set localPrefix but this dir has a package.json
|
| 731 |
+
// then we need to see if `p` is a workspace root by reading its package.json
|
| 732 |
+
// however, if reading it fails then we should just move on
|
| 733 |
+
const { content: pkg } = await pkgJson.normalize(p).catch(() => ({ content: {} }))
|
| 734 |
+
if (!pkg?.workspaces) {
|
| 735 |
+
continue
|
| 736 |
+
}
|
| 737 |
+
|
| 738 |
+
const mapWorkspaces = require('@npmcli/map-workspaces')
|
| 739 |
+
const workspaces = await mapWorkspaces({ cwd: p, pkg })
|
| 740 |
+
for (const w of workspaces.values()) {
|
| 741 |
+
if (w === this.localPrefix) {
|
| 742 |
+
// see if there's a .npmrc file in the workspace, if so log a warning
|
| 743 |
+
if (await fileExists(this.localPrefix, '.npmrc')) {
|
| 744 |
+
log.warn('config', `ignoring workspace config at ${this.localPrefix}/.npmrc`)
|
| 745 |
+
}
|
| 746 |
+
|
| 747 |
+
// set the workspace in the default layer, which allows it to be overridden easily
|
| 748 |
+
const { data } = this.data.get('default')
|
| 749 |
+
data.workspace = [this.localPrefix]
|
| 750 |
+
this.localPrefix = p
|
| 751 |
+
this.localPackage = hasPackageJson
|
| 752 |
+
log.info('config', `found workspace root at ${this.localPrefix}`)
|
| 753 |
+
// we found a root, so we return now
|
| 754 |
+
return
|
| 755 |
+
}
|
| 756 |
+
}
|
| 757 |
+
}
|
| 758 |
+
}
|
| 759 |
+
|
| 760 |
+
if (!this.localPrefix) {
|
| 761 |
+
this.localPrefix = this.cwd
|
| 762 |
+
}
|
| 763 |
+
}
|
| 764 |
+
|
| 765 |
+
loadUserConfig () {
|
| 766 |
+
return this.#loadFile(this.#get('userconfig'), 'user')
|
| 767 |
+
}
|
| 768 |
+
|
| 769 |
+
loadGlobalConfig () {
|
| 770 |
+
return this.#loadFile(this.#get('globalconfig'), 'global')
|
| 771 |
+
}
|
| 772 |
+
|
| 773 |
+
async save (where) {
|
| 774 |
+
if (!this.loaded) {
|
| 775 |
+
throw new Error('call config.load() before saving')
|
| 776 |
+
}
|
| 777 |
+
if (!confFileTypes.has(where)) {
|
| 778 |
+
throw new Error('invalid config location param: ' + where)
|
| 779 |
+
}
|
| 780 |
+
|
| 781 |
+
const conf = this.data.get(where)
|
| 782 |
+
conf[_loadError] = null
|
| 783 |
+
|
| 784 |
+
if (where === 'user') {
|
| 785 |
+
// if email is nerfed, then we want to de-nerf it
|
| 786 |
+
const nerfed = nerfDart(this.get('registry'))
|
| 787 |
+
const email = this.get(`${nerfed}:email`, 'user')
|
| 788 |
+
if (email) {
|
| 789 |
+
this.delete(`${nerfed}:email`, 'user')
|
| 790 |
+
this.set('email', email, 'user')
|
| 791 |
+
}
|
| 792 |
+
}
|
| 793 |
+
|
| 794 |
+
// We need the actual raw data before we called parseField so that we are
|
| 795 |
+
// saving the same content back to the file
|
| 796 |
+
const iniData = ini.stringify(conf.raw).trim() + '\n'
|
| 797 |
+
if (!iniData.trim()) {
|
| 798 |
+
// ignore the unlink error (eg, if file doesn't exist)
|
| 799 |
+
await unlink(conf.source).catch(() => {})
|
| 800 |
+
return
|
| 801 |
+
}
|
| 802 |
+
const dir = dirname(conf.source)
|
| 803 |
+
await mkdir(dir, { recursive: true })
|
| 804 |
+
await writeFile(conf.source, iniData, 'utf8')
|
| 805 |
+
const mode = where === 'user' ? 0o600 : 0o666
|
| 806 |
+
await chmod(conf.source, mode)
|
| 807 |
+
}
|
| 808 |
+
|
| 809 |
+
clearCredentialsByURI (uri, level = 'user') {
|
| 810 |
+
const nerfed = nerfDart(uri)
|
| 811 |
+
const def = nerfDart(this.get('registry'))
|
| 812 |
+
if (def === nerfed) {
|
| 813 |
+
this.delete(`-authtoken`, level)
|
| 814 |
+
this.delete(`_authToken`, level)
|
| 815 |
+
this.delete(`_authtoken`, level)
|
| 816 |
+
this.delete(`_auth`, level)
|
| 817 |
+
this.delete(`_password`, level)
|
| 818 |
+
this.delete(`username`, level)
|
| 819 |
+
// de-nerf email if it's nerfed to the default registry
|
| 820 |
+
const email = this.get(`${nerfed}:email`, level)
|
| 821 |
+
if (email) {
|
| 822 |
+
this.set('email', email, level)
|
| 823 |
+
}
|
| 824 |
+
}
|
| 825 |
+
this.delete(`${nerfed}:_authToken`, level)
|
| 826 |
+
this.delete(`${nerfed}:_auth`, level)
|
| 827 |
+
this.delete(`${nerfed}:_password`, level)
|
| 828 |
+
this.delete(`${nerfed}:username`, level)
|
| 829 |
+
this.delete(`${nerfed}:email`, level)
|
| 830 |
+
this.delete(`${nerfed}:certfile`, level)
|
| 831 |
+
this.delete(`${nerfed}:keyfile`, level)
|
| 832 |
+
}
|
| 833 |
+
|
| 834 |
+
setCredentialsByURI (uri, { token, username, password, certfile, keyfile }) {
|
| 835 |
+
const nerfed = nerfDart(uri)
|
| 836 |
+
|
| 837 |
+
// field that hasn't been used as documented for a LONG time,
|
| 838 |
+
// and as of npm 7.10.0, isn't used at all. We just always
|
| 839 |
+
// send auth if we have it, only to the URIs under the nerf dart.
|
| 840 |
+
this.delete(`${nerfed}:always-auth`, 'user')
|
| 841 |
+
|
| 842 |
+
this.delete(`${nerfed}:email`, 'user')
|
| 843 |
+
if (certfile && keyfile) {
|
| 844 |
+
this.set(`${nerfed}:certfile`, certfile, 'user')
|
| 845 |
+
this.set(`${nerfed}:keyfile`, keyfile, 'user')
|
| 846 |
+
// cert/key may be used in conjunction with other credentials, thus no `else`
|
| 847 |
+
}
|
| 848 |
+
if (token) {
|
| 849 |
+
this.set(`${nerfed}:_authToken`, token, 'user')
|
| 850 |
+
this.delete(`${nerfed}:_password`, 'user')
|
| 851 |
+
this.delete(`${nerfed}:username`, 'user')
|
| 852 |
+
} else if (username || password) {
|
| 853 |
+
if (!username) {
|
| 854 |
+
throw new Error('must include username')
|
| 855 |
+
}
|
| 856 |
+
if (!password) {
|
| 857 |
+
throw new Error('must include password')
|
| 858 |
+
}
|
| 859 |
+
this.delete(`${nerfed}:_authToken`, 'user')
|
| 860 |
+
this.set(`${nerfed}:username`, username, 'user')
|
| 861 |
+
// note: not encrypted, no idea why we bothered to do this, but oh well
|
| 862 |
+
// protects against shoulder-hacks if password is memorable, I guess?
|
| 863 |
+
const encoded = Buffer.from(password, 'utf8').toString('base64')
|
| 864 |
+
this.set(`${nerfed}:_password`, encoded, 'user')
|
| 865 |
+
} else if (!certfile || !keyfile) {
|
| 866 |
+
throw new Error('No credentials to set.')
|
| 867 |
+
}
|
| 868 |
+
}
|
| 869 |
+
|
| 870 |
+
// this has to be a bit more complicated to support legacy data of all forms
|
| 871 |
+
getCredentialsByURI (uri) {
|
| 872 |
+
const nerfed = nerfDart(uri)
|
| 873 |
+
const def = nerfDart(this.get('registry'))
|
| 874 |
+
const creds = {}
|
| 875 |
+
|
| 876 |
+
// email is handled differently, it used to always be nerfed and now it never should be
|
| 877 |
+
// if it's set nerfed to the default registry, then we copy it to the unnerfed key
|
| 878 |
+
// TODO: evaluate removing 'email' from the credentials object returned here
|
| 879 |
+
const email = this.get(`${nerfed}:email`) || this.get('email')
|
| 880 |
+
if (email) {
|
| 881 |
+
if (nerfed === def) {
|
| 882 |
+
this.set('email', email, 'user')
|
| 883 |
+
}
|
| 884 |
+
creds.email = email
|
| 885 |
+
}
|
| 886 |
+
|
| 887 |
+
const certfileReg = this.get(`${nerfed}:certfile`)
|
| 888 |
+
const keyfileReg = this.get(`${nerfed}:keyfile`)
|
| 889 |
+
if (certfileReg && keyfileReg) {
|
| 890 |
+
creds.certfile = certfileReg
|
| 891 |
+
creds.keyfile = keyfileReg
|
| 892 |
+
// cert/key may be used in conjunction with other credentials, thus no `return`
|
| 893 |
+
}
|
| 894 |
+
|
| 895 |
+
const tokenReg = this.get(`${nerfed}:_authToken`)
|
| 896 |
+
if (tokenReg) {
|
| 897 |
+
creds.token = tokenReg
|
| 898 |
+
return creds
|
| 899 |
+
}
|
| 900 |
+
|
| 901 |
+
const userReg = this.get(`${nerfed}:username`)
|
| 902 |
+
const passReg = this.get(`${nerfed}:_password`)
|
| 903 |
+
if (userReg && passReg) {
|
| 904 |
+
creds.username = userReg
|
| 905 |
+
creds.password = Buffer.from(passReg, 'base64').toString('utf8')
|
| 906 |
+
const auth = `${creds.username}:${creds.password}`
|
| 907 |
+
creds.auth = Buffer.from(auth, 'utf8').toString('base64')
|
| 908 |
+
return creds
|
| 909 |
+
}
|
| 910 |
+
|
| 911 |
+
const authReg = this.get(`${nerfed}:_auth`)
|
| 912 |
+
if (authReg) {
|
| 913 |
+
const authDecode = Buffer.from(authReg, 'base64').toString('utf8')
|
| 914 |
+
const authSplit = authDecode.split(':')
|
| 915 |
+
creds.username = authSplit.shift()
|
| 916 |
+
creds.password = authSplit.join(':')
|
| 917 |
+
creds.auth = authReg
|
| 918 |
+
return creds
|
| 919 |
+
}
|
| 920 |
+
|
| 921 |
+
// at this point, nothing else is usable so just return what we do have
|
| 922 |
+
return creds
|
| 923 |
+
}
|
| 924 |
+
|
| 925 |
+
// set up the environment object we have with npm_config_* environs
|
| 926 |
+
// for all configs that are different from their default values, and
|
| 927 |
+
// set EDITOR and HOME.
|
| 928 |
+
setEnvs () {
|
| 929 |
+
setEnvs(this)
|
| 930 |
+
}
|
| 931 |
+
|
| 932 |
+
removeWarning (key) {
|
| 933 |
+
this.#warnings = this.#warnings.filter(w => w.type !== key)
|
| 934 |
+
}
|
| 935 |
+
|
| 936 |
+
getUnknownPositionals () {
|
| 937 |
+
return this.#warnings
|
| 938 |
+
.filter(w => w.type.startsWith('unknown:'))
|
| 939 |
+
.map(w => w.type.slice('unknown:'.length))
|
| 940 |
+
}
|
| 941 |
+
|
| 942 |
+
removeUnknownPositional (value) {
|
| 943 |
+
this.removeWarning(`unknown:${value}`)
|
| 944 |
+
}
|
| 945 |
+
|
| 946 |
+
queueWarning (type, ...args) {
|
| 947 |
+
if (!this.warn) {
|
| 948 |
+
this.#warnings.push({ type, args })
|
| 949 |
+
} else {
|
| 950 |
+
log.warn(...args)
|
| 951 |
+
}
|
| 952 |
+
}
|
| 953 |
+
|
| 954 |
+
logWarnings () {
|
| 955 |
+
for (const warning of this.#warnings) {
|
| 956 |
+
log.warn(...warning.args)
|
| 957 |
+
}
|
| 958 |
+
this.#warnings = []
|
| 959 |
+
}
|
| 960 |
+
}
|
| 961 |
+
|
| 962 |
+
const _loadError = Symbol('loadError')
|
| 963 |
+
const _valid = Symbol('valid')
|
| 964 |
+
|
| 965 |
+
class ConfigData {
|
| 966 |
+
#data
|
| 967 |
+
#source = null
|
| 968 |
+
#raw = null
|
| 969 |
+
constructor (parent) {
|
| 970 |
+
this.#data = Object.create(parent && parent.data)
|
| 971 |
+
this.#raw = {}
|
| 972 |
+
this[_valid] = true
|
| 973 |
+
}
|
| 974 |
+
|
| 975 |
+
get data () {
|
| 976 |
+
return this.#data
|
| 977 |
+
}
|
| 978 |
+
|
| 979 |
+
get valid () {
|
| 980 |
+
return this[_valid]
|
| 981 |
+
}
|
| 982 |
+
|
| 983 |
+
set source (s) {
|
| 984 |
+
if (this.#source) {
|
| 985 |
+
throw new Error('cannot set ConfigData source more than once')
|
| 986 |
+
}
|
| 987 |
+
this.#source = s
|
| 988 |
+
}
|
| 989 |
+
|
| 990 |
+
get source () {
|
| 991 |
+
return this.#source
|
| 992 |
+
}
|
| 993 |
+
|
| 994 |
+
set loadError (e) {
|
| 995 |
+
if (this[_loadError] || (Object.keys(this.#raw).length)) {
|
| 996 |
+
throw new Error('cannot set ConfigData loadError after load')
|
| 997 |
+
}
|
| 998 |
+
this[_loadError] = e
|
| 999 |
+
}
|
| 1000 |
+
|
| 1001 |
+
get loadError () {
|
| 1002 |
+
return this[_loadError]
|
| 1003 |
+
}
|
| 1004 |
+
|
| 1005 |
+
set raw (r) {
|
| 1006 |
+
if (Object.keys(this.#raw).length || this[_loadError]) {
|
| 1007 |
+
throw new Error('cannot set ConfigData raw after load')
|
| 1008 |
+
}
|
| 1009 |
+
this.#raw = r
|
| 1010 |
+
}
|
| 1011 |
+
|
| 1012 |
+
get raw () {
|
| 1013 |
+
return this.#raw
|
| 1014 |
+
}
|
| 1015 |
+
}
|
| 1016 |
+
|
| 1017 |
+
const getTypesFromDefinitions = (definitions) => {
|
| 1018 |
+
const types = {}
|
| 1019 |
+
const defaults = {}
|
| 1020 |
+
const deprecated = {}
|
| 1021 |
+
|
| 1022 |
+
for (const [key, def] of Object.entries(definitions)) {
|
| 1023 |
+
defaults[key] = def.default
|
| 1024 |
+
types[key] = def.type
|
| 1025 |
+
if (def.deprecated) {
|
| 1026 |
+
deprecated[key] = def.deprecated.trim().replace(/\n +/, '\n')
|
| 1027 |
+
}
|
| 1028 |
+
}
|
| 1029 |
+
|
| 1030 |
+
return { types, defaults, deprecated }
|
| 1031 |
+
}
|
| 1032 |
+
|
| 1033 |
+
module.exports = Config
|
| 1034 |
+
module.exports.getTypesFromDefinitions = getTypesFromDefinitions
|
node/node_modules/npm/node_modules/@npmcli/config/lib/nerf-dart.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const { URL } = require('node:url')
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Maps a URL to an identifier.
|
| 5 |
+
*
|
| 6 |
+
* Name courtesy schiffertronix media LLC, a New Jersey corporation
|
| 7 |
+
*
|
| 8 |
+
* @param {String} uri The URL to be nerfed.
|
| 9 |
+
*
|
| 10 |
+
* @returns {String} A nerfed URL.
|
| 11 |
+
*/
|
| 12 |
+
module.exports = (url) => {
|
| 13 |
+
const parsed = new URL(url)
|
| 14 |
+
const from = `${parsed.protocol}//${parsed.host}${parsed.pathname}`
|
| 15 |
+
const rel = new URL('.', from)
|
| 16 |
+
const res = `//${rel.host}${rel.pathname}`
|
| 17 |
+
return res
|
| 18 |
+
}
|
node/node_modules/npm/node_modules/@npmcli/config/lib/parse-field.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Parse a field, coercing it to the best type available.
|
| 2 |
+
const typeDefs = require('./type-defs.js')
|
| 3 |
+
const envReplace = require('./env-replace.js')
|
| 4 |
+
const { resolve } = require('node:path')
|
| 5 |
+
|
| 6 |
+
const { parse: umaskParse } = require('./umask.js')
|
| 7 |
+
|
| 8 |
+
const parseField = (f, key, opts, listElement = false) => {
|
| 9 |
+
if (typeof f !== 'string' && !Array.isArray(f)) {
|
| 10 |
+
return f
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
const { platform, types, home, env } = opts
|
| 14 |
+
|
| 15 |
+
// type can be array or a single thing. coerce to array.
|
| 16 |
+
const typeList = new Set([].concat(types[key]))
|
| 17 |
+
const isPath = typeList.has(typeDefs.path.type)
|
| 18 |
+
const isBool = typeList.has(typeDefs.Boolean.type)
|
| 19 |
+
const isString = isPath || typeList.has(typeDefs.String.type)
|
| 20 |
+
const isUmask = typeList.has(typeDefs.Umask.type)
|
| 21 |
+
const isNumber = typeList.has(typeDefs.Number.type)
|
| 22 |
+
const isList = !listElement && typeList.has(Array)
|
| 23 |
+
const isDate = typeList.has(typeDefs.Date.type)
|
| 24 |
+
|
| 25 |
+
if (Array.isArray(f)) {
|
| 26 |
+
return !isList ? f : f.map(field => parseField(field, key, opts, true))
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
// now we know it's a string
|
| 30 |
+
f = f.trim()
|
| 31 |
+
|
| 32 |
+
// list types get put in the environment separated by double-\n
|
| 33 |
+
// usually a single \n would suffice, but ca/cert configs can contain
|
| 34 |
+
// line breaks and multiple entries.
|
| 35 |
+
if (isList) {
|
| 36 |
+
return parseField(f.split('\n\n'), key, opts)
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
// --foo is like --foo=true for boolean types
|
| 40 |
+
if (isBool && !isString && f === '') {
|
| 41 |
+
return true
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
// string types can be the string 'true', 'false', etc.
|
| 45 |
+
// otherwise, parse these values out
|
| 46 |
+
if (!isString && !isPath && !isNumber) {
|
| 47 |
+
switch (f) {
|
| 48 |
+
case 'true': return true
|
| 49 |
+
case 'false': return false
|
| 50 |
+
case 'null': return null
|
| 51 |
+
case 'undefined': return undefined
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
f = envReplace(f, env)
|
| 56 |
+
|
| 57 |
+
if (isDate) {
|
| 58 |
+
return new Date(f)
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
if (isPath) {
|
| 62 |
+
const homePattern = platform === 'win32' ? /^~(\/|\\)/ : /^~\//
|
| 63 |
+
if (homePattern.test(f) && home) {
|
| 64 |
+
f = resolve(home, f.slice(2))
|
| 65 |
+
} else {
|
| 66 |
+
f = resolve(f)
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
if (isUmask) {
|
| 71 |
+
try {
|
| 72 |
+
return umaskParse(f)
|
| 73 |
+
} catch (er) {
|
| 74 |
+
// let it warn later when we validate
|
| 75 |
+
return f
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
if (isNumber && !isNaN(f)) {
|
| 80 |
+
f = +f
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
return f
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
module.exports = parseField
|
node/node_modules/npm/node_modules/@npmcli/config/lib/set-envs.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Set environment variables for any non-default configs,
|
| 2 |
+
// so that they're already there when we run lifecycle scripts.
|
| 3 |
+
//
|
| 4 |
+
// See https://github.com/npm/rfcs/pull/90
|
| 5 |
+
|
| 6 |
+
// Return the env key if this is a thing that belongs in the env.
|
| 7 |
+
// Ie, if the key isn't a @scope, //nerf.dart, or _private,
|
| 8 |
+
// and the value is a string or array. Otherwise return false.
|
| 9 |
+
const envKey = (key, val) => {
|
| 10 |
+
return !/^[/@_]/.test(key) &&
|
| 11 |
+
(typeof envVal(val) === 'string') &&
|
| 12 |
+
`npm_config_${key.replace(/-/g, '_').toLowerCase()}`
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
const envVal = val => Array.isArray(val) ? val.map(v => envVal(v)).join('\n\n')
|
| 16 |
+
: val === null || val === undefined || val === false ? ''
|
| 17 |
+
: typeof val === 'object' ? null
|
| 18 |
+
: String(val)
|
| 19 |
+
|
| 20 |
+
const sameConfigValue = (def, val) =>
|
| 21 |
+
!Array.isArray(val) || !Array.isArray(def) ? def === val
|
| 22 |
+
: sameArrayValue(def, val)
|
| 23 |
+
|
| 24 |
+
const sameArrayValue = (def, val) => {
|
| 25 |
+
if (def.length !== val.length) {
|
| 26 |
+
return false
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
for (let i = 0; i < def.length; i++) {
|
| 30 |
+
/* istanbul ignore next - there are no array configs where the default
|
| 31 |
+
* is not an empty array, so this loop is a no-op, but it's the correct
|
| 32 |
+
* thing to do if we ever DO add a config like that. */
|
| 33 |
+
if (def[i] !== val[i]) {
|
| 34 |
+
return false
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
return true
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
const setEnv = (env, rawKey, rawVal) => {
|
| 41 |
+
const val = envVal(rawVal)
|
| 42 |
+
const key = envKey(rawKey, val)
|
| 43 |
+
if (key && val !== null) {
|
| 44 |
+
env[key] = val
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
const setEnvs = (config) => {
|
| 49 |
+
// This ensures that all npm config values that are not the defaults are
|
| 50 |
+
// shared appropriately with child processes, without false positives.
|
| 51 |
+
const {
|
| 52 |
+
env,
|
| 53 |
+
defaults,
|
| 54 |
+
definitions,
|
| 55 |
+
list: [cliConf, envConf],
|
| 56 |
+
} = config
|
| 57 |
+
|
| 58 |
+
env.INIT_CWD = process.cwd()
|
| 59 |
+
|
| 60 |
+
// if the key is deprecated, skip it always.
|
| 61 |
+
// if the key is the default value,
|
| 62 |
+
// if the environ is NOT the default value,
|
| 63 |
+
// set the environ
|
| 64 |
+
// else skip it, it's fine
|
| 65 |
+
// if the key is NOT the default value,
|
| 66 |
+
// if the env is setting it, then leave it (already set)
|
| 67 |
+
// otherwise, set the env
|
| 68 |
+
const cliSet = new Set(Object.keys(cliConf))
|
| 69 |
+
const envSet = new Set(Object.keys(envConf))
|
| 70 |
+
for (const key in cliConf) {
|
| 71 |
+
const { deprecated, envExport = true } = definitions[key] || {}
|
| 72 |
+
if (deprecated || envExport === false) {
|
| 73 |
+
continue
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
if (sameConfigValue(defaults[key], cliConf[key])) {
|
| 77 |
+
// config is the default, if the env thought different, then we
|
| 78 |
+
// have to set it BACK to the default in the environment.
|
| 79 |
+
if (!sameConfigValue(envConf[key], cliConf[key])) {
|
| 80 |
+
setEnv(env, key, cliConf[key])
|
| 81 |
+
}
|
| 82 |
+
} else {
|
| 83 |
+
// config is not the default. if the env wasn't the one to set
|
| 84 |
+
// it that way, then we have to put it in the env
|
| 85 |
+
if (!(envSet.has(key) && !cliSet.has(key))) {
|
| 86 |
+
setEnv(env, key, cliConf[key])
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
// also set some other common nice envs that we want to rely on
|
| 92 |
+
env.HOME = config.home
|
| 93 |
+
// TODO this may not be the best away to persist these
|
| 94 |
+
env.npm_config_global_prefix = config.globalPrefix
|
| 95 |
+
env.npm_config_local_prefix = config.localPrefix
|
| 96 |
+
if (cliConf.editor) {
|
| 97 |
+
env.EDITOR = cliConf.editor
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
// note: this doesn't affect the *current* node process, of course, since
|
| 101 |
+
// it's already started, but it does affect the options passed to scripts.
|
| 102 |
+
if (cliConf['node-options']) {
|
| 103 |
+
env.NODE_OPTIONS = cliConf['node-options']
|
| 104 |
+
}
|
| 105 |
+
// the node-gyp bin uses this so we always set it
|
| 106 |
+
env.npm_config_node_gyp = cliConf['node-gyp']
|
| 107 |
+
// this doesn't have a full definition so we manually export it here
|
| 108 |
+
env.npm_config_npm_version = cliConf['npm-version'] || 'unknown'
|
| 109 |
+
env.npm_execpath = config.npmBin
|
| 110 |
+
env.NODE = env.npm_node_execpath = config.execPath
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
module.exports = setEnvs
|
node/node_modules/npm/node_modules/@npmcli/config/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@npmcli/config",
|
| 3 |
+
"version": "10.8.1",
|
| 4 |
+
"files": [
|
| 5 |
+
"bin/",
|
| 6 |
+
"lib/"
|
| 7 |
+
],
|
| 8 |
+
"main": "lib/index.js",
|
| 9 |
+
"description": "Configuration management for the npm cli",
|
| 10 |
+
"repository": {
|
| 11 |
+
"type": "git",
|
| 12 |
+
"url": "git+https://github.com/npm/cli.git",
|
| 13 |
+
"directory": "workspaces/config"
|
| 14 |
+
},
|
| 15 |
+
"author": "GitHub Inc.",
|
| 16 |
+
"license": "ISC",
|
| 17 |
+
"scripts": {
|
| 18 |
+
"test": "tap",
|
| 19 |
+
"snap": "tap",
|
| 20 |
+
"lint": "npm run eslint",
|
| 21 |
+
"postlint": "template-oss-check",
|
| 22 |
+
"lintfix": "npm run eslint -- --fix",
|
| 23 |
+
"posttest": "npm run lint",
|
| 24 |
+
"template-oss-apply": "template-oss-apply --force",
|
| 25 |
+
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
|
| 26 |
+
},
|
| 27 |
+
"tap": {
|
| 28 |
+
"nyc-arg": [
|
| 29 |
+
"--exclude",
|
| 30 |
+
"tap-snapshots/**"
|
| 31 |
+
]
|
| 32 |
+
},
|
| 33 |
+
"devDependencies": {
|
| 34 |
+
"@npmcli/eslint-config": "^5.0.1",
|
| 35 |
+
"@npmcli/mock-globals": "^1.0.0",
|
| 36 |
+
"@npmcli/template-oss": "4.29.0",
|
| 37 |
+
"tap": "^16.3.8"
|
| 38 |
+
},
|
| 39 |
+
"dependencies": {
|
| 40 |
+
"@npmcli/map-workspaces": "^5.0.0",
|
| 41 |
+
"@npmcli/package-json": "^7.0.0",
|
| 42 |
+
"ci-info": "^4.0.0",
|
| 43 |
+
"ini": "^6.0.0",
|
| 44 |
+
"nopt": "^9.0.0",
|
| 45 |
+
"proc-log": "^6.0.0",
|
| 46 |
+
"semver": "^7.3.5",
|
| 47 |
+
"walk-up-path": "^4.0.0"
|
| 48 |
+
},
|
| 49 |
+
"engines": {
|
| 50 |
+
"node": "^20.17.0 || >=22.9.0"
|
| 51 |
+
},
|
| 52 |
+
"templateOSS": {
|
| 53 |
+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
| 54 |
+
"version": "4.29.0",
|
| 55 |
+
"content": "../../scripts/template-oss/index.js"
|
| 56 |
+
}
|
| 57 |
+
}
|
node/node_modules/npm/node_modules/@npmcli/fs/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!-- This file is automatically added by @npmcli/template-oss. Do not edit. -->
|
| 2 |
+
|
| 3 |
+
ISC License
|
| 4 |
+
|
| 5 |
+
Copyright npm, Inc.
|
| 6 |
+
|
| 7 |
+
Permission to use, copy, modify, and/or distribute this
|
| 8 |
+
software for any purpose with or without fee is hereby
|
| 9 |
+
granted, provided that the above copyright notice and this
|
| 10 |
+
permission notice appear in all copies.
|
| 11 |
+
|
| 12 |
+
THE SOFTWARE IS PROVIDED "AS IS" AND NPM DISCLAIMS ALL
|
| 13 |
+
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
| 14 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
|
| 15 |
+
EVENT SHALL NPM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
| 16 |
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 17 |
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
| 18 |
+
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
| 19 |
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
|
| 20 |
+
USE OR PERFORMANCE OF THIS SOFTWARE.
|
node/node_modules/npm/node_modules/@npmcli/fs/lib/common/get-options.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// given an input that may or may not be an object, return an object that has
|
| 2 |
+
// a copy of every defined property listed in 'copy'. if the input is not an
|
| 3 |
+
// object, assign it to the property named by 'wrap'
|
| 4 |
+
const getOptions = (input, { copy, wrap }) => {
|
| 5 |
+
const result = {}
|
| 6 |
+
|
| 7 |
+
if (input && typeof input === 'object') {
|
| 8 |
+
for (const prop of copy) {
|
| 9 |
+
if (input[prop] !== undefined) {
|
| 10 |
+
result[prop] = input[prop]
|
| 11 |
+
}
|
| 12 |
+
}
|
| 13 |
+
} else {
|
| 14 |
+
result[wrap] = input
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
return result
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
module.exports = getOptions
|
node/node_modules/npm/node_modules/@npmcli/fs/lib/common/node.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const semver = require('semver')
|
| 2 |
+
|
| 3 |
+
const satisfies = (range) => {
|
| 4 |
+
return semver.satisfies(process.version, range, { includePrerelease: true })
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
module.exports = {
|
| 8 |
+
satisfies,
|
| 9 |
+
}
|
node/node_modules/npm/node_modules/@npmcli/fs/lib/cp/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
(The MIT License)
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2011-2017 JP Richardson
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
|
| 6 |
+
(the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
|
| 7 |
+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
| 11 |
+
|
| 12 |
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
| 13 |
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
| 14 |
+
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
| 15 |
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
node/node_modules/npm/node_modules/@npmcli/fs/lib/cp/errors.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
const { inspect } = require('util')
|
| 3 |
+
|
| 4 |
+
// adapted from node's internal/errors
|
| 5 |
+
// https://github.com/nodejs/node/blob/c8a04049/lib/internal/errors.js
|
| 6 |
+
|
| 7 |
+
// close copy of node's internal SystemError class.
|
| 8 |
+
class SystemError {
|
| 9 |
+
constructor (code, prefix, context) {
|
| 10 |
+
// XXX context.code is undefined in all constructors used in cp/polyfill
|
| 11 |
+
// that may be a bug copied from node, maybe the constructor should use
|
| 12 |
+
// `code` not `errno`? nodejs/node#41104
|
| 13 |
+
let message = `${prefix}: ${context.syscall} returned ` +
|
| 14 |
+
`${context.code} (${context.message})`
|
| 15 |
+
|
| 16 |
+
if (context.path !== undefined) {
|
| 17 |
+
message += ` ${context.path}`
|
| 18 |
+
}
|
| 19 |
+
if (context.dest !== undefined) {
|
| 20 |
+
message += ` => ${context.dest}`
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
this.code = code
|
| 24 |
+
Object.defineProperties(this, {
|
| 25 |
+
name: {
|
| 26 |
+
value: 'SystemError',
|
| 27 |
+
enumerable: false,
|
| 28 |
+
writable: true,
|
| 29 |
+
configurable: true,
|
| 30 |
+
},
|
| 31 |
+
message: {
|
| 32 |
+
value: message,
|
| 33 |
+
enumerable: false,
|
| 34 |
+
writable: true,
|
| 35 |
+
configurable: true,
|
| 36 |
+
},
|
| 37 |
+
info: {
|
| 38 |
+
value: context,
|
| 39 |
+
enumerable: true,
|
| 40 |
+
configurable: true,
|
| 41 |
+
writable: false,
|
| 42 |
+
},
|
| 43 |
+
errno: {
|
| 44 |
+
get () {
|
| 45 |
+
return context.errno
|
| 46 |
+
},
|
| 47 |
+
set (value) {
|
| 48 |
+
context.errno = value
|
| 49 |
+
},
|
| 50 |
+
enumerable: true,
|
| 51 |
+
configurable: true,
|
| 52 |
+
},
|
| 53 |
+
syscall: {
|
| 54 |
+
get () {
|
| 55 |
+
return context.syscall
|
| 56 |
+
},
|
| 57 |
+
set (value) {
|
| 58 |
+
context.syscall = value
|
| 59 |
+
},
|
| 60 |
+
enumerable: true,
|
| 61 |
+
configurable: true,
|
| 62 |
+
},
|
| 63 |
+
})
|
| 64 |
+
|
| 65 |
+
if (context.path !== undefined) {
|
| 66 |
+
Object.defineProperty(this, 'path', {
|
| 67 |
+
get () {
|
| 68 |
+
return context.path
|
| 69 |
+
},
|
| 70 |
+
set (value) {
|
| 71 |
+
context.path = value
|
| 72 |
+
},
|
| 73 |
+
enumerable: true,
|
| 74 |
+
configurable: true,
|
| 75 |
+
})
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
if (context.dest !== undefined) {
|
| 79 |
+
Object.defineProperty(this, 'dest', {
|
| 80 |
+
get () {
|
| 81 |
+
return context.dest
|
| 82 |
+
},
|
| 83 |
+
set (value) {
|
| 84 |
+
context.dest = value
|
| 85 |
+
},
|
| 86 |
+
enumerable: true,
|
| 87 |
+
configurable: true,
|
| 88 |
+
})
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
toString () {
|
| 93 |
+
return `${this.name} [${this.code}]: ${this.message}`
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
[Symbol.for('nodejs.util.inspect.custom')] (_recurseTimes, ctx) {
|
| 97 |
+
return inspect(this, {
|
| 98 |
+
...ctx,
|
| 99 |
+
getters: true,
|
| 100 |
+
customInspect: false,
|
| 101 |
+
})
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
function E (code, message) {
|
| 106 |
+
module.exports[code] = class NodeError extends SystemError {
|
| 107 |
+
constructor (ctx) {
|
| 108 |
+
super(code, message, ctx)
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
E('ERR_FS_CP_DIR_TO_NON_DIR', 'Cannot overwrite directory with non-directory')
|
| 114 |
+
E('ERR_FS_CP_EEXIST', 'Target already exists')
|
| 115 |
+
E('ERR_FS_CP_EINVAL', 'Invalid src or dest')
|
| 116 |
+
E('ERR_FS_CP_FIFO_PIPE', 'Cannot copy a FIFO pipe')
|
| 117 |
+
E('ERR_FS_CP_NON_DIR_TO_DIR', 'Cannot overwrite non-directory with directory')
|
| 118 |
+
E('ERR_FS_CP_SOCKET', 'Cannot copy a socket file')
|
| 119 |
+
E('ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY', 'Cannot overwrite symlink in subdirectory of self')
|
| 120 |
+
E('ERR_FS_CP_UNKNOWN', 'Cannot copy an unknown file type')
|
| 121 |
+
E('ERR_FS_EISDIR', 'Path is a directory')
|
| 122 |
+
|
| 123 |
+
module.exports.ERR_INVALID_ARG_TYPE = class ERR_INVALID_ARG_TYPE extends Error {
|
| 124 |
+
constructor (name, expected, actual) {
|
| 125 |
+
super()
|
| 126 |
+
this.code = 'ERR_INVALID_ARG_TYPE'
|
| 127 |
+
this.message = `The ${name} argument must be ${expected}. Received ${typeof actual}`
|
| 128 |
+
}
|
| 129 |
+
}
|
node/node_modules/npm/node_modules/@npmcli/fs/lib/cp/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const fs = require('fs/promises')
|
| 2 |
+
const getOptions = require('../common/get-options.js')
|
| 3 |
+
const node = require('../common/node.js')
|
| 4 |
+
const polyfill = require('./polyfill.js')
|
| 5 |
+
|
| 6 |
+
// node 16.7.0 added fs.cp
|
| 7 |
+
const useNative = node.satisfies('>=16.7.0')
|
| 8 |
+
|
| 9 |
+
const cp = async (src, dest, opts) => {
|
| 10 |
+
const options = getOptions(opts, {
|
| 11 |
+
copy: ['dereference', 'errorOnExist', 'filter', 'force', 'preserveTimestamps', 'recursive'],
|
| 12 |
+
})
|
| 13 |
+
|
| 14 |
+
// the polyfill is tested separately from this module, no need to hack
|
| 15 |
+
// process.version to try to trigger it just for coverage
|
| 16 |
+
// istanbul ignore next
|
| 17 |
+
return useNative
|
| 18 |
+
? fs.cp(src, dest, options)
|
| 19 |
+
: polyfill(src, dest, options)
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
module.exports = cp
|
node/node_modules/npm/node_modules/@npmcli/fs/lib/cp/polyfill.js
ADDED
|
@@ -0,0 +1,428 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// this file is a modified version of the code in node 17.2.0
|
| 2 |
+
// which is, in turn, a modified version of the fs-extra module on npm
|
| 3 |
+
// node core changes:
|
| 4 |
+
// - Use of the assert module has been replaced with core's error system.
|
| 5 |
+
// - All code related to the glob dependency has been removed.
|
| 6 |
+
// - Bring your own custom fs module is not currently supported.
|
| 7 |
+
// - Some basic code cleanup.
|
| 8 |
+
// changes here:
|
| 9 |
+
// - remove all callback related code
|
| 10 |
+
// - drop sync support
|
| 11 |
+
// - change assertions back to non-internal methods (see options.js)
|
| 12 |
+
// - throws ENOTDIR when rmdir gets an ENOENT for a path that exists in Windows
|
| 13 |
+
'use strict'
|
| 14 |
+
|
| 15 |
+
const {
|
| 16 |
+
ERR_FS_CP_DIR_TO_NON_DIR,
|
| 17 |
+
ERR_FS_CP_EEXIST,
|
| 18 |
+
ERR_FS_CP_EINVAL,
|
| 19 |
+
ERR_FS_CP_FIFO_PIPE,
|
| 20 |
+
ERR_FS_CP_NON_DIR_TO_DIR,
|
| 21 |
+
ERR_FS_CP_SOCKET,
|
| 22 |
+
ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY,
|
| 23 |
+
ERR_FS_CP_UNKNOWN,
|
| 24 |
+
ERR_FS_EISDIR,
|
| 25 |
+
ERR_INVALID_ARG_TYPE,
|
| 26 |
+
} = require('./errors.js')
|
| 27 |
+
const {
|
| 28 |
+
constants: {
|
| 29 |
+
errno: {
|
| 30 |
+
EEXIST,
|
| 31 |
+
EISDIR,
|
| 32 |
+
EINVAL,
|
| 33 |
+
ENOTDIR,
|
| 34 |
+
},
|
| 35 |
+
},
|
| 36 |
+
} = require('os')
|
| 37 |
+
const {
|
| 38 |
+
chmod,
|
| 39 |
+
copyFile,
|
| 40 |
+
lstat,
|
| 41 |
+
mkdir,
|
| 42 |
+
readdir,
|
| 43 |
+
readlink,
|
| 44 |
+
stat,
|
| 45 |
+
symlink,
|
| 46 |
+
unlink,
|
| 47 |
+
utimes,
|
| 48 |
+
} = require('fs/promises')
|
| 49 |
+
const {
|
| 50 |
+
dirname,
|
| 51 |
+
isAbsolute,
|
| 52 |
+
join,
|
| 53 |
+
parse,
|
| 54 |
+
resolve,
|
| 55 |
+
sep,
|
| 56 |
+
toNamespacedPath,
|
| 57 |
+
} = require('path')
|
| 58 |
+
const { fileURLToPath } = require('url')
|
| 59 |
+
|
| 60 |
+
const defaultOptions = {
|
| 61 |
+
dereference: false,
|
| 62 |
+
errorOnExist: false,
|
| 63 |
+
filter: undefined,
|
| 64 |
+
force: true,
|
| 65 |
+
preserveTimestamps: false,
|
| 66 |
+
recursive: false,
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
async function cp (src, dest, opts) {
|
| 70 |
+
if (opts != null && typeof opts !== 'object') {
|
| 71 |
+
throw new ERR_INVALID_ARG_TYPE('options', ['Object'], opts)
|
| 72 |
+
}
|
| 73 |
+
return cpFn(
|
| 74 |
+
toNamespacedPath(getValidatedPath(src)),
|
| 75 |
+
toNamespacedPath(getValidatedPath(dest)),
|
| 76 |
+
{ ...defaultOptions, ...opts })
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
function getValidatedPath (fileURLOrPath) {
|
| 80 |
+
const path = fileURLOrPath != null && fileURLOrPath.href
|
| 81 |
+
&& fileURLOrPath.origin
|
| 82 |
+
? fileURLToPath(fileURLOrPath)
|
| 83 |
+
: fileURLOrPath
|
| 84 |
+
return path
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
async function cpFn (src, dest, opts) {
|
| 88 |
+
// Warn about using preserveTimestamps on 32-bit node
|
| 89 |
+
// istanbul ignore next
|
| 90 |
+
if (opts.preserveTimestamps && process.arch === 'ia32') {
|
| 91 |
+
const warning = 'Using the preserveTimestamps option in 32-bit ' +
|
| 92 |
+
'node is not recommended'
|
| 93 |
+
process.emitWarning(warning, 'TimestampPrecisionWarning')
|
| 94 |
+
}
|
| 95 |
+
const stats = await checkPaths(src, dest, opts)
|
| 96 |
+
const { srcStat, destStat } = stats
|
| 97 |
+
await checkParentPaths(src, srcStat, dest)
|
| 98 |
+
if (opts.filter) {
|
| 99 |
+
return handleFilter(checkParentDir, destStat, src, dest, opts)
|
| 100 |
+
}
|
| 101 |
+
return checkParentDir(destStat, src, dest, opts)
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
async function checkPaths (src, dest, opts) {
|
| 105 |
+
const { 0: srcStat, 1: destStat } = await getStats(src, dest, opts)
|
| 106 |
+
if (destStat) {
|
| 107 |
+
if (areIdentical(srcStat, destStat)) {
|
| 108 |
+
throw new ERR_FS_CP_EINVAL({
|
| 109 |
+
message: 'src and dest cannot be the same',
|
| 110 |
+
path: dest,
|
| 111 |
+
syscall: 'cp',
|
| 112 |
+
errno: EINVAL,
|
| 113 |
+
})
|
| 114 |
+
}
|
| 115 |
+
if (srcStat.isDirectory() && !destStat.isDirectory()) {
|
| 116 |
+
throw new ERR_FS_CP_DIR_TO_NON_DIR({
|
| 117 |
+
message: `cannot overwrite directory ${src} ` +
|
| 118 |
+
`with non-directory ${dest}`,
|
| 119 |
+
path: dest,
|
| 120 |
+
syscall: 'cp',
|
| 121 |
+
errno: EISDIR,
|
| 122 |
+
})
|
| 123 |
+
}
|
| 124 |
+
if (!srcStat.isDirectory() && destStat.isDirectory()) {
|
| 125 |
+
throw new ERR_FS_CP_NON_DIR_TO_DIR({
|
| 126 |
+
message: `cannot overwrite non-directory ${src} ` +
|
| 127 |
+
`with directory ${dest}`,
|
| 128 |
+
path: dest,
|
| 129 |
+
syscall: 'cp',
|
| 130 |
+
errno: ENOTDIR,
|
| 131 |
+
})
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
|
| 136 |
+
throw new ERR_FS_CP_EINVAL({
|
| 137 |
+
message: `cannot copy ${src} to a subdirectory of self ${dest}`,
|
| 138 |
+
path: dest,
|
| 139 |
+
syscall: 'cp',
|
| 140 |
+
errno: EINVAL,
|
| 141 |
+
})
|
| 142 |
+
}
|
| 143 |
+
return { srcStat, destStat }
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
function areIdentical (srcStat, destStat) {
|
| 147 |
+
return destStat.ino && destStat.dev && destStat.ino === srcStat.ino &&
|
| 148 |
+
destStat.dev === srcStat.dev
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
function getStats (src, dest, opts) {
|
| 152 |
+
const statFunc = opts.dereference ?
|
| 153 |
+
(file) => stat(file, { bigint: true }) :
|
| 154 |
+
(file) => lstat(file, { bigint: true })
|
| 155 |
+
return Promise.all([
|
| 156 |
+
statFunc(src),
|
| 157 |
+
statFunc(dest).catch((err) => {
|
| 158 |
+
// istanbul ignore next: unsure how to cover.
|
| 159 |
+
if (err.code === 'ENOENT') {
|
| 160 |
+
return null
|
| 161 |
+
}
|
| 162 |
+
// istanbul ignore next: unsure how to cover.
|
| 163 |
+
throw err
|
| 164 |
+
}),
|
| 165 |
+
])
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
async function checkParentDir (destStat, src, dest, opts) {
|
| 169 |
+
const destParent = dirname(dest)
|
| 170 |
+
const dirExists = await pathExists(destParent)
|
| 171 |
+
if (dirExists) {
|
| 172 |
+
return getStatsForCopy(destStat, src, dest, opts)
|
| 173 |
+
}
|
| 174 |
+
await mkdir(destParent, { recursive: true })
|
| 175 |
+
return getStatsForCopy(destStat, src, dest, opts)
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
function pathExists (dest) {
|
| 179 |
+
return stat(dest).then(
|
| 180 |
+
() => true,
|
| 181 |
+
// istanbul ignore next: not sure when this would occur
|
| 182 |
+
(err) => (err.code === 'ENOENT' ? false : Promise.reject(err)))
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
// Recursively check if dest parent is a subdirectory of src.
|
| 186 |
+
// It works for all file types including symlinks since it
|
| 187 |
+
// checks the src and dest inodes. It starts from the deepest
|
| 188 |
+
// parent and stops once it reaches the src parent or the root path.
|
| 189 |
+
async function checkParentPaths (src, srcStat, dest) {
|
| 190 |
+
const srcParent = resolve(dirname(src))
|
| 191 |
+
const destParent = resolve(dirname(dest))
|
| 192 |
+
if (destParent === srcParent || destParent === parse(destParent).root) {
|
| 193 |
+
return
|
| 194 |
+
}
|
| 195 |
+
let destStat
|
| 196 |
+
try {
|
| 197 |
+
destStat = await stat(destParent, { bigint: true })
|
| 198 |
+
} catch (err) {
|
| 199 |
+
// istanbul ignore else: not sure when this would occur
|
| 200 |
+
if (err.code === 'ENOENT') {
|
| 201 |
+
return
|
| 202 |
+
}
|
| 203 |
+
// istanbul ignore next: not sure when this would occur
|
| 204 |
+
throw err
|
| 205 |
+
}
|
| 206 |
+
if (areIdentical(srcStat, destStat)) {
|
| 207 |
+
throw new ERR_FS_CP_EINVAL({
|
| 208 |
+
message: `cannot copy ${src} to a subdirectory of self ${dest}`,
|
| 209 |
+
path: dest,
|
| 210 |
+
syscall: 'cp',
|
| 211 |
+
errno: EINVAL,
|
| 212 |
+
})
|
| 213 |
+
}
|
| 214 |
+
return checkParentPaths(src, srcStat, destParent)
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
const normalizePathToArray = (path) =>
|
| 218 |
+
resolve(path).split(sep).filter(Boolean)
|
| 219 |
+
|
| 220 |
+
// Return true if dest is a subdir of src, otherwise false.
|
| 221 |
+
// It only checks the path strings.
|
| 222 |
+
function isSrcSubdir (src, dest) {
|
| 223 |
+
const srcArr = normalizePathToArray(src)
|
| 224 |
+
const destArr = normalizePathToArray(dest)
|
| 225 |
+
return srcArr.every((cur, i) => destArr[i] === cur)
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
async function handleFilter (onInclude, destStat, src, dest, opts, cb) {
|
| 229 |
+
const include = await opts.filter(src, dest)
|
| 230 |
+
if (include) {
|
| 231 |
+
return onInclude(destStat, src, dest, opts, cb)
|
| 232 |
+
}
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
function startCopy (destStat, src, dest, opts) {
|
| 236 |
+
if (opts.filter) {
|
| 237 |
+
return handleFilter(getStatsForCopy, destStat, src, dest, opts)
|
| 238 |
+
}
|
| 239 |
+
return getStatsForCopy(destStat, src, dest, opts)
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
async function getStatsForCopy (destStat, src, dest, opts) {
|
| 243 |
+
const statFn = opts.dereference ? stat : lstat
|
| 244 |
+
const srcStat = await statFn(src)
|
| 245 |
+
// istanbul ignore else: can't portably test FIFO
|
| 246 |
+
if (srcStat.isDirectory() && opts.recursive) {
|
| 247 |
+
return onDir(srcStat, destStat, src, dest, opts)
|
| 248 |
+
} else if (srcStat.isDirectory()) {
|
| 249 |
+
throw new ERR_FS_EISDIR({
|
| 250 |
+
message: `${src} is a directory (not copied)`,
|
| 251 |
+
path: src,
|
| 252 |
+
syscall: 'cp',
|
| 253 |
+
errno: EINVAL,
|
| 254 |
+
})
|
| 255 |
+
} else if (srcStat.isFile() ||
|
| 256 |
+
srcStat.isCharacterDevice() ||
|
| 257 |
+
srcStat.isBlockDevice()) {
|
| 258 |
+
return onFile(srcStat, destStat, src, dest, opts)
|
| 259 |
+
} else if (srcStat.isSymbolicLink()) {
|
| 260 |
+
return onLink(destStat, src, dest)
|
| 261 |
+
} else if (srcStat.isSocket()) {
|
| 262 |
+
throw new ERR_FS_CP_SOCKET({
|
| 263 |
+
message: `cannot copy a socket file: ${dest}`,
|
| 264 |
+
path: dest,
|
| 265 |
+
syscall: 'cp',
|
| 266 |
+
errno: EINVAL,
|
| 267 |
+
})
|
| 268 |
+
} else if (srcStat.isFIFO()) {
|
| 269 |
+
throw new ERR_FS_CP_FIFO_PIPE({
|
| 270 |
+
message: `cannot copy a FIFO pipe: ${dest}`,
|
| 271 |
+
path: dest,
|
| 272 |
+
syscall: 'cp',
|
| 273 |
+
errno: EINVAL,
|
| 274 |
+
})
|
| 275 |
+
}
|
| 276 |
+
// istanbul ignore next: should be unreachable
|
| 277 |
+
throw new ERR_FS_CP_UNKNOWN({
|
| 278 |
+
message: `cannot copy an unknown file type: ${dest}`,
|
| 279 |
+
path: dest,
|
| 280 |
+
syscall: 'cp',
|
| 281 |
+
errno: EINVAL,
|
| 282 |
+
})
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
function onFile (srcStat, destStat, src, dest, opts) {
|
| 286 |
+
if (!destStat) {
|
| 287 |
+
return _copyFile(srcStat, src, dest, opts)
|
| 288 |
+
}
|
| 289 |
+
return mayCopyFile(srcStat, src, dest, opts)
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
async function mayCopyFile (srcStat, src, dest, opts) {
|
| 293 |
+
if (opts.force) {
|
| 294 |
+
await unlink(dest)
|
| 295 |
+
return _copyFile(srcStat, src, dest, opts)
|
| 296 |
+
} else if (opts.errorOnExist) {
|
| 297 |
+
throw new ERR_FS_CP_EEXIST({
|
| 298 |
+
message: `${dest} already exists`,
|
| 299 |
+
path: dest,
|
| 300 |
+
syscall: 'cp',
|
| 301 |
+
errno: EEXIST,
|
| 302 |
+
})
|
| 303 |
+
}
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
async function _copyFile (srcStat, src, dest, opts) {
|
| 307 |
+
await copyFile(src, dest)
|
| 308 |
+
if (opts.preserveTimestamps) {
|
| 309 |
+
return handleTimestampsAndMode(srcStat.mode, src, dest)
|
| 310 |
+
}
|
| 311 |
+
return setDestMode(dest, srcStat.mode)
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
async function handleTimestampsAndMode (srcMode, src, dest) {
|
| 315 |
+
// Make sure the file is writable before setting the timestamp
|
| 316 |
+
// otherwise open fails with EPERM when invoked with 'r+'
|
| 317 |
+
// (through utimes call)
|
| 318 |
+
if (fileIsNotWritable(srcMode)) {
|
| 319 |
+
await makeFileWritable(dest, srcMode)
|
| 320 |
+
return setDestTimestampsAndMode(srcMode, src, dest)
|
| 321 |
+
}
|
| 322 |
+
return setDestTimestampsAndMode(srcMode, src, dest)
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
function fileIsNotWritable (srcMode) {
|
| 326 |
+
return (srcMode & 0o200) === 0
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
function makeFileWritable (dest, srcMode) {
|
| 330 |
+
return setDestMode(dest, srcMode | 0o200)
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
async function setDestTimestampsAndMode (srcMode, src, dest) {
|
| 334 |
+
await setDestTimestamps(src, dest)
|
| 335 |
+
return setDestMode(dest, srcMode)
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
function setDestMode (dest, srcMode) {
|
| 339 |
+
return chmod(dest, srcMode)
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
async function setDestTimestamps (src, dest) {
|
| 343 |
+
// The initial srcStat.atime cannot be trusted
|
| 344 |
+
// because it is modified by the read(2) system call
|
| 345 |
+
// (See https://nodejs.org/api/fs.html#fs_stat_time_values)
|
| 346 |
+
const updatedSrcStat = await stat(src)
|
| 347 |
+
return utimes(dest, updatedSrcStat.atime, updatedSrcStat.mtime)
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
function onDir (srcStat, destStat, src, dest, opts) {
|
| 351 |
+
if (!destStat) {
|
| 352 |
+
return mkDirAndCopy(srcStat.mode, src, dest, opts)
|
| 353 |
+
}
|
| 354 |
+
return copyDir(src, dest, opts)
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
async function mkDirAndCopy (srcMode, src, dest, opts) {
|
| 358 |
+
await mkdir(dest)
|
| 359 |
+
await copyDir(src, dest, opts)
|
| 360 |
+
return setDestMode(dest, srcMode)
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
async function copyDir (src, dest, opts) {
|
| 364 |
+
const dir = await readdir(src)
|
| 365 |
+
for (let i = 0; i < dir.length; i++) {
|
| 366 |
+
const item = dir[i]
|
| 367 |
+
const srcItem = join(src, item)
|
| 368 |
+
const destItem = join(dest, item)
|
| 369 |
+
const { destStat } = await checkPaths(srcItem, destItem, opts)
|
| 370 |
+
await startCopy(destStat, srcItem, destItem, opts)
|
| 371 |
+
}
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
async function onLink (destStat, src, dest) {
|
| 375 |
+
let resolvedSrc = await readlink(src)
|
| 376 |
+
if (!isAbsolute(resolvedSrc)) {
|
| 377 |
+
resolvedSrc = resolve(dirname(src), resolvedSrc)
|
| 378 |
+
}
|
| 379 |
+
if (!destStat) {
|
| 380 |
+
return symlink(resolvedSrc, dest)
|
| 381 |
+
}
|
| 382 |
+
let resolvedDest
|
| 383 |
+
try {
|
| 384 |
+
resolvedDest = await readlink(dest)
|
| 385 |
+
} catch (err) {
|
| 386 |
+
// Dest exists and is a regular file or directory,
|
| 387 |
+
// Windows may throw UNKNOWN error. If dest already exists,
|
| 388 |
+
// fs throws error anyway, so no need to guard against it here.
|
| 389 |
+
// istanbul ignore next: can only test on windows
|
| 390 |
+
if (err.code === 'EINVAL' || err.code === 'UNKNOWN') {
|
| 391 |
+
return symlink(resolvedSrc, dest)
|
| 392 |
+
}
|
| 393 |
+
// istanbul ignore next: should not be possible
|
| 394 |
+
throw err
|
| 395 |
+
}
|
| 396 |
+
if (!isAbsolute(resolvedDest)) {
|
| 397 |
+
resolvedDest = resolve(dirname(dest), resolvedDest)
|
| 398 |
+
}
|
| 399 |
+
if (isSrcSubdir(resolvedSrc, resolvedDest)) {
|
| 400 |
+
throw new ERR_FS_CP_EINVAL({
|
| 401 |
+
message: `cannot copy ${resolvedSrc} to a subdirectory of self ` +
|
| 402 |
+
`${resolvedDest}`,
|
| 403 |
+
path: dest,
|
| 404 |
+
syscall: 'cp',
|
| 405 |
+
errno: EINVAL,
|
| 406 |
+
})
|
| 407 |
+
}
|
| 408 |
+
// Do not copy if src is a subdir of dest since unlinking
|
| 409 |
+
// dest in this case would result in removing src contents
|
| 410 |
+
// and therefore a broken symlink would be created.
|
| 411 |
+
const srcStat = await stat(src)
|
| 412 |
+
if (srcStat.isDirectory() && isSrcSubdir(resolvedDest, resolvedSrc)) {
|
| 413 |
+
throw new ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY({
|
| 414 |
+
message: `cannot overwrite ${resolvedDest} with ${resolvedSrc}`,
|
| 415 |
+
path: dest,
|
| 416 |
+
syscall: 'cp',
|
| 417 |
+
errno: EINVAL,
|
| 418 |
+
})
|
| 419 |
+
}
|
| 420 |
+
return copyLink(resolvedSrc, dest)
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
async function copyLink (resolvedSrc, dest) {
|
| 424 |
+
await unlink(dest)
|
| 425 |
+
return symlink(resolvedSrc, dest)
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
module.exports = cp
|
node/node_modules/npm/node_modules/@npmcli/fs/lib/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const cp = require('./cp/index.js')
|
| 4 |
+
const withTempDir = require('./with-temp-dir.js')
|
| 5 |
+
const readdirScoped = require('./readdir-scoped.js')
|
| 6 |
+
const moveFile = require('./move-file.js')
|
| 7 |
+
|
| 8 |
+
module.exports = {
|
| 9 |
+
cp,
|
| 10 |
+
withTempDir,
|
| 11 |
+
readdirScoped,
|
| 12 |
+
moveFile,
|
| 13 |
+
}
|
node/node_modules/npm/node_modules/@npmcli/fs/lib/move-file.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const { dirname, join, resolve, relative, isAbsolute } = require('path')
|
| 2 |
+
const fs = require('fs/promises')
|
| 3 |
+
|
| 4 |
+
const pathExists = async path => {
|
| 5 |
+
try {
|
| 6 |
+
await fs.access(path)
|
| 7 |
+
return true
|
| 8 |
+
} catch (er) {
|
| 9 |
+
return er.code !== 'ENOENT'
|
| 10 |
+
}
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
const moveFile = async (source, destination, options = {}, root = true, symlinks = []) => {
|
| 14 |
+
if (!source || !destination) {
|
| 15 |
+
throw new TypeError('`source` and `destination` file required')
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
options = {
|
| 19 |
+
overwrite: true,
|
| 20 |
+
...options,
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
if (!options.overwrite && await pathExists(destination)) {
|
| 24 |
+
throw new Error(`The destination file exists: ${destination}`)
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
await fs.mkdir(dirname(destination), { recursive: true })
|
| 28 |
+
|
| 29 |
+
try {
|
| 30 |
+
await fs.rename(source, destination)
|
| 31 |
+
} catch (error) {
|
| 32 |
+
if (error.code === 'EXDEV' || error.code === 'EPERM') {
|
| 33 |
+
const sourceStat = await fs.lstat(source)
|
| 34 |
+
if (sourceStat.isDirectory()) {
|
| 35 |
+
const files = await fs.readdir(source)
|
| 36 |
+
await Promise.all(files.map((file) =>
|
| 37 |
+
moveFile(join(source, file), join(destination, file), options, false, symlinks)
|
| 38 |
+
))
|
| 39 |
+
} else if (sourceStat.isSymbolicLink()) {
|
| 40 |
+
symlinks.push({ source, destination })
|
| 41 |
+
} else {
|
| 42 |
+
await fs.copyFile(source, destination)
|
| 43 |
+
}
|
| 44 |
+
} else {
|
| 45 |
+
throw error
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
if (root) {
|
| 50 |
+
await Promise.all(symlinks.map(async ({ source: symSource, destination: symDestination }) => {
|
| 51 |
+
let target = await fs.readlink(symSource)
|
| 52 |
+
// junction symlinks in windows will be absolute paths, so we need to
|
| 53 |
+
// make sure they point to the symlink destination
|
| 54 |
+
if (isAbsolute(target)) {
|
| 55 |
+
target = resolve(symDestination, relative(symSource, target))
|
| 56 |
+
}
|
| 57 |
+
// try to determine what the actual file is so we can create the correct
|
| 58 |
+
// type of symlink in windows
|
| 59 |
+
let targetStat = 'file'
|
| 60 |
+
try {
|
| 61 |
+
targetStat = await fs.stat(resolve(dirname(symSource), target))
|
| 62 |
+
if (targetStat.isDirectory()) {
|
| 63 |
+
targetStat = 'junction'
|
| 64 |
+
}
|
| 65 |
+
} catch {
|
| 66 |
+
// targetStat remains 'file'
|
| 67 |
+
}
|
| 68 |
+
await fs.symlink(
|
| 69 |
+
target,
|
| 70 |
+
symDestination,
|
| 71 |
+
targetStat
|
| 72 |
+
)
|
| 73 |
+
}))
|
| 74 |
+
await fs.rm(source, { recursive: true, force: true })
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
module.exports = moveFile
|
node/node_modules/npm/node_modules/@npmcli/fs/lib/readdir-scoped.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const { readdir } = require('fs/promises')
|
| 2 |
+
const { join } = require('path')
|
| 3 |
+
|
| 4 |
+
const readdirScoped = async (dir) => {
|
| 5 |
+
const results = []
|
| 6 |
+
|
| 7 |
+
for (const item of await readdir(dir)) {
|
| 8 |
+
if (item.startsWith('@')) {
|
| 9 |
+
for (const scopedItem of await readdir(join(dir, item))) {
|
| 10 |
+
results.push(join(item, scopedItem))
|
| 11 |
+
}
|
| 12 |
+
} else {
|
| 13 |
+
results.push(item)
|
| 14 |
+
}
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
return results
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
module.exports = readdirScoped
|
node/node_modules/npm/node_modules/@npmcli/fs/lib/with-temp-dir.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const { join, sep } = require('path')
|
| 2 |
+
|
| 3 |
+
const getOptions = require('./common/get-options.js')
|
| 4 |
+
const { mkdir, mkdtemp, rm } = require('fs/promises')
|
| 5 |
+
|
| 6 |
+
// create a temp directory, ensure its permissions match its parent, then call
|
| 7 |
+
// the supplied function passing it the path to the directory. clean up after
|
| 8 |
+
// the function finishes, whether it throws or not
|
| 9 |
+
const withTempDir = async (root, fn, opts) => {
|
| 10 |
+
const options = getOptions(opts, {
|
| 11 |
+
copy: ['tmpPrefix'],
|
| 12 |
+
})
|
| 13 |
+
// create the directory
|
| 14 |
+
await mkdir(root, { recursive: true })
|
| 15 |
+
|
| 16 |
+
const target = await mkdtemp(join(`${root}${sep}`, options.tmpPrefix || ''))
|
| 17 |
+
let err
|
| 18 |
+
let result
|
| 19 |
+
|
| 20 |
+
try {
|
| 21 |
+
result = await fn(target)
|
| 22 |
+
} catch (_err) {
|
| 23 |
+
err = _err
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
try {
|
| 27 |
+
await rm(target, { force: true, recursive: true })
|
| 28 |
+
} catch {
|
| 29 |
+
// ignore errors
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
if (err) {
|
| 33 |
+
throw err
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
return result
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
module.exports = withTempDir
|
node/node_modules/npm/node_modules/@npmcli/fs/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@npmcli/fs",
|
| 3 |
+
"version": "5.0.0",
|
| 4 |
+
"description": "filesystem utilities for the npm cli",
|
| 5 |
+
"main": "lib/index.js",
|
| 6 |
+
"files": [
|
| 7 |
+
"bin/",
|
| 8 |
+
"lib/"
|
| 9 |
+
],
|
| 10 |
+
"scripts": {
|
| 11 |
+
"snap": "tap",
|
| 12 |
+
"test": "tap",
|
| 13 |
+
"npmclilint": "npmcli-lint",
|
| 14 |
+
"lint": "npm run eslint",
|
| 15 |
+
"lintfix": "npm run eslint -- --fix",
|
| 16 |
+
"posttest": "npm run lint",
|
| 17 |
+
"postsnap": "npm run lintfix --",
|
| 18 |
+
"postlint": "template-oss-check",
|
| 19 |
+
"template-oss-apply": "template-oss-apply --force",
|
| 20 |
+
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
|
| 21 |
+
},
|
| 22 |
+
"repository": {
|
| 23 |
+
"type": "git",
|
| 24 |
+
"url": "git+https://github.com/npm/fs.git"
|
| 25 |
+
},
|
| 26 |
+
"keywords": [
|
| 27 |
+
"npm",
|
| 28 |
+
"oss"
|
| 29 |
+
],
|
| 30 |
+
"author": "GitHub Inc.",
|
| 31 |
+
"license": "ISC",
|
| 32 |
+
"devDependencies": {
|
| 33 |
+
"@npmcli/eslint-config": "^5.0.0",
|
| 34 |
+
"@npmcli/template-oss": "4.27.1",
|
| 35 |
+
"tap": "^16.0.1"
|
| 36 |
+
},
|
| 37 |
+
"dependencies": {
|
| 38 |
+
"semver": "^7.3.5"
|
| 39 |
+
},
|
| 40 |
+
"engines": {
|
| 41 |
+
"node": "^20.17.0 || >=22.9.0"
|
| 42 |
+
},
|
| 43 |
+
"templateOSS": {
|
| 44 |
+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
| 45 |
+
"version": "4.27.1",
|
| 46 |
+
"publish": true
|
| 47 |
+
},
|
| 48 |
+
"tap": {
|
| 49 |
+
"nyc-arg": [
|
| 50 |
+
"--exclude",
|
| 51 |
+
"tap-snapshots/**"
|
| 52 |
+
]
|
| 53 |
+
}
|
| 54 |
+
}
|
node/node_modules/npm/node_modules/@npmcli/git/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The ISC License
|
| 2 |
+
|
| 3 |
+
Copyright (c) npm, Inc.
|
| 4 |
+
|
| 5 |
+
Permission to use, copy, modify, and/or distribute this software for any
|
| 6 |
+
purpose with or without fee is hereby granted, provided that the above
|
| 7 |
+
copyright notice and this permission notice appear in all copies.
|
| 8 |
+
|
| 9 |
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE NPM DISCLAIMS ALL WARRANTIES WITH
|
| 10 |
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
| 11 |
+
FITNESS. IN NO EVENT SHALL THE NPM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
|
| 12 |
+
OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
| 13 |
+
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
| 14 |
+
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
| 15 |
+
SOFTWARE.
|
node/node_modules/npm/node_modules/@npmcli/git/lib/clone.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// The goal here is to minimize both git workload and
|
| 2 |
+
// the number of refs we download over the network.
|
| 3 |
+
//
|
| 4 |
+
// Every method ends up with the checked out working dir
|
| 5 |
+
// at the specified ref, and resolves with the git sha.
|
| 6 |
+
|
| 7 |
+
// Only certain whitelisted hosts get shallow cloning.
|
| 8 |
+
// Many hosts (including GHE) don't always support it.
|
| 9 |
+
// A failed shallow fetch takes a LOT longer than a full
|
| 10 |
+
// fetch in most cases, so we skip it entirely.
|
| 11 |
+
// Set opts.gitShallow = true/false to force this behavior
|
| 12 |
+
// one way or the other.
|
| 13 |
+
const shallowHosts = new Set([
|
| 14 |
+
'github.com',
|
| 15 |
+
'gist.github.com',
|
| 16 |
+
'gitlab.com',
|
| 17 |
+
'bitbucket.com',
|
| 18 |
+
'bitbucket.org',
|
| 19 |
+
])
|
| 20 |
+
// we have to use url.parse until we add the same shim that hosted-git-info has
|
| 21 |
+
// to handle scp:// urls
|
| 22 |
+
const { parse } = require('url') // eslint-disable-line node/no-deprecated-api
|
| 23 |
+
const path = require('path')
|
| 24 |
+
|
| 25 |
+
const getRevs = require('./revs.js')
|
| 26 |
+
const spawn = require('./spawn.js')
|
| 27 |
+
const { isWindows } = require('./utils.js')
|
| 28 |
+
|
| 29 |
+
const pickManifest = require('npm-pick-manifest')
|
| 30 |
+
const fs = require('fs/promises')
|
| 31 |
+
|
| 32 |
+
module.exports = (repo, ref = 'HEAD', target = null, opts = {}) =>
|
| 33 |
+
getRevs(repo, opts).then(revs => clone(
|
| 34 |
+
repo,
|
| 35 |
+
revs,
|
| 36 |
+
ref,
|
| 37 |
+
resolveRef(revs, ref, opts),
|
| 38 |
+
target || defaultTarget(repo, opts.cwd),
|
| 39 |
+
opts
|
| 40 |
+
))
|
| 41 |
+
|
| 42 |
+
const maybeShallow = (repo, opts) => {
|
| 43 |
+
if (opts.gitShallow === false || opts.gitShallow) {
|
| 44 |
+
return opts.gitShallow
|
| 45 |
+
}
|
| 46 |
+
return shallowHosts.has(parse(repo).host)
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
const defaultTarget = (repo, /* istanbul ignore next */ cwd = process.cwd()) =>
|
| 50 |
+
path.resolve(cwd, path.basename(repo.replace(/[/\\]?\.git$/, '')))
|
| 51 |
+
|
| 52 |
+
const clone = (repo, revs, ref, revDoc, target, opts) => {
|
| 53 |
+
if (!revDoc) {
|
| 54 |
+
return unresolved(repo, ref, target, opts)
|
| 55 |
+
}
|
| 56 |
+
if (revDoc.sha === revs.refs.HEAD.sha) {
|
| 57 |
+
return plain(repo, revDoc, target, opts)
|
| 58 |
+
}
|
| 59 |
+
if (revDoc.type === 'tag' || revDoc.type === 'branch') {
|
| 60 |
+
return branch(repo, revDoc, target, opts)
|
| 61 |
+
}
|
| 62 |
+
return other(repo, revDoc, target, opts)
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
const resolveRef = (revs, ref, opts) => {
|
| 66 |
+
const { spec = {} } = opts
|
| 67 |
+
ref = spec.gitCommittish || ref
|
| 68 |
+
/* istanbul ignore next - will fail anyway, can't pull */
|
| 69 |
+
if (!revs) {
|
| 70 |
+
return null
|
| 71 |
+
}
|
| 72 |
+
if (spec.gitRange) {
|
| 73 |
+
return pickManifest(revs, spec.gitRange, opts)
|
| 74 |
+
}
|
| 75 |
+
if (!ref) {
|
| 76 |
+
return revs.refs.HEAD
|
| 77 |
+
}
|
| 78 |
+
if (revs.refs[ref]) {
|
| 79 |
+
return revs.refs[ref]
|
| 80 |
+
}
|
| 81 |
+
if (revs.shas[ref]) {
|
| 82 |
+
return revs.refs[revs.shas[ref][0]]
|
| 83 |
+
}
|
| 84 |
+
return null
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
// pull request or some other kind of advertised ref
|
| 88 |
+
const other = (repo, revDoc, target, opts) => {
|
| 89 |
+
const shallow = maybeShallow(repo, opts)
|
| 90 |
+
|
| 91 |
+
const fetchOrigin = ['fetch', 'origin', revDoc.rawRef]
|
| 92 |
+
.concat(shallow ? ['--depth=1'] : [])
|
| 93 |
+
|
| 94 |
+
const git = (args) => spawn(args, { ...opts, cwd: target })
|
| 95 |
+
return fs.mkdir(target, { recursive: true })
|
| 96 |
+
.then(() => git(['init']))
|
| 97 |
+
.then(() => isWindows(opts)
|
| 98 |
+
? git(['config', '--local', '--add', 'core.longpaths', 'true'])
|
| 99 |
+
: null)
|
| 100 |
+
.then(() => git(['remote', 'add', 'origin', repo]))
|
| 101 |
+
.then(() => git(fetchOrigin))
|
| 102 |
+
.then(() => git(['checkout', revDoc.sha]))
|
| 103 |
+
.then(() => updateSubmodules(target, opts))
|
| 104 |
+
.then(() => revDoc.sha)
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
// tag or branches. use -b
|
| 108 |
+
const branch = (repo, revDoc, target, opts) => {
|
| 109 |
+
const args = [
|
| 110 |
+
'clone',
|
| 111 |
+
'-b',
|
| 112 |
+
revDoc.ref,
|
| 113 |
+
repo,
|
| 114 |
+
target,
|
| 115 |
+
'--recurse-submodules',
|
| 116 |
+
]
|
| 117 |
+
if (maybeShallow(repo, opts)) {
|
| 118 |
+
args.push('--depth=1')
|
| 119 |
+
}
|
| 120 |
+
if (isWindows(opts)) {
|
| 121 |
+
args.push('--config', 'core.longpaths=true')
|
| 122 |
+
}
|
| 123 |
+
return spawn(args, opts).then(() => revDoc.sha)
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
// just the head. clone it
|
| 127 |
+
const plain = (repo, revDoc, target, opts) => {
|
| 128 |
+
const args = [
|
| 129 |
+
'clone',
|
| 130 |
+
repo,
|
| 131 |
+
target,
|
| 132 |
+
'--recurse-submodules',
|
| 133 |
+
]
|
| 134 |
+
if (maybeShallow(repo, opts)) {
|
| 135 |
+
args.push('--depth=1')
|
| 136 |
+
}
|
| 137 |
+
if (isWindows(opts)) {
|
| 138 |
+
args.push('--config', 'core.longpaths=true')
|
| 139 |
+
}
|
| 140 |
+
return spawn(args, opts).then(() => revDoc.sha)
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
const updateSubmodules = async (target, opts) => {
|
| 144 |
+
const hasSubmodules = await fs.stat(`${target}/.gitmodules`)
|
| 145 |
+
.then(() => true)
|
| 146 |
+
.catch(() => false)
|
| 147 |
+
if (!hasSubmodules) {
|
| 148 |
+
return null
|
| 149 |
+
}
|
| 150 |
+
return spawn([
|
| 151 |
+
'submodule',
|
| 152 |
+
'update',
|
| 153 |
+
'-q',
|
| 154 |
+
'--init',
|
| 155 |
+
'--recursive',
|
| 156 |
+
], { ...opts, cwd: target })
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
const unresolved = (repo, ref, target, opts) => {
|
| 160 |
+
// can't do this one shallowly, because the ref isn't advertised
|
| 161 |
+
// but we can avoid checking out the working dir twice, at least
|
| 162 |
+
const lp = isWindows(opts) ? ['--config', 'core.longpaths=true'] : []
|
| 163 |
+
const cloneArgs = ['clone', '--mirror', '-q', repo, target + '/.git']
|
| 164 |
+
const git = (args) => spawn(args, { ...opts, cwd: target })
|
| 165 |
+
return fs.mkdir(target, { recursive: true })
|
| 166 |
+
.then(() => git(cloneArgs.concat(lp)))
|
| 167 |
+
.then(() => git(['init']))
|
| 168 |
+
.then(() => git(['checkout', ref]))
|
| 169 |
+
.then(() => updateSubmodules(target, opts))
|
| 170 |
+
.then(() => git(['rev-parse', '--revs-only', 'HEAD']))
|
| 171 |
+
.then(({ stdout }) => stdout.trim())
|
| 172 |
+
}
|
node/node_modules/npm/node_modules/@npmcli/git/lib/errors.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
const maxRetry = 3
|
| 3 |
+
|
| 4 |
+
class GitError extends Error {
|
| 5 |
+
shouldRetry () {
|
| 6 |
+
return false
|
| 7 |
+
}
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
class GitConnectionError extends GitError {
|
| 11 |
+
constructor () {
|
| 12 |
+
super('A git connection error occurred')
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
shouldRetry (number) {
|
| 16 |
+
return number < maxRetry
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
class GitPathspecError extends GitError {
|
| 21 |
+
constructor () {
|
| 22 |
+
super('The git reference could not be found')
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
class GitUnknownError extends GitError {
|
| 27 |
+
constructor () {
|
| 28 |
+
super('An unknown git error occurred')
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
module.exports = {
|
| 33 |
+
GitConnectionError,
|
| 34 |
+
GitPathspecError,
|
| 35 |
+
GitUnknownError,
|
| 36 |
+
}
|
node/node_modules/npm/node_modules/@npmcli/git/lib/find.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const is = require('./is.js')
|
| 2 |
+
const { dirname } = require('path')
|
| 3 |
+
|
| 4 |
+
module.exports = async ({ cwd = process.cwd(), root } = {}) => {
|
| 5 |
+
while (true) {
|
| 6 |
+
if (await is({ cwd })) {
|
| 7 |
+
return cwd
|
| 8 |
+
}
|
| 9 |
+
const next = dirname(cwd)
|
| 10 |
+
if (cwd === root || cwd === next) {
|
| 11 |
+
return null
|
| 12 |
+
}
|
| 13 |
+
cwd = next
|
| 14 |
+
}
|
| 15 |
+
}
|
node/node_modules/npm/node_modules/@npmcli/git/lib/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module.exports = {
|
| 2 |
+
clone: require('./clone.js'),
|
| 3 |
+
revs: require('./revs.js'),
|
| 4 |
+
spawn: require('./spawn.js'),
|
| 5 |
+
is: require('./is.js'),
|
| 6 |
+
find: require('./find.js'),
|
| 7 |
+
isClean: require('./is-clean.js'),
|
| 8 |
+
errors: require('./errors.js'),
|
| 9 |
+
}
|
node/node_modules/npm/node_modules/@npmcli/git/lib/is-clean.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const spawn = require('./spawn.js')
|
| 2 |
+
|
| 3 |
+
module.exports = (opts = {}) =>
|
| 4 |
+
spawn(['status', '--porcelain=v1', '-uno'], opts)
|
| 5 |
+
.then(res => !res.stdout.trim().split(/\r?\n+/)
|
| 6 |
+
.map(l => l.trim()).filter(l => l).length)
|
node/node_modules/npm/node_modules/@npmcli/git/lib/is.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// not an airtight indicator, but a good gut-check to even bother trying
|
| 2 |
+
const { stat } = require('fs/promises')
|
| 3 |
+
module.exports = ({ cwd = process.cwd() } = {}) =>
|
| 4 |
+
stat(cwd + '/.git').then(() => true, () => false)
|
node/node_modules/npm/node_modules/@npmcli/git/lib/lines-to-revs.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// turn an array of lines from `git ls-remote` into a thing
|
| 2 |
+
// vaguely resembling a packument, where docs are a resolved ref
|
| 3 |
+
|
| 4 |
+
const semver = require('semver')
|
| 5 |
+
|
| 6 |
+
module.exports = lines => finish(lines.reduce(linesToRevsReducer, {
|
| 7 |
+
versions: {},
|
| 8 |
+
'dist-tags': {},
|
| 9 |
+
refs: {},
|
| 10 |
+
shas: {},
|
| 11 |
+
}))
|
| 12 |
+
|
| 13 |
+
const finish = revs => distTags(shaList(peelTags(revs)))
|
| 14 |
+
|
| 15 |
+
// We can check out shallow clones on specific SHAs if we have a ref
|
| 16 |
+
const shaList = revs => {
|
| 17 |
+
Object.keys(revs.refs).forEach(ref => {
|
| 18 |
+
const doc = revs.refs[ref]
|
| 19 |
+
if (!revs.shas[doc.sha]) {
|
| 20 |
+
revs.shas[doc.sha] = [ref]
|
| 21 |
+
} else {
|
| 22 |
+
revs.shas[doc.sha].push(ref)
|
| 23 |
+
}
|
| 24 |
+
})
|
| 25 |
+
return revs
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
// Replace any tags with their ^{} counterparts, if those exist
|
| 29 |
+
const peelTags = revs => {
|
| 30 |
+
Object.keys(revs.refs).filter(ref => ref.endsWith('^{}')).forEach(ref => {
|
| 31 |
+
const peeled = revs.refs[ref]
|
| 32 |
+
const unpeeled = revs.refs[ref.replace(/\^\{\}$/, '')]
|
| 33 |
+
if (unpeeled) {
|
| 34 |
+
unpeeled.sha = peeled.sha
|
| 35 |
+
delete revs.refs[ref]
|
| 36 |
+
}
|
| 37 |
+
})
|
| 38 |
+
return revs
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
const distTags = revs => {
|
| 42 |
+
// not entirely sure what situations would result in an
|
| 43 |
+
// ichabod repo, but best to be careful in Sleepy Hollow anyway
|
| 44 |
+
const HEAD = revs.refs.HEAD || /* istanbul ignore next */ {}
|
| 45 |
+
const versions = Object.keys(revs.versions)
|
| 46 |
+
versions.forEach(v => {
|
| 47 |
+
// simulate a dist-tags with latest pointing at the
|
| 48 |
+
// 'latest' branch if one exists and is a version,
|
| 49 |
+
// or HEAD if not.
|
| 50 |
+
const ver = revs.versions[v]
|
| 51 |
+
if (revs.refs.latest && ver.sha === revs.refs.latest.sha) {
|
| 52 |
+
revs['dist-tags'].latest = v
|
| 53 |
+
} else if (ver.sha === HEAD.sha) {
|
| 54 |
+
revs['dist-tags'].HEAD = v
|
| 55 |
+
if (!revs.refs.latest) {
|
| 56 |
+
revs['dist-tags'].latest = v
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
})
|
| 60 |
+
return revs
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
const refType = ref => {
|
| 64 |
+
if (ref.startsWith('refs/tags/')) {
|
| 65 |
+
return 'tag'
|
| 66 |
+
}
|
| 67 |
+
if (ref.startsWith('refs/heads/')) {
|
| 68 |
+
return 'branch'
|
| 69 |
+
}
|
| 70 |
+
if (ref.startsWith('refs/pull/')) {
|
| 71 |
+
return 'pull'
|
| 72 |
+
}
|
| 73 |
+
if (ref === 'HEAD') {
|
| 74 |
+
return 'head'
|
| 75 |
+
}
|
| 76 |
+
// Could be anything, ignore for now
|
| 77 |
+
/* istanbul ignore next */
|
| 78 |
+
return 'other'
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
// return the doc, or null if we should ignore it.
|
| 82 |
+
const lineToRevDoc = line => {
|
| 83 |
+
const split = line.trim().split(/\s+/, 2)
|
| 84 |
+
if (split.length < 2) {
|
| 85 |
+
return null
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
const sha = split[0].trim()
|
| 89 |
+
const rawRef = split[1].trim()
|
| 90 |
+
const type = refType(rawRef)
|
| 91 |
+
|
| 92 |
+
if (type === 'tag') {
|
| 93 |
+
// refs/tags/foo^{} is the 'peeled tag', ie the commit
|
| 94 |
+
// that is tagged by refs/tags/foo they resolve to the same
|
| 95 |
+
// content, just different objects in git's data structure.
|
| 96 |
+
// But, we care about the thing the tag POINTS to, not the tag
|
| 97 |
+
// object itself, so we only look at the peeled tag refs, and
|
| 98 |
+
// ignore the pointer.
|
| 99 |
+
// For now, though, we have to save both, because some tags
|
| 100 |
+
// don't have peels, if they were not annotated.
|
| 101 |
+
const ref = rawRef.slice('refs/tags/'.length)
|
| 102 |
+
return { sha, ref, rawRef, type }
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
if (type === 'branch') {
|
| 106 |
+
const ref = rawRef.slice('refs/heads/'.length)
|
| 107 |
+
return { sha, ref, rawRef, type }
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
if (type === 'pull') {
|
| 111 |
+
// NB: merged pull requests installable with #pull/123/merge
|
| 112 |
+
// for the merged pr, or #pull/123 for the PR head
|
| 113 |
+
const ref = rawRef.slice('refs/'.length).replace(/\/head$/, '')
|
| 114 |
+
return { sha, ref, rawRef, type }
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
if (type === 'head') {
|
| 118 |
+
const ref = 'HEAD'
|
| 119 |
+
return { sha, ref, rawRef, type }
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
// at this point, all we can do is leave the ref un-munged
|
| 123 |
+
return { sha, ref: rawRef, rawRef, type }
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
const linesToRevsReducer = (revs, line) => {
|
| 127 |
+
const doc = lineToRevDoc(line)
|
| 128 |
+
|
| 129 |
+
if (!doc) {
|
| 130 |
+
return revs
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
revs.refs[doc.ref] = doc
|
| 134 |
+
revs.refs[doc.rawRef] = doc
|
| 135 |
+
|
| 136 |
+
if (doc.type === 'tag') {
|
| 137 |
+
// try to pull a semver value out of tags like `release-v1.2.3`
|
| 138 |
+
// which is a pretty common pattern.
|
| 139 |
+
const match = !doc.ref.endsWith('^{}') &&
|
| 140 |
+
doc.ref.match(/v?(\d+\.\d+\.\d+(?:[-+].+)?)$/)
|
| 141 |
+
if (match && semver.valid(match[1], true)) {
|
| 142 |
+
revs.versions[semver.clean(match[1], true)] = doc
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
return revs
|
| 147 |
+
}
|
node/node_modules/npm/node_modules/@npmcli/git/lib/make-error.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const {
|
| 2 |
+
GitConnectionError,
|
| 3 |
+
GitPathspecError,
|
| 4 |
+
GitUnknownError,
|
| 5 |
+
} = require('./errors.js')
|
| 6 |
+
|
| 7 |
+
const connectionErrorRe = new RegExp([
|
| 8 |
+
'remote error: Internal Server Error',
|
| 9 |
+
'The remote end hung up unexpectedly',
|
| 10 |
+
'Connection timed out',
|
| 11 |
+
'Operation timed out',
|
| 12 |
+
'Failed to connect to .* Timed out',
|
| 13 |
+
'Connection reset by peer',
|
| 14 |
+
'SSL_ERROR_SYSCALL',
|
| 15 |
+
'The requested URL returned error: 503',
|
| 16 |
+
].join('|'))
|
| 17 |
+
|
| 18 |
+
const missingPathspecRe = /pathspec .* did not match any file\(s\) known to git/
|
| 19 |
+
|
| 20 |
+
function makeError (er) {
|
| 21 |
+
const message = er.stderr
|
| 22 |
+
let gitEr
|
| 23 |
+
if (connectionErrorRe.test(message)) {
|
| 24 |
+
gitEr = new GitConnectionError(message)
|
| 25 |
+
} else if (missingPathspecRe.test(message)) {
|
| 26 |
+
gitEr = new GitPathspecError(message)
|
| 27 |
+
} else {
|
| 28 |
+
gitEr = new GitUnknownError(message)
|
| 29 |
+
}
|
| 30 |
+
return Object.assign(gitEr, er)
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
module.exports = makeError
|
node/node_modules/npm/node_modules/@npmcli/git/lib/opts.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const fs = require('node:fs')
|
| 2 |
+
const os = require('node:os')
|
| 3 |
+
const path = require('node:path')
|
| 4 |
+
const ini = require('ini')
|
| 5 |
+
|
| 6 |
+
const gitConfigPath = path.join(os.homedir(), '.gitconfig')
|
| 7 |
+
|
| 8 |
+
let cachedConfig = null
|
| 9 |
+
|
| 10 |
+
// Function to load and cache the git config
|
| 11 |
+
const loadGitConfig = () => {
|
| 12 |
+
if (cachedConfig === null) {
|
| 13 |
+
try {
|
| 14 |
+
cachedConfig = {}
|
| 15 |
+
if (fs.existsSync(gitConfigPath)) {
|
| 16 |
+
const configContent = fs.readFileSync(gitConfigPath, 'utf-8')
|
| 17 |
+
cachedConfig = ini.parse(configContent)
|
| 18 |
+
}
|
| 19 |
+
} catch (error) {
|
| 20 |
+
cachedConfig = {}
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
return cachedConfig
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
const checkGitConfigs = () => {
|
| 27 |
+
const config = loadGitConfig()
|
| 28 |
+
return {
|
| 29 |
+
sshCommandSetInConfig: config?.core?.sshCommand !== undefined,
|
| 30 |
+
askPassSetInConfig: config?.core?.askpass !== undefined,
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
const sshCommandSetInEnv = process.env.GIT_SSH_COMMAND !== undefined
|
| 35 |
+
const askPassSetInEnv = process.env.GIT_ASKPASS !== undefined
|
| 36 |
+
const { sshCommandSetInConfig, askPassSetInConfig } = checkGitConfigs()
|
| 37 |
+
|
| 38 |
+
// Values we want to set if they're not already defined by the end user
|
| 39 |
+
// This defaults to accepting new ssh host key fingerprints
|
| 40 |
+
const finalGitEnv = {
|
| 41 |
+
...(askPassSetInEnv || askPassSetInConfig ? {} : {
|
| 42 |
+
GIT_ASKPASS: 'echo',
|
| 43 |
+
}),
|
| 44 |
+
...(sshCommandSetInEnv || sshCommandSetInConfig ? {} : {
|
| 45 |
+
GIT_SSH_COMMAND: 'ssh -oStrictHostKeyChecking=accept-new',
|
| 46 |
+
}),
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
module.exports = (opts = {}) => ({
|
| 50 |
+
stdioString: true,
|
| 51 |
+
...opts,
|
| 52 |
+
shell: false,
|
| 53 |
+
env: opts.env || { ...finalGitEnv, ...process.env },
|
| 54 |
+
})
|
| 55 |
+
|
| 56 |
+
// Export the loadGitConfig function for testing
|
| 57 |
+
module.exports.loadGitConfig = loadGitConfig
|
node/node_modules/npm/node_modules/@npmcli/git/lib/revs.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const spawn = require('./spawn.js')
|
| 2 |
+
const { LRUCache } = require('lru-cache')
|
| 3 |
+
const linesToRevs = require('./lines-to-revs.js')
|
| 4 |
+
|
| 5 |
+
const revsCache = new LRUCache({
|
| 6 |
+
max: 100,
|
| 7 |
+
ttl: 5 * 60 * 1000,
|
| 8 |
+
})
|
| 9 |
+
|
| 10 |
+
module.exports = async (repo, opts = {}) => {
|
| 11 |
+
if (!opts.noGitRevCache) {
|
| 12 |
+
const cached = revsCache.get(repo)
|
| 13 |
+
if (cached) {
|
| 14 |
+
return cached
|
| 15 |
+
}
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
const { stdout } = await spawn(['ls-remote', repo], opts)
|
| 19 |
+
const revs = linesToRevs(stdout.trim().split('\n'))
|
| 20 |
+
revsCache.set(repo, revs)
|
| 21 |
+
return revs
|
| 22 |
+
}
|
node/node_modules/npm/node_modules/@npmcli/git/lib/spawn.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const spawn = require('@npmcli/promise-spawn')
|
| 2 |
+
const { promiseRetry } = require('@gar/promise-retry')
|
| 3 |
+
const { log } = require('proc-log')
|
| 4 |
+
const makeError = require('./make-error.js')
|
| 5 |
+
const makeOpts = require('./opts.js')
|
| 6 |
+
|
| 7 |
+
module.exports = (gitArgs, opts = {}) => {
|
| 8 |
+
const whichGit = require('./which.js')
|
| 9 |
+
const gitPath = whichGit(opts)
|
| 10 |
+
|
| 11 |
+
if (gitPath instanceof Error) {
|
| 12 |
+
return Promise.reject(gitPath)
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
// undocumented option, mostly only here for tests
|
| 16 |
+
const args = opts.allowReplace || gitArgs[0] === '--no-replace-objects'
|
| 17 |
+
? gitArgs
|
| 18 |
+
: ['--no-replace-objects', ...gitArgs]
|
| 19 |
+
|
| 20 |
+
let retryOpts = opts.retry
|
| 21 |
+
if (retryOpts === null || retryOpts === undefined) {
|
| 22 |
+
retryOpts = {
|
| 23 |
+
retries: opts.fetchRetries || 2,
|
| 24 |
+
factor: opts.fetchRetryFactor || 10,
|
| 25 |
+
maxTimeout: opts.fetchRetryMaxtimeout || 60000,
|
| 26 |
+
minTimeout: opts.fetchRetryMintimeout || 1000,
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
return promiseRetry((retryFn, number) => {
|
| 30 |
+
if (number !== 1) {
|
| 31 |
+
log.silly('git', `Retrying git command: ${
|
| 32 |
+
args.join(' ')} attempt # ${number}`)
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
return spawn(gitPath, args, makeOpts(opts))
|
| 36 |
+
.catch(er => {
|
| 37 |
+
const gitError = makeError(er)
|
| 38 |
+
if (!gitError.shouldRetry(number)) {
|
| 39 |
+
throw gitError
|
| 40 |
+
}
|
| 41 |
+
retryFn(gitError)
|
| 42 |
+
})
|
| 43 |
+
}, retryOpts)
|
| 44 |
+
}
|
node/node_modules/npm/node_modules/@npmcli/git/lib/utils.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const isWindows = opts => (opts.fakePlatform || process.platform) === 'win32'
|
| 2 |
+
|
| 3 |
+
exports.isWindows = isWindows
|
node/node_modules/npm/node_modules/@npmcli/git/lib/which.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const which = require('which')
|
| 2 |
+
|
| 3 |
+
let gitPath
|
| 4 |
+
try {
|
| 5 |
+
gitPath = which.sync('git')
|
| 6 |
+
} catch {
|
| 7 |
+
// ignore errors
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
module.exports = (opts = {}) => {
|
| 11 |
+
if (opts.git) {
|
| 12 |
+
return opts.git
|
| 13 |
+
}
|
| 14 |
+
if (!gitPath || opts.git === false) {
|
| 15 |
+
return Object.assign(new Error('No git binary found in $PATH'), { code: 'ENOGIT' })
|
| 16 |
+
}
|
| 17 |
+
return gitPath
|
| 18 |
+
}
|
node/node_modules/npm/node_modules/@npmcli/git/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@npmcli/git",
|
| 3 |
+
"version": "7.0.2",
|
| 4 |
+
"main": "lib/index.js",
|
| 5 |
+
"files": [
|
| 6 |
+
"bin/",
|
| 7 |
+
"lib/"
|
| 8 |
+
],
|
| 9 |
+
"description": "a util for spawning git from npm CLI contexts",
|
| 10 |
+
"repository": {
|
| 11 |
+
"type": "git",
|
| 12 |
+
"url": "git+https://github.com/npm/git.git"
|
| 13 |
+
},
|
| 14 |
+
"author": "GitHub Inc.",
|
| 15 |
+
"license": "ISC",
|
| 16 |
+
"scripts": {
|
| 17 |
+
"lint": "npm run eslint",
|
| 18 |
+
"snap": "tap",
|
| 19 |
+
"test": "tap",
|
| 20 |
+
"posttest": "npm run lint",
|
| 21 |
+
"postlint": "template-oss-check",
|
| 22 |
+
"lintfix": "npm run eslint -- --fix",
|
| 23 |
+
"template-oss-apply": "template-oss-apply --force",
|
| 24 |
+
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
|
| 25 |
+
},
|
| 26 |
+
"tap": {
|
| 27 |
+
"timeout": 600,
|
| 28 |
+
"nyc-arg": [
|
| 29 |
+
"--exclude",
|
| 30 |
+
"tap-snapshots/**"
|
| 31 |
+
]
|
| 32 |
+
},
|
| 33 |
+
"devDependencies": {
|
| 34 |
+
"@npmcli/eslint-config": "^5.0.0",
|
| 35 |
+
"@npmcli/template-oss": "4.24.1",
|
| 36 |
+
"npm-package-arg": "^13.0.0",
|
| 37 |
+
"slash": "^3.0.0",
|
| 38 |
+
"tap": "^16.0.1"
|
| 39 |
+
},
|
| 40 |
+
"dependencies": {
|
| 41 |
+
"@gar/promise-retry": "^1.0.0",
|
| 42 |
+
"@npmcli/promise-spawn": "^9.0.0",
|
| 43 |
+
"ini": "^6.0.0",
|
| 44 |
+
"lru-cache": "^11.2.1",
|
| 45 |
+
"npm-pick-manifest": "^11.0.1",
|
| 46 |
+
"proc-log": "^6.0.0",
|
| 47 |
+
"semver": "^7.3.5",
|
| 48 |
+
"which": "^6.0.0"
|
| 49 |
+
},
|
| 50 |
+
"engines": {
|
| 51 |
+
"node": "^20.17.0 || >=22.9.0"
|
| 52 |
+
},
|
| 53 |
+
"templateOSS": {
|
| 54 |
+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
| 55 |
+
"version": "4.24.1",
|
| 56 |
+
"publish": true
|
| 57 |
+
}
|
| 58 |
+
}
|
node/node_modules/npm/node_modules/@npmcli/installed-package-contents/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The ISC License
|
| 2 |
+
|
| 3 |
+
Copyright (c) npm, Inc.
|
| 4 |
+
|
| 5 |
+
Permission to use, copy, modify, and/or distribute this software for any
|
| 6 |
+
purpose with or without fee is hereby granted, provided that the above
|
| 7 |
+
copyright notice and this permission notice appear in all copies.
|
| 8 |
+
|
| 9 |
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
| 10 |
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
| 11 |
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
| 12 |
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 13 |
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 14 |
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
| 15 |
+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
node/node_modules/npm/node_modules/@npmcli/installed-package-contents/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# @npmcli/installed-package-contents
|
| 2 |
+
|
| 3 |
+
Get the list of files installed in a package in node_modules, including
|
| 4 |
+
bundled dependencies.
|
| 5 |
+
|
| 6 |
+
This is useful if you want to remove a package node from the tree _without_
|
| 7 |
+
removing its child nodes, for example to extract a new version of the
|
| 8 |
+
dependency into place safely.
|
| 9 |
+
|
| 10 |
+
It's sort of the reflection of [npm-packlist](http://npm.im/npm-packlist),
|
| 11 |
+
but for listing out the _installed_ files rather than the files that _will_
|
| 12 |
+
be installed. This is of course a much simpler operation, because we don't
|
| 13 |
+
have to handle ignore files or package.json `files` lists.
|
| 14 |
+
|
| 15 |
+
## USAGE
|
| 16 |
+
|
| 17 |
+
```js
|
| 18 |
+
// programmatic usage
|
| 19 |
+
const pkgContents = require('@npmcli/installed-package-contents')
|
| 20 |
+
|
| 21 |
+
pkgContents({ path: 'node_modules/foo', depth: 1 }).then(files => {
|
| 22 |
+
// files is an array of items that need to be passed to
|
| 23 |
+
// rimraf or moved out of the way to make the folder empty
|
| 24 |
+
// if foo bundled dependencies, those will be included.
|
| 25 |
+
// It will not traverse into child directories, because we set
|
| 26 |
+
// depth:1 in the options.
|
| 27 |
+
// If the folder doesn't exist, this returns an empty array.
|
| 28 |
+
})
|
| 29 |
+
|
| 30 |
+
pkgContents({ path: 'node_modules/foo', depth: Infinity }).then(files => {
|
| 31 |
+
// setting depth:Infinity tells it to keep walking forever
|
| 32 |
+
// until it hits something that isn't a directory, so we'll
|
| 33 |
+
// just get the list of all files, but not their containing
|
| 34 |
+
// directories.
|
| 35 |
+
})
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
As a CLI:
|
| 39 |
+
|
| 40 |
+
```bash
|
| 41 |
+
$ installed-package-contents node_modules/bundle-some -d1
|
| 42 |
+
node_modules/.bin/some
|
| 43 |
+
node_modules/bundle-some/package.json
|
| 44 |
+
node_modules/bundle-some/node_modules/@scope/baz
|
| 45 |
+
node_modules/bundle-some/node_modules/.bin/foo
|
| 46 |
+
node_modules/bundle-some/node_modules/foo
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
CLI options:
|
| 50 |
+
|
| 51 |
+
```
|
| 52 |
+
Usage:
|
| 53 |
+
installed-package-contents <path> [-d<n> --depth=<n>]
|
| 54 |
+
|
| 55 |
+
Lists the files installed for a package specified by <path>.
|
| 56 |
+
|
| 57 |
+
Options:
|
| 58 |
+
-d<n> --depth=<n> Provide a numeric value ("Infinity" is allowed)
|
| 59 |
+
to specify how deep in the file tree to traverse.
|
| 60 |
+
Default=1
|
| 61 |
+
-h --help Show this usage information
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
## OPTIONS
|
| 65 |
+
|
| 66 |
+
* `depth` Number, default `1`. How deep to traverse through folders to get
|
| 67 |
+
contents. Typically you'd want to set this to either `1` (to get the
|
| 68 |
+
surface files and folders) or `Infinity` (to get all files), but any
|
| 69 |
+
other positive number is supported as well. If set to `0` or a
|
| 70 |
+
negative number, returns the path provided and (if it is a package) its
|
| 71 |
+
set of linked bins.
|
| 72 |
+
* `path` Required. Path to the package in `node_modules` where traversal
|
| 73 |
+
should begin.
|
| 74 |
+
|
| 75 |
+
## RETURN VALUE
|
| 76 |
+
|
| 77 |
+
A Promise that resolves to an array of fully-resolved files and folders
|
| 78 |
+
matching the criteria. This includes all bundled dependencies in
|
| 79 |
+
`node_modules`, and any linked executables in `node_modules/.bin` that the
|
| 80 |
+
package caused to be installed.
|
| 81 |
+
|
| 82 |
+
An empty or missing package folder will return an empty array. Empty
|
| 83 |
+
directories _within_ package contents are listed, even if the `depth`
|
| 84 |
+
argument would cause them to be traversed into.
|
| 85 |
+
|
| 86 |
+
## CAVEAT
|
| 87 |
+
|
| 88 |
+
If using this module to generate a list of files that should be recursively
|
| 89 |
+
removed to clear away the package, note that this will leave empty
|
| 90 |
+
directories behind in certain cases:
|
| 91 |
+
|
| 92 |
+
- If all child packages are bundled dependencies, then the
|
| 93 |
+
`node_modules` folder will remain.
|
| 94 |
+
- If all child packages within a given scope were bundled dependencies,
|
| 95 |
+
then the `node_modules/@scope` folder will remain.
|
| 96 |
+
- If all linked bin scripts were removed, then an empty `node_modules/.bin`
|
| 97 |
+
folder will remain.
|
| 98 |
+
|
| 99 |
+
In the interest of speed and algorithmic complexity, this module does _not_
|
| 100 |
+
do a subsequent readdir to see if it would remove all directory entries,
|
| 101 |
+
though it would be easier to look at if it returned `node_modules` or
|
| 102 |
+
`.bin` in that case rather than the contents. However, if the intent is to
|
| 103 |
+
pass these arguments to `rimraf`, it hardly makes sense to do _two_
|
| 104 |
+
`readdir` calls just so that we can have the luxury of having to make a
|
| 105 |
+
third.
|
| 106 |
+
|
| 107 |
+
Since the primary use case is to delete a package's contents so that they
|
| 108 |
+
can be re-filled with a new version of that package, this caveat does not
|
| 109 |
+
pose a problem. Empty directories are already ignored by both npm and git.
|
node/node_modules/npm/node_modules/@npmcli/installed-package-contents/bin/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#! /usr/bin/env node
|
| 2 |
+
|
| 3 |
+
const { relative } = require('path')
|
| 4 |
+
const pkgContents = require('../')
|
| 5 |
+
|
| 6 |
+
const usage = `Usage:
|
| 7 |
+
installed-package-contents <path> [-d<n> --depth=<n>]
|
| 8 |
+
|
| 9 |
+
Lists the files installed for a package specified by <path>.
|
| 10 |
+
|
| 11 |
+
Options:
|
| 12 |
+
-d<n> --depth=<n> Provide a numeric value ("Infinity" is allowed)
|
| 13 |
+
to specify how deep in the file tree to traverse.
|
| 14 |
+
Default=1
|
| 15 |
+
-h --help Show this usage information`
|
| 16 |
+
|
| 17 |
+
const options = {}
|
| 18 |
+
|
| 19 |
+
process.argv.slice(2).forEach(arg => {
|
| 20 |
+
let match
|
| 21 |
+
if ((match = arg.match(/^(?:--depth=|-d)([0-9]+|Infinity)/))) {
|
| 22 |
+
options.depth = +match[1]
|
| 23 |
+
} else if (arg === '-h' || arg === '--help') {
|
| 24 |
+
console.log(usage)
|
| 25 |
+
process.exit(0)
|
| 26 |
+
} else {
|
| 27 |
+
options.path = arg
|
| 28 |
+
}
|
| 29 |
+
})
|
| 30 |
+
|
| 31 |
+
if (!options.path) {
|
| 32 |
+
console.error('ERROR: no path provided')
|
| 33 |
+
console.error(usage)
|
| 34 |
+
process.exit(1)
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
const cwd = process.cwd()
|
| 38 |
+
|
| 39 |
+
pkgContents(options)
|
| 40 |
+
.then(list => list.sort().forEach(p => console.log(relative(cwd, p))))
|
| 41 |
+
.catch(/* istanbul ignore next - pretty unusual */ er => {
|
| 42 |
+
console.error(er)
|
| 43 |
+
process.exit(1)
|
| 44 |
+
})
|
node/node_modules/npm/node_modules/@npmcli/installed-package-contents/lib/index.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// to GET CONTENTS for folder at PATH (which may be a PACKAGE):
|
| 2 |
+
// - if PACKAGE, read path/package.json
|
| 3 |
+
// - if bins in ../node_modules/.bin, add those to result
|
| 4 |
+
// - if depth >= maxDepth, add PATH to result, and finish
|
| 5 |
+
// - readdir(PATH, with file types)
|
| 6 |
+
// - add all FILEs in PATH to result
|
| 7 |
+
// - if PARENT:
|
| 8 |
+
// - if depth < maxDepth, add GET CONTENTS of all DIRs in PATH
|
| 9 |
+
// - else, add all DIRs in PATH
|
| 10 |
+
// - if no parent
|
| 11 |
+
// - if no bundled deps,
|
| 12 |
+
// - if depth < maxDepth, add GET CONTENTS of DIRs in path except
|
| 13 |
+
// node_modules
|
| 14 |
+
// - else, add all DIRs in path other than node_modules
|
| 15 |
+
// - if has bundled deps,
|
| 16 |
+
// - get list of bundled deps
|
| 17 |
+
// - add GET CONTENTS of bundled deps, PACKAGE=true, depth + 1
|
| 18 |
+
|
| 19 |
+
const bundled = require('npm-bundled')
|
| 20 |
+
const { readFile, readdir, stat } = require('fs/promises')
|
| 21 |
+
const { resolve, basename, dirname } = require('path')
|
| 22 |
+
const normalizePackageBin = require('npm-normalize-package-bin')
|
| 23 |
+
|
| 24 |
+
const readPackage = ({ path, packageJsonCache }) => packageJsonCache.has(path)
|
| 25 |
+
? Promise.resolve(packageJsonCache.get(path))
|
| 26 |
+
: readFile(path).then(json => {
|
| 27 |
+
const pkg = normalizePackageBin(JSON.parse(json))
|
| 28 |
+
packageJsonCache.set(path, pkg)
|
| 29 |
+
return pkg
|
| 30 |
+
}).catch(() => null)
|
| 31 |
+
|
| 32 |
+
// just normalize bundle deps and bin, that's all we care about here.
|
| 33 |
+
const normalized = Symbol('package data has been normalized')
|
| 34 |
+
const rpj = ({ path, packageJsonCache }) => readPackage({ path, packageJsonCache })
|
| 35 |
+
.then(pkg => {
|
| 36 |
+
if (!pkg || pkg[normalized]) {
|
| 37 |
+
return pkg
|
| 38 |
+
}
|
| 39 |
+
if (pkg.bundledDependencies && !pkg.bundleDependencies) {
|
| 40 |
+
pkg.bundleDependencies = pkg.bundledDependencies
|
| 41 |
+
delete pkg.bundledDependencies
|
| 42 |
+
}
|
| 43 |
+
const bd = pkg.bundleDependencies
|
| 44 |
+
if (bd === true) {
|
| 45 |
+
pkg.bundleDependencies = [
|
| 46 |
+
...Object.keys(pkg.dependencies || {}),
|
| 47 |
+
...Object.keys(pkg.optionalDependencies || {}),
|
| 48 |
+
]
|
| 49 |
+
}
|
| 50 |
+
if (typeof bd === 'object' && !Array.isArray(bd)) {
|
| 51 |
+
pkg.bundleDependencies = Object.keys(bd)
|
| 52 |
+
}
|
| 53 |
+
pkg[normalized] = true
|
| 54 |
+
return pkg
|
| 55 |
+
})
|
| 56 |
+
|
| 57 |
+
const pkgContents = async ({
|
| 58 |
+
path,
|
| 59 |
+
depth = 1,
|
| 60 |
+
currentDepth = 0,
|
| 61 |
+
pkg = null,
|
| 62 |
+
result = null,
|
| 63 |
+
packageJsonCache = null,
|
| 64 |
+
}) => {
|
| 65 |
+
if (!result) {
|
| 66 |
+
result = new Set()
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
if (!packageJsonCache) {
|
| 70 |
+
packageJsonCache = new Map()
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
if (pkg === true) {
|
| 74 |
+
return rpj({ path: path + '/package.json', packageJsonCache })
|
| 75 |
+
.then(p => pkgContents({
|
| 76 |
+
path,
|
| 77 |
+
depth,
|
| 78 |
+
currentDepth,
|
| 79 |
+
pkg: p,
|
| 80 |
+
result,
|
| 81 |
+
packageJsonCache,
|
| 82 |
+
}))
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
if (pkg) {
|
| 86 |
+
// add all bins to result if they exist
|
| 87 |
+
if (pkg.bin) {
|
| 88 |
+
const dir = dirname(path)
|
| 89 |
+
const scope = basename(dir)
|
| 90 |
+
const nm = /^@.+/.test(scope) ? dirname(dir) : dir
|
| 91 |
+
|
| 92 |
+
const binFiles = []
|
| 93 |
+
Object.keys(pkg.bin).forEach(b => {
|
| 94 |
+
const base = resolve(nm, '.bin', b)
|
| 95 |
+
binFiles.push(base, base + '.cmd', base + '.ps1')
|
| 96 |
+
})
|
| 97 |
+
|
| 98 |
+
const bins = await Promise.all(
|
| 99 |
+
binFiles.map(b => stat(b).then(() => b).catch(() => null))
|
| 100 |
+
)
|
| 101 |
+
bins.filter(b => b).forEach(b => result.add(b))
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
if (currentDepth >= depth) {
|
| 106 |
+
result.add(path)
|
| 107 |
+
return result
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
// we'll need bundle list later, so get that now in parallel
|
| 111 |
+
const [dirEntries, bundleDeps] = await Promise.all([
|
| 112 |
+
readdir(path, { withFileTypes: true }),
|
| 113 |
+
currentDepth === 0 && pkg && pkg.bundleDependencies
|
| 114 |
+
? bundled({ path, packageJsonCache }) : null,
|
| 115 |
+
]).catch(() => [])
|
| 116 |
+
|
| 117 |
+
// not a thing, probably a missing folder
|
| 118 |
+
if (!dirEntries) {
|
| 119 |
+
return result
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
// empty folder, just add the folder itself to the result
|
| 123 |
+
if (!dirEntries.length && !bundleDeps && currentDepth !== 0) {
|
| 124 |
+
result.add(path)
|
| 125 |
+
return result
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
const recursePromises = []
|
| 129 |
+
|
| 130 |
+
for (const entry of dirEntries) {
|
| 131 |
+
const p = resolve(path, entry.name)
|
| 132 |
+
if (entry.isDirectory() === false) {
|
| 133 |
+
result.add(p)
|
| 134 |
+
continue
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
if (currentDepth !== 0 || entry.name !== 'node_modules') {
|
| 138 |
+
if (currentDepth < depth - 1) {
|
| 139 |
+
recursePromises.push(pkgContents({
|
| 140 |
+
path: p,
|
| 141 |
+
packageJsonCache,
|
| 142 |
+
depth,
|
| 143 |
+
currentDepth: currentDepth + 1,
|
| 144 |
+
result,
|
| 145 |
+
}))
|
| 146 |
+
} else {
|
| 147 |
+
result.add(p)
|
| 148 |
+
}
|
| 149 |
+
continue
|
| 150 |
+
}
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
if (bundleDeps) {
|
| 154 |
+
// bundle deps are all folders
|
| 155 |
+
// we always recurse to get pkg bins, but if currentDepth is too high,
|
| 156 |
+
// it'll return early before walking their contents.
|
| 157 |
+
recursePromises.push(...bundleDeps.map(dep => {
|
| 158 |
+
const p = resolve(path, 'node_modules', dep)
|
| 159 |
+
return pkgContents({
|
| 160 |
+
path: p,
|
| 161 |
+
packageJsonCache,
|
| 162 |
+
pkg: true,
|
| 163 |
+
depth,
|
| 164 |
+
currentDepth: currentDepth + 1,
|
| 165 |
+
result,
|
| 166 |
+
})
|
| 167 |
+
}))
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
if (recursePromises.length) {
|
| 171 |
+
await Promise.all(recursePromises)
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
return result
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
module.exports = ({ path, ...opts }) => pkgContents({
|
| 178 |
+
path: resolve(path),
|
| 179 |
+
...opts,
|
| 180 |
+
pkg: true,
|
| 181 |
+
}).then(results => [...results])
|
node/node_modules/npm/node_modules/@npmcli/installed-package-contents/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@npmcli/installed-package-contents",
|
| 3 |
+
"version": "4.0.0",
|
| 4 |
+
"description": "Get the list of files installed in a package in node_modules, including bundled dependencies",
|
| 5 |
+
"author": "GitHub Inc.",
|
| 6 |
+
"main": "lib/index.js",
|
| 7 |
+
"bin": {
|
| 8 |
+
"installed-package-contents": "bin/index.js"
|
| 9 |
+
},
|
| 10 |
+
"license": "ISC",
|
| 11 |
+
"scripts": {
|
| 12 |
+
"test": "tap",
|
| 13 |
+
"snap": "tap",
|
| 14 |
+
"lint": "npm run eslint",
|
| 15 |
+
"postlint": "template-oss-check",
|
| 16 |
+
"template-oss-apply": "template-oss-apply --force",
|
| 17 |
+
"lintfix": "npm run eslint -- --fix",
|
| 18 |
+
"posttest": "npm run lint",
|
| 19 |
+
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
|
| 20 |
+
},
|
| 21 |
+
"devDependencies": {
|
| 22 |
+
"@npmcli/eslint-config": "^5.0.0",
|
| 23 |
+
"@npmcli/template-oss": "4.27.1",
|
| 24 |
+
"tap": "^16.3.0"
|
| 25 |
+
},
|
| 26 |
+
"dependencies": {
|
| 27 |
+
"npm-bundled": "^5.0.0",
|
| 28 |
+
"npm-normalize-package-bin": "^5.0.0"
|
| 29 |
+
},
|
| 30 |
+
"repository": {
|
| 31 |
+
"type": "git",
|
| 32 |
+
"url": "git+https://github.com/npm/installed-package-contents.git"
|
| 33 |
+
},
|
| 34 |
+
"files": [
|
| 35 |
+
"bin/",
|
| 36 |
+
"lib/"
|
| 37 |
+
],
|
| 38 |
+
"engines": {
|
| 39 |
+
"node": "^20.17.0 || >=22.9.0"
|
| 40 |
+
},
|
| 41 |
+
"templateOSS": {
|
| 42 |
+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
| 43 |
+
"version": "4.27.1",
|
| 44 |
+
"publish": true
|
| 45 |
+
},
|
| 46 |
+
"tap": {
|
| 47 |
+
"nyc-arg": [
|
| 48 |
+
"--exclude",
|
| 49 |
+
"tap-snapshots/**"
|
| 50 |
+
]
|
| 51 |
+
}
|
| 52 |
+
}
|
node/node_modules/npm/node_modules/@npmcli/map-workspaces/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!-- This file is automatically added by @npmcli/template-oss. Do not edit. -->
|
| 2 |
+
|
| 3 |
+
ISC License
|
| 4 |
+
|
| 5 |
+
Copyright npm, Inc.
|
| 6 |
+
|
| 7 |
+
Permission to use, copy, modify, and/or distribute this
|
| 8 |
+
software for any purpose with or without fee is hereby
|
| 9 |
+
granted, provided that the above copyright notice and this
|
| 10 |
+
permission notice appear in all copies.
|
| 11 |
+
|
| 12 |
+
THE SOFTWARE IS PROVIDED "AS IS" AND NPM DISCLAIMS ALL
|
| 13 |
+
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
| 14 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
|
| 15 |
+
EVENT SHALL NPM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
| 16 |
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 17 |
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
| 18 |
+
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
| 19 |
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
|
| 20 |
+
USE OR PERFORMANCE OF THIS SOFTWARE.
|
node/node_modules/npm/node_modules/@npmcli/map-workspaces/lib/index.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const path = require('path')
|
| 2 |
+
|
| 3 |
+
const getName = require('@npmcli/name-from-folder')
|
| 4 |
+
const { minimatch } = require('minimatch')
|
| 5 |
+
const pkgJson = require('@npmcli/package-json')
|
| 6 |
+
const { glob } = require('glob')
|
| 7 |
+
|
| 8 |
+
function appendNegatedPatterns (allPatterns) {
|
| 9 |
+
const patterns = []
|
| 10 |
+
const negatedPatterns = []
|
| 11 |
+
for (let pattern of allPatterns) {
|
| 12 |
+
const excl = pattern.match(/^!+/)
|
| 13 |
+
if (excl) {
|
| 14 |
+
pattern = pattern.slice(excl[0].length)
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
// strip off any / or ./ from the start of the pattern. /foo => foo
|
| 18 |
+
pattern = pattern.replace(/^\.?\/+/, '')
|
| 19 |
+
|
| 20 |
+
// an odd number of ! means a negated pattern. !!foo ==> foo
|
| 21 |
+
const negate = excl && excl[0].length % 2 === 1
|
| 22 |
+
if (negate) {
|
| 23 |
+
negatedPatterns.push(pattern)
|
| 24 |
+
} else {
|
| 25 |
+
// remove negated patterns that appeared before this pattern to avoid
|
| 26 |
+
// ignoring paths that were matched afterwards
|
| 27 |
+
// e.g: ['packages/**', '!packages/b/**', 'packages/b/a']
|
| 28 |
+
// in the above list, the last pattern overrides the negated pattern
|
| 29 |
+
// right before it. In effect, the above list would become:
|
| 30 |
+
// ['packages/**', 'packages/b/a']
|
| 31 |
+
// The order matters here which is why we must do it inside the loop
|
| 32 |
+
// as opposed to doing it all together at the end.
|
| 33 |
+
for (let i = 0; i < negatedPatterns.length; ++i) {
|
| 34 |
+
const negatedPattern = negatedPatterns[i]
|
| 35 |
+
if (minimatch(pattern, negatedPattern)) {
|
| 36 |
+
negatedPatterns.splice(i, 1)
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
patterns.push(pattern)
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
// use the negated patterns to eagerly remove all the patterns that
|
| 44 |
+
// can be removed to avoid unnecessary crawling
|
| 45 |
+
for (const negated of negatedPatterns) {
|
| 46 |
+
for (const pattern of minimatch.match(patterns, negated)) {
|
| 47 |
+
patterns.splice(patterns.indexOf(pattern), 1)
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
return { patterns, negatedPatterns }
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
function getPatterns (workspaces) {
|
| 54 |
+
const workspacesDeclaration =
|
| 55 |
+
Array.isArray(workspaces.packages)
|
| 56 |
+
? workspaces.packages
|
| 57 |
+
: workspaces
|
| 58 |
+
|
| 59 |
+
if (!Array.isArray(workspacesDeclaration)) {
|
| 60 |
+
throw getError({
|
| 61 |
+
message: 'workspaces config expects an Array',
|
| 62 |
+
code: 'EWORKSPACESCONFIG',
|
| 63 |
+
})
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
return appendNegatedPatterns(workspacesDeclaration)
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
function getPackageName (pkg, pathname) {
|
| 70 |
+
return pkg.name || getName(pathname)
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
// make sure glob pattern only matches folders
|
| 74 |
+
function getGlobPattern (pattern) {
|
| 75 |
+
pattern = pattern.replace(/\\/g, '/')
|
| 76 |
+
return pattern.endsWith('/')
|
| 77 |
+
? pattern
|
| 78 |
+
: `${pattern}/`
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
function getError ({ Type = TypeError, message, code }) {
|
| 82 |
+
return Object.assign(new Type(message), { code })
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
function reverseResultMap (map) {
|
| 86 |
+
return new Map(Array.from(map, item => item.reverse()))
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
async function mapWorkspaces (opts = {}) {
|
| 90 |
+
if (!opts || !opts.pkg) {
|
| 91 |
+
throw getError({
|
| 92 |
+
message: 'mapWorkspaces missing pkg info',
|
| 93 |
+
code: 'EMAPWORKSPACESPKG',
|
| 94 |
+
})
|
| 95 |
+
}
|
| 96 |
+
if (!opts.cwd) {
|
| 97 |
+
opts.cwd = process.cwd()
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
const { workspaces = [] } = opts.pkg
|
| 101 |
+
const { patterns, negatedPatterns } = getPatterns(workspaces)
|
| 102 |
+
const results = new Map()
|
| 103 |
+
|
| 104 |
+
if (!patterns.length && !negatedPatterns.length) {
|
| 105 |
+
return results
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
const seen = new Map()
|
| 109 |
+
const getGlobOpts = () => ({
|
| 110 |
+
...opts,
|
| 111 |
+
ignore: [
|
| 112 |
+
...opts.ignore || [],
|
| 113 |
+
'**/node_modules/**',
|
| 114 |
+
// just ignore the negated patterns to avoid unnecessary crawling
|
| 115 |
+
...negatedPatterns,
|
| 116 |
+
],
|
| 117 |
+
})
|
| 118 |
+
|
| 119 |
+
let matches = await glob(patterns.map((p) => getGlobPattern(p)), getGlobOpts())
|
| 120 |
+
// preserves glob@8 behavior
|
| 121 |
+
matches = matches.sort((a, b) => a.localeCompare(b, 'en'))
|
| 122 |
+
|
| 123 |
+
// we must preserve the order of results according to the given list of
|
| 124 |
+
// workspace patterns
|
| 125 |
+
const orderedMatches = []
|
| 126 |
+
for (const pattern of patterns) {
|
| 127 |
+
orderedMatches.push(...matches.filter((m) => {
|
| 128 |
+
return minimatch(m, pattern, { partial: true, windowsPathsNoEscape: true })
|
| 129 |
+
}))
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
for (const match of orderedMatches) {
|
| 133 |
+
let pkg
|
| 134 |
+
try {
|
| 135 |
+
pkg = await pkgJson.normalize(path.join(opts.cwd, match))
|
| 136 |
+
} catch (err) {
|
| 137 |
+
if (err.code === 'ENOENT' || err.code === 'ENOTDIR') {
|
| 138 |
+
continue
|
| 139 |
+
} else {
|
| 140 |
+
throw err
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
const name = getPackageName(pkg.content, pkg.path)
|
| 145 |
+
|
| 146 |
+
let seenPackagePathnames = seen.get(name)
|
| 147 |
+
if (!seenPackagePathnames) {
|
| 148 |
+
seenPackagePathnames = new Set()
|
| 149 |
+
seen.set(name, seenPackagePathnames)
|
| 150 |
+
}
|
| 151 |
+
seenPackagePathnames.add(pkg.path)
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
const errorMessageArray = ['must not have multiple workspaces with the same name']
|
| 155 |
+
for (const [packageName, seenPackagePathnames] of seen) {
|
| 156 |
+
if (seenPackagePathnames.size > 1) {
|
| 157 |
+
addDuplicateErrorMessages(errorMessageArray, packageName, seenPackagePathnames)
|
| 158 |
+
} else {
|
| 159 |
+
results.set(packageName, seenPackagePathnames.values().next().value)
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
if (errorMessageArray.length > 1) {
|
| 164 |
+
throw getError({
|
| 165 |
+
Type: Error,
|
| 166 |
+
message: errorMessageArray.join('\n'),
|
| 167 |
+
code: 'EDUPLICATEWORKSPACE',
|
| 168 |
+
})
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
return results
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
function addDuplicateErrorMessages (messageArray, packageName, packagePathnames) {
|
| 175 |
+
messageArray.push(
|
| 176 |
+
`package '${packageName}' has conflicts in the following paths:`
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
for (const packagePathname of packagePathnames) {
|
| 180 |
+
messageArray.push(
|
| 181 |
+
' ' + packagePathname
|
| 182 |
+
)
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
mapWorkspaces.virtual = function (opts = {}) {
|
| 187 |
+
if (!opts || !opts.lockfile) {
|
| 188 |
+
throw getError({
|
| 189 |
+
message: 'mapWorkspaces.virtual missing lockfile info',
|
| 190 |
+
code: 'EMAPWORKSPACESLOCKFILE',
|
| 191 |
+
})
|
| 192 |
+
}
|
| 193 |
+
if (!opts.cwd) {
|
| 194 |
+
opts.cwd = process.cwd()
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
const { packages = {} } = opts.lockfile
|
| 198 |
+
const { workspaces = [] } = packages[''] || {}
|
| 199 |
+
// uses a pathname-keyed map in order to negate the exact items
|
| 200 |
+
const results = new Map()
|
| 201 |
+
const { patterns, negatedPatterns } = getPatterns(workspaces)
|
| 202 |
+
if (!patterns.length && !negatedPatterns.length) {
|
| 203 |
+
return results
|
| 204 |
+
}
|
| 205 |
+
negatedPatterns.push('**/node_modules/**')
|
| 206 |
+
|
| 207 |
+
const packageKeys = Object.keys(packages)
|
| 208 |
+
for (const pattern of negatedPatterns) {
|
| 209 |
+
for (const packageKey of minimatch.match(packageKeys, pattern)) {
|
| 210 |
+
packageKeys.splice(packageKeys.indexOf(packageKey), 1)
|
| 211 |
+
}
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
for (const pattern of patterns) {
|
| 215 |
+
for (const packageKey of minimatch.match(packageKeys, pattern)) {
|
| 216 |
+
const packagePathname = path.join(opts.cwd, packageKey)
|
| 217 |
+
const name = getPackageName(packages[packageKey], packagePathname)
|
| 218 |
+
results.set(packagePathname, name)
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
// Invert pathname-keyed to a proper name-to-pathnames Map
|
| 223 |
+
return reverseResultMap(results)
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
module.exports = mapWorkspaces
|
node/node_modules/npm/node_modules/@npmcli/map-workspaces/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@npmcli/map-workspaces",
|
| 3 |
+
"version": "5.0.3",
|
| 4 |
+
"main": "lib/index.js",
|
| 5 |
+
"files": [
|
| 6 |
+
"bin/",
|
| 7 |
+
"lib/"
|
| 8 |
+
],
|
| 9 |
+
"engines": {
|
| 10 |
+
"node": "^20.17.0 || >=22.9.0"
|
| 11 |
+
},
|
| 12 |
+
"description": "Retrieves a name:pathname Map for a given workspaces config",
|
| 13 |
+
"repository": {
|
| 14 |
+
"type": "git",
|
| 15 |
+
"url": "git+https://github.com/npm/map-workspaces.git"
|
| 16 |
+
},
|
| 17 |
+
"keywords": [
|
| 18 |
+
"npm",
|
| 19 |
+
"npmcli",
|
| 20 |
+
"libnpm",
|
| 21 |
+
"cli",
|
| 22 |
+
"workspaces",
|
| 23 |
+
"map-workspaces"
|
| 24 |
+
],
|
| 25 |
+
"author": "GitHub Inc.",
|
| 26 |
+
"license": "ISC",
|
| 27 |
+
"scripts": {
|
| 28 |
+
"lint": "npm run eslint",
|
| 29 |
+
"pretest": "npm run lint",
|
| 30 |
+
"test": "tap",
|
| 31 |
+
"snap": "tap",
|
| 32 |
+
"postlint": "template-oss-check",
|
| 33 |
+
"lintfix": "npm run eslint -- --fix",
|
| 34 |
+
"posttest": "npm run lint",
|
| 35 |
+
"template-oss-apply": "template-oss-apply --force",
|
| 36 |
+
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
|
| 37 |
+
},
|
| 38 |
+
"tap": {
|
| 39 |
+
"check-coverage": true,
|
| 40 |
+
"nyc-arg": [
|
| 41 |
+
"--exclude",
|
| 42 |
+
"tap-snapshots/**"
|
| 43 |
+
]
|
| 44 |
+
},
|
| 45 |
+
"devDependencies": {
|
| 46 |
+
"@npmcli/eslint-config": "^6.0.0",
|
| 47 |
+
"@npmcli/template-oss": "4.28.0",
|
| 48 |
+
"tap": "^16.0.1"
|
| 49 |
+
},
|
| 50 |
+
"dependencies": {
|
| 51 |
+
"@npmcli/name-from-folder": "^4.0.0",
|
| 52 |
+
"@npmcli/package-json": "^7.0.0",
|
| 53 |
+
"glob": "^13.0.0",
|
| 54 |
+
"minimatch": "^10.0.3"
|
| 55 |
+
},
|
| 56 |
+
"templateOSS": {
|
| 57 |
+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
| 58 |
+
"version": "4.28.0",
|
| 59 |
+
"publish": "true"
|
| 60 |
+
}
|
| 61 |
+
}
|
node/node_modules/npm/node_modules/@npmcli/metavuln-calculator/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The ISC License
|
| 2 |
+
|
| 3 |
+
Copyright (c) npm, Inc.
|
| 4 |
+
|
| 5 |
+
Permission to use, copy, modify, and/or distribute this software for any
|
| 6 |
+
purpose with or without fee is hereby granted, provided that the above
|
| 7 |
+
copyright notice and this permission notice appear in all copies.
|
| 8 |
+
|
| 9 |
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
| 10 |
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
| 11 |
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
| 12 |
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 13 |
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 14 |
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
| 15 |
+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
node/node_modules/npm/node_modules/@npmcli/metavuln-calculator/lib/advisory.js
ADDED
|
@@ -0,0 +1,435 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const hash = require('./hash.js')
|
| 2 |
+
const semver = require('semver')
|
| 3 |
+
const semverOpt = { includePrerelease: true, loose: true }
|
| 4 |
+
const getDepSpec = require('./get-dep-spec.js')
|
| 5 |
+
|
| 6 |
+
// any fields that we don't want in the cache need to be hidden
|
| 7 |
+
const _source = Symbol('source')
|
| 8 |
+
const _packument = Symbol('packument')
|
| 9 |
+
const _versionVulnMemo = Symbol('versionVulnMemo')
|
| 10 |
+
const _updated = Symbol('updated')
|
| 11 |
+
const _options = Symbol('options')
|
| 12 |
+
const _specVulnMemo = Symbol('specVulnMemo')
|
| 13 |
+
const _testVersion = Symbol('testVersion')
|
| 14 |
+
const _testVersions = Symbol('testVersions')
|
| 15 |
+
const _calculateRange = Symbol('calculateRange')
|
| 16 |
+
const _markVulnerable = Symbol('markVulnerable')
|
| 17 |
+
const _testSpec = Symbol('testSpec')
|
| 18 |
+
|
| 19 |
+
class Advisory {
|
| 20 |
+
constructor (name, source, options = {}) {
|
| 21 |
+
this.source = source.id
|
| 22 |
+
this[_source] = source
|
| 23 |
+
this[_options] = options
|
| 24 |
+
this.name = name
|
| 25 |
+
if (!source.name) {
|
| 26 |
+
source.name = name
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
this.dependency = source.name
|
| 30 |
+
|
| 31 |
+
if (this.type === 'advisory') {
|
| 32 |
+
this.title = source.title
|
| 33 |
+
this.url = source.url
|
| 34 |
+
} else {
|
| 35 |
+
this.title = `Depends on vulnerable versions of ${source.name}`
|
| 36 |
+
this.url = null
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
this.severity = source.severity || 'high'
|
| 40 |
+
this.versions = []
|
| 41 |
+
this.vulnerableVersions = []
|
| 42 |
+
this.cwe = source.cwe
|
| 43 |
+
this.cvss = source.cvss
|
| 44 |
+
|
| 45 |
+
// advisories have the range, metavulns do not
|
| 46 |
+
// if an advisory doesn't specify range, assume all are vulnerable
|
| 47 |
+
this.range = this.type === 'advisory' ? source.vulnerable_versions || '*'
|
| 48 |
+
: null
|
| 49 |
+
|
| 50 |
+
this.id = hash(this)
|
| 51 |
+
|
| 52 |
+
this[_packument] = null
|
| 53 |
+
// memoized list of which versions are vulnerable
|
| 54 |
+
this[_versionVulnMemo] = new Map()
|
| 55 |
+
// memoized list of which dependency specs are vulnerable
|
| 56 |
+
this[_specVulnMemo] = new Map()
|
| 57 |
+
this[_updated] = false
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
// true if we updated from what we had in cache
|
| 61 |
+
get updated () {
|
| 62 |
+
return this[_updated]
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
get type () {
|
| 66 |
+
return this.dependency === this.name ? 'advisory' : 'metavuln'
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
get packument () {
|
| 70 |
+
return this[_packument]
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
// load up the data from a cache entry and a fetched packument
|
| 74 |
+
load (cached, packument) {
|
| 75 |
+
// basic data integrity gutcheck
|
| 76 |
+
if (!cached || typeof cached !== 'object') {
|
| 77 |
+
throw new TypeError('invalid cached data, expected object')
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
if (!packument || typeof packument !== 'object') {
|
| 81 |
+
throw new TypeError('invalid packument data, expected object')
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
if (cached.id && cached.id !== this.id) {
|
| 85 |
+
throw Object.assign(new Error('loading from incorrect cache entry'), {
|
| 86 |
+
expected: this.id,
|
| 87 |
+
actual: cached.id,
|
| 88 |
+
})
|
| 89 |
+
}
|
| 90 |
+
if (packument.name !== this.name) {
|
| 91 |
+
throw Object.assign(new Error('loading from incorrect packument'), {
|
| 92 |
+
expected: this.name,
|
| 93 |
+
actual: packument.name,
|
| 94 |
+
})
|
| 95 |
+
}
|
| 96 |
+
if (this[_packument]) {
|
| 97 |
+
throw new Error('advisory object already loaded')
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
// if we have a range from the initialization, and the cached
|
| 101 |
+
// data has a *different* range, then we know we have to recalc.
|
| 102 |
+
// just don't use the cached data, so we will definitely not match later
|
| 103 |
+
if (!this.range || cached.range && cached.range === this.range) {
|
| 104 |
+
Object.assign(this, cached)
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
this[_packument] = packument
|
| 108 |
+
|
| 109 |
+
const pakuVersions = Object.keys(packument.versions || {})
|
| 110 |
+
const allVersions = new Set([...pakuVersions, ...this.versions])
|
| 111 |
+
const versionsAdded = []
|
| 112 |
+
const versionsRemoved = []
|
| 113 |
+
for (const v of allVersions) {
|
| 114 |
+
if (!this.versions.includes(v)) {
|
| 115 |
+
versionsAdded.push(v)
|
| 116 |
+
this.versions.push(v)
|
| 117 |
+
} else if (!pakuVersions.includes(v)) {
|
| 118 |
+
versionsRemoved.push(v)
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
// strip out any removed versions from our lists, and sort by semver
|
| 123 |
+
this.versions = semver.sort(this.versions.filter(v =>
|
| 124 |
+
!versionsRemoved.includes(v)), semverOpt)
|
| 125 |
+
|
| 126 |
+
// if no changes, then just return what we got from cache
|
| 127 |
+
// versions added or removed always means we changed
|
| 128 |
+
// otherwise, advisories change if the range changes, and
|
| 129 |
+
// metavulns change if the source was updated
|
| 130 |
+
const unchanged = this.type === 'advisory'
|
| 131 |
+
? this.range && this.range === cached.range
|
| 132 |
+
: !this[_source].updated
|
| 133 |
+
|
| 134 |
+
// if the underlying source changed, by an advisory updating the
|
| 135 |
+
// range, or a source advisory being updated, then we have to re-check
|
| 136 |
+
// otherwise, only recheck the new ones.
|
| 137 |
+
this.vulnerableVersions = !unchanged ? []
|
| 138 |
+
: semver.sort(this.vulnerableVersions.filter(v =>
|
| 139 |
+
!versionsRemoved.includes(v)), semverOpt)
|
| 140 |
+
|
| 141 |
+
if (unchanged && !versionsAdded.length && !versionsRemoved.length) {
|
| 142 |
+
// nothing added or removed, nothing to do here. use the cached copy.
|
| 143 |
+
return this
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
this[_updated] = true
|
| 147 |
+
|
| 148 |
+
// test any versions newly added
|
| 149 |
+
if (!unchanged || versionsAdded.length) {
|
| 150 |
+
this[_testVersions](unchanged ? versionsAdded : this.versions)
|
| 151 |
+
}
|
| 152 |
+
this.vulnerableVersions = semver.sort(this.vulnerableVersions, semverOpt)
|
| 153 |
+
|
| 154 |
+
// metavulns have to calculate their range, since cache is invalidated
|
| 155 |
+
// advisories just get their range from the advisory above
|
| 156 |
+
if (this.type === 'metavuln') {
|
| 157 |
+
this[_calculateRange]()
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
return this
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
[_calculateRange] () {
|
| 164 |
+
// calling semver.simplifyRange with a massive list of versions, and those
|
| 165 |
+
// versions all concatenated with `||` is a geometric CPU explosion!
|
| 166 |
+
// we can try to be a *little* smarter up front by doing x-y for all
|
| 167 |
+
// contiguous version sets in the list
|
| 168 |
+
const ranges = []
|
| 169 |
+
this.versions = semver.sort(this.versions, semverOpt)
|
| 170 |
+
this.vulnerableVersions = semver.sort(this.vulnerableVersions, semverOpt)
|
| 171 |
+
for (let v = 0, vulnVer = 0; v < this.versions.length; v++) {
|
| 172 |
+
// figure out the vulnerable subrange
|
| 173 |
+
const vr = [this.versions[v]]
|
| 174 |
+
while (v < this.versions.length) {
|
| 175 |
+
if (this.versions[v] !== this.vulnerableVersions[vulnVer]) {
|
| 176 |
+
// we don't test prerelease versions, so just skip past it
|
| 177 |
+
if (/-/.test(this.versions[v])) {
|
| 178 |
+
v++
|
| 179 |
+
continue
|
| 180 |
+
}
|
| 181 |
+
break
|
| 182 |
+
}
|
| 183 |
+
if (vr.length > 1) {
|
| 184 |
+
vr[1] = this.versions[v]
|
| 185 |
+
} else {
|
| 186 |
+
vr.push(this.versions[v])
|
| 187 |
+
}
|
| 188 |
+
v++
|
| 189 |
+
vulnVer++
|
| 190 |
+
}
|
| 191 |
+
// it'll either be just the first version, which means no overlap,
|
| 192 |
+
// or the start and end versions, which might be the same version
|
| 193 |
+
if (vr.length > 1) {
|
| 194 |
+
const tail = this.versions[this.versions.length - 1]
|
| 195 |
+
ranges.push(vr[1] === tail ? `>=${vr[0]}`
|
| 196 |
+
: vr[0] === vr[1] ? vr[0]
|
| 197 |
+
: vr.join(' - '))
|
| 198 |
+
}
|
| 199 |
+
}
|
| 200 |
+
const metavuln = ranges.join(' || ').trim()
|
| 201 |
+
this.range = !metavuln ? '<0.0.0-0'
|
| 202 |
+
: semver.simplifyRange(this.versions, metavuln, semverOpt)
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
// returns true if marked as vulnerable, false if ok
|
| 206 |
+
// spec is a dependency specifier, for metavuln cases
|
| 207 |
+
// where the version might not be in the packument. if
|
| 208 |
+
// we have the packument and spec is not provided, then
|
| 209 |
+
// we use the dependency version from the manifest.
|
| 210 |
+
testVersion (version, spec = null) {
|
| 211 |
+
const sv = String(version)
|
| 212 |
+
if (this[_versionVulnMemo].has(sv)) {
|
| 213 |
+
return this[_versionVulnMemo].get(sv)
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
const result = this[_testVersion](version, spec)
|
| 217 |
+
if (result) {
|
| 218 |
+
this[_markVulnerable](version)
|
| 219 |
+
}
|
| 220 |
+
this[_versionVulnMemo].set(sv, !!result)
|
| 221 |
+
return result
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
[_markVulnerable] (version) {
|
| 225 |
+
const sv = String(version)
|
| 226 |
+
if (!this.vulnerableVersions.includes(sv)) {
|
| 227 |
+
this.vulnerableVersions.push(sv)
|
| 228 |
+
}
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
[_testVersion] (version, spec) {
|
| 232 |
+
const sv = String(version)
|
| 233 |
+
if (this.vulnerableVersions.includes(sv)) {
|
| 234 |
+
return true
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
if (this.type === 'advisory') {
|
| 238 |
+
// advisory, just test range
|
| 239 |
+
return semver.satisfies(version, this.range, semverOpt)
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
// check the dependency of this version on the vulnerable dep
|
| 243 |
+
// if we got a version that's not in the packument, fall back on
|
| 244 |
+
// the spec provided, if possible.
|
| 245 |
+
const mani = this[_packument]?.versions?.[version] || {
|
| 246 |
+
dependencies: {
|
| 247 |
+
[this.dependency]: spec,
|
| 248 |
+
},
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
if (!spec) {
|
| 252 |
+
spec = getDepSpec(mani, this.dependency)
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
// no dep, no vuln
|
| 256 |
+
if (spec === null) {
|
| 257 |
+
return false
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
if (!semver.validRange(spec, semverOpt)) {
|
| 261 |
+
// not a semver range, nothing we can hope to do about it
|
| 262 |
+
return true
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
const bd = mani.bundleDependencies
|
| 266 |
+
const bundled = bd && bd.includes(this[_source].name)
|
| 267 |
+
// XXX if bundled, then semver.intersects() means vulnerable
|
| 268 |
+
// else, pick a manifest and see if it can't be avoided
|
| 269 |
+
// try to pick a version of the dep that isn't vulnerable
|
| 270 |
+
const avoid = this[_source].range
|
| 271 |
+
|
| 272 |
+
if (bundled) {
|
| 273 |
+
return semver.intersects(spec, avoid, semverOpt)
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
return this[_source].testSpec(spec)
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
testSpec (spec) {
|
| 280 |
+
// testing all the versions is a bit costly, and the spec tends to stay
|
| 281 |
+
// consistent across multiple versions, so memoize this as well, in case
|
| 282 |
+
// we're testing lots of versions.
|
| 283 |
+
const memo = this[_specVulnMemo]
|
| 284 |
+
if (memo.has(spec)) {
|
| 285 |
+
return memo.get(spec)
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
const res = this[_testSpec](spec)
|
| 289 |
+
memo.set(spec, res)
|
| 290 |
+
return res
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
[_testSpec] (spec) {
|
| 294 |
+
for (const v of this.versions) {
|
| 295 |
+
const satisfies = semver.satisfies(v, spec, semverOpt)
|
| 296 |
+
if (!satisfies) {
|
| 297 |
+
continue
|
| 298 |
+
}
|
| 299 |
+
if (!this.testVersion(v)) {
|
| 300 |
+
return false
|
| 301 |
+
}
|
| 302 |
+
}
|
| 303 |
+
// either vulnerable, or not installable because nothing satisfied
|
| 304 |
+
// either way, best avoided.
|
| 305 |
+
return true
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
[_testVersions] (versions) {
|
| 309 |
+
if (!versions.length) {
|
| 310 |
+
return
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
// set of lists of versions
|
| 314 |
+
const versionSets = new Set()
|
| 315 |
+
versions = semver.sort(versions.map(v => semver.parse(v, semverOpt)))
|
| 316 |
+
|
| 317 |
+
// start out with the versions grouped by major and minor
|
| 318 |
+
let last = versions[0].major + '.' + versions[0].minor
|
| 319 |
+
let list = []
|
| 320 |
+
versionSets.add(list)
|
| 321 |
+
for (const v of versions) {
|
| 322 |
+
const k = v.major + '.' + v.minor
|
| 323 |
+
if (k !== last) {
|
| 324 |
+
last = k
|
| 325 |
+
list = []
|
| 326 |
+
versionSets.add(list)
|
| 327 |
+
}
|
| 328 |
+
list.push(v)
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
for (const set of versionSets) {
|
| 332 |
+
// it's common to have version lists like:
|
| 333 |
+
// 1.0.0
|
| 334 |
+
// 1.0.1-alpha.0
|
| 335 |
+
// 1.0.1-alpha.1
|
| 336 |
+
// ...
|
| 337 |
+
// 1.0.1-alpha.999
|
| 338 |
+
// 1.0.1
|
| 339 |
+
// 1.0.2-alpha.0
|
| 340 |
+
// ...
|
| 341 |
+
// 1.0.2-alpha.99
|
| 342 |
+
// 1.0.2
|
| 343 |
+
// with a huge number of prerelease versions that are not installable
|
| 344 |
+
// anyway.
|
| 345 |
+
// If mid has a prerelease tag, and set[0] does not, then walk it
|
| 346 |
+
// back until we hit a non-prerelease version
|
| 347 |
+
// If mid has a prerelease tag, and set[set.length-1] does not,
|
| 348 |
+
// then walk it forward until we hit a version without a prerelease tag
|
| 349 |
+
// Similarly, if the head/tail is a prerelease, but there is a non-pr
|
| 350 |
+
// version in the set, then start there instead.
|
| 351 |
+
let h = 0
|
| 352 |
+
const origHeadVuln = this.testVersion(set[h])
|
| 353 |
+
while (h < set.length && /-/.test(String(set[h]))) {
|
| 354 |
+
h++
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
// don't filter out the whole list! they might all be pr's
|
| 358 |
+
if (h === set.length) {
|
| 359 |
+
h = 0
|
| 360 |
+
} else if (origHeadVuln) {
|
| 361 |
+
// if the original was vulnerable, assume so are all of these
|
| 362 |
+
for (let hh = 0; hh < h; hh++) {
|
| 363 |
+
this[_markVulnerable](set[hh])
|
| 364 |
+
}
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
let t = set.length - 1
|
| 368 |
+
const origTailVuln = this.testVersion(set[t])
|
| 369 |
+
while (t > h && /-/.test(String(set[t]))) {
|
| 370 |
+
t--
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
// don't filter out the whole list! might all be pr's
|
| 374 |
+
if (t === h) {
|
| 375 |
+
t = set.length - 1
|
| 376 |
+
} else if (origTailVuln) {
|
| 377 |
+
// if original tail was vulnerable, assume these are as well
|
| 378 |
+
for (let tt = set.length - 1; tt > t; tt--) {
|
| 379 |
+
this[_markVulnerable](set[tt])
|
| 380 |
+
}
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
const headVuln = h === 0 ? origHeadVuln
|
| 384 |
+
: this.testVersion(set[h])
|
| 385 |
+
|
| 386 |
+
const tailVuln = t === set.length - 1 ? origTailVuln
|
| 387 |
+
: this.testVersion(set[t])
|
| 388 |
+
|
| 389 |
+
// if head and tail both vulnerable, whole list is thrown out
|
| 390 |
+
if (headVuln && tailVuln) {
|
| 391 |
+
for (let v = h; v < t; v++) {
|
| 392 |
+
this[_markVulnerable](set[v])
|
| 393 |
+
}
|
| 394 |
+
continue
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
// if length is 2 or 1, then we marked them all already
|
| 398 |
+
if (t < h + 2) {
|
| 399 |
+
continue
|
| 400 |
+
}
|
| 401 |
+
|
| 402 |
+
const mid = Math.floor(set.length / 2)
|
| 403 |
+
const pre = set.slice(0, mid)
|
| 404 |
+
const post = set.slice(mid)
|
| 405 |
+
|
| 406 |
+
// if the parent list wasn't prereleases, then drop pr tags
|
| 407 |
+
// from end of the pre list, and beginning of the post list,
|
| 408 |
+
// marking as vulnerable if the midpoint item we picked is.
|
| 409 |
+
if (!/-/.test(String(pre[0]))) {
|
| 410 |
+
const midVuln = this.testVersion(pre[pre.length - 1])
|
| 411 |
+
while (/-/.test(String(pre[pre.length - 1]))) {
|
| 412 |
+
const v = pre.pop()
|
| 413 |
+
if (midVuln) {
|
| 414 |
+
this[_markVulnerable](v)
|
| 415 |
+
}
|
| 416 |
+
}
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
if (!/-/.test(String(post[post.length - 1]))) {
|
| 420 |
+
const midVuln = this.testVersion(post[0])
|
| 421 |
+
while (/-/.test(String(post[0]))) {
|
| 422 |
+
const v = post.shift()
|
| 423 |
+
if (midVuln) {
|
| 424 |
+
this[_markVulnerable](v)
|
| 425 |
+
}
|
| 426 |
+
}
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
versionSets.add(pre)
|
| 430 |
+
versionSets.add(post)
|
| 431 |
+
}
|
| 432 |
+
}
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
module.exports = Advisory
|