Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logging module in newer versions of npm #119

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading