merge code dirs 1031 (part 34)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/agent/lib/errors.js +61 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/agent/lib/index.js +56 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/agent/lib/options.js +86 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/agent/lib/proxy.js +88 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/agent/package.json +60 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/LICENSE.md +20 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/README.md +349 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/actual.js +19 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/audit.js +51 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/funding.js +38 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/ideal.js +14 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/index.js +112 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/lib/logging.js +77 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/lib/options.js +123 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/lib/print-tree.js +4 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/lib/timers.js +33 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/license.js +48 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/prune.js +48 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/reify.js +48 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/shrinkwrap.js +7 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/virtual.js +14 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/add-rm-pkg-deps.js +143 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js +1523 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/index.js +280 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/isolated-reifier.js +453 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/load-actual.js +438 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/load-virtual.js +303 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/rebuild.js +400 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js +1535 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/audit-report.js +415 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/calc-dep-flags.js +126 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/can-place-dep.js +436 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/case-insensitive-map.js +50 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/consistent-resolve.js +45 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/debug.js +32 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/deepest-nesting-target.js +18 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/dep-valid.js +150 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/diff.js +306 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/edge.js +301 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/from-path.js +30 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/gather-dep-set.js +43 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/index.js +6 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/inventory.js +138 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/link.js +126 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/node.js +1475 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/optional-set.js +38 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/override-resolves.js +11 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/override-set.js +147 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/packument-cache.js +77 -0
- tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/peer-entry-sets.js +77 -0
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/agent/lib/errors.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
class InvalidProxyProtocolError extends Error {
|
| 4 |
+
constructor (url) {
|
| 5 |
+
super(`Invalid protocol \`${url.protocol}\` connecting to proxy \`${url.host}\``)
|
| 6 |
+
this.code = 'EINVALIDPROXY'
|
| 7 |
+
this.proxy = url
|
| 8 |
+
}
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
class ConnectionTimeoutError extends Error {
|
| 12 |
+
constructor (host) {
|
| 13 |
+
super(`Timeout connecting to host \`${host}\``)
|
| 14 |
+
this.code = 'ECONNECTIONTIMEOUT'
|
| 15 |
+
this.host = host
|
| 16 |
+
}
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
class IdleTimeoutError extends Error {
|
| 20 |
+
constructor (host) {
|
| 21 |
+
super(`Idle timeout reached for host \`${host}\``)
|
| 22 |
+
this.code = 'EIDLETIMEOUT'
|
| 23 |
+
this.host = host
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
class ResponseTimeoutError extends Error {
|
| 28 |
+
constructor (request, proxy) {
|
| 29 |
+
let msg = 'Response timeout '
|
| 30 |
+
if (proxy) {
|
| 31 |
+
msg += `from proxy \`${proxy.host}\` `
|
| 32 |
+
}
|
| 33 |
+
msg += `connecting to host \`${request.host}\``
|
| 34 |
+
super(msg)
|
| 35 |
+
this.code = 'ERESPONSETIMEOUT'
|
| 36 |
+
this.proxy = proxy
|
| 37 |
+
this.request = request
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
class TransferTimeoutError extends Error {
|
| 42 |
+
constructor (request, proxy) {
|
| 43 |
+
let msg = 'Transfer timeout '
|
| 44 |
+
if (proxy) {
|
| 45 |
+
msg += `from proxy \`${proxy.host}\` `
|
| 46 |
+
}
|
| 47 |
+
msg += `for \`${request.host}\``
|
| 48 |
+
super(msg)
|
| 49 |
+
this.code = 'ETRANSFERTIMEOUT'
|
| 50 |
+
this.proxy = proxy
|
| 51 |
+
this.request = request
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
module.exports = {
|
| 56 |
+
InvalidProxyProtocolError,
|
| 57 |
+
ConnectionTimeoutError,
|
| 58 |
+
IdleTimeoutError,
|
| 59 |
+
ResponseTimeoutError,
|
| 60 |
+
TransferTimeoutError,
|
| 61 |
+
}
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/agent/lib/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const { LRUCache } = require('lru-cache')
|
| 4 |
+
const { normalizeOptions, cacheOptions } = require('./options')
|
| 5 |
+
const { getProxy, proxyCache } = require('./proxy.js')
|
| 6 |
+
const dns = require('./dns.js')
|
| 7 |
+
const Agent = require('./agents.js')
|
| 8 |
+
|
| 9 |
+
const agentCache = new LRUCache({ max: 20 })
|
| 10 |
+
|
| 11 |
+
const getAgent = (url, { agent, proxy, noProxy, ...options } = {}) => {
|
| 12 |
+
// false has meaning so this can't be a simple truthiness check
|
| 13 |
+
if (agent != null) {
|
| 14 |
+
return agent
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
url = new URL(url)
|
| 18 |
+
|
| 19 |
+
const proxyForUrl = getProxy(url, { proxy, noProxy })
|
| 20 |
+
const normalizedOptions = {
|
| 21 |
+
...normalizeOptions(options),
|
| 22 |
+
proxy: proxyForUrl,
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
const cacheKey = cacheOptions({
|
| 26 |
+
...normalizedOptions,
|
| 27 |
+
secureEndpoint: url.protocol === 'https:',
|
| 28 |
+
})
|
| 29 |
+
|
| 30 |
+
if (agentCache.has(cacheKey)) {
|
| 31 |
+
return agentCache.get(cacheKey)
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
const newAgent = new Agent(normalizedOptions)
|
| 35 |
+
agentCache.set(cacheKey, newAgent)
|
| 36 |
+
|
| 37 |
+
return newAgent
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
module.exports = {
|
| 41 |
+
getAgent,
|
| 42 |
+
Agent,
|
| 43 |
+
// these are exported for backwards compatability
|
| 44 |
+
HttpAgent: Agent,
|
| 45 |
+
HttpsAgent: Agent,
|
| 46 |
+
cache: {
|
| 47 |
+
proxy: proxyCache,
|
| 48 |
+
agent: agentCache,
|
| 49 |
+
dns: dns.cache,
|
| 50 |
+
clear: () => {
|
| 51 |
+
proxyCache.clear()
|
| 52 |
+
agentCache.clear()
|
| 53 |
+
dns.cache.clear()
|
| 54 |
+
},
|
| 55 |
+
},
|
| 56 |
+
}
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/agent/lib/options.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const dns = require('./dns')
|
| 4 |
+
|
| 5 |
+
const normalizeOptions = (opts) => {
|
| 6 |
+
const family = parseInt(opts.family ?? '0', 10)
|
| 7 |
+
const keepAlive = opts.keepAlive ?? true
|
| 8 |
+
|
| 9 |
+
const normalized = {
|
| 10 |
+
// nodejs http agent options. these are all the defaults
|
| 11 |
+
// but kept here to increase the likelihood of cache hits
|
| 12 |
+
// https://nodejs.org/api/http.html#new-agentoptions
|
| 13 |
+
keepAliveMsecs: keepAlive ? 1000 : undefined,
|
| 14 |
+
maxSockets: opts.maxSockets ?? 15,
|
| 15 |
+
maxTotalSockets: Infinity,
|
| 16 |
+
maxFreeSockets: keepAlive ? 256 : undefined,
|
| 17 |
+
scheduling: 'fifo',
|
| 18 |
+
// then spread the rest of the options
|
| 19 |
+
...opts,
|
| 20 |
+
// we already set these to their defaults that we want
|
| 21 |
+
family,
|
| 22 |
+
keepAlive,
|
| 23 |
+
// our custom timeout options
|
| 24 |
+
timeouts: {
|
| 25 |
+
// the standard timeout option is mapped to our idle timeout
|
| 26 |
+
// and then deleted below
|
| 27 |
+
idle: opts.timeout ?? 0,
|
| 28 |
+
connection: 0,
|
| 29 |
+
response: 0,
|
| 30 |
+
transfer: 0,
|
| 31 |
+
...opts.timeouts,
|
| 32 |
+
},
|
| 33 |
+
// get the dns options that go at the top level of socket connection
|
| 34 |
+
...dns.getOptions({ family, ...opts.dns }),
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
// remove timeout since we already used it to set our own idle timeout
|
| 38 |
+
delete normalized.timeout
|
| 39 |
+
|
| 40 |
+
return normalized
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
const createKey = (obj) => {
|
| 44 |
+
let key = ''
|
| 45 |
+
const sorted = Object.entries(obj).sort((a, b) => a[0] - b[0])
|
| 46 |
+
for (let [k, v] of sorted) {
|
| 47 |
+
if (v == null) {
|
| 48 |
+
v = 'null'
|
| 49 |
+
} else if (v instanceof URL) {
|
| 50 |
+
v = v.toString()
|
| 51 |
+
} else if (typeof v === 'object') {
|
| 52 |
+
v = createKey(v)
|
| 53 |
+
}
|
| 54 |
+
key += `${k}:${v}:`
|
| 55 |
+
}
|
| 56 |
+
return key
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
const cacheOptions = ({ secureEndpoint, ...options }) => createKey({
|
| 60 |
+
secureEndpoint: !!secureEndpoint,
|
| 61 |
+
// socket connect options
|
| 62 |
+
family: options.family,
|
| 63 |
+
hints: options.hints,
|
| 64 |
+
localAddress: options.localAddress,
|
| 65 |
+
// tls specific connect options
|
| 66 |
+
strictSsl: secureEndpoint ? !!options.rejectUnauthorized : false,
|
| 67 |
+
ca: secureEndpoint ? options.ca : null,
|
| 68 |
+
cert: secureEndpoint ? options.cert : null,
|
| 69 |
+
key: secureEndpoint ? options.key : null,
|
| 70 |
+
// http agent options
|
| 71 |
+
keepAlive: options.keepAlive,
|
| 72 |
+
keepAliveMsecs: options.keepAliveMsecs,
|
| 73 |
+
maxSockets: options.maxSockets,
|
| 74 |
+
maxTotalSockets: options.maxTotalSockets,
|
| 75 |
+
maxFreeSockets: options.maxFreeSockets,
|
| 76 |
+
scheduling: options.scheduling,
|
| 77 |
+
// timeout options
|
| 78 |
+
timeouts: options.timeouts,
|
| 79 |
+
// proxy
|
| 80 |
+
proxy: options.proxy,
|
| 81 |
+
})
|
| 82 |
+
|
| 83 |
+
module.exports = {
|
| 84 |
+
normalizeOptions,
|
| 85 |
+
cacheOptions,
|
| 86 |
+
}
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/agent/lib/proxy.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const { HttpProxyAgent } = require('http-proxy-agent')
|
| 4 |
+
const { HttpsProxyAgent } = require('https-proxy-agent')
|
| 5 |
+
const { SocksProxyAgent } = require('socks-proxy-agent')
|
| 6 |
+
const { LRUCache } = require('lru-cache')
|
| 7 |
+
const { InvalidProxyProtocolError } = require('./errors.js')
|
| 8 |
+
|
| 9 |
+
const PROXY_CACHE = new LRUCache({ max: 20 })
|
| 10 |
+
|
| 11 |
+
const SOCKS_PROTOCOLS = new Set(SocksProxyAgent.protocols)
|
| 12 |
+
|
| 13 |
+
const PROXY_ENV_KEYS = new Set(['https_proxy', 'http_proxy', 'proxy', 'no_proxy'])
|
| 14 |
+
|
| 15 |
+
const PROXY_ENV = Object.entries(process.env).reduce((acc, [key, value]) => {
|
| 16 |
+
key = key.toLowerCase()
|
| 17 |
+
if (PROXY_ENV_KEYS.has(key)) {
|
| 18 |
+
acc[key] = value
|
| 19 |
+
}
|
| 20 |
+
return acc
|
| 21 |
+
}, {})
|
| 22 |
+
|
| 23 |
+
const getProxyAgent = (url) => {
|
| 24 |
+
url = new URL(url)
|
| 25 |
+
|
| 26 |
+
const protocol = url.protocol.slice(0, -1)
|
| 27 |
+
if (SOCKS_PROTOCOLS.has(protocol)) {
|
| 28 |
+
return SocksProxyAgent
|
| 29 |
+
}
|
| 30 |
+
if (protocol === 'https' || protocol === 'http') {
|
| 31 |
+
return [HttpProxyAgent, HttpsProxyAgent]
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
throw new InvalidProxyProtocolError(url)
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
const isNoProxy = (url, noProxy) => {
|
| 38 |
+
if (typeof noProxy === 'string') {
|
| 39 |
+
noProxy = noProxy.split(',').map((p) => p.trim()).filter(Boolean)
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
if (!noProxy || !noProxy.length) {
|
| 43 |
+
return false
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
const hostSegments = url.hostname.split('.').reverse()
|
| 47 |
+
|
| 48 |
+
return noProxy.some((no) => {
|
| 49 |
+
const noSegments = no.split('.').filter(Boolean).reverse()
|
| 50 |
+
if (!noSegments.length) {
|
| 51 |
+
return false
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
for (let i = 0; i < noSegments.length; i++) {
|
| 55 |
+
if (hostSegments[i] !== noSegments[i]) {
|
| 56 |
+
return false
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
return true
|
| 61 |
+
})
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
const getProxy = (url, { proxy, noProxy }) => {
|
| 65 |
+
url = new URL(url)
|
| 66 |
+
|
| 67 |
+
if (!proxy) {
|
| 68 |
+
proxy = url.protocol === 'https:'
|
| 69 |
+
? PROXY_ENV.https_proxy
|
| 70 |
+
: PROXY_ENV.https_proxy || PROXY_ENV.http_proxy || PROXY_ENV.proxy
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
if (!noProxy) {
|
| 74 |
+
noProxy = PROXY_ENV.no_proxy
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
if (!proxy || isNoProxy(url, noProxy)) {
|
| 78 |
+
return null
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
return new URL(proxy)
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
module.exports = {
|
| 85 |
+
getProxyAgent,
|
| 86 |
+
getProxy,
|
| 87 |
+
proxyCache: PROXY_CACHE,
|
| 88 |
+
}
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/agent/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@npmcli/agent",
|
| 3 |
+
"version": "3.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": "^18.17.0 || >=20.5.0"
|
| 29 |
+
},
|
| 30 |
+
"templateOSS": {
|
| 31 |
+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
| 32 |
+
"version": "4.23.1",
|
| 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": "^10.0.1",
|
| 40 |
+
"socks-proxy-agent": "^8.0.3"
|
| 41 |
+
},
|
| 42 |
+
"devDependencies": {
|
| 43 |
+
"@npmcli/eslint-config": "^5.0.0",
|
| 44 |
+
"@npmcli/template-oss": "4.23.1",
|
| 45 |
+
"minipass-fetch": "^3.0.3",
|
| 46 |
+
"nock": "^13.2.7",
|
| 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 |
+
}
|
tools/node-v22.19.0-linux-x64/lib/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.
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/README.md
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
```
|
| 271 |
+
| extraneous | peer | dev | optional | devOptional | meaning | prune? |
|
| 272 |
+
|------------+------+-----+----------+-------------+---------------------+-------------------|
|
| 273 |
+
| | | | | | production dep | never |
|
| 274 |
+
|------------+------+-----+----------+-------------+---------------------+-------------------|
|
| 275 |
+
| X | N/A | N/A | N/A | N/A | nothing depends on | always |
|
| 276 |
+
| | | | | | this, it is trash | |
|
| 277 |
+
|------------+------+-----+----------+-------------+---------------------+-------------------|
|
| 278 |
+
| | | X | | X | devDependency, or | if pruning dev |
|
| 279 |
+
| | | | | not in lock | only depended upon | |
|
| 280 |
+
| | | | | | by devDependencies | |
|
| 281 |
+
|------------+------+-----+----------+-------------+---------------------+-------------------|
|
| 282 |
+
| | | | X | X | optionalDependency, | if pruning |
|
| 283 |
+
| | | | | not in lock | or only depended on | optional |
|
| 284 |
+
| | | | | | by optionalDeps | |
|
| 285 |
+
|------------+------+-----+----------+-------------+---------------------+-------------------|
|
| 286 |
+
| | | X | X | X | Optional dependency | if pruning EITHER |
|
| 287 |
+
| | | | | not in lock | of dep(s) in the | dev OR optional |
|
| 288 |
+
| | | | | | dev hierarchy | |
|
| 289 |
+
|------------+------+-----+----------+-------------+---------------------+-------------------|
|
| 290 |
+
| | | | | X | BOTH a non-optional | if pruning BOTH |
|
| 291 |
+
| | | | | in lock | dep within the dev | dev AND optional |
|
| 292 |
+
| | | | | | hierarchy, AND a | |
|
| 293 |
+
| | | | | | dep within the | |
|
| 294 |
+
| | | | | | optional hierarchy | |
|
| 295 |
+
|------------+------+-----+----------+-------------+---------------------+-------------------|
|
| 296 |
+
| | X | | | | peer dependency, or | if pruning peers |
|
| 297 |
+
| | | | | | only depended on by | |
|
| 298 |
+
| | | | | | peer dependencies | |
|
| 299 |
+
|------------+------+-----+----------+-------------+---------------------+-------------------|
|
| 300 |
+
| | X | X | | X | peer dependency of | if pruning peer |
|
| 301 |
+
| | | | | not in lock | dev node hierarchy | OR dev deps |
|
| 302 |
+
|------------+------+-----+----------+-------------+---------------------+-------------------|
|
| 303 |
+
| | X | | X | X | peer dependency of | if pruning peer |
|
| 304 |
+
| | | | | not in lock | optional nodes, or | OR optional deps |
|
| 305 |
+
| | | | | | peerOptional dep | |
|
| 306 |
+
|------------+------+-----+----------+-------------+---------------------+-------------------|
|
| 307 |
+
| | X | X | X | X | peer optional deps | if pruning peer |
|
| 308 |
+
| | | | | not in lock | of the dev dep | OR optional OR |
|
| 309 |
+
| | | | | | hierarchy | dev |
|
| 310 |
+
|------------+------+-----+----------+-------------+---------------------+-------------------|
|
| 311 |
+
| | X | | | X | BOTH a non-optional | if pruning peers |
|
| 312 |
+
| | | | | in lock | peer dep within the | OR: |
|
| 313 |
+
| | | | | | dev hierarchy, AND | BOTH optional |
|
| 314 |
+
| | | | | | a peer optional dep | AND dev deps |
|
| 315 |
+
+------------+------+-----+----------+-------------+---------------------+-------------------+
|
| 316 |
+
```
|
| 317 |
+
|
| 318 |
+
* If none of these flags are set, then the node is required by the
|
| 319 |
+
dependency and/or peerDependency hierarchy. It should not be pruned.
|
| 320 |
+
* If _both_ `node.dev` and `node.optional` are set, then the node is an
|
| 321 |
+
optional dependency of one of the packages in the devDependency
|
| 322 |
+
hierarchy. It should be pruned if _either_ dev or optional deps are
|
| 323 |
+
being removed.
|
| 324 |
+
* If `node.dev` is set, but `node.optional` is not, then the node is
|
| 325 |
+
required in the devDependency hierarchy. It should be pruned if dev
|
| 326 |
+
dependencies are being removed.
|
| 327 |
+
* If `node.optional` is set, but `node.dev` is not, then the node is
|
| 328 |
+
required in the optionalDependency hierarchy. It should be pruned if
|
| 329 |
+
optional dependencies are being removed.
|
| 330 |
+
* If `node.devOptional` is set, then the node is a (non-optional)
|
| 331 |
+
dependency within the devDependency hierarchy, _and_ a dependency
|
| 332 |
+
within the `optionalDependency` hierarchy. It should be pruned if
|
| 333 |
+
_both_ dev and optional dependencies are being removed.
|
| 334 |
+
* If `node.peer` is set, then all the same semantics apply as above, except
|
| 335 |
+
that the dep is brought in by a peer dep at some point, rather than a
|
| 336 |
+
normal non-peer dependency.
|
| 337 |
+
|
| 338 |
+
Note: `devOptional` is only set in the shrinkwrap/package-lock file if
|
| 339 |
+
_neither_ `dev` nor `optional` are set, as it would be redundant.
|
| 340 |
+
|
| 341 |
+
## BIN
|
| 342 |
+
|
| 343 |
+
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.
|
| 344 |
+
|
| 345 |
+
To see the usage run:
|
| 346 |
+
|
| 347 |
+
```
|
| 348 |
+
npx @npmcli/arborist --help
|
| 349 |
+
```
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/actual.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const Arborist = require('../')
|
| 2 |
+
|
| 3 |
+
const printTree = require('./lib/print-tree.js')
|
| 4 |
+
|
| 5 |
+
module.exports = (options, time) => new Arborist(options)
|
| 6 |
+
.loadActual(options)
|
| 7 |
+
.then(time)
|
| 8 |
+
.then(async ({ timing, result: tree }) => {
|
| 9 |
+
printTree(tree)
|
| 10 |
+
if (options.save) {
|
| 11 |
+
await tree.meta.save()
|
| 12 |
+
}
|
| 13 |
+
if (options.saveHidden) {
|
| 14 |
+
tree.meta.hiddenLockfile = true
|
| 15 |
+
tree.meta.filename = options.path + '/node_modules/.package-lock.json'
|
| 16 |
+
await tree.meta.save()
|
| 17 |
+
}
|
| 18 |
+
return `read ${tree.inventory.size} deps in ${timing.ms}`
|
| 19 |
+
})
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/audit.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const Arborist = require('../')
|
| 2 |
+
|
| 3 |
+
const printTree = require('./lib/print-tree.js')
|
| 4 |
+
const log = require('./lib/logging.js')
|
| 5 |
+
|
| 6 |
+
const Vuln = require('../lib/vuln.js')
|
| 7 |
+
const printReport = report => {
|
| 8 |
+
for (const vuln of report.values()) {
|
| 9 |
+
log.info(printVuln(vuln))
|
| 10 |
+
}
|
| 11 |
+
if (report.topVulns.size) {
|
| 12 |
+
log.info('\n# top-level vulnerabilities')
|
| 13 |
+
for (const vuln of report.topVulns.values()) {
|
| 14 |
+
log.info(printVuln(vuln))
|
| 15 |
+
}
|
| 16 |
+
}
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
const printVuln = vuln => {
|
| 20 |
+
return {
|
| 21 |
+
__proto__: { constructor: Vuln },
|
| 22 |
+
name: vuln.name,
|
| 23 |
+
issues: [...vuln.advisories].map(a => printAdvisory(a)),
|
| 24 |
+
range: vuln.simpleRange,
|
| 25 |
+
nodes: [...vuln.nodes].map(node => `${node.name} ${node.location || '#ROOT'}`),
|
| 26 |
+
...(vuln.topNodes.size === 0 ? {} : {
|
| 27 |
+
topNodes: [...vuln.topNodes].map(node => `${node.location || '#ROOT'}`),
|
| 28 |
+
}),
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
const printAdvisory = a => `${a.title}${a.url ? ' ' + a.url : ''}`
|
| 33 |
+
|
| 34 |
+
module.exports = (options, time) => {
|
| 35 |
+
const arb = new Arborist(options)
|
| 36 |
+
return arb
|
| 37 |
+
.audit(options)
|
| 38 |
+
.then(time)
|
| 39 |
+
.then(async ({ timing, result: tree }) => {
|
| 40 |
+
if (options.fix) {
|
| 41 |
+
printTree(tree)
|
| 42 |
+
}
|
| 43 |
+
printReport(arb.auditReport)
|
| 44 |
+
if (tree.meta && options.save) {
|
| 45 |
+
await tree.meta.save()
|
| 46 |
+
}
|
| 47 |
+
return options.fix
|
| 48 |
+
? `resolved ${tree.inventory.size} deps in ${timing.seconds}`
|
| 49 |
+
: `done in ${timing.seconds}`
|
| 50 |
+
})
|
| 51 |
+
}
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/funding.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const Arborist = require('../')
|
| 2 |
+
|
| 3 |
+
const log = require('./lib/logging.js')
|
| 4 |
+
|
| 5 |
+
module.exports = (options, time) => {
|
| 6 |
+
const query = options._.shift()
|
| 7 |
+
const a = new Arborist(options)
|
| 8 |
+
return a
|
| 9 |
+
.loadVirtual()
|
| 10 |
+
.then(tree => {
|
| 11 |
+
// only load the actual tree if the virtual one doesn't have modern metadata
|
| 12 |
+
if (!tree.meta || !(tree.meta.originalLockfileVersion >= 2)) {
|
| 13 |
+
log.error('old metadata, load actual')
|
| 14 |
+
throw 'load actual'
|
| 15 |
+
} else {
|
| 16 |
+
log.error('meta ok, return virtual tree')
|
| 17 |
+
return tree
|
| 18 |
+
}
|
| 19 |
+
})
|
| 20 |
+
.catch(() => a.loadActual())
|
| 21 |
+
.then(time)
|
| 22 |
+
.then(({ timing, result: tree }) => {
|
| 23 |
+
if (!query) {
|
| 24 |
+
for (const node of tree.inventory.values()) {
|
| 25 |
+
if (node.package.funding) {
|
| 26 |
+
log.info(node.name, node.location, node.package.funding)
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
} else {
|
| 30 |
+
for (const node of tree.inventory.query('name', query)) {
|
| 31 |
+
if (node.package.funding) {
|
| 32 |
+
log.info(node.name, node.location, node.package.funding)
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
return `read ${tree.inventory.size} deps in ${timing.ms}`
|
| 37 |
+
})
|
| 38 |
+
}
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/ideal.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const Arborist = require('../')
|
| 2 |
+
|
| 3 |
+
const printTree = require('./lib/print-tree.js')
|
| 4 |
+
|
| 5 |
+
module.exports = (options, time) => new Arborist(options)
|
| 6 |
+
.buildIdealTree(options)
|
| 7 |
+
.then(time)
|
| 8 |
+
.then(async ({ timing, result: tree }) => {
|
| 9 |
+
printTree(tree)
|
| 10 |
+
if (tree.meta && options.save) {
|
| 11 |
+
await tree.meta.save()
|
| 12 |
+
}
|
| 13 |
+
return `resolved ${tree.inventory.size} deps in ${timing.seconds}`
|
| 14 |
+
})
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/index.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env node
|
| 2 |
+
|
| 3 |
+
const fs = require('node:fs')
|
| 4 |
+
const path = require('node:path')
|
| 5 |
+
const { time } = require('proc-log')
|
| 6 |
+
|
| 7 |
+
const { bin, arb: options } = require('./lib/options')
|
| 8 |
+
const version = require('../package.json').version
|
| 9 |
+
|
| 10 |
+
const usage = (message = '') => `Arborist - the npm tree doctor
|
| 11 |
+
|
| 12 |
+
Version: ${version}
|
| 13 |
+
${message && '\n' + message + '\n'}
|
| 14 |
+
# USAGE
|
| 15 |
+
arborist <cmd> [path] [options...]
|
| 16 |
+
|
| 17 |
+
# COMMANDS
|
| 18 |
+
|
| 19 |
+
* reify: reify ideal tree to node_modules (install, update, rm, ...)
|
| 20 |
+
* prune: prune the ideal tree and reify (like npm prune)
|
| 21 |
+
* ideal: generate and print the ideal tree
|
| 22 |
+
* actual: read and print the actual tree in node_modules
|
| 23 |
+
* virtual: read and print the virtual tree in the local shrinkwrap file
|
| 24 |
+
* shrinkwrap: load a local shrinkwrap and print its data
|
| 25 |
+
* audit: perform a security audit on project dependencies
|
| 26 |
+
* funding: query funding information in the local package tree. A second
|
| 27 |
+
positional argument after the path name can limit to a package name.
|
| 28 |
+
* license: query license information in the local package tree. A second
|
| 29 |
+
positional argument after the path name can limit to a license type.
|
| 30 |
+
* help: print this text
|
| 31 |
+
* version: print the version
|
| 32 |
+
|
| 33 |
+
# OPTIONS
|
| 34 |
+
|
| 35 |
+
Most npm options are supported, but in camelCase rather than css-case. For
|
| 36 |
+
example, instead of '--dry-run', use '--dryRun'.
|
| 37 |
+
|
| 38 |
+
Additionally:
|
| 39 |
+
|
| 40 |
+
* --loglevel=warn|--quiet will supppress the printing of package trees
|
| 41 |
+
* --logfile <file|bool> will output logs to a file
|
| 42 |
+
* --timing will show timing information
|
| 43 |
+
* Instead of 'npm install <pkg>', use 'arborist reify --add=<pkg>'.
|
| 44 |
+
The '--add=<pkg>' option can be specified multiple times.
|
| 45 |
+
* Instead of 'npm rm <pkg>', use 'arborist reify --rm=<pkg>'.
|
| 46 |
+
The '--rm=<pkg>' option can be specified multiple times.
|
| 47 |
+
* Instead of 'npm update', use 'arborist reify --update-all'.
|
| 48 |
+
* 'npm audit fix' is 'arborist audit --fix'
|
| 49 |
+
`
|
| 50 |
+
|
| 51 |
+
const commands = {
|
| 52 |
+
version: () => console.log(version),
|
| 53 |
+
help: () => console.log(usage()),
|
| 54 |
+
exit: () => {
|
| 55 |
+
process.exitCode = 1
|
| 56 |
+
console.error(
|
| 57 |
+
usage(`Error: command '${bin.command}' does not exist.`)
|
| 58 |
+
)
|
| 59 |
+
},
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
const commandFiles = fs.readdirSync(__dirname).filter((f) => path.extname(f) === '.js' && f !== __filename)
|
| 63 |
+
|
| 64 |
+
for (const file of commandFiles) {
|
| 65 |
+
const command = require(`./${file}`)
|
| 66 |
+
const name = path.basename(file, '.js')
|
| 67 |
+
const totalTime = `bin:${name}:init`
|
| 68 |
+
const scriptTime = `bin:${name}:script`
|
| 69 |
+
|
| 70 |
+
commands[name] = () => {
|
| 71 |
+
const timers = require('./lib/timers')
|
| 72 |
+
const log = require('./lib/logging')
|
| 73 |
+
|
| 74 |
+
log.info(name, options)
|
| 75 |
+
|
| 76 |
+
const timeEnd = time.start(totalTime)
|
| 77 |
+
const scriptEnd = time.start(scriptTime)
|
| 78 |
+
|
| 79 |
+
return command(options, (result) => {
|
| 80 |
+
scriptEnd()
|
| 81 |
+
return {
|
| 82 |
+
result,
|
| 83 |
+
timing: {
|
| 84 |
+
seconds: `${timers.get(scriptTime) / 1e9}s`,
|
| 85 |
+
ms: `${timers.get(scriptTime) / 1e6}ms`,
|
| 86 |
+
},
|
| 87 |
+
}
|
| 88 |
+
})
|
| 89 |
+
.then((result) => {
|
| 90 |
+
log.info(result)
|
| 91 |
+
return result
|
| 92 |
+
})
|
| 93 |
+
.catch((err) => {
|
| 94 |
+
process.exitCode = 1
|
| 95 |
+
log.error(err)
|
| 96 |
+
return err
|
| 97 |
+
})
|
| 98 |
+
.then((r) => {
|
| 99 |
+
timeEnd()
|
| 100 |
+
if (bin.loglevel !== 'silent') {
|
| 101 |
+
console[process.exitCode ? 'error' : 'log'](r)
|
| 102 |
+
}
|
| 103 |
+
return r
|
| 104 |
+
})
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
if (commands[bin.command]) {
|
| 109 |
+
commands[bin.command]()
|
| 110 |
+
} else {
|
| 111 |
+
commands.exit()
|
| 112 |
+
}
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/lib/logging.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const { log } = require('proc-log')
|
| 2 |
+
const fs = require('node:fs')
|
| 3 |
+
const { dirname } = require('node:path')
|
| 4 |
+
const os = require('node:os')
|
| 5 |
+
const { inspect, format } = require('node:util')
|
| 6 |
+
|
| 7 |
+
const { bin: options } = require('./options.js')
|
| 8 |
+
|
| 9 |
+
// add a meta method to proc-log for passing optional
|
| 10 |
+
// metadata through to log handlers
|
| 11 |
+
const META = Symbol('meta')
|
| 12 |
+
const parseArgs = (...args) => {
|
| 13 |
+
const { [META]: isMeta } = args[args.length - 1] || {}
|
| 14 |
+
return isMeta
|
| 15 |
+
? [args[args.length - 1], ...args.slice(0, args.length - 1)]
|
| 16 |
+
: [{}, ...args]
|
| 17 |
+
}
|
| 18 |
+
log.meta = (meta = {}) => ({ [META]: true, ...meta })
|
| 19 |
+
|
| 20 |
+
const levels = new Map([
|
| 21 |
+
'silly',
|
| 22 |
+
'verbose',
|
| 23 |
+
'info',
|
| 24 |
+
'http',
|
| 25 |
+
'notice',
|
| 26 |
+
'warn',
|
| 27 |
+
'error',
|
| 28 |
+
'silent',
|
| 29 |
+
].map((level, index) => [level, index]))
|
| 30 |
+
|
| 31 |
+
const addLogListener = (write, { eol = os.EOL, loglevel = 'silly', colors = false } = {}) => {
|
| 32 |
+
const levelIndex = levels.get(loglevel)
|
| 33 |
+
|
| 34 |
+
const magenta = m => colors ? `\x1B[35m${m}\x1B[39m` : m
|
| 35 |
+
const dim = m => colors ? `\x1B[2m${m}\x1B[22m` : m
|
| 36 |
+
const red = m => colors ? `\x1B[31m${m}\x1B[39m` : m
|
| 37 |
+
|
| 38 |
+
const formatter = (level, ...args) => {
|
| 39 |
+
const depth = level === 'error' && args[0] && args[0].code === 'ERESOLVE' ? Infinity : 10
|
| 40 |
+
|
| 41 |
+
if (level === 'info' && args[0] === 'timeEnd') {
|
| 42 |
+
args[1] = dim(args[1])
|
| 43 |
+
} else if (level === 'error' && args[0] === 'timeError') {
|
| 44 |
+
args[1] = red(args[1])
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
const messages = args.map(a => typeof a === 'string' ? a : inspect(a, { depth, colors }))
|
| 48 |
+
const pref = `${process.pid} ${magenta(level)} `
|
| 49 |
+
|
| 50 |
+
return pref + format(...messages).trim().split('\n').join(`${eol}${pref}`) + eol
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
process.on('log', (...args) => {
|
| 54 |
+
const [meta, level, ...logArgs] = parseArgs(...args)
|
| 55 |
+
|
| 56 |
+
if (levelIndex <= levels.get(level) || meta.force) {
|
| 57 |
+
write(formatter(level, ...logArgs))
|
| 58 |
+
}
|
| 59 |
+
})
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
if (options.loglevel !== 'silent') {
|
| 63 |
+
addLogListener((v) => process.stderr.write(v), {
|
| 64 |
+
eol: '\n',
|
| 65 |
+
colors: options.colors,
|
| 66 |
+
loglevel: options.loglevel,
|
| 67 |
+
})
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
if (options.logfile) {
|
| 71 |
+
log.silly('logfile', options.logfile)
|
| 72 |
+
fs.mkdirSync(dirname(options.logfile), { recursive: true })
|
| 73 |
+
const fd = fs.openSync(options.logfile, 'a')
|
| 74 |
+
addLogListener((str) => fs.writeSync(fd, str))
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
module.exports = log
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/lib/options.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const nopt = require('nopt')
|
| 2 |
+
const path = require('node:path')
|
| 3 |
+
|
| 4 |
+
const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k)
|
| 5 |
+
|
| 6 |
+
const cleanPath = (val) => {
|
| 7 |
+
const k = Symbol('key')
|
| 8 |
+
const data = {}
|
| 9 |
+
nopt.typeDefs.path.validate(data, k, val)
|
| 10 |
+
return data[k]
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
const parse = (...noptArgs) => {
|
| 14 |
+
const binOnlyOpts = {
|
| 15 |
+
command: String,
|
| 16 |
+
loglevel: String,
|
| 17 |
+
colors: Boolean,
|
| 18 |
+
timing: ['always', Boolean],
|
| 19 |
+
logfile: String,
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
const arbOpts = {
|
| 23 |
+
add: Array,
|
| 24 |
+
rm: Array,
|
| 25 |
+
omit: Array,
|
| 26 |
+
update: Array,
|
| 27 |
+
workspaces: Array,
|
| 28 |
+
global: Boolean,
|
| 29 |
+
force: Boolean,
|
| 30 |
+
'global-style': Boolean,
|
| 31 |
+
'prefer-dedupe': Boolean,
|
| 32 |
+
'legacy-peer-deps': Boolean,
|
| 33 |
+
'update-all': Boolean,
|
| 34 |
+
before: Date,
|
| 35 |
+
path: path,
|
| 36 |
+
cache: path,
|
| 37 |
+
...binOnlyOpts,
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
const short = {
|
| 41 |
+
quiet: ['--loglevel', 'warn'],
|
| 42 |
+
logs: ['--logfile', 'true'],
|
| 43 |
+
w: '--workspaces',
|
| 44 |
+
g: '--global',
|
| 45 |
+
f: '--force',
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
const defaults = {
|
| 49 |
+
// key order is important for command and path
|
| 50 |
+
// since they shift positional args
|
| 51 |
+
// command is 1st, path is 2nd
|
| 52 |
+
command: (o) => o.argv.remain.shift(),
|
| 53 |
+
path: (o) => cleanPath(o.argv.remain.shift() || '.'),
|
| 54 |
+
colors: has(process.env, 'NO_COLOR') ? false : !!process.stderr.isTTY,
|
| 55 |
+
loglevel: 'silly',
|
| 56 |
+
timing: (o) => o.loglevel === 'silly',
|
| 57 |
+
cache: `${process.env.HOME}/.npm/_cacache`,
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
const derived = [
|
| 61 |
+
// making update either `all` or an array of names but not both
|
| 62 |
+
({ updateAll: all, update: names, ...o }) => {
|
| 63 |
+
if (all || names) {
|
| 64 |
+
o.update = all != null ? { all } : { names }
|
| 65 |
+
}
|
| 66 |
+
return o
|
| 67 |
+
},
|
| 68 |
+
({ logfile, ...o }) => {
|
| 69 |
+
// logfile is parsed as a string so if its true or set but empty
|
| 70 |
+
// then set the default logfile
|
| 71 |
+
if (logfile === 'true' || logfile === '') {
|
| 72 |
+
logfile = `arb-log-${new Date().toISOString().replace(/[.:]/g, '_')}.log`
|
| 73 |
+
}
|
| 74 |
+
// then parse it the same as nopt parses other paths
|
| 75 |
+
if (logfile) {
|
| 76 |
+
o.logfile = cleanPath(logfile)
|
| 77 |
+
}
|
| 78 |
+
return o
|
| 79 |
+
},
|
| 80 |
+
]
|
| 81 |
+
|
| 82 |
+
const transforms = [
|
| 83 |
+
// Camelcase all top level keys
|
| 84 |
+
(o) => {
|
| 85 |
+
const entries = Object.entries(o).map(([k, v]) => [
|
| 86 |
+
k.replace(/-./g, s => s[1].toUpperCase()),
|
| 87 |
+
v,
|
| 88 |
+
])
|
| 89 |
+
return Object.fromEntries(entries)
|
| 90 |
+
},
|
| 91 |
+
// Set defaults on unset keys
|
| 92 |
+
(o) => {
|
| 93 |
+
for (const [k, v] of Object.entries(defaults)) {
|
| 94 |
+
if (!has(o, k)) {
|
| 95 |
+
o[k] = typeof v === 'function' ? v(o) : v
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
return o
|
| 99 |
+
},
|
| 100 |
+
// Set/unset derived values
|
| 101 |
+
...derived.map((derive) => (o) => derive(o) || o),
|
| 102 |
+
// Separate bin and arborist options
|
| 103 |
+
({ argv: { remain: _ }, ...o }) => {
|
| 104 |
+
const bin = { _ }
|
| 105 |
+
for (const k of Object.keys(binOnlyOpts)) {
|
| 106 |
+
if (has(o, k)) {
|
| 107 |
+
bin[k] = o[k]
|
| 108 |
+
delete o[k]
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
return { bin, arb: o }
|
| 112 |
+
},
|
| 113 |
+
]
|
| 114 |
+
|
| 115 |
+
let options = nopt(arbOpts, short, ...noptArgs)
|
| 116 |
+
for (const t of transforms) {
|
| 117 |
+
options = t(options)
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
return options
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
module.exports = parse()
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/lib/print-tree.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const { inspect } = require('node:util')
|
| 2 |
+
const log = require('./logging.js')
|
| 3 |
+
|
| 4 |
+
module.exports = tree => log.info(inspect(tree.toJSON(), { depth: Infinity }))
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/lib/timers.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const { bin: options } = require('./options.js')
|
| 2 |
+
const log = require('./logging.js')
|
| 3 |
+
|
| 4 |
+
const timers = new Map()
|
| 5 |
+
const finished = new Map()
|
| 6 |
+
|
| 7 |
+
process.on('time', (level, name) => {
|
| 8 |
+
if (level === 'start') {
|
| 9 |
+
if (timers.has(name)) {
|
| 10 |
+
throw new Error('conflicting timer! ' + name)
|
| 11 |
+
}
|
| 12 |
+
timers.set(name, process.hrtime.bigint())
|
| 13 |
+
} else if (level === 'end') {
|
| 14 |
+
if (!timers.has(name)) {
|
| 15 |
+
throw new Error('timer not started! ' + name)
|
| 16 |
+
}
|
| 17 |
+
const elapsed = Number(process.hrtime.bigint() - timers.get(name))
|
| 18 |
+
timers.delete(name)
|
| 19 |
+
finished.set(name, elapsed)
|
| 20 |
+
if (options.timing) {
|
| 21 |
+
log.info('timeEnd', `${name} ${elapsed / 1e9}s`, log.meta({ force: options.timing === 'always' }))
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
})
|
| 25 |
+
|
| 26 |
+
process.on('exit', () => {
|
| 27 |
+
for (const name of timers.keys()) {
|
| 28 |
+
log.error('timeError', 'Dangling timer:', name)
|
| 29 |
+
process.exitCode = 1
|
| 30 |
+
}
|
| 31 |
+
})
|
| 32 |
+
|
| 33 |
+
module.exports = finished
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/license.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const localeCompare = require('@isaacs/string-locale-compare')('en')
|
| 2 |
+
const Arborist = require('../')
|
| 3 |
+
const log = require('./lib/logging.js')
|
| 4 |
+
|
| 5 |
+
module.exports = (options, time) => {
|
| 6 |
+
const query = options._.shift()
|
| 7 |
+
const a = new Arborist(options)
|
| 8 |
+
return a
|
| 9 |
+
.loadVirtual()
|
| 10 |
+
.then(tree => {
|
| 11 |
+
// only load the actual tree if the virtual one doesn't have modern metadata
|
| 12 |
+
if (!tree.meta || !(tree.meta.originalLockfileVersion >= 2)) {
|
| 13 |
+
throw 'load actual'
|
| 14 |
+
} else {
|
| 15 |
+
return tree
|
| 16 |
+
}
|
| 17 |
+
}).catch((er) => {
|
| 18 |
+
log.error('loading actual tree', er)
|
| 19 |
+
return a.loadActual()
|
| 20 |
+
})
|
| 21 |
+
.then(time)
|
| 22 |
+
.then(({ result: tree }) => {
|
| 23 |
+
const output = []
|
| 24 |
+
if (!query) {
|
| 25 |
+
const set = []
|
| 26 |
+
for (const license of tree.inventory.query('license')) {
|
| 27 |
+
set.push([tree.inventory.query('license', license).size, license])
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
for (const [count, license] of set.sort((a, b) =>
|
| 31 |
+
a[1] && b[1] ? b[0] - a[0] || localeCompare(a[1], b[1])
|
| 32 |
+
: a[1] ? -1
|
| 33 |
+
: b[1] ? 1
|
| 34 |
+
: 0)) {
|
| 35 |
+
output.push(`${count} ${license}`)
|
| 36 |
+
log.info(count, license)
|
| 37 |
+
}
|
| 38 |
+
} else {
|
| 39 |
+
for (const node of tree.inventory.query('license', query === 'undefined' ? undefined : query)) {
|
| 40 |
+
const msg = `${node.name} ${node.location} ${node.package.description || ''}`
|
| 41 |
+
output.push(msg)
|
| 42 |
+
log.info(msg)
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
return output.join('\n')
|
| 47 |
+
})
|
| 48 |
+
}
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/prune.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const Arborist = require('../')
|
| 2 |
+
|
| 3 |
+
const printTree = require('./lib/print-tree.js')
|
| 4 |
+
const log = require('./lib/logging.js')
|
| 5 |
+
|
| 6 |
+
const printDiff = diff => {
|
| 7 |
+
const { depth } = require('treeverse')
|
| 8 |
+
depth({
|
| 9 |
+
tree: diff,
|
| 10 |
+
visit: d => {
|
| 11 |
+
if (d.location === '') {
|
| 12 |
+
return
|
| 13 |
+
}
|
| 14 |
+
switch (d.action) {
|
| 15 |
+
case 'REMOVE':
|
| 16 |
+
log.info('REMOVE', d.actual.location)
|
| 17 |
+
break
|
| 18 |
+
case 'ADD':
|
| 19 |
+
log.info('ADD', d.ideal.location, d.ideal.resolved)
|
| 20 |
+
break
|
| 21 |
+
case 'CHANGE':
|
| 22 |
+
log.info('CHANGE', d.actual.location, {
|
| 23 |
+
from: d.actual.resolved,
|
| 24 |
+
to: d.ideal.resolved,
|
| 25 |
+
})
|
| 26 |
+
break
|
| 27 |
+
}
|
| 28 |
+
},
|
| 29 |
+
getChildren: d => d.children,
|
| 30 |
+
})
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
module.exports = (options, time) => {
|
| 34 |
+
const arb = new Arborist(options)
|
| 35 |
+
return arb
|
| 36 |
+
.prune(options)
|
| 37 |
+
.then(time)
|
| 38 |
+
.then(async ({ timing, result: tree }) => {
|
| 39 |
+
printTree(tree)
|
| 40 |
+
if (options.dryRun) {
|
| 41 |
+
printDiff(arb.diff)
|
| 42 |
+
}
|
| 43 |
+
if (tree.meta && options.save) {
|
| 44 |
+
await tree.meta.save()
|
| 45 |
+
}
|
| 46 |
+
return `resolved ${tree.inventory.size} deps in ${timing.seconds}`
|
| 47 |
+
})
|
| 48 |
+
}
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/reify.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const Arborist = require('../')
|
| 2 |
+
|
| 3 |
+
const printTree = require('./lib/print-tree.js')
|
| 4 |
+
const log = require('./lib/logging.js')
|
| 5 |
+
|
| 6 |
+
const printDiff = diff => {
|
| 7 |
+
const { depth } = require('treeverse')
|
| 8 |
+
depth({
|
| 9 |
+
tree: diff,
|
| 10 |
+
visit: d => {
|
| 11 |
+
if (d.location === '') {
|
| 12 |
+
return
|
| 13 |
+
}
|
| 14 |
+
switch (d.action) {
|
| 15 |
+
case 'REMOVE':
|
| 16 |
+
log.info('REMOVE', d.actual.location)
|
| 17 |
+
break
|
| 18 |
+
case 'ADD':
|
| 19 |
+
log.info('ADD', d.ideal.location, d.ideal.resolved)
|
| 20 |
+
break
|
| 21 |
+
case 'CHANGE':
|
| 22 |
+
log.info('CHANGE', d.actual.location, {
|
| 23 |
+
from: d.actual.resolved,
|
| 24 |
+
to: d.ideal.resolved,
|
| 25 |
+
})
|
| 26 |
+
break
|
| 27 |
+
}
|
| 28 |
+
},
|
| 29 |
+
getChildren: d => d.children,
|
| 30 |
+
})
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
module.exports = (options, time) => {
|
| 34 |
+
const arb = new Arborist(options)
|
| 35 |
+
return arb
|
| 36 |
+
.reify(options)
|
| 37 |
+
.then(time)
|
| 38 |
+
.then(async ({ timing, result: tree }) => {
|
| 39 |
+
printTree(tree)
|
| 40 |
+
if (options.dryRun) {
|
| 41 |
+
printDiff(arb.diff)
|
| 42 |
+
}
|
| 43 |
+
if (tree.meta && options.save) {
|
| 44 |
+
await tree.meta.save()
|
| 45 |
+
}
|
| 46 |
+
return `resolved ${tree.inventory.size} deps in ${timing.seconds}`
|
| 47 |
+
})
|
| 48 |
+
}
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/shrinkwrap.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const Shrinkwrap = require('../lib/shrinkwrap.js')
|
| 2 |
+
|
| 3 |
+
module.exports = (options, time) => Shrinkwrap
|
| 4 |
+
.load(options)
|
| 5 |
+
.then((s) => s.commit())
|
| 6 |
+
.then(time)
|
| 7 |
+
.then(({ result: s }) => JSON.stringify(s, 0, 2))
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/bin/virtual.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const Arborist = require('../')
|
| 2 |
+
|
| 3 |
+
const printTree = require('./lib/print-tree.js')
|
| 4 |
+
|
| 5 |
+
module.exports = (options, time) => new Arborist(options)
|
| 6 |
+
.loadVirtual()
|
| 7 |
+
.then(time)
|
| 8 |
+
.then(async ({ timing, result: tree }) => {
|
| 9 |
+
printTree(tree)
|
| 10 |
+
if (options.save) {
|
| 11 |
+
await tree.meta.save()
|
| 12 |
+
}
|
| 13 |
+
return `read ${tree.inventory.size} deps in ${timing.ms}`
|
| 14 |
+
})
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/add-rm-pkg-deps.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// add and remove dependency specs to/from pkg manifest
|
| 2 |
+
|
| 3 |
+
const { log } = require('proc-log')
|
| 4 |
+
const localeCompare = require('@isaacs/string-locale-compare')('en')
|
| 5 |
+
|
| 6 |
+
const add = ({ pkg, add, saveBundle, saveType }) => {
|
| 7 |
+
for (const { name, rawSpec } of add) {
|
| 8 |
+
let addSaveType = saveType
|
| 9 |
+
// if the user does not give us a type, we infer which type(s)
|
| 10 |
+
// to keep based on the same order of priority we do when
|
| 11 |
+
// building the tree as defined in the _loadDeps method of
|
| 12 |
+
// the node class.
|
| 13 |
+
if (!addSaveType) {
|
| 14 |
+
addSaveType = inferSaveType(pkg, name)
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
if (addSaveType === 'prod') {
|
| 18 |
+
// a production dependency can only exist as production (rpj ensures it
|
| 19 |
+
// doesn't coexist w/ optional)
|
| 20 |
+
deleteSubKey(pkg, 'devDependencies', name, 'dependencies')
|
| 21 |
+
deleteSubKey(pkg, 'peerDependencies', name, 'dependencies')
|
| 22 |
+
} else if (addSaveType === 'dev') {
|
| 23 |
+
// a dev dependency may co-exist as peer, or optional, but not production
|
| 24 |
+
deleteSubKey(pkg, 'dependencies', name, 'devDependencies')
|
| 25 |
+
} else if (addSaveType === 'optional') {
|
| 26 |
+
// an optional dependency may co-exist as dev (rpj ensures it doesn't
|
| 27 |
+
// coexist w/ prod)
|
| 28 |
+
deleteSubKey(pkg, 'peerDependencies', name, 'optionalDependencies')
|
| 29 |
+
} else { // peer or peerOptional is all that's left
|
| 30 |
+
// a peer dependency may coexist as dev
|
| 31 |
+
deleteSubKey(pkg, 'dependencies', name, 'peerDependencies')
|
| 32 |
+
deleteSubKey(pkg, 'optionalDependencies', name, 'peerDependencies')
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
const depType = saveTypeMap.get(addSaveType)
|
| 36 |
+
|
| 37 |
+
pkg[depType] = pkg[depType] || {}
|
| 38 |
+
if (rawSpec !== '*' || pkg[depType][name] === undefined) {
|
| 39 |
+
pkg[depType][name] = rawSpec
|
| 40 |
+
}
|
| 41 |
+
if (addSaveType === 'optional') {
|
| 42 |
+
// Affordance for previous npm versions that require this behaviour
|
| 43 |
+
pkg.dependencies = pkg.dependencies || {}
|
| 44 |
+
pkg.dependencies[name] = pkg.optionalDependencies[name]
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
if (addSaveType === 'peer' || addSaveType === 'peerOptional') {
|
| 48 |
+
const pdm = pkg.peerDependenciesMeta || {}
|
| 49 |
+
if (addSaveType === 'peer' && pdm[name] && pdm[name].optional) {
|
| 50 |
+
pdm[name].optional = false
|
| 51 |
+
} else if (addSaveType === 'peerOptional') {
|
| 52 |
+
pdm[name] = pdm[name] || {}
|
| 53 |
+
pdm[name].optional = true
|
| 54 |
+
pkg.peerDependenciesMeta = pdm
|
| 55 |
+
}
|
| 56 |
+
// peerDeps are often also a devDep, so that they can be tested when
|
| 57 |
+
// using package managers that don't auto-install peer deps
|
| 58 |
+
if (pkg.devDependencies && pkg.devDependencies[name] !== undefined) {
|
| 59 |
+
pkg.devDependencies[name] = pkg.peerDependencies[name]
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
if (saveBundle && addSaveType !== 'peer' && addSaveType !== 'peerOptional') {
|
| 64 |
+
// keep it sorted, keep it unique
|
| 65 |
+
const bd = new Set(pkg.bundleDependencies || [])
|
| 66 |
+
bd.add(name)
|
| 67 |
+
pkg.bundleDependencies = [...bd].sort(localeCompare)
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
return pkg
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
// Canonical source of both the map between saveType and where it correlates to
|
| 75 |
+
// in the package, and the names of all our dependencies attributes
|
| 76 |
+
const saveTypeMap = new Map([
|
| 77 |
+
['dev', 'devDependencies'],
|
| 78 |
+
['optional', 'optionalDependencies'],
|
| 79 |
+
['prod', 'dependencies'],
|
| 80 |
+
['peerOptional', 'peerDependencies'],
|
| 81 |
+
['peer', 'peerDependencies'],
|
| 82 |
+
])
|
| 83 |
+
|
| 84 |
+
// Finds where the package is already in the spec and infers saveType from that
|
| 85 |
+
const inferSaveType = (pkg, name) => {
|
| 86 |
+
for (const saveType of saveTypeMap.keys()) {
|
| 87 |
+
if (hasSubKey(pkg, saveTypeMap.get(saveType), name)) {
|
| 88 |
+
if (
|
| 89 |
+
saveType === 'peerOptional' &&
|
| 90 |
+
(!hasSubKey(pkg, 'peerDependenciesMeta', name) ||
|
| 91 |
+
!pkg.peerDependenciesMeta[name].optional)
|
| 92 |
+
) {
|
| 93 |
+
return 'peer'
|
| 94 |
+
}
|
| 95 |
+
return saveType
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
return 'prod'
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
const hasSubKey = (pkg, depType, name) => {
|
| 102 |
+
return pkg[depType] && Object.prototype.hasOwnProperty.call(pkg[depType], name)
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
// Removes a subkey and warns about it if it's being replaced
|
| 106 |
+
const deleteSubKey = (pkg, depType, name, replacedBy) => {
|
| 107 |
+
if (hasSubKey(pkg, depType, name)) {
|
| 108 |
+
if (replacedBy) {
|
| 109 |
+
log.warn('idealTree', `Removing ${depType}.${name} in favor of ${replacedBy}.${name}`)
|
| 110 |
+
}
|
| 111 |
+
delete pkg[depType][name]
|
| 112 |
+
|
| 113 |
+
// clean up peerDepsMeta if we are removing something from peerDependencies
|
| 114 |
+
if (depType === 'peerDependencies' && pkg.peerDependenciesMeta) {
|
| 115 |
+
delete pkg.peerDependenciesMeta[name]
|
| 116 |
+
if (!Object.keys(pkg.peerDependenciesMeta).length) {
|
| 117 |
+
delete pkg.peerDependenciesMeta
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
if (!Object.keys(pkg[depType]).length) {
|
| 122 |
+
delete pkg[depType]
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
const rm = (pkg, rm) => {
|
| 128 |
+
for (const depType of new Set(saveTypeMap.values())) {
|
| 129 |
+
for (const name of rm) {
|
| 130 |
+
deleteSubKey(pkg, depType, name)
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
if (pkg.bundleDependencies) {
|
| 134 |
+
pkg.bundleDependencies = pkg.bundleDependencies
|
| 135 |
+
.filter(name => !rm.includes(name))
|
| 136 |
+
if (!pkg.bundleDependencies.length) {
|
| 137 |
+
delete pkg.bundleDependencies
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
return pkg
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
module.exports = { add, rm, saveTypeMap, hasSubKey }
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js
ADDED
|
@@ -0,0 +1,1523 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// mixin implementing the buildIdealTree method
|
| 2 |
+
const localeCompare = require('@isaacs/string-locale-compare')('en')
|
| 3 |
+
const rpj = require('read-package-json-fast')
|
| 4 |
+
const npa = require('npm-package-arg')
|
| 5 |
+
const pacote = require('pacote')
|
| 6 |
+
const cacache = require('cacache')
|
| 7 |
+
const { callLimit: promiseCallLimit } = require('promise-call-limit')
|
| 8 |
+
const realpath = require('../../lib/realpath.js')
|
| 9 |
+
const { resolve, dirname } = require('node:path')
|
| 10 |
+
const treeCheck = require('../tree-check.js')
|
| 11 |
+
const { readdirScoped } = require('@npmcli/fs')
|
| 12 |
+
const { lstat, readlink } = require('node:fs/promises')
|
| 13 |
+
const { depth } = require('treeverse')
|
| 14 |
+
const { log, time } = require('proc-log')
|
| 15 |
+
const { redact } = require('@npmcli/redact')
|
| 16 |
+
|
| 17 |
+
const {
|
| 18 |
+
OK,
|
| 19 |
+
REPLACE,
|
| 20 |
+
CONFLICT,
|
| 21 |
+
} = require('../can-place-dep.js')
|
| 22 |
+
const PlaceDep = require('../place-dep.js')
|
| 23 |
+
|
| 24 |
+
const debug = require('../debug.js')
|
| 25 |
+
const fromPath = require('../from-path.js')
|
| 26 |
+
const calcDepFlags = require('../calc-dep-flags.js')
|
| 27 |
+
const Shrinkwrap = require('../shrinkwrap.js')
|
| 28 |
+
const { defaultLockfileVersion } = Shrinkwrap
|
| 29 |
+
const Node = require('../node.js')
|
| 30 |
+
const Link = require('../link.js')
|
| 31 |
+
const addRmPkgDeps = require('../add-rm-pkg-deps.js')
|
| 32 |
+
const optionalSet = require('../optional-set.js')
|
| 33 |
+
const { checkEngine, checkPlatform } = require('npm-install-checks')
|
| 34 |
+
const relpath = require('../relpath.js')
|
| 35 |
+
const resetDepFlags = require('../reset-dep-flags.js')
|
| 36 |
+
|
| 37 |
+
// note: some of these symbols are shared so we can hit
|
| 38 |
+
// them with unit tests and reuse them across mixins
|
| 39 |
+
const _updateAll = Symbol.for('updateAll')
|
| 40 |
+
const _flagsSuspect = Symbol.for('flagsSuspect')
|
| 41 |
+
const _setWorkspaces = Symbol.for('setWorkspaces')
|
| 42 |
+
const _updateNames = Symbol.for('updateNames')
|
| 43 |
+
const _resolvedAdd = Symbol.for('resolvedAdd')
|
| 44 |
+
const _usePackageLock = Symbol.for('usePackageLock')
|
| 45 |
+
const _rpcache = Symbol.for('realpathCache')
|
| 46 |
+
const _stcache = Symbol.for('statCache')
|
| 47 |
+
|
| 48 |
+
// used by Reify mixin
|
| 49 |
+
const _addNodeToTrashList = Symbol.for('addNodeToTrashList')
|
| 50 |
+
|
| 51 |
+
// Push items in, pop them sorted by depth and then path
|
| 52 |
+
// Sorts physically shallower deps up to the front of the queue, because
|
| 53 |
+
// they'll affect things deeper in, then alphabetical for consistency between
|
| 54 |
+
// installs
|
| 55 |
+
class DepsQueue {
|
| 56 |
+
#deps = []
|
| 57 |
+
#sorted = true
|
| 58 |
+
|
| 59 |
+
get length () {
|
| 60 |
+
return this.#deps.length
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
push (item) {
|
| 64 |
+
if (!this.#deps.includes(item)) {
|
| 65 |
+
this.#sorted = false
|
| 66 |
+
this.#deps.push(item)
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
pop () {
|
| 71 |
+
if (!this.#sorted) {
|
| 72 |
+
this.#deps.sort((a, b) => (a.depth - b.depth) || localeCompare(a.path, b.path))
|
| 73 |
+
this.#sorted = true
|
| 74 |
+
}
|
| 75 |
+
return this.#deps.shift()
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
module.exports = cls => class IdealTreeBuilder extends cls {
|
| 80 |
+
#complete
|
| 81 |
+
#currentDep = null
|
| 82 |
+
#depsQueue = new DepsQueue()
|
| 83 |
+
#depsSeen = new Set()
|
| 84 |
+
#explicitRequests = new Set()
|
| 85 |
+
#follow
|
| 86 |
+
#installStrategy
|
| 87 |
+
#linkNodes = new Set()
|
| 88 |
+
#loadFailures = new Set()
|
| 89 |
+
#manifests = new Map()
|
| 90 |
+
#mutateTree = false
|
| 91 |
+
// a map of each module in a peer set to the thing that depended on
|
| 92 |
+
// that set of peers in the first place. Use a WeakMap so that we
|
| 93 |
+
// don't hold onto references for nodes that are garbage collected.
|
| 94 |
+
#peerSetSource = new WeakMap()
|
| 95 |
+
#preferDedupe = false
|
| 96 |
+
#prune
|
| 97 |
+
#strictPeerDeps
|
| 98 |
+
#virtualRoots = new Map()
|
| 99 |
+
|
| 100 |
+
constructor (options) {
|
| 101 |
+
super(options)
|
| 102 |
+
|
| 103 |
+
// normalize trailing slash
|
| 104 |
+
const registry = options.registry || 'https://registry.npmjs.org'
|
| 105 |
+
options.registry = this.registry = registry.replace(/\/+$/, '') + '/'
|
| 106 |
+
|
| 107 |
+
const {
|
| 108 |
+
follow = false,
|
| 109 |
+
installStrategy = 'hoisted',
|
| 110 |
+
idealTree = null,
|
| 111 |
+
installLinks = false,
|
| 112 |
+
legacyPeerDeps = false,
|
| 113 |
+
packageLock = true,
|
| 114 |
+
strictPeerDeps = false,
|
| 115 |
+
workspaces,
|
| 116 |
+
global,
|
| 117 |
+
} = options
|
| 118 |
+
|
| 119 |
+
this.#strictPeerDeps = !!strictPeerDeps
|
| 120 |
+
|
| 121 |
+
this.idealTree = idealTree
|
| 122 |
+
this.installLinks = installLinks
|
| 123 |
+
this.legacyPeerDeps = legacyPeerDeps
|
| 124 |
+
|
| 125 |
+
this[_usePackageLock] = packageLock
|
| 126 |
+
this.#installStrategy = global ? 'shallow' : installStrategy
|
| 127 |
+
this.#follow = !!follow
|
| 128 |
+
|
| 129 |
+
if (workspaces?.length && global) {
|
| 130 |
+
throw new Error('Cannot operate on workspaces in global mode')
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
this[_updateAll] = false
|
| 134 |
+
this[_updateNames] = []
|
| 135 |
+
this[_resolvedAdd] = []
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
get explicitRequests () {
|
| 139 |
+
return new Set(this.#explicitRequests)
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
// public method
|
| 143 |
+
async buildIdealTree (options = {}) {
|
| 144 |
+
if (this.idealTree) {
|
| 145 |
+
return this.idealTree
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
// allow the user to set reify options on the ctor as well.
|
| 149 |
+
// XXX: deprecate separate reify() options object.
|
| 150 |
+
options = { ...this.options, ...options }
|
| 151 |
+
|
| 152 |
+
// an empty array or any falsey value is the same as null
|
| 153 |
+
if (!options.add || options.add.length === 0) {
|
| 154 |
+
options.add = null
|
| 155 |
+
}
|
| 156 |
+
if (!options.rm || options.rm.length === 0) {
|
| 157 |
+
options.rm = null
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
const timeEnd = time.start('idealTree')
|
| 161 |
+
|
| 162 |
+
if (!options.add && !options.rm && !options.update && this.options.global) {
|
| 163 |
+
throw new Error('global requires add, rm, or update option')
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
// first get the virtual tree, if possible. If there's a lockfile, then
|
| 167 |
+
// that defines the ideal tree, unless the root package.json is not
|
| 168 |
+
// satisfied by what the ideal tree provides.
|
| 169 |
+
// from there, we start adding nodes to it to satisfy the deps requested
|
| 170 |
+
// by the package.json in the root.
|
| 171 |
+
|
| 172 |
+
this.#parseSettings(options)
|
| 173 |
+
|
| 174 |
+
// start tracker block
|
| 175 |
+
this.addTracker('idealTree')
|
| 176 |
+
|
| 177 |
+
try {
|
| 178 |
+
await this.#initTree()
|
| 179 |
+
await this.#inflateAncientLockfile()
|
| 180 |
+
await this.#applyUserRequests(options)
|
| 181 |
+
await this.#buildDeps()
|
| 182 |
+
await this.#fixDepFlags()
|
| 183 |
+
await this.#pruneFailedOptional()
|
| 184 |
+
await this.#checkEngineAndPlatform()
|
| 185 |
+
} finally {
|
| 186 |
+
timeEnd()
|
| 187 |
+
this.finishTracker('idealTree')
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
return treeCheck(this.idealTree)
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
async #checkEngineAndPlatform () {
|
| 194 |
+
const { engineStrict, npmVersion, nodeVersion } = this.options
|
| 195 |
+
for (const node of this.idealTree.inventory.values()) {
|
| 196 |
+
if (!node.optional) {
|
| 197 |
+
try {
|
| 198 |
+
// if devEngines is present in the root node we ignore the engines check
|
| 199 |
+
if (!(node.isRoot && node.package.devEngines)) {
|
| 200 |
+
checkEngine(node.package, npmVersion, nodeVersion, this.options.force)
|
| 201 |
+
}
|
| 202 |
+
} catch (err) {
|
| 203 |
+
if (engineStrict) {
|
| 204 |
+
throw err
|
| 205 |
+
}
|
| 206 |
+
log.warn(err.code, err.message, {
|
| 207 |
+
package: err.pkgid,
|
| 208 |
+
required: err.required,
|
| 209 |
+
current: err.current,
|
| 210 |
+
})
|
| 211 |
+
}
|
| 212 |
+
checkPlatform(node.package, this.options.force)
|
| 213 |
+
}
|
| 214 |
+
}
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
#parseSettings (options) {
|
| 218 |
+
const update = options.update === true ? { all: true }
|
| 219 |
+
: Array.isArray(options.update) ? { names: options.update }
|
| 220 |
+
: options.update || {}
|
| 221 |
+
|
| 222 |
+
if (update.all || !Array.isArray(update.names)) {
|
| 223 |
+
update.names = []
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
this.#complete = !!options.complete
|
| 227 |
+
this.#preferDedupe = !!options.preferDedupe
|
| 228 |
+
|
| 229 |
+
// validates list of update names, they must
|
| 230 |
+
// be dep names only, no semver ranges are supported
|
| 231 |
+
for (const name of update.names) {
|
| 232 |
+
const spec = npa(name)
|
| 233 |
+
const validationError =
|
| 234 |
+
new TypeError(`Update arguments must only contain package names, eg:
|
| 235 |
+
npm update ${spec.name}`)
|
| 236 |
+
validationError.code = 'EUPDATEARGS'
|
| 237 |
+
|
| 238 |
+
// If they gave us anything other than a bare package name
|
| 239 |
+
if (spec.raw !== spec.name) {
|
| 240 |
+
throw validationError
|
| 241 |
+
}
|
| 242 |
+
}
|
| 243 |
+
this[_updateNames] = update.names
|
| 244 |
+
|
| 245 |
+
this[_updateAll] = update.all
|
| 246 |
+
// we prune by default unless explicitly set to boolean false
|
| 247 |
+
this.#prune = options.prune !== false
|
| 248 |
+
|
| 249 |
+
// set if we add anything, but also set here if we know we'll make
|
| 250 |
+
// changes and thus have to maybe prune later.
|
| 251 |
+
this.#mutateTree = !!(
|
| 252 |
+
options.add ||
|
| 253 |
+
options.rm ||
|
| 254 |
+
update.all ||
|
| 255 |
+
update.names.length
|
| 256 |
+
)
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
// load the initial tree, either the virtualTree from a shrinkwrap,
|
| 260 |
+
// or just the root node from a package.json
|
| 261 |
+
async #initTree () {
|
| 262 |
+
const timeEnd = time.start('idealTree:init')
|
| 263 |
+
let root
|
| 264 |
+
if (this.options.global) {
|
| 265 |
+
root = await this.#globalRootNode()
|
| 266 |
+
} else {
|
| 267 |
+
try {
|
| 268 |
+
const pkg = await rpj(this.path + '/package.json')
|
| 269 |
+
root = await this.#rootNodeFromPackage(pkg)
|
| 270 |
+
} catch (err) {
|
| 271 |
+
if (err.code === 'EJSONPARSE') {
|
| 272 |
+
throw err
|
| 273 |
+
}
|
| 274 |
+
root = await this.#rootNodeFromPackage({})
|
| 275 |
+
}
|
| 276 |
+
}
|
| 277 |
+
return this[_setWorkspaces](root)
|
| 278 |
+
// ok to not have a virtual tree. probably initial install.
|
| 279 |
+
// When updating all, we load the shrinkwrap, but don't bother
|
| 280 |
+
// to build out the full virtual tree from it, since we'll be
|
| 281 |
+
// reconstructing it anyway.
|
| 282 |
+
.then(root => this.options.global ? root
|
| 283 |
+
: !this[_usePackageLock] || this[_updateAll]
|
| 284 |
+
? Shrinkwrap.reset({
|
| 285 |
+
path: this.path,
|
| 286 |
+
lockfileVersion: this.options.lockfileVersion,
|
| 287 |
+
resolveOptions: this.options,
|
| 288 |
+
}).then(meta => Object.assign(root, { meta }))
|
| 289 |
+
: this.loadVirtual({ root }))
|
| 290 |
+
|
| 291 |
+
// if we don't have a lockfile to go from, then start with the
|
| 292 |
+
// actual tree, so we only make the minimum required changes.
|
| 293 |
+
// don't do this for global installs or updates, because in those
|
| 294 |
+
// cases we don't use a lockfile anyway.
|
| 295 |
+
// Load on a new Arborist object, so the Nodes aren't the same,
|
| 296 |
+
// or else it'll get super confusing when we change them!
|
| 297 |
+
.then(async root => {
|
| 298 |
+
if ((!this[_updateAll] && !this.options.global && !root.meta.loadedFromDisk) || (this.options.global && this[_updateNames].length)) {
|
| 299 |
+
await new this.constructor(this.options).loadActual({ root })
|
| 300 |
+
const tree = root.target
|
| 301 |
+
// even though we didn't load it from a package-lock.json FILE,
|
| 302 |
+
// we still loaded it "from disk", meaning we have to reset
|
| 303 |
+
// dep flags before assuming that any mutations were reflected.
|
| 304 |
+
if (tree.children.size) {
|
| 305 |
+
root.meta.loadedFromDisk = true
|
| 306 |
+
// set these so that we don't try to ancient lockfile reload it
|
| 307 |
+
root.meta.originalLockfileVersion = root.meta.lockfileVersion = this.options.lockfileVersion || defaultLockfileVersion
|
| 308 |
+
}
|
| 309 |
+
}
|
| 310 |
+
root.meta.inferFormattingOptions(root.package)
|
| 311 |
+
return root
|
| 312 |
+
})
|
| 313 |
+
|
| 314 |
+
.then(tree => {
|
| 315 |
+
// search the virtual tree for invalid edges, if any are found add their source to
|
| 316 |
+
// the depsQueue so that we'll fix it later
|
| 317 |
+
depth({
|
| 318 |
+
tree,
|
| 319 |
+
getChildren: (node) => {
|
| 320 |
+
const children = []
|
| 321 |
+
for (const edge of node.edgesOut.values()) {
|
| 322 |
+
children.push(edge.to)
|
| 323 |
+
}
|
| 324 |
+
return children
|
| 325 |
+
},
|
| 326 |
+
filter: node => node,
|
| 327 |
+
visit: node => {
|
| 328 |
+
for (const edge of node.edgesOut.values()) {
|
| 329 |
+
if (!edge.valid) {
|
| 330 |
+
this.#depsQueue.push(node)
|
| 331 |
+
break // no need to continue the loop after the first hit
|
| 332 |
+
}
|
| 333 |
+
}
|
| 334 |
+
},
|
| 335 |
+
})
|
| 336 |
+
// null the virtual tree, because we're about to hack away at it
|
| 337 |
+
// if you want another one, load another copy.
|
| 338 |
+
this.idealTree = tree
|
| 339 |
+
this.virtualTree = null
|
| 340 |
+
timeEnd()
|
| 341 |
+
return tree
|
| 342 |
+
})
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
async #globalRootNode () {
|
| 346 |
+
const root = await this.#rootNodeFromPackage({ dependencies: {} })
|
| 347 |
+
// this is a gross kludge to handle the fact that we don't save
|
| 348 |
+
// metadata on the root node in global installs, because the "root"
|
| 349 |
+
// node is something like /usr/local/lib.
|
| 350 |
+
const meta = new Shrinkwrap({
|
| 351 |
+
path: this.path,
|
| 352 |
+
lockfileVersion: this.options.lockfileVersion,
|
| 353 |
+
resolveOptions: this.options,
|
| 354 |
+
})
|
| 355 |
+
meta.reset()
|
| 356 |
+
root.meta = meta
|
| 357 |
+
return root
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
async #rootNodeFromPackage (pkg) {
|
| 361 |
+
// if the path doesn't exist, then we explode at this point. Note that
|
| 362 |
+
// this is not a problem for reify(), since it creates the root path
|
| 363 |
+
// before ever loading trees.
|
| 364 |
+
// TODO: make buildIdealTree() and loadActual handle a missing root path,
|
| 365 |
+
// or a symlink to a missing target, and let reify() create it as needed.
|
| 366 |
+
const real = await realpath(this.path, this[_rpcache], this[_stcache])
|
| 367 |
+
const Cls = real === this.path ? Node : Link
|
| 368 |
+
const root = new Cls({
|
| 369 |
+
path: this.path,
|
| 370 |
+
realpath: real,
|
| 371 |
+
pkg,
|
| 372 |
+
extraneous: false,
|
| 373 |
+
dev: false,
|
| 374 |
+
devOptional: false,
|
| 375 |
+
peer: false,
|
| 376 |
+
optional: false,
|
| 377 |
+
global: this.options.global,
|
| 378 |
+
installLinks: this.installLinks,
|
| 379 |
+
legacyPeerDeps: this.legacyPeerDeps,
|
| 380 |
+
loadOverrides: true,
|
| 381 |
+
})
|
| 382 |
+
if (root.isLink) {
|
| 383 |
+
root.target = new Node({
|
| 384 |
+
path: real,
|
| 385 |
+
realpath: real,
|
| 386 |
+
pkg,
|
| 387 |
+
extraneous: false,
|
| 388 |
+
dev: false,
|
| 389 |
+
devOptional: false,
|
| 390 |
+
peer: false,
|
| 391 |
+
optional: false,
|
| 392 |
+
global: this.options.global,
|
| 393 |
+
installLinks: this.installLinks,
|
| 394 |
+
legacyPeerDeps: this.legacyPeerDeps,
|
| 395 |
+
root,
|
| 396 |
+
})
|
| 397 |
+
}
|
| 398 |
+
return root
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
// process the add/rm requests by modifying the root node, and the
|
| 402 |
+
// update.names request by queueing nodes dependent on those named.
|
| 403 |
+
async #applyUserRequests (options) {
|
| 404 |
+
const timeEnd = time.start('idealTree:userRequests')
|
| 405 |
+
const tree = this.idealTree.target
|
| 406 |
+
|
| 407 |
+
if (!this.options.workspaces.length) {
|
| 408 |
+
await this.#applyUserRequestsToNode(tree, options)
|
| 409 |
+
} else {
|
| 410 |
+
const nodes = this.workspaceNodes(tree, this.options.workspaces)
|
| 411 |
+
if (this.options.includeWorkspaceRoot) {
|
| 412 |
+
nodes.push(tree)
|
| 413 |
+
}
|
| 414 |
+
const appliedRequests = nodes.map(
|
| 415 |
+
node => this.#applyUserRequestsToNode(node, options)
|
| 416 |
+
)
|
| 417 |
+
await Promise.all(appliedRequests)
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
timeEnd()
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
async #applyUserRequestsToNode (tree, options) {
|
| 424 |
+
// If we have a list of package names to update, and we know it's
|
| 425 |
+
// going to update them wherever they are, add any paths into those
|
| 426 |
+
// named nodes to the buildIdealTree queue.
|
| 427 |
+
if (!this.options.global && this[_updateNames].length) {
|
| 428 |
+
this.#queueNamedUpdates()
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
// global updates only update the globalTop nodes, but we need to know
|
| 432 |
+
// that they're there, and not reinstall the world unnecessarily.
|
| 433 |
+
const globalExplicitUpdateNames = []
|
| 434 |
+
if (this.options.global && (this[_updateAll] || this[_updateNames].length)) {
|
| 435 |
+
const nm = resolve(this.path, 'node_modules')
|
| 436 |
+
const paths = await readdirScoped(nm).catch(() => [])
|
| 437 |
+
for (const p of paths) {
|
| 438 |
+
const name = p.replace(/\\/g, '/')
|
| 439 |
+
tree.package.dependencies = tree.package.dependencies || {}
|
| 440 |
+
const updateName = this[_updateNames].includes(name)
|
| 441 |
+
if (this[_updateAll] || updateName) {
|
| 442 |
+
if (updateName) {
|
| 443 |
+
globalExplicitUpdateNames.push(name)
|
| 444 |
+
}
|
| 445 |
+
const dir = resolve(nm, name)
|
| 446 |
+
const st = await lstat(dir)
|
| 447 |
+
.catch(/* istanbul ignore next */ () => null)
|
| 448 |
+
if (st && st.isSymbolicLink()) {
|
| 449 |
+
const target = await readlink(dir)
|
| 450 |
+
const real = resolve(dirname(dir), target)
|
| 451 |
+
tree.package.dependencies[name] = `file:${real}`
|
| 452 |
+
} else {
|
| 453 |
+
tree.package.dependencies[name] = '*'
|
| 454 |
+
}
|
| 455 |
+
}
|
| 456 |
+
}
|
| 457 |
+
}
|
| 458 |
+
|
| 459 |
+
if (this.auditReport && this.auditReport.size > 0) {
|
| 460 |
+
await this.#queueVulnDependents(options)
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
const { add, rm } = options
|
| 464 |
+
|
| 465 |
+
if (rm && rm.length) {
|
| 466 |
+
addRmPkgDeps.rm(tree.package, rm)
|
| 467 |
+
for (const name of rm) {
|
| 468 |
+
this.#explicitRequests.add({ from: tree, name, action: 'DELETE' })
|
| 469 |
+
}
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
if (add && add.length) {
|
| 473 |
+
await this.#add(tree, options)
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
// triggers a refresh of all edgesOut. this has to be done BEFORE
|
| 477 |
+
// adding the edges to explicitRequests, because the package setter
|
| 478 |
+
// resets all edgesOut.
|
| 479 |
+
if (add && add.length || rm && rm.length || this.options.global) {
|
| 480 |
+
tree.package = tree.package
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
for (const spec of this[_resolvedAdd]) {
|
| 484 |
+
if (spec.tree === tree) {
|
| 485 |
+
this.#explicitRequests.add(tree.edgesOut.get(spec.name))
|
| 486 |
+
}
|
| 487 |
+
}
|
| 488 |
+
for (const name of globalExplicitUpdateNames) {
|
| 489 |
+
this.#explicitRequests.add(tree.edgesOut.get(name))
|
| 490 |
+
}
|
| 491 |
+
|
| 492 |
+
this.#depsQueue.push(tree)
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
// This returns a promise because we might not have the name yet, and need to
|
| 496 |
+
// call pacote.manifest to find the name.
|
| 497 |
+
async #add (tree, { add, saveType = null, saveBundle = false }) {
|
| 498 |
+
// If we have a link it will need to be added relative to the target's path
|
| 499 |
+
const path = tree.target.path
|
| 500 |
+
|
| 501 |
+
// get the name for each of the specs in the list.
|
| 502 |
+
// ie, doing `foo@bar` we just return foo but if it's a url or git, we
|
| 503 |
+
// don't know the name until we fetch it and look in its manifest.
|
| 504 |
+
await Promise.all(add.map(async rawSpec => {
|
| 505 |
+
// We do NOT provide the path to npa here, because user-additions need to
|
| 506 |
+
// be resolved relative to the tree being added to.
|
| 507 |
+
let spec = npa(rawSpec)
|
| 508 |
+
|
| 509 |
+
// if it's just @'' then we reload whatever's there, or get latest
|
| 510 |
+
// if it's an explicit tag, we need to install that specific tag version
|
| 511 |
+
const isTag = spec.rawSpec && spec.type === 'tag'
|
| 512 |
+
|
| 513 |
+
// look up the names of file/directory/git specs
|
| 514 |
+
if (!spec.name || isTag) {
|
| 515 |
+
const mani = await pacote.manifest(spec, { ...this.options })
|
| 516 |
+
if (isTag) {
|
| 517 |
+
// translate tag to a version
|
| 518 |
+
spec = npa(`${mani.name}@${mani.version}`)
|
| 519 |
+
}
|
| 520 |
+
spec.name = mani.name
|
| 521 |
+
}
|
| 522 |
+
|
| 523 |
+
const { name } = spec
|
| 524 |
+
if (spec.type === 'file') {
|
| 525 |
+
spec = npa(`file:${relpath(path, spec.fetchSpec)}`, path)
|
| 526 |
+
spec.name = name
|
| 527 |
+
} else if (spec.type === 'directory') {
|
| 528 |
+
try {
|
| 529 |
+
const real = await realpath(spec.fetchSpec, this[_rpcache], this[_stcache])
|
| 530 |
+
spec = npa(`file:${relpath(path, real)}`, path)
|
| 531 |
+
spec.name = name
|
| 532 |
+
} catch {
|
| 533 |
+
// TODO: create synthetic test case to simulate realpath failure
|
| 534 |
+
}
|
| 535 |
+
}
|
| 536 |
+
spec.tree = tree
|
| 537 |
+
this[_resolvedAdd].push(spec)
|
| 538 |
+
}))
|
| 539 |
+
|
| 540 |
+
// now this._resolvedAdd is a list of spec objects with names.
|
| 541 |
+
// find a home for each of them!
|
| 542 |
+
addRmPkgDeps.add({
|
| 543 |
+
pkg: tree.package,
|
| 544 |
+
add: this[_resolvedAdd],
|
| 545 |
+
saveBundle,
|
| 546 |
+
saveType,
|
| 547 |
+
})
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
// TODO: provide a way to fix bundled deps by exposing metadata about
|
| 551 |
+
// what's in the bundle at each published manifest. Without that, we
|
| 552 |
+
// can't possibly fix bundled deps without breaking a ton of other stuff,
|
| 553 |
+
// and leaving the user subject to getting it overwritten later anyway.
|
| 554 |
+
async #queueVulnDependents (options) {
|
| 555 |
+
for (const vuln of this.auditReport.values()) {
|
| 556 |
+
for (const node of vuln.nodes) {
|
| 557 |
+
const bundler = node.getBundler()
|
| 558 |
+
|
| 559 |
+
// XXX this belongs in the audit report itself, not here.
|
| 560 |
+
// We shouldn't even get these things here, and they shouldn't
|
| 561 |
+
// be printed by npm-audit-report as if they can be fixed, because
|
| 562 |
+
// they can't.
|
| 563 |
+
if (bundler) {
|
| 564 |
+
log.warn(`audit fix ${node.name}@${node.version}`,
|
| 565 |
+
`${node.location}\nis a bundled dependency of\n${
|
| 566 |
+
bundler.name}@${bundler.version} at ${bundler.location}\n` +
|
| 567 |
+
'It cannot be fixed automatically.\n' +
|
| 568 |
+
`Check for updates to the ${bundler.name} package.`)
|
| 569 |
+
continue
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
for (const edge of node.edgesIn) {
|
| 573 |
+
this.addTracker('idealTree', edge.from.name, edge.from.location)
|
| 574 |
+
this.#depsQueue.push(edge.from)
|
| 575 |
+
}
|
| 576 |
+
}
|
| 577 |
+
}
|
| 578 |
+
|
| 579 |
+
// note any that can't be fixed at the root level without --force
|
| 580 |
+
// if there's a fix, we use that. otherwise, the user has to remove it,
|
| 581 |
+
// find a different thing, fix the upstream, etc.
|
| 582 |
+
//
|
| 583 |
+
// XXX: how to handle top nodes that aren't the root? Maybe the report
|
| 584 |
+
// just tells the user to cd into that directory and fix it?
|
| 585 |
+
if (this.options.force && this.auditReport && this.auditReport.topVulns.size) {
|
| 586 |
+
options.add = options.add || []
|
| 587 |
+
options.rm = options.rm || []
|
| 588 |
+
const nodesTouched = new Set()
|
| 589 |
+
for (const [name, topVuln] of this.auditReport.topVulns.entries()) {
|
| 590 |
+
const {
|
| 591 |
+
simpleRange,
|
| 592 |
+
topNodes,
|
| 593 |
+
fixAvailable,
|
| 594 |
+
} = topVuln
|
| 595 |
+
for (const node of topNodes) {
|
| 596 |
+
if (!node.isProjectRoot && !node.isWorkspace) {
|
| 597 |
+
// not something we're going to fix, sorry. have to cd into
|
| 598 |
+
// that directory and fix it yourself.
|
| 599 |
+
log.warn('audit', 'Manual fix required in linked project ' +
|
| 600 |
+
`at ./${node.location} for ${name}@${simpleRange}.\n` +
|
| 601 |
+
`'cd ./${node.location}' and run 'npm audit' for details.`)
|
| 602 |
+
continue
|
| 603 |
+
}
|
| 604 |
+
|
| 605 |
+
if (!fixAvailable) {
|
| 606 |
+
log.warn('audit', `No fix available for ${name}@${simpleRange}`)
|
| 607 |
+
continue
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
// name may be different if parent fixes the dep
|
| 611 |
+
// see Vuln fixAvailable setter
|
| 612 |
+
const { isSemVerMajor, version, name: fixName } = fixAvailable
|
| 613 |
+
const breakingMessage = isSemVerMajor
|
| 614 |
+
? 'a SemVer major change'
|
| 615 |
+
: 'outside your stated dependency range'
|
| 616 |
+
log.warn('audit', `Updating ${fixName} to ${version}, ` +
|
| 617 |
+
`which is ${breakingMessage}.`)
|
| 618 |
+
|
| 619 |
+
await this.#add(node, { add: [`${fixName}@${version}`] })
|
| 620 |
+
nodesTouched.add(node)
|
| 621 |
+
}
|
| 622 |
+
}
|
| 623 |
+
for (const node of nodesTouched) {
|
| 624 |
+
node.package = node.package
|
| 625 |
+
}
|
| 626 |
+
}
|
| 627 |
+
}
|
| 628 |
+
|
| 629 |
+
#avoidRange (name) {
|
| 630 |
+
if (!this.auditReport) {
|
| 631 |
+
return null
|
| 632 |
+
}
|
| 633 |
+
const vuln = this.auditReport.get(name)
|
| 634 |
+
if (!vuln) {
|
| 635 |
+
return null
|
| 636 |
+
}
|
| 637 |
+
return vuln.range
|
| 638 |
+
}
|
| 639 |
+
|
| 640 |
+
#queueNamedUpdates () {
|
| 641 |
+
// ignore top nodes, since they are not loaded the same way, and
|
| 642 |
+
// probably have their own project associated with them.
|
| 643 |
+
|
| 644 |
+
// for every node with one of the names on the list, we add its
|
| 645 |
+
// dependents to the queue to be evaluated. in buildDepStep,
|
| 646 |
+
// anything on the update names list will get refreshed, even if
|
| 647 |
+
// it isn't a problem.
|
| 648 |
+
|
| 649 |
+
// XXX this could be faster by doing a series of inventory.query('name')
|
| 650 |
+
// calls rather than walking over everything in the tree.
|
| 651 |
+
for (const node of this.idealTree.inventory.values()) {
|
| 652 |
+
// XXX add any invalid edgesOut to the queue
|
| 653 |
+
if (this[_updateNames].includes(node.name) &&
|
| 654 |
+
!node.isTop && !node.inDepBundle && !node.inShrinkwrap) {
|
| 655 |
+
for (const edge of node.edgesIn) {
|
| 656 |
+
this.addTracker('idealTree', edge.from.name, edge.from.location)
|
| 657 |
+
this.#depsQueue.push(edge.from)
|
| 658 |
+
}
|
| 659 |
+
}
|
| 660 |
+
}
|
| 661 |
+
}
|
| 662 |
+
|
| 663 |
+
async #inflateAncientLockfile () {
|
| 664 |
+
const { meta, inventory } = this.idealTree
|
| 665 |
+
const ancient = meta.ancientLockfile
|
| 666 |
+
const old = meta.loadedFromDisk && !(meta.originalLockfileVersion >= 2)
|
| 667 |
+
|
| 668 |
+
if (inventory.size === 0 || !ancient && !old) {
|
| 669 |
+
return
|
| 670 |
+
}
|
| 671 |
+
|
| 672 |
+
// if the lockfile is from node v5 or earlier, then we'll have to reload
|
| 673 |
+
// all the manifests of everything we encounter. this is costly, but at
|
| 674 |
+
// least it's just a one-time hit.
|
| 675 |
+
const timeEnd = time.start('idealTree:inflate')
|
| 676 |
+
|
| 677 |
+
// don't warn if we're not gonna actually write it back anyway.
|
| 678 |
+
const heading = ancient ? 'ancient lockfile' : 'old lockfile'
|
| 679 |
+
if (ancient || !this.options.lockfileVersion ||
|
| 680 |
+
this.options.lockfileVersion >= defaultLockfileVersion) {
|
| 681 |
+
log.warn(heading,
|
| 682 |
+
`
|
| 683 |
+
The ${meta.type} file was created with an old version of npm,
|
| 684 |
+
so supplemental metadata must be fetched from the registry.
|
| 685 |
+
|
| 686 |
+
This is a one-time fix-up, please be patient...
|
| 687 |
+
`)
|
| 688 |
+
}
|
| 689 |
+
|
| 690 |
+
this.addTracker('idealTree:inflate')
|
| 691 |
+
const queue = []
|
| 692 |
+
for (const node of inventory.values()) {
|
| 693 |
+
if (node.isProjectRoot) {
|
| 694 |
+
continue
|
| 695 |
+
}
|
| 696 |
+
|
| 697 |
+
// if the node's location isn't within node_modules then this is actually
|
| 698 |
+
// a link target, so skip it. the link node itself will be queued later.
|
| 699 |
+
if (!node.location.startsWith('node_modules')) {
|
| 700 |
+
continue
|
| 701 |
+
}
|
| 702 |
+
|
| 703 |
+
queue.push(async () => {
|
| 704 |
+
log.silly('inflate', node.location)
|
| 705 |
+
const { resolved, version, path, name, location, integrity } = node
|
| 706 |
+
// don't try to hit the registry for linked deps
|
| 707 |
+
const useResolved = resolved && (
|
| 708 |
+
!version || resolved.startsWith('file:')
|
| 709 |
+
)
|
| 710 |
+
const id = useResolved ? resolved : version
|
| 711 |
+
const spec = npa.resolve(name, id, dirname(path))
|
| 712 |
+
const t = `idealTree:inflate:${location}`
|
| 713 |
+
this.addTracker(t)
|
| 714 |
+
try {
|
| 715 |
+
const mani = await pacote.manifest(spec, {
|
| 716 |
+
...this.options,
|
| 717 |
+
resolved: resolved,
|
| 718 |
+
integrity: integrity,
|
| 719 |
+
fullMetadata: false,
|
| 720 |
+
})
|
| 721 |
+
node.package = { ...mani, _id: `${mani.name}@${mani.version}` }
|
| 722 |
+
} catch (er) {
|
| 723 |
+
const warning = `Could not fetch metadata for ${name}@${id}`
|
| 724 |
+
log.warn(heading, warning, er)
|
| 725 |
+
}
|
| 726 |
+
this.finishTracker(t)
|
| 727 |
+
})
|
| 728 |
+
}
|
| 729 |
+
await promiseCallLimit(queue)
|
| 730 |
+
|
| 731 |
+
// have to re-calc dep flags, because the nodes don't have edges
|
| 732 |
+
// until their packages get assigned, so everything looks extraneous
|
| 733 |
+
calcDepFlags(this.idealTree)
|
| 734 |
+
|
| 735 |
+
// yes, yes, this isn't the "original" version, but now that it's been
|
| 736 |
+
// upgraded, we need to make sure we don't do the work to upgrade it
|
| 737 |
+
// again, since it's now as new as can be.
|
| 738 |
+
if (!this.options.lockfileVersion && !meta.hiddenLockfile) {
|
| 739 |
+
meta.originalLockfileVersion = defaultLockfileVersion
|
| 740 |
+
}
|
| 741 |
+
this.finishTracker('idealTree:inflate')
|
| 742 |
+
timeEnd()
|
| 743 |
+
}
|
| 744 |
+
|
| 745 |
+
// at this point we have a virtual tree with the actual root node's
|
| 746 |
+
// package deps, which may be partly or entirely incomplete, invalid
|
| 747 |
+
// or extraneous.
|
| 748 |
+
#buildDeps () {
|
| 749 |
+
const timeEnd = time.start('idealTree:buildDeps')
|
| 750 |
+
const tree = this.idealTree.target
|
| 751 |
+
tree.assertRootOverrides()
|
| 752 |
+
this.#depsQueue.push(tree)
|
| 753 |
+
// XXX also push anything that depends on a node with a name
|
| 754 |
+
// in the override list
|
| 755 |
+
log.silly('idealTree', 'buildDeps')
|
| 756 |
+
this.addTracker('idealTree', tree.name, '')
|
| 757 |
+
return this.#buildDepStep().then(timeEnd)
|
| 758 |
+
}
|
| 759 |
+
|
| 760 |
+
async #buildDepStep () {
|
| 761 |
+
// removes tracker of previous dependency in the queue
|
| 762 |
+
if (this.#currentDep) {
|
| 763 |
+
const { location, name } = this.#currentDep
|
| 764 |
+
time.end(`idealTree:${location || '#root'}`)
|
| 765 |
+
this.finishTracker('idealTree', name, location)
|
| 766 |
+
this.#currentDep = null
|
| 767 |
+
}
|
| 768 |
+
|
| 769 |
+
if (!this.#depsQueue.length) {
|
| 770 |
+
return this.#resolveLinks()
|
| 771 |
+
}
|
| 772 |
+
|
| 773 |
+
const node = this.#depsQueue.pop()
|
| 774 |
+
const bd = node.package.bundleDependencies
|
| 775 |
+
const hasBundle = bd && Array.isArray(bd) && bd.length
|
| 776 |
+
const { hasShrinkwrap } = node
|
| 777 |
+
|
| 778 |
+
// if the node was already visited, or has since been removed from the
|
| 779 |
+
// tree, skip over it and process the rest of the queue. If a node has
|
| 780 |
+
// a shrinkwrap, also skip it, because it's going to get its deps
|
| 781 |
+
// satisfied by whatever's in that file anyway.
|
| 782 |
+
if (this.#depsSeen.has(node) ||
|
| 783 |
+
node.root !== this.idealTree ||
|
| 784 |
+
hasShrinkwrap && !this.#complete) {
|
| 785 |
+
return this.#buildDepStep()
|
| 786 |
+
}
|
| 787 |
+
|
| 788 |
+
this.#depsSeen.add(node)
|
| 789 |
+
this.#currentDep = node
|
| 790 |
+
time.start(`idealTree:${node.location || '#root'}`)
|
| 791 |
+
|
| 792 |
+
// if we're loading a _complete_ ideal tree, for a --package-lock-only
|
| 793 |
+
// installation for example, we have to crack open the tarball and
|
| 794 |
+
// look inside if it has bundle deps or shrinkwraps. note that this is
|
| 795 |
+
// not necessary during a reification, because we just update the
|
| 796 |
+
// ideal tree by reading bundles/shrinkwraps in place.
|
| 797 |
+
// Don't bother if the node is from the actual tree and hasn't
|
| 798 |
+
// been resolved, because we can't fetch it anyway, could be anything!
|
| 799 |
+
const crackOpen = this.#complete &&
|
| 800 |
+
node !== this.idealTree &&
|
| 801 |
+
node.resolved &&
|
| 802 |
+
(hasBundle || hasShrinkwrap)
|
| 803 |
+
if (crackOpen) {
|
| 804 |
+
const Arborist = this.constructor
|
| 805 |
+
const opt = { ...this.options }
|
| 806 |
+
await cacache.tmp.withTmp(this.cache, opt, async path => {
|
| 807 |
+
await pacote.extract(node.resolved, path, {
|
| 808 |
+
...opt,
|
| 809 |
+
Arborist,
|
| 810 |
+
resolved: node.resolved,
|
| 811 |
+
integrity: node.integrity,
|
| 812 |
+
})
|
| 813 |
+
|
| 814 |
+
if (hasShrinkwrap) {
|
| 815 |
+
await new Arborist({ ...this.options, path })
|
| 816 |
+
.loadVirtual({ root: node })
|
| 817 |
+
}
|
| 818 |
+
|
| 819 |
+
if (hasBundle) {
|
| 820 |
+
await new Arborist({ ...this.options, path })
|
| 821 |
+
.loadActual({ root: node, ignoreMissing: true })
|
| 822 |
+
}
|
| 823 |
+
})
|
| 824 |
+
}
|
| 825 |
+
|
| 826 |
+
// if any deps are missing or invalid, then we fetch the manifest for
|
| 827 |
+
// the thing we want, and build a new dep node from that.
|
| 828 |
+
// Then, find the ideal placement for that node. The ideal placement
|
| 829 |
+
// searches from the node's deps (or parent deps in the case of non-root
|
| 830 |
+
// peer deps), and walks up the tree until it finds the highest spot
|
| 831 |
+
// where it doesn't cause any conflicts.
|
| 832 |
+
//
|
| 833 |
+
// A conflict can be:
|
| 834 |
+
// - A node by that name already exists at that location.
|
| 835 |
+
// - The parent has a peer dep on that name
|
| 836 |
+
// - One of the node's peer deps conflicts at that location, unless the
|
| 837 |
+
// peer dep is met by a node at that location, which is fine.
|
| 838 |
+
//
|
| 839 |
+
// If we create a new node, then build its ideal deps as well.
|
| 840 |
+
//
|
| 841 |
+
// Note: this is the same "maximally naive" deduping tree-building
|
| 842 |
+
// algorithm that npm has used since v3. In a case like this:
|
| 843 |
+
//
|
| 844 |
+
// root -> (a@1, b@1||2)
|
| 845 |
+
// a -> (b@1)
|
| 846 |
+
//
|
| 847 |
+
// You'll end up with a tree like this:
|
| 848 |
+
//
|
| 849 |
+
// root
|
| 850 |
+
// +-- a@1
|
| 851 |
+
// | +-- b@1
|
| 852 |
+
// +-- b@2
|
| 853 |
+
//
|
| 854 |
+
// rather than this, more deduped, but just as correct tree:
|
| 855 |
+
//
|
| 856 |
+
// root
|
| 857 |
+
// +-- a@1
|
| 858 |
+
// +-- b@1
|
| 859 |
+
//
|
| 860 |
+
// Another way to look at it is that this algorithm favors getting higher
|
| 861 |
+
// version deps at higher levels in the tree, even if that reduces
|
| 862 |
+
// potential deduplication.
|
| 863 |
+
//
|
| 864 |
+
// Set `preferDedupe: true` in the options to replace the shallower
|
| 865 |
+
// dep if allowed.
|
| 866 |
+
|
| 867 |
+
const tasks = []
|
| 868 |
+
const peerSource = this.#peerSetSource.get(node) || node
|
| 869 |
+
for (const edge of this.#problemEdges(node)) {
|
| 870 |
+
if (edge.peerConflicted) {
|
| 871 |
+
continue
|
| 872 |
+
}
|
| 873 |
+
|
| 874 |
+
// peerSetSource is only relevant when we have a peerEntryEdge
|
| 875 |
+
// otherwise we're setting regular non-peer deps as if they have
|
| 876 |
+
// a virtual root of whatever brought in THIS node.
|
| 877 |
+
// so we VR the node itself if the edge is not a peer
|
| 878 |
+
const source = edge.peer ? peerSource : node
|
| 879 |
+
|
| 880 |
+
const virtualRoot = this.#virtualRoot(source, true)
|
| 881 |
+
// reuse virtual root if we already have one, but don't
|
| 882 |
+
// try to do the override ahead of time, since we MAY be able
|
| 883 |
+
// to create a more correct tree than the virtual root could.
|
| 884 |
+
const vrEdge = virtualRoot && virtualRoot.edgesOut.get(edge.name)
|
| 885 |
+
const vrDep = vrEdge && vrEdge.valid && vrEdge.to
|
| 886 |
+
// only re-use the virtualRoot if it's a peer edge we're placing.
|
| 887 |
+
// otherwise, we end up in situations where we override peer deps that
|
| 888 |
+
// we could have otherwise found homes for. Eg:
|
| 889 |
+
// xy -> (x, y)
|
| 890 |
+
// x -> PEER(z@1)
|
| 891 |
+
// y -> PEER(z@2)
|
| 892 |
+
// If xy is a dependency, we can resolve this like:
|
| 893 |
+
// project
|
| 894 |
+
// +-- xy
|
| 895 |
+
// | +-- y
|
| 896 |
+
// | +-- z@2
|
| 897 |
+
// +-- x
|
| 898 |
+
// +-- z@1
|
| 899 |
+
// But if x and y are loaded in the same virtual root, then they will
|
| 900 |
+
// be forced to agree on a version of z.
|
| 901 |
+
const required = new Set([edge.from])
|
| 902 |
+
const parent = edge.peer ? virtualRoot : null
|
| 903 |
+
const dep = vrDep && vrDep.satisfies(edge) ? vrDep
|
| 904 |
+
: await this.#nodeFromEdge(edge, parent, null, required)
|
| 905 |
+
|
| 906 |
+
/* istanbul ignore next */
|
| 907 |
+
debug(() => {
|
| 908 |
+
if (!dep) {
|
| 909 |
+
throw new Error('no dep??')
|
| 910 |
+
}
|
| 911 |
+
})
|
| 912 |
+
|
| 913 |
+
tasks.push({ edge, dep })
|
| 914 |
+
}
|
| 915 |
+
|
| 916 |
+
const placeDeps = tasks.sort((a, b) => localeCompare(a.edge.name, b.edge.name))
|
| 917 |
+
|
| 918 |
+
const promises = []
|
| 919 |
+
for (const { edge, dep } of placeDeps) {
|
| 920 |
+
const pd = new PlaceDep({
|
| 921 |
+
edge,
|
| 922 |
+
dep,
|
| 923 |
+
|
| 924 |
+
auditReport: this.auditReport,
|
| 925 |
+
explicitRequest: this.#explicitRequests.has(edge),
|
| 926 |
+
force: this.options.force,
|
| 927 |
+
installLinks: this.installLinks,
|
| 928 |
+
installStrategy: this.#installStrategy,
|
| 929 |
+
legacyPeerDeps: this.legacyPeerDeps,
|
| 930 |
+
preferDedupe: this.#preferDedupe,
|
| 931 |
+
strictPeerDeps: this.#strictPeerDeps,
|
| 932 |
+
updateNames: this[_updateNames],
|
| 933 |
+
})
|
| 934 |
+
// placing a dep is actually a tree of placing the dep itself
|
| 935 |
+
// and all of its peer group that aren't already met by the tree
|
| 936 |
+
depth({
|
| 937 |
+
tree: pd,
|
| 938 |
+
getChildren: pd => pd.children,
|
| 939 |
+
visit: pd => {
|
| 940 |
+
const { placed, edge, canPlace: cpd } = pd
|
| 941 |
+
// if we didn't place anything, nothing to do here
|
| 942 |
+
if (!placed) {
|
| 943 |
+
return
|
| 944 |
+
}
|
| 945 |
+
|
| 946 |
+
// we placed something, that means we changed the tree
|
| 947 |
+
if (placed.errors.length) {
|
| 948 |
+
this.#loadFailures.add(placed)
|
| 949 |
+
}
|
| 950 |
+
this.#mutateTree = true
|
| 951 |
+
if (cpd.canPlaceSelf === OK) {
|
| 952 |
+
for (const edgeIn of placed.edgesIn) {
|
| 953 |
+
if (edgeIn === edge) {
|
| 954 |
+
continue
|
| 955 |
+
}
|
| 956 |
+
const { from, valid, peerConflicted } = edgeIn
|
| 957 |
+
if (!peerConflicted && !valid && !this.#depsSeen.has(from)) {
|
| 958 |
+
this.addTracker('idealTree', from.name, from.location)
|
| 959 |
+
this.#depsQueue.push(edgeIn.from)
|
| 960 |
+
}
|
| 961 |
+
}
|
| 962 |
+
} else {
|
| 963 |
+
/* istanbul ignore else - should be only OK or REPLACE here */
|
| 964 |
+
if (cpd.canPlaceSelf === REPLACE) {
|
| 965 |
+
// this may also create some invalid edges, for example if we're
|
| 966 |
+
// intentionally causing something to get nested which was
|
| 967 |
+
// previously placed in this location.
|
| 968 |
+
for (const edgeIn of placed.edgesIn) {
|
| 969 |
+
if (edgeIn === edge) {
|
| 970 |
+
continue
|
| 971 |
+
}
|
| 972 |
+
|
| 973 |
+
const { valid, peerConflicted } = edgeIn
|
| 974 |
+
if (!valid && !peerConflicted) {
|
| 975 |
+
// if it's already been visited, we have to re-visit
|
| 976 |
+
// otherwise, just enqueue normally.
|
| 977 |
+
this.#depsSeen.delete(edgeIn.from)
|
| 978 |
+
this.#depsQueue.push(edgeIn.from)
|
| 979 |
+
}
|
| 980 |
+
}
|
| 981 |
+
}
|
| 982 |
+
}
|
| 983 |
+
|
| 984 |
+
/* istanbul ignore if - should be impossible */
|
| 985 |
+
if (cpd.canPlaceSelf === CONFLICT) {
|
| 986 |
+
debug(() => {
|
| 987 |
+
const er = new Error('placed with canPlaceSelf=CONFLICT')
|
| 988 |
+
throw Object.assign(er, { placeDep: pd })
|
| 989 |
+
})
|
| 990 |
+
return
|
| 991 |
+
}
|
| 992 |
+
|
| 993 |
+
// lastly, also check for the missing deps of the node we placed,
|
| 994 |
+
// and any holes created by pruning out conflicted peer sets.
|
| 995 |
+
this.#depsQueue.push(placed)
|
| 996 |
+
for (const dep of pd.needEvaluation) {
|
| 997 |
+
this.#depsSeen.delete(dep)
|
| 998 |
+
this.#depsQueue.push(dep)
|
| 999 |
+
}
|
| 1000 |
+
|
| 1001 |
+
// pre-fetch any problem edges, since we'll need these soon
|
| 1002 |
+
// if it fails at this point, though, dont' worry because it
|
| 1003 |
+
// may well be an optional dep that has gone missing. it'll
|
| 1004 |
+
// fail later anyway.
|
| 1005 |
+
for (const e of this.#problemEdges(placed)) {
|
| 1006 |
+
// XXX This is somehow load bearing. This makes tests that print
|
| 1007 |
+
// the ideal tree of a tree with tarball dependencies fail. This
|
| 1008 |
+
// can't be changed or removed till we figure out why
|
| 1009 |
+
// The test is named "tarball deps with transitive tarball deps"
|
| 1010 |
+
promises.push(() =>
|
| 1011 |
+
this.#fetchManifest(npa.resolve(e.name, e.spec, fromPath(placed, e)))
|
| 1012 |
+
.catch(() => null)
|
| 1013 |
+
)
|
| 1014 |
+
}
|
| 1015 |
+
},
|
| 1016 |
+
})
|
| 1017 |
+
}
|
| 1018 |
+
|
| 1019 |
+
for (const { to } of node.edgesOut.values()) {
|
| 1020 |
+
if (to && to.isLink && to.target) {
|
| 1021 |
+
this.#linkNodes.add(to)
|
| 1022 |
+
}
|
| 1023 |
+
}
|
| 1024 |
+
|
| 1025 |
+
await promiseCallLimit(promises)
|
| 1026 |
+
return this.#buildDepStep()
|
| 1027 |
+
}
|
| 1028 |
+
|
| 1029 |
+
// loads a node from an edge, and then loads its peer deps (and their
|
| 1030 |
+
// peer deps, on down the line) into a virtual root parent.
|
| 1031 |
+
async #nodeFromEdge (edge, parent_, secondEdge, required) {
|
| 1032 |
+
// create a virtual root node with the same deps as the node that
|
| 1033 |
+
// is requesting this one, so that we can get all the peer deps in
|
| 1034 |
+
// a context where they're likely to be resolvable.
|
| 1035 |
+
// Note that the virtual root will also have virtual copies of the
|
| 1036 |
+
// targets of any child Links, so that they resolve appropriately.
|
| 1037 |
+
const parent = parent_ || this.#virtualRoot(edge.from)
|
| 1038 |
+
|
| 1039 |
+
const spec = npa.resolve(edge.name, edge.spec, edge.from.path)
|
| 1040 |
+
const first = await this.#nodeFromSpec(edge.name, spec, parent, edge)
|
| 1041 |
+
|
| 1042 |
+
// we might have a case where the parent has a peer dependency on
|
| 1043 |
+
// `foo@*` which resolves to v2, but another dep in the set has a
|
| 1044 |
+
// peerDependency on `foo@1`. In that case, if we force it to be v2,
|
| 1045 |
+
// we're unnecessarily triggering an ERESOLVE.
|
| 1046 |
+
// If we have a second edge to worry about, and it's not satisfied
|
| 1047 |
+
// by the first node, try a second and see if that satisfies the
|
| 1048 |
+
// original edge here.
|
| 1049 |
+
const spec2 = secondEdge && npa.resolve(
|
| 1050 |
+
edge.name,
|
| 1051 |
+
secondEdge.spec,
|
| 1052 |
+
secondEdge.from.path
|
| 1053 |
+
)
|
| 1054 |
+
const second = secondEdge && !secondEdge.valid
|
| 1055 |
+
? await this.#nodeFromSpec(edge.name, spec2, parent, secondEdge)
|
| 1056 |
+
: null
|
| 1057 |
+
|
| 1058 |
+
// pick the second one if they're both happy with that, otherwise first
|
| 1059 |
+
const node = second && edge.valid ? second : first
|
| 1060 |
+
// ensure the one we want is the one that's placed
|
| 1061 |
+
node.parent = parent
|
| 1062 |
+
|
| 1063 |
+
if (required.has(edge.from) && edge.type !== 'peerOptional' ||
|
| 1064 |
+
secondEdge && (
|
| 1065 |
+
required.has(secondEdge.from) && secondEdge.type !== 'peerOptional')) {
|
| 1066 |
+
required.add(node)
|
| 1067 |
+
}
|
| 1068 |
+
|
| 1069 |
+
// keep track of the thing that caused this node to be included.
|
| 1070 |
+
const src = parent.sourceReference
|
| 1071 |
+
this.#peerSetSource.set(node, src)
|
| 1072 |
+
|
| 1073 |
+
// do not load the peers along with the set if this is a global top pkg
|
| 1074 |
+
// otherwise we'll be tempted to put peers as other top-level installed
|
| 1075 |
+
// things, potentially clobbering what's there already, which is not
|
| 1076 |
+
// what we want. the missing edges will be picked up on the next pass.
|
| 1077 |
+
if (this.options.global && edge.from.isProjectRoot) {
|
| 1078 |
+
return node
|
| 1079 |
+
}
|
| 1080 |
+
|
| 1081 |
+
// otherwise, we have to make sure that our peers can go along with us.
|
| 1082 |
+
return this.#loadPeerSet(node, required)
|
| 1083 |
+
}
|
| 1084 |
+
|
| 1085 |
+
#virtualRoot (node, reuse = false) {
|
| 1086 |
+
if (reuse && this.#virtualRoots.has(node)) {
|
| 1087 |
+
return this.#virtualRoots.get(node)
|
| 1088 |
+
}
|
| 1089 |
+
|
| 1090 |
+
const vr = new Node({
|
| 1091 |
+
path: node.realpath,
|
| 1092 |
+
sourceReference: node,
|
| 1093 |
+
installLinks: this.installLinks,
|
| 1094 |
+
legacyPeerDeps: this.legacyPeerDeps,
|
| 1095 |
+
overrides: node.overrides,
|
| 1096 |
+
})
|
| 1097 |
+
|
| 1098 |
+
// also need to set up any targets from any link deps, so that
|
| 1099 |
+
// they are properly reflected in the virtual environment
|
| 1100 |
+
for (const child of node.children.values()) {
|
| 1101 |
+
if (child.isLink) {
|
| 1102 |
+
new Node({
|
| 1103 |
+
path: child.realpath,
|
| 1104 |
+
sourceReference: child.target,
|
| 1105 |
+
root: vr,
|
| 1106 |
+
})
|
| 1107 |
+
}
|
| 1108 |
+
}
|
| 1109 |
+
|
| 1110 |
+
this.#virtualRoots.set(node, vr)
|
| 1111 |
+
return vr
|
| 1112 |
+
}
|
| 1113 |
+
|
| 1114 |
+
#problemEdges (node) {
|
| 1115 |
+
// skip over any bundled deps, they're not our problem.
|
| 1116 |
+
// Note that this WILL fetch bundled meta-deps which are also dependencies
|
| 1117 |
+
// but not listed as bundled deps. When reifying, we first unpack any
|
| 1118 |
+
// nodes that have bundleDependencies, then do a loadActual on them, move
|
| 1119 |
+
// the nodes into the ideal tree, and then prune. So, fetching those
|
| 1120 |
+
// possibly-bundled meta-deps at this point doesn't cause any worse
|
| 1121 |
+
// problems than a few unnecessary packument fetches.
|
| 1122 |
+
|
| 1123 |
+
// also skip over any nodes in the tree that failed to load, since those
|
| 1124 |
+
// will crash the install later on anyway.
|
| 1125 |
+
const bd = node.isProjectRoot || node.isWorkspace ? null
|
| 1126 |
+
: node.package.bundleDependencies
|
| 1127 |
+
const bundled = new Set(bd || [])
|
| 1128 |
+
|
| 1129 |
+
const problems = []
|
| 1130 |
+
for (const edge of node.edgesOut.values()) {
|
| 1131 |
+
// If it's included in a bundle, we take whatever is specified.
|
| 1132 |
+
if (bundled.has(edge.name)) {
|
| 1133 |
+
continue
|
| 1134 |
+
}
|
| 1135 |
+
|
| 1136 |
+
// If it's already been logged as a load failure, skip it.
|
| 1137 |
+
if (edge.to && this.#loadFailures.has(edge.to)) {
|
| 1138 |
+
continue
|
| 1139 |
+
}
|
| 1140 |
+
|
| 1141 |
+
// If it's shrinkwrapped, we use what the shrinkwap wants.
|
| 1142 |
+
if (edge.to && edge.to.inShrinkwrap) {
|
| 1143 |
+
continue
|
| 1144 |
+
}
|
| 1145 |
+
|
| 1146 |
+
// If the edge has no destination, that's a problem, unless
|
| 1147 |
+
// if it's peerOptional and not explicitly requested.
|
| 1148 |
+
if (!edge.to) {
|
| 1149 |
+
if (edge.type !== 'peerOptional' ||
|
| 1150 |
+
this.#explicitRequests.has(edge)) {
|
| 1151 |
+
problems.push(edge)
|
| 1152 |
+
}
|
| 1153 |
+
continue
|
| 1154 |
+
}
|
| 1155 |
+
|
| 1156 |
+
// If the edge has an error, there's a problem.
|
| 1157 |
+
if (!edge.valid) {
|
| 1158 |
+
problems.push(edge)
|
| 1159 |
+
continue
|
| 1160 |
+
}
|
| 1161 |
+
|
| 1162 |
+
// If the edge is a workspace, and it's valid, leave it alone
|
| 1163 |
+
if (edge.to.isWorkspace) {
|
| 1164 |
+
continue
|
| 1165 |
+
}
|
| 1166 |
+
|
| 1167 |
+
// user explicitly asked to update this package by name, problem
|
| 1168 |
+
if (this[_updateNames].includes(edge.name)) {
|
| 1169 |
+
problems.push(edge)
|
| 1170 |
+
continue
|
| 1171 |
+
}
|
| 1172 |
+
|
| 1173 |
+
// fixing a security vulnerability with this package, problem
|
| 1174 |
+
if (this.auditReport && this.auditReport.isVulnerable(edge.to)) {
|
| 1175 |
+
problems.push(edge)
|
| 1176 |
+
continue
|
| 1177 |
+
}
|
| 1178 |
+
|
| 1179 |
+
// user has explicitly asked to install this package, problem
|
| 1180 |
+
if (this.#explicitRequests.has(edge)) {
|
| 1181 |
+
problems.push(edge)
|
| 1182 |
+
continue
|
| 1183 |
+
}
|
| 1184 |
+
}
|
| 1185 |
+
return problems
|
| 1186 |
+
}
|
| 1187 |
+
|
| 1188 |
+
async #fetchManifest (spec) {
|
| 1189 |
+
const options = {
|
| 1190 |
+
...this.options,
|
| 1191 |
+
avoid: this.#avoidRange(spec.name),
|
| 1192 |
+
fullMetadata: true,
|
| 1193 |
+
}
|
| 1194 |
+
// get the intended spec and stored metadata from yarn.lock file,
|
| 1195 |
+
// if available and valid.
|
| 1196 |
+
spec = this.idealTree.meta.checkYarnLock(spec, options)
|
| 1197 |
+
|
| 1198 |
+
if (this.#manifests.has(spec.raw)) {
|
| 1199 |
+
return this.#manifests.get(spec.raw)
|
| 1200 |
+
} else {
|
| 1201 |
+
log.silly('fetch manifest', spec.raw.replace(spec.rawSpec, redact(spec.rawSpec)))
|
| 1202 |
+
const mani = await pacote.manifest(spec, options)
|
| 1203 |
+
this.#manifests.set(spec.raw, mani)
|
| 1204 |
+
return mani
|
| 1205 |
+
}
|
| 1206 |
+
}
|
| 1207 |
+
|
| 1208 |
+
#nodeFromSpec (name, spec, parent, edge) {
|
| 1209 |
+
// pacote will slap integrity on its options, so we have to clone
|
| 1210 |
+
// the object so it doesn't get mutated.
|
| 1211 |
+
// Don't bother to load the manifest for link deps, because the target
|
| 1212 |
+
// might be within another package that doesn't exist yet.
|
| 1213 |
+
const { installLinks, legacyPeerDeps } = this
|
| 1214 |
+
const isWorkspace = this.idealTree.workspaces && this.idealTree.workspaces.has(spec.name)
|
| 1215 |
+
|
| 1216 |
+
// spec is a directory, link it unless installLinks is set or it's a workspace
|
| 1217 |
+
// TODO post arborist refactor, will need to check for installStrategy=linked
|
| 1218 |
+
if (spec.type === 'directory' && (isWorkspace || !installLinks)) {
|
| 1219 |
+
return this.#linkFromSpec(name, spec, parent, edge)
|
| 1220 |
+
}
|
| 1221 |
+
|
| 1222 |
+
// if the spec matches a workspace name, then see if the workspace node will
|
| 1223 |
+
// satisfy the edge. if it does, we return the workspace node to make sure it
|
| 1224 |
+
// takes priority.
|
| 1225 |
+
if (isWorkspace) {
|
| 1226 |
+
const existingNode = this.idealTree.edgesOut.get(spec.name).to
|
| 1227 |
+
if (existingNode && existingNode.isWorkspace && existingNode.satisfies(edge)) {
|
| 1228 |
+
return existingNode
|
| 1229 |
+
}
|
| 1230 |
+
}
|
| 1231 |
+
|
| 1232 |
+
// spec isn't a directory, and either isn't a workspace or the workspace we have
|
| 1233 |
+
// doesn't satisfy the edge. try to fetch a manifest and build a node from that.
|
| 1234 |
+
return this.#fetchManifest(spec)
|
| 1235 |
+
.then(pkg => new Node({ name, pkg, parent, installLinks, legacyPeerDeps }), error => {
|
| 1236 |
+
error.requiredBy = edge.from.location || '.'
|
| 1237 |
+
|
| 1238 |
+
// failed to load the spec, either because of enotarget or
|
| 1239 |
+
// fetch failure of some other sort. save it so we can verify
|
| 1240 |
+
// later that it's optional, otherwise the error is fatal.
|
| 1241 |
+
const n = new Node({
|
| 1242 |
+
name,
|
| 1243 |
+
parent,
|
| 1244 |
+
error,
|
| 1245 |
+
installLinks,
|
| 1246 |
+
legacyPeerDeps,
|
| 1247 |
+
})
|
| 1248 |
+
this.#loadFailures.add(n)
|
| 1249 |
+
return n
|
| 1250 |
+
})
|
| 1251 |
+
}
|
| 1252 |
+
|
| 1253 |
+
#linkFromSpec (name, spec, parent) {
|
| 1254 |
+
const realpath = spec.fetchSpec
|
| 1255 |
+
const { installLinks, legacyPeerDeps } = this
|
| 1256 |
+
return rpj(realpath + '/package.json').catch(() => ({})).then(pkg => {
|
| 1257 |
+
const link = new Link({ name, parent, realpath, pkg, installLinks, legacyPeerDeps })
|
| 1258 |
+
this.#linkNodes.add(link)
|
| 1259 |
+
return link
|
| 1260 |
+
})
|
| 1261 |
+
}
|
| 1262 |
+
|
| 1263 |
+
// load all peer deps and meta-peer deps into the node's parent
|
| 1264 |
+
// At the end of this, the node's peer-type outward edges are all
|
| 1265 |
+
// resolved, and so are all of theirs, but other dep types are not.
|
| 1266 |
+
// We prefer to get peer deps that meet the requiring node's dependency,
|
| 1267 |
+
// if possible, since that almost certainly works (since that package was
|
| 1268 |
+
// developed with this set of deps) and will typically be more restrictive.
|
| 1269 |
+
// Note that the peers in the set can conflict either with each other,
|
| 1270 |
+
// or with a direct dependency from the virtual root parent! In strict
|
| 1271 |
+
// mode, this is always an error. In force mode, it never is, and we
|
| 1272 |
+
// prefer the parent's non-peer dep over a peer dep, or the version that
|
| 1273 |
+
// gets placed first. In non-strict mode, we behave strictly if the
|
| 1274 |
+
// virtual root is based on the root project, and allow non-peer parent
|
| 1275 |
+
// deps to override, but throw if no preference can be determined.
|
| 1276 |
+
async #loadPeerSet (node, required) {
|
| 1277 |
+
const peerEdges = [...node.edgesOut.values()]
|
| 1278 |
+
// we typically only install non-optional peers, but we have to
|
| 1279 |
+
// factor them into the peerSet so that we can avoid conflicts
|
| 1280 |
+
.filter(e => e.peer && !(e.valid && e.to))
|
| 1281 |
+
.sort(({ name: a }, { name: b }) => localeCompare(a, b))
|
| 1282 |
+
|
| 1283 |
+
for (const edge of peerEdges) {
|
| 1284 |
+
// already placed this one, and we're happy with it.
|
| 1285 |
+
if (edge.valid && edge.to) {
|
| 1286 |
+
continue
|
| 1287 |
+
}
|
| 1288 |
+
|
| 1289 |
+
const parentEdge = node.parent.edgesOut.get(edge.name)
|
| 1290 |
+
const { isProjectRoot, isWorkspace } = node.parent.sourceReference
|
| 1291 |
+
const isMine = isProjectRoot || isWorkspace
|
| 1292 |
+
const conflictOK = this.options.force || !isMine && !this.#strictPeerDeps
|
| 1293 |
+
|
| 1294 |
+
if (!edge.to) {
|
| 1295 |
+
if (!parentEdge) {
|
| 1296 |
+
// easy, just put the thing there
|
| 1297 |
+
await this.#nodeFromEdge(edge, node.parent, null, required)
|
| 1298 |
+
continue
|
| 1299 |
+
} else {
|
| 1300 |
+
// if the parent's edge is very broad like >=1, and the edge in
|
| 1301 |
+
// question is something like 1.x, then we want to get a 1.x, not
|
| 1302 |
+
// a 2.x. pass along the child edge as an advisory guideline.
|
| 1303 |
+
// if the parent edge doesn't satisfy the child edge, and the
|
| 1304 |
+
// child edge doesn't satisfy the parent edge, then we have
|
| 1305 |
+
// a conflict. this is always a problem in strict mode, never
|
| 1306 |
+
// in force mode, and a problem in non-strict mode if this isn't
|
| 1307 |
+
// on behalf of our project. in all such cases, we warn at least.
|
| 1308 |
+
const dep = await this.#nodeFromEdge(
|
| 1309 |
+
parentEdge,
|
| 1310 |
+
node.parent,
|
| 1311 |
+
edge,
|
| 1312 |
+
required
|
| 1313 |
+
)
|
| 1314 |
+
|
| 1315 |
+
// hooray! that worked!
|
| 1316 |
+
if (edge.valid) {
|
| 1317 |
+
continue
|
| 1318 |
+
}
|
| 1319 |
+
|
| 1320 |
+
// allow it. either we're overriding, or it's not something
|
| 1321 |
+
// that will be installed by default anyway, and we'll fail when
|
| 1322 |
+
// we get to the point where we need to, if we need to.
|
| 1323 |
+
if (conflictOK || !required.has(dep)) {
|
| 1324 |
+
edge.peerConflicted = true
|
| 1325 |
+
continue
|
| 1326 |
+
}
|
| 1327 |
+
|
| 1328 |
+
// problem
|
| 1329 |
+
this.#failPeerConflict(edge, parentEdge)
|
| 1330 |
+
}
|
| 1331 |
+
}
|
| 1332 |
+
|
| 1333 |
+
// There is something present already, and we're not happy about it
|
| 1334 |
+
// See if the thing we WOULD be happy with is also going to satisfy
|
| 1335 |
+
// the other dependents on the current node.
|
| 1336 |
+
const current = edge.to
|
| 1337 |
+
const dep = await this.#nodeFromEdge(edge, null, null, required)
|
| 1338 |
+
if (dep.canReplace(current)) {
|
| 1339 |
+
await this.#nodeFromEdge(edge, node.parent, null, required)
|
| 1340 |
+
continue
|
| 1341 |
+
}
|
| 1342 |
+
|
| 1343 |
+
// at this point we know that there is a dep there, and
|
| 1344 |
+
// we don't like it. always fail strictly, always allow forcibly or
|
| 1345 |
+
// in non-strict mode if it's not our fault. don't warn here, because
|
| 1346 |
+
// we are going to warn again when we place the deps, if we end up
|
| 1347 |
+
// overriding for something else. If the thing that has this dep
|
| 1348 |
+
// isn't also required, then there's a good chance we won't need it,
|
| 1349 |
+
// so allow it for now and let it conflict if it turns out to actually
|
| 1350 |
+
// be necessary for the installation.
|
| 1351 |
+
if (conflictOK || !required.has(edge.from)) {
|
| 1352 |
+
continue
|
| 1353 |
+
}
|
| 1354 |
+
|
| 1355 |
+
// ok, it's the root, or we're in unforced strict mode, so this is bad
|
| 1356 |
+
this.#failPeerConflict(edge, parentEdge)
|
| 1357 |
+
}
|
| 1358 |
+
return node
|
| 1359 |
+
}
|
| 1360 |
+
|
| 1361 |
+
#failPeerConflict (edge, currentEdge) {
|
| 1362 |
+
const expl = this.#explainPeerConflict(edge, currentEdge)
|
| 1363 |
+
throw Object.assign(new Error('unable to resolve dependency tree'), expl)
|
| 1364 |
+
}
|
| 1365 |
+
|
| 1366 |
+
#explainPeerConflict (edge, currentEdge) {
|
| 1367 |
+
const node = edge.from
|
| 1368 |
+
const curNode = node.resolve(edge.name)
|
| 1369 |
+
const current = curNode.explain()
|
| 1370 |
+
return {
|
| 1371 |
+
code: 'ERESOLVE',
|
| 1372 |
+
current,
|
| 1373 |
+
// it SHOULD be impossible to get here without a current node in place,
|
| 1374 |
+
// but this at least gives us something report on when bugs creep into
|
| 1375 |
+
// the tree handling logic.
|
| 1376 |
+
currentEdge: currentEdge ? currentEdge.explain() : null,
|
| 1377 |
+
edge: edge.explain(),
|
| 1378 |
+
strictPeerDeps: this.#strictPeerDeps,
|
| 1379 |
+
force: this.options.force,
|
| 1380 |
+
}
|
| 1381 |
+
}
|
| 1382 |
+
|
| 1383 |
+
// go through all the links in the this.#linkNodes set
|
| 1384 |
+
// for each one:
|
| 1385 |
+
// - if outside the root, ignore it, assume it's fine, it's not our problem
|
| 1386 |
+
// - if a node in the tree already, assign the target to that node.
|
| 1387 |
+
// - if a path under an existing node, then assign that as the fsParent,
|
| 1388 |
+
// and add it to the _depsQueue
|
| 1389 |
+
//
|
| 1390 |
+
// call buildDepStep if anything was added to the queue, otherwise we're done
|
| 1391 |
+
#resolveLinks () {
|
| 1392 |
+
for (const link of this.#linkNodes) {
|
| 1393 |
+
this.#linkNodes.delete(link)
|
| 1394 |
+
|
| 1395 |
+
// link we never ended up placing, skip it
|
| 1396 |
+
if (link.root !== this.idealTree) {
|
| 1397 |
+
continue
|
| 1398 |
+
}
|
| 1399 |
+
|
| 1400 |
+
const tree = this.idealTree.target
|
| 1401 |
+
const external = !link.target.isDescendantOf(tree)
|
| 1402 |
+
|
| 1403 |
+
// outside the root, somebody else's problem, ignore it
|
| 1404 |
+
if (external && !this.#follow) {
|
| 1405 |
+
continue
|
| 1406 |
+
}
|
| 1407 |
+
|
| 1408 |
+
// didn't find a parent for it or it has not been seen yet
|
| 1409 |
+
// so go ahead and process it.
|
| 1410 |
+
const unseenLink = (link.target.parent || link.target.fsParent) &&
|
| 1411 |
+
!this.#depsSeen.has(link.target)
|
| 1412 |
+
|
| 1413 |
+
if (this.#follow &&
|
| 1414 |
+
!link.target.parent &&
|
| 1415 |
+
!link.target.fsParent ||
|
| 1416 |
+
unseenLink) {
|
| 1417 |
+
this.addTracker('idealTree', link.target.name, link.target.location)
|
| 1418 |
+
this.#depsQueue.push(link.target)
|
| 1419 |
+
}
|
| 1420 |
+
}
|
| 1421 |
+
|
| 1422 |
+
if (this.#depsQueue.length) {
|
| 1423 |
+
return this.#buildDepStep()
|
| 1424 |
+
}
|
| 1425 |
+
}
|
| 1426 |
+
|
| 1427 |
+
#fixDepFlags () {
|
| 1428 |
+
const timeEnd = time.start('idealTree:fixDepFlags')
|
| 1429 |
+
const metaFromDisk = this.idealTree.meta.loadedFromDisk
|
| 1430 |
+
const flagsSuspect = this[_flagsSuspect]
|
| 1431 |
+
const mutateTree = this.#mutateTree
|
| 1432 |
+
// if the options set prune:false, then we don't prune, but we still
|
| 1433 |
+
// mark the extraneous items in the tree if we modified it at all.
|
| 1434 |
+
// If we did no modifications, we just iterate over the extraneous nodes.
|
| 1435 |
+
// if we started with an empty tree, then the dep flags are already
|
| 1436 |
+
// all set to true, and there can be nothing extraneous, so there's
|
| 1437 |
+
// nothing to prune, because we built it from scratch. if we didn't
|
| 1438 |
+
// add or remove anything, then also nothing to do.
|
| 1439 |
+
if (metaFromDisk && mutateTree) {
|
| 1440 |
+
resetDepFlags(this.idealTree)
|
| 1441 |
+
}
|
| 1442 |
+
|
| 1443 |
+
// update all the dev/optional/etc flags in the tree
|
| 1444 |
+
// either we started with a fresh tree, or we
|
| 1445 |
+
// reset all the flags to find the extraneous nodes.
|
| 1446 |
+
//
|
| 1447 |
+
// if we started from a blank slate, or changed something, then
|
| 1448 |
+
// the dep flags will be all set to true.
|
| 1449 |
+
if (!metaFromDisk || mutateTree) {
|
| 1450 |
+
calcDepFlags(this.idealTree)
|
| 1451 |
+
} else {
|
| 1452 |
+
// otherwise just unset all the flags on the root node
|
| 1453 |
+
// since they will sometimes have the default value
|
| 1454 |
+
this.idealTree.extraneous = false
|
| 1455 |
+
this.idealTree.dev = false
|
| 1456 |
+
this.idealTree.optional = false
|
| 1457 |
+
this.idealTree.devOptional = false
|
| 1458 |
+
this.idealTree.peer = false
|
| 1459 |
+
}
|
| 1460 |
+
|
| 1461 |
+
// at this point, any node marked as extraneous should be pruned.
|
| 1462 |
+
// if we started from a shrinkwrap, and then added/removed something,
|
| 1463 |
+
// then the tree is suspect. Prune what is marked as extraneous.
|
| 1464 |
+
// otherwise, don't bother.
|
| 1465 |
+
const needPrune = metaFromDisk && (mutateTree || flagsSuspect)
|
| 1466 |
+
if (this.#prune && needPrune) {
|
| 1467 |
+
this.#idealTreePrune()
|
| 1468 |
+
for (const node of this.idealTree.inventory.values()) {
|
| 1469 |
+
if (node.extraneous) {
|
| 1470 |
+
node.parent = null
|
| 1471 |
+
}
|
| 1472 |
+
}
|
| 1473 |
+
}
|
| 1474 |
+
|
| 1475 |
+
timeEnd()
|
| 1476 |
+
}
|
| 1477 |
+
|
| 1478 |
+
#idealTreePrune () {
|
| 1479 |
+
for (const node of this.idealTree.inventory.values()) {
|
| 1480 |
+
if (node.extraneous) {
|
| 1481 |
+
node.parent = null
|
| 1482 |
+
}
|
| 1483 |
+
}
|
| 1484 |
+
}
|
| 1485 |
+
|
| 1486 |
+
#pruneFailedOptional () {
|
| 1487 |
+
for (const node of this.#loadFailures) {
|
| 1488 |
+
if (!node.optional) {
|
| 1489 |
+
throw node.errors[0]
|
| 1490 |
+
}
|
| 1491 |
+
|
| 1492 |
+
const set = optionalSet(node)
|
| 1493 |
+
for (const node of set) {
|
| 1494 |
+
node.parent = null
|
| 1495 |
+
}
|
| 1496 |
+
}
|
| 1497 |
+
}
|
| 1498 |
+
|
| 1499 |
+
async prune (options = {}) {
|
| 1500 |
+
// allow the user to set options on the ctor as well.
|
| 1501 |
+
// XXX: deprecate separate method options objects.
|
| 1502 |
+
options = { ...this.options, ...options }
|
| 1503 |
+
|
| 1504 |
+
await this.buildIdealTree(options)
|
| 1505 |
+
|
| 1506 |
+
this.#idealTreePrune()
|
| 1507 |
+
|
| 1508 |
+
if (!this.options.workspacesEnabled) {
|
| 1509 |
+
const excludeNodes = this.excludeWorkspacesDependencySet(this.idealTree)
|
| 1510 |
+
for (const node of this.idealTree.inventory.values()) {
|
| 1511 |
+
if (
|
| 1512 |
+
node.parent !== null
|
| 1513 |
+
&& !node.isProjectRoot
|
| 1514 |
+
&& !excludeNodes.has(node)
|
| 1515 |
+
) {
|
| 1516 |
+
this[_addNodeToTrashList](node)
|
| 1517 |
+
}
|
| 1518 |
+
}
|
| 1519 |
+
}
|
| 1520 |
+
|
| 1521 |
+
return this.reify(options)
|
| 1522 |
+
}
|
| 1523 |
+
}
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/index.js
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// The arborist manages three trees:
|
| 2 |
+
// - actual
|
| 3 |
+
// - virtual
|
| 4 |
+
// - ideal
|
| 5 |
+
//
|
| 6 |
+
// The actual tree is what's present on disk in the node_modules tree
|
| 7 |
+
// and elsewhere that links may extend.
|
| 8 |
+
//
|
| 9 |
+
// The virtual tree is loaded from metadata (package.json and lock files).
|
| 10 |
+
//
|
| 11 |
+
// The ideal tree is what we WANT that actual tree to become. This starts
|
| 12 |
+
// with the virtual tree, and then applies the options requesting
|
| 13 |
+
// add/remove/update actions.
|
| 14 |
+
//
|
| 15 |
+
// To reify a tree, we calculate a diff between the ideal and actual trees,
|
| 16 |
+
// and then turn the actual tree into the ideal tree by taking the actions
|
| 17 |
+
// required. At the end of the reification process, the actualTree is
|
| 18 |
+
// updated to reflect the changes.
|
| 19 |
+
//
|
| 20 |
+
// Each tree has an Inventory at the root. Shrinkwrap is tracked by Arborist
|
| 21 |
+
// instance. It always refers to the actual tree, but is updated (and written
|
| 22 |
+
// to disk) on reification.
|
| 23 |
+
|
| 24 |
+
// Each of the mixin "classes" adds functionality, but are not dependent on
|
| 25 |
+
// constructor call order. So, we just load them in an array, and build up
|
| 26 |
+
// the base class, so that the overall voltron class is easier to test and
|
| 27 |
+
// cover, and separation of concerns can be maintained.
|
| 28 |
+
|
| 29 |
+
const { resolve } = require('node:path')
|
| 30 |
+
const { homedir } = require('node:os')
|
| 31 |
+
const { depth } = require('treeverse')
|
| 32 |
+
const mapWorkspaces = require('@npmcli/map-workspaces')
|
| 33 |
+
const { log, time } = require('proc-log')
|
| 34 |
+
const { saveTypeMap } = require('../add-rm-pkg-deps.js')
|
| 35 |
+
const AuditReport = require('../audit-report.js')
|
| 36 |
+
const relpath = require('../relpath.js')
|
| 37 |
+
const PackumentCache = require('../packument-cache.js')
|
| 38 |
+
|
| 39 |
+
const mixins = [
|
| 40 |
+
require('../tracker.js'),
|
| 41 |
+
require('./build-ideal-tree.js'),
|
| 42 |
+
require('./load-actual.js'),
|
| 43 |
+
require('./load-virtual.js'),
|
| 44 |
+
require('./rebuild.js'),
|
| 45 |
+
require('./reify.js'),
|
| 46 |
+
require('./isolated-reifier.js'),
|
| 47 |
+
]
|
| 48 |
+
|
| 49 |
+
const _setWorkspaces = Symbol.for('setWorkspaces')
|
| 50 |
+
const Base = mixins.reduce((a, b) => b(a), require('node:events'))
|
| 51 |
+
|
| 52 |
+
// if it's 1, 2, or 3, set it explicitly that.
|
| 53 |
+
// if undefined or null, set it null
|
| 54 |
+
// otherwise, throw.
|
| 55 |
+
const lockfileVersion = lfv => {
|
| 56 |
+
if (lfv === 1 || lfv === 2 || lfv === 3) {
|
| 57 |
+
return lfv
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
if (lfv === undefined || lfv === null) {
|
| 61 |
+
return null
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
throw new TypeError('Invalid lockfileVersion config: ' + lfv)
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
class Arborist extends Base {
|
| 68 |
+
constructor (options = {}) {
|
| 69 |
+
const timeEnd = time.start('arborist:ctor')
|
| 70 |
+
super(options)
|
| 71 |
+
this.options = {
|
| 72 |
+
nodeVersion: process.version,
|
| 73 |
+
...options,
|
| 74 |
+
Arborist: this.constructor,
|
| 75 |
+
binLinks: 'binLinks' in options ? !!options.binLinks : true,
|
| 76 |
+
cache: options.cache || `${homedir()}/.npm/_cacache`,
|
| 77 |
+
dryRun: !!options.dryRun,
|
| 78 |
+
formatPackageLock: 'formatPackageLock' in options ? !!options.formatPackageLock : true,
|
| 79 |
+
force: !!options.force,
|
| 80 |
+
global: !!options.global,
|
| 81 |
+
ignoreScripts: !!options.ignoreScripts,
|
| 82 |
+
installStrategy: options.global ? 'shallow' : (options.installStrategy ? options.installStrategy : 'hoisted'),
|
| 83 |
+
lockfileVersion: lockfileVersion(options.lockfileVersion),
|
| 84 |
+
packageLockOnly: !!options.packageLockOnly,
|
| 85 |
+
packumentCache: options.packumentCache || new PackumentCache(),
|
| 86 |
+
path: options.path || '.',
|
| 87 |
+
rebuildBundle: 'rebuildBundle' in options ? !!options.rebuildBundle : true,
|
| 88 |
+
replaceRegistryHost: options.replaceRegistryHost,
|
| 89 |
+
savePrefix: 'savePrefix' in options ? options.savePrefix : '^',
|
| 90 |
+
scriptShell: options.scriptShell,
|
| 91 |
+
workspaces: options.workspaces || [],
|
| 92 |
+
workspacesEnabled: options.workspacesEnabled !== false,
|
| 93 |
+
}
|
| 94 |
+
// TODO we only ever look at this.options.replaceRegistryHost, not
|
| 95 |
+
// this.replaceRegistryHost. Defaulting needs to be written back to
|
| 96 |
+
// this.options to work properly
|
| 97 |
+
this.replaceRegistryHost = this.options.replaceRegistryHost =
|
| 98 |
+
(!this.options.replaceRegistryHost || this.options.replaceRegistryHost === 'npmjs') ?
|
| 99 |
+
'registry.npmjs.org' : this.options.replaceRegistryHost
|
| 100 |
+
|
| 101 |
+
if (options.saveType && !saveTypeMap.get(options.saveType)) {
|
| 102 |
+
throw new Error(`Invalid saveType ${options.saveType}`)
|
| 103 |
+
}
|
| 104 |
+
this.cache = resolve(this.options.cache)
|
| 105 |
+
this.diff = null
|
| 106 |
+
this.path = resolve(this.options.path)
|
| 107 |
+
timeEnd()
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
// TODO: We should change these to static functions instead
|
| 111 |
+
// of methods for the next major version
|
| 112 |
+
|
| 113 |
+
// Get the actual nodes corresponding to a root node's child workspaces,
|
| 114 |
+
// given a list of workspace names.
|
| 115 |
+
workspaceNodes (tree, workspaces) {
|
| 116 |
+
const wsMap = tree.workspaces
|
| 117 |
+
if (!wsMap) {
|
| 118 |
+
log.warn('workspaces', 'filter set, but no workspaces present')
|
| 119 |
+
return []
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
const nodes = []
|
| 123 |
+
for (const name of workspaces) {
|
| 124 |
+
const path = wsMap.get(name)
|
| 125 |
+
if (!path) {
|
| 126 |
+
log.warn('workspaces', `${name} in filter set, but not in workspaces`)
|
| 127 |
+
continue
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
const loc = relpath(tree.realpath, path)
|
| 131 |
+
const node = tree.inventory.get(loc)
|
| 132 |
+
|
| 133 |
+
if (!node) {
|
| 134 |
+
log.warn('workspaces', `${name} in filter set, but no workspace folder present`)
|
| 135 |
+
continue
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
nodes.push(node)
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
return nodes
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
// returns a set of workspace nodes and all their deps
|
| 145 |
+
// TODO why is includeWorkspaceRoot a param?
|
| 146 |
+
// TODO why is workspaces a param?
|
| 147 |
+
workspaceDependencySet (tree, workspaces, includeWorkspaceRoot) {
|
| 148 |
+
const wsNodes = this.workspaceNodes(tree, workspaces)
|
| 149 |
+
if (includeWorkspaceRoot) {
|
| 150 |
+
for (const edge of tree.edgesOut.values()) {
|
| 151 |
+
if (edge.type !== 'workspace' && edge.to) {
|
| 152 |
+
wsNodes.push(edge.to)
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
const wsDepSet = new Set(wsNodes)
|
| 157 |
+
const extraneous = new Set()
|
| 158 |
+
for (const node of wsDepSet) {
|
| 159 |
+
for (const edge of node.edgesOut.values()) {
|
| 160 |
+
const dep = edge.to
|
| 161 |
+
if (dep) {
|
| 162 |
+
wsDepSet.add(dep)
|
| 163 |
+
if (dep.isLink) {
|
| 164 |
+
wsDepSet.add(dep.target)
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
}
|
| 168 |
+
for (const child of node.children.values()) {
|
| 169 |
+
if (child.extraneous) {
|
| 170 |
+
extraneous.add(child)
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
for (const extra of extraneous) {
|
| 175 |
+
wsDepSet.add(extra)
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
return wsDepSet
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
// returns a set of root dependencies, excluding dependencies that are
|
| 182 |
+
// exclusively workspace dependencies
|
| 183 |
+
excludeWorkspacesDependencySet (tree) {
|
| 184 |
+
const rootDepSet = new Set()
|
| 185 |
+
depth({
|
| 186 |
+
tree,
|
| 187 |
+
visit: node => {
|
| 188 |
+
for (const { to } of node.edgesOut.values()) {
|
| 189 |
+
if (!to || to.isWorkspace) {
|
| 190 |
+
continue
|
| 191 |
+
}
|
| 192 |
+
for (const edgeIn of to.edgesIn.values()) {
|
| 193 |
+
if (edgeIn.from.isRoot || rootDepSet.has(edgeIn.from)) {
|
| 194 |
+
rootDepSet.add(to)
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
return node
|
| 199 |
+
},
|
| 200 |
+
filter: node => node,
|
| 201 |
+
getChildren: (node, tree) =>
|
| 202 |
+
[...tree.edgesOut.values()].map(edge => edge.to),
|
| 203 |
+
})
|
| 204 |
+
return rootDepSet
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
async [_setWorkspaces] (node) {
|
| 208 |
+
const workspaces = await mapWorkspaces({
|
| 209 |
+
cwd: node.path,
|
| 210 |
+
pkg: node.package,
|
| 211 |
+
})
|
| 212 |
+
|
| 213 |
+
if (node && workspaces.size) {
|
| 214 |
+
node.workspaces = workspaces
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
return node
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
async audit (options = {}) {
|
| 221 |
+
this.addTracker('audit')
|
| 222 |
+
if (this.options.global) {
|
| 223 |
+
throw Object.assign(
|
| 224 |
+
new Error('`npm audit` does not support testing globals'),
|
| 225 |
+
{ code: 'EAUDITGLOBAL' }
|
| 226 |
+
)
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
// allow the user to set options on the ctor as well.
|
| 230 |
+
// XXX: deprecate separate method options objects.
|
| 231 |
+
options = { ...this.options, ...options }
|
| 232 |
+
|
| 233 |
+
const timeEnd = time.start('audit')
|
| 234 |
+
let tree
|
| 235 |
+
if (options.packageLock === false) {
|
| 236 |
+
// build ideal tree
|
| 237 |
+
await this.loadActual(options)
|
| 238 |
+
await this.buildIdealTree()
|
| 239 |
+
tree = this.idealTree
|
| 240 |
+
} else {
|
| 241 |
+
tree = await this.loadVirtual()
|
| 242 |
+
}
|
| 243 |
+
if (this.options.workspaces.length) {
|
| 244 |
+
options.filterSet = this.workspaceDependencySet(
|
| 245 |
+
tree,
|
| 246 |
+
this.options.workspaces,
|
| 247 |
+
this.options.includeWorkspaceRoot
|
| 248 |
+
)
|
| 249 |
+
}
|
| 250 |
+
if (!options.workspacesEnabled) {
|
| 251 |
+
options.filterSet =
|
| 252 |
+
this.excludeWorkspacesDependencySet(tree)
|
| 253 |
+
}
|
| 254 |
+
this.auditReport = await AuditReport.load(tree, options)
|
| 255 |
+
const ret = options.fix ? this.reify(options) : this.auditReport
|
| 256 |
+
timeEnd()
|
| 257 |
+
this.finishTracker('audit')
|
| 258 |
+
return ret
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
async dedupe (options = {}) {
|
| 262 |
+
// allow the user to set options on the ctor as well.
|
| 263 |
+
// XXX: deprecate separate method options objects.
|
| 264 |
+
options = { ...this.options, ...options }
|
| 265 |
+
const tree = await this.loadVirtual().catch(() => this.loadActual())
|
| 266 |
+
const names = []
|
| 267 |
+
for (const name of tree.inventory.query('name')) {
|
| 268 |
+
if (tree.inventory.query('name', name).size > 1) {
|
| 269 |
+
names.push(name)
|
| 270 |
+
}
|
| 271 |
+
}
|
| 272 |
+
return this.reify({
|
| 273 |
+
...options,
|
| 274 |
+
preferDedupe: true,
|
| 275 |
+
update: { names },
|
| 276 |
+
})
|
| 277 |
+
}
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
module.exports = Arborist
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/isolated-reifier.js
ADDED
|
@@ -0,0 +1,453 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const _makeIdealGraph = Symbol('makeIdealGraph')
|
| 2 |
+
const _createIsolatedTree = Symbol.for('createIsolatedTree')
|
| 3 |
+
const _createBundledTree = Symbol('createBundledTree')
|
| 4 |
+
const { mkdirSync } = require('node:fs')
|
| 5 |
+
const pacote = require('pacote')
|
| 6 |
+
const { join } = require('node:path')
|
| 7 |
+
const { depth } = require('treeverse')
|
| 8 |
+
const crypto = require('node:crypto')
|
| 9 |
+
|
| 10 |
+
// cache complicated function results
|
| 11 |
+
const memoize = (fn) => {
|
| 12 |
+
const memo = new Map()
|
| 13 |
+
return async function (arg) {
|
| 14 |
+
const key = arg
|
| 15 |
+
if (memo.has(key)) {
|
| 16 |
+
return memo.get(key)
|
| 17 |
+
}
|
| 18 |
+
const result = {}
|
| 19 |
+
memo.set(key, result)
|
| 20 |
+
await fn(result, arg)
|
| 21 |
+
return result
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
module.exports = cls => class IsolatedReifier extends cls {
|
| 26 |
+
/**
|
| 27 |
+
* Create an ideal graph.
|
| 28 |
+
*
|
| 29 |
+
* An implementation of npm RFC-0042
|
| 30 |
+
* https://github.com/npm/rfcs/blob/main/accepted/0042-isolated-mode.md
|
| 31 |
+
*
|
| 32 |
+
* This entire file should be considered technical debt that will be resolved
|
| 33 |
+
* with an Arborist refactor or rewrite. Embedded logic in Nodes and Links,
|
| 34 |
+
* and the incremental state of building trees and reifying contains too many
|
| 35 |
+
* assumptions to do a linked mode properly.
|
| 36 |
+
*
|
| 37 |
+
* Instead, this approach takes a tree built from build-ideal-tree, and
|
| 38 |
+
* returns a new tree-like structure without the embedded logic of Node and
|
| 39 |
+
* Link classes.
|
| 40 |
+
*
|
| 41 |
+
* Since the RFC requires leaving the package-lock in place, this approach
|
| 42 |
+
* temporarily replaces the tree state for a couple of steps of reifying.
|
| 43 |
+
*
|
| 44 |
+
**/
|
| 45 |
+
async [_makeIdealGraph] (options) {
|
| 46 |
+
/* Make sure that the ideal tree is build as the rest of
|
| 47 |
+
* the algorithm depends on it.
|
| 48 |
+
*/
|
| 49 |
+
const bitOpt = {
|
| 50 |
+
...options,
|
| 51 |
+
complete: false,
|
| 52 |
+
}
|
| 53 |
+
await this.buildIdealTree(bitOpt)
|
| 54 |
+
const idealTree = this.idealTree
|
| 55 |
+
|
| 56 |
+
this.rootNode = {}
|
| 57 |
+
const root = this.rootNode
|
| 58 |
+
this.counter = 0
|
| 59 |
+
|
| 60 |
+
// memoize to cache generating proxy Nodes
|
| 61 |
+
this.externalProxyMemo = memoize(this.externalProxy.bind(this))
|
| 62 |
+
this.workspaceProxyMemo = memoize(this.workspaceProxy.bind(this))
|
| 63 |
+
|
| 64 |
+
root.external = []
|
| 65 |
+
root.isProjectRoot = true
|
| 66 |
+
root.localLocation = idealTree.location
|
| 67 |
+
root.localPath = idealTree.path
|
| 68 |
+
root.workspaces = await Promise.all(
|
| 69 |
+
Array.from(idealTree.fsChildren.values(), this.workspaceProxyMemo))
|
| 70 |
+
const processed = new Set()
|
| 71 |
+
const queue = [idealTree, ...idealTree.fsChildren]
|
| 72 |
+
while (queue.length !== 0) {
|
| 73 |
+
const next = queue.pop()
|
| 74 |
+
if (processed.has(next.location)) {
|
| 75 |
+
continue
|
| 76 |
+
}
|
| 77 |
+
processed.add(next.location)
|
| 78 |
+
next.edgesOut.forEach(e => {
|
| 79 |
+
if (!e.to || (next.package.bundleDependencies || next.package.bundledDependencies || []).includes(e.to.name)) {
|
| 80 |
+
return
|
| 81 |
+
}
|
| 82 |
+
queue.push(e.to)
|
| 83 |
+
})
|
| 84 |
+
if (!next.isProjectRoot && !next.isWorkspace) {
|
| 85 |
+
root.external.push(await this.externalProxyMemo(next))
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
await this.assignCommonProperties(idealTree, root)
|
| 90 |
+
|
| 91 |
+
this.idealGraph = root
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
async workspaceProxy (result, node) {
|
| 95 |
+
result.localLocation = node.location
|
| 96 |
+
result.localPath = node.path
|
| 97 |
+
result.isWorkspace = true
|
| 98 |
+
result.resolved = node.resolved
|
| 99 |
+
await this.assignCommonProperties(node, result)
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
async externalProxy (result, node) {
|
| 103 |
+
await this.assignCommonProperties(node, result)
|
| 104 |
+
if (node.hasShrinkwrap) {
|
| 105 |
+
const dir = join(
|
| 106 |
+
node.root.path,
|
| 107 |
+
'node_modules',
|
| 108 |
+
'.store',
|
| 109 |
+
`${node.name}@${node.version}`
|
| 110 |
+
)
|
| 111 |
+
mkdirSync(dir, { recursive: true })
|
| 112 |
+
// TODO this approach feels wrong
|
| 113 |
+
// and shouldn't be necessary for shrinkwraps
|
| 114 |
+
await pacote.extract(node.resolved, dir, {
|
| 115 |
+
...this.options,
|
| 116 |
+
resolved: node.resolved,
|
| 117 |
+
integrity: node.integrity,
|
| 118 |
+
})
|
| 119 |
+
const Arborist = this.constructor
|
| 120 |
+
const arb = new Arborist({ ...this.options, path: dir })
|
| 121 |
+
await arb[_makeIdealGraph]({ dev: false })
|
| 122 |
+
this.rootNode.external.push(...arb.idealGraph.external)
|
| 123 |
+
arb.idealGraph.external.forEach(e => {
|
| 124 |
+
e.root = this.rootNode
|
| 125 |
+
e.id = `${node.id}=>${e.id}`
|
| 126 |
+
})
|
| 127 |
+
result.localDependencies = []
|
| 128 |
+
result.externalDependencies = arb.idealGraph.externalDependencies
|
| 129 |
+
result.externalOptionalDependencies = arb.idealGraph.externalOptionalDependencies
|
| 130 |
+
result.dependencies = [
|
| 131 |
+
...result.externalDependencies,
|
| 132 |
+
...result.localDependencies,
|
| 133 |
+
...result.externalOptionalDependencies,
|
| 134 |
+
]
|
| 135 |
+
}
|
| 136 |
+
result.optional = node.optional
|
| 137 |
+
result.resolved = node.resolved
|
| 138 |
+
result.version = node.version
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
async assignCommonProperties (node, result) {
|
| 142 |
+
function validEdgesOut (node) {
|
| 143 |
+
return [...node.edgesOut.values()].filter(e => e.to && e.to.target && !(node.package.bundledDepenedencies || node.package.bundleDependencies || []).includes(e.to.name))
|
| 144 |
+
}
|
| 145 |
+
const edges = validEdgesOut(node)
|
| 146 |
+
const optionalDeps = edges.filter(e => e.optional).map(e => e.to.target)
|
| 147 |
+
const nonOptionalDeps = edges.filter(e => !e.optional).map(e => e.to.target)
|
| 148 |
+
|
| 149 |
+
result.localDependencies = await Promise.all(nonOptionalDeps.filter(n => n.isWorkspace).map(this.workspaceProxyMemo))
|
| 150 |
+
result.externalDependencies = await Promise.all(nonOptionalDeps.filter(n => !n.isWorkspace).map(this.externalProxyMemo))
|
| 151 |
+
result.externalOptionalDependencies = await Promise.all(optionalDeps.map(this.externalProxyMemo))
|
| 152 |
+
result.dependencies = [
|
| 153 |
+
...result.externalDependencies,
|
| 154 |
+
...result.localDependencies,
|
| 155 |
+
...result.externalOptionalDependencies,
|
| 156 |
+
]
|
| 157 |
+
result.root = this.rootNode
|
| 158 |
+
result.id = this.counter++
|
| 159 |
+
result.name = node.name
|
| 160 |
+
result.package = { ...node.package }
|
| 161 |
+
result.package.bundleDependencies = undefined
|
| 162 |
+
result.hasInstallScript = node.hasInstallScript
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
async [_createBundledTree] () {
|
| 166 |
+
// TODO: make sure that idealTree object exists
|
| 167 |
+
const idealTree = this.idealTree
|
| 168 |
+
// TODO: test workspaces having bundled deps
|
| 169 |
+
const queue = []
|
| 170 |
+
|
| 171 |
+
for (const [, edge] of idealTree.edgesOut) {
|
| 172 |
+
if (edge.to && (idealTree.package.bundleDependencies || idealTree.package.bundledDependencies || []).includes(edge.to.name)) {
|
| 173 |
+
queue.push({ from: idealTree, to: edge.to })
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
for (const child of idealTree.fsChildren) {
|
| 177 |
+
for (const [, edge] of child.edgesOut) {
|
| 178 |
+
if (edge.to && (child.package.bundleDependencies || child.package.bundledDependencies || []).includes(edge.to.name)) {
|
| 179 |
+
queue.push({ from: child, to: edge.to })
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
const processed = new Set()
|
| 185 |
+
const nodes = new Map()
|
| 186 |
+
const edges = []
|
| 187 |
+
while (queue.length !== 0) {
|
| 188 |
+
const nextEdge = queue.pop()
|
| 189 |
+
const key = `${nextEdge.from.location}=>${nextEdge.to.location}`
|
| 190 |
+
// should be impossible, unless bundled is duped
|
| 191 |
+
/* istanbul ignore next */
|
| 192 |
+
if (processed.has(key)) {
|
| 193 |
+
continue
|
| 194 |
+
}
|
| 195 |
+
processed.add(key)
|
| 196 |
+
const from = nextEdge.from
|
| 197 |
+
if (!from.isRoot && !from.isWorkspace) {
|
| 198 |
+
nodes.set(from.location, { location: from.location, resolved: from.resolved, name: from.name, optional: from.optional, pkg: { ...from.package, bundleDependencies: undefined } })
|
| 199 |
+
}
|
| 200 |
+
const to = nextEdge.to
|
| 201 |
+
nodes.set(to.location, { location: to.location, resolved: to.resolved, name: to.name, optional: to.optional, pkg: { ...to.package, bundleDependencies: undefined } })
|
| 202 |
+
edges.push({ from: from.isRoot ? 'root' : from.location, to: to.location })
|
| 203 |
+
|
| 204 |
+
to.edgesOut.forEach(e => {
|
| 205 |
+
// an edge out should always have a to
|
| 206 |
+
/* istanbul ignore else */
|
| 207 |
+
if (e.to) {
|
| 208 |
+
queue.push({ from: e.from, to: e.to })
|
| 209 |
+
}
|
| 210 |
+
})
|
| 211 |
+
}
|
| 212 |
+
return { edges, nodes }
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
async [_createIsolatedTree] () {
|
| 216 |
+
await this[_makeIdealGraph](this.options)
|
| 217 |
+
|
| 218 |
+
const proxiedIdealTree = this.idealGraph
|
| 219 |
+
|
| 220 |
+
const bundledTree = await this[_createBundledTree]()
|
| 221 |
+
|
| 222 |
+
const treeHash = (startNode) => {
|
| 223 |
+
// generate short hash based on the dependency tree
|
| 224 |
+
// starting at this node
|
| 225 |
+
const deps = []
|
| 226 |
+
const branch = []
|
| 227 |
+
depth({
|
| 228 |
+
tree: startNode,
|
| 229 |
+
getChildren: node => node.dependencies,
|
| 230 |
+
filter: node => node,
|
| 231 |
+
visit: node => {
|
| 232 |
+
branch.push(`${node.name}@${node.version}`)
|
| 233 |
+
deps.push(`${branch.join('->')}::${node.resolved}`)
|
| 234 |
+
},
|
| 235 |
+
leave: () => {
|
| 236 |
+
branch.pop()
|
| 237 |
+
},
|
| 238 |
+
})
|
| 239 |
+
deps.sort()
|
| 240 |
+
return crypto.createHash('shake256', { outputLength: 16 })
|
| 241 |
+
.update(deps.join(','))
|
| 242 |
+
.digest('base64')
|
| 243 |
+
// Node v14 doesn't support base64url
|
| 244 |
+
.replace(/\+/g, '-')
|
| 245 |
+
.replace(/\//g, '_')
|
| 246 |
+
.replace(/=+$/m, '')
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
const getKey = (idealTreeNode) => {
|
| 250 |
+
return `${idealTreeNode.name}@${idealTreeNode.version}-${treeHash(idealTreeNode)}`
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
const root = {
|
| 254 |
+
fsChildren: [],
|
| 255 |
+
integrity: null,
|
| 256 |
+
inventory: new Map(),
|
| 257 |
+
isLink: false,
|
| 258 |
+
isRoot: true,
|
| 259 |
+
binPaths: [],
|
| 260 |
+
edgesIn: new Set(),
|
| 261 |
+
edgesOut: new Map(),
|
| 262 |
+
hasShrinkwrap: false,
|
| 263 |
+
parent: null,
|
| 264 |
+
// TODO: we should probably not reference this.idealTree
|
| 265 |
+
resolved: this.idealTree.resolved,
|
| 266 |
+
isTop: true,
|
| 267 |
+
path: proxiedIdealTree.root.localPath,
|
| 268 |
+
realpath: proxiedIdealTree.root.localPath,
|
| 269 |
+
package: proxiedIdealTree.root.package,
|
| 270 |
+
meta: { loadedFromDisk: false },
|
| 271 |
+
global: false,
|
| 272 |
+
isProjectRoot: true,
|
| 273 |
+
children: [],
|
| 274 |
+
}
|
| 275 |
+
// root.inventory.set('', t)
|
| 276 |
+
// root.meta = this.idealTree.meta
|
| 277 |
+
// TODO We should mock better the inventory object because it is used by audit-report.js ... maybe
|
| 278 |
+
root.inventory.query = () => {
|
| 279 |
+
return []
|
| 280 |
+
}
|
| 281 |
+
const processed = new Set()
|
| 282 |
+
proxiedIdealTree.workspaces.forEach(c => {
|
| 283 |
+
const workspace = {
|
| 284 |
+
edgesIn: new Set(),
|
| 285 |
+
edgesOut: new Map(),
|
| 286 |
+
children: [],
|
| 287 |
+
hasInstallScript: c.hasInstallScript,
|
| 288 |
+
binPaths: [],
|
| 289 |
+
package: c.package,
|
| 290 |
+
location: c.localLocation,
|
| 291 |
+
path: c.localPath,
|
| 292 |
+
realpath: c.localPath,
|
| 293 |
+
resolved: c.resolved,
|
| 294 |
+
}
|
| 295 |
+
root.fsChildren.push(workspace)
|
| 296 |
+
root.inventory.set(workspace.location, workspace)
|
| 297 |
+
})
|
| 298 |
+
const generateChild = (node, location, pkg, inStore) => {
|
| 299 |
+
const newChild = {
|
| 300 |
+
global: false,
|
| 301 |
+
globalTop: false,
|
| 302 |
+
isProjectRoot: false,
|
| 303 |
+
isTop: false,
|
| 304 |
+
location,
|
| 305 |
+
name: node.name,
|
| 306 |
+
optional: node.optional,
|
| 307 |
+
top: { path: proxiedIdealTree.root.localPath },
|
| 308 |
+
children: [],
|
| 309 |
+
edgesIn: new Set(),
|
| 310 |
+
edgesOut: new Map(),
|
| 311 |
+
binPaths: [],
|
| 312 |
+
fsChildren: [],
|
| 313 |
+
/* istanbul ignore next -- emulate Node */
|
| 314 |
+
getBundler () {
|
| 315 |
+
return null
|
| 316 |
+
},
|
| 317 |
+
hasShrinkwrap: false,
|
| 318 |
+
inDepBundle: false,
|
| 319 |
+
integrity: null,
|
| 320 |
+
isLink: false,
|
| 321 |
+
isRoot: false,
|
| 322 |
+
isInStore: inStore,
|
| 323 |
+
path: join(proxiedIdealTree.root.localPath, location),
|
| 324 |
+
realpath: join(proxiedIdealTree.root.localPath, location),
|
| 325 |
+
resolved: node.resolved,
|
| 326 |
+
version: pkg.version,
|
| 327 |
+
package: pkg,
|
| 328 |
+
}
|
| 329 |
+
newChild.target = newChild
|
| 330 |
+
root.children.push(newChild)
|
| 331 |
+
root.inventory.set(newChild.location, newChild)
|
| 332 |
+
}
|
| 333 |
+
proxiedIdealTree.external.forEach(c => {
|
| 334 |
+
const key = getKey(c)
|
| 335 |
+
if (processed.has(key)) {
|
| 336 |
+
return
|
| 337 |
+
}
|
| 338 |
+
processed.add(key)
|
| 339 |
+
const location = join('node_modules', '.store', key, 'node_modules', c.name)
|
| 340 |
+
generateChild(c, location, c.package, true)
|
| 341 |
+
})
|
| 342 |
+
bundledTree.nodes.forEach(node => {
|
| 343 |
+
generateChild(node, node.location, node.pkg, false)
|
| 344 |
+
})
|
| 345 |
+
bundledTree.edges.forEach(e => {
|
| 346 |
+
const from = e.from === 'root' ? root : root.inventory.get(e.from)
|
| 347 |
+
const to = root.inventory.get(e.to)
|
| 348 |
+
// Maybe optional should be propagated from the original edge
|
| 349 |
+
const edge = { optional: false, from, to }
|
| 350 |
+
from.edgesOut.set(to.name, edge)
|
| 351 |
+
to.edgesIn.add(edge)
|
| 352 |
+
})
|
| 353 |
+
const memo = new Set()
|
| 354 |
+
|
| 355 |
+
function processEdges (node, externalEdge) {
|
| 356 |
+
externalEdge = !!externalEdge
|
| 357 |
+
const key = getKey(node)
|
| 358 |
+
if (memo.has(key)) {
|
| 359 |
+
return
|
| 360 |
+
}
|
| 361 |
+
memo.add(key)
|
| 362 |
+
|
| 363 |
+
let from, nmFolder
|
| 364 |
+
if (externalEdge) {
|
| 365 |
+
const fromLocation = join('node_modules', '.store', key, 'node_modules', node.name)
|
| 366 |
+
from = root.children.find(c => c.location === fromLocation)
|
| 367 |
+
nmFolder = join('node_modules', '.store', key, 'node_modules')
|
| 368 |
+
} else {
|
| 369 |
+
from = node.isProjectRoot ? root : root.fsChildren.find(c => c.location === node.localLocation)
|
| 370 |
+
nmFolder = join(node.localLocation, 'node_modules')
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
const processDeps = (dep, optional, external) => {
|
| 374 |
+
optional = !!optional
|
| 375 |
+
external = !!external
|
| 376 |
+
|
| 377 |
+
const location = join(nmFolder, dep.name)
|
| 378 |
+
const binNames = dep.package.bin && Object.keys(dep.package.bin) || []
|
| 379 |
+
const toKey = getKey(dep)
|
| 380 |
+
|
| 381 |
+
let target
|
| 382 |
+
if (external) {
|
| 383 |
+
const toLocation = join('node_modules', '.store', toKey, 'node_modules', dep.name)
|
| 384 |
+
target = root.children.find(c => c.location === toLocation)
|
| 385 |
+
} else {
|
| 386 |
+
target = root.fsChildren.find(c => c.location === dep.localLocation)
|
| 387 |
+
}
|
| 388 |
+
// TODO: we should no-op is an edge has already been created with the same fromKey and toKey
|
| 389 |
+
|
| 390 |
+
binNames.forEach(bn => {
|
| 391 |
+
target.binPaths.push(join(from.realpath, 'node_modules', '.bin', bn))
|
| 392 |
+
})
|
| 393 |
+
|
| 394 |
+
const link = {
|
| 395 |
+
global: false,
|
| 396 |
+
globalTop: false,
|
| 397 |
+
isProjectRoot: false,
|
| 398 |
+
edgesIn: new Set(),
|
| 399 |
+
edgesOut: new Map(),
|
| 400 |
+
binPaths: [],
|
| 401 |
+
isTop: false,
|
| 402 |
+
optional,
|
| 403 |
+
location: location,
|
| 404 |
+
path: join(dep.root.localPath, nmFolder, dep.name),
|
| 405 |
+
realpath: target.path,
|
| 406 |
+
name: toKey,
|
| 407 |
+
resolved: dep.resolved,
|
| 408 |
+
top: { path: dep.root.localPath },
|
| 409 |
+
children: [],
|
| 410 |
+
fsChildren: [],
|
| 411 |
+
isLink: true,
|
| 412 |
+
isStoreLink: true,
|
| 413 |
+
isRoot: false,
|
| 414 |
+
package: { _id: 'abc', bundleDependencies: undefined, deprecated: undefined, bin: target.package.bin, scripts: dep.package.scripts },
|
| 415 |
+
target,
|
| 416 |
+
}
|
| 417 |
+
const newEdge1 = { optional, from, to: link }
|
| 418 |
+
from.edgesOut.set(dep.name, newEdge1)
|
| 419 |
+
link.edgesIn.add(newEdge1)
|
| 420 |
+
const newEdge2 = { optional: false, from: link, to: target }
|
| 421 |
+
link.edgesOut.set(dep.name, newEdge2)
|
| 422 |
+
target.edgesIn.add(newEdge2)
|
| 423 |
+
root.children.push(link)
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
for (const dep of node.localDependencies) {
|
| 427 |
+
processEdges(dep, false)
|
| 428 |
+
// nonOptional, local
|
| 429 |
+
processDeps(dep, false, false)
|
| 430 |
+
}
|
| 431 |
+
for (const dep of node.externalDependencies) {
|
| 432 |
+
processEdges(dep, true)
|
| 433 |
+
// nonOptional, external
|
| 434 |
+
processDeps(dep, false, true)
|
| 435 |
+
}
|
| 436 |
+
for (const dep of node.externalOptionalDependencies) {
|
| 437 |
+
processEdges(dep, true)
|
| 438 |
+
// optional, external
|
| 439 |
+
processDeps(dep, true, true)
|
| 440 |
+
}
|
| 441 |
+
}
|
| 442 |
+
|
| 443 |
+
processEdges(proxiedIdealTree, false)
|
| 444 |
+
for (const node of proxiedIdealTree.workspaces) {
|
| 445 |
+
processEdges(node, false)
|
| 446 |
+
}
|
| 447 |
+
root.children.forEach(c => c.parent = root)
|
| 448 |
+
root.children.forEach(c => c.root = root)
|
| 449 |
+
root.root = root
|
| 450 |
+
root.target = root
|
| 451 |
+
return root
|
| 452 |
+
}
|
| 453 |
+
}
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/load-actual.js
ADDED
|
@@ -0,0 +1,438 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// mix-in implementing the loadActual method
|
| 2 |
+
|
| 3 |
+
const { relative, dirname, resolve, join, normalize } = require('node:path')
|
| 4 |
+
|
| 5 |
+
const rpj = require('read-package-json-fast')
|
| 6 |
+
const { readdirScoped } = require('@npmcli/fs')
|
| 7 |
+
const { walkUp } = require('walk-up-path')
|
| 8 |
+
const ancestorPath = require('common-ancestor-path')
|
| 9 |
+
const treeCheck = require('../tree-check.js')
|
| 10 |
+
|
| 11 |
+
const Shrinkwrap = require('../shrinkwrap.js')
|
| 12 |
+
const calcDepFlags = require('../calc-dep-flags.js')
|
| 13 |
+
const Node = require('../node.js')
|
| 14 |
+
const Link = require('../link.js')
|
| 15 |
+
const realpath = require('../realpath.js')
|
| 16 |
+
|
| 17 |
+
// public symbols
|
| 18 |
+
const _changePath = Symbol.for('_changePath')
|
| 19 |
+
const _setWorkspaces = Symbol.for('setWorkspaces')
|
| 20 |
+
const _rpcache = Symbol.for('realpathCache')
|
| 21 |
+
const _stcache = Symbol.for('statCache')
|
| 22 |
+
|
| 23 |
+
module.exports = cls => class ActualLoader extends cls {
|
| 24 |
+
#actualTree
|
| 25 |
+
// ensure when walking the tree that we don't call loadTree on the same
|
| 26 |
+
// actual node more than one time.
|
| 27 |
+
#actualTreeLoaded = new Set()
|
| 28 |
+
#actualTreePromise
|
| 29 |
+
|
| 30 |
+
// cache of nodes when loading the actualTree, so that we avoid loaded the
|
| 31 |
+
// same node multiple times when symlinks attack.
|
| 32 |
+
#cache = new Map()
|
| 33 |
+
#filter
|
| 34 |
+
|
| 35 |
+
// cache of link targets for setting fsParent links
|
| 36 |
+
// We don't do fsParent as a magic getter/setter, because it'd be too costly
|
| 37 |
+
// to keep up to date along the walk.
|
| 38 |
+
// And, we know that it can ONLY be relevant when the node is a target of a
|
| 39 |
+
// link, otherwise it'd be in a node_modules folder, so take advantage of
|
| 40 |
+
// that to limit the scans later.
|
| 41 |
+
#topNodes = new Set()
|
| 42 |
+
#transplantFilter
|
| 43 |
+
|
| 44 |
+
constructor (options) {
|
| 45 |
+
super(options)
|
| 46 |
+
|
| 47 |
+
// the tree of nodes on disk
|
| 48 |
+
this.actualTree = options.actualTree
|
| 49 |
+
|
| 50 |
+
// caches for cached realpath calls
|
| 51 |
+
const cwd = process.cwd()
|
| 52 |
+
// assume that the cwd is real enough for our purposes
|
| 53 |
+
this[_rpcache] = new Map([[cwd, cwd]])
|
| 54 |
+
this[_stcache] = new Map()
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
// public method
|
| 58 |
+
// TODO remove options param in next semver major
|
| 59 |
+
async loadActual (options = {}) {
|
| 60 |
+
// In the past this.actualTree was set as a promise that eventually
|
| 61 |
+
// resolved, and overwrite this.actualTree with the resolved value. This
|
| 62 |
+
// was a problem because virtually no other code expects this.actualTree to
|
| 63 |
+
// be a promise. Instead we only set it once resolved, and also return it
|
| 64 |
+
// from the promise so that it is what's returned from this function when
|
| 65 |
+
// awaited.
|
| 66 |
+
if (this.actualTree) {
|
| 67 |
+
return this.actualTree
|
| 68 |
+
}
|
| 69 |
+
if (!this.#actualTreePromise) {
|
| 70 |
+
// allow the user to set options on the ctor as well.
|
| 71 |
+
// XXX: deprecate separate method options objects.
|
| 72 |
+
options = { ...this.options, ...options }
|
| 73 |
+
|
| 74 |
+
this.#actualTreePromise = this.#loadActual(options)
|
| 75 |
+
.then(tree => {
|
| 76 |
+
// reset all deps to extraneous prior to recalc
|
| 77 |
+
if (!options.root) {
|
| 78 |
+
for (const node of tree.inventory.values()) {
|
| 79 |
+
node.extraneous = true
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
// only reset root flags if we're not re-rooting,
|
| 84 |
+
// otherwise leave as-is
|
| 85 |
+
calcDepFlags(tree, !options.root)
|
| 86 |
+
this.actualTree = treeCheck(tree)
|
| 87 |
+
return this.actualTree
|
| 88 |
+
})
|
| 89 |
+
}
|
| 90 |
+
return this.#actualTreePromise
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
// return the promise so that we don't ever have more than one going at the
|
| 94 |
+
// same time. This is so that buildIdealTree can default to the actualTree
|
| 95 |
+
// if no shrinkwrap present, but reify() can still call buildIdealTree and
|
| 96 |
+
// loadActual in parallel safely.
|
| 97 |
+
|
| 98 |
+
async #loadActual (options) {
|
| 99 |
+
// mostly realpath to throw if the root doesn't exist
|
| 100 |
+
const {
|
| 101 |
+
global,
|
| 102 |
+
filter = () => true,
|
| 103 |
+
root = null,
|
| 104 |
+
transplantFilter = () => true,
|
| 105 |
+
ignoreMissing = false,
|
| 106 |
+
forceActual = false,
|
| 107 |
+
} = options
|
| 108 |
+
this.#filter = filter
|
| 109 |
+
this.#transplantFilter = transplantFilter
|
| 110 |
+
|
| 111 |
+
if (global) {
|
| 112 |
+
const real = await realpath(this.path, this[_rpcache], this[_stcache])
|
| 113 |
+
const params = {
|
| 114 |
+
path: this.path,
|
| 115 |
+
realpath: real,
|
| 116 |
+
pkg: {},
|
| 117 |
+
global,
|
| 118 |
+
loadOverrides: true,
|
| 119 |
+
}
|
| 120 |
+
if (this.path === real) {
|
| 121 |
+
this.#actualTree = this.#newNode(params)
|
| 122 |
+
} else {
|
| 123 |
+
this.#actualTree = await this.#newLink(params)
|
| 124 |
+
}
|
| 125 |
+
} else {
|
| 126 |
+
// not in global mode, hidden lockfile is allowed, load root pkg too
|
| 127 |
+
this.#actualTree = await this.#loadFSNode({
|
| 128 |
+
path: this.path,
|
| 129 |
+
real: await realpath(this.path, this[_rpcache], this[_stcache]),
|
| 130 |
+
loadOverrides: true,
|
| 131 |
+
})
|
| 132 |
+
|
| 133 |
+
this.#actualTree.assertRootOverrides()
|
| 134 |
+
|
| 135 |
+
// if forceActual is set, don't even try the hidden lockfile
|
| 136 |
+
if (!forceActual) {
|
| 137 |
+
// Note: hidden lockfile will be rejected if it's not the latest thing
|
| 138 |
+
// in the folder, or if any of the entries in the hidden lockfile are
|
| 139 |
+
// missing.
|
| 140 |
+
const meta = await Shrinkwrap.load({
|
| 141 |
+
path: this.#actualTree.path,
|
| 142 |
+
hiddenLockfile: true,
|
| 143 |
+
resolveOptions: this.options,
|
| 144 |
+
})
|
| 145 |
+
|
| 146 |
+
if (meta.loadedFromDisk) {
|
| 147 |
+
this.#actualTree.meta = meta
|
| 148 |
+
// have to load on a new Arborist object, so we don't assign
|
| 149 |
+
// the virtualTree on this one! Also, the weird reference is because
|
| 150 |
+
// we can't easily get a ref to Arborist in this module, without
|
| 151 |
+
// creating a circular reference, since this class is a mixin used
|
| 152 |
+
// to build up the Arborist class itself.
|
| 153 |
+
await new this.constructor({ ...this.options }).loadVirtual({
|
| 154 |
+
root: this.#actualTree,
|
| 155 |
+
})
|
| 156 |
+
await this[_setWorkspaces](this.#actualTree)
|
| 157 |
+
|
| 158 |
+
this.#transplant(root)
|
| 159 |
+
return this.#actualTree
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
const meta = await Shrinkwrap.load({
|
| 164 |
+
path: this.#actualTree.path,
|
| 165 |
+
lockfileVersion: this.options.lockfileVersion,
|
| 166 |
+
resolveOptions: this.options,
|
| 167 |
+
})
|
| 168 |
+
this.#actualTree.meta = meta
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
await this.#loadFSTree(this.#actualTree)
|
| 172 |
+
await this[_setWorkspaces](this.#actualTree)
|
| 173 |
+
|
| 174 |
+
// if there are workspace targets without Link nodes created, load
|
| 175 |
+
// the targets, so that we know what they are.
|
| 176 |
+
if (this.#actualTree.workspaces && this.#actualTree.workspaces.size) {
|
| 177 |
+
const promises = []
|
| 178 |
+
for (const path of this.#actualTree.workspaces.values()) {
|
| 179 |
+
if (!this.#cache.has(path)) {
|
| 180 |
+
// workspace overrides use the root overrides
|
| 181 |
+
const p = this.#loadFSNode({ path, root: this.#actualTree, useRootOverrides: true })
|
| 182 |
+
.then(node => this.#loadFSTree(node))
|
| 183 |
+
promises.push(p)
|
| 184 |
+
}
|
| 185 |
+
}
|
| 186 |
+
await Promise.all(promises)
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
if (!ignoreMissing) {
|
| 190 |
+
await this.#findMissingEdges()
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
// try to find a node that is the parent in a fs tree sense, but not a
|
| 194 |
+
// node_modules tree sense, of any link targets. this allows us to
|
| 195 |
+
// resolve deps that node will find, but a legacy npm view of the
|
| 196 |
+
// world would not have noticed.
|
| 197 |
+
for (const path of this.#topNodes) {
|
| 198 |
+
const node = this.#cache.get(path)
|
| 199 |
+
if (node && !node.parent && !node.fsParent) {
|
| 200 |
+
for (const p of walkUp(dirname(path))) {
|
| 201 |
+
if (this.#cache.has(p)) {
|
| 202 |
+
node.fsParent = this.#cache.get(p)
|
| 203 |
+
break
|
| 204 |
+
}
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
this.#transplant(root)
|
| 210 |
+
|
| 211 |
+
if (global) {
|
| 212 |
+
// need to depend on the children, or else all of them
|
| 213 |
+
// will end up being flagged as extraneous, since the
|
| 214 |
+
// global root isn't a "real" project
|
| 215 |
+
const tree = this.#actualTree
|
| 216 |
+
const actualRoot = tree.isLink ? tree.target : tree
|
| 217 |
+
const { dependencies = {} } = actualRoot.package
|
| 218 |
+
for (const [name, kid] of actualRoot.children.entries()) {
|
| 219 |
+
const def = kid.isLink ? `file:${kid.realpath}` : '*'
|
| 220 |
+
dependencies[name] = dependencies[name] || def
|
| 221 |
+
}
|
| 222 |
+
actualRoot.package = { ...actualRoot.package, dependencies }
|
| 223 |
+
}
|
| 224 |
+
return this.#actualTree
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
#transplant (root) {
|
| 228 |
+
if (!root || root === this.#actualTree) {
|
| 229 |
+
return
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
this.#actualTree[_changePath](root.path)
|
| 233 |
+
for (const node of this.#actualTree.children.values()) {
|
| 234 |
+
if (!this.#transplantFilter(node)) {
|
| 235 |
+
node.root = null
|
| 236 |
+
}
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
root.replace(this.#actualTree)
|
| 240 |
+
for (const node of this.#actualTree.fsChildren) {
|
| 241 |
+
node.root = this.#transplantFilter(node) ? root : null
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
this.#actualTree = root
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
async #loadFSNode ({ path, parent, real, root, loadOverrides, useRootOverrides }) {
|
| 248 |
+
if (!real) {
|
| 249 |
+
try {
|
| 250 |
+
real = await realpath(path, this[_rpcache], this[_stcache])
|
| 251 |
+
} catch (error) {
|
| 252 |
+
// if realpath fails, just provide a dummy error node
|
| 253 |
+
return new Node({
|
| 254 |
+
error,
|
| 255 |
+
path,
|
| 256 |
+
realpath: path,
|
| 257 |
+
parent,
|
| 258 |
+
root,
|
| 259 |
+
loadOverrides,
|
| 260 |
+
})
|
| 261 |
+
}
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
const cached = this.#cache.get(path)
|
| 265 |
+
let node
|
| 266 |
+
// missing edges get a dummy node, assign the parent and return it
|
| 267 |
+
if (cached && !cached.dummy) {
|
| 268 |
+
cached.parent = parent
|
| 269 |
+
return cached
|
| 270 |
+
} else {
|
| 271 |
+
const params = {
|
| 272 |
+
installLinks: this.installLinks,
|
| 273 |
+
legacyPeerDeps: this.legacyPeerDeps,
|
| 274 |
+
path,
|
| 275 |
+
realpath: real,
|
| 276 |
+
parent,
|
| 277 |
+
root,
|
| 278 |
+
loadOverrides,
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
try {
|
| 282 |
+
const pkg = await rpj(join(real, 'package.json'))
|
| 283 |
+
params.pkg = pkg
|
| 284 |
+
if (useRootOverrides && root.overrides) {
|
| 285 |
+
params.overrides = root.overrides.getNodeRule({ name: pkg.name, version: pkg.version })
|
| 286 |
+
}
|
| 287 |
+
} catch (err) {
|
| 288 |
+
params.error = err
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
// soldier on if read-package-json raises an error, passing it to the
|
| 292 |
+
// Node which will attach it to its errors array (Link passes it along to
|
| 293 |
+
// its target node)
|
| 294 |
+
if (normalize(path) === real) {
|
| 295 |
+
node = this.#newNode(params)
|
| 296 |
+
} else {
|
| 297 |
+
node = await this.#newLink(params)
|
| 298 |
+
}
|
| 299 |
+
}
|
| 300 |
+
this.#cache.set(path, node)
|
| 301 |
+
return node
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
#newNode (options) {
|
| 305 |
+
// check it for an fsParent if it's a tree top. there's a decent chance
|
| 306 |
+
// it'll get parented later, making the fsParent scan a no-op, but better
|
| 307 |
+
// safe than sorry, since it's cheap.
|
| 308 |
+
const { parent, realpath } = options
|
| 309 |
+
if (!parent) {
|
| 310 |
+
this.#topNodes.add(realpath)
|
| 311 |
+
}
|
| 312 |
+
return new Node(options)
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
async #newLink (options) {
|
| 316 |
+
const { realpath } = options
|
| 317 |
+
this.#topNodes.add(realpath)
|
| 318 |
+
const target = this.#cache.get(realpath)
|
| 319 |
+
const link = new Link({ ...options, target })
|
| 320 |
+
|
| 321 |
+
if (!target) {
|
| 322 |
+
// Link set its target itself in this case
|
| 323 |
+
this.#cache.set(realpath, link.target)
|
| 324 |
+
// if a link target points at a node outside of the root tree's
|
| 325 |
+
// node_modules hierarchy, then load that node as well.
|
| 326 |
+
await this.#loadFSTree(link.target)
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
return link
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
async #loadFSTree (node) {
|
| 333 |
+
const did = this.#actualTreeLoaded
|
| 334 |
+
if (!node.isLink && !did.has(node.target.realpath)) {
|
| 335 |
+
did.add(node.target.realpath)
|
| 336 |
+
await this.#loadFSChildren(node.target)
|
| 337 |
+
return Promise.all(
|
| 338 |
+
[...node.target.children.entries()]
|
| 339 |
+
.filter(([, kid]) => !did.has(kid.realpath))
|
| 340 |
+
.map(([, kid]) => this.#loadFSTree(kid))
|
| 341 |
+
)
|
| 342 |
+
}
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
// create child nodes for all the entries in node_modules
|
| 346 |
+
// and attach them to the node as a parent
|
| 347 |
+
async #loadFSChildren (node) {
|
| 348 |
+
const nm = resolve(node.realpath, 'node_modules')
|
| 349 |
+
try {
|
| 350 |
+
const kids = await readdirScoped(nm).then(paths => paths.map(p => p.replace(/\\/g, '/')))
|
| 351 |
+
return Promise.all(
|
| 352 |
+
// ignore . dirs and retired scoped package folders
|
| 353 |
+
kids.filter(kid => !/^(@[^/]+\/)?\./.test(kid))
|
| 354 |
+
.filter(kid => this.#filter(node, kid))
|
| 355 |
+
.map(kid => this.#loadFSNode({
|
| 356 |
+
parent: node,
|
| 357 |
+
path: resolve(nm, kid),
|
| 358 |
+
})))
|
| 359 |
+
} catch {
|
| 360 |
+
// error in the readdir is not fatal, just means no kids
|
| 361 |
+
}
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
async #findMissingEdges () {
|
| 365 |
+
// try to resolve any missing edges by walking up the directory tree,
|
| 366 |
+
// checking for the package in each node_modules folder. stop at the
|
| 367 |
+
// root directory.
|
| 368 |
+
// The tricky move here is that we load a "dummy" node for the folder
|
| 369 |
+
// containing the node_modules folder, so that it can be assigned as
|
| 370 |
+
// the fsParent. It's a bad idea to *actually* load that full node,
|
| 371 |
+
// because people sometimes develop in ~/projects/node_modules/...
|
| 372 |
+
// so we'd end up loading a massive tree with lots of unrelated junk.
|
| 373 |
+
const nmContents = new Map()
|
| 374 |
+
const tree = this.#actualTree
|
| 375 |
+
for (const node of tree.inventory.values()) {
|
| 376 |
+
const ancestor = ancestorPath(node.realpath, this.path)
|
| 377 |
+
|
| 378 |
+
const depPromises = []
|
| 379 |
+
for (const [name, edge] of node.edgesOut.entries()) {
|
| 380 |
+
const notMissing = !edge.missing &&
|
| 381 |
+
!(edge.to && (edge.to.dummy || edge.to.parent !== node))
|
| 382 |
+
if (notMissing) {
|
| 383 |
+
continue
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
// start the walk from the dirname, because we would have found
|
| 387 |
+
// the dep in the loadFSTree step already if it was local.
|
| 388 |
+
for (const p of walkUp(dirname(node.realpath))) {
|
| 389 |
+
// only walk as far as the nearest ancestor
|
| 390 |
+
// this keeps us from going into completely unrelated
|
| 391 |
+
// places when a project is just missing something, but
|
| 392 |
+
// allows for finding the transitive deps of link targets.
|
| 393 |
+
// ie, if it has to go up and back out to get to the path
|
| 394 |
+
// from the nearest common ancestor, we've gone too far.
|
| 395 |
+
if (ancestor && /^\.\.(?:[\\/]|$)/.test(relative(ancestor, p))) {
|
| 396 |
+
break
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
let entries
|
| 400 |
+
if (!nmContents.has(p)) {
|
| 401 |
+
entries = await readdirScoped(p + '/node_modules')
|
| 402 |
+
.catch(() => []).then(paths => paths.map(p => p.replace(/\\/g, '/')))
|
| 403 |
+
nmContents.set(p, entries)
|
| 404 |
+
} else {
|
| 405 |
+
entries = nmContents.get(p)
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
if (!entries.includes(name)) {
|
| 409 |
+
continue
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
let d
|
| 413 |
+
if (!this.#cache.has(p)) {
|
| 414 |
+
d = new Node({ path: p, root: node.root, dummy: true })
|
| 415 |
+
this.#cache.set(p, d)
|
| 416 |
+
} else {
|
| 417 |
+
d = this.#cache.get(p)
|
| 418 |
+
}
|
| 419 |
+
if (d.dummy) {
|
| 420 |
+
// it's a placeholder, so likely would not have loaded this dep,
|
| 421 |
+
// unless another dep in the tree also needs it.
|
| 422 |
+
const depPath = normalize(`${p}/node_modules/${name}`)
|
| 423 |
+
const cached = this.#cache.get(depPath)
|
| 424 |
+
if (!cached || cached.dummy) {
|
| 425 |
+
depPromises.push(this.#loadFSNode({
|
| 426 |
+
path: depPath,
|
| 427 |
+
root: node.root,
|
| 428 |
+
parent: d,
|
| 429 |
+
}).then(node => this.#loadFSTree(node)))
|
| 430 |
+
}
|
| 431 |
+
}
|
| 432 |
+
break
|
| 433 |
+
}
|
| 434 |
+
}
|
| 435 |
+
await Promise.all(depPromises)
|
| 436 |
+
}
|
| 437 |
+
}
|
| 438 |
+
}
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/load-virtual.js
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// mixin providing the loadVirtual method
|
| 2 |
+
const mapWorkspaces = require('@npmcli/map-workspaces')
|
| 3 |
+
|
| 4 |
+
const { resolve } = require('node:path')
|
| 5 |
+
|
| 6 |
+
const nameFromFolder = require('@npmcli/name-from-folder')
|
| 7 |
+
const consistentResolve = require('../consistent-resolve.js')
|
| 8 |
+
const Shrinkwrap = require('../shrinkwrap.js')
|
| 9 |
+
const Node = require('../node.js')
|
| 10 |
+
const Link = require('../link.js')
|
| 11 |
+
const relpath = require('../relpath.js')
|
| 12 |
+
const calcDepFlags = require('../calc-dep-flags.js')
|
| 13 |
+
const rpj = require('read-package-json-fast')
|
| 14 |
+
const treeCheck = require('../tree-check.js')
|
| 15 |
+
|
| 16 |
+
const flagsSuspect = Symbol.for('flagsSuspect')
|
| 17 |
+
const setWorkspaces = Symbol.for('setWorkspaces')
|
| 18 |
+
|
| 19 |
+
module.exports = cls => class VirtualLoader extends cls {
|
| 20 |
+
#rootOptionProvided
|
| 21 |
+
|
| 22 |
+
constructor (options) {
|
| 23 |
+
super(options)
|
| 24 |
+
|
| 25 |
+
// the virtual tree we load from a shrinkwrap
|
| 26 |
+
this.virtualTree = options.virtualTree
|
| 27 |
+
this[flagsSuspect] = false
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
// public method
|
| 31 |
+
async loadVirtual (options = {}) {
|
| 32 |
+
if (this.virtualTree) {
|
| 33 |
+
return this.virtualTree
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
// allow the user to set reify options on the ctor as well.
|
| 37 |
+
// XXX: deprecate separate reify() options object.
|
| 38 |
+
options = { ...this.options, ...options }
|
| 39 |
+
|
| 40 |
+
if (options.root && options.root.meta) {
|
| 41 |
+
await this.#loadFromShrinkwrap(options.root.meta, options.root)
|
| 42 |
+
return treeCheck(this.virtualTree)
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
const s = await Shrinkwrap.load({
|
| 46 |
+
path: this.path,
|
| 47 |
+
lockfileVersion: this.options.lockfileVersion,
|
| 48 |
+
resolveOptions: this.options,
|
| 49 |
+
})
|
| 50 |
+
if (!s.loadedFromDisk && !options.root) {
|
| 51 |
+
const er = new Error('loadVirtual requires existing shrinkwrap file')
|
| 52 |
+
throw Object.assign(er, { code: 'ENOLOCK' })
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
// when building the ideal tree, we pass in a root node to this function
|
| 56 |
+
// otherwise, load it from the root package json or the lockfile
|
| 57 |
+
const {
|
| 58 |
+
root = await this.#loadRoot(s),
|
| 59 |
+
} = options
|
| 60 |
+
|
| 61 |
+
this.#rootOptionProvided = options.root
|
| 62 |
+
|
| 63 |
+
await this.#loadFromShrinkwrap(s, root)
|
| 64 |
+
root.assertRootOverrides()
|
| 65 |
+
return treeCheck(this.virtualTree)
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
async #loadRoot (s) {
|
| 69 |
+
const pj = this.path + '/package.json'
|
| 70 |
+
const pkg = await rpj(pj).catch(() => s.data.packages['']) || {}
|
| 71 |
+
return this[setWorkspaces](this.#loadNode('', pkg, true))
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
async #loadFromShrinkwrap (s, root) {
|
| 75 |
+
if (!this.#rootOptionProvided) {
|
| 76 |
+
// root is never any of these things, but might be a brand new
|
| 77 |
+
// baby Node object that never had its dep flags calculated.
|
| 78 |
+
root.extraneous = false
|
| 79 |
+
root.dev = false
|
| 80 |
+
root.optional = false
|
| 81 |
+
root.devOptional = false
|
| 82 |
+
root.peer = false
|
| 83 |
+
} else {
|
| 84 |
+
this[flagsSuspect] = true
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
this.#checkRootEdges(s, root)
|
| 88 |
+
root.meta = s
|
| 89 |
+
this.virtualTree = root
|
| 90 |
+
const { links, nodes } = this.#resolveNodes(s, root)
|
| 91 |
+
await this.#resolveLinks(links, nodes)
|
| 92 |
+
if (!(s.originalLockfileVersion >= 2)) {
|
| 93 |
+
this.#assignBundles(nodes)
|
| 94 |
+
}
|
| 95 |
+
if (this[flagsSuspect]) {
|
| 96 |
+
// reset all dep flags
|
| 97 |
+
// can't use inventory here, because virtualTree might not be root
|
| 98 |
+
for (const node of nodes.values()) {
|
| 99 |
+
if (node.isRoot || node === this.#rootOptionProvided) {
|
| 100 |
+
continue
|
| 101 |
+
}
|
| 102 |
+
node.extraneous = true
|
| 103 |
+
node.dev = true
|
| 104 |
+
node.optional = true
|
| 105 |
+
node.devOptional = true
|
| 106 |
+
node.peer = true
|
| 107 |
+
}
|
| 108 |
+
calcDepFlags(this.virtualTree, !this.#rootOptionProvided)
|
| 109 |
+
}
|
| 110 |
+
return root
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
// check the lockfile deps, and see if they match. if they do not
|
| 114 |
+
// then we have to reset dep flags at the end. for example, if the
|
| 115 |
+
// user manually edits their package.json file, then we need to know
|
| 116 |
+
// that the idealTree is no longer entirely trustworthy.
|
| 117 |
+
#checkRootEdges (s, root) {
|
| 118 |
+
// loaded virtually from tree, no chance of being out of sync
|
| 119 |
+
// ancient lockfiles are critically damaged by this process,
|
| 120 |
+
// so we need to just hope for the best in those cases.
|
| 121 |
+
if (!s.loadedFromDisk || s.ancientLockfile) {
|
| 122 |
+
return
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
const lock = s.get('')
|
| 126 |
+
const prod = lock.dependencies || {}
|
| 127 |
+
const dev = lock.devDependencies || {}
|
| 128 |
+
const optional = lock.optionalDependencies || {}
|
| 129 |
+
const peer = lock.peerDependencies || {}
|
| 130 |
+
const peerOptional = {}
|
| 131 |
+
|
| 132 |
+
if (lock.peerDependenciesMeta) {
|
| 133 |
+
for (const [name, meta] of Object.entries(lock.peerDependenciesMeta)) {
|
| 134 |
+
if (meta.optional && peer[name] !== undefined) {
|
| 135 |
+
peerOptional[name] = peer[name]
|
| 136 |
+
delete peer[name]
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
for (const name of Object.keys(optional)) {
|
| 142 |
+
delete prod[name]
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
const lockWS = {}
|
| 146 |
+
const workspaces = mapWorkspaces.virtual({
|
| 147 |
+
cwd: this.path,
|
| 148 |
+
lockfile: s.data,
|
| 149 |
+
})
|
| 150 |
+
|
| 151 |
+
for (const [name, path] of workspaces.entries()) {
|
| 152 |
+
lockWS[name] = `file:${path}`
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
// Should rootNames exclude optional?
|
| 156 |
+
const rootNames = new Set(root.edgesOut.keys())
|
| 157 |
+
|
| 158 |
+
const lockByType = ({ dev, optional, peer, peerOptional, prod, workspace: lockWS })
|
| 159 |
+
|
| 160 |
+
// Find anything in shrinkwrap deps that doesn't match root's type or spec
|
| 161 |
+
for (const type in lockByType) {
|
| 162 |
+
const deps = lockByType[type]
|
| 163 |
+
for (const name in deps) {
|
| 164 |
+
const edge = root.edgesOut.get(name)
|
| 165 |
+
if (!edge || edge.type !== type || edge.spec !== deps[name]) {
|
| 166 |
+
return this[flagsSuspect] = true
|
| 167 |
+
}
|
| 168 |
+
rootNames.delete(name)
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
// Something was in root that's not accounted for in shrinkwrap
|
| 172 |
+
if (rootNames.size) {
|
| 173 |
+
return this[flagsSuspect] = true
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
// separate out link metadatas, and create Node objects for nodes
|
| 178 |
+
#resolveNodes (s, root) {
|
| 179 |
+
const links = new Map()
|
| 180 |
+
const nodes = new Map([['', root]])
|
| 181 |
+
for (const [location, meta] of Object.entries(s.data.packages)) {
|
| 182 |
+
// skip the root because we already got it
|
| 183 |
+
if (!location) {
|
| 184 |
+
continue
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
if (meta.link) {
|
| 188 |
+
links.set(location, meta)
|
| 189 |
+
} else {
|
| 190 |
+
nodes.set(location, this.#loadNode(location, meta))
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
+
return { links, nodes }
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
// links is the set of metadata, and nodes is the map of non-Link nodes
|
| 197 |
+
// Set the targets to nodes in the set, if we have them (we might not)
|
| 198 |
+
async #resolveLinks (links, nodes) {
|
| 199 |
+
for (const [location, meta] of links.entries()) {
|
| 200 |
+
const targetPath = resolve(this.path, meta.resolved)
|
| 201 |
+
const targetLoc = relpath(this.path, targetPath)
|
| 202 |
+
const target = nodes.get(targetLoc)
|
| 203 |
+
const link = this.#loadLink(location, targetLoc, target, meta)
|
| 204 |
+
nodes.set(location, link)
|
| 205 |
+
nodes.set(targetLoc, link.target)
|
| 206 |
+
|
| 207 |
+
// we always need to read the package.json for link targets
|
| 208 |
+
// outside node_modules because they can be changed by the local user
|
| 209 |
+
if (!link.target.parent) {
|
| 210 |
+
const pj = link.realpath + '/package.json'
|
| 211 |
+
const pkg = await rpj(pj).catch(() => null)
|
| 212 |
+
if (pkg) {
|
| 213 |
+
link.target.package = pkg
|
| 214 |
+
}
|
| 215 |
+
}
|
| 216 |
+
}
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
#assignBundles (nodes) {
|
| 220 |
+
for (const [location, node] of nodes) {
|
| 221 |
+
// Skip assignment of parentage for the root package
|
| 222 |
+
if (!location || node.isLink && !node.target.location) {
|
| 223 |
+
continue
|
| 224 |
+
}
|
| 225 |
+
const { name, parent, package: { inBundle } } = node
|
| 226 |
+
|
| 227 |
+
if (!parent) {
|
| 228 |
+
continue
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
// read inBundle from package because 'package' here is
|
| 232 |
+
// actually a v2 lockfile metadata entry.
|
| 233 |
+
// If the *parent* is also bundled, though, or if the parent has
|
| 234 |
+
// no dependency on it, then we assume that it's being pulled in
|
| 235 |
+
// just by virtue of its parent or a transitive dep being bundled.
|
| 236 |
+
const { package: ppkg } = parent
|
| 237 |
+
const { inBundle: parentBundled } = ppkg
|
| 238 |
+
if (inBundle && !parentBundled && parent.edgesOut.has(node.name)) {
|
| 239 |
+
if (!ppkg.bundleDependencies) {
|
| 240 |
+
ppkg.bundleDependencies = [name]
|
| 241 |
+
} else {
|
| 242 |
+
ppkg.bundleDependencies.push(name)
|
| 243 |
+
}
|
| 244 |
+
}
|
| 245 |
+
}
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
#loadNode (location, sw, loadOverrides) {
|
| 249 |
+
const p = this.virtualTree ? this.virtualTree.realpath : this.path
|
| 250 |
+
const path = resolve(p, location)
|
| 251 |
+
// shrinkwrap doesn't include package name unless necessary
|
| 252 |
+
if (!sw.name) {
|
| 253 |
+
sw.name = nameFromFolder(path)
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
const dev = sw.dev
|
| 257 |
+
const optional = sw.optional
|
| 258 |
+
const devOptional = dev || optional || sw.devOptional
|
| 259 |
+
const peer = sw.peer
|
| 260 |
+
|
| 261 |
+
const node = new Node({
|
| 262 |
+
installLinks: this.installLinks,
|
| 263 |
+
legacyPeerDeps: this.legacyPeerDeps,
|
| 264 |
+
root: this.virtualTree,
|
| 265 |
+
path,
|
| 266 |
+
realpath: path,
|
| 267 |
+
integrity: sw.integrity,
|
| 268 |
+
resolved: consistentResolve(sw.resolved, this.path, path),
|
| 269 |
+
pkg: sw,
|
| 270 |
+
hasShrinkwrap: sw.hasShrinkwrap,
|
| 271 |
+
dev,
|
| 272 |
+
optional,
|
| 273 |
+
devOptional,
|
| 274 |
+
peer,
|
| 275 |
+
loadOverrides,
|
| 276 |
+
})
|
| 277 |
+
// cast to boolean because they're undefined in the lock file when false
|
| 278 |
+
node.extraneous = !!sw.extraneous
|
| 279 |
+
node.devOptional = !!(sw.devOptional || sw.dev || sw.optional)
|
| 280 |
+
node.peer = !!sw.peer
|
| 281 |
+
node.optional = !!sw.optional
|
| 282 |
+
node.dev = !!sw.dev
|
| 283 |
+
return node
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
#loadLink (location, targetLoc, target) {
|
| 287 |
+
const path = resolve(this.path, location)
|
| 288 |
+
const link = new Link({
|
| 289 |
+
installLinks: this.installLinks,
|
| 290 |
+
legacyPeerDeps: this.legacyPeerDeps,
|
| 291 |
+
path,
|
| 292 |
+
realpath: resolve(this.path, targetLoc),
|
| 293 |
+
target,
|
| 294 |
+
pkg: target && target.package,
|
| 295 |
+
})
|
| 296 |
+
link.extraneous = target.extraneous
|
| 297 |
+
link.devOptional = target.devOptional
|
| 298 |
+
link.peer = target.peer
|
| 299 |
+
link.optional = target.optional
|
| 300 |
+
link.dev = target.dev
|
| 301 |
+
return link
|
| 302 |
+
}
|
| 303 |
+
}
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/rebuild.js
ADDED
|
@@ -0,0 +1,400 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Arborist.rebuild({path = this.path}) will do all the binlinks and
|
| 2 |
+
// bundle building needed. Called by reify, and by `npm rebuild`.
|
| 3 |
+
|
| 4 |
+
const localeCompare = require('@isaacs/string-locale-compare')('en')
|
| 5 |
+
const { depth: dfwalk } = require('treeverse')
|
| 6 |
+
const promiseAllRejectLate = require('promise-all-reject-late')
|
| 7 |
+
const rpj = require('read-package-json-fast')
|
| 8 |
+
const binLinks = require('bin-links')
|
| 9 |
+
const runScript = require('@npmcli/run-script')
|
| 10 |
+
const { callLimit: promiseCallLimit } = require('promise-call-limit')
|
| 11 |
+
const { resolve } = require('node:path')
|
| 12 |
+
const { isNodeGypPackage, defaultGypInstallScript } = require('@npmcli/node-gyp')
|
| 13 |
+
const { log, time } = require('proc-log')
|
| 14 |
+
|
| 15 |
+
const boolEnv = b => b ? '1' : ''
|
| 16 |
+
const sortNodes = (a, b) =>
|
| 17 |
+
(a.depth - b.depth) || localeCompare(a.path, b.path)
|
| 18 |
+
|
| 19 |
+
const _checkBins = Symbol.for('checkBins')
|
| 20 |
+
|
| 21 |
+
// defined by reify mixin
|
| 22 |
+
const _handleOptionalFailure = Symbol.for('handleOptionalFailure')
|
| 23 |
+
const _trashList = Symbol.for('trashList')
|
| 24 |
+
|
| 25 |
+
module.exports = cls => class Builder extends cls {
|
| 26 |
+
#doHandleOptionalFailure
|
| 27 |
+
#oldMeta = null
|
| 28 |
+
#queues
|
| 29 |
+
|
| 30 |
+
constructor (options) {
|
| 31 |
+
super(options)
|
| 32 |
+
|
| 33 |
+
this.scriptsRun = new Set()
|
| 34 |
+
this.#resetQueues()
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
async rebuild ({ nodes, handleOptionalFailure = false } = {}) {
|
| 38 |
+
// nothing to do if we're not building anything!
|
| 39 |
+
if (this.options.ignoreScripts && !this.options.binLinks) {
|
| 40 |
+
return
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
// when building for the first time, as part of reify, we ignore
|
| 44 |
+
// failures in optional nodes, and just delete them. however, when
|
| 45 |
+
// running JUST a rebuild, we treat optional failures as real fails
|
| 46 |
+
this.#doHandleOptionalFailure = handleOptionalFailure
|
| 47 |
+
|
| 48 |
+
if (!nodes) {
|
| 49 |
+
nodes = await this.#loadDefaultNodes()
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
// separates links nodes so that it can run
|
| 53 |
+
// prepare scripts and link bins in the expected order
|
| 54 |
+
const timeEnd = time.start('build')
|
| 55 |
+
|
| 56 |
+
const {
|
| 57 |
+
depNodes,
|
| 58 |
+
linkNodes,
|
| 59 |
+
} = this.#retrieveNodesByType(nodes)
|
| 60 |
+
|
| 61 |
+
// build regular deps
|
| 62 |
+
await this.#build(depNodes, {})
|
| 63 |
+
|
| 64 |
+
// build link deps
|
| 65 |
+
if (linkNodes.size) {
|
| 66 |
+
this.#resetQueues()
|
| 67 |
+
await this.#build(linkNodes, { type: 'links' })
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
timeEnd()
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
// if we don't have a set of nodes, then just rebuild
|
| 74 |
+
// the actual tree on disk.
|
| 75 |
+
async #loadDefaultNodes () {
|
| 76 |
+
let nodes
|
| 77 |
+
const tree = await this.loadActual()
|
| 78 |
+
let filterSet
|
| 79 |
+
if (!this.options.workspacesEnabled) {
|
| 80 |
+
filterSet = this.excludeWorkspacesDependencySet(tree)
|
| 81 |
+
nodes = tree.inventory.filter(node =>
|
| 82 |
+
filterSet.has(node) || node.isProjectRoot
|
| 83 |
+
)
|
| 84 |
+
} else if (this.options.workspaces.length) {
|
| 85 |
+
filterSet = this.workspaceDependencySet(
|
| 86 |
+
tree,
|
| 87 |
+
this.options.workspaces,
|
| 88 |
+
this.options.includeWorkspaceRoot
|
| 89 |
+
)
|
| 90 |
+
nodes = tree.inventory.filter(node => filterSet.has(node))
|
| 91 |
+
} else {
|
| 92 |
+
nodes = tree.inventory.values()
|
| 93 |
+
}
|
| 94 |
+
return nodes
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
#retrieveNodesByType (nodes) {
|
| 98 |
+
const depNodes = new Set()
|
| 99 |
+
const linkNodes = new Set()
|
| 100 |
+
const storeNodes = new Set()
|
| 101 |
+
|
| 102 |
+
for (const node of nodes) {
|
| 103 |
+
if (node.isStoreLink) {
|
| 104 |
+
storeNodes.add(node)
|
| 105 |
+
} else if (node.isLink) {
|
| 106 |
+
linkNodes.add(node)
|
| 107 |
+
} else {
|
| 108 |
+
depNodes.add(node)
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
// Make sure that store linked nodes are processed last.
|
| 112 |
+
// We can't process store links separately or else lifecycle scripts on
|
| 113 |
+
// standard nodes might not have bin links yet.
|
| 114 |
+
for (const node of storeNodes) {
|
| 115 |
+
depNodes.add(node)
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
// deduplicates link nodes and their targets, avoids
|
| 119 |
+
// calling lifecycle scripts twice when running `npm rebuild`
|
| 120 |
+
// ref: https://github.com/npm/cli/issues/2905
|
| 121 |
+
//
|
| 122 |
+
// we avoid doing so if global=true since `bin-links` relies
|
| 123 |
+
// on having the target nodes available in global mode.
|
| 124 |
+
if (!this.options.global) {
|
| 125 |
+
for (const node of linkNodes) {
|
| 126 |
+
depNodes.delete(node.target)
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
return {
|
| 131 |
+
depNodes,
|
| 132 |
+
linkNodes,
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
#resetQueues () {
|
| 137 |
+
this.#queues = {
|
| 138 |
+
preinstall: [],
|
| 139 |
+
install: [],
|
| 140 |
+
postinstall: [],
|
| 141 |
+
prepare: [],
|
| 142 |
+
bin: [],
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
async #build (nodes, { type = 'deps' }) {
|
| 147 |
+
const timeEnd = time.start(`build:${type}`)
|
| 148 |
+
|
| 149 |
+
await this.#buildQueues(nodes)
|
| 150 |
+
|
| 151 |
+
if (!this.options.ignoreScripts) {
|
| 152 |
+
await this.#runScripts('preinstall')
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
// links should run prepare scripts and only link bins after that
|
| 156 |
+
if (type === 'links') {
|
| 157 |
+
await this.#runScripts('prepare')
|
| 158 |
+
}
|
| 159 |
+
if (this.options.binLinks) {
|
| 160 |
+
await this.#linkAllBins()
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
if (!this.options.ignoreScripts) {
|
| 164 |
+
await this.#runScripts('install')
|
| 165 |
+
await this.#runScripts('postinstall')
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
timeEnd()
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
async #buildQueues (nodes) {
|
| 172 |
+
const timeEnd = time.start('build:queue')
|
| 173 |
+
const set = new Set()
|
| 174 |
+
|
| 175 |
+
const promises = []
|
| 176 |
+
for (const node of nodes) {
|
| 177 |
+
promises.push(this.#addToBuildSet(node, set))
|
| 178 |
+
|
| 179 |
+
// if it has bundle deps, add those too, if rebuildBundle
|
| 180 |
+
if (this.options.rebuildBundle !== false) {
|
| 181 |
+
const bd = node.package.bundleDependencies
|
| 182 |
+
if (bd && bd.length) {
|
| 183 |
+
dfwalk({
|
| 184 |
+
tree: node,
|
| 185 |
+
leave: node => promises.push(this.#addToBuildSet(node, set)),
|
| 186 |
+
getChildren: node => [...node.children.values()],
|
| 187 |
+
filter: node => node.inBundle,
|
| 188 |
+
})
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
}
|
| 192 |
+
await promiseAllRejectLate(promises)
|
| 193 |
+
|
| 194 |
+
// now sort into the queues for the 4 things we have to do
|
| 195 |
+
// run in the same predictable order that buildIdealTree uses
|
| 196 |
+
// there's no particular reason for doing it in this order rather
|
| 197 |
+
// than another, but sorting *somehow* makes it consistent.
|
| 198 |
+
const queue = [...set].sort(sortNodes)
|
| 199 |
+
|
| 200 |
+
for (const node of queue) {
|
| 201 |
+
const { package: { bin, scripts = {} } } = node.target
|
| 202 |
+
const { preinstall, install, postinstall, prepare } = scripts
|
| 203 |
+
const tests = { bin, preinstall, install, postinstall, prepare }
|
| 204 |
+
for (const [key, has] of Object.entries(tests)) {
|
| 205 |
+
if (has) {
|
| 206 |
+
this.#queues[key].push(node)
|
| 207 |
+
}
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
timeEnd()
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
async [_checkBins] (node) {
|
| 214 |
+
// if the node is a global top, and we're not in force mode, then
|
| 215 |
+
// any existing bins need to either be missing, or a symlink into
|
| 216 |
+
// the node path. Otherwise a package can have a preinstall script
|
| 217 |
+
// that unlinks something, to allow them to silently overwrite system
|
| 218 |
+
// binaries, which is unsafe and insecure.
|
| 219 |
+
if (!node.globalTop || this.options.force) {
|
| 220 |
+
return
|
| 221 |
+
}
|
| 222 |
+
const { path, package: pkg } = node
|
| 223 |
+
await binLinks.checkBins({ pkg, path, top: true, global: true })
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
async #addToBuildSet (node, set, refreshed = false) {
|
| 227 |
+
if (set.has(node)) {
|
| 228 |
+
return
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
if (this.#oldMeta === null) {
|
| 232 |
+
const { root: { meta } } = node
|
| 233 |
+
this.#oldMeta = meta && meta.loadedFromDisk &&
|
| 234 |
+
!(meta.originalLockfileVersion >= 2)
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
const { package: pkg, hasInstallScript } = node.target
|
| 238 |
+
const { gypfile, bin, scripts = {} } = pkg
|
| 239 |
+
|
| 240 |
+
const { preinstall, install, postinstall, prepare } = scripts
|
| 241 |
+
const anyScript = preinstall || install || postinstall || prepare
|
| 242 |
+
if (!refreshed && !anyScript && (hasInstallScript || this.#oldMeta)) {
|
| 243 |
+
// we either have an old metadata (and thus might have scripts)
|
| 244 |
+
// or we have an indication that there's install scripts (but
|
| 245 |
+
// don't yet know what they are) so we have to load the package.json
|
| 246 |
+
// from disk to see what the deal is. Failure here just means
|
| 247 |
+
// no scripts to add, probably borked package.json.
|
| 248 |
+
// add to the set then remove while we're reading the pj, so we
|
| 249 |
+
// don't accidentally hit it multiple times.
|
| 250 |
+
set.add(node)
|
| 251 |
+
const pkg = await rpj(node.path + '/package.json').catch(() => ({}))
|
| 252 |
+
set.delete(node)
|
| 253 |
+
|
| 254 |
+
const { scripts = {} } = pkg
|
| 255 |
+
node.package.scripts = scripts
|
| 256 |
+
return this.#addToBuildSet(node, set, true)
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
// Rebuild node-gyp dependencies lacking an install or preinstall script
|
| 260 |
+
// note that 'scripts' might be missing entirely, and the package may
|
| 261 |
+
// set gypfile:false to avoid this automatic detection.
|
| 262 |
+
const isGyp = gypfile !== false &&
|
| 263 |
+
!install &&
|
| 264 |
+
!preinstall &&
|
| 265 |
+
await isNodeGypPackage(node.path)
|
| 266 |
+
|
| 267 |
+
if (bin || preinstall || install || postinstall || prepare || isGyp) {
|
| 268 |
+
if (bin) {
|
| 269 |
+
await this[_checkBins](node)
|
| 270 |
+
}
|
| 271 |
+
if (isGyp) {
|
| 272 |
+
scripts.install = defaultGypInstallScript
|
| 273 |
+
node.package.scripts = scripts
|
| 274 |
+
}
|
| 275 |
+
set.add(node)
|
| 276 |
+
}
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
async #runScripts (event) {
|
| 280 |
+
const queue = this.#queues[event]
|
| 281 |
+
|
| 282 |
+
if (!queue.length) {
|
| 283 |
+
return
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
const timeEnd = time.start(`build:run:${event}`)
|
| 287 |
+
const stdio = this.options.foregroundScripts ? 'inherit' : 'pipe'
|
| 288 |
+
const limit = this.options.foregroundScripts ? 1 : undefined
|
| 289 |
+
await promiseCallLimit(queue.map(node => async () => {
|
| 290 |
+
const {
|
| 291 |
+
path,
|
| 292 |
+
integrity,
|
| 293 |
+
resolved,
|
| 294 |
+
optional,
|
| 295 |
+
peer,
|
| 296 |
+
dev,
|
| 297 |
+
devOptional,
|
| 298 |
+
package: pkg,
|
| 299 |
+
location,
|
| 300 |
+
isStoreLink,
|
| 301 |
+
} = node.target
|
| 302 |
+
|
| 303 |
+
// skip any that we know we'll be deleting
|
| 304 |
+
// or storeLinks
|
| 305 |
+
if (this[_trashList].has(path) || isStoreLink) {
|
| 306 |
+
return
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
const timeEndLocation = time.start(`build:run:${event}:${location}`)
|
| 310 |
+
log.info('run', pkg._id, event, location, pkg.scripts[event])
|
| 311 |
+
const env = {
|
| 312 |
+
npm_package_resolved: resolved,
|
| 313 |
+
npm_package_integrity: integrity,
|
| 314 |
+
npm_package_json: resolve(path, 'package.json'),
|
| 315 |
+
npm_package_optional: boolEnv(optional),
|
| 316 |
+
npm_package_dev: boolEnv(dev),
|
| 317 |
+
npm_package_peer: boolEnv(peer),
|
| 318 |
+
npm_package_dev_optional:
|
| 319 |
+
boolEnv(devOptional && !dev && !optional),
|
| 320 |
+
}
|
| 321 |
+
const runOpts = {
|
| 322 |
+
event,
|
| 323 |
+
path,
|
| 324 |
+
pkg,
|
| 325 |
+
stdio,
|
| 326 |
+
env,
|
| 327 |
+
scriptShell: this.options.scriptShell,
|
| 328 |
+
}
|
| 329 |
+
const p = runScript(runOpts).catch(er => {
|
| 330 |
+
const { code, signal } = er
|
| 331 |
+
log.info('run', pkg._id, event, { code, signal })
|
| 332 |
+
throw er
|
| 333 |
+
}).then(({ args, code, signal, stdout, stderr }) => {
|
| 334 |
+
this.scriptsRun.add({
|
| 335 |
+
pkg,
|
| 336 |
+
path,
|
| 337 |
+
event,
|
| 338 |
+
// I do not know why this needs to be on THIS line but refactoring
|
| 339 |
+
// this function would be quite a process
|
| 340 |
+
// eslint-disable-next-line promise/always-return
|
| 341 |
+
cmd: args && args[args.length - 1],
|
| 342 |
+
env,
|
| 343 |
+
code,
|
| 344 |
+
signal,
|
| 345 |
+
stdout,
|
| 346 |
+
stderr,
|
| 347 |
+
})
|
| 348 |
+
log.info('run', pkg._id, event, { code, signal })
|
| 349 |
+
})
|
| 350 |
+
|
| 351 |
+
await (this.#doHandleOptionalFailure
|
| 352 |
+
? this[_handleOptionalFailure](node, p)
|
| 353 |
+
: p)
|
| 354 |
+
|
| 355 |
+
timeEndLocation()
|
| 356 |
+
}), { limit })
|
| 357 |
+
timeEnd()
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
async #linkAllBins () {
|
| 361 |
+
const queue = this.#queues.bin
|
| 362 |
+
if (!queue.length) {
|
| 363 |
+
return
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
const timeEnd = time.start('build:link')
|
| 367 |
+
const promises = []
|
| 368 |
+
// sort the queue by node path, so that the module-local collision
|
| 369 |
+
// detector in bin-links will always resolve the same way.
|
| 370 |
+
for (const node of queue.sort(sortNodes)) {
|
| 371 |
+
// TODO these run before they're awaited
|
| 372 |
+
promises.push(this.#createBinLinks(node))
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
await promiseAllRejectLate(promises)
|
| 376 |
+
timeEnd()
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
async #createBinLinks (node) {
|
| 380 |
+
if (this[_trashList].has(node.path)) {
|
| 381 |
+
return
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
const timeEnd = time.start(`build:link:${node.location}`)
|
| 385 |
+
|
| 386 |
+
const p = binLinks({
|
| 387 |
+
pkg: node.package,
|
| 388 |
+
path: node.path,
|
| 389 |
+
top: !!(node.isTop || node.globalTop),
|
| 390 |
+
force: this.options.force,
|
| 391 |
+
global: !!node.globalTop,
|
| 392 |
+
})
|
| 393 |
+
|
| 394 |
+
await (this.#doHandleOptionalFailure
|
| 395 |
+
? this[_handleOptionalFailure](node, p)
|
| 396 |
+
: p)
|
| 397 |
+
|
| 398 |
+
timeEnd()
|
| 399 |
+
}
|
| 400 |
+
}
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js
ADDED
|
@@ -0,0 +1,1535 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// mixin implementing the reify method
|
| 2 |
+
const onExit = require('../signal-handling.js')
|
| 3 |
+
const pacote = require('pacote')
|
| 4 |
+
const AuditReport = require('../audit-report.js')
|
| 5 |
+
const { subset, intersects } = require('semver')
|
| 6 |
+
const npa = require('npm-package-arg')
|
| 7 |
+
const semver = require('semver')
|
| 8 |
+
const debug = require('../debug.js')
|
| 9 |
+
const { walkUp } = require('walk-up-path')
|
| 10 |
+
const { log, time } = require('proc-log')
|
| 11 |
+
const hgi = require('hosted-git-info')
|
| 12 |
+
const rpj = require('read-package-json-fast')
|
| 13 |
+
|
| 14 |
+
const { dirname, resolve, relative, join } = require('node:path')
|
| 15 |
+
const { depth: dfwalk } = require('treeverse')
|
| 16 |
+
const {
|
| 17 |
+
lstat,
|
| 18 |
+
mkdir,
|
| 19 |
+
rm,
|
| 20 |
+
symlink,
|
| 21 |
+
} = require('node:fs/promises')
|
| 22 |
+
const { moveFile } = require('@npmcli/fs')
|
| 23 |
+
const PackageJson = require('@npmcli/package-json')
|
| 24 |
+
const packageContents = require('@npmcli/installed-package-contents')
|
| 25 |
+
const runScript = require('@npmcli/run-script')
|
| 26 |
+
const { checkEngine, checkPlatform } = require('npm-install-checks')
|
| 27 |
+
|
| 28 |
+
const treeCheck = require('../tree-check.js')
|
| 29 |
+
const relpath = require('../relpath.js')
|
| 30 |
+
const Diff = require('../diff.js')
|
| 31 |
+
const retirePath = require('../retire-path.js')
|
| 32 |
+
const promiseAllRejectLate = require('promise-all-reject-late')
|
| 33 |
+
const { callLimit: promiseCallLimit } = require('promise-call-limit')
|
| 34 |
+
const optionalSet = require('../optional-set.js')
|
| 35 |
+
const calcDepFlags = require('../calc-dep-flags.js')
|
| 36 |
+
const { saveTypeMap, hasSubKey } = require('../add-rm-pkg-deps.js')
|
| 37 |
+
|
| 38 |
+
const Shrinkwrap = require('../shrinkwrap.js')
|
| 39 |
+
const { defaultLockfileVersion } = Shrinkwrap
|
| 40 |
+
|
| 41 |
+
// Part of steps (steps need refactoring before we can do anything about these)
|
| 42 |
+
const _retireShallowNodes = Symbol.for('retireShallowNodes')
|
| 43 |
+
const _loadBundlesAndUpdateTrees = Symbol.for('loadBundlesAndUpdateTrees')
|
| 44 |
+
const _submitQuickAudit = Symbol('submitQuickAudit')
|
| 45 |
+
const _addOmitsToTrashList = Symbol('addOmitsToTrashList')
|
| 46 |
+
const _unpackNewModules = Symbol.for('unpackNewModules')
|
| 47 |
+
const _build = Symbol.for('build')
|
| 48 |
+
|
| 49 |
+
// shared by rebuild mixin
|
| 50 |
+
const _trashList = Symbol.for('trashList')
|
| 51 |
+
const _handleOptionalFailure = Symbol.for('handleOptionalFailure')
|
| 52 |
+
const _loadTrees = Symbol.for('loadTrees')
|
| 53 |
+
// defined by rebuild mixin
|
| 54 |
+
const _checkBins = Symbol.for('checkBins')
|
| 55 |
+
|
| 56 |
+
// shared symbols for swapping out when testing
|
| 57 |
+
// TODO tests should not be this deep into internals
|
| 58 |
+
const _diffTrees = Symbol.for('diffTrees')
|
| 59 |
+
const _createSparseTree = Symbol.for('createSparseTree')
|
| 60 |
+
const _loadShrinkwrapsAndUpdateTrees = Symbol.for('loadShrinkwrapsAndUpdateTrees')
|
| 61 |
+
const _reifyNode = Symbol.for('reifyNode')
|
| 62 |
+
const _updateAll = Symbol.for('updateAll')
|
| 63 |
+
const _updateNames = Symbol.for('updateNames')
|
| 64 |
+
const _moveContents = Symbol.for('moveContents')
|
| 65 |
+
const _moveBackRetiredUnchanged = Symbol.for('moveBackRetiredUnchanged')
|
| 66 |
+
const _removeTrash = Symbol.for('removeTrash')
|
| 67 |
+
const _renamePath = Symbol.for('renamePath')
|
| 68 |
+
const _rollbackRetireShallowNodes = Symbol.for('rollbackRetireShallowNodes')
|
| 69 |
+
const _rollbackCreateSparseTree = Symbol.for('rollbackCreateSparseTree')
|
| 70 |
+
const _rollbackMoveBackRetiredUnchanged = Symbol.for('rollbackMoveBackRetiredUnchanged')
|
| 71 |
+
const _saveIdealTree = Symbol.for('saveIdealTree')
|
| 72 |
+
const _reifyPackages = Symbol.for('reifyPackages')
|
| 73 |
+
|
| 74 |
+
// defined by build-ideal-tree mixin
|
| 75 |
+
const _resolvedAdd = Symbol.for('resolvedAdd')
|
| 76 |
+
const _usePackageLock = Symbol.for('usePackageLock')
|
| 77 |
+
// used by build-ideal-tree mixin
|
| 78 |
+
const _addNodeToTrashList = Symbol.for('addNodeToTrashList')
|
| 79 |
+
|
| 80 |
+
const _createIsolatedTree = Symbol.for('createIsolatedTree')
|
| 81 |
+
|
| 82 |
+
module.exports = cls => class Reifier extends cls {
|
| 83 |
+
#bundleMissing = new Set() // child nodes we'd EXPECT to be included in a bundle, but aren't
|
| 84 |
+
#bundleUnpacked = new Set() // the nodes we unpack to read their bundles
|
| 85 |
+
#dryRun
|
| 86 |
+
#nmValidated = new Set()
|
| 87 |
+
#omitDev
|
| 88 |
+
#omitPeer
|
| 89 |
+
#omitOptional
|
| 90 |
+
#retiredPaths = {}
|
| 91 |
+
#retiredUnchanged = {}
|
| 92 |
+
#savePrefix
|
| 93 |
+
#shrinkwrapInflated = new Set()
|
| 94 |
+
#sparseTreeDirs = new Set()
|
| 95 |
+
#sparseTreeRoots = new Set()
|
| 96 |
+
|
| 97 |
+
constructor (options) {
|
| 98 |
+
super(options)
|
| 99 |
+
|
| 100 |
+
this[_trashList] = new Set()
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
// public method
|
| 104 |
+
async reify (options = {}) {
|
| 105 |
+
const linked = (options.installStrategy || this.options.installStrategy) === 'linked'
|
| 106 |
+
|
| 107 |
+
if (this.options.packageLockOnly && this.options.global) {
|
| 108 |
+
const er = new Error('cannot generate lockfile for global packages')
|
| 109 |
+
er.code = 'ESHRINKWRAPGLOBAL'
|
| 110 |
+
throw er
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
const omit = new Set(options.omit || [])
|
| 114 |
+
this.#omitDev = omit.has('dev')
|
| 115 |
+
this.#omitOptional = omit.has('optional')
|
| 116 |
+
this.#omitPeer = omit.has('peer')
|
| 117 |
+
|
| 118 |
+
// start tracker block
|
| 119 |
+
this.addTracker('reify')
|
| 120 |
+
const timeEnd = time.start('reify')
|
| 121 |
+
// don't create missing dirs on dry runs
|
| 122 |
+
if (!this.options.packageLockOnly && !this.options.dryRun) {
|
| 123 |
+
// we do NOT want to set ownership on this folder, especially
|
| 124 |
+
// recursively, because it can have other side effects to do that
|
| 125 |
+
// in a project directory. We just want to make it if it's missing.
|
| 126 |
+
await mkdir(resolve(this.path), { recursive: true })
|
| 127 |
+
|
| 128 |
+
// do not allow the top-level node_modules to be a symlink
|
| 129 |
+
await this.#validateNodeModules(resolve(this.path, 'node_modules'))
|
| 130 |
+
}
|
| 131 |
+
await this[_loadTrees](options)
|
| 132 |
+
|
| 133 |
+
const oldTree = this.idealTree
|
| 134 |
+
if (linked) {
|
| 135 |
+
// swap out the tree with the isolated tree
|
| 136 |
+
// this is currently technical debt which will be resolved in a refactor
|
| 137 |
+
// of Node/Link trees
|
| 138 |
+
log.warn('reify', 'The "linked" install strategy is EXPERIMENTAL and may contain bugs.')
|
| 139 |
+
this.idealTree = await this[_createIsolatedTree]()
|
| 140 |
+
}
|
| 141 |
+
await this[_diffTrees]()
|
| 142 |
+
await this[_reifyPackages]()
|
| 143 |
+
if (linked) {
|
| 144 |
+
// swap back in the idealTree
|
| 145 |
+
// so that the lockfile is preserved
|
| 146 |
+
this.idealTree = oldTree
|
| 147 |
+
}
|
| 148 |
+
await this[_saveIdealTree](options)
|
| 149 |
+
// clean up any trash that is still in the tree
|
| 150 |
+
for (const path of this[_trashList]) {
|
| 151 |
+
const loc = relpath(this.idealTree.realpath, path)
|
| 152 |
+
const node = this.idealTree.inventory.get(loc)
|
| 153 |
+
if (node && node.root === this.idealTree) {
|
| 154 |
+
node.parent = null
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
// if we filtered to only certain nodes, then anything ELSE needs
|
| 159 |
+
// to be untouched in the resulting actual tree, even if it differs
|
| 160 |
+
// in the idealTree. Copy over anything that was in the actual and
|
| 161 |
+
// was not changed, delete anything in the ideal and not actual.
|
| 162 |
+
// Then we move the entire idealTree over to this.actualTree, and
|
| 163 |
+
// save the hidden lockfile.
|
| 164 |
+
if (this.diff && this.diff.filterSet.size) {
|
| 165 |
+
const reroot = new Set()
|
| 166 |
+
|
| 167 |
+
const { filterSet } = this.diff
|
| 168 |
+
const seen = new Set()
|
| 169 |
+
for (const [loc, ideal] of this.idealTree.inventory.entries()) {
|
| 170 |
+
seen.add(loc)
|
| 171 |
+
|
| 172 |
+
// if it's an ideal node from the filter set, then skip it
|
| 173 |
+
// because we already made whatever changes were necessary
|
| 174 |
+
if (filterSet.has(ideal)) {
|
| 175 |
+
continue
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
// otherwise, if it's not in the actualTree, then it's not a thing
|
| 179 |
+
// that we actually added. And if it IS in the actualTree, then
|
| 180 |
+
// it's something that we left untouched, so we need to record
|
| 181 |
+
// that.
|
| 182 |
+
const actual = this.actualTree.inventory.get(loc)
|
| 183 |
+
if (!actual) {
|
| 184 |
+
ideal.root = null
|
| 185 |
+
} else {
|
| 186 |
+
if ([...actual.linksIn].some(link => filterSet.has(link))) {
|
| 187 |
+
seen.add(actual.location)
|
| 188 |
+
continue
|
| 189 |
+
}
|
| 190 |
+
const { realpath, isLink } = actual
|
| 191 |
+
if (isLink && ideal.isLink && ideal.realpath === realpath) {
|
| 192 |
+
continue
|
| 193 |
+
} else {
|
| 194 |
+
reroot.add(actual)
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
// now find any actual nodes that may not be present in the ideal
|
| 200 |
+
// tree, but were left behind by virtue of not being in the filter
|
| 201 |
+
for (const [loc, actual] of this.actualTree.inventory.entries()) {
|
| 202 |
+
if (seen.has(loc)) {
|
| 203 |
+
continue
|
| 204 |
+
}
|
| 205 |
+
seen.add(loc)
|
| 206 |
+
|
| 207 |
+
// we know that this is something that ISN'T in the idealTree,
|
| 208 |
+
// or else we will have addressed it in the previous loop.
|
| 209 |
+
// If it's in the filterSet, that means we intentionally removed
|
| 210 |
+
// it, so nothing to do here.
|
| 211 |
+
if (filterSet.has(actual)) {
|
| 212 |
+
continue
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
reroot.add(actual)
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
// go through the rerooted actual nodes, and move them over.
|
| 219 |
+
for (const actual of reroot) {
|
| 220 |
+
actual.root = this.idealTree
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
// prune out any tops that lack a linkIn, they are no longer relevant.
|
| 224 |
+
for (const top of this.idealTree.tops) {
|
| 225 |
+
if (top.linksIn.size === 0) {
|
| 226 |
+
top.root = null
|
| 227 |
+
}
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
// need to calculate dep flags, since nodes may have been marked
|
| 231 |
+
// as extraneous or otherwise incorrect during transit.
|
| 232 |
+
calcDepFlags(this.idealTree)
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
// save the ideal's meta as a hidden lockfile after we actualize it
|
| 236 |
+
this.idealTree.meta.filename =
|
| 237 |
+
this.idealTree.realpath + '/node_modules/.package-lock.json'
|
| 238 |
+
this.idealTree.meta.hiddenLockfile = true
|
| 239 |
+
this.idealTree.meta.lockfileVersion = defaultLockfileVersion
|
| 240 |
+
|
| 241 |
+
this.actualTree = this.idealTree
|
| 242 |
+
this.idealTree = null
|
| 243 |
+
|
| 244 |
+
if (!this.options.global) {
|
| 245 |
+
await this.actualTree.meta.save()
|
| 246 |
+
const ignoreScripts = !!this.options.ignoreScripts
|
| 247 |
+
// if we aren't doing a dry run or ignoring scripts and we actually made changes to the dep
|
| 248 |
+
// tree, then run the dependencies scripts
|
| 249 |
+
if (!this.options.dryRun && !ignoreScripts && this.diff && this.diff.children.length) {
|
| 250 |
+
const { path, package: pkg } = this.actualTree.target
|
| 251 |
+
const stdio = this.options.foregroundScripts ? 'inherit' : 'pipe'
|
| 252 |
+
const { scripts = {} } = pkg
|
| 253 |
+
for (const event of ['predependencies', 'dependencies', 'postdependencies']) {
|
| 254 |
+
if (Object.prototype.hasOwnProperty.call(scripts, event)) {
|
| 255 |
+
log.info('run', pkg._id, event, scripts[event])
|
| 256 |
+
await time.start(`reify:run:${event}`, () => runScript({
|
| 257 |
+
event,
|
| 258 |
+
path,
|
| 259 |
+
pkg,
|
| 260 |
+
stdio,
|
| 261 |
+
scriptShell: this.options.scriptShell,
|
| 262 |
+
}))
|
| 263 |
+
}
|
| 264 |
+
}
|
| 265 |
+
}
|
| 266 |
+
}
|
| 267 |
+
// This is a very bad pattern and I can't wait to stop doing it
|
| 268 |
+
this.auditReport = await this.auditReport
|
| 269 |
+
|
| 270 |
+
this.finishTracker('reify')
|
| 271 |
+
timeEnd()
|
| 272 |
+
return treeCheck(this.actualTree)
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
async [_reifyPackages] () {
|
| 276 |
+
// we don't submit the audit report or write to disk on dry runs
|
| 277 |
+
if (this.options.dryRun) {
|
| 278 |
+
return
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
if (this.options.packageLockOnly) {
|
| 282 |
+
// we already have the complete tree, so just audit it now,
|
| 283 |
+
// and that's all we have to do here.
|
| 284 |
+
return this[_submitQuickAudit]()
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
// ok, we're about to start touching the fs. need to roll back
|
| 288 |
+
// if we get an early termination.
|
| 289 |
+
let reifyTerminated = null
|
| 290 |
+
const removeHandler = onExit(({ signal }) => {
|
| 291 |
+
// only call once. if signal hits twice, we just terminate
|
| 292 |
+
removeHandler()
|
| 293 |
+
reifyTerminated = Object.assign(new Error('process terminated'), {
|
| 294 |
+
signal,
|
| 295 |
+
})
|
| 296 |
+
return false
|
| 297 |
+
})
|
| 298 |
+
|
| 299 |
+
// [rollbackfn, [...actions]]
|
| 300 |
+
// after each step, if the process was terminated, execute the rollback
|
| 301 |
+
// note that each rollback *also* calls the previous one when it's
|
| 302 |
+
// finished, and then the first one throws the error, so we only need
|
| 303 |
+
// a new rollback step when we have a new thing that must be done to
|
| 304 |
+
// revert the install.
|
| 305 |
+
const steps = [
|
| 306 |
+
[_rollbackRetireShallowNodes, [
|
| 307 |
+
_retireShallowNodes,
|
| 308 |
+
]],
|
| 309 |
+
[_rollbackCreateSparseTree, [
|
| 310 |
+
_createSparseTree,
|
| 311 |
+
_addOmitsToTrashList,
|
| 312 |
+
_loadShrinkwrapsAndUpdateTrees,
|
| 313 |
+
_loadBundlesAndUpdateTrees,
|
| 314 |
+
_submitQuickAudit,
|
| 315 |
+
_unpackNewModules,
|
| 316 |
+
]],
|
| 317 |
+
[_rollbackMoveBackRetiredUnchanged, [
|
| 318 |
+
_moveBackRetiredUnchanged,
|
| 319 |
+
_build,
|
| 320 |
+
]],
|
| 321 |
+
]
|
| 322 |
+
for (const [rollback, actions] of steps) {
|
| 323 |
+
for (const action of actions) {
|
| 324 |
+
try {
|
| 325 |
+
await this[action]()
|
| 326 |
+
if (reifyTerminated) {
|
| 327 |
+
throw reifyTerminated
|
| 328 |
+
}
|
| 329 |
+
} catch (er) {
|
| 330 |
+
// TODO rollbacks shouldn't be relied on to throw err
|
| 331 |
+
await this[rollback](er)
|
| 332 |
+
/* istanbul ignore next - rollback throws, should never hit this */
|
| 333 |
+
throw er
|
| 334 |
+
}
|
| 335 |
+
}
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
// no rollback for this one, just exit with the error, since the
|
| 339 |
+
// install completed and can't be safely recovered at this point.
|
| 340 |
+
await this[_removeTrash]()
|
| 341 |
+
if (reifyTerminated) {
|
| 342 |
+
throw reifyTerminated
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
// done modifying the file system, no need to keep listening for sigs
|
| 346 |
+
removeHandler()
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
// when doing a local install, we load everything and figure it all out.
|
| 350 |
+
// when doing a global install, we *only* care about the explicit requests.
|
| 351 |
+
[_loadTrees] (options) {
|
| 352 |
+
const timeEnd = time.start('reify:loadTrees')
|
| 353 |
+
const bitOpt = {
|
| 354 |
+
...options,
|
| 355 |
+
complete: this.options.packageLockOnly || this.options.dryRun,
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
// if we're only writing a package lock, then it doesn't matter what's here
|
| 359 |
+
if (this.options.packageLockOnly) {
|
| 360 |
+
return this.buildIdealTree(bitOpt).then(timeEnd)
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
const actualOpt = this.options.global ? {
|
| 364 |
+
ignoreMissing: true,
|
| 365 |
+
global: true,
|
| 366 |
+
filter: (node, kid) => {
|
| 367 |
+
// if it's not the project root, and we have no explicit requests,
|
| 368 |
+
// then we're already into a nested dep, so we keep it
|
| 369 |
+
if (this.explicitRequests.size === 0 || !node.isProjectRoot) {
|
| 370 |
+
return true
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
// if we added it as an edgeOut, then we want it
|
| 374 |
+
if (this.idealTree.edgesOut.has(kid)) {
|
| 375 |
+
return true
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
// if it's an explicit request, then we want it
|
| 379 |
+
const hasExplicit = [...this.explicitRequests]
|
| 380 |
+
.some(edge => edge.name === kid)
|
| 381 |
+
if (hasExplicit) {
|
| 382 |
+
return true
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
// ignore the rest of the global install folder
|
| 386 |
+
return false
|
| 387 |
+
},
|
| 388 |
+
} : { ignoreMissing: true }
|
| 389 |
+
|
| 390 |
+
if (!this.options.global) {
|
| 391 |
+
return Promise.all([
|
| 392 |
+
this.loadActual(actualOpt),
|
| 393 |
+
this.buildIdealTree(bitOpt),
|
| 394 |
+
]).then(timeEnd)
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
// the global install space tends to have a lot of stuff in it. don't
|
| 398 |
+
// load all of it, just what we care about. we won't be saving a
|
| 399 |
+
// hidden lockfile in there anyway. Note that we have to load ideal
|
| 400 |
+
// BEFORE loading actual, so that the actualOpt can use the
|
| 401 |
+
// explicitRequests which is set during buildIdealTree
|
| 402 |
+
return this.buildIdealTree(bitOpt)
|
| 403 |
+
.then(() => this.loadActual(actualOpt))
|
| 404 |
+
.then(timeEnd)
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
[_diffTrees] () {
|
| 408 |
+
if (this.options.packageLockOnly) {
|
| 409 |
+
return
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
const timeEnd = time.start('reify:diffTrees')
|
| 413 |
+
// XXX if we have an existing diff already, there should be a way
|
| 414 |
+
// to just invalidate the parts that changed, but avoid walking the
|
| 415 |
+
// whole tree again.
|
| 416 |
+
|
| 417 |
+
const includeWorkspaces = this.options.workspacesEnabled
|
| 418 |
+
const includeRootDeps = !includeWorkspaces
|
| 419 |
+
|| this.options.includeWorkspaceRoot && this.options.workspaces.length > 0
|
| 420 |
+
|
| 421 |
+
const filterNodes = []
|
| 422 |
+
if (this.options.global && this.explicitRequests.size) {
|
| 423 |
+
const idealTree = this.idealTree.target
|
| 424 |
+
const actualTree = this.actualTree.target
|
| 425 |
+
// we ONLY are allowed to make changes in the global top-level
|
| 426 |
+
// children where there's an explicit request.
|
| 427 |
+
for (const { name } of this.explicitRequests) {
|
| 428 |
+
const ideal = idealTree.children.get(name)
|
| 429 |
+
if (ideal) {
|
| 430 |
+
filterNodes.push(ideal)
|
| 431 |
+
}
|
| 432 |
+
const actual = actualTree.children.get(name)
|
| 433 |
+
if (actual) {
|
| 434 |
+
filterNodes.push(actual)
|
| 435 |
+
}
|
| 436 |
+
}
|
| 437 |
+
} else {
|
| 438 |
+
if (includeWorkspaces) {
|
| 439 |
+
// add all ws nodes to filterNodes
|
| 440 |
+
for (const ws of this.options.workspaces) {
|
| 441 |
+
const ideal = this.idealTree.children.get(ws)
|
| 442 |
+
if (ideal) {
|
| 443 |
+
filterNodes.push(ideal)
|
| 444 |
+
}
|
| 445 |
+
const actual = this.actualTree.children.get(ws)
|
| 446 |
+
if (actual) {
|
| 447 |
+
filterNodes.push(actual)
|
| 448 |
+
}
|
| 449 |
+
}
|
| 450 |
+
}
|
| 451 |
+
if (includeRootDeps) {
|
| 452 |
+
// add all non-workspace nodes to filterNodes
|
| 453 |
+
for (const tree of [this.idealTree, this.actualTree]) {
|
| 454 |
+
for (const { type, to } of tree.edgesOut.values()) {
|
| 455 |
+
if (type !== 'workspace' && to) {
|
| 456 |
+
filterNodes.push(to)
|
| 457 |
+
}
|
| 458 |
+
}
|
| 459 |
+
}
|
| 460 |
+
}
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
// find all the nodes that need to change between the actual
|
| 464 |
+
// and ideal trees.
|
| 465 |
+
this.diff = Diff.calculate({
|
| 466 |
+
shrinkwrapInflated: this.#shrinkwrapInflated,
|
| 467 |
+
filterNodes,
|
| 468 |
+
actual: this.actualTree,
|
| 469 |
+
ideal: this.idealTree,
|
| 470 |
+
})
|
| 471 |
+
|
| 472 |
+
// we don't have to add 'removed' folders to the trashlist, because
|
| 473 |
+
// they'll be moved aside to a retirement folder, and then the retired
|
| 474 |
+
// folder will be deleted at the end. This is important when we have
|
| 475 |
+
// a folder like FOO being "removed" in favor of a folder like "foo",
|
| 476 |
+
// because if we remove node_modules/FOO on case-insensitive systems,
|
| 477 |
+
// it will remove the dep that we *want* at node_modules/foo.
|
| 478 |
+
|
| 479 |
+
timeEnd()
|
| 480 |
+
}
|
| 481 |
+
|
| 482 |
+
// add the node and all its bins to the list of things to be
|
| 483 |
+
// removed later on in the process. optionally, also mark them
|
| 484 |
+
// as a retired paths, so that we move them out of the way and
|
| 485 |
+
// replace them when rolling back on failure.
|
| 486 |
+
[_addNodeToTrashList] (node, retire = false) {
|
| 487 |
+
const paths = [node.path, ...node.binPaths]
|
| 488 |
+
const moves = this.#retiredPaths
|
| 489 |
+
log.silly('reify', 'mark', retire ? 'retired' : 'deleted', paths)
|
| 490 |
+
for (const path of paths) {
|
| 491 |
+
if (retire) {
|
| 492 |
+
const retired = retirePath(path)
|
| 493 |
+
moves[path] = retired
|
| 494 |
+
this[_trashList].add(retired)
|
| 495 |
+
} else {
|
| 496 |
+
this[_trashList].add(path)
|
| 497 |
+
}
|
| 498 |
+
}
|
| 499 |
+
}
|
| 500 |
+
|
| 501 |
+
// move aside the shallowest nodes in the tree that have to be
|
| 502 |
+
// changed or removed, so that we can rollback if necessary.
|
| 503 |
+
[_retireShallowNodes] () {
|
| 504 |
+
const timeEnd = time.start('reify:retireShallow')
|
| 505 |
+
const moves = this.#retiredPaths = {}
|
| 506 |
+
for (const diff of this.diff.children) {
|
| 507 |
+
if (diff.action === 'CHANGE' || diff.action === 'REMOVE') {
|
| 508 |
+
// we'll have to clean these up at the end, so add them to the list
|
| 509 |
+
this[_addNodeToTrashList](diff.actual, true)
|
| 510 |
+
}
|
| 511 |
+
}
|
| 512 |
+
log.silly('reify', 'moves', moves)
|
| 513 |
+
const movePromises = Object.entries(moves)
|
| 514 |
+
.map(([from, to]) => this[_renamePath](from, to))
|
| 515 |
+
return promiseAllRejectLate(movePromises).then(timeEnd)
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
[_renamePath] (from, to, didMkdirp = false) {
|
| 519 |
+
return moveFile(from, to)
|
| 520 |
+
.catch(er => {
|
| 521 |
+
// Occasionally an expected bin file might not exist in the package,
|
| 522 |
+
// or a shim/symlink might have been moved aside. If we've already
|
| 523 |
+
// handled the most common cause of ENOENT (dir doesn't exist yet),
|
| 524 |
+
// then just ignore any ENOENT.
|
| 525 |
+
if (er.code === 'ENOENT') {
|
| 526 |
+
return didMkdirp ? null : mkdir(dirname(to), { recursive: true }).then(() =>
|
| 527 |
+
this[_renamePath](from, to, true))
|
| 528 |
+
} else if (er.code === 'EEXIST') {
|
| 529 |
+
return rm(to, { recursive: true, force: true }).then(() => moveFile(from, to))
|
| 530 |
+
} else {
|
| 531 |
+
throw er
|
| 532 |
+
}
|
| 533 |
+
})
|
| 534 |
+
}
|
| 535 |
+
|
| 536 |
+
[_rollbackRetireShallowNodes] (er) {
|
| 537 |
+
const timeEnd = time.start('reify:rollback:retireShallow')
|
| 538 |
+
const moves = this.#retiredPaths
|
| 539 |
+
const movePromises = Object.entries(moves)
|
| 540 |
+
.map(([from, to]) => this[_renamePath](to, from))
|
| 541 |
+
return promiseAllRejectLate(movePromises)
|
| 542 |
+
// ignore subsequent rollback errors
|
| 543 |
+
.catch(() => {})
|
| 544 |
+
.then(timeEnd)
|
| 545 |
+
.then(() => {
|
| 546 |
+
throw er
|
| 547 |
+
})
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
// adding to the trash list will skip reifying, and delete them
|
| 551 |
+
// if they are currently in the tree and otherwise untouched.
|
| 552 |
+
[_addOmitsToTrashList] () {
|
| 553 |
+
if (!this.#omitDev && !this.#omitOptional && !this.#omitPeer) {
|
| 554 |
+
return
|
| 555 |
+
}
|
| 556 |
+
|
| 557 |
+
const timeEnd = time.start('reify:trashOmits')
|
| 558 |
+
|
| 559 |
+
for (const node of this.idealTree.inventory.values()) {
|
| 560 |
+
const { top } = node
|
| 561 |
+
|
| 562 |
+
// if the top is not the root or workspace then we do not want to omit it
|
| 563 |
+
if (!top.isProjectRoot && !top.isWorkspace) {
|
| 564 |
+
continue
|
| 565 |
+
}
|
| 566 |
+
|
| 567 |
+
// if a diff filter has been created, then we do not omit the node if the
|
| 568 |
+
// top node is not in that set
|
| 569 |
+
if (this.diff?.filterSet?.size && !this.diff.filterSet.has(top)) {
|
| 570 |
+
continue
|
| 571 |
+
}
|
| 572 |
+
|
| 573 |
+
// omit node if the dep type matches any omit flags that were set
|
| 574 |
+
if (
|
| 575 |
+
node.peer && this.#omitPeer ||
|
| 576 |
+
node.dev && this.#omitDev ||
|
| 577 |
+
node.optional && this.#omitOptional ||
|
| 578 |
+
node.devOptional && this.#omitOptional && this.#omitDev
|
| 579 |
+
) {
|
| 580 |
+
this[_addNodeToTrashList](node)
|
| 581 |
+
}
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
+
timeEnd()
|
| 585 |
+
}
|
| 586 |
+
|
| 587 |
+
[_createSparseTree] () {
|
| 588 |
+
const timeEnd = time.start('reify:createSparse')
|
| 589 |
+
// if we call this fn again, we look for the previous list
|
| 590 |
+
// so that we can avoid making the same directory multiple times
|
| 591 |
+
const leaves = this.diff.leaves
|
| 592 |
+
.filter(diff => {
|
| 593 |
+
return (diff.action === 'ADD' || diff.action === 'CHANGE') &&
|
| 594 |
+
!this.#sparseTreeDirs.has(diff.ideal.path) &&
|
| 595 |
+
!diff.ideal.isLink
|
| 596 |
+
})
|
| 597 |
+
.map(diff => diff.ideal)
|
| 598 |
+
|
| 599 |
+
// we check this in parallel, so guard against multiple attempts to
|
| 600 |
+
// retire the same path at the same time.
|
| 601 |
+
const dirsChecked = new Set()
|
| 602 |
+
return promiseAllRejectLate(leaves.map(async node => {
|
| 603 |
+
for (const d of walkUp(node.path)) {
|
| 604 |
+
if (d === node.top.path) {
|
| 605 |
+
break
|
| 606 |
+
}
|
| 607 |
+
if (dirsChecked.has(d)) {
|
| 608 |
+
continue
|
| 609 |
+
}
|
| 610 |
+
dirsChecked.add(d)
|
| 611 |
+
const st = await lstat(d).catch(() => null)
|
| 612 |
+
// this can happen if we have a link to a package with a name
|
| 613 |
+
// that the filesystem treats as if it is the same thing.
|
| 614 |
+
// would be nice to have conditional istanbul ignores here...
|
| 615 |
+
/* istanbul ignore next - defense in depth */
|
| 616 |
+
if (st && !st.isDirectory()) {
|
| 617 |
+
const retired = retirePath(d)
|
| 618 |
+
this.#retiredPaths[d] = retired
|
| 619 |
+
this[_trashList].add(retired)
|
| 620 |
+
await this[_renamePath](d, retired)
|
| 621 |
+
}
|
| 622 |
+
}
|
| 623 |
+
this.#sparseTreeDirs.add(node.path)
|
| 624 |
+
const made = await mkdir(node.path, { recursive: true })
|
| 625 |
+
// if the directory already exists, made will be undefined. if that's the case
|
| 626 |
+
// we don't want to remove it because we aren't the ones who created it so we
|
| 627 |
+
// omit it from the #sparseTreeRoots
|
| 628 |
+
if (made) {
|
| 629 |
+
this.#sparseTreeRoots.add(made)
|
| 630 |
+
}
|
| 631 |
+
})).then(timeEnd)
|
| 632 |
+
}
|
| 633 |
+
|
| 634 |
+
[_rollbackCreateSparseTree] (er) {
|
| 635 |
+
const timeEnd = time.start('reify:rollback:createSparse')
|
| 636 |
+
// cut the roots of the sparse tree that were created, not the leaves
|
| 637 |
+
const roots = this.#sparseTreeRoots
|
| 638 |
+
// also delete the moves that we retired, so that we can move them back
|
| 639 |
+
const failures = []
|
| 640 |
+
const targets = [...roots, ...Object.keys(this.#retiredPaths)]
|
| 641 |
+
const unlinks = targets
|
| 642 |
+
.map(path => rm(path, { recursive: true, force: true }).catch(er => failures.push([path, er])))
|
| 643 |
+
return promiseAllRejectLate(unlinks).then(() => {
|
| 644 |
+
// eslint-disable-next-line promise/always-return
|
| 645 |
+
if (failures.length) {
|
| 646 |
+
log.warn('cleanup', 'Failed to remove some directories', failures)
|
| 647 |
+
}
|
| 648 |
+
})
|
| 649 |
+
.then(timeEnd)
|
| 650 |
+
.then(() => this[_rollbackRetireShallowNodes](er))
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
// shrinkwrap nodes define their dependency branches with a file, so
|
| 654 |
+
// we need to unpack them, read that shrinkwrap file, and then update
|
| 655 |
+
// the tree by calling loadVirtual with the node as the root.
|
| 656 |
+
[_loadShrinkwrapsAndUpdateTrees] () {
|
| 657 |
+
const seen = this.#shrinkwrapInflated
|
| 658 |
+
const shrinkwraps = this.diff.leaves
|
| 659 |
+
.filter(d => (d.action === 'CHANGE' || d.action === 'ADD' || !d.action) &&
|
| 660 |
+
d.ideal.hasShrinkwrap && !seen.has(d.ideal) &&
|
| 661 |
+
!this[_trashList].has(d.ideal.path))
|
| 662 |
+
|
| 663 |
+
if (!shrinkwraps.length) {
|
| 664 |
+
return
|
| 665 |
+
}
|
| 666 |
+
|
| 667 |
+
const timeEnd = time.start('reify:loadShrinkwraps')
|
| 668 |
+
|
| 669 |
+
const Arborist = this.constructor
|
| 670 |
+
return promiseAllRejectLate(shrinkwraps.map(diff => {
|
| 671 |
+
const node = diff.ideal
|
| 672 |
+
seen.add(node)
|
| 673 |
+
return diff.action ? this[_reifyNode](node) : node
|
| 674 |
+
}))
|
| 675 |
+
.then(nodes => promiseAllRejectLate(nodes.map(node => new Arborist({
|
| 676 |
+
...this.options,
|
| 677 |
+
path: node.path,
|
| 678 |
+
}).loadVirtual({ root: node }))))
|
| 679 |
+
// reload the diff and sparse tree because the ideal tree changed
|
| 680 |
+
.then(() => this[_diffTrees]())
|
| 681 |
+
.then(() => this[_createSparseTree]())
|
| 682 |
+
.then(() => this[_addOmitsToTrashList]())
|
| 683 |
+
.then(() => this[_loadShrinkwrapsAndUpdateTrees]())
|
| 684 |
+
.then(timeEnd)
|
| 685 |
+
}
|
| 686 |
+
|
| 687 |
+
// create a symlink for Links, extract for Nodes
|
| 688 |
+
// return the node object, since we usually want that
|
| 689 |
+
// handle optional dep failures here
|
| 690 |
+
// If node is in trash list, skip it
|
| 691 |
+
// If reifying fails, and the node is optional, add it and its optionalSet
|
| 692 |
+
// to the trash list
|
| 693 |
+
// Always return the node.
|
| 694 |
+
[_reifyNode] (node) {
|
| 695 |
+
if (this[_trashList].has(node.path)) {
|
| 696 |
+
return node
|
| 697 |
+
}
|
| 698 |
+
|
| 699 |
+
const timeEnd = time.start(`reifyNode:${node.location}`)
|
| 700 |
+
this.addTracker('reify', node.name, node.location)
|
| 701 |
+
|
| 702 |
+
const { npmVersion, nodeVersion, cpu, os, libc } = this.options
|
| 703 |
+
const p = Promise.resolve().then(async () => {
|
| 704 |
+
// when we reify an optional node, check the engine and platform
|
| 705 |
+
// first. be sure to ignore the --force and --engine-strict flags,
|
| 706 |
+
// since we always want to skip any optional packages we can't install.
|
| 707 |
+
// these checks throwing will result in a rollback and removal
|
| 708 |
+
// of the mismatches
|
| 709 |
+
// eslint-disable-next-line promise/always-return
|
| 710 |
+
if (node.optional) {
|
| 711 |
+
checkEngine(node.package, npmVersion, nodeVersion, false)
|
| 712 |
+
checkPlatform(node.package, false, { cpu, os, libc })
|
| 713 |
+
}
|
| 714 |
+
await this[_checkBins](node)
|
| 715 |
+
await this.#extractOrLink(node)
|
| 716 |
+
const { _id, deprecated } = node.package
|
| 717 |
+
// The .catch is in _handleOptionalFailure. Not ideal, this should be cleaned up.
|
| 718 |
+
// eslint-disable-next-line promise/always-return
|
| 719 |
+
if (deprecated) {
|
| 720 |
+
log.warn('deprecated', `${_id}: ${deprecated}`)
|
| 721 |
+
}
|
| 722 |
+
})
|
| 723 |
+
|
| 724 |
+
return this[_handleOptionalFailure](node, p)
|
| 725 |
+
.then(() => {
|
| 726 |
+
this.finishTracker('reify', node.name, node.location)
|
| 727 |
+
timeEnd()
|
| 728 |
+
return node
|
| 729 |
+
})
|
| 730 |
+
}
|
| 731 |
+
|
| 732 |
+
// do not allow node_modules to be a symlink
|
| 733 |
+
async #validateNodeModules (nm) {
|
| 734 |
+
if (this.options.force || this.#nmValidated.has(nm)) {
|
| 735 |
+
return
|
| 736 |
+
}
|
| 737 |
+
const st = await lstat(nm).catch(() => null)
|
| 738 |
+
if (!st || st.isDirectory()) {
|
| 739 |
+
this.#nmValidated.add(nm)
|
| 740 |
+
return
|
| 741 |
+
}
|
| 742 |
+
log.warn('reify', 'Removing non-directory', nm)
|
| 743 |
+
await rm(nm, { recursive: true, force: true })
|
| 744 |
+
}
|
| 745 |
+
|
| 746 |
+
async #extractOrLink (node) {
|
| 747 |
+
const nm = resolve(node.parent.path, 'node_modules')
|
| 748 |
+
await this.#validateNodeModules(nm)
|
| 749 |
+
|
| 750 |
+
if (!node.isLink) {
|
| 751 |
+
// in normal cases, node.resolved should *always* be set by now.
|
| 752 |
+
// however, it is possible when a lockfile is damaged, or very old,
|
| 753 |
+
// or in some other race condition bugs in npm v6, that a previously
|
| 754 |
+
// bundled dependency will have just a version, but no resolved value,
|
| 755 |
+
// and no 'bundled: true' setting.
|
| 756 |
+
// Do the best with what we have, or else remove it from the tree
|
| 757 |
+
// entirely, since we can't possibly reify it.
|
| 758 |
+
let res = null
|
| 759 |
+
if (node.resolved) {
|
| 760 |
+
const registryResolved = this.#registryResolved(node.resolved)
|
| 761 |
+
if (registryResolved) {
|
| 762 |
+
res = `${node.name}@${registryResolved}`
|
| 763 |
+
}
|
| 764 |
+
} else if (node.package.name && node.version) {
|
| 765 |
+
res = `${node.package.name}@${node.version}`
|
| 766 |
+
}
|
| 767 |
+
|
| 768 |
+
// no idea what this thing is. remove it from the tree.
|
| 769 |
+
if (!res) {
|
| 770 |
+
const warning = 'invalid or damaged lockfile detected\n' +
|
| 771 |
+
'please re-try this operation once it completes\n' +
|
| 772 |
+
'so that the damage can be corrected, or perform\n' +
|
| 773 |
+
'a fresh install with no lockfile if the problem persists.'
|
| 774 |
+
log.warn('reify', warning)
|
| 775 |
+
log.verbose('reify', 'unrecognized node in tree', node.path)
|
| 776 |
+
node.parent = null
|
| 777 |
+
node.fsParent = null
|
| 778 |
+
this[_addNodeToTrashList](node)
|
| 779 |
+
return
|
| 780 |
+
}
|
| 781 |
+
await debug(async () => {
|
| 782 |
+
const st = await lstat(node.path).catch(() => null)
|
| 783 |
+
if (st && !st.isDirectory()) {
|
| 784 |
+
debug.log('unpacking into a non-directory', node)
|
| 785 |
+
throw Object.assign(new Error('ENOTDIR: not a directory'), {
|
| 786 |
+
code: 'ENOTDIR',
|
| 787 |
+
path: node.path,
|
| 788 |
+
})
|
| 789 |
+
}
|
| 790 |
+
})
|
| 791 |
+
await pacote.extract(res, node.path, {
|
| 792 |
+
...this.options,
|
| 793 |
+
resolved: node.resolved,
|
| 794 |
+
integrity: node.integrity,
|
| 795 |
+
})
|
| 796 |
+
// store nodes don't use Node class so node.package doesn't get updated
|
| 797 |
+
if (node.isInStore) {
|
| 798 |
+
const pkg = await rpj(join(node.path, 'package.json'))
|
| 799 |
+
node.package.scripts = pkg.scripts
|
| 800 |
+
}
|
| 801 |
+
return
|
| 802 |
+
}
|
| 803 |
+
|
| 804 |
+
// node.isLink
|
| 805 |
+
await rm(node.path, { recursive: true, force: true })
|
| 806 |
+
|
| 807 |
+
// symlink
|
| 808 |
+
const dir = dirname(node.path)
|
| 809 |
+
const target = node.realpath
|
| 810 |
+
const rel = relative(dir, target)
|
| 811 |
+
await mkdir(dir, { recursive: true })
|
| 812 |
+
return symlink(rel, node.path, 'junction')
|
| 813 |
+
}
|
| 814 |
+
|
| 815 |
+
// if the node is optional, then the failure of the promise is nonfatal
|
| 816 |
+
// just add it and its optional set to the trash list.
|
| 817 |
+
[_handleOptionalFailure] (node, p) {
|
| 818 |
+
return (node.optional ? p.catch(() => {
|
| 819 |
+
const set = optionalSet(node)
|
| 820 |
+
for (node of set) {
|
| 821 |
+
log.verbose('reify', 'failed optional dependency', node.path)
|
| 822 |
+
this[_addNodeToTrashList](node)
|
| 823 |
+
}
|
| 824 |
+
}) : p).then(() => node)
|
| 825 |
+
}
|
| 826 |
+
|
| 827 |
+
#registryResolved (resolved) {
|
| 828 |
+
// the default registry url is a magic value meaning "the currently
|
| 829 |
+
// configured registry".
|
| 830 |
+
// `resolved` must never be falsey.
|
| 831 |
+
//
|
| 832 |
+
// XXX: use a magic string that isn't also a valid value, like
|
| 833 |
+
// ${REGISTRY} or something. This has to be threaded through the
|
| 834 |
+
// Shrinkwrap and Node classes carefully, so for now, just treat
|
| 835 |
+
// the default reg as the magical animal that it has been.
|
| 836 |
+
const resolvedURL = hgi.parseUrl(resolved)
|
| 837 |
+
|
| 838 |
+
if (!resolvedURL) {
|
| 839 |
+
// if we could not parse the url at all then returning nothing
|
| 840 |
+
// here means it will get removed from the tree in the next step
|
| 841 |
+
return
|
| 842 |
+
}
|
| 843 |
+
|
| 844 |
+
if ((this.options.replaceRegistryHost === resolvedURL.hostname)
|
| 845 |
+
|| this.options.replaceRegistryHost === 'always') {
|
| 846 |
+
// this.registry always has a trailing slash
|
| 847 |
+
return `${this.registry.slice(0, -1)}${resolvedURL.pathname}${resolvedURL.searchParams}`
|
| 848 |
+
}
|
| 849 |
+
|
| 850 |
+
return resolved
|
| 851 |
+
}
|
| 852 |
+
|
| 853 |
+
// bundles are *sort of* like shrinkwraps, in that the branch is defined
|
| 854 |
+
// by the contents of the package. however, in their case, rather than
|
| 855 |
+
// shipping a virtual tree that must be reified, they ship an entire
|
| 856 |
+
// reified actual tree that must be unpacked and not modified.
|
| 857 |
+
[_loadBundlesAndUpdateTrees] (depth = 0, bundlesByDepth) {
|
| 858 |
+
let maxBundleDepth
|
| 859 |
+
if (!bundlesByDepth) {
|
| 860 |
+
bundlesByDepth = new Map()
|
| 861 |
+
maxBundleDepth = -1
|
| 862 |
+
dfwalk({
|
| 863 |
+
tree: this.diff,
|
| 864 |
+
visit: diff => {
|
| 865 |
+
const node = diff.ideal
|
| 866 |
+
if (!node) {
|
| 867 |
+
return
|
| 868 |
+
}
|
| 869 |
+
if (node.isProjectRoot) {
|
| 870 |
+
return
|
| 871 |
+
}
|
| 872 |
+
|
| 873 |
+
const { bundleDependencies } = node.package
|
| 874 |
+
if (bundleDependencies && bundleDependencies.length) {
|
| 875 |
+
maxBundleDepth = Math.max(maxBundleDepth, node.depth)
|
| 876 |
+
if (!bundlesByDepth.has(node.depth)) {
|
| 877 |
+
bundlesByDepth.set(node.depth, [node])
|
| 878 |
+
} else {
|
| 879 |
+
bundlesByDepth.get(node.depth).push(node)
|
| 880 |
+
}
|
| 881 |
+
}
|
| 882 |
+
},
|
| 883 |
+
getChildren: diff => diff.children,
|
| 884 |
+
})
|
| 885 |
+
|
| 886 |
+
bundlesByDepth.set('maxBundleDepth', maxBundleDepth)
|
| 887 |
+
} else {
|
| 888 |
+
maxBundleDepth = bundlesByDepth.get('maxBundleDepth')
|
| 889 |
+
}
|
| 890 |
+
|
| 891 |
+
if (depth === 0) {
|
| 892 |
+
time.start('reify:loadBundles')
|
| 893 |
+
}
|
| 894 |
+
|
| 895 |
+
if (depth > maxBundleDepth) {
|
| 896 |
+
// if we did something, then prune the tree and update the diffs
|
| 897 |
+
if (maxBundleDepth !== -1) {
|
| 898 |
+
this.#pruneBundledMetadeps(bundlesByDepth)
|
| 899 |
+
this[_diffTrees]()
|
| 900 |
+
}
|
| 901 |
+
time.end('reify:loadBundles')
|
| 902 |
+
return
|
| 903 |
+
}
|
| 904 |
+
|
| 905 |
+
// skip any that have since been removed from the tree, eg by a
|
| 906 |
+
// shallower bundle overwriting them with a bundled meta-dep.
|
| 907 |
+
const set = (bundlesByDepth.get(depth) || [])
|
| 908 |
+
.filter(node => node.root === this.idealTree &&
|
| 909 |
+
node.target !== node.root &&
|
| 910 |
+
!this[_trashList].has(node.path))
|
| 911 |
+
|
| 912 |
+
if (!set.length) {
|
| 913 |
+
return this[_loadBundlesAndUpdateTrees](depth + 1, bundlesByDepth)
|
| 914 |
+
}
|
| 915 |
+
|
| 916 |
+
// extract all the nodes with bundles
|
| 917 |
+
return promiseCallLimit(set.map(node => {
|
| 918 |
+
return () => {
|
| 919 |
+
this.#bundleUnpacked.add(node)
|
| 920 |
+
return this[_reifyNode](node)
|
| 921 |
+
}
|
| 922 |
+
}), { rejectLate: true })
|
| 923 |
+
// then load their unpacked children and move into the ideal tree
|
| 924 |
+
.then(nodes =>
|
| 925 |
+
promiseAllRejectLate(nodes.map(async node => {
|
| 926 |
+
const arb = new this.constructor({
|
| 927 |
+
...this.options,
|
| 928 |
+
path: node.path,
|
| 929 |
+
})
|
| 930 |
+
const notTransplanted = new Set(node.children.keys())
|
| 931 |
+
await arb.loadActual({
|
| 932 |
+
root: node,
|
| 933 |
+
// don't transplant any sparse folders we created
|
| 934 |
+
// loadActual will set node.package to {} for empty directories
|
| 935 |
+
// if by chance there are some empty folders in the node_modules
|
| 936 |
+
// tree for some other reason, then ok, ignore those too.
|
| 937 |
+
transplantFilter: node => {
|
| 938 |
+
if (node.package._id) {
|
| 939 |
+
// it's actually in the bundle if it gets transplanted
|
| 940 |
+
notTransplanted.delete(node.name)
|
| 941 |
+
return true
|
| 942 |
+
} else {
|
| 943 |
+
return false
|
| 944 |
+
}
|
| 945 |
+
},
|
| 946 |
+
})
|
| 947 |
+
for (const name of notTransplanted) {
|
| 948 |
+
this.#bundleMissing.add(node.children.get(name))
|
| 949 |
+
}
|
| 950 |
+
})))
|
| 951 |
+
// move onto the next level of bundled items
|
| 952 |
+
.then(() => this[_loadBundlesAndUpdateTrees](depth + 1, bundlesByDepth))
|
| 953 |
+
}
|
| 954 |
+
|
| 955 |
+
// https://github.com/npm/cli/issues/1597#issuecomment-667639545
|
| 956 |
+
#pruneBundledMetadeps (bundlesByDepth) {
|
| 957 |
+
const bundleShadowed = new Set()
|
| 958 |
+
|
| 959 |
+
// Example dep graph:
|
| 960 |
+
// root -> (a, c)
|
| 961 |
+
// a -> BUNDLE(b)
|
| 962 |
+
// b -> c
|
| 963 |
+
// c -> b
|
| 964 |
+
//
|
| 965 |
+
// package tree:
|
| 966 |
+
// root
|
| 967 |
+
// +-- a
|
| 968 |
+
// | +-- b(1)
|
| 969 |
+
// | +-- c(1)
|
| 970 |
+
// +-- b(2)
|
| 971 |
+
// +-- c(2)
|
| 972 |
+
// 1. mark everything that's shadowed by anything in the bundle. This
|
| 973 |
+
// marks b(2) and c(2).
|
| 974 |
+
// 2. anything with edgesIn from outside the set, mark not-extraneous,
|
| 975 |
+
// remove from set. This unmarks c(2).
|
| 976 |
+
// 3. continue until no change
|
| 977 |
+
// 4. remove everything in the set from the tree. b(2) is pruned
|
| 978 |
+
|
| 979 |
+
// create the list of nodes shadowed by children of bundlers
|
| 980 |
+
for (const bundles of bundlesByDepth.values()) {
|
| 981 |
+
// skip the 'maxBundleDepth' item
|
| 982 |
+
if (!Array.isArray(bundles)) {
|
| 983 |
+
continue
|
| 984 |
+
}
|
| 985 |
+
for (const node of bundles) {
|
| 986 |
+
for (const name of node.children.keys()) {
|
| 987 |
+
const shadow = node.parent.resolve(name)
|
| 988 |
+
if (!shadow) {
|
| 989 |
+
continue
|
| 990 |
+
}
|
| 991 |
+
bundleShadowed.add(shadow)
|
| 992 |
+
shadow.extraneous = true
|
| 993 |
+
}
|
| 994 |
+
}
|
| 995 |
+
}
|
| 996 |
+
|
| 997 |
+
// lib -> (a@1.x) BUNDLE(a@1.2.3 (b@1.2.3))
|
| 998 |
+
// a@1.2.3 -> (b@1.2.3)
|
| 999 |
+
// a@1.3.0 -> (b@2)
|
| 1000 |
+
// b@1.2.3 -> ()
|
| 1001 |
+
// b@2 -> (c@2)
|
| 1002 |
+
//
|
| 1003 |
+
// root
|
| 1004 |
+
// +-- lib
|
| 1005 |
+
// | +-- a@1.2.3
|
| 1006 |
+
// | +-- b@1.2.3
|
| 1007 |
+
// +-- b@2 <-- shadowed, now extraneous
|
| 1008 |
+
// +-- c@2 <-- also shadowed, because only dependent is shadowed
|
| 1009 |
+
for (const shadow of bundleShadowed) {
|
| 1010 |
+
for (const shadDep of shadow.edgesOut.values()) {
|
| 1011 |
+
/* istanbul ignore else - pretty unusual situation, just being
|
| 1012 |
+
* defensive here. Would mean that a bundled dep has a dependency
|
| 1013 |
+
* that is unmet. which, weird, but if you bundle it, we take
|
| 1014 |
+
* whatever you put there and assume the publisher knows best. */
|
| 1015 |
+
if (shadDep.to) {
|
| 1016 |
+
bundleShadowed.add(shadDep.to)
|
| 1017 |
+
shadDep.to.extraneous = true
|
| 1018 |
+
}
|
| 1019 |
+
}
|
| 1020 |
+
}
|
| 1021 |
+
|
| 1022 |
+
let changed
|
| 1023 |
+
do {
|
| 1024 |
+
changed = false
|
| 1025 |
+
for (const shadow of bundleShadowed) {
|
| 1026 |
+
for (const edge of shadow.edgesIn) {
|
| 1027 |
+
if (!bundleShadowed.has(edge.from)) {
|
| 1028 |
+
shadow.extraneous = false
|
| 1029 |
+
bundleShadowed.delete(shadow)
|
| 1030 |
+
changed = true
|
| 1031 |
+
break
|
| 1032 |
+
}
|
| 1033 |
+
}
|
| 1034 |
+
}
|
| 1035 |
+
} while (changed)
|
| 1036 |
+
|
| 1037 |
+
for (const shadow of bundleShadowed) {
|
| 1038 |
+
this[_addNodeToTrashList](shadow)
|
| 1039 |
+
shadow.root = null
|
| 1040 |
+
}
|
| 1041 |
+
}
|
| 1042 |
+
|
| 1043 |
+
async [_submitQuickAudit] () {
|
| 1044 |
+
if (this.options.audit === false) {
|
| 1045 |
+
this.auditReport = null
|
| 1046 |
+
return
|
| 1047 |
+
}
|
| 1048 |
+
|
| 1049 |
+
// we submit the quick audit at this point in the process, as soon as
|
| 1050 |
+
// we have all the deps resolved, so that it can overlap with the other
|
| 1051 |
+
// actions as much as possible. Stash the promise, which we resolve
|
| 1052 |
+
// before finishing the reify() and returning the tree. Thus, we do
|
| 1053 |
+
// NOT return the promise, as the intent is for this to run in parallel
|
| 1054 |
+
// with the reification, and be resolved at a later time.
|
| 1055 |
+
const timeEnd = time.start('reify:audit')
|
| 1056 |
+
const options = { ...this.options }
|
| 1057 |
+
const tree = this.idealTree
|
| 1058 |
+
|
| 1059 |
+
// if we're operating on a workspace, only audit the workspace deps
|
| 1060 |
+
if (this.options.workspaces.length) {
|
| 1061 |
+
options.filterSet = this.workspaceDependencySet(
|
| 1062 |
+
tree,
|
| 1063 |
+
this.options.workspaces,
|
| 1064 |
+
this.options.includeWorkspaceRoot
|
| 1065 |
+
)
|
| 1066 |
+
}
|
| 1067 |
+
|
| 1068 |
+
this.auditReport = AuditReport.load(tree, options).then(res => {
|
| 1069 |
+
timeEnd()
|
| 1070 |
+
return res
|
| 1071 |
+
})
|
| 1072 |
+
}
|
| 1073 |
+
|
| 1074 |
+
// ok! actually unpack stuff into their target locations!
|
| 1075 |
+
// The sparse tree has already been created, so we walk the diff
|
| 1076 |
+
// kicking off each unpack job. If any fail, we rm the sparse
|
| 1077 |
+
// tree entirely and try to put everything back where it was.
|
| 1078 |
+
[_unpackNewModules] () {
|
| 1079 |
+
const timeEnd = time.start('reify:unpack')
|
| 1080 |
+
const unpacks = []
|
| 1081 |
+
dfwalk({
|
| 1082 |
+
tree: this.diff,
|
| 1083 |
+
visit: diff => {
|
| 1084 |
+
// no unpacking if we don't want to change this thing
|
| 1085 |
+
if (diff.action !== 'CHANGE' && diff.action !== 'ADD') {
|
| 1086 |
+
return
|
| 1087 |
+
}
|
| 1088 |
+
|
| 1089 |
+
const node = diff.ideal
|
| 1090 |
+
const bd = this.#bundleUnpacked.has(node)
|
| 1091 |
+
const sw = this.#shrinkwrapInflated.has(node)
|
| 1092 |
+
const bundleMissing = this.#bundleMissing.has(node)
|
| 1093 |
+
|
| 1094 |
+
// check whether we still need to unpack this one.
|
| 1095 |
+
// test the inDepBundle last, since that's potentially a tree walk.
|
| 1096 |
+
const doUnpack = node && // can't unpack if removed!
|
| 1097 |
+
// root node already exists
|
| 1098 |
+
!node.isRoot &&
|
| 1099 |
+
// already unpacked to read bundle
|
| 1100 |
+
!bd &&
|
| 1101 |
+
// already unpacked to read sw
|
| 1102 |
+
!sw &&
|
| 1103 |
+
// already unpacked by another dep's bundle
|
| 1104 |
+
(bundleMissing || !node.inDepBundle)
|
| 1105 |
+
|
| 1106 |
+
if (doUnpack) {
|
| 1107 |
+
unpacks.push(this[_reifyNode](node))
|
| 1108 |
+
}
|
| 1109 |
+
},
|
| 1110 |
+
getChildren: diff => diff.children,
|
| 1111 |
+
})
|
| 1112 |
+
return promiseAllRejectLate(unpacks).then(timeEnd)
|
| 1113 |
+
}
|
| 1114 |
+
|
| 1115 |
+
// This is the part where we move back the unchanging nodes that were
|
| 1116 |
+
// the children of a node that did change. If this fails, the rollback
|
| 1117 |
+
// is a three-step process. First, we try to move the retired unchanged
|
| 1118 |
+
// nodes BACK to their retirement folders, then delete the sparse tree,
|
| 1119 |
+
// then move everything out of retirement.
|
| 1120 |
+
[_moveBackRetiredUnchanged] () {
|
| 1121 |
+
// get a list of all unchanging children of any shallow retired nodes
|
| 1122 |
+
// if they are not the ancestor of any node in the diff set, then the
|
| 1123 |
+
// directory won't already exist, so just rename it over.
|
| 1124 |
+
// This is sort of an inverse diff tree, of all the nodes where
|
| 1125 |
+
// the actualTree and idealTree _don't_ differ, starting from the
|
| 1126 |
+
// shallowest nodes that we moved aside in the first place.
|
| 1127 |
+
const timeEnd = time.start('reify:unretire')
|
| 1128 |
+
const moves = this.#retiredPaths
|
| 1129 |
+
this.#retiredUnchanged = {}
|
| 1130 |
+
return promiseAllRejectLate(this.diff.children.map(diff => {
|
| 1131 |
+
// skip if nothing was retired
|
| 1132 |
+
if (diff.action !== 'CHANGE' && diff.action !== 'REMOVE') {
|
| 1133 |
+
return
|
| 1134 |
+
}
|
| 1135 |
+
|
| 1136 |
+
const { path: realFolder } = diff.actual
|
| 1137 |
+
const retireFolder = moves[realFolder]
|
| 1138 |
+
/* istanbul ignore next - should be impossible */
|
| 1139 |
+
debug(() => {
|
| 1140 |
+
if (!retireFolder) {
|
| 1141 |
+
const er = new Error('trying to un-retire but not retired')
|
| 1142 |
+
throw Object.assign(er, {
|
| 1143 |
+
realFolder,
|
| 1144 |
+
retireFolder,
|
| 1145 |
+
actual: diff.actual,
|
| 1146 |
+
ideal: diff.ideal,
|
| 1147 |
+
action: diff.action,
|
| 1148 |
+
})
|
| 1149 |
+
}
|
| 1150 |
+
})
|
| 1151 |
+
|
| 1152 |
+
this.#retiredUnchanged[retireFolder] = []
|
| 1153 |
+
return promiseAllRejectLate(diff.unchanged.map(node => {
|
| 1154 |
+
// no need to roll back links, since we'll just delete them anyway
|
| 1155 |
+
if (node.isLink) {
|
| 1156 |
+
return mkdir(dirname(node.path), { recursive: true, force: true })
|
| 1157 |
+
.then(() => this[_reifyNode](node))
|
| 1158 |
+
}
|
| 1159 |
+
|
| 1160 |
+
// will have been moved/unpacked along with bundler
|
| 1161 |
+
if (node.inDepBundle && !this.#bundleMissing.has(node)) {
|
| 1162 |
+
return
|
| 1163 |
+
}
|
| 1164 |
+
|
| 1165 |
+
this.#retiredUnchanged[retireFolder].push(node)
|
| 1166 |
+
|
| 1167 |
+
const rel = relative(realFolder, node.path)
|
| 1168 |
+
const fromPath = resolve(retireFolder, rel)
|
| 1169 |
+
// if it has bundleDependencies, then make node_modules. otherwise
|
| 1170 |
+
// skip it.
|
| 1171 |
+
const bd = node.package.bundleDependencies
|
| 1172 |
+
const dir = bd && bd.length ? node.path + '/node_modules' : node.path
|
| 1173 |
+
return mkdir(dir, { recursive: true }).then(() => this[_moveContents](node, fromPath))
|
| 1174 |
+
}))
|
| 1175 |
+
})).then(timeEnd)
|
| 1176 |
+
}
|
| 1177 |
+
|
| 1178 |
+
// move the contents from the fromPath to the node.path
|
| 1179 |
+
[_moveContents] (node, fromPath) {
|
| 1180 |
+
return packageContents({
|
| 1181 |
+
path: fromPath,
|
| 1182 |
+
depth: 1,
|
| 1183 |
+
packageJsonCache: new Map([[fromPath + '/package.json', node.package]]),
|
| 1184 |
+
}).then(res => promiseAllRejectLate(res.map(path => {
|
| 1185 |
+
const rel = relative(fromPath, path)
|
| 1186 |
+
const to = resolve(node.path, rel)
|
| 1187 |
+
return this[_renamePath](path, to)
|
| 1188 |
+
})))
|
| 1189 |
+
}
|
| 1190 |
+
|
| 1191 |
+
[_rollbackMoveBackRetiredUnchanged] (er) {
|
| 1192 |
+
const moves = this.#retiredPaths
|
| 1193 |
+
// flip the mapping around to go back
|
| 1194 |
+
const realFolders = new Map(Object.entries(moves).map(([k, v]) => [v, k]))
|
| 1195 |
+
const promises = Object.entries(this.#retiredUnchanged)
|
| 1196 |
+
.map(([retireFolder, nodes]) => promiseAllRejectLate(nodes.map(node => {
|
| 1197 |
+
const realFolder = realFolders.get(retireFolder)
|
| 1198 |
+
const rel = relative(realFolder, node.path)
|
| 1199 |
+
const fromPath = resolve(retireFolder, rel)
|
| 1200 |
+
return this[_moveContents]({ ...node, path: fromPath }, node.path)
|
| 1201 |
+
})))
|
| 1202 |
+
return promiseAllRejectLate(promises)
|
| 1203 |
+
.then(() => this[_rollbackCreateSparseTree](er))
|
| 1204 |
+
}
|
| 1205 |
+
|
| 1206 |
+
[_build] () {
|
| 1207 |
+
const timeEnd = time.start('reify:build')
|
| 1208 |
+
|
| 1209 |
+
// for all the things being installed, run their appropriate scripts
|
| 1210 |
+
// run in tip->root order, so as to be more likely to build a node's
|
| 1211 |
+
// deps before attempting to build it itself
|
| 1212 |
+
const nodes = []
|
| 1213 |
+
dfwalk({
|
| 1214 |
+
tree: this.diff,
|
| 1215 |
+
leave: diff => {
|
| 1216 |
+
if (!diff.ideal.isProjectRoot) {
|
| 1217 |
+
nodes.push(diff.ideal)
|
| 1218 |
+
}
|
| 1219 |
+
},
|
| 1220 |
+
// process adds before changes, ignore removals
|
| 1221 |
+
getChildren: diff => diff && diff.children,
|
| 1222 |
+
filter: diff => diff.action === 'ADD' || diff.action === 'CHANGE',
|
| 1223 |
+
})
|
| 1224 |
+
|
| 1225 |
+
// pick up link nodes from the unchanged list as we want to run their
|
| 1226 |
+
// scripts in every install despite of having a diff status change
|
| 1227 |
+
for (const node of this.diff.unchanged) {
|
| 1228 |
+
const tree = node.root.target
|
| 1229 |
+
|
| 1230 |
+
// skip links that only live within node_modules as they are most
|
| 1231 |
+
// likely managed by packages we installed, we only want to rebuild
|
| 1232 |
+
// unchanged links we directly manage
|
| 1233 |
+
const linkedFromRoot = node.parent === tree || node.target.fsTop === tree
|
| 1234 |
+
if (node.isLink && linkedFromRoot) {
|
| 1235 |
+
nodes.push(node)
|
| 1236 |
+
}
|
| 1237 |
+
}
|
| 1238 |
+
|
| 1239 |
+
return this.rebuild({ nodes, handleOptionalFailure: true }).then(timeEnd)
|
| 1240 |
+
}
|
| 1241 |
+
|
| 1242 |
+
// the tree is pretty much built now, so it's cleanup time.
|
| 1243 |
+
// remove the retired folders, and any deleted nodes
|
| 1244 |
+
// If this fails, there isn't much we can do but tell the user about it.
|
| 1245 |
+
// Thankfully, it's pretty unlikely that it'll fail, since rm is a node builtin.
|
| 1246 |
+
async [_removeTrash] () {
|
| 1247 |
+
const timeEnd = time.start('reify:trash')
|
| 1248 |
+
const promises = []
|
| 1249 |
+
const failures = []
|
| 1250 |
+
const _rm = path => rm(path, { recursive: true, force: true }).catch(er => failures.push([path, er]))
|
| 1251 |
+
|
| 1252 |
+
for (const path of this[_trashList]) {
|
| 1253 |
+
promises.push(_rm(path))
|
| 1254 |
+
}
|
| 1255 |
+
|
| 1256 |
+
await promiseAllRejectLate(promises)
|
| 1257 |
+
if (failures.length) {
|
| 1258 |
+
log.warn('cleanup', 'Failed to remove some directories', failures)
|
| 1259 |
+
}
|
| 1260 |
+
|
| 1261 |
+
timeEnd()
|
| 1262 |
+
}
|
| 1263 |
+
|
| 1264 |
+
// last but not least, we save the ideal tree metadata to the package-lock
|
| 1265 |
+
// or shrinkwrap file, and any additions or removals to package.json
|
| 1266 |
+
async [_saveIdealTree] (options) {
|
| 1267 |
+
// the ideal tree is actualized now, hooray!
|
| 1268 |
+
// it still contains all the references to optional nodes that were removed
|
| 1269 |
+
// for install failures. Those still end up in the shrinkwrap, so we
|
| 1270 |
+
// save it first, then prune out the optional trash, and then return it.
|
| 1271 |
+
|
| 1272 |
+
const save = !(options.save === false)
|
| 1273 |
+
|
| 1274 |
+
// we check for updates in order to make sure we run save ideal tree
|
| 1275 |
+
// even though save=false since we want `npm update` to be able to
|
| 1276 |
+
// write to package-lock files by default
|
| 1277 |
+
const hasUpdates = this[_updateAll] || this[_updateNames].length
|
| 1278 |
+
|
| 1279 |
+
// we're going to completely skip save ideal tree in case of a global or
|
| 1280 |
+
// dry-run install and also if the save option is set to false, EXCEPT for
|
| 1281 |
+
// update since the expected behavior for npm7+ is for update to
|
| 1282 |
+
// NOT save to package.json, we make that exception since we still want
|
| 1283 |
+
// saveIdealTree to be able to write the lockfile by default.
|
| 1284 |
+
const saveIdealTree = !(
|
| 1285 |
+
(!save && !hasUpdates)
|
| 1286 |
+
|| this.options.global
|
| 1287 |
+
|| this.options.dryRun
|
| 1288 |
+
)
|
| 1289 |
+
|
| 1290 |
+
if (!saveIdealTree) {
|
| 1291 |
+
return false
|
| 1292 |
+
}
|
| 1293 |
+
|
| 1294 |
+
const timeEnd = time.start('reify:save')
|
| 1295 |
+
|
| 1296 |
+
const updatedTrees = new Set()
|
| 1297 |
+
const updateNodes = nodes => {
|
| 1298 |
+
for (const { name, tree: addTree } of nodes) {
|
| 1299 |
+
// addTree either the root, or a workspace
|
| 1300 |
+
const edge = addTree.edgesOut.get(name)
|
| 1301 |
+
const pkg = addTree.package
|
| 1302 |
+
const req = npa.resolve(name, edge.spec, addTree.realpath)
|
| 1303 |
+
const { rawSpec, subSpec } = req
|
| 1304 |
+
|
| 1305 |
+
const spec = subSpec ? subSpec.rawSpec : rawSpec
|
| 1306 |
+
const child = edge.to
|
| 1307 |
+
|
| 1308 |
+
// if we tried to install an optional dep, but it was a version
|
| 1309 |
+
// that we couldn't resolve, this MAY be missing. if we haven't
|
| 1310 |
+
// blown up by now, it's because it was not a problem, though, so
|
| 1311 |
+
// just move on.
|
| 1312 |
+
if (!child || !addTree.isTop) {
|
| 1313 |
+
continue
|
| 1314 |
+
}
|
| 1315 |
+
|
| 1316 |
+
let newSpec
|
| 1317 |
+
// True if the dependency is getting installed from a local file path
|
| 1318 |
+
// In this case it is not possible to do the normal version comparisons
|
| 1319 |
+
// as the new version will be a file path
|
| 1320 |
+
const isLocalDep = req.type === 'directory' || req.type === 'file'
|
| 1321 |
+
if (req.registry) {
|
| 1322 |
+
const version = child.version
|
| 1323 |
+
const prefixRange = version ? this.options.savePrefix + version : '*'
|
| 1324 |
+
// if we installed a range, then we save the range specified
|
| 1325 |
+
// if it is not a subset of the ^x.y.z. eg, installing a range
|
| 1326 |
+
// of `1.x <1.2.3` will not be saved as `^1.2.0`, because that
|
| 1327 |
+
// would allow versions outside the requested range. Tags and
|
| 1328 |
+
// specific versions save with the save-prefix.
|
| 1329 |
+
const isRange = (subSpec || req).type === 'range'
|
| 1330 |
+
|
| 1331 |
+
let range = spec
|
| 1332 |
+
if (
|
| 1333 |
+
!isRange ||
|
| 1334 |
+
spec === '*' ||
|
| 1335 |
+
subset(prefixRange, spec, { loose: true })
|
| 1336 |
+
) {
|
| 1337 |
+
range = prefixRange
|
| 1338 |
+
}
|
| 1339 |
+
|
| 1340 |
+
const pname = child.packageName
|
| 1341 |
+
const alias = name !== pname
|
| 1342 |
+
newSpec = alias ? `npm:${pname}@${range}` : range
|
| 1343 |
+
} else if (req.hosted) {
|
| 1344 |
+
// save the git+https url if it has auth, otherwise shortcut
|
| 1345 |
+
const h = req.hosted
|
| 1346 |
+
const opt = { noCommittish: false }
|
| 1347 |
+
if (h.https && h.auth) {
|
| 1348 |
+
newSpec = `git+${h.https(opt)}`
|
| 1349 |
+
} else {
|
| 1350 |
+
newSpec = h.shortcut(opt)
|
| 1351 |
+
}
|
| 1352 |
+
} else if (isLocalDep) {
|
| 1353 |
+
// when finding workspace nodes, make sure that
|
| 1354 |
+
// we save them using their version instead of
|
| 1355 |
+
// using their relative path
|
| 1356 |
+
if (edge.type === 'workspace') {
|
| 1357 |
+
const { version } = edge.to.target
|
| 1358 |
+
const prefixRange = version ? this.options.savePrefix + version : '*'
|
| 1359 |
+
newSpec = prefixRange
|
| 1360 |
+
} else {
|
| 1361 |
+
// save the relative path in package.json
|
| 1362 |
+
// Normally saveSpec is updated with the proper relative
|
| 1363 |
+
// path already, but it's possible to specify a full absolute
|
| 1364 |
+
// path initially, in which case we can end up with the wrong
|
| 1365 |
+
// thing, so just get the ultimate fetchSpec and relativize it.
|
| 1366 |
+
const p = req.fetchSpec.replace(/^file:/, '')
|
| 1367 |
+
const rel = relpath(addTree.realpath, p)
|
| 1368 |
+
newSpec = `file:${rel}`
|
| 1369 |
+
}
|
| 1370 |
+
} else {
|
| 1371 |
+
newSpec = req.saveSpec
|
| 1372 |
+
}
|
| 1373 |
+
|
| 1374 |
+
if (options.saveType) {
|
| 1375 |
+
const depType = saveTypeMap.get(options.saveType)
|
| 1376 |
+
pkg[depType][name] = newSpec
|
| 1377 |
+
// rpj will have moved it here if it was in both
|
| 1378 |
+
// if it is empty it will be deleted later
|
| 1379 |
+
if (options.saveType === 'prod' && pkg.optionalDependencies) {
|
| 1380 |
+
delete pkg.optionalDependencies[name]
|
| 1381 |
+
}
|
| 1382 |
+
} else {
|
| 1383 |
+
if (hasSubKey(pkg, 'dependencies', name)) {
|
| 1384 |
+
pkg.dependencies[name] = newSpec
|
| 1385 |
+
}
|
| 1386 |
+
|
| 1387 |
+
if (hasSubKey(pkg, 'devDependencies', name)) {
|
| 1388 |
+
pkg.devDependencies[name] = newSpec
|
| 1389 |
+
// don't update peer or optional if we don't have to
|
| 1390 |
+
if (hasSubKey(pkg, 'peerDependencies', name) && (isLocalDep || !intersects(newSpec, pkg.peerDependencies[name]))) {
|
| 1391 |
+
pkg.peerDependencies[name] = newSpec
|
| 1392 |
+
}
|
| 1393 |
+
|
| 1394 |
+
if (hasSubKey(pkg, 'optionalDependencies', name) && (isLocalDep || !intersects(newSpec, pkg.optionalDependencies[name]))) {
|
| 1395 |
+
pkg.optionalDependencies[name] = newSpec
|
| 1396 |
+
}
|
| 1397 |
+
} else {
|
| 1398 |
+
if (hasSubKey(pkg, 'peerDependencies', name)) {
|
| 1399 |
+
pkg.peerDependencies[name] = newSpec
|
| 1400 |
+
}
|
| 1401 |
+
|
| 1402 |
+
if (hasSubKey(pkg, 'optionalDependencies', name)) {
|
| 1403 |
+
pkg.optionalDependencies[name] = newSpec
|
| 1404 |
+
}
|
| 1405 |
+
}
|
| 1406 |
+
}
|
| 1407 |
+
|
| 1408 |
+
updatedTrees.add(addTree)
|
| 1409 |
+
}
|
| 1410 |
+
}
|
| 1411 |
+
|
| 1412 |
+
// Returns true if any of the edges from this node has a semver
|
| 1413 |
+
// range definition that is an exact match to the version installed
|
| 1414 |
+
// e.g: should return true if for a given an installed version 1.0.0,
|
| 1415 |
+
// range is either =1.0.0 or 1.0.0
|
| 1416 |
+
const exactVersion = node => {
|
| 1417 |
+
for (const edge of node.edgesIn) {
|
| 1418 |
+
try {
|
| 1419 |
+
if (semver.subset(edge.spec, node.version)) {
|
| 1420 |
+
return false
|
| 1421 |
+
}
|
| 1422 |
+
} catch {
|
| 1423 |
+
// ignore errors
|
| 1424 |
+
}
|
| 1425 |
+
}
|
| 1426 |
+
return true
|
| 1427 |
+
}
|
| 1428 |
+
|
| 1429 |
+
// helper that retrieves an array of nodes that were
|
| 1430 |
+
// potentially updated during the reify process, in order
|
| 1431 |
+
// to limit the number of nodes to check and update, only
|
| 1432 |
+
// select nodes from the inventory that are direct deps
|
| 1433 |
+
// of a given package.json (project root or a workspace)
|
| 1434 |
+
// and in ase of using a list of `names`, restrict nodes
|
| 1435 |
+
// to only names that are found in this list
|
| 1436 |
+
const retrieveUpdatedNodes = names => {
|
| 1437 |
+
const filterDirectDependencies = node =>
|
| 1438 |
+
!node.isRoot && node.resolveParent && node.resolveParent.isRoot
|
| 1439 |
+
&& (!names || names.includes(node.name))
|
| 1440 |
+
&& exactVersion(node) // skip update for exact ranges
|
| 1441 |
+
|
| 1442 |
+
const directDeps = this.idealTree.inventory
|
| 1443 |
+
.filter(filterDirectDependencies)
|
| 1444 |
+
|
| 1445 |
+
// traverses the list of direct dependencies and collect all nodes
|
| 1446 |
+
// to be updated, since any of them might have changed during reify
|
| 1447 |
+
const nodes = []
|
| 1448 |
+
for (const node of directDeps) {
|
| 1449 |
+
for (const edgeIn of node.edgesIn) {
|
| 1450 |
+
nodes.push({
|
| 1451 |
+
name: node.name,
|
| 1452 |
+
tree: edgeIn.from.target,
|
| 1453 |
+
})
|
| 1454 |
+
}
|
| 1455 |
+
}
|
| 1456 |
+
return nodes
|
| 1457 |
+
}
|
| 1458 |
+
|
| 1459 |
+
if (save) {
|
| 1460 |
+
// when using update all alongside with save, we'll make
|
| 1461 |
+
// sure to refresh every dependency of the root idealTree
|
| 1462 |
+
if (this[_updateAll]) {
|
| 1463 |
+
const nodes = retrieveUpdatedNodes()
|
| 1464 |
+
updateNodes(nodes)
|
| 1465 |
+
} else {
|
| 1466 |
+
// resolvedAdd is the list of user add requests, but with names added
|
| 1467 |
+
// to things like git repos and tarball file/urls. However, if the
|
| 1468 |
+
// user requested 'foo@', and we have a foo@file:../foo, then we should
|
| 1469 |
+
// end up saving the spec we actually used, not whatever they gave us.
|
| 1470 |
+
if (this[_resolvedAdd].length) {
|
| 1471 |
+
updateNodes(this[_resolvedAdd])
|
| 1472 |
+
}
|
| 1473 |
+
|
| 1474 |
+
// if updating given dependencies by name, restrict the list of
|
| 1475 |
+
// nodes to check to only those currently in _updateNames
|
| 1476 |
+
if (this[_updateNames].length) {
|
| 1477 |
+
const nodes = retrieveUpdatedNodes(this[_updateNames])
|
| 1478 |
+
updateNodes(nodes)
|
| 1479 |
+
}
|
| 1480 |
+
|
| 1481 |
+
// grab any from explicitRequests that had deps removed
|
| 1482 |
+
for (const { from: tree } of this.explicitRequests) {
|
| 1483 |
+
updatedTrees.add(tree)
|
| 1484 |
+
}
|
| 1485 |
+
}
|
| 1486 |
+
}
|
| 1487 |
+
|
| 1488 |
+
if (save) {
|
| 1489 |
+
for (const tree of updatedTrees) {
|
| 1490 |
+
// refresh the edges so they have the correct specs
|
| 1491 |
+
tree.package = tree.package
|
| 1492 |
+
const pkgJson = await PackageJson.load(tree.path, { create: true })
|
| 1493 |
+
const {
|
| 1494 |
+
dependencies = {},
|
| 1495 |
+
devDependencies = {},
|
| 1496 |
+
optionalDependencies = {},
|
| 1497 |
+
peerDependencies = {},
|
| 1498 |
+
// bundleDependencies is not required by PackageJson like the other
|
| 1499 |
+
// fields here PackageJson also doesn't omit an empty array for this
|
| 1500 |
+
// field so defaulting this to an empty array would add that field to
|
| 1501 |
+
// every package.json file.
|
| 1502 |
+
bundleDependencies,
|
| 1503 |
+
} = tree.package
|
| 1504 |
+
|
| 1505 |
+
pkgJson.update({
|
| 1506 |
+
dependencies,
|
| 1507 |
+
devDependencies,
|
| 1508 |
+
optionalDependencies,
|
| 1509 |
+
peerDependencies,
|
| 1510 |
+
bundleDependencies,
|
| 1511 |
+
})
|
| 1512 |
+
await pkgJson.save()
|
| 1513 |
+
}
|
| 1514 |
+
}
|
| 1515 |
+
|
| 1516 |
+
// before now edge specs could be changing, affecting the `requires` field
|
| 1517 |
+
// in the package lock, so we hold off saving to the very last action
|
| 1518 |
+
if (this[_usePackageLock]) {
|
| 1519 |
+
// preserve indentation, if possible
|
| 1520 |
+
let format = this.idealTree.package[Symbol.for('indent')]
|
| 1521 |
+
if (format === undefined) {
|
| 1522 |
+
format = ' '
|
| 1523 |
+
}
|
| 1524 |
+
|
| 1525 |
+
// TODO this ignores options.save
|
| 1526 |
+
await this.idealTree.meta.save({
|
| 1527 |
+
format: (this.options.formatPackageLock && format) ? format
|
| 1528 |
+
: this.options.formatPackageLock,
|
| 1529 |
+
})
|
| 1530 |
+
}
|
| 1531 |
+
|
| 1532 |
+
timeEnd()
|
| 1533 |
+
return true
|
| 1534 |
+
}
|
| 1535 |
+
}
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/audit-report.js
ADDED
|
@@ -0,0 +1,415 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// an object representing the set of vulnerabilities in a tree
|
| 2 |
+
/* eslint camelcase: "off" */
|
| 3 |
+
|
| 4 |
+
const localeCompare = require('@isaacs/string-locale-compare')('en')
|
| 5 |
+
const npa = require('npm-package-arg')
|
| 6 |
+
const pickManifest = require('npm-pick-manifest')
|
| 7 |
+
|
| 8 |
+
const Vuln = require('./vuln.js')
|
| 9 |
+
const Calculator = require('@npmcli/metavuln-calculator')
|
| 10 |
+
|
| 11 |
+
const _getReport = Symbol('getReport')
|
| 12 |
+
const _fixAvailable = Symbol('fixAvailable')
|
| 13 |
+
const _checkTopNode = Symbol('checkTopNode')
|
| 14 |
+
const _init = Symbol('init')
|
| 15 |
+
const _omit = Symbol('omit')
|
| 16 |
+
const { log, time } = require('proc-log')
|
| 17 |
+
|
| 18 |
+
const fetch = require('npm-registry-fetch')
|
| 19 |
+
|
| 20 |
+
class AuditReport extends Map {
|
| 21 |
+
static load (tree, opts) {
|
| 22 |
+
return new AuditReport(tree, opts).run()
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
get auditReportVersion () {
|
| 26 |
+
return 2
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
toJSON () {
|
| 30 |
+
const obj = {
|
| 31 |
+
auditReportVersion: this.auditReportVersion,
|
| 32 |
+
vulnerabilities: {},
|
| 33 |
+
metadata: {
|
| 34 |
+
vulnerabilities: {
|
| 35 |
+
info: 0,
|
| 36 |
+
low: 0,
|
| 37 |
+
moderate: 0,
|
| 38 |
+
high: 0,
|
| 39 |
+
critical: 0,
|
| 40 |
+
total: this.size,
|
| 41 |
+
},
|
| 42 |
+
dependencies: {
|
| 43 |
+
prod: 0,
|
| 44 |
+
dev: 0,
|
| 45 |
+
optional: 0,
|
| 46 |
+
peer: 0,
|
| 47 |
+
peerOptional: 0,
|
| 48 |
+
total: this.tree.inventory.size - 1,
|
| 49 |
+
},
|
| 50 |
+
},
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
for (const node of this.tree.inventory.values()) {
|
| 54 |
+
const { dependencies } = obj.metadata
|
| 55 |
+
let prod = true
|
| 56 |
+
for (const type of [
|
| 57 |
+
'dev',
|
| 58 |
+
'optional',
|
| 59 |
+
'peer',
|
| 60 |
+
'peerOptional',
|
| 61 |
+
]) {
|
| 62 |
+
if (node[type]) {
|
| 63 |
+
dependencies[type]++
|
| 64 |
+
prod = false
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
if (prod) {
|
| 68 |
+
dependencies.prod++
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
// if it doesn't have any topVulns, then it's fixable with audit fix
|
| 73 |
+
// for each topVuln, figure out if it's fixable with audit fix --force,
|
| 74 |
+
// or if we have to just delete the thing, and if the fix --force will
|
| 75 |
+
// require a semver major update.
|
| 76 |
+
const vulnerabilities = []
|
| 77 |
+
for (const [name, vuln] of this.entries()) {
|
| 78 |
+
vulnerabilities.push([name, vuln.toJSON()])
|
| 79 |
+
obj.metadata.vulnerabilities[vuln.severity]++
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
obj.vulnerabilities = vulnerabilities
|
| 83 |
+
.sort(([a], [b]) => localeCompare(a, b))
|
| 84 |
+
.reduce((set, [name, vuln]) => {
|
| 85 |
+
set[name] = vuln
|
| 86 |
+
return set
|
| 87 |
+
}, {})
|
| 88 |
+
|
| 89 |
+
return obj
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
constructor (tree, opts = {}) {
|
| 93 |
+
super()
|
| 94 |
+
const { omit } = opts
|
| 95 |
+
this[_omit] = new Set(omit || [])
|
| 96 |
+
this.topVulns = new Map()
|
| 97 |
+
|
| 98 |
+
this.calculator = new Calculator(opts)
|
| 99 |
+
this.error = null
|
| 100 |
+
this.options = opts
|
| 101 |
+
this.tree = tree
|
| 102 |
+
this.filterSet = opts.filterSet
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
async run () {
|
| 106 |
+
this.report = await this[_getReport]()
|
| 107 |
+
log.silly('audit report', this.report)
|
| 108 |
+
if (this.report) {
|
| 109 |
+
await this[_init]()
|
| 110 |
+
}
|
| 111 |
+
return this
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
isVulnerable (node) {
|
| 115 |
+
const vuln = this.get(node.packageName)
|
| 116 |
+
return !!(vuln && vuln.isVulnerable(node))
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
async [_init] () {
|
| 120 |
+
const timeEnd = time.start('auditReport:init')
|
| 121 |
+
|
| 122 |
+
const promises = []
|
| 123 |
+
for (const [name, advisories] of Object.entries(this.report)) {
|
| 124 |
+
for (const advisory of advisories) {
|
| 125 |
+
promises.push(this.calculator.calculate(name, advisory))
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
// now the advisories are calculated with a set of versions
|
| 130 |
+
// and the packument. turn them into our style of vuln objects
|
| 131 |
+
// which also have the affected nodes, and also create entries
|
| 132 |
+
// for all the metavulns that we find from dependents.
|
| 133 |
+
const advisories = new Set(await Promise.all(promises))
|
| 134 |
+
const seen = new Set()
|
| 135 |
+
for (const advisory of advisories) {
|
| 136 |
+
const { name, range } = advisory
|
| 137 |
+
const k = `${name}@${range}`
|
| 138 |
+
|
| 139 |
+
const vuln = this.get(name) || new Vuln({ name, advisory })
|
| 140 |
+
if (this.has(name)) {
|
| 141 |
+
vuln.addAdvisory(advisory)
|
| 142 |
+
}
|
| 143 |
+
super.set(name, vuln)
|
| 144 |
+
|
| 145 |
+
// don't flag the exact same name/range more than once
|
| 146 |
+
// adding multiple advisories with the same range is fine, but no
|
| 147 |
+
// need to search for nodes we already would have added.
|
| 148 |
+
if (!seen.has(k)) {
|
| 149 |
+
const p = []
|
| 150 |
+
for (const node of this.tree.inventory.query('packageName', name)) {
|
| 151 |
+
if (!shouldAudit(node, this[_omit], this.filterSet)) {
|
| 152 |
+
continue
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
// if not vulnerable by this advisory, keep searching
|
| 156 |
+
if (!advisory.testVersion(node.version)) {
|
| 157 |
+
continue
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
// we will have loaded the source already if this is a metavuln
|
| 161 |
+
if (advisory.type === 'metavuln') {
|
| 162 |
+
vuln.addVia(this.get(advisory.dependency))
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
// already marked this one, no need to do it again
|
| 166 |
+
if (vuln.nodes.has(node)) {
|
| 167 |
+
continue
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
// haven't marked this one yet. get its dependents.
|
| 171 |
+
vuln.nodes.add(node)
|
| 172 |
+
for (const { from: dep, spec } of node.edgesIn) {
|
| 173 |
+
if (dep.isTop && !vuln.topNodes.has(dep)) {
|
| 174 |
+
this[_checkTopNode](dep, vuln, spec)
|
| 175 |
+
} else {
|
| 176 |
+
// calculate a metavuln, if necessary
|
| 177 |
+
const calc = this.calculator.calculate(dep.packageName, advisory)
|
| 178 |
+
// eslint-disable-next-line promise/always-return
|
| 179 |
+
p.push(calc.then(meta => {
|
| 180 |
+
// eslint-disable-next-line promise/always-return
|
| 181 |
+
if (meta.testVersion(dep.version, spec)) {
|
| 182 |
+
advisories.add(meta)
|
| 183 |
+
}
|
| 184 |
+
}))
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
await Promise.all(p)
|
| 189 |
+
seen.add(k)
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
// make sure we actually got something. if not, remove it
|
| 193 |
+
// this can happen if you are loading from a lockfile created by
|
| 194 |
+
// npm v5, since it lists the current version of all deps,
|
| 195 |
+
// rather than the range that is actually depended upon,
|
| 196 |
+
// or if using --omit with the older audit endpoint.
|
| 197 |
+
if (this.get(name).nodes.size === 0) {
|
| 198 |
+
this.delete(name)
|
| 199 |
+
continue
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
// if the vuln is valid, but THIS advisory doesn't apply to any of
|
| 203 |
+
// the nodes it references, then remove it from the advisory list.
|
| 204 |
+
// happens when using omit with old audit endpoint.
|
| 205 |
+
for (const advisory of vuln.advisories) {
|
| 206 |
+
const relevant = [...vuln.nodes]
|
| 207 |
+
.some(n => advisory.testVersion(n.version))
|
| 208 |
+
if (!relevant) {
|
| 209 |
+
vuln.deleteAdvisory(advisory)
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
timeEnd()
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
[_checkTopNode] (topNode, vuln, spec) {
|
| 218 |
+
vuln.fixAvailable = this[_fixAvailable](topNode, vuln, spec)
|
| 219 |
+
|
| 220 |
+
if (vuln.fixAvailable !== true) {
|
| 221 |
+
// now we know the top node is vulnerable, and cannot be
|
| 222 |
+
// upgraded out of the bad place without --force. But, there's
|
| 223 |
+
// no need to add it to the actual vulns list, because nothing
|
| 224 |
+
// depends on root.
|
| 225 |
+
this.topVulns.set(vuln.name, vuln)
|
| 226 |
+
vuln.topNodes.add(topNode)
|
| 227 |
+
}
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
// check whether the top node is vulnerable.
|
| 231 |
+
// check whether we can get out of the bad place with --force, and if
|
| 232 |
+
// so, whether that update is SemVer Major
|
| 233 |
+
[_fixAvailable] (topNode, vuln, spec) {
|
| 234 |
+
// this will always be set to at least {name, versions:{}}
|
| 235 |
+
const paku = vuln.packument
|
| 236 |
+
|
| 237 |
+
if (!vuln.testSpec(spec)) {
|
| 238 |
+
return true
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
// similarly, even if we HAVE a packument, but we're looking for it
|
| 242 |
+
// somewhere other than the registry, and we got something vulnerable,
|
| 243 |
+
// then we're stuck with it.
|
| 244 |
+
const specObj = npa(spec)
|
| 245 |
+
if (!specObj.registry) {
|
| 246 |
+
return false
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
if (specObj.subSpec) {
|
| 250 |
+
spec = specObj.subSpec.rawSpec
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
// We don't provide fixes for top nodes other than root, but we
|
| 254 |
+
// still check to see if the node is fixable with a different version,
|
| 255 |
+
// and if that is a semver major bump.
|
| 256 |
+
try {
|
| 257 |
+
const {
|
| 258 |
+
_isSemVerMajor: isSemVerMajor,
|
| 259 |
+
version,
|
| 260 |
+
name,
|
| 261 |
+
} = pickManifest(paku, spec, {
|
| 262 |
+
...this.options,
|
| 263 |
+
before: null,
|
| 264 |
+
avoid: vuln.range,
|
| 265 |
+
avoidStrict: true,
|
| 266 |
+
})
|
| 267 |
+
return { name, version, isSemVerMajor }
|
| 268 |
+
} catch (er) {
|
| 269 |
+
return false
|
| 270 |
+
}
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
set () {
|
| 274 |
+
throw new Error('do not call AuditReport.set() directly')
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
// convert a quick-audit into a bulk advisory listing
|
| 278 |
+
static auditToBulk (report) {
|
| 279 |
+
if (!report.advisories) {
|
| 280 |
+
// tack on the report json where the response body would go
|
| 281 |
+
throw Object.assign(new Error('Invalid advisory report'), {
|
| 282 |
+
body: JSON.stringify(report),
|
| 283 |
+
})
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
const bulk = {}
|
| 287 |
+
const { advisories } = report
|
| 288 |
+
for (const advisory of Object.values(advisories)) {
|
| 289 |
+
const {
|
| 290 |
+
id,
|
| 291 |
+
url,
|
| 292 |
+
title,
|
| 293 |
+
severity = 'high',
|
| 294 |
+
vulnerable_versions = '*',
|
| 295 |
+
module_name: name,
|
| 296 |
+
} = advisory
|
| 297 |
+
bulk[name] = bulk[name] || []
|
| 298 |
+
bulk[name].push({ id, url, title, severity, vulnerable_versions })
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
return bulk
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
async [_getReport] () {
|
| 305 |
+
// if we're not auditing, just return false
|
| 306 |
+
if (this.options.audit === false || this.options.offline === true || this.tree.inventory.size === 1) {
|
| 307 |
+
return null
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
const timeEnd = time.start('auditReport:getReport')
|
| 311 |
+
try {
|
| 312 |
+
try {
|
| 313 |
+
// first try the super fast bulk advisory listing
|
| 314 |
+
const body = prepareBulkData(this.tree, this[_omit], this.filterSet)
|
| 315 |
+
log.silly('audit', 'bulk request', body)
|
| 316 |
+
|
| 317 |
+
// no sense asking if we don't have anything to audit,
|
| 318 |
+
// we know it'll be empty
|
| 319 |
+
if (!Object.keys(body).length) {
|
| 320 |
+
return null
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
const res = await fetch('/-/npm/v1/security/advisories/bulk', {
|
| 324 |
+
...this.options,
|
| 325 |
+
registry: this.options.auditRegistry || this.options.registry,
|
| 326 |
+
method: 'POST',
|
| 327 |
+
gzip: true,
|
| 328 |
+
body,
|
| 329 |
+
})
|
| 330 |
+
|
| 331 |
+
return await res.json()
|
| 332 |
+
} catch (er) {
|
| 333 |
+
log.silly('audit', 'bulk request failed', String(er.body))
|
| 334 |
+
// that failed, try the quick audit endpoint
|
| 335 |
+
const body = prepareData(this.tree, this.options)
|
| 336 |
+
const res = await fetch('/-/npm/v1/security/audits/quick', {
|
| 337 |
+
...this.options,
|
| 338 |
+
registry: this.options.auditRegistry || this.options.registry,
|
| 339 |
+
method: 'POST',
|
| 340 |
+
gzip: true,
|
| 341 |
+
body,
|
| 342 |
+
})
|
| 343 |
+
return AuditReport.auditToBulk(await res.json())
|
| 344 |
+
}
|
| 345 |
+
} catch (er) {
|
| 346 |
+
log.verbose('audit error', er)
|
| 347 |
+
log.silly('audit error', String(er.body))
|
| 348 |
+
this.error = er
|
| 349 |
+
return null
|
| 350 |
+
} finally {
|
| 351 |
+
timeEnd()
|
| 352 |
+
}
|
| 353 |
+
}
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
// return true if we should audit this one
|
| 357 |
+
const shouldAudit = (node, omit, filterSet) =>
|
| 358 |
+
!node.version ? false
|
| 359 |
+
: node.isRoot ? false
|
| 360 |
+
: filterSet && filterSet.size !== 0 && !filterSet.has(node) ? false
|
| 361 |
+
: omit.size === 0 ? true
|
| 362 |
+
: !( // otherwise, just ensure we're not omitting this one
|
| 363 |
+
node.dev && omit.has('dev') ||
|
| 364 |
+
node.optional && omit.has('optional') ||
|
| 365 |
+
node.devOptional && omit.has('dev') && omit.has('optional') ||
|
| 366 |
+
node.peer && omit.has('peer')
|
| 367 |
+
)
|
| 368 |
+
|
| 369 |
+
const prepareBulkData = (tree, omit, filterSet) => {
|
| 370 |
+
const payload = {}
|
| 371 |
+
for (const name of tree.inventory.query('packageName')) {
|
| 372 |
+
const set = new Set()
|
| 373 |
+
for (const node of tree.inventory.query('packageName', name)) {
|
| 374 |
+
if (!shouldAudit(node, omit, filterSet)) {
|
| 375 |
+
continue
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
set.add(node.version)
|
| 379 |
+
}
|
| 380 |
+
if (set.size) {
|
| 381 |
+
payload[name] = [...set]
|
| 382 |
+
}
|
| 383 |
+
}
|
| 384 |
+
return payload
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
const prepareData = (tree, opts) => {
|
| 388 |
+
const { npmVersion: npm_version } = opts
|
| 389 |
+
const node_version = process.version
|
| 390 |
+
const { platform, arch } = process
|
| 391 |
+
const { NODE_ENV: node_env } = process.env
|
| 392 |
+
const data = tree.meta.commit()
|
| 393 |
+
// the legacy audit endpoint doesn't support any kind of pre-filtering
|
| 394 |
+
// we just have to get the advisories and skip over them in the report
|
| 395 |
+
return {
|
| 396 |
+
name: data.name,
|
| 397 |
+
version: data.version,
|
| 398 |
+
requires: {
|
| 399 |
+
...(tree.package.devDependencies || {}),
|
| 400 |
+
...(tree.package.peerDependencies || {}),
|
| 401 |
+
...(tree.package.optionalDependencies || {}),
|
| 402 |
+
...(tree.package.dependencies || {}),
|
| 403 |
+
},
|
| 404 |
+
dependencies: data.dependencies,
|
| 405 |
+
metadata: {
|
| 406 |
+
node_version,
|
| 407 |
+
npm_version,
|
| 408 |
+
platform,
|
| 409 |
+
arch,
|
| 410 |
+
node_env,
|
| 411 |
+
},
|
| 412 |
+
}
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
module.exports = AuditReport
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/calc-dep-flags.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const { depth } = require('treeverse')
|
| 2 |
+
|
| 3 |
+
const calcDepFlags = (tree, resetRoot = true) => {
|
| 4 |
+
if (resetRoot) {
|
| 5 |
+
tree.dev = false
|
| 6 |
+
tree.optional = false
|
| 7 |
+
tree.devOptional = false
|
| 8 |
+
tree.peer = false
|
| 9 |
+
}
|
| 10 |
+
const ret = depth({
|
| 11 |
+
tree,
|
| 12 |
+
visit: node => calcDepFlagsStep(node),
|
| 13 |
+
filter: node => node,
|
| 14 |
+
getChildren: (node, tree) =>
|
| 15 |
+
[...tree.edgesOut.values()].map(edge => edge.to),
|
| 16 |
+
})
|
| 17 |
+
return ret
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
const calcDepFlagsStep = (node) => {
|
| 21 |
+
// This rewalk is necessary to handle cases where devDep and optional
|
| 22 |
+
// or normal dependency graphs overlap deep in the dep graph.
|
| 23 |
+
// Since we're only walking through deps that are not already flagged
|
| 24 |
+
// as non-dev/non-optional, it's typically a very shallow traversal
|
| 25 |
+
node.extraneous = false
|
| 26 |
+
resetParents(node, 'extraneous')
|
| 27 |
+
resetParents(node, 'dev')
|
| 28 |
+
resetParents(node, 'peer')
|
| 29 |
+
resetParents(node, 'devOptional')
|
| 30 |
+
resetParents(node, 'optional')
|
| 31 |
+
|
| 32 |
+
// for links, map their hierarchy appropriately
|
| 33 |
+
if (node.isLink) {
|
| 34 |
+
// node.target can be null, we check to ensure it's not null before proceeding
|
| 35 |
+
if (node.target == null) {
|
| 36 |
+
return node
|
| 37 |
+
}
|
| 38 |
+
node.target.dev = node.dev
|
| 39 |
+
node.target.optional = node.optional
|
| 40 |
+
node.target.devOptional = node.devOptional
|
| 41 |
+
node.target.peer = node.peer
|
| 42 |
+
return calcDepFlagsStep(node.target)
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
node.edgesOut.forEach(({ peer, optional, dev, to }) => {
|
| 46 |
+
// if the dep is missing, then its flags are already maximally unset
|
| 47 |
+
if (!to) {
|
| 48 |
+
return
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
// everything with any kind of edge into it is not extraneous
|
| 52 |
+
to.extraneous = false
|
| 53 |
+
|
| 54 |
+
// devOptional is the *overlap* of the dev and optional tree.
|
| 55 |
+
// however, for convenience and to save an extra rewalk, we leave
|
| 56 |
+
// it set when we are in *either* tree, and then omit it from the
|
| 57 |
+
// package-lock if either dev or optional are set.
|
| 58 |
+
const unsetDevOpt = !node.devOptional && !node.dev && !node.optional && !dev && !optional
|
| 59 |
+
|
| 60 |
+
// if we are not in the devOpt tree, then we're also not in
|
| 61 |
+
// either the dev or opt trees
|
| 62 |
+
const unsetDev = unsetDevOpt || !node.dev && !dev
|
| 63 |
+
const unsetOpt = unsetDevOpt || !node.optional && !optional
|
| 64 |
+
const unsetPeer = !node.peer && !peer
|
| 65 |
+
|
| 66 |
+
if (unsetPeer) {
|
| 67 |
+
unsetFlag(to, 'peer')
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
if (unsetDevOpt) {
|
| 71 |
+
unsetFlag(to, 'devOptional')
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
if (unsetDev) {
|
| 75 |
+
unsetFlag(to, 'dev')
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
if (unsetOpt) {
|
| 79 |
+
unsetFlag(to, 'optional')
|
| 80 |
+
}
|
| 81 |
+
})
|
| 82 |
+
|
| 83 |
+
return node
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
const resetParents = (node, flag) => {
|
| 87 |
+
if (node[flag]) {
|
| 88 |
+
return
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
for (let p = node; p && (p === node || p[flag]); p = p.resolveParent) {
|
| 92 |
+
p[flag] = false
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
// typically a short walk, since it only traverses deps that have the flag set.
|
| 97 |
+
const unsetFlag = (node, flag) => {
|
| 98 |
+
if (node[flag]) {
|
| 99 |
+
node[flag] = false
|
| 100 |
+
depth({
|
| 101 |
+
tree: node,
|
| 102 |
+
visit: node => {
|
| 103 |
+
node.extraneous = node[flag] = false
|
| 104 |
+
if (node.isLink && node.target) {
|
| 105 |
+
node.target.extraneous = node.target[flag] = false
|
| 106 |
+
}
|
| 107 |
+
},
|
| 108 |
+
getChildren: node => {
|
| 109 |
+
const children = []
|
| 110 |
+
const targetNode = node.isLink && node.target ? node.target : node
|
| 111 |
+
for (const edge of targetNode.edgesOut.values()) {
|
| 112 |
+
if (
|
| 113 |
+
edge.to &&
|
| 114 |
+
edge.to[flag] &&
|
| 115 |
+
((flag !== 'peer' && edge.type === 'peer') || edge.type === 'prod')
|
| 116 |
+
) {
|
| 117 |
+
children.push(edge.to)
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
return children
|
| 121 |
+
},
|
| 122 |
+
})
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
module.exports = calcDepFlags
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/can-place-dep.js
ADDED
|
@@ -0,0 +1,436 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Internal methods used by buildIdealTree.
|
| 2 |
+
// Answer the question: "can I put this dep here?"
|
| 3 |
+
//
|
| 4 |
+
// IMPORTANT: *nothing* in this class should *ever* modify or mutate the tree
|
| 5 |
+
// at all. The contract here is strictly limited to read operations. We call
|
| 6 |
+
// this in the process of walking through the ideal tree checking many
|
| 7 |
+
// different potential placement targets for a given node. If a change is made
|
| 8 |
+
// to the tree along the way, that can cause serious problems!
|
| 9 |
+
//
|
| 10 |
+
// In order to enforce this restriction, in debug mode, canPlaceDep() will
|
| 11 |
+
// snapshot the tree at the start of the process, and then at the end, will
|
| 12 |
+
// verify that it still matches the snapshot, and throw an error if any changes
|
| 13 |
+
// occurred.
|
| 14 |
+
//
|
| 15 |
+
// The algorithm is roughly like this:
|
| 16 |
+
// - check the node itself:
|
| 17 |
+
// - if there is no version present, and no conflicting edges from target,
|
| 18 |
+
// OK, provided all peers can be placed at or above the target.
|
| 19 |
+
// - if the current version matches, KEEP
|
| 20 |
+
// - if there is an older version present, which can be replaced, then
|
| 21 |
+
// - if satisfying and preferDedupe? KEEP
|
| 22 |
+
// - else: REPLACE
|
| 23 |
+
// - if there is a newer version present, and preferDedupe, REPLACE
|
| 24 |
+
// - if the version present satisfies the edge, KEEP
|
| 25 |
+
// - else: CONFLICT
|
| 26 |
+
// - if the node is not in conflict, check each of its peers:
|
| 27 |
+
// - if the peer can be placed in the target, continue
|
| 28 |
+
// - else if the peer can be placed in a parent, and there is no other
|
| 29 |
+
// conflicting version shadowing it, continue
|
| 30 |
+
// - else CONFLICT
|
| 31 |
+
// - If the peers are not in conflict, return the original node's value
|
| 32 |
+
//
|
| 33 |
+
// An exception to this logic is that if the target is the deepest location
|
| 34 |
+
// that a node can be placed, and the conflicting node can be placed deeper,
|
| 35 |
+
// then we will return REPLACE rather than CONFLICT, and Arborist will queue
|
| 36 |
+
// the replaced node for resolution elsewhere.
|
| 37 |
+
|
| 38 |
+
const localeCompare = require('@isaacs/string-locale-compare')('en')
|
| 39 |
+
const semver = require('semver')
|
| 40 |
+
const debug = require('./debug.js')
|
| 41 |
+
const peerEntrySets = require('./peer-entry-sets.js')
|
| 42 |
+
const deepestNestingTarget = require('./deepest-nesting-target.js')
|
| 43 |
+
|
| 44 |
+
const CONFLICT = Symbol('CONFLICT')
|
| 45 |
+
const OK = Symbol('OK')
|
| 46 |
+
const REPLACE = Symbol('REPLACE')
|
| 47 |
+
const KEEP = Symbol('KEEP')
|
| 48 |
+
|
| 49 |
+
class CanPlaceDep {
|
| 50 |
+
// dep is a dep that we're trying to place. it should already live in
|
| 51 |
+
// a virtual tree where its peer set is loaded as children of the root.
|
| 52 |
+
// target is the actual place where we're trying to place this dep
|
| 53 |
+
// in a node_modules folder.
|
| 54 |
+
// edge is the edge that we're trying to satisfy with this placement.
|
| 55 |
+
// parent is the CanPlaceDep object of the entry node when placing a peer.
|
| 56 |
+
constructor (options) {
|
| 57 |
+
const {
|
| 58 |
+
dep,
|
| 59 |
+
target,
|
| 60 |
+
edge,
|
| 61 |
+
preferDedupe,
|
| 62 |
+
parent = null,
|
| 63 |
+
peerPath = [],
|
| 64 |
+
explicitRequest = false,
|
| 65 |
+
} = options
|
| 66 |
+
|
| 67 |
+
debug(() => {
|
| 68 |
+
if (!dep) {
|
| 69 |
+
throw new Error('no dep provided to CanPlaceDep')
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
if (!target) {
|
| 73 |
+
throw new Error('no target provided to CanPlaceDep')
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
if (!edge) {
|
| 77 |
+
throw new Error('no edge provided to CanPlaceDep')
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
this._treeSnapshot = JSON.stringify([...target.root.inventory.entries()]
|
| 81 |
+
.map(([loc, { packageName, version, resolved }]) => {
|
| 82 |
+
return [loc, packageName, version, resolved]
|
| 83 |
+
}).sort(([a], [b]) => localeCompare(a, b)))
|
| 84 |
+
})
|
| 85 |
+
|
| 86 |
+
// the result of whether we can place it or not
|
| 87 |
+
this.canPlace = null
|
| 88 |
+
// if peers conflict, but this one doesn't, then that is useful info
|
| 89 |
+
this.canPlaceSelf = null
|
| 90 |
+
|
| 91 |
+
this.dep = dep
|
| 92 |
+
this.target = target
|
| 93 |
+
this.edge = edge
|
| 94 |
+
this.explicitRequest = explicitRequest
|
| 95 |
+
|
| 96 |
+
// preventing cycles when we check peer sets
|
| 97 |
+
this.peerPath = peerPath
|
| 98 |
+
// we always prefer to dedupe peers, because they are trying
|
| 99 |
+
// a bit harder to be singletons.
|
| 100 |
+
this.preferDedupe = !!preferDedupe || edge.peer
|
| 101 |
+
this.parent = parent
|
| 102 |
+
this.children = []
|
| 103 |
+
|
| 104 |
+
this.isSource = target === this.peerSetSource
|
| 105 |
+
this.name = edge.name
|
| 106 |
+
this.current = target.children.get(this.name)
|
| 107 |
+
this.targetEdge = target.edgesOut.get(this.name)
|
| 108 |
+
this.conflicts = new Map()
|
| 109 |
+
|
| 110 |
+
// check if this dep was already subject to a peerDep override while
|
| 111 |
+
// building the peerSet.
|
| 112 |
+
this.edgeOverride = !dep.satisfies(edge)
|
| 113 |
+
|
| 114 |
+
this.canPlace = this.checkCanPlace()
|
| 115 |
+
if (!this.canPlaceSelf) {
|
| 116 |
+
this.canPlaceSelf = this.canPlace
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
debug(() => {
|
| 120 |
+
const treeSnapshot = JSON.stringify([...target.root.inventory.entries()]
|
| 121 |
+
.map(([loc, { packageName, version, resolved }]) => {
|
| 122 |
+
return [loc, packageName, version, resolved]
|
| 123 |
+
}).sort(([a], [b]) => localeCompare(a, b)))
|
| 124 |
+
/* istanbul ignore if */
|
| 125 |
+
if (this._treeSnapshot !== treeSnapshot) {
|
| 126 |
+
throw Object.assign(new Error('tree changed in CanPlaceDep'), {
|
| 127 |
+
expect: this._treeSnapshot,
|
| 128 |
+
actual: treeSnapshot,
|
| 129 |
+
})
|
| 130 |
+
}
|
| 131 |
+
})
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
checkCanPlace () {
|
| 135 |
+
const { target, targetEdge, current, dep } = this
|
| 136 |
+
|
| 137 |
+
// if the dep failed to load, we're going to fail the build or
|
| 138 |
+
// prune it out anyway, so just move forward placing/replacing it.
|
| 139 |
+
if (dep.errors.length) {
|
| 140 |
+
return current ? REPLACE : OK
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
// cannot place peers inside their dependents, except for tops
|
| 144 |
+
if (targetEdge && targetEdge.peer && !target.isTop) {
|
| 145 |
+
return CONFLICT
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
// skip this test if there's a current node, because we might be able
|
| 149 |
+
// to dedupe against it anyway
|
| 150 |
+
if (!current &&
|
| 151 |
+
targetEdge &&
|
| 152 |
+
!dep.satisfies(targetEdge) &&
|
| 153 |
+
targetEdge !== this.edge) {
|
| 154 |
+
return CONFLICT
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
return current ? this.checkCanPlaceCurrent() : this.checkCanPlaceNoCurrent()
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
// we know that the target has a dep by this name in its node_modules
|
| 161 |
+
// already. Can return KEEP, REPLACE, or CONFLICT.
|
| 162 |
+
checkCanPlaceCurrent () {
|
| 163 |
+
const { preferDedupe, explicitRequest, current, target, edge, dep } = this
|
| 164 |
+
|
| 165 |
+
if (dep.matches(current)) {
|
| 166 |
+
if (current.satisfies(edge) || this.edgeOverride) {
|
| 167 |
+
return explicitRequest ? REPLACE : KEEP
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
const { version: curVer } = current
|
| 172 |
+
const { version: newVer } = dep
|
| 173 |
+
const tryReplace = curVer && newVer && semver.gte(newVer, curVer)
|
| 174 |
+
if (tryReplace && dep.canReplace(current)) {
|
| 175 |
+
// It's extremely rare that a replaceable node would be a conflict, if
|
| 176 |
+
// the current one wasn't a conflict, but it is theoretically possible
|
| 177 |
+
// if peer deps are pinned. In that case we treat it like any other
|
| 178 |
+
// conflict, and keep trying.
|
| 179 |
+
const cpp = this.canPlacePeers(REPLACE)
|
| 180 |
+
if (cpp !== CONFLICT) {
|
| 181 |
+
return cpp
|
| 182 |
+
}
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
// ok, can't replace the current with new one, but maybe current is ok?
|
| 186 |
+
if (current.satisfies(edge) && (!explicitRequest || preferDedupe)) {
|
| 187 |
+
return KEEP
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
// if we prefer deduping, then try replacing newer with older
|
| 191 |
+
if (preferDedupe && !tryReplace && dep.canReplace(current)) {
|
| 192 |
+
const cpp = this.canPlacePeers(REPLACE)
|
| 193 |
+
if (cpp !== CONFLICT) {
|
| 194 |
+
return cpp
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
// Check for interesting cases!
|
| 199 |
+
// First, is this the deepest place that this thing can go, and NOT the
|
| 200 |
+
// deepest place where the conflicting dep can go? If so, replace it,
|
| 201 |
+
// and let it re-resolve deeper in the tree.
|
| 202 |
+
const myDeepest = this.deepestNestingTarget
|
| 203 |
+
|
| 204 |
+
// ok, i COULD be placed deeper, so leave the current one alone.
|
| 205 |
+
if (target !== myDeepest) {
|
| 206 |
+
return CONFLICT
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
// if we are not checking a peerDep, then we MUST place it here, in the
|
| 210 |
+
// target that has a non-peer dep on it.
|
| 211 |
+
if (!edge.peer && target === edge.from) {
|
| 212 |
+
return this.canPlacePeers(REPLACE)
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
// if we aren't placing a peer in a set, then we're done here.
|
| 216 |
+
// This is ignored because it SHOULD be redundant, as far as I can tell,
|
| 217 |
+
// with the deepest target and target===edge.from tests. But until we
|
| 218 |
+
// can prove that isn't possible, this condition is here for safety.
|
| 219 |
+
/* istanbul ignore if - allegedly impossible */
|
| 220 |
+
if (!this.parent && !edge.peer) {
|
| 221 |
+
return CONFLICT
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
// check the deps in the peer group for each edge into that peer group
|
| 225 |
+
// if ALL of them can be pushed deeper, or if it's ok to replace its
|
| 226 |
+
// members with the contents of the new peer group, then we're good.
|
| 227 |
+
let canReplace = true
|
| 228 |
+
for (const [entryEdge, currentPeers] of peerEntrySets(current)) {
|
| 229 |
+
if (entryEdge === this.edge || entryEdge === this.peerEntryEdge) {
|
| 230 |
+
continue
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
// First, see if it's ok to just replace the peerSet entirely.
|
| 234 |
+
// we do this by walking out from the entryEdge, because in a case like
|
| 235 |
+
// this:
|
| 236 |
+
//
|
| 237 |
+
// v -> PEER(a@1||2)
|
| 238 |
+
// a@1 -> PEER(b@1)
|
| 239 |
+
// a@2 -> PEER(b@2)
|
| 240 |
+
// b@1 -> PEER(a@1)
|
| 241 |
+
// b@2 -> PEER(a@2)
|
| 242 |
+
//
|
| 243 |
+
// root
|
| 244 |
+
// +-- v
|
| 245 |
+
// +-- a@2
|
| 246 |
+
// +-- b@2
|
| 247 |
+
//
|
| 248 |
+
// Trying to place a peer group of (a@1, b@1) would fail to note that
|
| 249 |
+
// they can be replaced, if we did it by looping 1 by 1. If we are
|
| 250 |
+
// replacing something, we don't have to check its peer deps, because
|
| 251 |
+
// the peerDeps in the placed peerSet will presumably satisfy.
|
| 252 |
+
const entryNode = entryEdge.to
|
| 253 |
+
const entryRep = dep.parent.children.get(entryNode.name)
|
| 254 |
+
if (entryRep) {
|
| 255 |
+
if (entryRep.canReplace(entryNode, dep.parent.children.keys())) {
|
| 256 |
+
continue
|
| 257 |
+
}
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
let canClobber = !entryRep
|
| 261 |
+
if (!entryRep) {
|
| 262 |
+
const peerReplacementWalk = new Set([entryNode])
|
| 263 |
+
OUTER: for (const currentPeer of peerReplacementWalk) {
|
| 264 |
+
for (const edge of currentPeer.edgesOut.values()) {
|
| 265 |
+
if (!edge.peer || !edge.valid) {
|
| 266 |
+
continue
|
| 267 |
+
}
|
| 268 |
+
const rep = dep.parent.children.get(edge.name)
|
| 269 |
+
if (!rep) {
|
| 270 |
+
if (edge.to) {
|
| 271 |
+
peerReplacementWalk.add(edge.to)
|
| 272 |
+
}
|
| 273 |
+
continue
|
| 274 |
+
}
|
| 275 |
+
if (!rep.satisfies(edge)) {
|
| 276 |
+
canClobber = false
|
| 277 |
+
break OUTER
|
| 278 |
+
}
|
| 279 |
+
}
|
| 280 |
+
}
|
| 281 |
+
}
|
| 282 |
+
if (canClobber) {
|
| 283 |
+
continue
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
// ok, we can't replace, but maybe we can nest the current set deeper?
|
| 287 |
+
let canNestCurrent = true
|
| 288 |
+
for (const currentPeer of currentPeers) {
|
| 289 |
+
if (!canNestCurrent) {
|
| 290 |
+
break
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
// still possible to nest this peerSet
|
| 294 |
+
const curDeep = deepestNestingTarget(entryEdge.from, currentPeer.name)
|
| 295 |
+
if (curDeep === target || target.isDescendantOf(curDeep)) {
|
| 296 |
+
canNestCurrent = false
|
| 297 |
+
canReplace = false
|
| 298 |
+
}
|
| 299 |
+
if (canNestCurrent) {
|
| 300 |
+
continue
|
| 301 |
+
}
|
| 302 |
+
}
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
// if we can nest or replace all the current peer groups, we can replace.
|
| 306 |
+
if (canReplace) {
|
| 307 |
+
return this.canPlacePeers(REPLACE)
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
return CONFLICT
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
checkCanPlaceNoCurrent () {
|
| 314 |
+
const { target, peerEntryEdge, dep, name } = this
|
| 315 |
+
|
| 316 |
+
// check to see what that name resolves to here, and who may depend on
|
| 317 |
+
// being able to reach it by crawling up past the parent. we know
|
| 318 |
+
// that it's not the target's direct child node, and if it was a direct
|
| 319 |
+
// dep of the target, we would have conflicted earlier.
|
| 320 |
+
const current = target !== peerEntryEdge.from && target.resolve(name)
|
| 321 |
+
if (current) {
|
| 322 |
+
for (const edge of current.edgesIn.values()) {
|
| 323 |
+
if (edge.from.isDescendantOf(target) && edge.valid) {
|
| 324 |
+
if (!dep.satisfies(edge)) {
|
| 325 |
+
return CONFLICT
|
| 326 |
+
}
|
| 327 |
+
}
|
| 328 |
+
}
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
// no objections, so this is fine as long as peers are ok here.
|
| 332 |
+
return this.canPlacePeers(OK)
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
get deepestNestingTarget () {
|
| 336 |
+
const start = this.parent ? this.parent.deepestNestingTarget
|
| 337 |
+
: this.edge.from
|
| 338 |
+
return deepestNestingTarget(start, this.name)
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
get conflictChildren () {
|
| 342 |
+
return this.allChildren.filter(c => c.canPlace === CONFLICT)
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
get allChildren () {
|
| 346 |
+
const set = new Set(this.children)
|
| 347 |
+
for (const child of set) {
|
| 348 |
+
for (const grandchild of child.children) {
|
| 349 |
+
set.add(grandchild)
|
| 350 |
+
}
|
| 351 |
+
}
|
| 352 |
+
return [...set]
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
get top () {
|
| 356 |
+
return this.parent ? this.parent.top : this
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
// check if peers can go here. returns state or CONFLICT
|
| 360 |
+
canPlacePeers (state) {
|
| 361 |
+
this.canPlaceSelf = state
|
| 362 |
+
if (this._canPlacePeers) {
|
| 363 |
+
return this._canPlacePeers
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
// TODO: represent peerPath in ERESOLVE error somehow?
|
| 367 |
+
const peerPath = [...this.peerPath, this.dep]
|
| 368 |
+
let sawConflict = false
|
| 369 |
+
for (const peerEdge of this.dep.edgesOut.values()) {
|
| 370 |
+
if (!peerEdge.peer || !peerEdge.to || peerPath.includes(peerEdge.to)) {
|
| 371 |
+
continue
|
| 372 |
+
}
|
| 373 |
+
const peer = peerEdge.to
|
| 374 |
+
// it may be the case that the *initial* dep can be nested, but a peer
|
| 375 |
+
// of that dep needs to be placed shallower, because the target has
|
| 376 |
+
// a peer dep on the peer as well.
|
| 377 |
+
const target = deepestNestingTarget(this.target, peer.name)
|
| 378 |
+
const cpp = new CanPlaceDep({
|
| 379 |
+
dep: peer,
|
| 380 |
+
target,
|
| 381 |
+
parent: this,
|
| 382 |
+
edge: peerEdge,
|
| 383 |
+
peerPath,
|
| 384 |
+
// always place peers in preferDedupe mode
|
| 385 |
+
preferDedupe: true,
|
| 386 |
+
})
|
| 387 |
+
/* istanbul ignore next */
|
| 388 |
+
debug(() => {
|
| 389 |
+
if (this.children.some(c => c.dep === cpp.dep)) {
|
| 390 |
+
throw new Error('checking same dep repeatedly')
|
| 391 |
+
}
|
| 392 |
+
})
|
| 393 |
+
this.children.push(cpp)
|
| 394 |
+
|
| 395 |
+
if (cpp.canPlace === CONFLICT) {
|
| 396 |
+
sawConflict = true
|
| 397 |
+
}
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
this._canPlacePeers = sawConflict ? CONFLICT : state
|
| 401 |
+
return this._canPlacePeers
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
// what is the node that is causing this peerSet to be placed?
|
| 405 |
+
get peerSetSource () {
|
| 406 |
+
return this.parent ? this.parent.peerSetSource : this.edge.from
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
get peerEntryEdge () {
|
| 410 |
+
return this.top.edge
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
static get CONFLICT () {
|
| 414 |
+
return CONFLICT
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
static get OK () {
|
| 418 |
+
return OK
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
static get REPLACE () {
|
| 422 |
+
return REPLACE
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
static get KEEP () {
|
| 426 |
+
return KEEP
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
get description () {
|
| 430 |
+
const { canPlace } = this
|
| 431 |
+
return canPlace && canPlace.description ||
|
| 432 |
+
/* istanbul ignore next - old node affordance */ canPlace
|
| 433 |
+
}
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
module.exports = CanPlaceDep
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/case-insensitive-map.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// package children are represented with a Map object, but many file systems
|
| 2 |
+
// are case-insensitive and unicode-normalizing, so we need to treat
|
| 3 |
+
// node.children.get('FOO') and node.children.get('foo') as the same thing.
|
| 4 |
+
|
| 5 |
+
module.exports = class CIMap extends Map {
|
| 6 |
+
#keys = new Map()
|
| 7 |
+
|
| 8 |
+
constructor (items = []) {
|
| 9 |
+
super()
|
| 10 |
+
for (const [key, val] of items) {
|
| 11 |
+
this.set(key, val)
|
| 12 |
+
}
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
#normKey (key) {
|
| 16 |
+
if (typeof key !== 'string') {
|
| 17 |
+
return key
|
| 18 |
+
}
|
| 19 |
+
return key.normalize('NFKD').toLowerCase()
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
get (key) {
|
| 23 |
+
const normKey = this.#normKey(key)
|
| 24 |
+
return this.#keys.has(normKey) ? super.get(this.#keys.get(normKey))
|
| 25 |
+
: undefined
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
set (key, val) {
|
| 29 |
+
const normKey = this.#normKey(key)
|
| 30 |
+
if (this.#keys.has(normKey)) {
|
| 31 |
+
super.delete(this.#keys.get(normKey))
|
| 32 |
+
}
|
| 33 |
+
this.#keys.set(normKey, key)
|
| 34 |
+
return super.set(key, val)
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
delete (key) {
|
| 38 |
+
const normKey = this.#normKey(key)
|
| 39 |
+
if (this.#keys.has(normKey)) {
|
| 40 |
+
const prevKey = this.#keys.get(normKey)
|
| 41 |
+
this.#keys.delete(normKey)
|
| 42 |
+
return super.delete(prevKey)
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
has (key) {
|
| 47 |
+
const normKey = this.#normKey(key)
|
| 48 |
+
return this.#keys.has(normKey) && super.has(this.#keys.get(normKey))
|
| 49 |
+
}
|
| 50 |
+
}
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/consistent-resolve.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// take a path and a resolved value, and turn it into a resolution from
|
| 2 |
+
// the given new path. This is used with converting a package.json's
|
| 3 |
+
// relative file: path into one suitable for a lockfile, or between
|
| 4 |
+
// lockfiles, and for converting hosted git repos to a consistent url type.
|
| 5 |
+
const npa = require('npm-package-arg')
|
| 6 |
+
const relpath = require('./relpath.js')
|
| 7 |
+
const consistentResolve = (resolved, fromPath, toPath, relPaths = false) => {
|
| 8 |
+
if (!resolved) {
|
| 9 |
+
return null
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
try {
|
| 13 |
+
const hostedOpt = { noCommittish: false }
|
| 14 |
+
const {
|
| 15 |
+
fetchSpec,
|
| 16 |
+
saveSpec,
|
| 17 |
+
type,
|
| 18 |
+
hosted,
|
| 19 |
+
rawSpec,
|
| 20 |
+
raw,
|
| 21 |
+
} = npa(resolved, fromPath)
|
| 22 |
+
if (type === 'file' || type === 'directory') {
|
| 23 |
+
const cleanFetchSpec = fetchSpec
|
| 24 |
+
if (relPaths && toPath) {
|
| 25 |
+
return `file:${relpath(toPath, cleanFetchSpec)}`
|
| 26 |
+
}
|
| 27 |
+
return `file:${cleanFetchSpec}`
|
| 28 |
+
}
|
| 29 |
+
if (hosted) {
|
| 30 |
+
return `git+${hosted.auth ? hosted.https(hostedOpt) : hosted.sshurl(hostedOpt)}`
|
| 31 |
+
}
|
| 32 |
+
if (type === 'git') {
|
| 33 |
+
return saveSpec
|
| 34 |
+
}
|
| 35 |
+
if (rawSpec === '*') {
|
| 36 |
+
return raw
|
| 37 |
+
}
|
| 38 |
+
return rawSpec
|
| 39 |
+
} catch (_) {
|
| 40 |
+
// whatever we passed in was not acceptable to npa.
|
| 41 |
+
// leave it 100% untouched.
|
| 42 |
+
return resolved
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
module.exports = consistentResolve
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/debug.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// certain assertions we should do only when testing arborist itself, because
|
| 2 |
+
// they are too expensive or aggressive and would break user programs if we
|
| 3 |
+
// miss a situation where they are actually valid.
|
| 4 |
+
//
|
| 5 |
+
// call like this:
|
| 6 |
+
//
|
| 7 |
+
// /* istanbul ignore next - debug check */
|
| 8 |
+
// debug(() => {
|
| 9 |
+
// if (someExpensiveCheck)
|
| 10 |
+
// throw new Error('expensive check should have returned false')
|
| 11 |
+
// })
|
| 12 |
+
|
| 13 |
+
// run in debug mode if explicitly requested, running arborist tests,
|
| 14 |
+
// or working in the arborist project directory.
|
| 15 |
+
|
| 16 |
+
const debug = process.env.ARBORIST_DEBUG !== '0' && (
|
| 17 |
+
process.env.ARBORIST_DEBUG === '1' ||
|
| 18 |
+
/\barborist\b/.test(process.env.NODE_DEBUG || '') ||
|
| 19 |
+
process.env.npm_package_name === '@npmcli/arborist' &&
|
| 20 |
+
['test', 'snap'].includes(process.env.npm_lifecycle_event) ||
|
| 21 |
+
process.cwd() === require('node:path').resolve(__dirname, '..')
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
module.exports = debug ? fn => fn() : () => {}
|
| 25 |
+
const red = process.stderr.isTTY ? msg => `\x1B[31m${msg}\x1B[39m` : m => m
|
| 26 |
+
module.exports.log = (...msg) => module.exports(() => {
|
| 27 |
+
const { format } = require('node:util')
|
| 28 |
+
const prefix = `\n${process.pid} ${red(format(msg.shift()))} `
|
| 29 |
+
msg = (prefix + format(...msg).trim().split('\n').join(prefix)).trim()
|
| 30 |
+
/* eslint-disable-next-line no-console */
|
| 31 |
+
console.error(msg)
|
| 32 |
+
})
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/deepest-nesting-target.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// given a starting node, what is the *deepest* target where name could go?
|
| 2 |
+
// This is not on the Node class for the simple reason that we sometimes
|
| 3 |
+
// need to check the deepest *potential* target for a Node that is not yet
|
| 4 |
+
// added to the tree where we are checking.
|
| 5 |
+
const deepestNestingTarget = (start, name) => {
|
| 6 |
+
for (const target of start.ancestry()) {
|
| 7 |
+
// note: this will skip past the first target if edge is peer
|
| 8 |
+
if (target.isProjectRoot || !target.resolveParent || target.globalTop) {
|
| 9 |
+
return target
|
| 10 |
+
}
|
| 11 |
+
const targetEdge = target.edgesOut.get(name)
|
| 12 |
+
if (!targetEdge || !targetEdge.peer) {
|
| 13 |
+
return target
|
| 14 |
+
}
|
| 15 |
+
}
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
module.exports = deepestNestingTarget
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/dep-valid.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Do not rely on package._fields, so that we don't throw
|
| 2 |
+
// false failures if a tree is generated by other clients.
|
| 3 |
+
// Only relies on child.resolved, which MAY come from
|
| 4 |
+
// client-specific package.json meta _fields, but most of
|
| 5 |
+
// the time will be pulled out of a lockfile
|
| 6 |
+
|
| 7 |
+
const semver = require('semver')
|
| 8 |
+
const npa = require('npm-package-arg')
|
| 9 |
+
const { relative } = require('node:path')
|
| 10 |
+
const fromPath = require('./from-path.js')
|
| 11 |
+
|
| 12 |
+
const depValid = (child, requested, requestor) => {
|
| 13 |
+
// NB: we don't do much to verify 'tag' type requests.
|
| 14 |
+
// Just verify that we got a remote resolution. Presumably, it
|
| 15 |
+
// came from a registry and was tagged at some point.
|
| 16 |
+
|
| 17 |
+
if (typeof requested === 'string') {
|
| 18 |
+
try {
|
| 19 |
+
// tarball/dir must have resolved to the same tgz on disk, but for
|
| 20 |
+
// file: deps that depend on other files/dirs, we must resolve the
|
| 21 |
+
// location based on the *requestor* file/dir, not where it ends up.
|
| 22 |
+
// '' is equivalent to '*'
|
| 23 |
+
requested = npa.resolve(child.name, requested || '*', fromPath(requestor, requestor.edgesOut.get(child.name)))
|
| 24 |
+
} catch (er) {
|
| 25 |
+
// Not invalid because the child doesn't match, but because
|
| 26 |
+
// the spec itself is not supported. Nothing would match,
|
| 27 |
+
// so the edge is definitely not valid and never can be.
|
| 28 |
+
er.dependency = child.name
|
| 29 |
+
er.requested = requested
|
| 30 |
+
requestor.errors.push(er)
|
| 31 |
+
return false
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
// if the lockfile is super old, or hand-modified,
|
| 36 |
+
// then it's possible to hit this state.
|
| 37 |
+
if (!requested) {
|
| 38 |
+
const er = new Error('Invalid dependency specifier')
|
| 39 |
+
er.dependency = child.name
|
| 40 |
+
er.requested = requested
|
| 41 |
+
requestor.errors.push(er)
|
| 42 |
+
return false
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
switch (requested.type) {
|
| 46 |
+
case 'range':
|
| 47 |
+
if (requested.fetchSpec === '*') {
|
| 48 |
+
return true
|
| 49 |
+
}
|
| 50 |
+
// fallthrough
|
| 51 |
+
case 'version':
|
| 52 |
+
// if it's a version or a range other than '*', semver it
|
| 53 |
+
return semver.satisfies(child.version, requested.fetchSpec, true)
|
| 54 |
+
|
| 55 |
+
case 'directory':
|
| 56 |
+
return linkValid(child, requested, requestor)
|
| 57 |
+
|
| 58 |
+
case 'file':
|
| 59 |
+
return tarballValid(child, requested, requestor)
|
| 60 |
+
|
| 61 |
+
case 'alias':
|
| 62 |
+
// check that the alias target is valid
|
| 63 |
+
return depValid(child, requested.subSpec, requestor)
|
| 64 |
+
|
| 65 |
+
case 'tag':
|
| 66 |
+
// if it's a tag, we just verify that it has a tarball resolution
|
| 67 |
+
// presumably, it came from the registry and was tagged at some point
|
| 68 |
+
return child.resolved && npa(child.resolved).type === 'remote'
|
| 69 |
+
|
| 70 |
+
case 'remote':
|
| 71 |
+
// verify that we got it from the desired location
|
| 72 |
+
return child.resolved === requested.fetchSpec
|
| 73 |
+
|
| 74 |
+
case 'git': {
|
| 75 |
+
// if it's a git type, verify that they're the same repo
|
| 76 |
+
//
|
| 77 |
+
// if it specifies a definite commit, then it must have the
|
| 78 |
+
// same commit to be considered the same repo
|
| 79 |
+
//
|
| 80 |
+
// if it has a #semver:<range> specifier, verify that the
|
| 81 |
+
// version in the package is in the semver range
|
| 82 |
+
const resRepo = npa(child.resolved || '')
|
| 83 |
+
const resHost = resRepo.hosted
|
| 84 |
+
const reqHost = requested.hosted
|
| 85 |
+
const reqCommit = /^[a-fA-F0-9]{40}$/.test(requested.gitCommittish || '')
|
| 86 |
+
const nc = { noCommittish: !reqCommit }
|
| 87 |
+
if (!resHost) {
|
| 88 |
+
if (resRepo.fetchSpec !== requested.fetchSpec) {
|
| 89 |
+
return false
|
| 90 |
+
}
|
| 91 |
+
} else {
|
| 92 |
+
if (reqHost?.ssh(nc) !== resHost.ssh(nc)) {
|
| 93 |
+
return false
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
if (!requested.gitRange) {
|
| 97 |
+
return true
|
| 98 |
+
}
|
| 99 |
+
return semver.satisfies(child.package.version, requested.gitRange, {
|
| 100 |
+
loose: true,
|
| 101 |
+
})
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
default: // unpossible, just being cautious
|
| 105 |
+
break
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
const er = new Error('Unsupported dependency type')
|
| 109 |
+
er.dependency = child.name
|
| 110 |
+
er.requested = requested
|
| 111 |
+
requestor.errors.push(er)
|
| 112 |
+
return false
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
const linkValid = (child, requested, requestor) => {
|
| 116 |
+
const isLink = !!child.isLink
|
| 117 |
+
// if we're installing links and the node is a link, then it's invalid because we want
|
| 118 |
+
// a real node to be there. Except for workspaces. They are always links.
|
| 119 |
+
if (requestor.installLinks && !child.isWorkspace) {
|
| 120 |
+
return !isLink
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
// directory must be a link to the specified folder
|
| 124 |
+
return isLink && relative(child.realpath, requested.fetchSpec) === ''
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
const tarballValid = (child, requested) => {
|
| 128 |
+
if (child.isLink) {
|
| 129 |
+
return false
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
if (child.resolved) {
|
| 133 |
+
return child.resolved.replace(/\\/g, '/') === `file:${requested.fetchSpec.replace(/\\/g, '/')}`
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
// if we have a legacy mutated package.json file. we can't be 100%
|
| 137 |
+
// sure that it resolved to the same file, but if it was the same
|
| 138 |
+
// request, that's a pretty good indicator of sameness.
|
| 139 |
+
if (child.package._requested) {
|
| 140 |
+
return child.package._requested.saveSpec === requested.saveSpec
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
// ok, we're probably dealing with some legacy cruft here, not much
|
| 144 |
+
// we can do at this point unfortunately.
|
| 145 |
+
return false
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
module.exports = (child, requested, accept, requestor) =>
|
| 149 |
+
depValid(child, requested, requestor) ||
|
| 150 |
+
(typeof accept === 'string' ? depValid(child, accept, requestor) : false)
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/diff.js
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// a tree representing the difference between two trees
|
| 2 |
+
// A Diff node's parent is not necessarily the parent of
|
| 3 |
+
// the node location it refers to, but rather the highest level
|
| 4 |
+
// node that needs to be either changed or removed.
|
| 5 |
+
// Thus, the root Diff node is the shallowest change required
|
| 6 |
+
// for a given branch of the tree being mutated.
|
| 7 |
+
|
| 8 |
+
const { depth } = require('treeverse')
|
| 9 |
+
const { existsSync } = require('node:fs')
|
| 10 |
+
|
| 11 |
+
const ssri = require('ssri')
|
| 12 |
+
|
| 13 |
+
class Diff {
|
| 14 |
+
constructor ({ actual, ideal, filterSet, shrinkwrapInflated }) {
|
| 15 |
+
this.filterSet = filterSet
|
| 16 |
+
this.shrinkwrapInflated = shrinkwrapInflated
|
| 17 |
+
this.children = []
|
| 18 |
+
this.actual = actual
|
| 19 |
+
this.ideal = ideal
|
| 20 |
+
if (this.ideal) {
|
| 21 |
+
this.resolved = this.ideal.resolved
|
| 22 |
+
this.integrity = this.ideal.integrity
|
| 23 |
+
}
|
| 24 |
+
this.action = getAction(this)
|
| 25 |
+
this.parent = null
|
| 26 |
+
// the set of leaf nodes that we rake up to the top level
|
| 27 |
+
this.leaves = []
|
| 28 |
+
// the set of nodes that don't change in this branch of the tree
|
| 29 |
+
this.unchanged = []
|
| 30 |
+
// the set of nodes that will be removed in this branch of the tree
|
| 31 |
+
this.removed = []
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
static calculate ({
|
| 35 |
+
actual,
|
| 36 |
+
ideal,
|
| 37 |
+
filterNodes = [],
|
| 38 |
+
shrinkwrapInflated = new Set(),
|
| 39 |
+
}) {
|
| 40 |
+
// if there's a filterNode, then:
|
| 41 |
+
// - get the path from the root to the filterNode. The root or
|
| 42 |
+
// root.target should have an edge either to the filterNode or
|
| 43 |
+
// a link to the filterNode. If not, abort. Add the path to the
|
| 44 |
+
// filterSet.
|
| 45 |
+
// - Add set of Nodes depended on by the filterNode to filterSet.
|
| 46 |
+
// - Anything outside of that set should be ignored by getChildren
|
| 47 |
+
const filterSet = new Set()
|
| 48 |
+
const extraneous = new Set()
|
| 49 |
+
for (const filterNode of filterNodes) {
|
| 50 |
+
const { root } = filterNode
|
| 51 |
+
if (root !== ideal && root !== actual) {
|
| 52 |
+
throw new Error('invalid filterNode: outside idealTree/actualTree')
|
| 53 |
+
}
|
| 54 |
+
const rootTarget = root.target
|
| 55 |
+
const edge = [...rootTarget.edgesOut.values()].filter(e => {
|
| 56 |
+
return e.to && (e.to === filterNode || e.to.target === filterNode)
|
| 57 |
+
})[0]
|
| 58 |
+
filterSet.add(root)
|
| 59 |
+
filterSet.add(rootTarget)
|
| 60 |
+
filterSet.add(ideal)
|
| 61 |
+
filterSet.add(actual)
|
| 62 |
+
if (edge && edge.to) {
|
| 63 |
+
filterSet.add(edge.to)
|
| 64 |
+
filterSet.add(edge.to.target)
|
| 65 |
+
}
|
| 66 |
+
filterSet.add(filterNode)
|
| 67 |
+
|
| 68 |
+
depth({
|
| 69 |
+
tree: filterNode,
|
| 70 |
+
visit: node => filterSet.add(node),
|
| 71 |
+
getChildren: node => {
|
| 72 |
+
node = node.target
|
| 73 |
+
const loc = node.location
|
| 74 |
+
const idealNode = ideal.inventory.get(loc)
|
| 75 |
+
const ideals = !idealNode ? []
|
| 76 |
+
: [...idealNode.edgesOut.values()].filter(e => e.to).map(e => e.to)
|
| 77 |
+
const actualNode = actual.inventory.get(loc)
|
| 78 |
+
const actuals = !actualNode ? []
|
| 79 |
+
: [...actualNode.edgesOut.values()].filter(e => e.to).map(e => e.to)
|
| 80 |
+
if (actualNode) {
|
| 81 |
+
for (const child of actualNode.children.values()) {
|
| 82 |
+
if (child.extraneous) {
|
| 83 |
+
extraneous.add(child)
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
return ideals.concat(actuals)
|
| 89 |
+
},
|
| 90 |
+
})
|
| 91 |
+
}
|
| 92 |
+
for (const extra of extraneous) {
|
| 93 |
+
filterSet.add(extra)
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
return depth({
|
| 97 |
+
tree: new Diff({ actual, ideal, filterSet, shrinkwrapInflated }),
|
| 98 |
+
getChildren,
|
| 99 |
+
leave,
|
| 100 |
+
})
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
const getAction = ({ actual, ideal }) => {
|
| 105 |
+
if (!ideal) {
|
| 106 |
+
return 'REMOVE'
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
// bundled meta-deps are copied over to the ideal tree when we visit it,
|
| 110 |
+
// so they'll appear to be missing here. There's no need to handle them
|
| 111 |
+
// in the diff, though, because they'll be replaced at reify time anyway
|
| 112 |
+
// Otherwise, add the missing node.
|
| 113 |
+
if (!actual) {
|
| 114 |
+
return ideal.inDepBundle ? null : 'ADD'
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
// always ignore the root node
|
| 118 |
+
if (ideal.isRoot && actual.isRoot) {
|
| 119 |
+
return null
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
// if the versions don't match, it's a change no matter what
|
| 123 |
+
if (ideal.version !== actual.version) {
|
| 124 |
+
return 'CHANGE'
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
const binsExist = ideal.binPaths.every((path) => existsSync(path))
|
| 128 |
+
|
| 129 |
+
// top nodes, links, and git deps won't have integrity, but do have resolved
|
| 130 |
+
// if neither node has integrity, the bins exist, and either (a) neither
|
| 131 |
+
// node has a resolved value or (b) they both do and match, then we can
|
| 132 |
+
// leave this one alone since we already know the versions match due to
|
| 133 |
+
// the condition above. The "neither has resolved" case (a) cannot be
|
| 134 |
+
// treated as a 'mark CHANGE and refetch', because shrinkwraps, bundles,
|
| 135 |
+
// and link deps may lack this information, and we don't want to try to
|
| 136 |
+
// go to the registry for something that isn't there.
|
| 137 |
+
const noIntegrity = !ideal.integrity && !actual.integrity
|
| 138 |
+
const noResolved = !ideal.resolved && !actual.resolved
|
| 139 |
+
const resolvedMatch = ideal.resolved && ideal.resolved === actual.resolved
|
| 140 |
+
if (noIntegrity && binsExist && (resolvedMatch || noResolved)) {
|
| 141 |
+
return null
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
// otherwise, verify that it's the same bits
|
| 145 |
+
// note that if ideal has integrity, and resolved doesn't, we treat
|
| 146 |
+
// that as a 'change', so that it gets re-fetched and locked down.
|
| 147 |
+
const integrityMismatch = !ideal.integrity || !actual.integrity ||
|
| 148 |
+
!ssri.parse(ideal.integrity).match(actual.integrity)
|
| 149 |
+
if (integrityMismatch || !binsExist) {
|
| 150 |
+
return 'CHANGE'
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
return null
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
const allChildren = node => {
|
| 157 |
+
if (!node) {
|
| 158 |
+
return new Map()
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
// if the node is root, and also a link, then what we really
|
| 162 |
+
// want is to traverse the target's children
|
| 163 |
+
if (node.isRoot && node.isLink) {
|
| 164 |
+
return allChildren(node.target)
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
const kids = new Map()
|
| 168 |
+
for (const n of [node, ...node.fsChildren]) {
|
| 169 |
+
for (const kid of n.children.values()) {
|
| 170 |
+
kids.set(kid.path, kid)
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
return kids
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
// functions for the walk options when we traverse the trees
|
| 177 |
+
// to create the diff tree
|
| 178 |
+
const getChildren = diff => {
|
| 179 |
+
const children = []
|
| 180 |
+
const {
|
| 181 |
+
actual,
|
| 182 |
+
ideal,
|
| 183 |
+
unchanged,
|
| 184 |
+
removed,
|
| 185 |
+
filterSet,
|
| 186 |
+
shrinkwrapInflated,
|
| 187 |
+
} = diff
|
| 188 |
+
|
| 189 |
+
// Note: we DON'T diff fsChildren themselves, because they are either
|
| 190 |
+
// included in the package contents, or part of some other project, and
|
| 191 |
+
// will never appear in legacy shrinkwraps anyway. but we _do_ include the
|
| 192 |
+
// child nodes of fsChildren, because those are nodes that we are typically
|
| 193 |
+
// responsible for installing.
|
| 194 |
+
const actualKids = allChildren(actual)
|
| 195 |
+
const idealKids = allChildren(ideal)
|
| 196 |
+
|
| 197 |
+
if (ideal && ideal.hasShrinkwrap && !shrinkwrapInflated.has(ideal)) {
|
| 198 |
+
// Guaranteed to get a diff.leaves here, because we always
|
| 199 |
+
// be called with a proper Diff object when ideal has a shrinkwrap
|
| 200 |
+
// that has not been inflated.
|
| 201 |
+
diff.leaves.push(diff)
|
| 202 |
+
return children
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
const paths = new Set([...actualKids.keys(), ...idealKids.keys()])
|
| 206 |
+
for (const path of paths) {
|
| 207 |
+
const actual = actualKids.get(path)
|
| 208 |
+
const ideal = idealKids.get(path)
|
| 209 |
+
diffNode({
|
| 210 |
+
actual,
|
| 211 |
+
ideal,
|
| 212 |
+
children,
|
| 213 |
+
unchanged,
|
| 214 |
+
removed,
|
| 215 |
+
filterSet,
|
| 216 |
+
shrinkwrapInflated,
|
| 217 |
+
})
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
if (diff.leaves && !children.length) {
|
| 221 |
+
diff.leaves.push(diff)
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
return children
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
const diffNode = ({
|
| 228 |
+
actual,
|
| 229 |
+
ideal,
|
| 230 |
+
children,
|
| 231 |
+
unchanged,
|
| 232 |
+
removed,
|
| 233 |
+
filterSet,
|
| 234 |
+
shrinkwrapInflated,
|
| 235 |
+
}) => {
|
| 236 |
+
if (filterSet.size && !(filterSet.has(ideal) || filterSet.has(actual))) {
|
| 237 |
+
return
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
const action = getAction({ actual, ideal })
|
| 241 |
+
|
| 242 |
+
// if it's a match, then get its children
|
| 243 |
+
// otherwise, this is the child diff node
|
| 244 |
+
if (action || (!shrinkwrapInflated.has(ideal) && ideal.hasShrinkwrap)) {
|
| 245 |
+
if (action === 'REMOVE') {
|
| 246 |
+
removed.push(actual)
|
| 247 |
+
}
|
| 248 |
+
children.push(new Diff({ actual, ideal, filterSet, shrinkwrapInflated }))
|
| 249 |
+
} else {
|
| 250 |
+
unchanged.push(ideal)
|
| 251 |
+
// !*! Weird dirty hack warning !*!
|
| 252 |
+
//
|
| 253 |
+
// Bundled deps aren't loaded in the ideal tree, because we don't know
|
| 254 |
+
// what they are going to be without unpacking. Swap them over now if
|
| 255 |
+
// the bundling node isn't changing, so we don't prune them later.
|
| 256 |
+
//
|
| 257 |
+
// It's a little bit dirty to be doing this here, since it means that
|
| 258 |
+
// diffing trees can mutate them, but otherwise we have to walk over
|
| 259 |
+
// all unchanging bundlers and correct the diff later, so it's more
|
| 260 |
+
// efficient to just fix it while we're passing through already.
|
| 261 |
+
//
|
| 262 |
+
// Note that moving over a bundled dep will break the links to other
|
| 263 |
+
// deps under this parent, which may have been transitively bundled.
|
| 264 |
+
// Breaking those links means that we'll no longer see the transitive
|
| 265 |
+
// dependency, meaning that it won't appear as bundled any longer!
|
| 266 |
+
// In order to not end up dropping transitively bundled deps, we have
|
| 267 |
+
// to get the list of nodes to move, then move them all at once, rather
|
| 268 |
+
// than moving them one at a time in the first loop.
|
| 269 |
+
const bd = ideal.package.bundleDependencies
|
| 270 |
+
if (actual && bd && bd.length) {
|
| 271 |
+
const bundledChildren = []
|
| 272 |
+
for (const node of actual.children.values()) {
|
| 273 |
+
if (node.inBundle) {
|
| 274 |
+
bundledChildren.push(node)
|
| 275 |
+
}
|
| 276 |
+
}
|
| 277 |
+
for (const node of bundledChildren) {
|
| 278 |
+
node.parent = ideal
|
| 279 |
+
}
|
| 280 |
+
}
|
| 281 |
+
children.push(...getChildren({
|
| 282 |
+
actual,
|
| 283 |
+
ideal,
|
| 284 |
+
unchanged,
|
| 285 |
+
removed,
|
| 286 |
+
filterSet,
|
| 287 |
+
shrinkwrapInflated,
|
| 288 |
+
}))
|
| 289 |
+
}
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
// set the parentage in the leave step so that we aren't attaching
|
| 293 |
+
// child nodes only to remove them later. also bubble up the unchanged
|
| 294 |
+
// nodes so that we can move them out of staging in the reification step.
|
| 295 |
+
const leave = (diff, children) => {
|
| 296 |
+
children.forEach(kid => {
|
| 297 |
+
kid.parent = diff
|
| 298 |
+
diff.leaves.push(...kid.leaves)
|
| 299 |
+
diff.unchanged.push(...kid.unchanged)
|
| 300 |
+
diff.removed.push(...kid.removed)
|
| 301 |
+
})
|
| 302 |
+
diff.children = children
|
| 303 |
+
return diff
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
module.exports = Diff
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/edge.js
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ency graph
|
| 2 |
+
// Represents a dependency relationship of some kind
|
| 3 |
+
|
| 4 |
+
const util = require('node:util')
|
| 5 |
+
const npa = require('npm-package-arg')
|
| 6 |
+
const depValid = require('./dep-valid.js')
|
| 7 |
+
|
| 8 |
+
class ArboristEdge {
|
| 9 |
+
constructor (edge) {
|
| 10 |
+
this.name = edge.name
|
| 11 |
+
this.spec = edge.spec
|
| 12 |
+
this.type = edge.type
|
| 13 |
+
|
| 14 |
+
const edgeFrom = edge.from?.location
|
| 15 |
+
const edgeTo = edge.to?.location
|
| 16 |
+
const override = edge.overrides?.value
|
| 17 |
+
|
| 18 |
+
if (edgeFrom != null) {
|
| 19 |
+
this.from = edgeFrom
|
| 20 |
+
}
|
| 21 |
+
if (edgeTo) {
|
| 22 |
+
this.to = edgeTo
|
| 23 |
+
}
|
| 24 |
+
if (edge.error) {
|
| 25 |
+
this.error = edge.error
|
| 26 |
+
}
|
| 27 |
+
if (edge.peerConflicted) {
|
| 28 |
+
this.peerConflicted = true
|
| 29 |
+
}
|
| 30 |
+
if (override) {
|
| 31 |
+
this.overridden = override
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
class Edge {
|
| 37 |
+
#accept
|
| 38 |
+
#error
|
| 39 |
+
#explanation
|
| 40 |
+
#from
|
| 41 |
+
#name
|
| 42 |
+
#spec
|
| 43 |
+
#to
|
| 44 |
+
#type
|
| 45 |
+
|
| 46 |
+
static types = Object.freeze([
|
| 47 |
+
'prod',
|
| 48 |
+
'dev',
|
| 49 |
+
'optional',
|
| 50 |
+
'peer',
|
| 51 |
+
'peerOptional',
|
| 52 |
+
'workspace',
|
| 53 |
+
])
|
| 54 |
+
|
| 55 |
+
// XXX where is this used?
|
| 56 |
+
static errors = Object.freeze([
|
| 57 |
+
'DETACHED',
|
| 58 |
+
'MISSING',
|
| 59 |
+
'PEER LOCAL',
|
| 60 |
+
'INVALID',
|
| 61 |
+
])
|
| 62 |
+
|
| 63 |
+
constructor (options) {
|
| 64 |
+
const { type, name, spec, accept, from, overrides } = options
|
| 65 |
+
|
| 66 |
+
// XXX are all of these error states even possible?
|
| 67 |
+
if (typeof spec !== 'string') {
|
| 68 |
+
throw new TypeError('must provide string spec')
|
| 69 |
+
}
|
| 70 |
+
if (!Edge.types.includes(type)) {
|
| 71 |
+
throw new TypeError(`invalid type: ${type}\n(valid types are: ${Edge.types.join(', ')})`)
|
| 72 |
+
}
|
| 73 |
+
if (type === 'workspace' && npa(spec).type !== 'directory') {
|
| 74 |
+
throw new TypeError('workspace edges must be a symlink')
|
| 75 |
+
}
|
| 76 |
+
if (typeof name !== 'string') {
|
| 77 |
+
throw new TypeError('must provide dependency name')
|
| 78 |
+
}
|
| 79 |
+
if (!from) {
|
| 80 |
+
throw new TypeError('must provide "from" node')
|
| 81 |
+
}
|
| 82 |
+
if (accept !== undefined) {
|
| 83 |
+
if (typeof accept !== 'string') {
|
| 84 |
+
throw new TypeError('accept field must be a string if provided')
|
| 85 |
+
}
|
| 86 |
+
this.#accept = accept || '*'
|
| 87 |
+
}
|
| 88 |
+
if (overrides !== undefined) {
|
| 89 |
+
this.overrides = overrides
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
this.#name = name
|
| 93 |
+
this.#type = type
|
| 94 |
+
this.#spec = spec
|
| 95 |
+
this.#explanation = null
|
| 96 |
+
this.#from = from
|
| 97 |
+
|
| 98 |
+
from.edgesOut.get(this.#name)?.detach()
|
| 99 |
+
from.addEdgeOut(this)
|
| 100 |
+
|
| 101 |
+
this.reload(true)
|
| 102 |
+
this.peerConflicted = false
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
satisfiedBy (node) {
|
| 106 |
+
if (node.name !== this.#name) {
|
| 107 |
+
return false
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
// NOTE: this condition means we explicitly do not support overriding
|
| 111 |
+
// bundled or shrinkwrapped dependencies
|
| 112 |
+
if (node.hasShrinkwrap || node.inShrinkwrap || node.inBundle) {
|
| 113 |
+
return depValid(node, this.rawSpec, this.#accept, this.#from)
|
| 114 |
+
}
|
| 115 |
+
return depValid(node, this.spec, this.#accept, this.#from)
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
// return the edge data, and an explanation of how that edge came to be here
|
| 119 |
+
explain (seen = []) {
|
| 120 |
+
if (!this.#explanation) {
|
| 121 |
+
const explanation = {
|
| 122 |
+
type: this.#type,
|
| 123 |
+
name: this.#name,
|
| 124 |
+
spec: this.spec,
|
| 125 |
+
}
|
| 126 |
+
if (this.rawSpec !== this.spec) {
|
| 127 |
+
explanation.rawSpec = this.rawSpec
|
| 128 |
+
explanation.overridden = true
|
| 129 |
+
}
|
| 130 |
+
if (this.bundled) {
|
| 131 |
+
explanation.bundled = this.bundled
|
| 132 |
+
}
|
| 133 |
+
if (this.error) {
|
| 134 |
+
explanation.error = this.error
|
| 135 |
+
}
|
| 136 |
+
if (this.#from) {
|
| 137 |
+
explanation.from = this.#from.explain(null, seen)
|
| 138 |
+
}
|
| 139 |
+
this.#explanation = explanation
|
| 140 |
+
}
|
| 141 |
+
return this.#explanation
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
get bundled () {
|
| 145 |
+
return !!this.#from?.package?.bundleDependencies?.includes(this.#name)
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
get workspace () {
|
| 149 |
+
return this.#type === 'workspace'
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
get prod () {
|
| 153 |
+
return this.#type === 'prod'
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
get dev () {
|
| 157 |
+
return this.#type === 'dev'
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
get optional () {
|
| 161 |
+
return this.#type === 'optional' || this.#type === 'peerOptional'
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
get peer () {
|
| 165 |
+
return this.#type === 'peer' || this.#type === 'peerOptional'
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
get type () {
|
| 169 |
+
return this.#type
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
get name () {
|
| 173 |
+
return this.#name
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
get rawSpec () {
|
| 177 |
+
return this.#spec
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
get spec () {
|
| 181 |
+
if (this.overrides?.value && this.overrides.value !== '*' && this.overrides.name === this.#name) {
|
| 182 |
+
if (this.overrides.value.startsWith('$')) {
|
| 183 |
+
const ref = this.overrides.value.slice(1)
|
| 184 |
+
// we may be a virtual root, if we are we want to resolve reference overrides
|
| 185 |
+
// from the real root, not the virtual one
|
| 186 |
+
const pkg = this.#from.sourceReference
|
| 187 |
+
? this.#from.sourceReference.root.package
|
| 188 |
+
: this.#from.root.package
|
| 189 |
+
if (pkg.devDependencies?.[ref]) {
|
| 190 |
+
return pkg.devDependencies[ref]
|
| 191 |
+
}
|
| 192 |
+
if (pkg.optionalDependencies?.[ref]) {
|
| 193 |
+
return pkg.optionalDependencies[ref]
|
| 194 |
+
}
|
| 195 |
+
if (pkg.dependencies?.[ref]) {
|
| 196 |
+
return pkg.dependencies[ref]
|
| 197 |
+
}
|
| 198 |
+
if (pkg.peerDependencies?.[ref]) {
|
| 199 |
+
return pkg.peerDependencies[ref]
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
throw new Error(`Unable to resolve reference ${this.overrides.value}`)
|
| 203 |
+
}
|
| 204 |
+
return this.overrides.value
|
| 205 |
+
}
|
| 206 |
+
return this.#spec
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
get accept () {
|
| 210 |
+
return this.#accept
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
get valid () {
|
| 214 |
+
return !this.error
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
get missing () {
|
| 218 |
+
return this.error === 'MISSING'
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
get invalid () {
|
| 222 |
+
return this.error === 'INVALID'
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
get peerLocal () {
|
| 226 |
+
return this.error === 'PEER LOCAL'
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
get error () {
|
| 230 |
+
if (!this.#error) {
|
| 231 |
+
if (!this.#to) {
|
| 232 |
+
if (this.optional) {
|
| 233 |
+
this.#error = null
|
| 234 |
+
} else {
|
| 235 |
+
this.#error = 'MISSING'
|
| 236 |
+
}
|
| 237 |
+
} else if (this.peer && this.#from === this.#to.parent && !this.#from.isTop) {
|
| 238 |
+
this.#error = 'PEER LOCAL'
|
| 239 |
+
} else if (!this.satisfiedBy(this.#to)) {
|
| 240 |
+
this.#error = 'INVALID'
|
| 241 |
+
} else {
|
| 242 |
+
this.#error = 'OK'
|
| 243 |
+
}
|
| 244 |
+
}
|
| 245 |
+
if (this.#error === 'OK') {
|
| 246 |
+
return null
|
| 247 |
+
}
|
| 248 |
+
return this.#error
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
reload (hard = false) {
|
| 252 |
+
this.#explanation = null
|
| 253 |
+
if (this.#from.overrides) {
|
| 254 |
+
this.overrides = this.#from.overrides.getEdgeRule(this)
|
| 255 |
+
} else {
|
| 256 |
+
delete this.overrides
|
| 257 |
+
}
|
| 258 |
+
const newTo = this.#from.resolve(this.#name)
|
| 259 |
+
if (newTo !== this.#to) {
|
| 260 |
+
if (this.#to) {
|
| 261 |
+
this.#to.edgesIn.delete(this)
|
| 262 |
+
}
|
| 263 |
+
this.#to = newTo
|
| 264 |
+
this.#error = null
|
| 265 |
+
if (this.#to) {
|
| 266 |
+
this.#to.addEdgeIn(this)
|
| 267 |
+
}
|
| 268 |
+
} else if (hard) {
|
| 269 |
+
this.#error = null
|
| 270 |
+
}
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
detach () {
|
| 274 |
+
this.#explanation = null
|
| 275 |
+
if (this.#to) {
|
| 276 |
+
this.#to.edgesIn.delete(this)
|
| 277 |
+
}
|
| 278 |
+
this.#from.edgesOut.delete(this.#name)
|
| 279 |
+
this.#to = null
|
| 280 |
+
this.#error = 'DETACHED'
|
| 281 |
+
this.#from = null
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
get from () {
|
| 285 |
+
return this.#from
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
get to () {
|
| 289 |
+
return this.#to
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
toJSON () {
|
| 293 |
+
return new ArboristEdge(this)
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
[util.inspect.custom] () {
|
| 297 |
+
return this.toJSON()
|
| 298 |
+
}
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
module.exports = Edge
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/from-path.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// file dependencies need their dependencies resolved based on the location
|
| 2 |
+
// where the tarball was found, not the location where they end up getting
|
| 3 |
+
// installed. directory (ie, symlink) deps also need to be resolved based on
|
| 4 |
+
// their targets, but that's what realpath is
|
| 5 |
+
|
| 6 |
+
const { dirname } = require('node:path')
|
| 7 |
+
const npa = require('npm-package-arg')
|
| 8 |
+
|
| 9 |
+
const fromPath = (node, edge) => {
|
| 10 |
+
if (edge && edge.overrides && edge.overrides.name === edge.name && edge.overrides.value) {
|
| 11 |
+
// fromPath could be called with a node that has a virtual root, if that
|
| 12 |
+
// happens we want to make sure we get the real root node when overrides
|
| 13 |
+
// are in use. this is to allow things like overriding a dependency with a
|
| 14 |
+
// tarball file that's a relative path from the project root
|
| 15 |
+
if (node.sourceReference) {
|
| 16 |
+
return node.sourceReference.root.realpath
|
| 17 |
+
}
|
| 18 |
+
return node.root.realpath
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
if (node.resolved) {
|
| 22 |
+
const spec = npa(node.resolved)
|
| 23 |
+
if (spec?.type === 'file') {
|
| 24 |
+
return dirname(spec.fetchSpec)
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
return node.realpath
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
module.exports = fromPath
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/gather-dep-set.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Given a set of nodes in a tree, and a filter function to test
|
| 2 |
+
// incoming edges to the dep set that should be ignored otherwise.
|
| 3 |
+
//
|
| 4 |
+
// find the set of deps that are only depended upon by nodes in the set, or
|
| 5 |
+
// their dependencies, or edges that are ignored.
|
| 6 |
+
//
|
| 7 |
+
// Used when figuring out what to prune when replacing a node with a newer
|
| 8 |
+
// version, or when an optional dep fails to install.
|
| 9 |
+
|
| 10 |
+
const gatherDepSet = (set, edgeFilter) => {
|
| 11 |
+
const deps = new Set(set)
|
| 12 |
+
|
| 13 |
+
// add the full set of dependencies. note that this loop will continue
|
| 14 |
+
// as the deps set increases in size.
|
| 15 |
+
for (const node of deps) {
|
| 16 |
+
for (const edge of node.edgesOut.values()) {
|
| 17 |
+
if (edge.to && edgeFilter(edge)) {
|
| 18 |
+
deps.add(edge.to)
|
| 19 |
+
}
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
// now remove all nodes in the set that have a dependant outside the set
|
| 24 |
+
// if any change is made, then re-check
|
| 25 |
+
// continue until no changes made, or deps set evaporates fully.
|
| 26 |
+
let changed = true
|
| 27 |
+
while (changed === true && deps.size > 0) {
|
| 28 |
+
changed = false
|
| 29 |
+
for (const dep of deps) {
|
| 30 |
+
for (const edge of dep.edgesIn) {
|
| 31 |
+
if (!deps.has(edge.from) && edgeFilter(edge)) {
|
| 32 |
+
changed = true
|
| 33 |
+
deps.delete(dep)
|
| 34 |
+
break
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
return deps
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
module.exports = gatherDepSet
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module.exports = require('./arborist/index.js')
|
| 2 |
+
module.exports.Arborist = module.exports
|
| 3 |
+
module.exports.Node = require('./node.js')
|
| 4 |
+
module.exports.Link = require('./link.js')
|
| 5 |
+
module.exports.Edge = require('./edge.js')
|
| 6 |
+
module.exports.Shrinkwrap = require('./shrinkwrap.js')
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/inventory.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// a class to manage an inventory and set of indexes of a set of objects based
|
| 2 |
+
// on specific fields.
|
| 3 |
+
const { hasOwnProperty } = Object.prototype
|
| 4 |
+
const debug = require('./debug.js')
|
| 5 |
+
|
| 6 |
+
const keys = ['name', 'license', 'funding', 'realpath', 'packageName']
|
| 7 |
+
class Inventory extends Map {
|
| 8 |
+
#index
|
| 9 |
+
|
| 10 |
+
constructor () {
|
| 11 |
+
super()
|
| 12 |
+
this.#index = new Map()
|
| 13 |
+
for (const key of keys) {
|
| 14 |
+
this.#index.set(key, new Map())
|
| 15 |
+
}
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
// XXX where is this used?
|
| 19 |
+
get primaryKey () {
|
| 20 |
+
return 'location'
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
// XXX where is this used?
|
| 24 |
+
get indexes () {
|
| 25 |
+
return [...keys]
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
* filter (fn) {
|
| 29 |
+
for (const node of this.values()) {
|
| 30 |
+
if (fn(node)) {
|
| 31 |
+
yield node
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
add (node) {
|
| 37 |
+
const root = super.get('')
|
| 38 |
+
if (root && node.root !== root && node.root !== root.root) {
|
| 39 |
+
debug(() => {
|
| 40 |
+
throw Object.assign(new Error('adding external node to inventory'), {
|
| 41 |
+
root: root.path,
|
| 42 |
+
node: node.path,
|
| 43 |
+
nodeRoot: node.root.path,
|
| 44 |
+
})
|
| 45 |
+
})
|
| 46 |
+
return
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
const current = super.get(node.location)
|
| 50 |
+
if (current) {
|
| 51 |
+
if (current === node) {
|
| 52 |
+
return
|
| 53 |
+
}
|
| 54 |
+
this.delete(current)
|
| 55 |
+
}
|
| 56 |
+
super.set(node.location, node)
|
| 57 |
+
for (const [key, map] of this.#index.entries()) {
|
| 58 |
+
let val
|
| 59 |
+
if (hasOwnProperty.call(node, key)) {
|
| 60 |
+
// if the node has the value, use it even if it's false
|
| 61 |
+
val = node[key]
|
| 62 |
+
} else if (key === 'license' && node.package) {
|
| 63 |
+
// handling for the outdated "licenses" array, just pick the first one
|
| 64 |
+
// also support the alternative spelling "licence"
|
| 65 |
+
if (node.package.license) {
|
| 66 |
+
val = node.package.license
|
| 67 |
+
} else if (node.package.licence) {
|
| 68 |
+
val = node.package.licence
|
| 69 |
+
} else if (Array.isArray(node.package.licenses)) {
|
| 70 |
+
val = node.package.licenses[0]
|
| 71 |
+
} else if (Array.isArray(node.package.licences)) {
|
| 72 |
+
val = node.package.licences[0]
|
| 73 |
+
}
|
| 74 |
+
} else if (node[key]) {
|
| 75 |
+
val = node[key]
|
| 76 |
+
} else {
|
| 77 |
+
val = node.package?.[key]
|
| 78 |
+
}
|
| 79 |
+
if (val && typeof val === 'object') {
|
| 80 |
+
// We currently only use license and funding
|
| 81 |
+
/* istanbul ignore next - not used */
|
| 82 |
+
if (key === 'license') {
|
| 83 |
+
val = val.type
|
| 84 |
+
} else if (key === 'funding') {
|
| 85 |
+
val = val.url
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
if (!map.has(val)) {
|
| 89 |
+
map.set(val, new Set())
|
| 90 |
+
}
|
| 91 |
+
map.get(val).add(node)
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
delete (node) {
|
| 96 |
+
if (!this.has(node)) {
|
| 97 |
+
return
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
super.delete(node.location)
|
| 101 |
+
for (const [key, map] of this.#index.entries()) {
|
| 102 |
+
let val
|
| 103 |
+
if (node[key] !== undefined) {
|
| 104 |
+
val = node[key]
|
| 105 |
+
} else {
|
| 106 |
+
val = node.package?.[key]
|
| 107 |
+
}
|
| 108 |
+
const set = map.get(val)
|
| 109 |
+
if (set) {
|
| 110 |
+
set.delete(node)
|
| 111 |
+
if (set.size === 0) {
|
| 112 |
+
map.delete(node[key])
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
query (key, val) {
|
| 119 |
+
const map = this.#index.get(key)
|
| 120 |
+
if (arguments.length === 2) {
|
| 121 |
+
if (map.has(val)) {
|
| 122 |
+
return map.get(val)
|
| 123 |
+
}
|
| 124 |
+
return new Set()
|
| 125 |
+
}
|
| 126 |
+
return map.keys()
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
has (node) {
|
| 130 |
+
return super.get(node.location) === node
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
set () {
|
| 134 |
+
throw new Error('direct set() not supported, use inventory.add(node)')
|
| 135 |
+
}
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
module.exports = Inventory
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/link.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const relpath = require('./relpath.js')
|
| 2 |
+
const Node = require('./node.js')
|
| 3 |
+
const _loadDeps = Symbol.for('Arborist.Node._loadDeps')
|
| 4 |
+
const _target = Symbol.for('_target')
|
| 5 |
+
const { dirname } = require('node:path')
|
| 6 |
+
// defined by Node class
|
| 7 |
+
const _delistFromMeta = Symbol.for('_delistFromMeta')
|
| 8 |
+
const _refreshLocation = Symbol.for('_refreshLocation')
|
| 9 |
+
class Link extends Node {
|
| 10 |
+
constructor (options) {
|
| 11 |
+
const { root, realpath, target, parent, fsParent, isStoreLink } = options
|
| 12 |
+
|
| 13 |
+
if (!realpath && !(target && target.path)) {
|
| 14 |
+
throw new TypeError('must provide realpath for Link node')
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
super({
|
| 18 |
+
...options,
|
| 19 |
+
realpath: realpath || target.path,
|
| 20 |
+
root: root || (parent ? parent.root
|
| 21 |
+
: fsParent ? fsParent.root
|
| 22 |
+
: target ? target.root
|
| 23 |
+
: null),
|
| 24 |
+
})
|
| 25 |
+
|
| 26 |
+
this.isStoreLink = isStoreLink || false
|
| 27 |
+
|
| 28 |
+
if (target) {
|
| 29 |
+
this.target = target
|
| 30 |
+
} else if (this.realpath === this.root.path) {
|
| 31 |
+
this.target = this.root
|
| 32 |
+
} else {
|
| 33 |
+
this.target = new Node({
|
| 34 |
+
...options,
|
| 35 |
+
path: realpath,
|
| 36 |
+
parent: null,
|
| 37 |
+
fsParent: null,
|
| 38 |
+
root: this.root,
|
| 39 |
+
})
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
get version () {
|
| 44 |
+
return this.target ? this.target.version : this.package.version || ''
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
get target () {
|
| 48 |
+
return this[_target]
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
set target (target) {
|
| 52 |
+
const current = this[_target]
|
| 53 |
+
if (target === current) {
|
| 54 |
+
return
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
if (!target) {
|
| 58 |
+
if (current && current.linksIn) {
|
| 59 |
+
current.linksIn.delete(this)
|
| 60 |
+
}
|
| 61 |
+
if (this.path) {
|
| 62 |
+
this[_delistFromMeta]()
|
| 63 |
+
this[_target] = null
|
| 64 |
+
this.package = {}
|
| 65 |
+
this[_refreshLocation]()
|
| 66 |
+
} else {
|
| 67 |
+
this[_target] = null
|
| 68 |
+
}
|
| 69 |
+
return
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
if (!this.path) {
|
| 73 |
+
// temp node pending assignment to a tree
|
| 74 |
+
// we know it's not in the inventory yet, because no path.
|
| 75 |
+
if (target.path) {
|
| 76 |
+
this.realpath = target.path
|
| 77 |
+
} else {
|
| 78 |
+
target.path = target.realpath = this.realpath
|
| 79 |
+
}
|
| 80 |
+
target.root = this.root
|
| 81 |
+
this[_target] = target
|
| 82 |
+
target.linksIn.add(this)
|
| 83 |
+
this.package = target.package
|
| 84 |
+
return
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
// have to refresh metadata, because either realpath or package
|
| 88 |
+
// is very likely changing.
|
| 89 |
+
this[_delistFromMeta]()
|
| 90 |
+
this.package = target.package
|
| 91 |
+
this.realpath = target.path
|
| 92 |
+
this[_refreshLocation]()
|
| 93 |
+
|
| 94 |
+
target.root = this.root
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
// a link always resolves to the relative path to its target
|
| 98 |
+
get resolved () {
|
| 99 |
+
// the path/realpath guard is there for the benefit of setting
|
| 100 |
+
// these things in the "wrong" order
|
| 101 |
+
return this.path && this.realpath
|
| 102 |
+
? `file:${relpath(dirname(this.path), this.realpath)}`
|
| 103 |
+
: null
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
set resolved (r) {}
|
| 107 |
+
|
| 108 |
+
// deps are resolved on the target, not the Link
|
| 109 |
+
// so this is a no-op
|
| 110 |
+
[_loadDeps] () {}
|
| 111 |
+
|
| 112 |
+
// links can't have children, only their targets can
|
| 113 |
+
// fix it to an empty list so that we can still call
|
| 114 |
+
// things that iterate over them, just as a no-op
|
| 115 |
+
get children () {
|
| 116 |
+
return new Map()
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
set children (c) {}
|
| 120 |
+
|
| 121 |
+
get isLink () {
|
| 122 |
+
return true
|
| 123 |
+
}
|
| 124 |
+
}
|
|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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// inventory, path, realpath, root, and parent
|
| 2 |
+
//
|
| 3 |
+
// node.root is a reference to the root module in the tree (ie, typically the
|
| 4 |
+
// cwd project folder)
|
| 5 |
+
//
|
| 6 |
+
// node.location is the /-delimited path from the root module to the node. In
|
| 7 |
+
// the case of link targets that may be outside of the root's package tree,
|
| 8 |
+
// this can include some number of /../ path segments. The location of the
|
| 9 |
+
// root module is always '.'. node.location thus never contains drive letters
|
| 10 |
+
// or absolute paths, and is portable within a given project, suitable for
|
| 11 |
+
// inclusion in lockfiles and metadata.
|
| 12 |
+
//
|
| 13 |
+
// node.path is the path to the place where this node lives on disk. It is
|
| 14 |
+
// system-specific and absolute.
|
| 15 |
+
//
|
| 16 |
+
// node.realpath is the path to where the module actually resides on disk. In
|
| 17 |
+
// the case of non-link nodes, node.realpath is equivalent to node.path. In
|
| 18 |
+
// the case of link nodes, it is equivalent to node.target.path.
|
| 19 |
+
//
|
| 20 |
+
// Setting node.parent will set the node's root to the parent's root, as well
|
| 21 |
+
// as updating edgesIn and edgesOut to reload dependency resolutions as needed,
|
| 22 |
+
// and setting node.path to parent.path/node_modules/name.
|
| 23 |
+
//
|
| 24 |
+
// node.inventory is a Map of name to a Set() of all the nodes under a given
|
| 25 |
+
// root by that name. It's empty for non-root nodes, and changing the root
|
| 26 |
+
// reference will remove it from the old root's inventory and add it to the new
|
| 27 |
+
// one. This map is useful for cases like `npm update foo` or `npm ls foo`
|
| 28 |
+
// where we need to quickly find all instances of a given package name within a
|
| 29 |
+
// tree.
|
| 30 |
+
|
| 31 |
+
const semver = require('semver')
|
| 32 |
+
const nameFromFolder = require('@npmcli/name-from-folder')
|
| 33 |
+
const Edge = require('./edge.js')
|
| 34 |
+
const Inventory = require('./inventory.js')
|
| 35 |
+
const OverrideSet = require('./override-set.js')
|
| 36 |
+
const { normalize } = require('read-package-json-fast')
|
| 37 |
+
const { getPaths: getBinPaths } = require('bin-links')
|
| 38 |
+
const npa = require('npm-package-arg')
|
| 39 |
+
const debug = require('./debug.js')
|
| 40 |
+
const gatherDepSet = require('./gather-dep-set.js')
|
| 41 |
+
const treeCheck = require('./tree-check.js')
|
| 42 |
+
const { walkUp } = require('walk-up-path')
|
| 43 |
+
|
| 44 |
+
const { resolve, relative, dirname, basename } = require('node:path')
|
| 45 |
+
const util = require('node:util')
|
| 46 |
+
const _package = Symbol('_package')
|
| 47 |
+
const _parent = Symbol('_parent')
|
| 48 |
+
const _target = Symbol.for('_target')
|
| 49 |
+
const _fsParent = Symbol('_fsParent')
|
| 50 |
+
const _reloadNamedEdges = Symbol('_reloadNamedEdges')
|
| 51 |
+
// overridden by Link class
|
| 52 |
+
const _loadDeps = Symbol.for('Arborist.Node._loadDeps')
|
| 53 |
+
const _refreshLocation = Symbol.for('_refreshLocation')
|
| 54 |
+
const _changePath = Symbol.for('_changePath')
|
| 55 |
+
// used by Link class as well
|
| 56 |
+
const _delistFromMeta = Symbol.for('_delistFromMeta')
|
| 57 |
+
const _explain = Symbol('_explain')
|
| 58 |
+
const _explanation = Symbol('_explanation')
|
| 59 |
+
|
| 60 |
+
const relpath = require('./relpath.js')
|
| 61 |
+
const consistentResolve = require('./consistent-resolve.js')
|
| 62 |
+
|
| 63 |
+
const printableTree = require('./printable.js')
|
| 64 |
+
const CaseInsensitiveMap = require('./case-insensitive-map.js')
|
| 65 |
+
|
| 66 |
+
const querySelectorAll = require('./query-selector-all.js')
|
| 67 |
+
|
| 68 |
+
class Node {
|
| 69 |
+
#global
|
| 70 |
+
#meta
|
| 71 |
+
#root
|
| 72 |
+
#workspaces
|
| 73 |
+
|
| 74 |
+
constructor (options) {
|
| 75 |
+
// NB: path can be null if it's a link target
|
| 76 |
+
const {
|
| 77 |
+
root,
|
| 78 |
+
path,
|
| 79 |
+
realpath,
|
| 80 |
+
parent,
|
| 81 |
+
error,
|
| 82 |
+
meta,
|
| 83 |
+
fsParent,
|
| 84 |
+
resolved,
|
| 85 |
+
integrity,
|
| 86 |
+
// allow setting name explicitly when we haven't set a path yet
|
| 87 |
+
name,
|
| 88 |
+
children,
|
| 89 |
+
fsChildren,
|
| 90 |
+
installLinks = false,
|
| 91 |
+
legacyPeerDeps = false,
|
| 92 |
+
linksIn,
|
| 93 |
+
isInStore = false,
|
| 94 |
+
hasShrinkwrap,
|
| 95 |
+
overrides,
|
| 96 |
+
loadOverrides = false,
|
| 97 |
+
extraneous = true,
|
| 98 |
+
dev = true,
|
| 99 |
+
optional = true,
|
| 100 |
+
devOptional = true,
|
| 101 |
+
peer = true,
|
| 102 |
+
global = false,
|
| 103 |
+
dummy = false,
|
| 104 |
+
sourceReference = null,
|
| 105 |
+
} = options
|
| 106 |
+
// this object gives querySelectorAll somewhere to stash context about a node
|
| 107 |
+
// while processing a query
|
| 108 |
+
this.queryContext = {}
|
| 109 |
+
|
| 110 |
+
// true if part of a global install
|
| 111 |
+
this.#global = global
|
| 112 |
+
|
| 113 |
+
this.#workspaces = null
|
| 114 |
+
|
| 115 |
+
this.errors = error ? [error] : []
|
| 116 |
+
this.isInStore = isInStore
|
| 117 |
+
|
| 118 |
+
// this will usually be null, except when modeling a
|
| 119 |
+
// package's dependencies in a virtual root.
|
| 120 |
+
this.sourceReference = sourceReference
|
| 121 |
+
|
| 122 |
+
// TODO if this came from pacote.manifest we don't have to do this,
|
| 123 |
+
// we can be told to skip this step
|
| 124 |
+
const pkg = sourceReference ? sourceReference.package
|
| 125 |
+
: normalize(options.pkg || {})
|
| 126 |
+
|
| 127 |
+
this.name = name ||
|
| 128 |
+
nameFromFolder(path || pkg.name || realpath) ||
|
| 129 |
+
pkg.name ||
|
| 130 |
+
null
|
| 131 |
+
|
| 132 |
+
// should be equal if not a link
|
| 133 |
+
this.path = path ? resolve(path) : null
|
| 134 |
+
|
| 135 |
+
if (!this.name && (!this.path || this.path !== dirname(this.path))) {
|
| 136 |
+
throw new TypeError('could not detect node name from path or package')
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
this.realpath = !this.isLink ? this.path : resolve(realpath)
|
| 140 |
+
|
| 141 |
+
this.resolved = resolved || null
|
| 142 |
+
if (!this.resolved) {
|
| 143 |
+
// note: this *only* works for non-file: deps, so we avoid even
|
| 144 |
+
// trying here.
|
| 145 |
+
// file: deps are tracked in package.json will _resolved set to the
|
| 146 |
+
// full path to the tarball or link target. However, if the package
|
| 147 |
+
// is checked into git or moved to another location, that's 100% not
|
| 148 |
+
// portable at all! The _where and _location don't provide much help,
|
| 149 |
+
// since _location is just where the module ended up in the tree,
|
| 150 |
+
// and _where can be different than the actual root if it's a
|
| 151 |
+
// meta-dep deeper in the dependency graph.
|
| 152 |
+
//
|
| 153 |
+
// If we don't have the other oldest indicators of legacy npm, then it's
|
| 154 |
+
// probably what we're getting from pacote, which IS trustworthy.
|
| 155 |
+
//
|
| 156 |
+
// Otherwise, hopefully a shrinkwrap will help us out.
|
| 157 |
+
const resolved = consistentResolve(pkg._resolved)
|
| 158 |
+
if (resolved && !(/^file:/.test(resolved) && pkg._where)) {
|
| 159 |
+
this.resolved = resolved
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
this.integrity = integrity || pkg._integrity || null
|
| 163 |
+
this.hasShrinkwrap = hasShrinkwrap || pkg._hasShrinkwrap || false
|
| 164 |
+
this.installLinks = installLinks
|
| 165 |
+
this.legacyPeerDeps = legacyPeerDeps
|
| 166 |
+
|
| 167 |
+
this.children = new CaseInsensitiveMap()
|
| 168 |
+
this.fsChildren = new Set()
|
| 169 |
+
this.inventory = new Inventory()
|
| 170 |
+
this.tops = new Set()
|
| 171 |
+
this.linksIn = new Set(linksIn || [])
|
| 172 |
+
|
| 173 |
+
// these three are set by an Arborist taking a catalog
|
| 174 |
+
// after the tree is built. We don't get this along the way,
|
| 175 |
+
// because they have a tendency to change as new children are
|
| 176 |
+
// added, especially when they're deduped. Eg, a dev dep may be
|
| 177 |
+
// a 3-levels-deep dependency of a non-dev dep. If we calc the
|
| 178 |
+
// flags along the way, then they'll tend to be invalid by the
|
| 179 |
+
// time we need to look at them.
|
| 180 |
+
if (!dummy) {
|
| 181 |
+
this.dev = dev
|
| 182 |
+
this.optional = optional
|
| 183 |
+
this.devOptional = devOptional
|
| 184 |
+
this.peer = peer
|
| 185 |
+
this.extraneous = extraneous
|
| 186 |
+
this.dummy = false
|
| 187 |
+
} else {
|
| 188 |
+
// true if this is a placeholder for the purpose of serving as a
|
| 189 |
+
// fsParent to link targets that get their deps resolved outside
|
| 190 |
+
// the root tree folder.
|
| 191 |
+
this.dummy = true
|
| 192 |
+
this.dev = false
|
| 193 |
+
this.optional = false
|
| 194 |
+
this.devOptional = false
|
| 195 |
+
this.peer = false
|
| 196 |
+
this.extraneous = false
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
this.edgesIn = new Set()
|
| 200 |
+
this.edgesOut = new CaseInsensitiveMap()
|
| 201 |
+
|
| 202 |
+
// have to set the internal package ref before assigning the parent,
|
| 203 |
+
// because this.package is read when adding to inventory
|
| 204 |
+
this[_package] = pkg && typeof pkg === 'object' ? pkg : {}
|
| 205 |
+
|
| 206 |
+
if (overrides) {
|
| 207 |
+
this.overrides = overrides
|
| 208 |
+
} else if (loadOverrides) {
|
| 209 |
+
const overrides = this[_package].overrides || {}
|
| 210 |
+
if (Object.keys(overrides).length > 0) {
|
| 211 |
+
this.overrides = new OverrideSet({
|
| 212 |
+
overrides: this[_package].overrides,
|
| 213 |
+
})
|
| 214 |
+
}
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
// only relevant for the root and top nodes
|
| 218 |
+
this.meta = meta
|
| 219 |
+
|
| 220 |
+
// Note: this is _slightly_ less efficient for the initial tree
|
| 221 |
+
// building than it could be, but in exchange, it's a much simpler
|
| 222 |
+
// algorithm.
|
| 223 |
+
// If this node has a bunch of children, and those children satisfy
|
| 224 |
+
// its various deps, then we're going to _first_ create all the
|
| 225 |
+
// edges, and _then_ assign the children into place, re-resolving
|
| 226 |
+
// them all in _reloadNamedEdges.
|
| 227 |
+
// A more efficient, but more complicated, approach would be to
|
| 228 |
+
// flag this node as being a part of a tree build, so it could
|
| 229 |
+
// hold off on resolving its deps until its children are in place.
|
| 230 |
+
|
| 231 |
+
// call the parent setter
|
| 232 |
+
// Must be set prior to calling _loadDeps, because top-ness is relevant
|
| 233 |
+
|
| 234 |
+
// will also assign root if present on the parent
|
| 235 |
+
this[_parent] = null
|
| 236 |
+
this.parent = parent || null
|
| 237 |
+
|
| 238 |
+
this[_fsParent] = null
|
| 239 |
+
this.fsParent = fsParent || null
|
| 240 |
+
|
| 241 |
+
// see parent/root setters below.
|
| 242 |
+
// root is set to parent's root if we have a parent, otherwise if it's
|
| 243 |
+
// null, then it's set to the node itself.
|
| 244 |
+
if (!parent && !fsParent) {
|
| 245 |
+
this.root = root || null
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
// mostly a convenience for testing, but also a way to create
|
| 249 |
+
// trees in a more declarative way than setting parent on each
|
| 250 |
+
if (children) {
|
| 251 |
+
for (const c of children) {
|
| 252 |
+
new Node({ ...c, parent: this })
|
| 253 |
+
}
|
| 254 |
+
}
|
| 255 |
+
if (fsChildren) {
|
| 256 |
+
for (const c of fsChildren) {
|
| 257 |
+
new Node({ ...c, fsParent: this })
|
| 258 |
+
}
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
// now load all the dep edges
|
| 262 |
+
this[_loadDeps]()
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
get meta () {
|
| 266 |
+
return this.#meta
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
set meta (meta) {
|
| 270 |
+
this.#meta = meta
|
| 271 |
+
if (meta) {
|
| 272 |
+
meta.add(this)
|
| 273 |
+
}
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
get global () {
|
| 277 |
+
if (this.#root === this) {
|
| 278 |
+
return this.#global
|
| 279 |
+
}
|
| 280 |
+
return this.#root.global
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
// true for packages installed directly in the global node_modules folder
|
| 284 |
+
get globalTop () {
|
| 285 |
+
return this.global && this.parent && this.parent.isProjectRoot
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
get workspaces () {
|
| 289 |
+
return this.#workspaces
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
set workspaces (workspaces) {
|
| 293 |
+
// deletes edges if they already exists
|
| 294 |
+
if (this.#workspaces) {
|
| 295 |
+
for (const name of this.#workspaces.keys()) {
|
| 296 |
+
if (!workspaces.has(name)) {
|
| 297 |
+
this.edgesOut.get(name).detach()
|
| 298 |
+
}
|
| 299 |
+
}
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
this.#workspaces = workspaces
|
| 303 |
+
this.#loadWorkspaces()
|
| 304 |
+
this[_loadDeps]()
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
get binPaths () {
|
| 308 |
+
if (!this.parent) {
|
| 309 |
+
return []
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
return getBinPaths({
|
| 313 |
+
pkg: this[_package],
|
| 314 |
+
path: this.path,
|
| 315 |
+
global: this.global,
|
| 316 |
+
top: this.globalTop,
|
| 317 |
+
})
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
get hasInstallScript () {
|
| 321 |
+
const { hasInstallScript, scripts } = this.package
|
| 322 |
+
const { install, preinstall, postinstall } = scripts || {}
|
| 323 |
+
return !!(hasInstallScript || install || preinstall || postinstall)
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
get version () {
|
| 327 |
+
return this[_package].version || ''
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
get packageName () {
|
| 331 |
+
return this[_package].name || null
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
get pkgid () {
|
| 335 |
+
const { name = '', version = '' } = this.package
|
| 336 |
+
// root package will prefer package name over folder name,
|
| 337 |
+
// and never be called an alias.
|
| 338 |
+
const { isProjectRoot } = this
|
| 339 |
+
const myname = isProjectRoot ? name || this.name
|
| 340 |
+
: this.name
|
| 341 |
+
const alias = !isProjectRoot && name && myname !== name ? `npm:${name}@`
|
| 342 |
+
: ''
|
| 343 |
+
return `${myname}@${alias}${version}`
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
get overridden () {
|
| 347 |
+
return !!(this.overrides && this.overrides.value && this.overrides.name === this.name)
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
get package () {
|
| 351 |
+
return this[_package]
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
set package (pkg) {
|
| 355 |
+
// just detach them all. we could make this _slightly_ more efficient
|
| 356 |
+
// by only detaching the ones that changed, but we'd still have to walk
|
| 357 |
+
// them all, and the comparison logic gets a bit tricky. we generally
|
| 358 |
+
// only do this more than once at the root level, so the resolve() calls
|
| 359 |
+
// are only one level deep, and there's not much to be saved, anyway.
|
| 360 |
+
// simpler to just toss them all out.
|
| 361 |
+
for (const edge of this.edgesOut.values()) {
|
| 362 |
+
edge.detach()
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
this[_explanation] = null
|
| 366 |
+
/* istanbul ignore next - should be impossible */
|
| 367 |
+
if (!pkg || typeof pkg !== 'object') {
|
| 368 |
+
debug(() => {
|
| 369 |
+
throw new Error('setting Node.package to non-object')
|
| 370 |
+
})
|
| 371 |
+
pkg = {}
|
| 372 |
+
}
|
| 373 |
+
this[_package] = pkg
|
| 374 |
+
this.#loadWorkspaces()
|
| 375 |
+
this[_loadDeps]()
|
| 376 |
+
// do a hard reload, since the dependents may now be valid or invalid
|
| 377 |
+
// as a result of the package change.
|
| 378 |
+
this.edgesIn.forEach(edge => edge.reload(true))
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
// node.explain(nodes seen already, edge we're trying to satisfy
|
| 382 |
+
// if edge is not specified, it lists every edge into the node.
|
| 383 |
+
explain (edge = null, seen = []) {
|
| 384 |
+
if (this[_explanation]) {
|
| 385 |
+
return this[_explanation]
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
return this[_explanation] = this[_explain](edge, seen)
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
[_explain] (edge, seen) {
|
| 392 |
+
if (this.isProjectRoot && !this.sourceReference) {
|
| 393 |
+
return {
|
| 394 |
+
location: this.path,
|
| 395 |
+
}
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
const why = {
|
| 399 |
+
name: this.isProjectRoot || this.isTop ? this.packageName : this.name,
|
| 400 |
+
version: this.package.version,
|
| 401 |
+
}
|
| 402 |
+
if (this.errors.length || !this.packageName || !this.package.version) {
|
| 403 |
+
why.errors = this.errors.length ? this.errors : [
|
| 404 |
+
new Error('invalid package: lacks name and/or version'),
|
| 405 |
+
]
|
| 406 |
+
why.package = this.package
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
if (this.root.sourceReference) {
|
| 410 |
+
const { name, version } = this.root.package
|
| 411 |
+
why.whileInstalling = {
|
| 412 |
+
name,
|
| 413 |
+
version,
|
| 414 |
+
path: this.root.sourceReference.path,
|
| 415 |
+
}
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
if (this.sourceReference) {
|
| 419 |
+
return this.sourceReference.explain(edge, seen)
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
if (seen.includes(this)) {
|
| 423 |
+
return why
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
why.location = this.location
|
| 427 |
+
why.isWorkspace = this.isWorkspace
|
| 428 |
+
|
| 429 |
+
// make a new list each time. we can revisit, but not loop.
|
| 430 |
+
seen = seen.concat(this)
|
| 431 |
+
|
| 432 |
+
why.dependents = []
|
| 433 |
+
if (edge) {
|
| 434 |
+
why.dependents.push(edge.explain(seen))
|
| 435 |
+
} else {
|
| 436 |
+
// ignore invalid edges, since those aren't satisfied by this thing,
|
| 437 |
+
// and are not keeping it held in this spot anyway.
|
| 438 |
+
const edges = []
|
| 439 |
+
for (const edge of this.edgesIn) {
|
| 440 |
+
if (!edge.valid && !edge.from.isProjectRoot) {
|
| 441 |
+
continue
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
edges.push(edge)
|
| 445 |
+
}
|
| 446 |
+
for (const edge of edges) {
|
| 447 |
+
why.dependents.push(edge.explain(seen))
|
| 448 |
+
}
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
if (this.linksIn.size) {
|
| 452 |
+
why.linksIn = [...this.linksIn].map(link => link[_explain](edge, seen))
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
return why
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
isDescendantOf (node) {
|
| 459 |
+
for (let p = this; p; p = p.resolveParent) {
|
| 460 |
+
if (p === node) {
|
| 461 |
+
return true
|
| 462 |
+
}
|
| 463 |
+
}
|
| 464 |
+
return false
|
| 465 |
+
}
|
| 466 |
+
|
| 467 |
+
getBundler (path = []) {
|
| 468 |
+
// made a cycle, definitely not bundled!
|
| 469 |
+
if (path.includes(this)) {
|
| 470 |
+
return null
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
path.push(this)
|
| 474 |
+
|
| 475 |
+
const parent = this[_parent]
|
| 476 |
+
if (!parent) {
|
| 477 |
+
return null
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
const pBundler = parent.getBundler(path)
|
| 481 |
+
if (pBundler) {
|
| 482 |
+
return pBundler
|
| 483 |
+
}
|
| 484 |
+
|
| 485 |
+
const ppkg = parent.package
|
| 486 |
+
const bd = ppkg && ppkg.bundleDependencies
|
| 487 |
+
// explicit bundling
|
| 488 |
+
if (Array.isArray(bd) && bd.includes(this.name)) {
|
| 489 |
+
return parent
|
| 490 |
+
}
|
| 491 |
+
|
| 492 |
+
// deps that are deduped up to the bundling level are bundled.
|
| 493 |
+
// however, if they get their dep met further up than that,
|
| 494 |
+
// then they are not bundled. Ie, installing a package with
|
| 495 |
+
// unmet bundled deps will not cause your deps to be bundled.
|
| 496 |
+
for (const edge of this.edgesIn) {
|
| 497 |
+
const eBundler = edge.from.getBundler(path)
|
| 498 |
+
if (!eBundler) {
|
| 499 |
+
continue
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
if (eBundler === parent) {
|
| 503 |
+
return eBundler
|
| 504 |
+
}
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
return null
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
get inBundle () {
|
| 511 |
+
return !!this.getBundler()
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
// when reifying, if a package is technically in a bundleDependencies list,
|
| 515 |
+
// but that list is the root project, we still have to install it. This
|
| 516 |
+
// getter returns true if it's in a dependency's bundle list, not the root's.
|
| 517 |
+
get inDepBundle () {
|
| 518 |
+
const bundler = this.getBundler()
|
| 519 |
+
return !!bundler && bundler !== this.root
|
| 520 |
+
}
|
| 521 |
+
|
| 522 |
+
get isWorkspace () {
|
| 523 |
+
if (this.isProjectRoot) {
|
| 524 |
+
return false
|
| 525 |
+
}
|
| 526 |
+
const { root } = this
|
| 527 |
+
const { type, to } = root.edgesOut.get(this.packageName) || {}
|
| 528 |
+
return type === 'workspace' && to && (to.target === this || to === this)
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
get isRoot () {
|
| 532 |
+
return this === this.root
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
get isProjectRoot () {
|
| 536 |
+
// only treat as project root if it's the actual link that is the root,
|
| 537 |
+
// or the target of the root link, but NOT if it's another link to the
|
| 538 |
+
// same root that happens to be somewhere else.
|
| 539 |
+
return this === this.root || this === this.root.target
|
| 540 |
+
}
|
| 541 |
+
|
| 542 |
+
get isRegistryDependency () {
|
| 543 |
+
if (this.edgesIn.size === 0) {
|
| 544 |
+
return false
|
| 545 |
+
}
|
| 546 |
+
for (const edge of this.edgesIn) {
|
| 547 |
+
if (!npa(edge.spec).registry) {
|
| 548 |
+
return false
|
| 549 |
+
}
|
| 550 |
+
}
|
| 551 |
+
return true
|
| 552 |
+
}
|
| 553 |
+
|
| 554 |
+
* ancestry () {
|
| 555 |
+
for (let anc = this; anc; anc = anc.resolveParent) {
|
| 556 |
+
yield anc
|
| 557 |
+
}
|
| 558 |
+
}
|
| 559 |
+
|
| 560 |
+
set root (root) {
|
| 561 |
+
// setting to null means this is the new root
|
| 562 |
+
// should only ever be one step
|
| 563 |
+
while (root && root.root !== root) {
|
| 564 |
+
root = root.root
|
| 565 |
+
}
|
| 566 |
+
|
| 567 |
+
root = root || this
|
| 568 |
+
|
| 569 |
+
// delete from current root inventory
|
| 570 |
+
this[_delistFromMeta]()
|
| 571 |
+
|
| 572 |
+
// can't set the root (yet) if there's no way to determine location
|
| 573 |
+
// this allows us to do new Node({...}) and then set the root later.
|
| 574 |
+
// just make the assignment so we don't lose it, and move on.
|
| 575 |
+
if (!this.path || !root.realpath || !root.path) {
|
| 576 |
+
this.#root = root
|
| 577 |
+
return
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
// temporarily become a root node
|
| 581 |
+
this.#root = this
|
| 582 |
+
|
| 583 |
+
// break all linksIn, we're going to re-set them if needed later
|
| 584 |
+
for (const link of this.linksIn) {
|
| 585 |
+
link[_target] = null
|
| 586 |
+
this.linksIn.delete(link)
|
| 587 |
+
}
|
| 588 |
+
|
| 589 |
+
// temporarily break this link as well, we'll re-set if possible later
|
| 590 |
+
const { target } = this
|
| 591 |
+
if (this.isLink) {
|
| 592 |
+
if (target) {
|
| 593 |
+
target.linksIn.delete(this)
|
| 594 |
+
if (target.root === this) {
|
| 595 |
+
target[_delistFromMeta]()
|
| 596 |
+
}
|
| 597 |
+
}
|
| 598 |
+
this[_target] = null
|
| 599 |
+
}
|
| 600 |
+
|
| 601 |
+
// if this is part of a cascading root set, then don't do this bit
|
| 602 |
+
// but if the parent/fsParent is in a different set, we have to break
|
| 603 |
+
// that reference before proceeding
|
| 604 |
+
if (this.parent && this.parent.root !== root) {
|
| 605 |
+
this.parent.children.delete(this.name)
|
| 606 |
+
this[_parent] = null
|
| 607 |
+
}
|
| 608 |
+
if (this.fsParent && this.fsParent.root !== root) {
|
| 609 |
+
this.fsParent.fsChildren.delete(this)
|
| 610 |
+
this[_fsParent] = null
|
| 611 |
+
}
|
| 612 |
+
|
| 613 |
+
if (root === this) {
|
| 614 |
+
this[_refreshLocation]()
|
| 615 |
+
} else {
|
| 616 |
+
// setting to some different node.
|
| 617 |
+
const loc = relpath(root.realpath, this.path)
|
| 618 |
+
const current = root.inventory.get(loc)
|
| 619 |
+
|
| 620 |
+
// clobber whatever is there now
|
| 621 |
+
if (current) {
|
| 622 |
+
current.root = null
|
| 623 |
+
}
|
| 624 |
+
|
| 625 |
+
this.#root = root
|
| 626 |
+
// set this.location and add to inventory
|
| 627 |
+
this[_refreshLocation]()
|
| 628 |
+
|
| 629 |
+
// try to find our parent/fsParent in the new root inventory
|
| 630 |
+
for (const p of walkUp(dirname(this.path))) {
|
| 631 |
+
if (p === this.path) {
|
| 632 |
+
continue
|
| 633 |
+
}
|
| 634 |
+
const ploc = relpath(root.realpath, p)
|
| 635 |
+
const parent = root.inventory.get(ploc)
|
| 636 |
+
if (parent) {
|
| 637 |
+
/* istanbul ignore next - impossible */
|
| 638 |
+
if (parent.isLink) {
|
| 639 |
+
debug(() => {
|
| 640 |
+
throw Object.assign(new Error('assigning parentage to link'), {
|
| 641 |
+
path: this.path,
|
| 642 |
+
parent: parent.path,
|
| 643 |
+
parentReal: parent.realpath,
|
| 644 |
+
})
|
| 645 |
+
})
|
| 646 |
+
continue
|
| 647 |
+
}
|
| 648 |
+
const childLoc = `${ploc}${ploc ? '/' : ''}node_modules/${this.name}`
|
| 649 |
+
const isParent = this.location === childLoc
|
| 650 |
+
if (isParent) {
|
| 651 |
+
const oldChild = parent.children.get(this.name)
|
| 652 |
+
if (oldChild && oldChild !== this) {
|
| 653 |
+
oldChild.root = null
|
| 654 |
+
}
|
| 655 |
+
if (this.parent) {
|
| 656 |
+
this.parent.children.delete(this.name)
|
| 657 |
+
this.parent[_reloadNamedEdges](this.name)
|
| 658 |
+
}
|
| 659 |
+
parent.children.set(this.name, this)
|
| 660 |
+
this[_parent] = parent
|
| 661 |
+
// don't do it for links, because they don't have a target yet
|
| 662 |
+
// we'll hit them up a bit later on.
|
| 663 |
+
if (!this.isLink) {
|
| 664 |
+
parent[_reloadNamedEdges](this.name)
|
| 665 |
+
}
|
| 666 |
+
} else {
|
| 667 |
+
/* istanbul ignore if - should be impossible, since we break
|
| 668 |
+
* all fsParent/child relationships when moving? */
|
| 669 |
+
if (this.fsParent) {
|
| 670 |
+
this.fsParent.fsChildren.delete(this)
|
| 671 |
+
}
|
| 672 |
+
parent.fsChildren.add(this)
|
| 673 |
+
this[_fsParent] = parent
|
| 674 |
+
}
|
| 675 |
+
break
|
| 676 |
+
}
|
| 677 |
+
}
|
| 678 |
+
|
| 679 |
+
// if it doesn't have a parent, it's a top node
|
| 680 |
+
if (!this.parent) {
|
| 681 |
+
root.tops.add(this)
|
| 682 |
+
} else {
|
| 683 |
+
root.tops.delete(this)
|
| 684 |
+
}
|
| 685 |
+
|
| 686 |
+
// assign parentage for any nodes that need to have this as a parent
|
| 687 |
+
// this can happen when we have a node at nm/a/nm/b added *before*
|
| 688 |
+
// the node at nm/a, which might have the root node as a fsParent.
|
| 689 |
+
// we can't rely on the public setter here, because it calls into
|
| 690 |
+
// this function to set up these references!
|
| 691 |
+
// check dirname so that /foo isn't treated as the fsparent of /foo-bar
|
| 692 |
+
const nmloc = `${this.location}${this.location ? '/' : ''}node_modules/`
|
| 693 |
+
// only walk top nodes, since anything else already has a parent.
|
| 694 |
+
for (const child of root.tops) {
|
| 695 |
+
const isChild = child.location === nmloc + child.name
|
| 696 |
+
const isFsChild =
|
| 697 |
+
dirname(child.path).startsWith(this.path) &&
|
| 698 |
+
child !== this &&
|
| 699 |
+
!child.parent &&
|
| 700 |
+
(
|
| 701 |
+
!child.fsParent ||
|
| 702 |
+
child.fsParent === this ||
|
| 703 |
+
dirname(this.path).startsWith(child.fsParent.path)
|
| 704 |
+
)
|
| 705 |
+
|
| 706 |
+
if (!isChild && !isFsChild) {
|
| 707 |
+
continue
|
| 708 |
+
}
|
| 709 |
+
|
| 710 |
+
// set up the internal parentage links
|
| 711 |
+
if (this.isLink) {
|
| 712 |
+
child.root = null
|
| 713 |
+
} else {
|
| 714 |
+
// can't possibly have a parent, because it's in tops
|
| 715 |
+
if (child.fsParent) {
|
| 716 |
+
child.fsParent.fsChildren.delete(child)
|
| 717 |
+
}
|
| 718 |
+
child[_fsParent] = null
|
| 719 |
+
if (isChild) {
|
| 720 |
+
this.children.set(child.name, child)
|
| 721 |
+
child[_parent] = this
|
| 722 |
+
root.tops.delete(child)
|
| 723 |
+
} else {
|
| 724 |
+
this.fsChildren.add(child)
|
| 725 |
+
child[_fsParent] = this
|
| 726 |
+
}
|
| 727 |
+
}
|
| 728 |
+
}
|
| 729 |
+
|
| 730 |
+
// look for any nodes with the same realpath. either they're links
|
| 731 |
+
// to that realpath, or a thing at that realpath if we're adding a link
|
| 732 |
+
// (if we're adding a regular node, we already deleted the old one)
|
| 733 |
+
for (const node of root.inventory.query('realpath', this.realpath)) {
|
| 734 |
+
if (node === this) {
|
| 735 |
+
continue
|
| 736 |
+
}
|
| 737 |
+
|
| 738 |
+
/* istanbul ignore next - should be impossible */
|
| 739 |
+
debug(() => {
|
| 740 |
+
if (node.root !== root) {
|
| 741 |
+
throw new Error('inventory contains node from other root')
|
| 742 |
+
}
|
| 743 |
+
})
|
| 744 |
+
|
| 745 |
+
if (this.isLink) {
|
| 746 |
+
const target = node.target
|
| 747 |
+
this[_target] = target
|
| 748 |
+
this[_package] = target.package
|
| 749 |
+
target.linksIn.add(this)
|
| 750 |
+
// reload edges here, because now we have a target
|
| 751 |
+
if (this.parent) {
|
| 752 |
+
this.parent[_reloadNamedEdges](this.name)
|
| 753 |
+
}
|
| 754 |
+
break
|
| 755 |
+
} else {
|
| 756 |
+
/* istanbul ignore else - should be impossible */
|
| 757 |
+
if (node.isLink) {
|
| 758 |
+
node[_target] = this
|
| 759 |
+
node[_package] = this.package
|
| 760 |
+
this.linksIn.add(node)
|
| 761 |
+
if (node.parent) {
|
| 762 |
+
node.parent[_reloadNamedEdges](node.name)
|
| 763 |
+
}
|
| 764 |
+
} else {
|
| 765 |
+
debug(() => {
|
| 766 |
+
throw Object.assign(new Error('duplicate node in root setter'), {
|
| 767 |
+
path: this.path,
|
| 768 |
+
realpath: this.realpath,
|
| 769 |
+
root: root.realpath,
|
| 770 |
+
})
|
| 771 |
+
})
|
| 772 |
+
}
|
| 773 |
+
}
|
| 774 |
+
}
|
| 775 |
+
}
|
| 776 |
+
|
| 777 |
+
// reload all edgesIn where the root doesn't match, so we don't have
|
| 778 |
+
// cross-tree dependency graphs
|
| 779 |
+
for (const edge of this.edgesIn) {
|
| 780 |
+
if (edge.from.root !== root) {
|
| 781 |
+
edge.reload()
|
| 782 |
+
}
|
| 783 |
+
}
|
| 784 |
+
// reload all edgesOut where root doens't match, or is missing, since
|
| 785 |
+
// it might not be missing in the new tree
|
| 786 |
+
for (const edge of this.edgesOut.values()) {
|
| 787 |
+
if (!edge.to || edge.to.root !== root) {
|
| 788 |
+
edge.reload()
|
| 789 |
+
}
|
| 790 |
+
}
|
| 791 |
+
|
| 792 |
+
// now make sure our family comes along for the ride!
|
| 793 |
+
const family = new Set([
|
| 794 |
+
...this.fsChildren,
|
| 795 |
+
...this.children.values(),
|
| 796 |
+
...this.inventory.values(),
|
| 797 |
+
].filter(n => n !== this))
|
| 798 |
+
|
| 799 |
+
for (const child of family) {
|
| 800 |
+
if (child.root !== root) {
|
| 801 |
+
child[_delistFromMeta]()
|
| 802 |
+
child[_parent] = null
|
| 803 |
+
this.children.delete(child.name)
|
| 804 |
+
child[_fsParent] = null
|
| 805 |
+
this.fsChildren.delete(child)
|
| 806 |
+
for (const l of child.linksIn) {
|
| 807 |
+
l[_target] = null
|
| 808 |
+
child.linksIn.delete(l)
|
| 809 |
+
}
|
| 810 |
+
}
|
| 811 |
+
}
|
| 812 |
+
for (const child of family) {
|
| 813 |
+
if (child.root !== root) {
|
| 814 |
+
child.root = root
|
| 815 |
+
}
|
| 816 |
+
}
|
| 817 |
+
|
| 818 |
+
// if we had a target, and didn't find one in the new root, then bring
|
| 819 |
+
// it over as well, but only if we're setting the link into a new root,
|
| 820 |
+
// as we don't want to lose the target any time we remove a link.
|
| 821 |
+
if (this.isLink && target && !this.target && root !== this) {
|
| 822 |
+
target.root = root
|
| 823 |
+
}
|
| 824 |
+
|
| 825 |
+
if (!this.overrides && this.parent && this.parent.overrides) {
|
| 826 |
+
this.overrides = this.parent.overrides.getNodeRule(this)
|
| 827 |
+
}
|
| 828 |
+
// tree should always be valid upon root setter completion.
|
| 829 |
+
treeCheck(this)
|
| 830 |
+
if (this !== root) {
|
| 831 |
+
treeCheck(root)
|
| 832 |
+
}
|
| 833 |
+
}
|
| 834 |
+
|
| 835 |
+
get root () {
|
| 836 |
+
return this.#root || this
|
| 837 |
+
}
|
| 838 |
+
|
| 839 |
+
#loadWorkspaces () {
|
| 840 |
+
if (!this.#workspaces) {
|
| 841 |
+
return
|
| 842 |
+
}
|
| 843 |
+
|
| 844 |
+
for (const [name, path] of this.#workspaces.entries()) {
|
| 845 |
+
new Edge({ from: this, name, spec: `file:${path}`, type: 'workspace' })
|
| 846 |
+
}
|
| 847 |
+
}
|
| 848 |
+
|
| 849 |
+
[_loadDeps] () {
|
| 850 |
+
// Caveat! Order is relevant!
|
| 851 |
+
// Packages in optionalDependencies are optional.
|
| 852 |
+
// Packages in both deps and devDeps are required.
|
| 853 |
+
// Note the subtle breaking change from v6: it is no longer possible
|
| 854 |
+
// to have a different spec for a devDep than production dep.
|
| 855 |
+
|
| 856 |
+
// Linked targets that are disconnected from the tree are tops,
|
| 857 |
+
// but don't have a 'path' field, only a 'realpath', because we
|
| 858 |
+
// don't know their canonical location. We don't need their devDeps.
|
| 859 |
+
const pd = this.package.peerDependencies
|
| 860 |
+
const ad = this.package.acceptDependencies || {}
|
| 861 |
+
if (pd && typeof pd === 'object' && !this.legacyPeerDeps) {
|
| 862 |
+
const pm = this.package.peerDependenciesMeta || {}
|
| 863 |
+
const peerDependencies = {}
|
| 864 |
+
const peerOptional = {}
|
| 865 |
+
for (const [name, dep] of Object.entries(pd)) {
|
| 866 |
+
if (pm[name]?.optional) {
|
| 867 |
+
peerOptional[name] = dep
|
| 868 |
+
} else {
|
| 869 |
+
peerDependencies[name] = dep
|
| 870 |
+
}
|
| 871 |
+
}
|
| 872 |
+
this.#loadDepType(peerDependencies, 'peer', ad)
|
| 873 |
+
this.#loadDepType(peerOptional, 'peerOptional', ad)
|
| 874 |
+
}
|
| 875 |
+
|
| 876 |
+
this.#loadDepType(this.package.dependencies, 'prod', ad)
|
| 877 |
+
this.#loadDepType(this.package.optionalDependencies, 'optional', ad)
|
| 878 |
+
|
| 879 |
+
const { globalTop, isTop, path, sourceReference } = this
|
| 880 |
+
const {
|
| 881 |
+
globalTop: srcGlobalTop,
|
| 882 |
+
isTop: srcTop,
|
| 883 |
+
path: srcPath,
|
| 884 |
+
} = sourceReference || {}
|
| 885 |
+
const thisDev = isTop && !globalTop && path
|
| 886 |
+
const srcDev = !sourceReference || srcTop && !srcGlobalTop && srcPath
|
| 887 |
+
if (thisDev && srcDev) {
|
| 888 |
+
this.#loadDepType(this.package.devDependencies, 'dev', ad)
|
| 889 |
+
}
|
| 890 |
+
}
|
| 891 |
+
|
| 892 |
+
#loadDepType (deps, type, ad) {
|
| 893 |
+
// Because of the order in which _loadDeps runs, we always want to
|
| 894 |
+
// prioritize a new edge over an existing one
|
| 895 |
+
for (const [name, spec] of Object.entries(deps || {})) {
|
| 896 |
+
const current = this.edgesOut.get(name)
|
| 897 |
+
if (!current || current.type !== 'workspace') {
|
| 898 |
+
new Edge({ from: this, name, spec, accept: ad[name], type })
|
| 899 |
+
}
|
| 900 |
+
}
|
| 901 |
+
}
|
| 902 |
+
|
| 903 |
+
get fsParent () {
|
| 904 |
+
// in debug setter prevents fsParent from being this
|
| 905 |
+
return this[_fsParent]
|
| 906 |
+
}
|
| 907 |
+
|
| 908 |
+
set fsParent (fsParent) {
|
| 909 |
+
if (!fsParent) {
|
| 910 |
+
if (this[_fsParent]) {
|
| 911 |
+
this.root = null
|
| 912 |
+
}
|
| 913 |
+
return
|
| 914 |
+
}
|
| 915 |
+
|
| 916 |
+
debug(() => {
|
| 917 |
+
if (fsParent === this) {
|
| 918 |
+
throw new Error('setting node to its own fsParent')
|
| 919 |
+
}
|
| 920 |
+
|
| 921 |
+
if (fsParent.realpath === this.realpath) {
|
| 922 |
+
throw new Error('setting fsParent to same path')
|
| 923 |
+
}
|
| 924 |
+
|
| 925 |
+
// the initial set MUST be an actual walk-up from the realpath
|
| 926 |
+
// subsequent sets will re-root on the new fsParent's path.
|
| 927 |
+
if (!this[_fsParent] && this.realpath.indexOf(fsParent.realpath) !== 0) {
|
| 928 |
+
throw Object.assign(new Error('setting fsParent improperly'), {
|
| 929 |
+
path: this.path,
|
| 930 |
+
realpath: this.realpath,
|
| 931 |
+
fsParent: {
|
| 932 |
+
path: fsParent.path,
|
| 933 |
+
realpath: fsParent.realpath,
|
| 934 |
+
},
|
| 935 |
+
})
|
| 936 |
+
}
|
| 937 |
+
})
|
| 938 |
+
|
| 939 |
+
if (fsParent.isLink) {
|
| 940 |
+
fsParent = fsParent.target
|
| 941 |
+
}
|
| 942 |
+
|
| 943 |
+
// setting a thing to its own fsParent is not normal, but no-op for safety
|
| 944 |
+
if (this === fsParent || fsParent.realpath === this.realpath) {
|
| 945 |
+
return
|
| 946 |
+
}
|
| 947 |
+
|
| 948 |
+
// nothing to do
|
| 949 |
+
if (this[_fsParent] === fsParent) {
|
| 950 |
+
return
|
| 951 |
+
}
|
| 952 |
+
|
| 953 |
+
const oldFsParent = this[_fsParent]
|
| 954 |
+
const newPath = !oldFsParent ? this.path
|
| 955 |
+
: resolve(fsParent.path, relative(oldFsParent.path, this.path))
|
| 956 |
+
const nmPath = resolve(fsParent.path, 'node_modules', this.name)
|
| 957 |
+
|
| 958 |
+
// this is actually the parent, set that instead
|
| 959 |
+
if (newPath === nmPath) {
|
| 960 |
+
this.parent = fsParent
|
| 961 |
+
return
|
| 962 |
+
}
|
| 963 |
+
|
| 964 |
+
const pathChange = newPath !== this.path
|
| 965 |
+
|
| 966 |
+
// remove from old parent/fsParent
|
| 967 |
+
const oldParent = this.parent
|
| 968 |
+
const oldName = this.name
|
| 969 |
+
if (this.parent) {
|
| 970 |
+
this.parent.children.delete(this.name)
|
| 971 |
+
this[_parent] = null
|
| 972 |
+
}
|
| 973 |
+
if (this.fsParent) {
|
| 974 |
+
this.fsParent.fsChildren.delete(this)
|
| 975 |
+
this[_fsParent] = null
|
| 976 |
+
}
|
| 977 |
+
|
| 978 |
+
// update this.path/realpath for this and all children/fsChildren
|
| 979 |
+
if (pathChange) {
|
| 980 |
+
this[_changePath](newPath)
|
| 981 |
+
}
|
| 982 |
+
|
| 983 |
+
if (oldParent) {
|
| 984 |
+
oldParent[_reloadNamedEdges](oldName)
|
| 985 |
+
}
|
| 986 |
+
|
| 987 |
+
// clobbers anything at that path, resets all appropriate references
|
| 988 |
+
this.root = fsParent.root
|
| 989 |
+
}
|
| 990 |
+
|
| 991 |
+
// is it safe to replace one node with another? check the edges to
|
| 992 |
+
// make sure no one will get upset. Note that the node might end up
|
| 993 |
+
// having its own unmet dependencies, if the new node has new deps.
|
| 994 |
+
// Note that there are cases where Arborist will opt to insert a node
|
| 995 |
+
// into the tree even though this function returns false! This is
|
| 996 |
+
// necessary when a root dependency is added or updated, or when a
|
| 997 |
+
// root dependency brings peer deps along with it. In that case, we
|
| 998 |
+
// will go ahead and create the invalid state, and then try to resolve
|
| 999 |
+
// it with more tree construction, because it's a user request.
|
| 1000 |
+
canReplaceWith (node, ignorePeers) {
|
| 1001 |
+
if (node.name !== this.name) {
|
| 1002 |
+
return false
|
| 1003 |
+
}
|
| 1004 |
+
|
| 1005 |
+
if (node.packageName !== this.packageName) {
|
| 1006 |
+
return false
|
| 1007 |
+
}
|
| 1008 |
+
|
| 1009 |
+
// XXX need to check for two root nodes?
|
| 1010 |
+
if (node.overrides !== this.overrides) {
|
| 1011 |
+
return false
|
| 1012 |
+
}
|
| 1013 |
+
ignorePeers = new Set(ignorePeers)
|
| 1014 |
+
|
| 1015 |
+
// gather up all the deps of this node and that are only depended
|
| 1016 |
+
// upon by deps of this node. those ones don't count, since
|
| 1017 |
+
// they'll be replaced if this node is replaced anyway.
|
| 1018 |
+
const depSet = gatherDepSet([this], e => e.to !== this && e.valid)
|
| 1019 |
+
|
| 1020 |
+
for (const edge of this.edgesIn) {
|
| 1021 |
+
// when replacing peer sets, we need to be able to replace the entire
|
| 1022 |
+
// peer group, which means we ignore incoming edges from other peers
|
| 1023 |
+
// within the replacement set.
|
| 1024 |
+
if (!this.isTop &&
|
| 1025 |
+
edge.from.parent === this.parent &&
|
| 1026 |
+
edge.peer &&
|
| 1027 |
+
ignorePeers.has(edge.from.name)) {
|
| 1028 |
+
continue
|
| 1029 |
+
}
|
| 1030 |
+
|
| 1031 |
+
// only care about edges that don't originate from this node
|
| 1032 |
+
if (!depSet.has(edge.from) && !edge.satisfiedBy(node)) {
|
| 1033 |
+
return false
|
| 1034 |
+
}
|
| 1035 |
+
}
|
| 1036 |
+
|
| 1037 |
+
return true
|
| 1038 |
+
}
|
| 1039 |
+
|
| 1040 |
+
canReplace (node, ignorePeers) {
|
| 1041 |
+
return node.canReplaceWith(this, ignorePeers)
|
| 1042 |
+
}
|
| 1043 |
+
|
| 1044 |
+
// return true if it's safe to remove this node, because anything that
|
| 1045 |
+
// is depending on it would be fine with the thing that they would resolve
|
| 1046 |
+
// to if it was removed, or nothing is depending on it in the first place.
|
| 1047 |
+
canDedupe (preferDedupe = false) {
|
| 1048 |
+
// not allowed to mess with shrinkwraps or bundles
|
| 1049 |
+
if (this.inDepBundle || this.inShrinkwrap) {
|
| 1050 |
+
return false
|
| 1051 |
+
}
|
| 1052 |
+
|
| 1053 |
+
// it's a top level pkg, or a dep of one
|
| 1054 |
+
if (!this.resolveParent || !this.resolveParent.resolveParent) {
|
| 1055 |
+
return false
|
| 1056 |
+
}
|
| 1057 |
+
|
| 1058 |
+
// no one wants it, remove it
|
| 1059 |
+
if (this.edgesIn.size === 0) {
|
| 1060 |
+
return true
|
| 1061 |
+
}
|
| 1062 |
+
|
| 1063 |
+
const other = this.resolveParent.resolveParent.resolve(this.name)
|
| 1064 |
+
|
| 1065 |
+
// nothing else, need this one
|
| 1066 |
+
if (!other) {
|
| 1067 |
+
return false
|
| 1068 |
+
}
|
| 1069 |
+
|
| 1070 |
+
// if it's the same thing, then always fine to remove
|
| 1071 |
+
if (other.matches(this)) {
|
| 1072 |
+
return true
|
| 1073 |
+
}
|
| 1074 |
+
|
| 1075 |
+
// if the other thing can't replace this, then skip it
|
| 1076 |
+
if (!other.canReplace(this)) {
|
| 1077 |
+
return false
|
| 1078 |
+
}
|
| 1079 |
+
|
| 1080 |
+
// if we prefer dedupe, or if the version is greater/equal, take the other
|
| 1081 |
+
if (preferDedupe || semver.gte(other.version, this.version)) {
|
| 1082 |
+
return true
|
| 1083 |
+
}
|
| 1084 |
+
|
| 1085 |
+
return false
|
| 1086 |
+
}
|
| 1087 |
+
|
| 1088 |
+
satisfies (requested) {
|
| 1089 |
+
if (requested instanceof Edge) {
|
| 1090 |
+
return this.name === requested.name && requested.satisfiedBy(this)
|
| 1091 |
+
}
|
| 1092 |
+
|
| 1093 |
+
const parsed = npa(requested)
|
| 1094 |
+
const { name = this.name, rawSpec: spec } = parsed
|
| 1095 |
+
return this.name === name && this.satisfies(new Edge({
|
| 1096 |
+
from: new Node({ path: this.root.realpath }),
|
| 1097 |
+
type: 'prod',
|
| 1098 |
+
name,
|
| 1099 |
+
spec,
|
| 1100 |
+
}))
|
| 1101 |
+
}
|
| 1102 |
+
|
| 1103 |
+
matches (node) {
|
| 1104 |
+
// if the nodes are literally the same object, obviously a match.
|
| 1105 |
+
if (node === this) {
|
| 1106 |
+
return true
|
| 1107 |
+
}
|
| 1108 |
+
|
| 1109 |
+
// if the names don't match, they're different things, even if
|
| 1110 |
+
// the package contents are identical.
|
| 1111 |
+
if (node.name !== this.name) {
|
| 1112 |
+
return false
|
| 1113 |
+
}
|
| 1114 |
+
|
| 1115 |
+
// if they're links, they match if the targets match
|
| 1116 |
+
if (this.isLink) {
|
| 1117 |
+
return node.isLink && this.target.matches(node.target)
|
| 1118 |
+
}
|
| 1119 |
+
|
| 1120 |
+
// if they're two project root nodes, they're different if the paths differ
|
| 1121 |
+
if (this.isProjectRoot && node.isProjectRoot) {
|
| 1122 |
+
return this.path === node.path
|
| 1123 |
+
}
|
| 1124 |
+
|
| 1125 |
+
// if the integrity matches, then they're the same.
|
| 1126 |
+
if (this.integrity && node.integrity) {
|
| 1127 |
+
return this.integrity === node.integrity
|
| 1128 |
+
}
|
| 1129 |
+
|
| 1130 |
+
// if no integrity, check resolved
|
| 1131 |
+
if (this.resolved && node.resolved) {
|
| 1132 |
+
return this.resolved === node.resolved
|
| 1133 |
+
}
|
| 1134 |
+
|
| 1135 |
+
// if no resolved, check both package name and version
|
| 1136 |
+
// otherwise, conclude that they are different things
|
| 1137 |
+
return this.packageName && node.packageName &&
|
| 1138 |
+
this.packageName === node.packageName &&
|
| 1139 |
+
this.version && node.version &&
|
| 1140 |
+
this.version === node.version
|
| 1141 |
+
}
|
| 1142 |
+
|
| 1143 |
+
// replace this node with the supplied argument
|
| 1144 |
+
// Useful when mutating an ideal tree, so we can avoid having to call
|
| 1145 |
+
// the parent/root setters more than necessary.
|
| 1146 |
+
replaceWith (node) {
|
| 1147 |
+
node.replace(this)
|
| 1148 |
+
}
|
| 1149 |
+
|
| 1150 |
+
replace (node) {
|
| 1151 |
+
this[_delistFromMeta]()
|
| 1152 |
+
|
| 1153 |
+
// if the name matches, but is not identical, we are intending to clobber
|
| 1154 |
+
// something case-insensitively, so merely setting name and path won't
|
| 1155 |
+
// have the desired effect. just set the path so it'll collide in the
|
| 1156 |
+
// parent's children map, and leave it at that.
|
| 1157 |
+
if (node.parent?.children.get(this.name) === node) {
|
| 1158 |
+
this.path = resolve(node.parent.path, 'node_modules', this.name)
|
| 1159 |
+
} else {
|
| 1160 |
+
this.path = node.path
|
| 1161 |
+
this.name = node.name
|
| 1162 |
+
}
|
| 1163 |
+
|
| 1164 |
+
if (!this.isLink) {
|
| 1165 |
+
this.realpath = this.path
|
| 1166 |
+
}
|
| 1167 |
+
this[_refreshLocation]()
|
| 1168 |
+
|
| 1169 |
+
// keep children when a node replaces another
|
| 1170 |
+
if (!this.isLink) {
|
| 1171 |
+
for (const kid of node.children.values()) {
|
| 1172 |
+
kid.parent = this
|
| 1173 |
+
}
|
| 1174 |
+
if (node.isLink && node.target) {
|
| 1175 |
+
node.target.root = null
|
| 1176 |
+
}
|
| 1177 |
+
}
|
| 1178 |
+
|
| 1179 |
+
if (!node.isRoot) {
|
| 1180 |
+
this.root = node.root
|
| 1181 |
+
}
|
| 1182 |
+
|
| 1183 |
+
treeCheck(this)
|
| 1184 |
+
}
|
| 1185 |
+
|
| 1186 |
+
get inShrinkwrap () {
|
| 1187 |
+
return this.parent &&
|
| 1188 |
+
(this.parent.hasShrinkwrap || this.parent.inShrinkwrap)
|
| 1189 |
+
}
|
| 1190 |
+
|
| 1191 |
+
get parent () {
|
| 1192 |
+
// setter prevents _parent from being this
|
| 1193 |
+
return this[_parent]
|
| 1194 |
+
}
|
| 1195 |
+
|
| 1196 |
+
// This setter keeps everything in order when we move a node from
|
| 1197 |
+
// one point in a logical tree to another. Edges get reloaded,
|
| 1198 |
+
// metadata updated, etc. It's also called when we *replace* a node
|
| 1199 |
+
// with another by the same name (eg, to update or dedupe).
|
| 1200 |
+
// This does a couple of walks out on the node_modules tree, recursing
|
| 1201 |
+
// into child nodes. However, as setting the parent is typically done
|
| 1202 |
+
// with nodes that don't have have many children, and (deduped) package
|
| 1203 |
+
// trees tend to be broad rather than deep, it's not that bad.
|
| 1204 |
+
// The only walk that starts from the parent rather than this node is
|
| 1205 |
+
// limited by edge name.
|
| 1206 |
+
set parent (parent) {
|
| 1207 |
+
// when setting to null, just remove it from the tree entirely
|
| 1208 |
+
if (!parent) {
|
| 1209 |
+
// but only delete it if we actually had a parent in the first place
|
| 1210 |
+
// otherwise it's just setting to null when it's already null
|
| 1211 |
+
if (this[_parent]) {
|
| 1212 |
+
this.root = null
|
| 1213 |
+
}
|
| 1214 |
+
return
|
| 1215 |
+
}
|
| 1216 |
+
|
| 1217 |
+
if (parent.isLink) {
|
| 1218 |
+
parent = parent.target
|
| 1219 |
+
}
|
| 1220 |
+
|
| 1221 |
+
// setting a thing to its own parent is not normal, but no-op for safety
|
| 1222 |
+
if (this === parent) {
|
| 1223 |
+
return
|
| 1224 |
+
}
|
| 1225 |
+
|
| 1226 |
+
const oldParent = this[_parent]
|
| 1227 |
+
|
| 1228 |
+
// nothing to do
|
| 1229 |
+
if (oldParent === parent) {
|
| 1230 |
+
return
|
| 1231 |
+
}
|
| 1232 |
+
|
| 1233 |
+
// ok now we know something is actually changing, and parent is not a link
|
| 1234 |
+
const newPath = resolve(parent.path, 'node_modules', this.name)
|
| 1235 |
+
const pathChange = newPath !== this.path
|
| 1236 |
+
|
| 1237 |
+
// remove from old parent/fsParent
|
| 1238 |
+
if (oldParent) {
|
| 1239 |
+
oldParent.children.delete(this.name)
|
| 1240 |
+
this[_parent] = null
|
| 1241 |
+
}
|
| 1242 |
+
if (this.fsParent) {
|
| 1243 |
+
this.fsParent.fsChildren.delete(this)
|
| 1244 |
+
this[_fsParent] = null
|
| 1245 |
+
}
|
| 1246 |
+
|
| 1247 |
+
// update this.path/realpath for this and all children/fsChildren
|
| 1248 |
+
if (pathChange) {
|
| 1249 |
+
this[_changePath](newPath)
|
| 1250 |
+
}
|
| 1251 |
+
|
| 1252 |
+
if (parent.overrides) {
|
| 1253 |
+
this.overrides = parent.overrides.getNodeRule(this)
|
| 1254 |
+
}
|
| 1255 |
+
|
| 1256 |
+
// clobbers anything at that path, resets all appropriate references
|
| 1257 |
+
this.root = parent.root
|
| 1258 |
+
}
|
| 1259 |
+
|
| 1260 |
+
// Call this before changing path or updating the _root reference.
|
| 1261 |
+
// Removes the node from its root the metadata and inventory.
|
| 1262 |
+
[_delistFromMeta] () {
|
| 1263 |
+
const root = this.root
|
| 1264 |
+
if (!root.realpath || !this.path) {
|
| 1265 |
+
return
|
| 1266 |
+
}
|
| 1267 |
+
root.inventory.delete(this)
|
| 1268 |
+
root.tops.delete(this)
|
| 1269 |
+
if (root.meta) {
|
| 1270 |
+
root.meta.delete(this.path)
|
| 1271 |
+
}
|
| 1272 |
+
/* istanbul ignore next - should be impossible */
|
| 1273 |
+
debug(() => {
|
| 1274 |
+
if ([...root.inventory.values()].includes(this)) {
|
| 1275 |
+
throw new Error('failed to delist')
|
| 1276 |
+
}
|
| 1277 |
+
})
|
| 1278 |
+
}
|
| 1279 |
+
|
| 1280 |
+
// update this.path/realpath and the paths of all children/fsChildren
|
| 1281 |
+
[_changePath] (newPath) {
|
| 1282 |
+
// have to de-list before changing paths
|
| 1283 |
+
this[_delistFromMeta]()
|
| 1284 |
+
const oldPath = this.path
|
| 1285 |
+
this.path = newPath
|
| 1286 |
+
const namePattern = /(?:^|\/|\\)node_modules[\\/](@[^/\\]+[\\/][^\\/]+|[^\\/]+)$/
|
| 1287 |
+
const nameChange = newPath.match(namePattern)
|
| 1288 |
+
if (nameChange && this.name !== nameChange[1]) {
|
| 1289 |
+
this.name = nameChange[1].replace(/\\/g, '/')
|
| 1290 |
+
}
|
| 1291 |
+
|
| 1292 |
+
// if we move a link target, update link realpaths
|
| 1293 |
+
if (!this.isLink) {
|
| 1294 |
+
this.realpath = newPath
|
| 1295 |
+
for (const link of this.linksIn) {
|
| 1296 |
+
link[_delistFromMeta]()
|
| 1297 |
+
link.realpath = newPath
|
| 1298 |
+
link[_refreshLocation]()
|
| 1299 |
+
}
|
| 1300 |
+
}
|
| 1301 |
+
// if we move /x to /y, then a module at /x/a/b becomes /y/a/b
|
| 1302 |
+
for (const child of this.fsChildren) {
|
| 1303 |
+
child[_changePath](resolve(newPath, relative(oldPath, child.path)))
|
| 1304 |
+
}
|
| 1305 |
+
for (const [name, child] of this.children.entries()) {
|
| 1306 |
+
child[_changePath](resolve(newPath, 'node_modules', name))
|
| 1307 |
+
}
|
| 1308 |
+
|
| 1309 |
+
this[_refreshLocation]()
|
| 1310 |
+
}
|
| 1311 |
+
|
| 1312 |
+
// Called whenever the root/parent is changed.
|
| 1313 |
+
// NB: need to remove from former root's meta/inventory and then update
|
| 1314 |
+
// this.path BEFORE calling this method!
|
| 1315 |
+
[_refreshLocation] () {
|
| 1316 |
+
const root = this.root
|
| 1317 |
+
const loc = relpath(root.realpath, this.path)
|
| 1318 |
+
|
| 1319 |
+
this.location = loc
|
| 1320 |
+
|
| 1321 |
+
root.inventory.add(this)
|
| 1322 |
+
if (root.meta) {
|
| 1323 |
+
root.meta.add(this)
|
| 1324 |
+
}
|
| 1325 |
+
}
|
| 1326 |
+
|
| 1327 |
+
assertRootOverrides () {
|
| 1328 |
+
if (!this.isProjectRoot || !this.overrides) {
|
| 1329 |
+
return
|
| 1330 |
+
}
|
| 1331 |
+
|
| 1332 |
+
for (const edge of this.edgesOut.values()) {
|
| 1333 |
+
// if these differ an override has been applied, those are not allowed
|
| 1334 |
+
// for top level dependencies so throw an error
|
| 1335 |
+
if (edge.spec !== edge.rawSpec && !edge.spec.startsWith('$')) {
|
| 1336 |
+
throw Object.assign(new Error(`Override for ${edge.name}@${edge.rawSpec} conflicts with direct dependency`), { code: 'EOVERRIDE' })
|
| 1337 |
+
}
|
| 1338 |
+
}
|
| 1339 |
+
}
|
| 1340 |
+
|
| 1341 |
+
addEdgeOut (edge) {
|
| 1342 |
+
if (this.overrides) {
|
| 1343 |
+
edge.overrides = this.overrides.getEdgeRule(edge)
|
| 1344 |
+
}
|
| 1345 |
+
|
| 1346 |
+
this.edgesOut.set(edge.name, edge)
|
| 1347 |
+
}
|
| 1348 |
+
|
| 1349 |
+
addEdgeIn (edge) {
|
| 1350 |
+
if (edge.overrides) {
|
| 1351 |
+
this.overrides = edge.overrides
|
| 1352 |
+
}
|
| 1353 |
+
|
| 1354 |
+
this.edgesIn.add(edge)
|
| 1355 |
+
|
| 1356 |
+
// try to get metadata from the yarn.lock file
|
| 1357 |
+
if (this.root.meta) {
|
| 1358 |
+
this.root.meta.addEdge(edge)
|
| 1359 |
+
}
|
| 1360 |
+
}
|
| 1361 |
+
|
| 1362 |
+
[_reloadNamedEdges] (name, rootLoc = this.location) {
|
| 1363 |
+
const edge = this.edgesOut.get(name)
|
| 1364 |
+
// if we don't have an edge, do nothing, but keep descending
|
| 1365 |
+
const rootLocResolved = edge && edge.to &&
|
| 1366 |
+
edge.to.location === `${rootLoc}/node_modules/${edge.name}`
|
| 1367 |
+
const sameResolved = edge && this.resolve(name) === edge.to
|
| 1368 |
+
const recheck = rootLocResolved || !sameResolved
|
| 1369 |
+
if (edge && recheck) {
|
| 1370 |
+
edge.reload(true)
|
| 1371 |
+
}
|
| 1372 |
+
for (const c of this.children.values()) {
|
| 1373 |
+
c[_reloadNamedEdges](name, rootLoc)
|
| 1374 |
+
}
|
| 1375 |
+
|
| 1376 |
+
for (const c of this.fsChildren) {
|
| 1377 |
+
c[_reloadNamedEdges](name, rootLoc)
|
| 1378 |
+
}
|
| 1379 |
+
}
|
| 1380 |
+
|
| 1381 |
+
get isLink () {
|
| 1382 |
+
return false
|
| 1383 |
+
}
|
| 1384 |
+
|
| 1385 |
+
get target () {
|
| 1386 |
+
return this
|
| 1387 |
+
}
|
| 1388 |
+
|
| 1389 |
+
set target (n) {
|
| 1390 |
+
debug(() => {
|
| 1391 |
+
throw Object.assign(new Error('cannot set target on non-Link Nodes'), {
|
| 1392 |
+
path: this.path,
|
| 1393 |
+
})
|
| 1394 |
+
})
|
| 1395 |
+
}
|
| 1396 |
+
|
| 1397 |
+
get depth () {
|
| 1398 |
+
if (this.isTop) {
|
| 1399 |
+
return 0
|
| 1400 |
+
}
|
| 1401 |
+
return this.parent.depth + 1
|
| 1402 |
+
}
|
| 1403 |
+
|
| 1404 |
+
get isTop () {
|
| 1405 |
+
return !this.parent || this.globalTop
|
| 1406 |
+
}
|
| 1407 |
+
|
| 1408 |
+
get top () {
|
| 1409 |
+
if (this.isTop) {
|
| 1410 |
+
return this
|
| 1411 |
+
}
|
| 1412 |
+
return this.parent.top
|
| 1413 |
+
}
|
| 1414 |
+
|
| 1415 |
+
get isFsTop () {
|
| 1416 |
+
return !this.fsParent
|
| 1417 |
+
}
|
| 1418 |
+
|
| 1419 |
+
get fsTop () {
|
| 1420 |
+
if (this.isFsTop) {
|
| 1421 |
+
return this
|
| 1422 |
+
}
|
| 1423 |
+
return this.fsParent.fsTop
|
| 1424 |
+
}
|
| 1425 |
+
|
| 1426 |
+
get resolveParent () {
|
| 1427 |
+
return this.parent || this.fsParent
|
| 1428 |
+
}
|
| 1429 |
+
|
| 1430 |
+
resolve (name) {
|
| 1431 |
+
/* istanbul ignore next - should be impossible,
|
| 1432 |
+
* but I keep doing this mistake in tests */
|
| 1433 |
+
debug(() => {
|
| 1434 |
+
if (typeof name !== 'string' || !name) {
|
| 1435 |
+
throw new Error('non-string passed to Node.resolve')
|
| 1436 |
+
}
|
| 1437 |
+
})
|
| 1438 |
+
const mine = this.children.get(name)
|
| 1439 |
+
if (mine) {
|
| 1440 |
+
return mine
|
| 1441 |
+
}
|
| 1442 |
+
const resolveParent = this.resolveParent
|
| 1443 |
+
if (resolveParent) {
|
| 1444 |
+
return resolveParent.resolve(name)
|
| 1445 |
+
}
|
| 1446 |
+
return null
|
| 1447 |
+
}
|
| 1448 |
+
|
| 1449 |
+
inNodeModules () {
|
| 1450 |
+
const rp = this.realpath
|
| 1451 |
+
const name = this.name
|
| 1452 |
+
const scoped = name.charAt(0) === '@'
|
| 1453 |
+
const d = dirname(rp)
|
| 1454 |
+
const nm = scoped ? dirname(d) : d
|
| 1455 |
+
const dir = dirname(nm)
|
| 1456 |
+
const base = scoped ? `${basename(d)}/${basename(rp)}` : basename(rp)
|
| 1457 |
+
return base === name && basename(nm) === 'node_modules' ? dir : false
|
| 1458 |
+
}
|
| 1459 |
+
|
| 1460 |
+
// maybe accept both string value or array of strings
|
| 1461 |
+
// seems to be what dom API does
|
| 1462 |
+
querySelectorAll (query, opts) {
|
| 1463 |
+
return querySelectorAll(this, query, opts)
|
| 1464 |
+
}
|
| 1465 |
+
|
| 1466 |
+
toJSON () {
|
| 1467 |
+
return printableTree(this)
|
| 1468 |
+
}
|
| 1469 |
+
|
| 1470 |
+
[util.inspect.custom] () {
|
| 1471 |
+
return this.toJSON()
|
| 1472 |
+
}
|
| 1473 |
+
}
|
| 1474 |
+
|
| 1475 |
+
module.exports = Node
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/optional-set.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// when an optional dep fails to install, we need to remove the branch of the
|
| 2 |
+
// graph up to the first optionalDependencies, as well as any nodes that are
|
| 3 |
+
// only required by other nodes in the set.
|
| 4 |
+
//
|
| 5 |
+
// This function finds the set of nodes that will need to be removed in that
|
| 6 |
+
// case.
|
| 7 |
+
//
|
| 8 |
+
// Note that this is *only* going to work with trees where calcDepFlags
|
| 9 |
+
// has been called, because we rely on the node.optional flag.
|
| 10 |
+
|
| 11 |
+
const gatherDepSet = require('./gather-dep-set.js')
|
| 12 |
+
const optionalSet = node => {
|
| 13 |
+
if (!node.optional) {
|
| 14 |
+
return new Set()
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
// start with the node, then walk up the dependency graph until we
|
| 18 |
+
// get to the boundaries that define the optional set. since the
|
| 19 |
+
// node is optional, we know that all paths INTO this area of the
|
| 20 |
+
// graph are optional, but there may be non-optional dependencies
|
| 21 |
+
// WITHIN the area.
|
| 22 |
+
const set = new Set([node])
|
| 23 |
+
for (const node of set) {
|
| 24 |
+
for (const edge of node.edgesIn) {
|
| 25 |
+
if (!edge.optional) {
|
| 26 |
+
set.add(edge.from)
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
// now that we've hit the boundary, gather the rest of the nodes in
|
| 32 |
+
// the optional section. that's the set of dependencies that are only
|
| 33 |
+
// depended upon by other nodes within the set, or optional dependencies
|
| 34 |
+
// from outside the set.
|
| 35 |
+
return gatherDepSet(set, edge => !edge.optional)
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
module.exports = optionalSet
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/override-resolves.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
function overrideResolves (resolved, opts) {
|
| 2 |
+
const { omitLockfileRegistryResolved = false } = opts
|
| 3 |
+
|
| 4 |
+
if (omitLockfileRegistryResolved) {
|
| 5 |
+
return undefined
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
return resolved
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
module.exports = { overrideResolves }
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/override-set.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const npa = require('npm-package-arg')
|
| 2 |
+
const semver = require('semver')
|
| 3 |
+
|
| 4 |
+
class OverrideSet {
|
| 5 |
+
constructor ({ overrides, key, parent }) {
|
| 6 |
+
this.parent = parent
|
| 7 |
+
this.children = new Map()
|
| 8 |
+
|
| 9 |
+
if (typeof overrides === 'string') {
|
| 10 |
+
overrides = { '.': overrides }
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
// change a literal empty string to * so we can use truthiness checks on
|
| 14 |
+
// the value property later
|
| 15 |
+
if (overrides['.'] === '') {
|
| 16 |
+
overrides['.'] = '*'
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
if (parent) {
|
| 20 |
+
const spec = npa(key)
|
| 21 |
+
if (!spec.name) {
|
| 22 |
+
throw new Error(`Override without name: ${key}`)
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
this.name = spec.name
|
| 26 |
+
spec.name = ''
|
| 27 |
+
this.key = key
|
| 28 |
+
this.keySpec = spec.toString()
|
| 29 |
+
this.value = overrides['.'] || this.keySpec
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
for (const [key, childOverrides] of Object.entries(overrides)) {
|
| 33 |
+
if (key === '.') {
|
| 34 |
+
continue
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
const child = new OverrideSet({
|
| 38 |
+
parent: this,
|
| 39 |
+
key,
|
| 40 |
+
overrides: childOverrides,
|
| 41 |
+
})
|
| 42 |
+
|
| 43 |
+
this.children.set(child.key, child)
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
getEdgeRule (edge) {
|
| 48 |
+
for (const rule of this.ruleset.values()) {
|
| 49 |
+
if (rule.name !== edge.name) {
|
| 50 |
+
continue
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
// if keySpec is * we found our override
|
| 54 |
+
if (rule.keySpec === '*') {
|
| 55 |
+
return rule
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
let spec = npa(`${edge.name}@${edge.spec}`)
|
| 59 |
+
if (spec.type === 'alias') {
|
| 60 |
+
spec = spec.subSpec
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
if (spec.type === 'git') {
|
| 64 |
+
if (spec.gitRange && semver.intersects(spec.gitRange, rule.keySpec)) {
|
| 65 |
+
return rule
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
continue
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
if (spec.type === 'range' || spec.type === 'version') {
|
| 72 |
+
if (semver.intersects(spec.fetchSpec, rule.keySpec)) {
|
| 73 |
+
return rule
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
continue
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// if we got this far, the spec type is one of tag, directory or file
|
| 80 |
+
// which means we have no real way to make version comparisons, so we
|
| 81 |
+
// just accept the override
|
| 82 |
+
return rule
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
return this
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
getNodeRule (node) {
|
| 89 |
+
for (const rule of this.ruleset.values()) {
|
| 90 |
+
if (rule.name !== node.name) {
|
| 91 |
+
continue
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
if (semver.satisfies(node.version, rule.keySpec) ||
|
| 95 |
+
semver.satisfies(node.version, rule.value)) {
|
| 96 |
+
return rule
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
return this
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
getMatchingRule (node) {
|
| 104 |
+
for (const rule of this.ruleset.values()) {
|
| 105 |
+
if (rule.name !== node.name) {
|
| 106 |
+
continue
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
if (semver.satisfies(node.version, rule.keySpec) ||
|
| 110 |
+
semver.satisfies(node.version, rule.value)) {
|
| 111 |
+
return rule
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
return null
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
* ancestry () {
|
| 119 |
+
for (let ancestor = this; ancestor; ancestor = ancestor.parent) {
|
| 120 |
+
yield ancestor
|
| 121 |
+
}
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
get isRoot () {
|
| 125 |
+
return !this.parent
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
get ruleset () {
|
| 129 |
+
const ruleset = new Map()
|
| 130 |
+
|
| 131 |
+
for (const override of this.ancestry()) {
|
| 132 |
+
for (const kid of override.children.values()) {
|
| 133 |
+
if (!ruleset.has(kid.key)) {
|
| 134 |
+
ruleset.set(kid.key, kid)
|
| 135 |
+
}
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
if (!override.isRoot && !ruleset.has(override.key)) {
|
| 139 |
+
ruleset.set(override.key, override)
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
return ruleset
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
module.exports = OverrideSet
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/packument-cache.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const { LRUCache } = require('lru-cache')
|
| 2 |
+
const { getHeapStatistics } = require('node:v8')
|
| 3 |
+
const { log } = require('proc-log')
|
| 4 |
+
|
| 5 |
+
// This is an in-memory cache that Pacote uses for packuments.
|
| 6 |
+
// Packuments are usually cached on disk. This allows for rapid re-requests
|
| 7 |
+
// of the same packument to bypass disk reads. The tradeoff here is memory
|
| 8 |
+
// usage for disk reads.
|
| 9 |
+
class PackumentCache extends LRUCache {
|
| 10 |
+
static #heapLimit = Math.floor(getHeapStatistics().heap_size_limit)
|
| 11 |
+
|
| 12 |
+
#sizeKey
|
| 13 |
+
#disposed = new Set()
|
| 14 |
+
|
| 15 |
+
#log (...args) {
|
| 16 |
+
log.silly('packumentCache', ...args)
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
constructor ({
|
| 20 |
+
// How much of this.#heapLimit to take up
|
| 21 |
+
heapFactor = 0.25,
|
| 22 |
+
// How much of this.#maxSize we allow any one packument to take up
|
| 23 |
+
// Anything over this is not cached
|
| 24 |
+
maxEntryFactor = 0.5,
|
| 25 |
+
sizeKey = '_contentLength',
|
| 26 |
+
} = {}) {
|
| 27 |
+
const maxSize = Math.floor(PackumentCache.#heapLimit * heapFactor)
|
| 28 |
+
const maxEntrySize = Math.floor(maxSize * maxEntryFactor)
|
| 29 |
+
super({
|
| 30 |
+
maxSize,
|
| 31 |
+
maxEntrySize,
|
| 32 |
+
sizeCalculation: (p) => {
|
| 33 |
+
// Don't cache if we dont know the size
|
| 34 |
+
// Some versions of pacote set this to `0`, newer versions set it to `null`
|
| 35 |
+
if (!p[sizeKey]) {
|
| 36 |
+
return maxEntrySize + 1
|
| 37 |
+
}
|
| 38 |
+
if (p[sizeKey] < 10_000) {
|
| 39 |
+
return p[sizeKey] * 2
|
| 40 |
+
}
|
| 41 |
+
if (p[sizeKey] < 1_000_000) {
|
| 42 |
+
return Math.floor(p[sizeKey] * 1.5)
|
| 43 |
+
}
|
| 44 |
+
// It is less beneficial to store a small amount of super large things
|
| 45 |
+
// at the cost of all other packuments.
|
| 46 |
+
return maxEntrySize + 1
|
| 47 |
+
},
|
| 48 |
+
dispose: (v, k) => {
|
| 49 |
+
this.#disposed.add(k)
|
| 50 |
+
this.#log(k, 'dispose')
|
| 51 |
+
},
|
| 52 |
+
})
|
| 53 |
+
this.#sizeKey = sizeKey
|
| 54 |
+
this.#log(`heap:${PackumentCache.#heapLimit} maxSize:${maxSize} maxEntrySize:${maxEntrySize}`)
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
set (k, v, ...args) {
|
| 58 |
+
// we use disposed only for a logging signal if we are setting packuments that
|
| 59 |
+
// have already been evicted from the cache previously. logging here could help
|
| 60 |
+
// us tune this in the future.
|
| 61 |
+
const disposed = this.#disposed.has(k)
|
| 62 |
+
/* istanbul ignore next - this doesnt happen consistently so hard to test without resorting to unit tests */
|
| 63 |
+
if (disposed) {
|
| 64 |
+
this.#disposed.delete(k)
|
| 65 |
+
}
|
| 66 |
+
this.#log(k, 'set', `size:${v[this.#sizeKey]} disposed:${disposed}`)
|
| 67 |
+
return super.set(k, v, ...args)
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
has (k, ...args) {
|
| 71 |
+
const has = super.has(k, ...args)
|
| 72 |
+
this.#log(k, `cache-${has ? 'hit' : 'miss'}`)
|
| 73 |
+
return has
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
module.exports = PackumentCache
|
tools/node-v22.19.0-linux-x64/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/peer-entry-sets.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Given a node in a tree, return all of the peer dependency sets that
|
| 2 |
+
// it is a part of, with the entry (top or non-peer) edges into the sets
|
| 3 |
+
// identified.
|
| 4 |
+
//
|
| 5 |
+
// With this information, we can determine whether it is appropriate to
|
| 6 |
+
// replace the entire peer set with another (and remove the old one),
|
| 7 |
+
// push the set deeper into the tree, and so on.
|
| 8 |
+
//
|
| 9 |
+
// Returns a Map of { edge => Set(peerNodes) },
|
| 10 |
+
|
| 11 |
+
const peerEntrySets = node => {
|
| 12 |
+
// this is the union of all peer groups that the node is a part of
|
| 13 |
+
// later, we identify all of the entry edges, and create a set of
|
| 14 |
+
// 1 or more overlapping sets that this node is a part of.
|
| 15 |
+
const unionSet = new Set([node])
|
| 16 |
+
for (const node of unionSet) {
|
| 17 |
+
for (const edge of node.edgesOut.values()) {
|
| 18 |
+
if (edge.valid && edge.peer && edge.to) {
|
| 19 |
+
unionSet.add(edge.to)
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
for (const edge of node.edgesIn) {
|
| 23 |
+
if (edge.valid && edge.peer) {
|
| 24 |
+
unionSet.add(edge.from)
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
}
|
| 28 |
+
const entrySets = new Map()
|
| 29 |
+
for (const peer of unionSet) {
|
| 30 |
+
for (const edge of peer.edgesIn) {
|
| 31 |
+
// if not valid, it doesn't matter anyway. either it's been previously
|
| 32 |
+
// peerConflicted, or it's the thing we're interested in replacing.
|
| 33 |
+
if (!edge.valid) {
|
| 34 |
+
continue
|
| 35 |
+
}
|
| 36 |
+
// this is the entry point into the peer set
|
| 37 |
+
if (!edge.peer || edge.from.isTop) {
|
| 38 |
+
// get the subset of peer brought in by this peer entry edge
|
| 39 |
+
const sub = new Set([peer])
|
| 40 |
+
for (const peer of sub) {
|
| 41 |
+
for (const edge of peer.edgesOut.values()) {
|
| 42 |
+
if (edge.valid && edge.peer && edge.to) {
|
| 43 |
+
sub.add(edge.to)
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
// if this subset does not include the node we are focused on,
|
| 48 |
+
// then it is not relevant for our purposes. Example:
|
| 49 |
+
//
|
| 50 |
+
// a -> (b, c, d)
|
| 51 |
+
// b -> PEER(d) b -> d -> e -> f <-> g
|
| 52 |
+
// c -> PEER(f, h) c -> (f <-> g, h -> g)
|
| 53 |
+
// d -> PEER(e) d -> e -> f <-> g
|
| 54 |
+
// e -> PEER(f)
|
| 55 |
+
// f -> PEER(g)
|
| 56 |
+
// g -> PEER(f)
|
| 57 |
+
// h -> PEER(g)
|
| 58 |
+
//
|
| 59 |
+
// The unionSet(e) will include c, but we don't actually care about
|
| 60 |
+
// it. We only expanded to the edge of the peer nodes in order to
|
| 61 |
+
// find the entry edges that caused the inclusion of peer sets
|
| 62 |
+
// including (e), so we want:
|
| 63 |
+
// Map{
|
| 64 |
+
// Edge(a->b) => Set(b, d, e, f, g)
|
| 65 |
+
// Edge(a->d) => Set(d, e, f, g)
|
| 66 |
+
// }
|
| 67 |
+
if (sub.has(node)) {
|
| 68 |
+
entrySets.set(edge, sub)
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
return entrySets
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
module.exports = peerEntrySets
|