Skip to content

Forked type checker execArgs #8090

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 3 commits into from
Oct 18, 2017
Merged
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
32 changes: 27 additions & 5 deletions packages/@ngtools/webpack/src/angular_compiler_plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'fs';
import { fork, ChildProcess } from 'child_process';
import { fork, ForkOptions, ChildProcess } from 'child_process';
import * as path from 'path';
import * as ts from 'typescript';

Expand Down Expand Up @@ -458,7 +458,29 @@ export class AngularCompilerPlugin implements Tapable {
? './type_checker_bootstrap.js'
: './type_checker.js';

this._typeCheckerProcess = fork(path.resolve(__dirname, typeCheckerFile));
let hasMemoryFlag = false;
const memoryFlagRegex = /--max-old-space-size/;
const debugArgRegex = /--inspect(?:-brk|-port)?|--debug(?:-brk|-port)/;

const execArgv = process.execArgv.filter((arg) => {
// Check if memory is being set by parent process.
if (memoryFlagRegex.test(arg)) {
hasMemoryFlag = true;
}

// Remove debug args.
// Workaround for https://github.com/nodejs/node/issues/9435
return !debugArgRegex.test(arg);
});

if (!hasMemoryFlag) {
// Force max 8gb ram.
execArgv.push('--max-old-space-size=8192');
}

const forkOptions: ForkOptions = { execArgv };

this._typeCheckerProcess = fork(path.resolve(__dirname, typeCheckerFile), [], forkOptions);
this._typeCheckerProcess.send(new InitMessage(this._compilerOptions, this._basePath,
this._JitMode, this._tsFilenames));

Expand All @@ -467,9 +489,9 @@ export class AngularCompilerPlugin implements Tapable {
treeKill(this._typeCheckerProcess.pid, 'SIGTERM');
process.exit();
};
process.on('exit', killTypeCheckerProcess);
process.on('SIGINT', killTypeCheckerProcess);
process.on('uncaughtException', killTypeCheckerProcess);
process.once('exit', killTypeCheckerProcess);
process.once('SIGINT', killTypeCheckerProcess);
process.once('uncaughtException', killTypeCheckerProcess);
}

private _updateForkedTypeChecker(changedTsFiles: string[]) {
Expand Down