Skip to content

Commit

Permalink
fix: do not pass --watch for non-worker mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmeku committed Nov 2, 2020
1 parent be2ad20 commit 342f052
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
3 changes: 1 addition & 2 deletions packages/typescript/internal/ts_project.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _ts_project_impl(ctx):
arguments.use_param_file("@%s", use_always = True)
arguments.set_param_file_format("multiline")
execution_requirements["supports-workers"] = "1"
execution_requirements["worker-key-mnemonic"] = "TsProjectMnemonic"
execution_requirements["worker-key-mnemonic"] = "TsProject"
progress_prefix = "Compiling TypeScript project (worker mode)"

generated_srcs = False
Expand Down Expand Up @@ -618,7 +618,6 @@ def ts_project_macro(
"--outDir",
"$(RULEDIR)",
# FIXME: what about other settings like declaration_dir, root_dir, etc
"--watch",
],
)

Expand Down
28 changes: 23 additions & 5 deletions packages/typescript/internal/worker/worker_adapter.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
const child_process = require('child_process');

const MNEMONIC = 'TsProject';
const worker = require('./worker');

const workerArg = process.argv.indexOf('--persistent_worker')
if (workerArg > 0) {
process.argv.splice(workerArg, 1)
process.argv.splice(workerArg, 1, '--watch')

if (process.platform !== 'linux' && process.platform !== 'darwin') {
throw new Error('Worker mode is only supported on unix type systems.');
}

worker.runWorkerLoop(awaitOneBuild);
}

const [tscBin, ...tscArgs] = process.argv.slice(2);
Expand All @@ -20,7 +18,6 @@ const child = child_process.spawn(
tscArgs,
{stdio: 'pipe'},
);

function awaitOneBuild() {
child.kill('SIGCONT')

Expand Down Expand Up @@ -49,4 +46,25 @@ function awaitOneBuild() {
};
child.stdout.on('data', awaitBuild);
});
}

async function main() {
// Bazel will pass a special argument to the program when it's running us as a worker
if (workerArg > 0) {
worker.log(`Running ${MNEMONIC} as a Bazel worker`);

worker.runWorkerLoop(awaitOneBuild);
} else {
// Running standalone so stdout is available as usual
console.log(`Running ${MNEMONIC} as a standalone process`);
console.error(
`Started a new process to perform this action. Your build might be misconfigured, try
--strategy=${MNEMONIC}=worker`);

child.on('exit', code => process.exit(code));
}
}

if (require.main === module) {
main();
}

0 comments on commit 342f052

Please sign in to comment.