@npmcli/arborist
Advanced tools
Comparing version 0.0.23 to 0.0.24
// add and remove dependency specs to/from pkg manifest | ||
const relpath = require('./relpath.js') | ||
const removeFromOthers = (name, type, pkg) => { | ||
@@ -36,5 +34,5 @@ const others = new Set([ | ||
const add = ({pkg, add, saveBundle, saveType, path}) => { | ||
const add = ({pkg, add, saveBundle, saveType}) => { | ||
for (const spec of add) { | ||
addSingle({pkg, spec, saveBundle, saveType, path}) | ||
addSingle({pkg, spec, saveBundle, saveType}) | ||
} | ||
@@ -44,3 +42,3 @@ return pkg | ||
const addSingle = ({pkg, spec, saveBundle, saveType, path}) => { | ||
const addSingle = ({pkg, spec, saveBundle, saveType}) => { | ||
if (!saveType) | ||
@@ -59,6 +57,3 @@ saveType = getSaveType(pkg, spec) | ||
if (rawSpec !== '' || pkg[type][name] === undefined) { | ||
// if we're in global mode, file specs are based on cwd, not arb path | ||
pkg[type][name] = specType === 'file' || specType === 'directory' | ||
? `file:${relpath(path, fetchSpec)}` | ||
: (rawSpec || '*') | ||
pkg[type][name] = rawSpec || '*' | ||
} | ||
@@ -65,0 +60,0 @@ |
@@ -11,2 +11,3 @@ // mixin implementing the buildIdealTree method | ||
const getPeerSet = require('../peer-set.js') | ||
const realpath = require('../../lib/realpath.js') | ||
@@ -83,2 +84,8 @@ const fromPath = require('../from-path.js') | ||
const _usePackageLock = Symbol.for('usePackageLock') | ||
const _rpcache = Symbol.for('realpathCache') | ||
const _stcache = Symbol.for('statCache') | ||
const _updateFilePath = Symbol('updateFilePath') | ||
const _followSymlinkPath = Symbol('followSymlinkPath') | ||
const _getRelpathSpec = Symbol('getRelpathSpec') | ||
const _retrieveSpecName = Symbol('retrieveSpecName') | ||
@@ -135,2 +142,8 @@ // used for the ERESOLVE error to show the last peer conflict encountered | ||
this[_peerConflict] = null | ||
// caches for cached realpath calls | ||
const cwd = process.cwd() | ||
// assume that the cwd is real enough for our purposes | ||
this[_rpcache] = this[_rpcache] | ||
this[_stcache] = this[_stcache] | ||
} | ||
@@ -329,18 +342,7 @@ | ||
// fetch it and look in its manifest. | ||
return Promise.all(add.map(s => { | ||
// in global mode, `npm i foo.tgz` needs to be resolved from | ||
// the current working dir, NOT /usr/local/lib! | ||
const spec = npa(s, this[_global] ? process.cwd() : this.path) | ||
// if it's just @'' then we reload whatever's there, or get latest | ||
// if it's an explicit tag, we need to install that specific tag version | ||
const isTag = spec.rawSpec && spec.type === 'tag' | ||
return spec.name && !isTag ? spec : pacote.manifest(spec).then(mani => { | ||
// if it's a tag type, then we need to run it down to an actual version | ||
if (isTag) | ||
return npa(`${mani.name}@${mani.version}`) | ||
spec.name = mani.name | ||
return spec | ||
}) | ||
})).then(add => { | ||
return Promise.all(add.map(rawSpec => | ||
this[_retrieveSpecName](npa(rawSpec)) | ||
.then(add => this[_updateFilePath](add)) | ||
.then(add => this[_followSymlinkPath](add)) | ||
)).then(add => { | ||
this[_resolvedAdd] = add | ||
@@ -362,2 +364,49 @@ // now add is a list of spec objects with names. | ||
async [_retrieveSpecName] (spec) { | ||
// if it's just @'' then we reload whatever's there, or get latest | ||
// if it's an explicit tag, we need to install that specific tag version | ||
const isTag = spec.rawSpec && spec.type === 'tag' | ||
if (spec.name && !isTag) | ||
return spec | ||
const mani = await pacote.manifest(spec) | ||
// if it's a tag type, then we need to run it down to an actual version | ||
if (isTag) | ||
return npa(`${mani.name}@${mani.version}`) | ||
spec.name = mani.name | ||
return spec | ||
} | ||
async [_updateFilePath] (spec) { | ||
if (spec.type === 'file') { | ||
spec = this[_getRelpathSpec](spec, spec.fetchSpec) | ||
} | ||
return spec | ||
} | ||
async [_followSymlinkPath] (spec) { | ||
if (spec.type === 'directory') { | ||
const real = await ( | ||
realpath(spec.fetchSpec, this[_rpcache], this[_stcache]) | ||
// TODO: create synthetic test case to simulate realpath failure | ||
.catch(/* istanbul ignore next */() => null) | ||
) | ||
spec = this[_getRelpathSpec](spec, real) | ||
} | ||
return spec | ||
} | ||
[_getRelpathSpec] (spec, filepath) { | ||
/* istanbul ignore else - should also be covered by realpath failure */ | ||
if (filepath) { | ||
const { name } = spec | ||
spec = npa(`file:${relpath(this.path, filepath)}`, this.path) | ||
spec.name = name | ||
} | ||
return spec | ||
} | ||
// TODO: provide a way to fix bundled deps by exposing metadata about | ||
@@ -364,0 +413,0 @@ // what's in the bundle at each published manifest. Without that, we |
@@ -27,4 +27,4 @@ // mix-in implementing the loadActual method | ||
const _actualTreeLoaded = Symbol('actualTreeLoaded') | ||
const _rpcache = Symbol('realpathCache') | ||
const _stcache = Symbol('statCache') | ||
const _rpcache = Symbol.for('realpathCache') | ||
const _stcache = Symbol.for('statCache') | ||
const _topNodes = Symbol('linkTargets') | ||
@@ -31,0 +31,0 @@ const _cache = Symbol('nodeLoadingCache') |
@@ -7,3 +7,3 @@ // mixin implementing the reify method | ||
const {checkEngine, checkPlatform} = require('npm-install-checks') | ||
const updateDepSpec = require('../update-dep-spec.js') | ||
const { orderDeps, updateDepSpec } = require('../dep-spec.js') | ||
const AuditReport = require('../audit-report.js') | ||
@@ -856,6 +856,6 @@ | ||
} = this.idealTree.package | ||
const pjData = { | ||
const pjData = orderDeps({ | ||
...this.idealTree.package, | ||
_id: undefined, // strip this off | ||
} | ||
}) | ||
const format = indent === undefined ? ' ' : indent | ||
@@ -862,0 +862,0 @@ const eol = newline === undefined ? '\n' : newline |
{ | ||
"name": "@npmcli/arborist", | ||
"version": "0.0.23", | ||
"version": "0.0.24", | ||
"description": "Manage node_modules trees", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
277146
6782