Skip to content

Commit bd0306f

Browse files
authored
VSCode plugin: fix predeploy call (#6238)
1 parent 95dba71 commit bd0306f

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

firebase-vscode/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## 0.0.25 (unreleased)
4+
5+
- Replace predeploy hack with something more robust.
6+
37
## 0.0.24
48

59
- Remove proxy-agent stub #6172

firebase-vscode/webpack.common.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,6 @@ const extensionConfig = {
8484
search: /Configstore\(pkg\.name\)/g,
8585
replace: "Configstore('firebase-tools')",
8686
},
87-
// TODO(hsubox76): replace with something more robust
88-
// This is an issue with a local call to cross-env-shell.js
89-
// and a dependency on calling the Node executable using an env
90-
// variable which returns a string with a lot of unusual characters
91-
// if called inside VSCode.
92-
// We may be able to copy cross-env-shell.js into dist?
93-
// For the node executable we can probably just call Node, still
94-
// need to search/replace though
95-
{
96-
search: "childProcess.spawn(translatedCommand",
97-
replace: "childProcess.spawn(escapedCommand"
98-
},
9987
// Some CLI code uses module.exports for test stubbing.
10088
// We are using ES2020 and it doesn't recognize functions called
10189
// as exports.functionName() or module.exports.functionName().
@@ -142,7 +130,13 @@ const extensionConfig = {
142130
from: "*.js",
143131
to: './',
144132
context: "../src/deploy/functions/runtimes/node",
145-
}
133+
},
134+
// Copy cross-env-shell.js used to run predeploy scripts
135+
// to ensure they work in Windows
136+
{
137+
from: "../node_modules/cross-env/dist",
138+
to: './cross-env/dist',
139+
},
146140
],
147141
})
148142
],

src/deploy/lifecycleHooks.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ import { Options } from "../options";
99

1010
function runCommand(command: string, childOptions: childProcess.SpawnOptions) {
1111
const escapedCommand = command.replace(/\"/g, '\\"');
12+
const isVSCode = utils.isVSCodeExtension();
13+
const nodeExecutable = isVSCode ? "node" : process.execPath;
14+
const crossEnvShellPath = isVSCode
15+
? path.resolve(__dirname, "./cross-env/dist/bin/cross-env-shell.js")
16+
: path.resolve(require.resolve("cross-env"), "..", "bin", "cross-env-shell.js");
1217
const translatedCommand =
13-
'"' +
14-
process.execPath +
15-
'" "' +
16-
path.resolve(require.resolve("cross-env"), "..", "bin", "cross-env-shell.js") +
17-
'" "' +
18-
escapedCommand +
19-
'"';
18+
'"' + nodeExecutable + '" "' + crossEnvShellPath + '" "' + escapedCommand + '"';
2019

2120
return new Promise<void>((resolve, reject) => {
2221
logger.info("Running command: " + command);

src/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,13 @@ export function isCloudEnvironment() {
581581
return !!process.env.CODESPACES || !!process.env.GOOGLE_CLOUD_WORKSTATIONS;
582582
}
583583

584+
/**
585+
* Detect if code is running in a VSCode Extension
586+
*/
587+
export function isVSCodeExtension(): boolean {
588+
return !!process.env.VSCODE_CWD;
589+
}
590+
584591
/**
585592
* Indicates whether or not this process is likely to be running in WSL.
586593
* @return true if we're likely in WSL, false otherwise

0 commit comments

Comments
 (0)