diff --git a/src/shadow/npm-cli.ts b/src/shadow/npm-cli.ts index 6af702c3..7aa43db3 100755 --- a/src/shadow/npm-cli.ts +++ b/src/shadow/npm-cli.ts @@ -5,6 +5,7 @@ import { realpathSync } from 'node:fs' import path from 'node:path' import { installLinks } from './link' +import { findRoot } from '../utils/path-resolve' const realFilename = realpathSync(__filename) const realDirname = path.dirname(realFilename) @@ -14,9 +15,32 @@ const injectionPath = path.join(realDirname, 'npm-injection.js') process.exitCode = 1 +/* + Adding the `--quiet` and `--no-progress` flags when the `proc-log` module + is found to fix a UX issue when running the command with recent versions of npm + (input swallowed by the standard npm spinner) +*/ +let npmArgs: string[] = [] +if(process.argv.slice(2).includes('install')){ + const npmEntrypoint = realpathSync(npmPath) + const npmRootPath = findRoot(path.dirname(npmEntrypoint)) + if (npmRootPath === undefined) { + process.exit(127) + } + const npmDepPath = path.join(npmRootPath, 'node_modules') + + let npmlog + try { + npmlog = require(path.join(npmDepPath, 'proc-log/lib/index.js')).log + } catch {} + if (npmlog) { + npmArgs = ['--quiet', '--no-progress'] + } +} + spawn( process.execPath, - ['--require', injectionPath, npmPath, ...process.argv.slice(2)], + ['--require', injectionPath, npmPath, ...process.argv.slice(2), ...npmArgs], { stdio: 'inherit' } diff --git a/src/shadow/npm-injection.ts b/src/shadow/npm-injection.ts index 9ff47d4a..b2850f30 100644 --- a/src/shadow/npm-injection.ts +++ b/src/shadow/npm-injection.ts @@ -27,6 +27,7 @@ import type { } from '@npmcli/arborist' import type { Writable } from 'node:stream' import type { Options as OraOptions } from 'ora' +import { findRoot } from '../utils/path-resolve' type ArboristClass = typeof BaseArborist & { new (...args: any): any @@ -175,20 +176,6 @@ async function* batchScan( } } -function findRoot(filepath: string): string | undefined { - let curPath = filepath - while (true) { - if (path.basename(curPath) === 'npm') { - return curPath - } - const parent = path.dirname(curPath) - if (parent === curPath) { - return undefined - } - curPath = parent - } -} - function findSocketYML() { let prevDir = null let dir = process.cwd() diff --git a/src/utils/path-resolve.ts b/src/utils/path-resolve.ts index d24c88fc..abb99c38 100644 --- a/src/utils/path-resolve.ts +++ b/src/utils/path-resolve.ts @@ -134,3 +134,17 @@ export async function mapGlobEntryToFiles( return files } + +export function findRoot(filepath: string): string | undefined { + let curPath = filepath + while (true) { + if (path.basename(curPath) === 'npm') { + return curPath + } + const parent = path.dirname(curPath) + if (parent === curPath) { + return undefined + } + curPath = parent + } +} \ No newline at end of file