|
1 | 1 | import * as vscode from "vscode";
|
2 |
| -import { spawnSync } from 'child_process'; |
| 2 | +import { spawnSync } from "child_process"; |
3 | 3 | import * as semver from "semver";
|
4 | 4 |
|
5 | 5 | import { ExtensionBroker } from "./extension-broker";
|
@@ -83,30 +83,40 @@ async function checkCLIInstallation(): Promise<void> {
|
83 | 83 | let message = "";
|
84 | 84 | try {
|
85 | 85 | // 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: "" }; |
89 | 93 | 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()); |
93 | 97 | if (!currentVersion) {
|
94 | 98 | message = `The Firebase CLI is not installed (or not available on $PATH). If you would like to install it, run ${
|
95 | 99 | npmVersion
|
96 | 100 | ? "npm install -g firebase-tools"
|
97 | 101 | : "curl -sL https://firebase.tools | bash"
|
98 |
| - }` |
| 102 | + }`; |
99 | 103 | } 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}`; |
105 | 115 | } else {
|
106 | 116 | pluginLogger.info(`Checked firebase-tools, is up to date!`);
|
107 | 117 | }
|
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}`); |
110 | 120 | }
|
111 | 121 |
|
112 | 122 | if (message) {
|
|
0 commit comments