diff --git a/packages/typescript/internal/ts_project.bzl b/packages/typescript/internal/ts_project.bzl index f6eb0a6cc6..9387a50ecf 100644 --- a/packages/typescript/internal/ts_project.bzl +++ b/packages/typescript/internal/ts_project.bzl @@ -549,15 +549,11 @@ def ts_project_macro( ) extra_deps.append("_validate_%s_options" % name) - is_windows = select({ - "@bazel_tools//src/conditions:host_windows": True, - "//conditions:default": False, - }) - supports_workers = supports_workers and not is_windows if supports_workers: - worker_name = name + "_worker" + if not tsc: + tsc = _DEFAULT_TSC nodejs_binary( - name = worker_name, + name = "%s_worker" % name, data = [ tsconfig, "//packages/typescript/internal/worker:copy_worker_js", @@ -568,15 +564,16 @@ def ts_project_macro( entry_point = "//packages/typescript/internal/worker:worker_adapter", templated_args = [ "--nobazel_patch_module_resolver", - "$(rootpath {tsc})".format(tsc = tsc), + "$(rootpaths {})".format(tsc), "--project", - "$(execpath {tsconfig})".format(tsconfig = tsconfig), + "$(execpath {})".format(tsconfig), + # FIXME: should take out_dir into account "--outDir", "$(RULEDIR)", + # FIXME: what about other settings like declaration_dir, root_dir, etc "--watch", ], ) - tsc = ":" + worker_name typings_out_dir = declaration_dir if declaration_dir else out_dir tsbuildinfo_path = ts_build_info_file if ts_build_info_file else name + ".tsbuildinfo" @@ -600,6 +597,13 @@ def ts_project_macro( typings_outs = _out_paths(srcs, typings_out_dir, root_dir, ".d.ts") if declaration or composite else [], typing_maps_outs = _out_paths(srcs, typings_out_dir, root_dir, ".d.ts.map") if declaration_map else [], buildinfo_out = tsbuildinfo_path if composite or incremental else None, - tsc = tsc, + tsc = select({ + "@bazel_tools//src/conditions:host_windows": tsc, + "//conditions:default": "%s_worker" % name if supports_workers else tsc, + }), + supports_workers = select({ + "@bazel_tools//src/conditions:host_windows": False, + "//conditions:default": supports_workers, + }), **kwargs ) diff --git a/packages/typescript/test/ts_project/worker/BUILD.bazel b/packages/typescript/test/ts_project/worker/BUILD.bazel index d88f89fa68..02afbe01ef 100644 --- a/packages/typescript/test/ts_project/worker/BUILD.bazel +++ b/packages/typescript/test/ts_project/worker/BUILD.bazel @@ -1,6 +1,10 @@ load("//packages/typescript:index.bzl", "ts_project") ts_project( - declaration = True, supports_workers = True, + tsconfig = { + "compilerOptions": { + "declaration": True, + }, + }, ) diff --git a/packages/typescript/test/ts_project/worker/big.ts b/packages/typescript/test/ts_project/worker/big.ts index c47d1b0914..90967f4441 100644 --- a/packages/typescript/test/ts_project/worker/big.ts +++ b/packages/typescript/test/ts_project/worker/big.ts @@ -1,3 +1,3 @@ // TODO: make it big enough to slow down tsc -export const a: number = 45; +export const a: number = 47; diff --git a/packages/typescript/test/ts_project/worker/tsconfig.json b/packages/typescript/test/ts_project/worker/tsconfig.json deleted file mode 100644 index 1e6e3b3652..0000000000 --- a/packages/typescript/test/ts_project/worker/tsconfig.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "compilerOptions": { - "types": [], - "declaration": true - } -} \ No newline at end of file diff --git a/packages/typescript/test/ts_project/worker/worker_adapter.js b/packages/typescript/test/ts_project/worker/worker_adapter.js deleted file mode 100644 index 1eae15672f..0000000000 --- a/packages/typescript/test/ts_project/worker/worker_adapter.js +++ /dev/null @@ -1,40 +0,0 @@ -const child_process = require('child_process'); - -const worker = require('./worker'); - -const workerArg = process.argv.indexOf('--persistent_worker') -if (workerArg > 0) { - process.argv.splice(workerArg, 1) - - 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); - -const child = child_process.spawn( - tscBin, - tscArgs, - {stdio: 'pipe'}, -); - -function awaitOneBuild() { - child.kill('SIGCONT') - - return new Promise((res) => { - function awaitBuild(s) { - if (s.includes('Watching for file changes.')) { - child.kill('SIGSTOP') - - const success = s.includes('Found 0 errors.'); - res(success); - - child.stdout.removeListener('data', awaitBuild); - } - }; - child.stdout.on('data', awaitBuild); - }); -} \ No newline at end of file