Skip to content

Commit

Permalink
Merge pull request #119 from SocketDev/cg/fixNpmLogger
Browse files Browse the repository at this point in the history
Fix logging module in newer versions of npm
  • Loading branch information
charliegerard authored Jun 10, 2024
2 parents a430fc8 + 5f0009c commit 8ce1b8c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/commands/npm/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { spawn } from 'child_process'
import { spawn, execSync } from 'child_process'
import { fileURLToPath } from 'url'

const description = 'npm wrapper functionality'
Expand All @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion lib/shadow/npm-injection.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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')}
*/
Expand Down

0 comments on commit 8ce1b8c

Please sign in to comment.