Skip to content

Conversation

@ficocelliguy
Copy link
Contributor

@ficocelliguy ficocelliguy commented Feb 7, 2024

closes #6960

Currently, when running npm install, if the --prefix flag is provided and set to the current working directory, this triggers some logic intended for a global install. Specifically, it makes npm.globalDir and npm.prefix the same. This causes the package ["."] to be included in the dependencies needed, adding a reference to the current directory to package.json as an empty file: dependency.

This PR ensures that the global install logic in install.js is only run for global installs.

@ficocelliguy ficocelliguy requested a review from a team as a code owner February 7, 2024 04:23
@ficocelliguy ficocelliguy changed the title Fix: issue-6960 Correctly handle scenario where prefix is the current working directory fix: issue-6960 Correctly handle scenario where prefix is the current working directory Feb 19, 2024
await npm.exec('install')
})

await t.test('should not self-install package if prefix is the same as PWD', async t => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean "CWD" instead of "PWD" here?


// `npm i -g` => "install this package globally"
if (where === globalTop && !args.length) {
if (isGlobalInstall && where === globalTop && !args.length) {
Copy link
Member

@wraithgar wraithgar Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is already coupled to isGlobalInstall:

    const isGlobalInstall = this.npm.global
    const where = isGlobalInstall ? globalTop : this.npm.prefix

I suspect we don't need both tested here.

@owlstronaut
Copy link
Contributor

closing in favor of #8269

@owlstronaut owlstronaut closed this May 2, 2025
wraithgar pushed a commit that referenced this pull request May 5, 2025
closes #6960

related #7208

resolves feedback from
#7208 (comment) and
#7208 (review)

Manually verified the fix on windows

Co-authored-by: Michael Ficocelli <ficocemt@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] npm install --prefix="$PWD" adds invalid dependency to package.json

4 participants