Skip to content

Commit 828e2d6

Browse files
authored
Switch env var for isVSCE check (#8257)
* Switch env var for isVSCE check * Make it a string instead; * Need to actually access process.env for this plugin to work * actually call the function * Refactor to not use a env var * A cleaner approach - touching webpack is scary
1 parent b84c378 commit 828e2d6

File tree

6 files changed

+22
-20
lines changed

6 files changed

+22
-20
lines changed

Diff for: CHANGELOG.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
- Add initial delay when loading python functions (#8239)
2-
- Enforce webframeworks enablement only on webframeworks sites (#8168)
3-
- Fix issue where `apps:init` throws an error upon app creation
1+
- Replaced `VSCODE_CWD` check to address issues running in VSCode environments. (#7471)
2+
- Added initial delay when loading python functions (#8239)
3+
- Enforced webframeworks enablement only on webframeworks sites (#8168)
4+
- Fixed issue where `apps:init` throws an error upon app creation.
45
- Update Firebase Data Connect local toolkit to v1.8.3, which includes the following changes: (#8263)
56
- Adds a `_metadata.distance` field to vector similarity search results
67
- Fixes `auth` and `request.auth` when the request is unauthenticated

Diff for: firebase-vscode/src/extension.ts

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
import { env } from "./core/env";
2626

2727
import { suggestGraphqlSyntaxExtension } from "./data-connect/graphql-syntax-highlighter";
28+
import { setIsVSCodeExtension } from "../../src/vsCodeUtils";
2829

2930
// This method is called when your extension is activated
3031
export async function activate(context: vscode.ExtensionContext) {
@@ -93,6 +94,7 @@ async function checkCLIInstallation(): Promise<void> {
9394
const latestVersion = (await latestVersionRes.json())?.["dist-tags"]?.[
9495
"latest"
9596
];
97+
setIsVSCodeExtension(true);
9698
const env = { ...process.env, VSCODE_CWD: "" };
9799
const versionRes = spawnSync("firebase", ["--version"], {
98100
env,

Diff for: src/deploy/lifecycleHooks.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ import { isVSCodeExtension } from "../vsCodeUtils";
1010

1111
function runCommand(command: string, childOptions: childProcess.SpawnOptions) {
1212
const escapedCommand = command.replace(/\"/g, '\\"');
13-
const isVSCode = isVSCodeExtension();
14-
const nodeExecutable = isVSCode ? "node" : process.execPath;
15-
const crossEnvShellPath = isVSCode
13+
const nodeExecutable = isVSCodeExtension() ? "node" : process.execPath;
14+
const crossEnvShellPath = isVSCodeExtension()
1615
? path.resolve(__dirname, "./cross-env/dist/bin/cross-env-shell.js")
1716
: path.resolve(require.resolve("cross-env"), "..", "bin", "cross-env-shell.js");
1817
const translatedCommand =

Diff for: src/emulator/hub.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class EmulatorHub extends ExpressBasedEmulator {
5454
const locator = JSON.parse(data) as Locator;
5555

5656
// TODO: In case the locator file format is changed, handle issues with format incompatability
57-
if (!isVSCodeExtension && locator.version !== this.CLI_VERSION) {
57+
if (!isVSCodeExtension() && locator.version !== this.CLI_VERSION) {
5858
logger.debug(`Found locator with mismatched version, ignoring: ${JSON.stringify(locator)}`);
5959
return undefined;
6060
}

Diff for: src/hosting/implicitInit.ts

+7-10
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { EmulatorRegistry } from "../emulator/registry";
88
import { EMULATORS_SUPPORTED_BY_USE_EMULATOR, Emulators } from "../emulator/types";
99
import { readTemplateSync } from "../templates";
1010

11-
const INIT_TEMPLATE = readTemplateSync("hosting/init.js");
12-
1311
export interface TemplateServerResponse {
1412
// __init.js content with only initializeApp()
1513
js: string;
@@ -77,14 +75,13 @@ export async function implicitInit(options: any): Promise<TemplateServerResponse
7775
}
7876
const emulatorsJson = JSON.stringify(emulators, null, 2);
7977

80-
const js = INIT_TEMPLATE.replace("/*--CONFIG--*/", `var firebaseConfig = ${configJson};`).replace(
81-
"/*--EMULATORS--*/",
82-
"var firebaseEmulators = undefined;",
83-
);
84-
const emulatorsJs = INIT_TEMPLATE.replace(
85-
"/*--CONFIG--*/",
86-
`var firebaseConfig = ${configJson};`,
87-
).replace("/*--EMULATORS--*/", `var firebaseEmulators = ${emulatorsJson};`);
78+
const initTemplate = readTemplateSync("hosting/init.js");
79+
const js = initTemplate
80+
.replace("/*--CONFIG--*/", `var firebaseConfig = ${configJson};`)
81+
.replace("/*--EMULATORS--*/", "var firebaseEmulators = undefined;");
82+
const emulatorsJs = initTemplate
83+
.replace("/*--CONFIG--*/", `var firebaseConfig = ${configJson};`)
84+
.replace("/*--EMULATORS--*/", `var firebaseEmulators = ${emulatorsJson};`);
8885
return {
8986
js,
9087
emulatorsJs,

Diff for: src/vsCodeUtils.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import { env } from "process";
2-
1+
let _IS_WEBPACKED_FOR_VSCE = false;
32
/**
43
* Detect if code is running in a VSCode Extension
54
*/
65
export function isVSCodeExtension(): boolean {
7-
return !!env.VSCODE_CWD;
6+
return _IS_WEBPACKED_FOR_VSCE;
7+
}
8+
9+
export function setIsVSCodeExtension(v: boolean) {
10+
_IS_WEBPACKED_FOR_VSCE = v;
811
}

0 commit comments

Comments
 (0)