From 83f8d37be0f3493f7e30e5c8e22720abbed4ebb7 Mon Sep 17 00:00:00 2001 From: Dan Muller Date: Mon, 2 Nov 2020 16:04:02 +0000 Subject: [PATCH] fix: log on standalone failures --- packages/typescript/internal/ts_project.bzl | 23 +++++++++++++++++-- .../internal/worker/worker_adapter.js | 20 +++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/packages/typescript/internal/ts_project.bzl b/packages/typescript/internal/ts_project.bzl index 5bd7bb0e69..c9146a82af 100644 --- a/packages/typescript/internal/ts_project.bzl +++ b/packages/typescript/internal/ts_project.bzl @@ -21,6 +21,13 @@ _DEFAULT_TSC_BIN = ( "//:node_modules/typescript/bin/tsc" ) +_DEFAULT_TYPESCRIP_MODULE = ( + # BEGIN-INTERNAL + "@npm" + + # END-INTERNAL + "//typescript" +) + _ATTRS = { "args": attr.string_list(), "declaration_dir": attr.string(), @@ -314,6 +321,8 @@ def ts_project_macro( emit_declaration_only = False, ts_build_info_file = None, tsc = None, + worker_tsc_bin = _DEFAULT_TSC_BIN, + worker_typescript_module = _DEFAULT_TYPESCRIP_MODULE, validate = True, supports_workers = False, declaration_dir = None, @@ -481,6 +490,15 @@ def ts_project_macro( For example, `tsc = "@my_deps//typescript/bin:tsc"` Or you can pass a custom compiler binary instead. + worker_tsc_bin: Label of the TypeScript compiler binary to run when running in worker mode. + + For example, `tsc = "@my_deps//node_modules/typescript/bin/tsc"` + Or you can pass a custom compiler binary instead. + + worker_typescript_module: Label of the package containing all data deps of worker_tsc_bin. + + For example, `tsc = "@my_deps//typescript"` + validate: boolean; whether to check that the tsconfig settings match the attributes. supports_workers: Experimental! Use only with caution. @@ -604,14 +622,15 @@ def ts_project_macro( name = tsc_worker, data = [ Label("//packages/typescript/internal/worker:worker"), - Label(_DEFAULT_TSC_BIN), + Label(worker_tsc_bin), + Label(worker_typescript_module), Label(protobufjs), tsconfig, ], entry_point = Label("//packages/typescript/internal/worker:worker_adapter"), templated_args = [ "--nobazel_patch_module_resolver", - "$(execpath {})".format(Label(_DEFAULT_TSC_BIN)), + "$(execpath {})".format(Label(worker_tsc_bin)), "--project", "$(execpath {})".format(tsconfig), # FIXME: should take out_dir into account diff --git a/packages/typescript/internal/worker/worker_adapter.js b/packages/typescript/internal/worker/worker_adapter.js index 88a95fe90d..f96d3f08f2 100644 --- a/packages/typescript/internal/worker/worker_adapter.js +++ b/packages/typescript/internal/worker/worker_adapter.js @@ -61,7 +61,25 @@ async function main() { `Started a new process to perform this action. Your build might be misconfigured, try --strategy=${MNEMONIC}=worker`); - child.on('exit', code => process.exit(code)); + const stdoutbuffer = []; + child.stdout.on('data', data => stdoutbuffer.push(data)); + + const stderrbuffer = []; + child.stderr.on('data', data => stderrbuffer.push(data)); + + child.on('exit', code => { + if (code !== 0) { + console.error( + `\nstdout from tsc:\n\n ${ + stdoutbuffer.map(s => s.toString()).join('').replace(/\n/g, '\n ')}`, + ) + console.error( + `\nstderr from tsc:\n\n ${ + stderrbuffer.map(s => s.toString()).join('').replace(/\n/g, '\n ')}`, + ) + } + process.exit(code) + }); } }