diff --git a/lib/commands/npm/index.js b/lib/commands/npm/index.js index 6342bd79..b6d85b74 100644 --- a/lib/commands/npm/index.js +++ b/lib/commands/npm/index.js @@ -1,4 +1,4 @@ -import { spawn } from 'child_process' +import { spawn, execSync } from 'child_process' import { fileURLToPath } from 'url' const description = 'npm wrapper functionality' @@ -7,10 +7,15 @@ const description = 'npm wrapper functionality' export const npm = { description, run: async (argv, _importMeta, _ctx) => { + const npmVersion = execSync('npm -v').toString() const wrapperPath = fileURLToPath(new URL('../../shadow/npm-cli.cjs', import.meta.url)) process.exitCode = 1 spawn(process.execPath, [wrapperPath, ...argv], { - stdio: 'inherit' + stdio: 'inherit', + env: { + ...process.env, + NPM_VERSION: npmVersion + } }).on('exit', (code, signal) => { if (signal) { process.kill(process.pid, signal) diff --git a/lib/shadow/npm-injection.cjs b/lib/shadow/npm-injection.cjs index aff44539..a0282986 100644 --- a/lib/shadow/npm-injection.cjs +++ b/lib/shadow/npm-injection.cjs @@ -268,7 +268,17 @@ function findRoot (filepath) { } const npmDir = findRoot(path.dirname(npmEntrypoint)) const arboristLibClassPath = path.join(npmDir, 'node_modules', '@npmcli', 'arborist', 'lib', 'arborist', 'index.js') -const npmlog = require(path.join(npmDir, 'node_modules', 'npmlog', 'lib', 'log.js')) + +const npmVersion = process.env.NPM_VERSION.split('.') +let npmlog + +if(npmVersion[0] === '10' && npmVersion[1] >= '6'){ + const { log } = require(path.join(npmDir, 'node_modules', 'proc-log', 'lib', 'index.js')) + npmlog = log +} else { + npmlog = require(path.join(npmDir, 'node_modules', 'npmlog', 'lib', 'log.js')) +} + /** * @type {import('pacote')} */