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
This commit is contained in:
parent
7d598801f0
commit
20a2bae1d3
|
@ -18,23 +18,32 @@ function main(args) {
|
||||||
if (args.length < 3) {
|
if (args.length < 3) {
|
||||||
console.error('Usage: $0 input.tsconfig.json output.tsconfig.json newRoot binDir');
|
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'}));
|
const data = JSON.parse(fs.readFileSync(input, {encoding: 'utf-8'}));
|
||||||
data['compilerOptions']['target'] = 'es5';
|
const {compilerOptions, bazelOptions} = data;
|
||||||
data['bazelOptions']['es5Mode'] = true;
|
|
||||||
data['compilerOptions']['outDir'] = path.posix.join(data['compilerOptions']['outDir'], newRoot);
|
|
||||||
if (data['angularCompilerOptions']) {
|
|
||||||
// Relative path to the execroot that refers to the directory for the ES5 output files.
|
// Relative path to the execroot that refers to the directory for the ES5 output files.
|
||||||
const newOutputBase = path.posix.join(binDir, newRoot);
|
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']) {
|
||||||
|
const {angularCompilerOptions} = data;
|
||||||
// Don't enable tsickle's closure conversions
|
// 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
|
// 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
|
// 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
|
// ngc-wrapped is expecting POSIX paths and the TypeScript Bazel rules by default only pass
|
||||||
// POSIX paths as well.
|
// POSIX paths as well.
|
||||||
data['angularCompilerOptions']['expectedOut'] =
|
angularCompilerOptions['expectedOut'] = angularCompilerOptions['expectedOut'].map(
|
||||||
data['angularCompilerOptions']['expectedOut'].map(
|
|
||||||
f => f.replace(/\.closure\.js$/, '.js').replace(binDir, newOutputBase));
|
f => f.replace(/\.closure\.js$/, '.js').replace(binDir, newOutputBase));
|
||||||
}
|
}
|
||||||
fs.writeFileSync(output, JSON.stringify(data));
|
fs.writeFileSync(output, JSON.stringify(data));
|
||||||
|
|
Loading…
Reference in New Issue