[go: nahoru, domu]

Skip to content

Commit

Permalink
Use shell:true for Pub/Sub emulator on Windows (#7033)
Browse files Browse the repository at this point in the history
* Use shell:true on windows

* actually pass opt
  • Loading branch information
joehan committed Apr 23, 2024
1 parent cb91d31 commit 6f20fbd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Release Firestore Emulator version 1.19.5 which adds support for import and export in Datastore Mode (#7020).
- Release Firestore Emulator version 1.19.5 which adds support for import and export in Datastore Mode. (#7020)
- Fix non static check for not-found route in Next.js 14.2 (#7012)
- Fix Next.js path issue on Windows (#7031)
- Fixes an issue where the Pub/Sub emulator would not start on Windows due to CVE-2024-27980. (#7026)
14 changes: 12 additions & 2 deletions src/emulator/downloadableEmulators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ const Commands: { [s in DownloadableEmulators]: DownloadableEmulatorCommand } =
"single_project_mode",
],
joinArgs: false,
shell: false,
},
firestore: {
binary: "java",
Expand All @@ -204,6 +205,7 @@ const Commands: { [s in DownloadableEmulators]: DownloadableEmulatorCommand } =
// "single_project_mode_error",
],
joinArgs: false,
shell: false,
},
storage: {
// This is for the Storage Emulator rules runtime, which is started
Expand All @@ -219,18 +221,21 @@ const Commands: { [s in DownloadableEmulators]: DownloadableEmulatorCommand } =
],
optionalArgs: [],
joinArgs: false,
shell: false,
},
pubsub: {
binary: getExecPath(Emulators.PUBSUB)!,
args: [],
optionalArgs: ["port", "host"],
joinArgs: true,
shell: true,
},
ui: {
binary: "node",
args: [getExecPath(Emulators.UI)],
optionalArgs: [],
joinArgs: false,
shell: false,
},
};

Expand Down Expand Up @@ -306,6 +311,7 @@ export function _getCommand(
args: cmdLineArgs,
optionalArgs: baseCmd.optionalArgs,
joinArgs: baseCmd.joinArgs,
shell: baseCmd.shell,
};
}

Expand Down Expand Up @@ -360,15 +366,19 @@ async function _runBinary(
const logger = EmulatorLogger.forEmulator(emulator.name);
emulator.stdout = fs.createWriteStream(getLogFileName(emulator.name));
try {
emulator.instance = childProcess.spawn(command.binary, command.args, {
const opts: childProcess.SpawnOptions = {
env: { ...process.env, ...extraEnv },
// `detached` must be true as else a SIGINT (Ctrl-c) will stop the child process before we can handle a
// graceful shutdown and call `downloadableEmulators.stop(...)` ourselves.
// Note that it seems to be a problem with gRPC processes for which a fix may be found on the Java side
// related to this issue: https://github.com/grpc/grpc-java/pull/6512
detached: true,
stdio: ["inherit", "pipe", "pipe"],
});
};
if (command.shell && utils.IS_WINDOWS) {
opts.shell = true;
}
emulator.instance = childProcess.spawn(command.binary, command.args, opts);
} catch (e: any) {
if (e.code === "EACCES") {
// Known issue when WSL users don't have java
Expand Down
1 change: 1 addition & 0 deletions src/emulator/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export interface DownloadableEmulatorCommand {
args: string[];
optionalArgs: string[];
joinArgs: boolean;
shell: boolean;
}

export interface EmulatorDownloadOptions {
Expand Down
8 changes: 4 additions & 4 deletions src/functions/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as path from "path";
import * as spawn from "cross-spawn";
import * as cp from "child_process";
import { logger } from "../logger";
import { IS_WINDOWS } from "../utils";

/**
* Default directory for python virtual environment.
Expand All @@ -12,12 +13,11 @@ export const DEFAULT_VENV_DIR = "venv";
* Get command for running Python virtual environment for given platform.
*/
export function virtualEnvCmd(cwd: string, venvDir: string): { command: string; args: string[] } {
const activateScriptPath =
process.platform === "win32" ? ["Scripts", "activate.bat"] : ["bin", "activate"];
const activateScriptPath = IS_WINDOWS ? ["Scripts", "activate.bat"] : ["bin", "activate"];
const venvActivate = `"${path.join(cwd, venvDir, ...activateScriptPath)}"`;
return {
command: process.platform === "win32" ? venvActivate : ".",
args: [process.platform === "win32" ? "" : venvActivate],
command: IS_WINDOWS ? venvActivate : ".",
args: [IS_WINDOWS ? "" : venvActivate],
};
}

Expand Down

0 comments on commit 6f20fbd

Please sign in to comment.