Skip to content

Commit

Permalink
Set FIREBASE_BINARY as "firebasePath" user setting (#7857)
Browse files Browse the repository at this point in the history
* set firebasePath as a user preference only

* update setting

* format and changelog

* add global configuration target

* format

* change to machine-overridable
  • Loading branch information
hlshen authored Oct 22, 2024
1 parent 39a5f63 commit 2559645
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions firebase-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion firebase-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
},
"firebase.firebasePath": {
"type": "string",
"markdownDescription": "%ext.config.firebasePath%"
"markdownDescription": "%ext.config.firebasePath%",
"scope": "machine-overridable"
},
"firebase.hosting.useFrameworks": {
"type": "boolean",
Expand Down
24 changes: 17 additions & 7 deletions firebase-vscode/src/utils/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConfigurationTarget, workspace } from "vscode";
import { ConfigurationTarget, window, workspace } from "vscode";

export interface Settings {
readonly firebasePath: string;
Expand All @@ -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<string>("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<string>("firebasePath") || FIREBASE_BINARY,
firebasePath: config.get<string>("firebasePath") || DEFAULT_FIREBASE_BINARY,
npmPath: config.get<string>("npmPath", "npm"),
useFrameworks: config.get<boolean>("hosting.useFrameworks", false),
shouldShowIdxMetricNotice: config.get<boolean>(
Expand Down

0 comments on commit 2559645

Please sign in to comment.