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

Pass in options for wc child process #1000

Merged
merged 6 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 13 additions & 9 deletions packages/cli/lib/commands/start.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { GoogleAnalytics, ProjectConfig, Util } from "@igniteui/cli-core";
import { ExecSyncOptions } from "child_process";
import * as path from "path";
import * as resolve from "resolve";
import { TemplateManager } from "../TemplateManager";
import { default as build } from "./build";

const execSyncNpmStart = (port: number, options: ExecSyncOptions): void => {
if (port) {
Util.execSync(`npm start -- --port=${port}`, options);
return;
}
Util.execSync(`npm start`, options);
};

let command: {
[name: string]: any,
templateManager: TemplateManager,
Expand Down Expand Up @@ -57,7 +66,9 @@ command = {
});

let port = Number(argv.port) || defaultPort;

// TODO: consider piping the stdin so that we handle the cp's termination
// this may require additional logic to be implemented if the cp asks for input
const options: ExecSyncOptions = { stdio: "inherit", killSignal: "SIGINT" };
switch (framework.toLowerCase()) {
case "jquery":
// browser-sync installed per project
Expand All @@ -82,15 +93,8 @@ command = {
}
/* falls through */
case "angular":
const options = { stdio: "inherit", killSignal: "SIGINT" };
if (port) {
Util.execSync(`npm start -- --port=` + port, options);
} else {
Util.execSync(`npm start`, options);
}
break;
case "webcomponents":
Util.execSync(`npm start`);
execSyncNpmStart(port, options);
default:
break;
}
Expand Down
10 changes: 7 additions & 3 deletions packages/core/util/Util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from "chalk";
import { execSync } from "child_process";
import { execSync, ExecSyncOptions } from "child_process";
import * as fs from "fs";
import * as glob from "glob";
import * as path from "path";
Expand Down Expand Up @@ -308,19 +308,23 @@ export class Util {
* @param options Command options
* @throws {Error} On timeout or non-zero exit code. Error has 'status', 'signal', 'output', 'stdout', 'stderr'
*/
public static execSync(command: string, options?: any) {
public static execSync(command: string, options?: ExecSyncOptions) {
try {
return execSync(command, options);
} catch (error) {
// execSync may throw an error during process interruption
// if this happens - stderr will ends with "^C" which was appended in the checkExecSyncError function
// if this happens - stderr will end with "^C" which was appended in the checkExecSyncError function
// this means that a SIGINT was attempted and failed
// npm may be involved in this as it works just fine with any other node process
if (error.stderr && error.stderr.toString().endsWith() === "^C") {
return process.exit();
}

// if SIGINT killed the process with no errors
// 3221225786 - cmd- Ctrl+C
// 128 - bash - invalid argument to exit
// 130 - bash - Ctrl+C
// 255 - bash - exit status out of range
if (error.status === 3221225786 || error.status > 128) {
return process.exit();
}
Expand Down