Repository navigation
fix(vscode): stop DEBUG leaking into the CLI version check - #11385
abhiramshaji-cyber wants to merge 2 commits into
Conversation
logSetup() set process.env.DEBUG = "true" only to turn on the CLI's console logger, but every child process the extension starts inherits process.env. The spawned `firebase --version` then printed its debug banner before the version, so semver.valid() saw no version and the semver.coerce() fallback picked up the year of the first timestamp (2026.0.0). The outdated CLI warning could never fire. useConsoleLoggers() now takes the debug flag as an argument that defaults to DEBUG, so the CLI behaves as before while the extension asks for debug output without touching the environment. The version check also reads the line of output that is exactly a version instead of coercing the first number it finds. The login shell can still bring in DEBUG or other text from a user's profile, and only a line that is a whole version is the CLI's answer. Fixes firebase#11363
There was a problem hiding this comment.
Code Review
This pull request improves Firebase CLI version parsing by introducing a robust parseVersionOutput helper that correctly handles debug banners and Windows line endings, and updates useConsoleLoggers to accept an optional debug parameter to avoid polluting process.env.DEBUG. It also adds comprehensive unit tests for these changes. The review feedback suggests aligning the test code with the repository style guide by avoiding any or unknown type assertions, importing Transport from winston-transport, and replacing .forEach loops with for..of loops when cleaning up logger transports.
|
Thanks for the review notes. All four are addressed in 90da488, and the logger spec plus the VS Code unit suite pass locally. Happy to change anything the maintainers would prefer. |
|
Hi team, hope you're doing well! Just a gentle check in on this one, no rush at all. The workflow run is still waiting for approval, and I'm happy to merge in the latest main whenever that helps. If you'd like the fix to look different, or have any tips, I'd love to hear them. |
Description
The VS Code extension read a year from the CLI's debug log as the installed CLI version, so its outdated CLI warning never showed; now it reads the real version.
What this code is for
When the extension starts,
activate()callslogSetup()to set up logging and thencheckCLIInstallation(). That check runsfirebase --versionandnpm --versionin a child process, compares the result with thelatesttag from the npm registry, and shows a warning if the CLI is missing or older thanlatest.Before this PR
A developer with
firebase-tools15.33.0 installed opens VS Code with the extension.logSetup()runsprocess.env.DEBUG = "true"so thatuseConsoleLoggers()adds the debug console logger.checkCLIInstallation()buildsenv = { ...process.env, VSCODE_CWD: "" }, soDEBUG=truegoes into the child process.firebase --versionseesDEBUGand prints its debug banner first, lines like[2026-10-24T18:16:05.021Z] CLI Version: 15.33.0, then15.33.0on the last line.semver.valid()on the whole output returnsnull, sosemver.coerce()takes the first number it finds: the year in the first timestamp.2026.0.0, which is never older thanlatest, so the outdated CLI warning can never show. (On the released 2.4.3, which has nocoerce(), the same output shows "The Firebase CLI is not installed" on every start.)After this PR
Same developer, same start.
logSetup()callsuseConsoleLoggers(true). The debug console logger is added as before, andprocess.env.DEBUGis left alone.firebase --versionno longer getsDEBUGfrom the extension, so it prints15.33.0.parseVersionOutput()splits the output into lines and keeps the last line thatsemver.valid()accepts as a whole version.DEBUGstill arrives some other way, for example from the user's shell profile through the-llogin shell, the banner lines are not whole versions and are skipped; the15.33.0line is still found.15.33.0, and shows the outdated CLI warning whenlatestis newer.The diagram
flowchart LR classDef box fill:#eef1ff,stroke:#4c5bd4,color:#111827 classDef bad fill:#ffd6d6,stroke:#cc0000,color:#111827,stroke-width:3px classDef good fill:#c8f0c8,stroke:#008800,color:#111827,stroke-width:3px subgraph BEFORE["BEFORE: version read as 2026.0.0"] direction TB B1["developer opens VS Code, CLI 15.33.0"] --> B2["logSetup sets process.env.DEBUG"] B2 --> B3["firebase --version prints banner, then 15.33.0"] B3 --> B4{"semver.coerce on the whole output"} B4 -->|"first number is the year"| B5["2026.0.0, warning never shows"] B4 -->|"output is only a version"| B6["version read correctly"] end subgraph AFTER["AFTER: version read as 15.33.0"] direction TB A1["developer opens VS Code, CLI 15.33.0"] --> A2["logSetup calls useConsoleLoggers(true)"] A2 --> A3["firebase --version prints 15.33.0"] A3 --> A4{"THE CHANGE: keep the line that is a whole version"} A4 -->|"banner lines skipped"| A5["15.33.0, outdated warning works"] A4 -->|"no version line at all"| A6["CLI not installed warning, as before"] end B1 ~~~ A1 class B1,B2,B3,B6 box class A1,A2,A3,A6 box class B4,B5 bad class A4,A5 good linkStyle 3 stroke:#cc0000,stroke-width:5px linkStyle 8 stroke:#008800,stroke-width:5px style BEFORE fill:#fff5f5,stroke:#cc0000,color:#111827 style AFTER fill:#f3fff3,stroke:#008800,color:#111827The change
The fix for the reported bug:
logSetup()infirebase-vscode/src/logger-wrapper.tsno longer setsprocess.env.DEBUG. To keep the debug console logger,useConsoleLoggers()insrc/logger.tsnow takesdebug = !!process.env.DEBUGas an argument. The CLI calls it with no argument, so the CLI behaves exactly as before.The second check:
checkCLIInstallation()now passes both thefirebase --versionandnpm --versionoutput to a small exportedparseVersionOutput(), which returns the last line that is a whole version andundefinedwhen there is none. This replacessemver.valid(out) || semver.coerce(out)?.version, so the update notices that #10874 handled are still covered (they are never a whole version on their own line), and a timestamp can no longer be read as a version.Many thanks to @vgerasymenko for the very clear report and root cause, and to @aalej for the minimal reproduction and for inviting a PR. vgerasymenko suggested two options: delete
DEBUGfrom the env of the spawned check, or keep the logging flag out ofprocess.env. I went with the second one because every child process the extension starts inheritsprocess.env, not only this check, and I added the stricter line parsing because the login shell can still bringDEBUGin from a user's profile. I am very happy to be corrected on either: if you would rather keepsrc/logger.tsuntouched and only deleteDEBUGfrom this one spawn, or drop the parsing change, I will gladly change it. What do you think fits the extension best?What changes for a user
latest.firebase --versionfails or prints no version.vsce-debug.logis unchanged.npm --versionandfirebase --tool:setup-check, no longer getDEBUG=truefrom the extension.--debugandDEBUGhandling is unchanged.Scenarios Tested
mainand ranDEBUG=true node lib/bin/firebase.js --version: the old parsing read2026.0.0;parseVersionOutput()on the same output reads15.34.2.firebase-vscode/src/test/suite/src/extension.test.tscover a bare version, the debug banner, Windows line endings, text after the version, and output with no version, plus a check thatlogSetup()leavesDEBUGunset. With the old code, 4 of these fail; with this change the VS Code unit suite passes (19 passing).src/logger.spec.tsforuseConsoleLoggers(); 2 of them fail without the change, and all pass with it.npm run lintandnpm run buildinfirebase-vscode, andtsc --noEmitat the root, with no new warnings.Sample Commands
None, no command or flag changes.
Closes #11363