Skip to content
This repository was archived by the owner on Jan 20, 2022. It is now read-only.
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
4 changes: 4 additions & 0 deletions lib/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ module.exports = cls => class IdealTreeBuilder extends Tracker(Virtual(Actual(cl
this[_manifests] = new Map()
}

get explicitRequests () {
return new Set(this[_explicitRequests])
}

// public method
buildIdealTree (options = {}) {
if (this.idealTree)
Expand Down
21 changes: 10 additions & 11 deletions lib/arborist/reify.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const promiseCallLimit = require('promise-call-limit')
const Ideal = require('./build-ideal-tree.js')
const optionalSet = require('../optional-set.js')

const _diff = Symbol('diff')
const _retiredPaths = Symbol('retiredPaths')
const _retiredUnchanged = Symbol('retiredUnchanged')
const _sparseTreeDirs = Symbol('sparseTreeDirs')
Expand Down Expand Up @@ -109,7 +108,7 @@ module.exports = cls => class Reifier extends Ideal(cls) {
this[_scriptShell] = scriptShell
this[_savePrefix] = savePrefix

this[_diff] = null
this.diff = null
this[_retiredPaths] = {}
this[_retiredUnchanged] = {}
this[_sparseTreeDirs] = new Set()
Expand Down Expand Up @@ -169,11 +168,11 @@ module.exports = cls => class Reifier extends Ideal(cls) {

// find all the nodes that need to change between the actual
// and ideal trees.
this[_diff] = Diff.calculate({
this.diff = Diff.calculate({
actual: this.actualTree,
ideal: this.idealTree,
})
for (const node of this[_diff].removed) {
for (const node of this.diff.removed) {
this[_addNodeToTrashList](node)
}
}
Expand All @@ -199,7 +198,7 @@ module.exports = cls => class Reifier extends Ideal(cls) {
// changed or removed, so that we can rollback if necessary.
[_retireShallowNodes] () {
const moves = this[_retiredPaths] = {}
for (const diff of this[_diff].children) {
for (const diff of this.diff.children) {
if (diff.action === 'CHANGE' || diff.action === 'REMOVE') {
// we'll have to clean these up at the end, so add them to the list
this[_addNodeToTrashList](diff.actual, true)
Expand Down Expand Up @@ -259,7 +258,7 @@ module.exports = cls => class Reifier extends Ideal(cls) {
[_createSparseTree] () {
// if we call this fn again, we look for the previous list
// so that we can avoid making the same directory multiple times
const dirs = this[_diff].leaves
const dirs = this.diff.leaves
.filter(diff => {
return (diff.action === 'ADD' || diff.action === 'CHANGE') &&
!this[_sparseTreeDirs].has(diff.ideal.path)
Expand Down Expand Up @@ -289,7 +288,7 @@ module.exports = cls => class Reifier extends Ideal(cls) {
// we need to unpack them, read that shrinkwrap file, and then update
// the tree by calling loadVirtual with the node as the root.
[_loadShrinkwrapsAndUpdateTrees] (seen = new Set()) {
const shrinkwraps = this[_diff].leaves
const shrinkwraps = this.diff.leaves
.filter(d => (d.action === 'CHANGE' || d.action === 'ADD') &&
d.ideal.hasShrinkwrap && !seen.has(d.ideal) &&
!this[_trashList].has(d.ideal.path))
Expand Down Expand Up @@ -498,7 +497,7 @@ module.exports = cls => class Reifier extends Ideal(cls) {
const bundlesByDepth = new Map()
let maxBundleDepth = -1
dfwalk({
tree: this[_diff],
tree: this.diff,
visit: diff => {
const node = diff.ideal
if (node && !node.isRoot && node.package.bundleDependencies &&
Expand All @@ -524,7 +523,7 @@ module.exports = cls => class Reifier extends Ideal(cls) {
[_unpackNewModules] () {
const unpacks = []
dfwalk({
tree: this[_diff],
tree: this.diff,
filter: diff => diff.ideal,
visit: diff => {
const node = diff.ideal
Expand Down Expand Up @@ -555,7 +554,7 @@ module.exports = cls => class Reifier extends Ideal(cls) {
// shallowest nodes that we moved aside in the first place.
const moves = this[_retiredPaths]
this[_retiredUnchanged] = {}
return promiseAllRejectLate(this[_diff].children.map(diff => {
return promiseAllRejectLate(this.diff.children.map(diff => {
const realFolder = (diff.actual || diff.ideal).path
const retireFolder = moves[realFolder]
this[_retiredUnchanged][retireFolder] = []
Expand Down Expand Up @@ -620,7 +619,7 @@ module.exports = cls => class Reifier extends Ideal(cls) {
// deps before attempting to build it itself
const installedNodes = []
dfwalk({
tree: this[_diff],
tree: this.diff,
leave: diff => installedNodes.push(diff.ideal),
// process adds before changes, ignore removals
getChildren: diff => diff && diff.children,
Expand Down
10 changes: 10 additions & 0 deletions test/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ t.test('dedupe example - deduped', t => {
return t.resolveMatchSnapshot(printIdeal(path), 'dedupe testing')
})

t.test('expose explicitRequest', async t => {
const path = resolve(__dirname, '../fixtures/simple')
const arb = new Arborist({ path })
const tree = await arb.buildIdealTree({ add: [ 'abbrev' ] })
t.ok(arb.explicitRequests, 'exposes the explicit request')
t.strictSame(arb.explicitRequests, new Set(['abbrev']))
t.ok(arb.explicitRequests.has('abbrev'), 'should contain explicit item')
t.end()
})

t.test('bundle deps example 1', t => {
// NB: this results in ignoring the bundled deps when building the
// ideal tree. When we reify, we'll have to ignore the deps that
Expand Down
5 changes: 4 additions & 1 deletion test/arborist/reify.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ t.test('update a bundling node without updating all of its deps', t => {
t.test('omit optional dep', t => {
const path = fixture(t, 'tap-react15-collision-legacy-sw')
const ignoreScripts = true
return new Arborist({ path, ignoreScripts }).reify({ omit: ['optional'] })

const arb = new Arborist({ path, ignoreScripts })
return arb.reify({ omit: ['optional'] })
.then(tree => {
t.equal(tree.children.get('fsevents'), undefined, 'no fsevents in tree')
t.throws(() => fs.statSync(path + '/node_modules/fsevents'), 'no fsevents unpacked')
Expand All @@ -209,6 +211,7 @@ t.test('omit optional dep', t => {
optional: true,
}, 'fsevents present in lockfile')
})
.then(() => t.ok(arb.diff, 'has a diff tree'))
})

t.test('dev, optional, devOptional flags and omissions', t => {
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/simple/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "simple",
"version": "2.0.0"
}