-
Notifications
You must be signed in to change notification settings - Fork 108
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
Add "default" Option for "external" Environment Vars #989
Add "default" Option for "external" Environment Vars #989
Conversation
There may be cases where a caller doesn't want to pass an "external" environment variable. In those cases, rather than relying on the script to handle the default case, `wireit` can support a "default" option. This option is used when no value is passed for an "external" variable.
Hi @ObliviousHarmony! Could you elaborate a bit? I think I'm missing something. Maybe an example? |
Thanks for the prompt reply @aomarks! There are some cases where you may have tasks that are nearly identical except for an environment variable being different. This can be solved by using Separate Commands{
"scripts": {
"build": "wireit",
"build:dev": "wireit"
},
"wireit": {
"build": {
"command": "webpack",
"env": {
"NODE_ENV": "development"
}
},
"build:dev": {
"command": "webpack",
"env": {
"NODE_ENV": "production"
}
}
}
} Extra Command{
"scripts": {
"build": "cross-env NODE_ENV=production npm run build:real",
"build:dev": "cross-env NODE_ENV=development npm run build:real",
"build:real": "wireit"
},
"wireit": {
"build:real": {
"command": "webpack",
"env": {
"NODE_ENV": {
"external": true
}
}
}
}
} With
|
Any follow-up here @aomarks? |
I think your idea makes sense. So the 3 patterns are:
{
"env": {
"FOO": {
"external": true
}
}
}
{
"env": {
"FOO": "bar"
}
}
{
"env": {
"FOO": {
"external": true,
"default": "foo"
}
}
} What would this case mean? It could either be an error, it could act like 2, or it could add like 3. I wonder if calling it "value" and making it act like 2 would make sense? {
"env": {
"FOO": {
"default": "foo"
}
}
} |
When we consider that the object value of environment variables comes across as configuration options for it, I think a |
I took another look today and I actually think it might be better to provide an error for #3 @aomarks. Since this PR currently provides an error in that way, I'm happy with this PR as-is. |
Any thoughts @aomarks? |
Yeah, that makes sense to me. And I agree that this code will already error in the way we discussed. Thanks for the PR, merging! |
I merged |
There may be cases where a caller doesn't want to pass an "external" environment variable. In those cases, rather than relying on the script to handle the default case,
wireit
can support a "default" option. This option is used when no value is passed for an "external" variable.