Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created February 22, 2021 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/5b563f5d43d88980ba90ad12c5986f35 to your computer and use it in GitHub Desktop.
Save isaacs/5b563f5d43d88980ba90ad12c5986f35 to your computer and use it in GitHub Desktop.
diff --git a/lib/arborist/reify.js b/lib/arborist/reify.js
index 9854d2d..54325aa 100644
--- a/lib/arborist/reify.js
+++ b/lib/arborist/reify.js
@@ -233,12 +233,18 @@ module.exports = cls => class Reifier extends cls {
.then(() => process.emit('timeEnd', 'reify:loadTrees'))
}
+ const updateNames = options.update && options.update.names || []
const actualOpt = this[_global] ? {
ignoreMissing: true,
global: true,
- filter: (node, kid) => this[_explicitRequests].size === 0 || !node.isProjectRoot
- ? true
- : (node.edgesOut.has(kid) || this[_explicitRequests].has(kid)),
+ filter: (node, kid) => {
+ const explicits = new Set([
+ ...this[_explicitRequests],
+ ...updateNames,
+ ])
+ return explicits.size === 0 || !node.isProjectRoot ? true
+ : (node.edgesOut.has(kid) || explicits.has(kid))
+ }
} : { ignoreMissing: true }
if (!this[_global]) {
@isaacs
Copy link
Author

isaacs commented Feb 22, 2021

test file:

#!/usr/bin/env bash

not_expect () {
  if [ -d $1 ]; then
    echo "SHOULD BE MISSING: $1"
    exit 1
  fi
}

expect () {
  if ! [ -d $1 ]; then
    echo "MISSING: $1"
    exit 1
  fi
}

rm -rf global-prefix
arborist reify global-prefix --global --add=abbrev@1.0
ls -laF global-prefix/node_modules
expect global-prefix/node_modules/abbrev
not_expect global-prefix/node_modules/once

arborist reify global-prefix --global --add=once
ls -laF global-prefix/node_modules
expect global-prefix/node_modules/abbrev
expect global-prefix/node_modules/once

arborist reify global-prefix --global --update=abbrev
ls -laF global-prefix/node_modules
expect global-prefix/node_modules/abbrev
expect global-prefix/node_modules/once

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment