-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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: prefix in .npmrc error log #6685
Conversation
workspaces/config/lib/index.js
Outdated
if (type === 'project') { | ||
const parsedConfigPrefix = parsedConfig.prefix | ||
// Log error if prefix is mentioned in project .npmrc | ||
if (parsedConfigPrefix) { | ||
log.error(`prefix=${parsedConfigPrefix} cannot be changed from project config: ${file}`) | ||
} | ||
} | ||
return this.#loadObject(parsedConfig, type, file) | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (type === 'project') { | |
const parsedConfigPrefix = parsedConfig.prefix | |
// Log error if prefix is mentioned in project .npmrc | |
if (parsedConfigPrefix) { | |
log.error(`prefix=${parsedConfigPrefix} cannot be changed from project config: ${file}`) | |
} | |
} | |
return this.#loadObject(parsedConfig, type, file) | |
}, | |
if (type === 'project' && parsedConfig.prefix) { | |
// Log error if prefix is mentioned in project .npmrc | |
log.error('config', `prefix=${parsedConfigPrefix} cannot be changed from project config: ${file}.`) | |
} | |
return this.#loadObject(parsedConfig, type, file) | |
}, |
We don't need to cast a whole new variable for one if statement, just assess it in place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also added the logging prefix to the log output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, parsedConfigPrefix is also used for the logged error, would you still prefer if we got rid of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's one lest instance where we're logging user input which is always a good thing to avoid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had originally removed it and added it back at the last second, I should have trusted my first instinct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, are you suggesting that we change the log error to be:
log.error('config', `prefix cannot be changed from project config: ${file}.`)
Or are you suggesting this?
log.error('config', `prefix=${parsedConfig.prefix} cannot be changed from project config: ${file}.`)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.error('config', `prefix cannot be changed from project config: ${file}.`)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, appreciate the response.
Adding |
Yeah just noticed that too, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very helpful thank you.
No problem, hope it helps. |
Summary
The original issue (#6081) wanted the project's .npmrc to set a prefix value for npm to use in both
npm prefix
andnpm install <package>
However, we made the changes according to wraithgar's comment.Currently, when running
npm prefix
ornpm install
, there is no error logged communicating to the user that prefix cannot be changed in the project config.This solution gives the error message more clarity to make debugging easier and lets the user know that prefix cannot be changed from the project level.
Also added the accompanying tap test to ensure the expected error is outputted.
PLEASE NOTE:
If prefix is set to a value, the error will be logged anytime a user enters in a npm or npx command, which means that the logging is not specific to just
npm prefix
ornpm install <package>
, but also applies to commands such asnpm exec
.Testing
Reproduce Original Issue:
npm prefix
ornpm install <package>
npm prefix
will give the current directory’s prefix, andnpm install <package>
will install the package in the current directory.File tap test:
TAP_SNAPSHOT=1 node . run test workspaces/config/test/index.js
Run the entire tap test:
node . run test
Dummy Project Test:
alias localnpm="node /workspaces/cli/"
localnpm prefix
localnpm install <package>
References
Fixes #6081