Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix missing fields, like scripts, in npm query when the virtual tree is loaded #5263

Merged
merged 2 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/commands/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Query extends BaseCommand {
const opts = {
...this.npm.flatOptions,
path: where,
forceActual: true,
}
const arb = new Arborist(opts)
const tree = await arb.loadActual(opts)
Expand Down
35 changes: 20 additions & 15 deletions workspaces/arborist/lib/arborist/load-actual.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ module.exports = cls => class ActualLoader extends cls {
root = null,
transplantFilter = () => true,
ignoreMissing = false,
forceActual = false,
} = options
this[_filter] = filter
this[_transplantFilter] = transplantFilter
Expand All @@ -141,26 +142,30 @@ module.exports = cls => class ActualLoader extends cls {

this[_actualTree].assertRootOverrides()

// Note: hidden lockfile will be rejected if it's not the latest thing
// in the folder, or if any of the entries in the hidden lockfile are
// missing.
const meta = await Shrinkwrap.load({
path: this[_actualTree].path,
hiddenLockfile: true,
resolveOptions: this.options,
})
if (meta.loadedFromDisk) {
this[_actualTree].meta = meta
return this[_loadActualVirtually]({ root })
} else {
// if forceActual is set, don't even try the hidden lockfile
if (!forceActual) {
// Note: hidden lockfile will be rejected if it's not the latest thing
// in the folder, or if any of the entries in the hidden lockfile are
// missing.
const meta = await Shrinkwrap.load({
path: this[_actualTree].path,
lockfileVersion: this.options.lockfileVersion,
hiddenLockfile: true,
resolveOptions: this.options,
})
this[_actualTree].meta = meta
return this[_loadActualActually]({ root, ignoreMissing })

if (meta.loadedFromDisk) {
this[_actualTree].meta = meta
return this[_loadActualVirtually]({ root })
}
}

const meta = await Shrinkwrap.load({
path: this[_actualTree].path,
lockfileVersion: this.options.lockfileVersion,
resolveOptions: this.options,
})
this[_actualTree].meta = meta
return this[_loadActualActually]({ root, ignoreMissing })
}

async [_loadActualVirtually] ({ root }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,39 @@ ArboristNode {
}
`

exports[`test/arborist/load-actual.js TAP do not load from a hidden lockfile when forceActual is set > must match snapshot 1`] = `
ArboristNode {
"children": Map {
"abbrev" => ArboristNode {
"edgesIn": Set {
EdgeIn {
"from": "",
"name": "abbrev",
"spec": "^1.1.1",
"type": "prod",
},
},
"location": "node_modules/abbrev",
"name": "abbrev",
"path": "hidden-lockfile/node_modules/abbrev",
"version": "1.1.1",
},
},
"edgesOut": Map {
"abbrev" => EdgeOut {
"name": "abbrev",
"spec": "^1.1.1",
"to": "node_modules/abbrev",
"type": "prod",
},
},
"isProjectRoot": true,
"location": "",
"name": "hidden-lockfile",
"path": "hidden-lockfile",
}
`

exports[`test/arborist/load-actual.js TAP external-dep/root > loaded tree 1`] = `
ArboristNode {
"edgesOut": Map {
Expand Down Expand Up @@ -3760,7 +3793,7 @@ ArboristNode {
}
`

exports[`test/arborist/load-actual.js TAP load from a hidden lockfile > expect resolving Promise 1`] = `
exports[`test/arborist/load-actual.js TAP load from a hidden lockfile > must match snapshot 1`] = `
ArboristNode {
"children": Map {
"abbrev" => ArboristNode {
Expand Down
13 changes: 11 additions & 2 deletions workspaces/arborist/test/arborist/load-actual.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,17 @@ t.test('missing symlinks', t =>
'bar has error')
}))

t.test('load from a hidden lockfile', t =>
t.resolveMatchSnapshot(loadActual(resolve(fixtures, 'hidden-lockfile'))))
t.test('load from a hidden lockfile', async (t) => {
const tree = await loadActual(resolve(fixtures, 'hidden-lockfile'))
t.ok(tree.meta.loadedFromDisk, 'meta was loaded from disk')
t.matchSnapshot(tree)
})

t.test('do not load from a hidden lockfile when forceActual is set', async (t) => {
const tree = await loadActual(resolve(fixtures, 'hidden-lockfile'), { forceActual: true })
t.not(tree.meta.loadedFromDisk, 'meta was NOT loaded from disk')
t.matchSnapshot(tree)
})

t.test('load a global space', t =>
t.resolveMatchSnapshot(loadActual(resolve(fixtures, 'global-style/lib'), {
Expand Down