Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start of CLI version checking from VSCE #7847

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
});
}

await checkCLIInstallation();

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

Expand All @@ -68,3 +72,39 @@
),
);
}

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 versionRes = spawnSync("firebase", ["--version"]);
pluginLogger.info("versionRes is :", versionRes.stderr?.toString());
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

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

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

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

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

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

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.showInformationMessage(message);
}
}
Loading