Skip to content
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

firebase use --alias is in conflict with commander #1457

Open
sferencik opened this issue Jul 2, 2019 · 8 comments
Open

firebase use --alias is in conflict with commander #1457

sferencik opened this issue Jul 2, 2019 · 8 comments
Assignees

Comments

@sferencik
Copy link

Running firebase use --alias, I get an error:

$ firebase use --alias myAlias myProjectId

Error: An unexpected error has occurred.

I believe the --alias option is in conflict with commander, which firebase uses for parsing the command-line. Commander has a feature called command aliases (so you could alias e.g. firebase set to firebase use) and as it tries to evaluate the aliases, it gets confused by the --alias option. If my assessment is correct, it's not possible to have an option named --alias (without a change in commander).

I briefly looked at the commander code, and what happens is this:

  1. commander constructs a list of all the known firebase commands (init, deploy, etc.), each represented by a Command object
    • as it happens, the Command class has a method called alias() - more on that later
  2. given the commandline firebase use --alias myAlias --debug myProjectId, the commander will
    1. parse the "command" (use) and create a Command object, setting ._name = "use"
    2. parse the options, setting .alias = "myAlias" and .debug = true
  3. notice how setting the .alias field above has overwritten the .alias() method
  4. when commander tries to evaluate the aliases for the Command("use"), it tries to invoke its .alias() method but it's gone - there's now an .alias field instead, courtesy to us using the --alias option
  5. crash

It makes me wonder why no-one else has encountered this before?

Is there an alternative to using --alias? I would be OK with --add, but I need to run this on the CI.

Environment info

firebase-tools: 7.0.2
commander: 2.20.0
Platform: Windows 10

Debug stack-trace

$ firebase use --alias myAlias --debug myProjectId
[2019-07-02T09:38:47.880Z] ----------------------------------------------------------------------
[2019-07-02T09:38:47.885Z] Command:       C:\Program Files\nodejs\node.exe C:\Users\e10110549\AppData\Roaming\npm\node_modules\firebase-tools\lib\bin\firebase.js use --alias myAlias --debug myProjectId
[2019-07-02T09:38:47.886Z] CLI Version:   7.0.2
[2019-07-02T09:38:47.886Z] Platform:      win32
[2019-07-02T09:38:47.887Z] Node Version:  v10.14.1
[2019-07-02T09:38:47.888Z] Time:          Tue Jul 02 2019 11:38:47 GMT+0200 (Central European Summer Time)
[2019-07-02T09:38:47.888Z] ----------------------------------------------------------------------

[2019-07-02T09:38:48.382Z] TypeError: command.alias is not a function
    at C:\Users\e10110549\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\commander\index.js:490:22
    at Array.filter (<anonymous>)
    at Command.parse (C:\Users\e10110549\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\commander\index.js:485:34)
    at Object.<anonymous> (C:\Users\e10110549\AppData\Roaming\npm\node_modules\firebase-tools\lib\bin\firebase.js:98:22)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)

Error: An unexpected error has occurred.
...
@google-oss-bot
Copy link
Contributor

This issue does not seem to follow the issue template. Make sure you provide all the required information.

@samtstern
Copy link
Contributor

@sferencik thanks for the detailed report!

@bkendall
Copy link
Contributor

bkendall commented Jul 8, 2019

Huh. I am making a note to myself to take a look. Thanks

b/137017467

@petarnikolovski
Copy link

@samedson I have the same problem. It seems that the bug is not resolved yet.

@lahiru-tennakoon
Copy link

@samtstern It's been more than a year since this issue has been opened but seems like this bug still exists.

@TimonSotiropoulos
Copy link

TimonSotiropoulos commented May 28, 2021

@samtstern

+1 also having this issue. Is there another way to create aliases using the CLI that don't involve using the interactive tool? Basically I want to be able to script this alias creation in my firebase project.

Update: I guess anyone is now currently using a .firebaserc file with projects in it when sharing across dev teams:

#.firebaserc
{
  "projects": {
    "default": "my-app",
    "production": "my-app",
    "staging": "my-app-staging",
    "development": "my-app-development"
  }
}

@samtstern
Copy link
Contributor

Seems like this is:
tj/commander.js#592

It was fixed in Commander 7, as described here:
https://github.com/tj/commander.js#legacy-options-as-properties

Right now we're only using Commander 4 so we'd have to upgrade 3 major versions to get the fix. Not too hard, but also a bit scary.

@harveylee
Copy link

Just bumped into this too. Not a big deal to write a small script to modify .firebaserc directly... but for what it's worth:
It seems like a simple fix to avoid having to upgrade Commander would be to add a short-form option that works (e.g. -a or -A) or rename the --alias option (which doesn't work anyway) to --setalias?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants