firebase / firebase-tools

The Firebase Command Line Tools
MIT License
4.02k stars 936 forks source link

Handle PowerShell comma behavior for parsing command arguments #7506

Open paulpv opened 3 months ago

paulpv commented 3 months ago

[REQUIRED] Environment info

firebase-tools: 13.14.2

Platform: Windows

[REQUIRED] Test case

...

[REQUIRED] Steps to reproduce

Setup: PowerShell v7 Administrator:

winget install nvm-windows
winget install -e --id Oracle.JDK.18

Close and reopen PowerShell (Admin), then:

nvm install 20
nvm use 20
npm install -g firebase-tools
firebase login
firebase target:apply hosting prod site-prod
firebase target:apply hosting dev site-dev
firebase init emulators
firebase emulators:start --only firestore,functions,hosting

[REQUIRED] Expected behavior

Emulator starts

[REQUIRED] Actual behavior

firebase emulators:start --only firestore,functions,hosting:dev --debug
[2024-07-29T22:50:35.978Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2024-07-29T22:50:35.979Z] > authorizing via signed-in user (distroavproject@gmail.com)
i  emulators: Shutting down emulators. {"metadata":{"emulator":{"name":"hub"},"message":"Shutting down emulators."}}

Error: No emulators to start, run firebase init emulators to get started.

Notes

Everything works fine if I run just:

firebase emulators:start

or even just

firebase emulators:start --only hosting

Seems like anything comma-separated --only a,b does not work.

This is using an existing project that runs fine on Mac/Linux, when I use --only firestore,functions,hosting.

Log of a successful non---only a,b command:

firebase emulators:start --debug                                       
[2024-07-29T22:59:26.809Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2024-07-29T22:59:26.811Z] > authorizing via signed-in user (distroavproject@gmail.com)
[2024-07-29T22:59:26.875Z] java version "18.0.2.1" 2022-08-18

[2024-07-29T22:59:26.876Z] Java(TM) SE Runtime Environment (build 18.0.2.1+1-1)
Java HotSpot(TM) 64-Bit Server VM (build 18.0.2.1+1-1, mixed mode, sharing)

[2024-07-29T22:59:26.887Z] Parsed Java major version: 18
i  emulators: Starting emulators: functions, firestore, hosting {"metadata":{"emulator":{"name":"hub"},"message":"Starting emulators: functions, firestore, hosting"}}
...
aalej commented 2 months ago

Hey @paulpv, thanks for the detailed report. I was able to reproduce this issue when using PowerShell, however, when I tried using Command Prompt, the command firebase emulators:start --only firestore,hosting works and does not raise any errors.

When using the Command Prompt, checking the generated firebase-debug.log shows that the command being run is:

C:\<PATH>\firebase.js emulators:start --only firestore,hosting --debug

However, when using PowerShell, I checked the generated firebase-debug.log file and noticed that the command being run is:

 C:\<PATH>\firebase.js emulators:start --only firestore hosting --debug

I noticed that the “,” separating firestore and hosting has been removed. This makes me think that this could be an issue with how PowerShell treats commas. I found this relevant Stack Overflow post.

Could you try adding quotes around the argument to see if you would be able to start the emulators? The command would look something like:

firebase emulators:start --only 'firestore,hosting' --debug
paulpv commented 2 months ago

Could you try adding quotes around the argument to see if you would be able to start the emulators? The command would look something like:

firebase emulators:start --only 'firestore,hosting' --debug

Purfect! Works just fine now!

I had a feeling it had something to do with the commas!

"Today I learned" that PS treats commas differently.

Hopefully this helps out anyone in the future that runs into this!

You may close as appropriate.
The only thing I could think of is maybe some example/mention in the docs on how to handle this.
PowerShell is being pushed more and more as the default Windows shell/terminal.
WindowKey and searching for "cmd" doesn't even bring up "Command Prompt" anymore. :/

aalej commented 2 months ago

Awesome! It’s good to hear that the command now works. For now, I’ll go ahead and close this issue as it’s solved. Though, I’ll bring this up to our engineering team to see if we could update the docs.

aalej commented 2 months ago

Quick update, re-opening this issue. Discussed this with our engineering team and we think we could add some logic to handle how PowerShell treats commas. I'll change the title of the issue to match this.