Skip to content

Commit 96b6781

Browse files
nlfwraithgar
authored andcommitted
feat(arborist): add option to forcibly skip loading a virtual tree
1 parent ca756fd commit 96b6781

File tree

3 files changed

+65
-18
lines changed

3 files changed

+65
-18
lines changed

workspaces/arborist/lib/arborist/load-actual.js

+20-15
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ module.exports = cls => class ActualLoader extends cls {
115115
root = null,
116116
transplantFilter = () => true,
117117
ignoreMissing = false,
118+
forceActual = false,
118119
} = options
119120
this[_filter] = filter
120121
this[_transplantFilter] = transplantFilter
@@ -141,26 +142,30 @@ module.exports = cls => class ActualLoader extends cls {
141142

142143
this[_actualTree].assertRootOverrides()
143144

144-
// Note: hidden lockfile will be rejected if it's not the latest thing
145-
// in the folder, or if any of the entries in the hidden lockfile are
146-
// missing.
147-
const meta = await Shrinkwrap.load({
148-
path: this[_actualTree].path,
149-
hiddenLockfile: true,
150-
resolveOptions: this.options,
151-
})
152-
if (meta.loadedFromDisk) {
153-
this[_actualTree].meta = meta
154-
return this[_loadActualVirtually]({ root })
155-
} else {
145+
// if forceActual is set, don't even try the hidden lockfile
146+
if (!forceActual) {
147+
// Note: hidden lockfile will be rejected if it's not the latest thing
148+
// in the folder, or if any of the entries in the hidden lockfile are
149+
// missing.
156150
const meta = await Shrinkwrap.load({
157151
path: this[_actualTree].path,
158-
lockfileVersion: this.options.lockfileVersion,
152+
hiddenLockfile: true,
159153
resolveOptions: this.options,
160154
})
161-
this[_actualTree].meta = meta
162-
return this[_loadActualActually]({ root, ignoreMissing })
155+
156+
if (meta.loadedFromDisk) {
157+
this[_actualTree].meta = meta
158+
return this[_loadActualVirtually]({ root })
159+
}
163160
}
161+
162+
const meta = await Shrinkwrap.load({
163+
path: this[_actualTree].path,
164+
lockfileVersion: this.options.lockfileVersion,
165+
resolveOptions: this.options,
166+
})
167+
this[_actualTree].meta = meta
168+
return this[_loadActualActually]({ root, ignoreMissing })
164169
}
165170

166171
async [_loadActualVirtually] ({ root }) {

workspaces/arborist/tap-snapshots/test/arborist/load-actual.js.test.cjs

+34-1
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,39 @@ ArboristNode {
10841084
}
10851085
`
10861086

1087+
exports[`test/arborist/load-actual.js TAP do not load from a hidden lockfile when forceActual is set > must match snapshot 1`] = `
1088+
ArboristNode {
1089+
"children": Map {
1090+
"abbrev" => ArboristNode {
1091+
"edgesIn": Set {
1092+
EdgeIn {
1093+
"from": "",
1094+
"name": "abbrev",
1095+
"spec": "^1.1.1",
1096+
"type": "prod",
1097+
},
1098+
},
1099+
"location": "node_modules/abbrev",
1100+
"name": "abbrev",
1101+
"path": "hidden-lockfile/node_modules/abbrev",
1102+
"version": "1.1.1",
1103+
},
1104+
},
1105+
"edgesOut": Map {
1106+
"abbrev" => EdgeOut {
1107+
"name": "abbrev",
1108+
"spec": "^1.1.1",
1109+
"to": "node_modules/abbrev",
1110+
"type": "prod",
1111+
},
1112+
},
1113+
"isProjectRoot": true,
1114+
"location": "",
1115+
"name": "hidden-lockfile",
1116+
"path": "hidden-lockfile",
1117+
}
1118+
`
1119+
10871120
exports[`test/arborist/load-actual.js TAP external-dep/root > loaded tree 1`] = `
10881121
ArboristNode {
10891122
"edgesOut": Map {
@@ -3760,7 +3793,7 @@ ArboristNode {
37603793
}
37613794
`
37623795

3763-
exports[`test/arborist/load-actual.js TAP load from a hidden lockfile > expect resolving Promise 1`] = `
3796+
exports[`test/arborist/load-actual.js TAP load from a hidden lockfile > must match snapshot 1`] = `
37643797
ArboristNode {
37653798
"children": Map {
37663799
"abbrev" => ArboristNode {

workspaces/arborist/test/arborist/load-actual.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,17 @@ t.test('missing symlinks', t =>
199199
'bar has error')
200200
}))
201201

202-
t.test('load from a hidden lockfile', t =>
203-
t.resolveMatchSnapshot(loadActual(resolve(fixtures, 'hidden-lockfile'))))
202+
t.test('load from a hidden lockfile', async (t) => {
203+
const tree = await loadActual(resolve(fixtures, 'hidden-lockfile'))
204+
t.ok(tree.meta.loadedFromDisk, 'meta was loaded from disk')
205+
t.matchSnapshot(tree)
206+
})
207+
208+
t.test('do not load from a hidden lockfile when forceActual is set', async (t) => {
209+
const tree = await loadActual(resolve(fixtures, 'hidden-lockfile'), { forceActual: true })
210+
t.not(tree.meta.loadedFromDisk, 'meta was NOT loaded from disk')
211+
t.matchSnapshot(tree)
212+
})
204213

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

0 commit comments

Comments
 (0)