diff --git a/lib/utils/installed-deep.js b/lib/utils/installed-deep.js index 3c56c5d036f25..79fe9195a573f 100644 --- a/lib/utils/installed-deep.js +++ b/lib/utils/installed-deep.js @@ -21,9 +21,12 @@ const installedDeep = async (npm) => { const res = new Set() const gArb = new Arborist({ + ...npm.flatOptions, global: true, path: resolve(npm.globalDir, '..'), workspacesEnabled, + // Completion only lists names; never execute a project .npm-extension. + ignoreExtension: true, }) const gTree = await gArb.loadActual({ global: true }) @@ -32,7 +35,13 @@ const installedDeep = async (npm) => { } if (!global) { - const arb = new Arborist({ global: false, path: prefix, workspacesEnabled }) + const arb = new Arborist({ + ...npm.flatOptions, + global: false, + path: prefix, + workspacesEnabled, + ignoreExtension: true, + }) const tree = await arb.loadActual() for (const node of getValues(tree)) { res.add(node.name) diff --git a/test/lib/utils/installed-deep.js b/test/lib/utils/installed-deep.js index 20e001aaec751..b32e71390809b 100644 --- a/test/lib/utils/installed-deep.js +++ b/test/lib/utils/installed-deep.js @@ -190,6 +190,28 @@ t.test('limit depth', async t => { ) }) +t.test('does not execute .npm-extension during completion inventory', async t => { + const mock = await mockNpm(t, { + prefixDir: { + 'package.json': JSON.stringify({ + name: 'ext-poc', + version: '1.0.0', + }), + '.npm-extension.mjs': [ + "throw new Error('npm-extension should not run during completion')", + 'export const transformManifest = (pkg) => pkg', + ].join('\n'), + }, + globalPrefixDir: globalFixture, + config: { + depth: Infinity, + }, + }) + + const res = await installedDeep(mock.npm) + t.ok(Array.isArray(res), 'inventory still returns a list') +}) + t.test('limit depth as global', async t => { const res = await mockDeep(t, { depth: 0, global: true }) t.same(