Skip to content

fix: issue-6960 Correctly handle scenario where prefix is the current working directory #7208

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

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
@@ -129,6 +129,25 @@ t.test('exec commands', async t => {
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?

@@ -131,7 +131,7 @@ class Install extends ArboristWorkspaceCmd {
args = args.filter(a => resolve(a) !== this.npm.prefix)

// `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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy