From 2559645f59b8f7ba38d789f87c40dcf98ecc200d Mon Sep 17 00:00:00 2001 From: Harold Shen Date: Tue, 22 Oct 2024 16:21:36 +0100 Subject: [PATCH] Set FIREBASE_BINARY as "firebasePath" user setting (#7857) * set firebasePath as a user preference only * update setting * format and changelog * add global configuration target * format * change to machine-overridable --- firebase-vscode/CHANGELOG.md | 2 ++ firebase-vscode/package.json | 3 ++- firebase-vscode/src/utils/settings.ts | 24 +++++++++++++++++------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/firebase-vscode/CHANGELOG.md b/firebase-vscode/CHANGELOG.md index 062735e5b62..57f36902d1e 100644 --- a/firebase-vscode/CHANGELOG.md +++ b/firebase-vscode/CHANGELOG.md @@ -1,5 +1,7 @@ ## NEXT +- [Added] Persist FIREBASE_BINARY env variable to settings. + ## 0.10.5 - [Fixed] Fixed an issue where multiple instances of the extension would break the toolkit. diff --git a/firebase-vscode/package.json b/firebase-vscode/package.json index 3a736fe822e..16885004583 100644 --- a/firebase-vscode/package.json +++ b/firebase-vscode/package.json @@ -63,7 +63,8 @@ }, "firebase.firebasePath": { "type": "string", - "markdownDescription": "%ext.config.firebasePath%" + "markdownDescription": "%ext.config.firebasePath%", + "scope": "machine-overridable" }, "firebase.hosting.useFrameworks": { "type": "boolean", diff --git a/firebase-vscode/src/utils/settings.ts b/firebase-vscode/src/utils/settings.ts index 2b81aee8b78..2881c469f12 100644 --- a/firebase-vscode/src/utils/settings.ts +++ b/firebase-vscode/src/utils/settings.ts @@ -1,4 +1,4 @@ -import { ConfigurationTarget, workspace } from "vscode"; +import { ConfigurationTarget, window, workspace } from "vscode"; export interface Settings { readonly firebasePath: string; @@ -7,17 +7,27 @@ export interface Settings { readonly shouldShowIdxMetricNotice: boolean; } -const FIREBASE_BINARY = - // Allow defaults via env var. Useful when starting VS Code from command line or Monospace. - process.env.FIREBASE_BINARY || - // TODO: Temporary fallback for bashing, this should probably point to the global firebase binary on the system - "npx -y firebase-tools@latest"; +// TODO: Temporary fallback for bashing, this should probably point to the global firebase binary on the system +const DEFAULT_FIREBASE_BINARY = "npx -y firebase-tools@latest"; export function getSettings(): Settings { const config = workspace.getConfiguration("firebase"); + // TODO: Consider moving side effect out of getSettings + // Persist env var as path setting when path setting doesn't exist + if (process.env.FIREBASE_BINARY && !config.get("firebasePath")) { + config.update( + "firebasePath", + process.env.FIREBASE_BINARY, + ConfigurationTarget.Global, + ); + window.showInformationMessage( + "Detected FIREBASE_BINARY env var. Saving to `Firebase Path` setting.", + ); + } + return { - firebasePath: config.get("firebasePath") || FIREBASE_BINARY, + firebasePath: config.get("firebasePath") || DEFAULT_FIREBASE_BINARY, npmPath: config.get("npmPath", "npm"), useFrameworks: config.get("hosting.useFrameworks", false), shouldShowIdxMetricNotice: config.get(