Skip to content

WIP: Fix #3401 #3481

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

Merged
merged 4 commits into from
Aug 6, 2018
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
1 change: 1 addition & 0 deletions packages/@ionic/cli-framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"stream-combiner2": "^1.1.1",
"string-width": "^2.1.1",
"strip-ansi": "^4.0.0",
"tree-kill": "1.2.0",
"tslib": "^1.9.0",
"untildify": "^3.0.2",
"wrap-ansi": "^3.0.1",
Expand Down
14 changes: 14 additions & 0 deletions packages/@ionic/cli-framework/src/utils/process.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import * as Debug from 'debug';
import * as lodash from 'lodash';
import * as kill from 'tree-kill';

import { createCaseInsensitiveObject } from './object';

const debug = Debug('ionic:cli-framework:utils:process');

export const ERROR_TIMEOUT_REACHED = 'TIMEOUT_REACHED';

export function killProcessTree(pid: number, signal: string | number = 'SIGTERM'): Promise<void> {
return new Promise((resolve, reject) => {
kill(pid, signal, err => {
if (err) {
debug('error while killing process tree for %d: %o', pid, err);
return reject(err);
}

resolve();
});
});
}

/**
* Creates an alternative implementation of `process.env` object.
*
Expand Down
4 changes: 2 additions & 2 deletions packages/@ionic/cli-utils/src/lib/serve.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseError, LOGGER_LEVELS, NetworkInterface, OptionGroup, PromptModule, createPrefixedFormatter } from '@ionic/cli-framework';
import { fsReadJsonFile } from '@ionic/cli-framework/utils/fs';
import { findClosestOpenPort, getExternalIPv4Interfaces, isHostConnectable } from '@ionic/cli-framework/utils/network';
import { onBeforeExit, processExit } from '@ionic/cli-framework/utils/process';
import { killProcessTree, onBeforeExit, processExit } from '@ionic/cli-framework/utils/process';
import { str2num } from '@ionic/cli-framework/utils/string';
import chalk from 'chalk';
import * as Debug from 'debug';
Expand Down Expand Up @@ -529,7 +529,7 @@ export abstract class ServeCLI<T extends ServeCLIOptions> extends EventEmitter {
p.on('error', errorHandler);
p.on('close', closeHandler);

onBeforeExit(async () => p.kill());
onBeforeExit(async () => killProcessTree(p.pid));

const log = this.e.log.clone();
log.setFormatter(createPrefixedFormatter(chalk.dim(`[${this.resolvedProgram === this.program ? this.prefix : this.resolvedProgram}]`)));
Expand Down
4 changes: 2 additions & 2 deletions packages/@ionic/cli-utils/src/lib/shell.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ERROR_SHELL_COMMAND_NOT_FOUND, LOGGER_LEVELS, ShellCommandError } from '@ionic/cli-framework';
import { createProcessEnv, onBeforeExit } from '@ionic/cli-framework/utils/process';
import { createProcessEnv, killProcessTree, onBeforeExit } from '@ionic/cli-framework/utils/process';
import { ShellCommand } from '@ionic/cli-framework/utils/shell';
import { combineStreams } from '@ionic/cli-framework/utils/streams';
import chalk from 'chalk';
Expand Down Expand Up @@ -69,7 +69,7 @@ export class Shell implements IShell {
}

if (killOnExit) {
onBeforeExit(async () => promise.p.kill());
onBeforeExit(async () => killProcessTree(promise.p.pid));
}

await promise;
Expand Down
1 change: 1 addition & 0 deletions packages/ionic/src/commands/cordova/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ ${chalk.cyan('[1]')}: ${chalk.bold('https://ionicframework.com/docs/developer-re
const ws = log.createWriteStream(LOGGER_LEVELS.INFO);

await this.runCordova(filterArgumentsForCordova(metadata, options), { stream: ws });
this.env.close(); // TODO: better way
await sleepForever();
} else {
if (options.build) {
Expand Down
1 change: 1 addition & 0 deletions packages/ionic/src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ Try the ${chalk.green('--lab')} option to see multiple platforms at once.`;

// TODO: use runner directly
await serve({ config: this.env.config, log: this.env.log, prompt: this.env.prompt, shell: this.env.shell, project: this.project }, inputs, options);
this.env.close(); // TODO: better way
await sleepForever();
}
}
Expand Down