Skip to content

Commit df2f682

Browse files
authored
Improve detection for outdated standalone CLI versions. (#7885)
1 parent ec55947 commit df2f682

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

firebase-vscode/src/extension.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from "vscode";
2-
import { spawnSync } from 'child_process';
2+
import { spawnSync } from "child_process";
33
import * as semver from "semver";
44

55
import { ExtensionBroker } from "./extension-broker";
@@ -83,30 +83,40 @@ async function checkCLIInstallation(): Promise<void> {
8383
let message = "";
8484
try {
8585
// Fetch directly so that we don't need to rely on any tools being presnt on path.
86-
const latestVersionRes = await fetch("https://registry.npmjs.org/firebase-tools");
87-
const latestVersion = (await latestVersionRes.json())?.["dist-tags"]?.["latest"];
88-
const env = { ...process.env, "VSCODE_CWD":"" }
86+
const latestVersionRes = await fetch(
87+
"https://registry.npmjs.org/firebase-tools",
88+
);
89+
const latestVersion = (await latestVersionRes.json())?.["dist-tags"]?.[
90+
"latest"
91+
];
92+
const env = { ...process.env, VSCODE_CWD: "" };
8993
const versionRes = spawnSync("firebase", ["--version"], { env });
90-
const currentVersion = semver.valid(versionRes.stdout?.toString())
91-
const npmVersionRes = spawnSync("npm", ["--version"])
92-
const npmVersion = semver.valid(npmVersionRes.stdout?.toString())
94+
const currentVersion = semver.valid(versionRes.stdout?.toString());
95+
const npmVersionRes = spawnSync("npm", ["--version"]);
96+
const npmVersion = semver.valid(npmVersionRes.stdout?.toString());
9397
if (!currentVersion) {
9498
message = `The Firebase CLI is not installed (or not available on $PATH). If you would like to install it, run ${
9599
npmVersion
96100
? "npm install -g firebase-tools"
97101
: "curl -sL https://firebase.tools | bash"
98-
}`
102+
}`;
99103
} else if (semver.lt(currentVersion, latestVersion)) {
100-
message = `There is an outdated version of the Firebase CLI installed on your system. We recommened updating to the latest verion by running ${
101-
npmVersion
102-
? "npm install -g firebase-tools"
103-
: "curl -sL https://firebase.tools | upgrade=true bash"
104-
}`
104+
let installCommand =
105+
"curl -sL https://firebase.tools | upgrade=true bash";
106+
if (npmVersion) {
107+
// Despite the presence of npm, the existing command may be standalone.
108+
// Run a special standalone-specific command to tell if it actually is.
109+
const checkRes = spawnSync("firebase", ["--tool:setup-check"], { env });
110+
if (checkRes.status !== 0) {
111+
installCommand = "npm install -g firebase-tools@latest";
112+
}
113+
}
114+
message = `There is an outdated version of the Firebase CLI installed on your system. We recommened updating to the latest verion by running ${installCommand}`;
105115
} else {
106116
pluginLogger.info(`Checked firebase-tools, is up to date!`);
107117
}
108-
} catch(err: any) {
109-
pluginLogger.info(`Unable to check firebase-tools installation: ${err}`)
118+
} catch (err: any) {
119+
pluginLogger.info(`Unable to check firebase-tools installation: ${err}`);
110120
}
111121

112122
if (message) {

0 commit comments

Comments
 (0)