From 079c4b3482e56124b14f64fc8279ffdabc4b7b64 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Wed, 21 Nov 2018 19:49:33 +0100 Subject: [PATCH] fix(bazel): do not throw error when writing tsickle externs (#27200) * Currently when building the ES5 and ES2015 output, `ngc_wrapped` will fail because it tries to write the `fs.openSync` the tsickle output file at the same time. This causes a runtime exception in Windows and can be fixed by just writing the externs for ES5 mode to the proper ES5 "output root". PR Close #27200 --- packages/bazel/src/modify_tsconfig.js | 29 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/bazel/src/modify_tsconfig.js b/packages/bazel/src/modify_tsconfig.js index b93fd97636..9d3c491598 100644 --- a/packages/bazel/src/modify_tsconfig.js +++ b/packages/bazel/src/modify_tsconfig.js @@ -18,24 +18,33 @@ function main(args) { if (args.length < 3) { console.error('Usage: $0 input.tsconfig.json output.tsconfig.json newRoot binDir'); } - [input, output, newRoot, binDir] = args; + const [input, output, newRoot, binDir] = args; const data = JSON.parse(fs.readFileSync(input, {encoding: 'utf-8'})); - data['compilerOptions']['target'] = 'es5'; - data['bazelOptions']['es5Mode'] = true; - data['compilerOptions']['outDir'] = path.posix.join(data['compilerOptions']['outDir'], newRoot); + const {compilerOptions, bazelOptions} = data; + + // Relative path to the execroot that refers to the directory for the ES5 output files. + const newOutputBase = path.posix.join(binDir, newRoot); + + // Update the compiler options to produce ES5 output. Also ensure that the new ES5 output + // directory is used. + compilerOptions['target'] = 'es5'; + compilerOptions['outDir'] = path.posix.join(compilerOptions['outDir'], newRoot); + + bazelOptions['es5Mode'] = true; + bazelOptions['tsickleExternsPath'] = + bazelOptions['tsickleExternsPath'].replace(binDir, newOutputBase); + if (data['angularCompilerOptions']) { - // Relative path to the execroot that refers to the directory for the ES5 output files. - const newOutputBase = path.posix.join(binDir, newRoot); + const {angularCompilerOptions} = data; // Don't enable tsickle's closure conversions - data['angularCompilerOptions']['annotateForClosureCompiler'] = false; + angularCompilerOptions['annotateForClosureCompiler'] = false; // Note: It's important that the "expectedOut" is only modified in a way that still // keeps posix normalized paths. Otherwise this could cause unexpected behavior because // ngc-wrapped is expecting POSIX paths and the TypeScript Bazel rules by default only pass // POSIX paths as well. - data['angularCompilerOptions']['expectedOut'] = - data['angularCompilerOptions']['expectedOut'].map( - f => f.replace(/\.closure\.js$/, '.js').replace(binDir, newOutputBase)); + angularCompilerOptions['expectedOut'] = angularCompilerOptions['expectedOut'].map( + f => f.replace(/\.closure\.js$/, '.js').replace(binDir, newOutputBase)); } fs.writeFileSync(output, JSON.stringify(data)); }