Skip to content

Commit

Permalink
pass config to child process simpler (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
zinserjan authored Sep 15, 2017
1 parent e54b267 commit aad9653
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
18 changes: 11 additions & 7 deletions src/worker/TsCheckerRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ import * as path from "path";
import IncrementalChecker from "../checker/IncrementalChecker";
import { transformToWebpackBuildResult, serializeWebpackBuildResult } from "../checker/resultSerializer";

export interface TsCheckerRuntimeConfig {
tsconfigPath: string;
diagnosticFormatter: string;
tslintPath?: string;
timings: boolean;
}

process.on("SIGINT", function() {
process.exit(130);
});

const tsconfigPath = process.env.TSCONFIG;
const diagnosticFormatter = process.env.DIAGNOSTIC_FORMATTER;
const tslintPath = process.env.TSLINT;
const timings = process.env.TIMINGS === "true";
const contextPath = path.dirname(tsconfigPath);
const config: TsCheckerRuntimeConfig = JSON.parse(process.env.TS_CHECKER_CONFIG);
const contextPath = path.dirname(config.tsconfigPath);

const incrementalChecker = new IncrementalChecker(timings, tsconfigPath, tslintPath);
const incrementalChecker = new IncrementalChecker(config.timings, config.tsconfigPath, config.tslintPath);

const messageOk = {
id: "ok",
Expand Down Expand Up @@ -41,7 +45,7 @@ process.on("message", function(message: any) {
incrementalChecker.updateBuiltFiles(message.files);
const result = incrementalChecker.run();

const webpackResult = transformToWebpackBuildResult(result, contextPath, diagnosticFormatter);
const webpackResult = transformToWebpackBuildResult(result, contextPath, config.diagnosticFormatter);
const serialized = serializeWebpackBuildResult(webpackResult);

sendMessage({
Expand Down
21 changes: 9 additions & 12 deletions src/worker/TsCheckerWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import { fork, ChildProcess } from "child_process";
import { deserializeWebpackBuildResult, WebpackBuildResult } from "../checker/resultSerializer";
import pDefer = require("p-defer");
const supportsColor = require("supports-color");
import { TsCheckerRuntimeConfig } from "./TsCheckerRuntime";

export default class TsCheckerWorker {
private process: ChildProcess | null = null;
private memoryLimit: number;
private timings: boolean;
private tsconfigPath: string;
private diagnosticFormatter: string;
private tslintPath?: string;
private exitListener: () => void;
private runtimeConfig: TsCheckerRuntimeConfig;

constructor(
memoryLimit: number,
Expand All @@ -20,10 +18,12 @@ export default class TsCheckerWorker {
tslintPath?: string
) {
this.memoryLimit = memoryLimit;
this.timings = timings;
this.tsconfigPath = tsconfigPath;
this.diagnosticFormatter = diagnosticFormatter;
this.tslintPath = tslintPath;
this.runtimeConfig = {
tsconfigPath,
diagnosticFormatter,
tslintPath,
timings,
};
this.exitListener = () => {
if (this.process != null) {
this.process.kill();
Expand All @@ -50,10 +50,7 @@ export default class TsCheckerWorker {
execArgv: [`--max-old-space-size=${this.memoryLimit}`],
env: {
FORCE_COLOR: Number(supportsColor),
TSCONFIG: this.tsconfigPath,
DIAGNOSTIC_FORMATTER: this.diagnosticFormatter,
TIMINGS: this.timings,
...this.tslintPath ? { TSLINT: this.tslintPath } : {},
TS_CHECKER_CONFIG: JSON.stringify(this.runtimeConfig),
},
stdio: ["inherit", "inherit", "inherit", "ipc"],
}
Expand Down

0 comments on commit aad9653

Please sign in to comment.