[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cross-spawn instead of spawn throughout extensions and functions emulators #4555

Merged
merged 4 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- Fixes missing Connection header in RTDB emulator REST streaming API (https://github.com/firebase/firebase-tools-ui/issues/3329).
- Fixes error messaging when working with apps in interactive/non-interactive modes (#4007).
- Fixes an issue where the Extensions emulator would not work on Windows (#4554).
- Removes unused `dotenv` dependency.
- Updates `fs-extra` dependency.
- Updates `tmp` dependency.
19 changes: 16 additions & 3 deletions src/emulator/extensionsEmulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as os from "os";
import * as path from "path";
import * as clc from "cli-color";
import Table = require("cli-table");
import { spawnSync } from "child_process";
import * as spawn from "cross-spawn";

import * as planner from "../deploy/extensions/planner";
import { Options } from "../options";
Expand Down Expand Up @@ -172,14 +172,22 @@ export class ExtensionsEmulator implements EmulatorInstance {

private installAndBuildSourceCode(sourceCodePath: string): void {
// TODO: Add logging during this so it is clear what is happening.
const npmInstall = spawnSync("npm", ["--prefix", `/${sourceCodePath}/functions/`, "install"], {

this.logger.logLabeled("DEBUG", "Extensions", `Running "npm install" for ${sourceCodePath}`);
const npmInstall = spawn.sync("npm", ["--prefix", `/${sourceCodePath}/functions/`, "install"], {
encoding: "utf8",
});
if (npmInstall.error) {
throw npmInstall.error;
}
this.logger.logLabeled("DEBUG", "Extensions", `Finished "npm install" for ${sourceCodePath}`);

const npmRunGCPBuild = spawnSync(
this.logger.logLabeled(
"DEBUG",
"Extensions",
`Running "npm run gcp-build" for ${sourceCodePath}`
);
const npmRunGCPBuild = spawn.sync(
"npm",
["--prefix", `/${sourceCodePath}/functions/`, "run", "gcp-build"],
{ encoding: "utf8" }
Expand All @@ -188,6 +196,11 @@ export class ExtensionsEmulator implements EmulatorInstance {
// TODO: Make sure this does not error out if "gcp-build" is not defined, but does error if it fails otherwise.
throw npmRunGCPBuild.error;
}
this.logger.logLabeled(
"DEBUG",
"Extensions",
`Finished "npm run gcp-build" for ${sourceCodePath}`
);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/emulator/functionsEmulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
import * as chokidar from "chokidar";

import * as spawn from "cross-spawn";
import { ChildProcess, spawnSync } from "child_process";
import { ChildProcess } from "child_process";
import {
EmulatedTriggerDefinition,
SignatureType,
Expand Down Expand Up @@ -995,7 +995,7 @@ export class FunctionsEmulator implements EmulatorInstance {

// Next check if we have a Node install in the node_modules folder
try {
const localNodeOutput = spawnSync(localNodePath, ["--version"]).stdout.toString();
const localNodeOutput = spawn.sync(localNodePath, ["--version"]).stdout.toString();
localMajorVersion = localNodeOutput.slice(1).split(".")[0];
} catch (err: any) {
// Will happen if we haven't asked about local version yet
Expand Down