Skip to content

Commit f6e82cc

Browse files
authored
build: fix release output containing invalid imports sometimes (#20214)
A very subtle issue has surfaced in our release output. Based on previous builds that have been performed locally by the caretaker performing the release, the release output might differ and contain invalid module imports that break ES2015 output. Notably the es2015 output is not primarily used by the CLI. It uses the flat ES2015 output instead. The issue surfaces because of a bug in `@bazel/typescript` where the `moduleName` for source files is leaking between TSC worker runs. This means that source files are incorrectly referenced by module name, instead of relative path when the prodmode ES2015 output is built. Deep paths to source files are not supported as per Angular Package format. We patch the fix that is pending upstream to ensure our release output works: bazelbuild/rules_typescript#504. Once the fix upstream lands (which might take quite some time; given g3 sync and sync with the rules_nodejs repository), we can remove the patch and update to the latest version of `@bazel/typescript`. Fixes #20179.
1 parent de3222a commit f6e82cc

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
diff --git node_modules/@bazel/typescript/internal/tsc_wrapped/compiler_host.js node_modules/@bazel/typescript/internal/tsc_wrapped/compiler_host.js
2+
index 031d9dad1..a7fe9b79b 100644
3+
--- node_modules/@bazel/typescript/internal/tsc_wrapped/compiler_host.js
4+
+++ node_modules/@bazel/typescript/internal/tsc_wrapped/compiler_host.js
5+
@@ -377,10 +377,27 @@ class CompilerHost {
6+
`which would be overwritten with ${moduleName} ` +
7+
`by Bazel's TypeScript compiler.`);
8+
}
9+
- // Setting the moduleName is equivalent to the original source having a
10+
- // ///<amd-module name="some/name"/> directive
11+
+
12+
+ // Setting the moduleName is equivalent to the original source having the triple
13+
+ // slash `///<amd-module name="some/name"/>` directive. Also note that we tag
14+
+ // source files for which we assigned a generated module name. This is necessary
15+
+ // so that we can reset the module name when the same source file is loaded from
16+
+ // a cache, but with a different module format where the auto-generated module
17+
+ // names are not desirable. The module name should not leak from previous
18+
+ // compilations through a potential source file cache.
19+
+ sf._hasGeneratedAmdModuleName = true;
20+
sf.moduleName = moduleName;
21+
+ return sf;
22+
}
23+
+
24+
+ // If the loaded source file has a generated amd module name applied from
25+
+ // previous compilations (in worker mode), reset the file module name
26+
+ // as neither the UMD or AMD module format is used (for which we generate
27+
+ // the AMD module names automatically).
28+
+ if (sf._hasGeneratedAmdModuleName) {
29+
+ sf.moduleName = undefined;
30+
+ }
31+
+
32+
return sf;
33+
});
34+
}

tools/postinstall/apply-patches.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const chalk = require('chalk');
1414
* Version of the post install patch. Needs to be incremented when
1515
* existing patches or edits have been modified.
1616
*/
17-
const PATCH_VERSION = 6;
17+
const PATCH_VERSION = 9;
1818

1919
/** Path to the project directory. */
2020
const projectDir = path.join(__dirname, '../..');
@@ -110,6 +110,9 @@ function applyPatches() {
110110
// Workaround for: https://github.com/bazelbuild/rules_nodejs/issues/1208.
111111
applyPatch(path.join(__dirname, './manifest_externs_hermeticity.patch'));
112112

113+
// Patches the changes from: https://github.com/bazelbuild/rules_typescript/pull/504.
114+
applyPatch(path.join(__dirname, './@bazel_typescript_tsc_wrapped_worker_cache_fix.patch'));
115+
113116
// Workaround for https://github.com/angular/angular/issues/33452:
114117
searchAndReplace(
115118
/angular_compiler_options = {/, `$&

0 commit comments

Comments
 (0)