Skip to content

Commit

Permalink
Merge branch 'master' into bl-blocking-fn-email
Browse files Browse the repository at this point in the history
  • Loading branch information
blidd-google authored Oct 21, 2024
2 parents f1f6c65 + 310c7a6 commit 38a1cb1
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions firebase-vscode/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as vscode from "vscode";
import { spawnSync } from 'child_process';
import * as semver from "semver";

import { ExtensionBroker } from "./extension-broker";
import { createBroker } from "../common/messaging/broker";
Expand Down Expand Up @@ -42,6 +44,8 @@ export async function activate(context: vscode.ExtensionContext) {
});
}

await checkCLIInstallation();

// log start event for session tracking
analyticsLogger.logger.logUsage(DATA_CONNECT_EVENT_NAME.EXTENSION_START);

Expand All @@ -68,3 +72,39 @@ export async function activate(context: vscode.ExtensionContext) {
),
);
}

async function checkCLIInstallation(): Promise<void> {
// This should never error out - it must be best effort.
let message = "";
try {
// Fetch directly so that we don't need to rely on any tools being presnt on path.
const latestVersionRes = await fetch("https://registry.npmjs.org/firebase-tools");
const latestVersion = (await latestVersionRes.json())?.["dist-tags"]?.["latest"];
const env = { ...process.env, "VSCODE_CWD":"" }

Check warning on line 83 in firebase-vscode/src/extension.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing semicolon
const versionRes = spawnSync("firebase", ["--version"], { env });
const currentVersion = semver.valid(versionRes.stdout?.toString())

Check warning on line 85 in firebase-vscode/src/extension.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing semicolon
const npmVersionRes = spawnSync("npm", ["--version"])

Check warning on line 86 in firebase-vscode/src/extension.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing semicolon
const npmVersion = semver.valid(npmVersionRes.stdout?.toString())

Check warning on line 87 in firebase-vscode/src/extension.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing semicolon
if (!currentVersion) {
message = `The Firebase CLI is not installed (or not available on $PATH). If you would like to install it, run ${
npmVersion
? "npm install -g firebase-tools"
: "curl -sL https://firebase.tools | bash"
}`

Check warning on line 93 in firebase-vscode/src/extension.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing semicolon
} else if (semver.lt(currentVersion, latestVersion)) {
message = `There is an outdated version of the Firebase CLI installed on your system. We recommened updating to the latest verion by running ${
npmVersion
? "npm install -g firebase-tools"
: "curl -sL https://firebase.tools | upgrade=true bash"
}`

Check warning on line 99 in firebase-vscode/src/extension.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing semicolon
} else {
pluginLogger.info(`Checked firebase-tools, is up to date!`);
}
} catch(err: any) {
pluginLogger.info(`Unable to check firebase-tools installation: ${err}`)

Check warning on line 104 in firebase-vscode/src/extension.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing semicolon
}

if (message) {
vscode.window.showWarningMessage(message);
}
}

0 comments on commit 38a1cb1

Please sign in to comment.