From ff7fa81584d4dc911e09d851ee54c48d53058da6 Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Wed, 9 Aug 2023 13:54:09 -0700 Subject: [PATCH 1/3] fix predeploy --- firebase-vscode/CHANGELOG.md | 3 +++ firebase-vscode/webpack.common.js | 20 +++++++------------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/firebase-vscode/CHANGELOG.md b/firebase-vscode/CHANGELOG.md index b35d2d2568b..304244fb2d4 100644 --- a/firebase-vscode/CHANGELOG.md +++ b/firebase-vscode/CHANGELOG.md @@ -1,5 +1,8 @@ # Change Log +## 0.0.25 (unreleased) +- Replace predeploy hack with something more robust. + ## 0.0.24 - Remove proxy-agent stub #6172 diff --git a/firebase-vscode/webpack.common.js b/firebase-vscode/webpack.common.js index 30af48af49c..8b7c5786494 100644 --- a/firebase-vscode/webpack.common.js +++ b/firebase-vscode/webpack.common.js @@ -84,18 +84,6 @@ const extensionConfig = { search: /Configstore\(pkg\.name\)/g, replace: "Configstore('firebase-tools')", }, - // TODO(hsubox76): replace with something more robust - // This is an issue with a local call to cross-env-shell.js - // and a dependency on calling the Node executable using an env - // variable which returns a string with a lot of unusual characters - // if called inside VSCode. - // We may be able to copy cross-env-shell.js into dist? - // For the node executable we can probably just call Node, still - // need to search/replace though - { - search: "childProcess.spawn(translatedCommand", - replace: "childProcess.spawn(escapedCommand" - }, // Some CLI code uses module.exports for test stubbing. // We are using ES2020 and it doesn't recognize functions called // as exports.functionName() or module.exports.functionName(). @@ -142,7 +130,13 @@ const extensionConfig = { from: "*.js", to: './', context: "../src/deploy/functions/runtimes/node", - } + }, + // Copy cross-env-shell.js used to run predeploy scripts + // to ensure they work in Windows + { + from: "../node_modules/cross-env/dist", + to: './cross-env/dist', + }, ], }) ], From fdffeb2944e80e3bfb9a356dfc1bb56d2f2611fa Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Wed, 9 Aug 2023 13:54:22 -0700 Subject: [PATCH 2/3] fix predeploy --- src/deploy/lifecycleHooks.ts | 13 ++++++------- src/utils.ts | 7 +++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/deploy/lifecycleHooks.ts b/src/deploy/lifecycleHooks.ts index 008fa584657..4edc7b7c949 100644 --- a/src/deploy/lifecycleHooks.ts +++ b/src/deploy/lifecycleHooks.ts @@ -9,14 +9,13 @@ import { Options } from "../options"; function runCommand(command: string, childOptions: childProcess.SpawnOptions) { const escapedCommand = command.replace(/\"/g, '\\"'); + const isVSCode = utils.isVSCodeExtension(); + const nodeExecutable = isVSCode ? "node" : process.execPath; + const crossEnvShellPath = isVSCode + ? path.resolve(__dirname, "./cross-env/dist/bin/cross-env-shell.js") + : path.resolve(require.resolve("cross-env"), "..", "bin", "cross-env-shell.js"); const translatedCommand = - '"' + - process.execPath + - '" "' + - path.resolve(require.resolve("cross-env"), "..", "bin", "cross-env-shell.js") + - '" "' + - escapedCommand + - '"'; + '"' + nodeExecutable + '" "' + crossEnvShellPath + '" "' + escapedCommand + '"'; return new Promise((resolve, reject) => { logger.info("Running command: " + command); diff --git a/src/utils.ts b/src/utils.ts index d9c1260b822..9f424b155df 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -581,6 +581,13 @@ export function isCloudEnvironment() { return !!process.env.CODESPACES || !!process.env.GOOGLE_CLOUD_WORKSTATIONS; } +/** + * Detect if code is running in a VSCode Extension + */ +export function isVSCodeExtension(): boolean { + return !!process.env.VSCODE_CWD; +} + /** * Indicates whether or not this process is likely to be running in WSL. * @return true if we're likely in WSL, false otherwise From 44c9467952d615a31f75565bd7fc7aa89a03e79b Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Wed, 9 Aug 2023 14:13:20 -0700 Subject: [PATCH 3/3] format --- firebase-vscode/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/firebase-vscode/CHANGELOG.md b/firebase-vscode/CHANGELOG.md index 304244fb2d4..c66b2e9b10e 100644 --- a/firebase-vscode/CHANGELOG.md +++ b/firebase-vscode/CHANGELOG.md @@ -1,6 +1,7 @@ # Change Log ## 0.0.25 (unreleased) + - Replace predeploy hack with something more robust. ## 0.0.24