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: don't go into global mode if aliased to npmg #7842

Merged
merged 1 commit into from
Oct 17, 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
5 changes: 0 additions & 5 deletions lib/cli/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ module.exports = async (process, validateEngines) => {
// leak any private CLI configs to other programs
process.title = 'npm'

// if npm is called as "npmg" or "npm_g", then run in global mode.
if (process.argv[1][process.argv[1].length - 1] === 'g') {
process.argv.splice(1, 1, 'npm', '-g')
}

// Patch the global fs module here at the app level
require('graceful-fs').gracefulify(require('node:fs'))

Expand Down
8 changes: 4 additions & 4 deletions test/lib/cli/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ const cliMock = async (t, opts) => {
}
}

t.test('print the version, and treat npm_g as npm -g', async t => {
t.test('print the version ', async t => {
const { logs, cli, Npm, outputs, exitHandlerCalled } = await cliMock(t, {
globals: { 'process.argv': ['node', 'npm_g', 'root'] },
globals: { 'process.argv': ['node', 'npm', 'root'] },
})
await cli(process)

t.strictSame(process.argv, ['node', 'npm', '-g', 'root'], 'system process.argv was rewritten')
t.strictSame(process.argv, ['node', 'npm', 'root'], 'system process.argv was rewritten')
t.strictSame(logs.verbose.byTitle('cli'), ['cli node npm'])
t.strictSame(logs.verbose.byTitle('title'), ['title npm root'])
t.match(logs.verbose.byTitle('argv'), ['argv "--global" "root"'])
t.match(logs.verbose.byTitle('argv'), ['argv "root"'])
t.strictSame(logs.info, [`using npm@${Npm.version}`, `using node@${process.version}`])
t.equal(outputs.length, 1)
t.match(outputs[0], dirname(process.cwd()))
Expand Down
Loading