(args)
| 66 | } |
| 67 | |
| 68 | async linkInstall (args) { |
| 69 | // load current packages from the global space, and then add symlinks installs locally |
| 70 | const globalTop = resolve(this.npm.globalDir, '..') |
| 71 | const Arborist = require('@npmcli/arborist') |
| 72 | // Resolve the policy up front so it also gates the global install of |
| 73 | // missing packages, not just the local link. |
| 74 | const { policy: allowScriptsPolicy } = await resolveAllowScripts(this.npm) |
| 75 | const globalOpts = { |
| 76 | ...this.npm.flatOptions, |
| 77 | Arborist, |
| 78 | path: globalTop, |
| 79 | global: true, |
| 80 | prune: false, |
| 81 | allowScripts: allowScriptsPolicy, |
| 82 | } |
| 83 | const globalArb = new Arborist(globalOpts) |
| 84 | |
| 85 | // get only current top-level packages from the global space |
| 86 | const globals = await globalArb.loadActual({ |
| 87 | filter: (node, kid) => |
| 88 | !node.isRoot || args.some(a => npa(a).name === kid), |
| 89 | }) |
| 90 | |
| 91 | // any extra arg that is missing from the current global space should be reified there first |
| 92 | const missing = this.missingArgsFromTree(globals, args) |
| 93 | if (missing.length) { |
| 94 | const globalReifyOpts = { |
| 95 | ...globalOpts, |
| 96 | add: missing, |
| 97 | } |
| 98 | // Gate the global install with the same preflight as `npm install`. |
| 99 | await strictAllowScriptsPreflight({ |
| 100 | arb: globalArb, |
| 101 | npm: this.npm, |
| 102 | idealTreeOpts: globalReifyOpts, |
| 103 | }) |
| 104 | await globalArb.reify(globalReifyOpts) |
| 105 | } |
| 106 | |
| 107 | // get a list of module names that should be linked in the local prefix |
| 108 | const names = [] |
| 109 | for (const a of args) { |
| 110 | const arg = npa(a) |
| 111 | if (arg.type === 'directory') { |
| 112 | const { content } = await pkgJson.normalize(arg.fetchSpec) |
| 113 | names.push(content.name) |
| 114 | } else { |
| 115 | names.push(arg.name) |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // npm link should not save=true by default unless you're using any of --save-dev or other types |
| 120 | const save = |
| 121 | Boolean( |
| 122 | (this.npm.config.find('save') !== 'default' && |
| 123 | this.npm.config.get('save')) || |
| 124 | this.npm.config.get('save-optional') || |
| 125 | this.npm.config.get('save-peer') || |
no test coverage detected