-
Notifications
You must be signed in to change notification settings - Fork 377
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!: upgrade to commander@12 and fix some conflicting short option names #7008
Conversation
@@ -27,6 +27,7 @@ export const detectNetlifyLambda = async function ({ packageJson } = {}) { | |||
.option('-b, --babelrc [file]') | |||
.option('-t, --timeout [delay]') | |||
|
|||
program.allowExcessArguments() |
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.
The default behaviour changed in the commander upgrade. This opts back into the previous behaviour. We might consider changing at some point, but it didn't seem right to include this in this PR (and require us to cut a major).
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.
(To be clear here, I ended up only upgrading to commander@12 after all. This behavioural change is in commander@13, but I left this here so we're ready for it, since it doesn't hurt.)
.option('-o, --output <path>', 'Defines the filesystem path where the blob data should be persisted') | ||
.option('-O, --output <path>', 'Defines the filesystem path where the blob data should be persisted') |
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.
-o
is already used for --offline
, so this was being quietly ignored (I tested it locally).
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.
Sort of a bummer--I think -o
for output is a somewhat universal convention. Maybe something for us to change in future release? I think I'd opt for making --offline
a long option only.
c3cdea8
to
b807744
Compare
.option('-o, --open', 'Open site after deploy', false) | ||
.option('-O, --open', 'Open site after deploy', false) |
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.
Same here, there's already -o
for --offline
, so deploy -o
wasn't working as intended. It just started an offline deploy which of course didn't work.
b807744
to
4727ceb
Compare
04372e6
to
0d11dde
Compare
0d11dde
to
6aa83f2
Compare
1fb55f2
to
ad03c5f
Compare
4585705
to
ab73b05
Compare
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'. | ||
const matchingScripts = Object.entries(scripts).filter(([, script]) => script.match(/netlify-lambda\s+build/)) | ||
|
||
for (const [key, script] of matchingScripts) { | ||
// E.g. ["netlify-lambda", "build", "functions/folder"] | ||
// these are all valid options for netlify-lambda | ||
program |
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.
because this is in a loop it was redeclaring these options over and over, which is no longer allowed
@@ -14,19 +14,21 @@ export const detectNetlifyLambda = async function ({ packageJson } = {}) { | |||
return false | |||
} | |||
|
|||
const program = new Command() |
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.
using this constructor is also cleaner since it avoids mutating the exported singleton
1ee9305
to
2f59a2a
Compare
`-o` is already used in the base command for `--offline`, so this was being quietly ignored This can't be considered a breaking change as it has never worked. (I just tried it to be sure.) See tj/commander.js#2055.
It's already used in the BaseCommand for `--offline`. This is not a breaking change, because this never worked as is. Same issue as in 9280c55.
It's already defined in the BaseCommand for `--offline`.
`-r` was already used globally so this was being ignored
It was redefining the options over and over and over. The latest commander throws.
and centralize `--auth` only in `BaseCommand` commander@12 doesn't allow redefining the same option, so this pattern was no longer viable This was a pure refactor, but it uncovered some commands that weren't declaring options they were using, so I fixed those too.
2f59a2a
to
e68a091
Compare
@@ -21,6 +21,7 @@ netlify login | |||
|
|||
- `new` (*boolean*) - Login to new Netlify account | |||
- `debug` (*boolean*) - Print debugging information | |||
- `auth` (*string*) - Netlify auth token - can be used to run this command without logging in |
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 guess this one's pretty weird, huh?
@@ -19,6 +19,7 @@ netlify switch | |||
**Flags** | |||
|
|||
- `debug` (*boolean*) - Print debugging information | |||
- `auth` (*string*) - Netlify auth token - can be used to run this command without logging in |
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.
🤔 does ntl switch
make sense with a token?
@@ -20,6 +20,7 @@ netlify unlink | |||
|
|||
- `filter` (*string*) - For monorepos, specify the name of the application to run the command in | |||
- `debug` (*boolean*) - Print debugging information | |||
- `auth` (*string*) - Netlify auth token - can be used to run this command without logging in |
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.
arguably slightly weird
@@ -3,13 +3,13 @@ import { sortOptions } from '../../../dist/utils/command-helpers.js' | |||
|
|||
const program = createMainCommand() | |||
|
|||
/** @type {Array<import('../../src/commands/base-command.js').default>} */ | |||
/** @type {Array<import('../../../src/commands/base-command.js').default>} */ |
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 totally unrelated, but I happened to notice this was wrong 😬
@@ -20,6 +20,7 @@ netlify completion | |||
**Flags** | |||
|
|||
- `debug` (*boolean*) - Print debugging information | |||
- `auth` (*string*) - Netlify auth token - can be used to run this command without logging in |
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.
arguably this one's slightly weird too
--auth <token> Netlify auth token - can be used to run this command | ||
without logging in |
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'm not sure I fully understand this, but:
If the auth option was previously undocumented, you might consider continuing hiding it. That'd let us kick the can down the road on hiding it from the commands where it doesn't make semantic sense (and I think I agree with all the ones you pointed out).
...Although, when we remove this undocumented flag from those commands, it'll be a breaking change anyway. So... either way is fine, I suppose.
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.
The challenge is that --auth
was documented on only a handful of commands, but existed on all of them and actually did something on some subset of them. Now it will be documented on all of them.
The challenge is that AFAICT there's no built-in way with commander to mutate the config (to change hideHelp
) of an already registered option on a command, so we'd have to refactor to come up with some solution here to allow for it, or to follow the same pattern I did for --json
and --offline
, which requires adding --auth
explicitly to ~50 commands (i.e. all but 2-3) and then possibly deciding to .hideHelp()
on the ones where it currently isn't documented (if want want to not change what is currently documented).
My inclination is to merge this as is, since none of the above seems worth the effort.
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.
Looks great! I trust your judgment on things like whether or not to hide the --auth
flag, but I would err on the side of documenting what already exists. It's the shorter path and we can remove these flags where they make no semantic sense as part of a future breaking change.
Summary
This upgrades commander from v10 to v12. (The latest is v13, but we'll cross that bridge later.)
This revealed some errors in some command options, which this PR also fixes.
Details
The two main updates in this PR are due to tj/commander.js#2055, which no longer allows redefining the same option twice on the same command:
BaseCommand
with the option hidden from help and then redefining it in some specific commands. I decided to bite the bullet here and just refactored these three problematic options:--json
and--offline
entirely out ofBaseCommand
. This uncovered that we weren't exhaustively redeclaring this on all the commands that use it. I fixed those.--auth
entirely intoBaseCommand
. It's intended as an alternative authentication mechanism tontl login
andNETLIFY_AUTH_TOKEN
, so I believe this is reasonable.This did result in some docs/help changes, but IMO they're good changes. It did result in a handful of commands now having a documented
--auth
option that doesn't make much sense, but I'm not sure it's worth the effort to find some way to hide those.Breaking changes
netlify blobs:get
]: the--output
short variant has changed from-o
to-O
-o
did not actually worknetlify deploy
]: the--open
short variant has changed from-o
to-O
-o
did not actually work