-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 yarn config set
for boolean values (#1237)
#1292
Conversation
All config values were treated as strings but several config keys are booleans. This introduces a check that verifies if a supplied value equals 'true' or 'false'.
@@ -16,8 +16,15 @@ export const {run, setFlags} = buildSubCommands('config', { | |||
return false; | |||
} | |||
|
|||
const [key, val = true] = args; | |||
const [key, val] = ((key, val = true) => { | |||
if (typeof val === 'string' && (/^(true|false)$/i).test(val)) { |
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.
Can you change this to `val === 'false' || val === 'true', it's not super obvious what this does on first glance.
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.
It won't work for upper/mixed-case letters, and simply usingval.toLowerCase() === 'false' || val.toLowerCase() === 'true'
(or introducing another, intermediate variable to hold the lowercase value) will break on the default true
value. The typeof check is required.
The regex can be replaced, e.g.
if (typeof val === 'string' && (val.toLowerCase() === 'false' || val.toLowerCase() === 'true')) {
but it's ugly :/
} | ||
|
||
return [key, val]; | ||
})(...args); |
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.
Not a fan of the IIFE and spreading the arguments into it, we should do something like:
const key = args[0];
let val = args[1];
if (key === 'true' ...) {
val = val === 'true';
}
We don't really need to handle the alternate casing of true
.
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.
const key = args[0];
let val = args[1];
You'll loose the default true
value this way from the val
assignment (I didn't want to introduce a regression). It could be replaced with let val = args[1] || true
but it's not the same as a default value (falsy values don't work, most importantly 0
), hence IIFE.
if (key === 'true' ...) {
val = val === 'true';
}
See my previous comment.
We don't really need to handle the alternate casing of
true
.
What about calling config set
without the value? AFAIK, NPM defaults to true
for flags and an empty string for other keys?
This also affects |
Created #1590 to fix this, pending approval. |
Summary
All config values were treated as strings but some config keys require booleans, e.g.
strict-ssl
orignore-scripts
. See: #1237Test plan
strict-ssl
tofalse
yarn config list
strict-ssl
is set to booleanfalse