Skip to content

Commit 55c6c4a

Browse files
Alex Eaglealexeagle
authored andcommitted
fix(typescript): don't mix worker mode and linker
This causes hard-to-reproduce resource leaks as demonstrated in #1803 Also we didn't fully understand this before, for example if a worker process stayed running we'd never re-link under it when deps change For now make the conservative fix to keep these two capabilities distinct Fixes #1803
1 parent efe6513 commit 55c6c4a

10 files changed

Lines changed: 77 additions & 39 deletions

File tree

examples/angular/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
},
1010
"dependencies": {
1111
"@angular/animations": "9.1.0",
12-
"@angular/cdk": "9.0.0",
12+
"@angular/cdk": "9.2.0",
1313
"@angular/common": "9.1.0",
1414
"@angular/core": "9.1.0",
1515
"@angular/forms": "9.1.0",
16-
"@angular/material": "9.0.0",
16+
"@angular/material": "9.2.0",
1717
"@angular/platform-browser": "9.1.0",
1818
"@angular/platform-browser-dynamic": "9.1.0",
1919
"@angular/platform-server": "^9.1.0",
@@ -61,7 +61,7 @@
6161
"rollup-plugin-commonjs": "^10.1.0",
6262
"rollup-plugin-node-resolve": "^5.2.0",
6363
"terser": "4.3.1",
64-
"typescript": "3.6.4"
64+
"typescript": "3.8.3"
6565
},
6666
"scripts": {
6767
"build": "bazelisk build //src:prodapp",

examples/angular/src/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ ts_library(
5353
use_angular_plugin = True,
5454
deps = [
5555
"//src/app",
56+
# Needed for the angular compiler plugin
57+
"@npm//@angular/compiler-cli",
5658
"@npm//@angular/core",
5759
"@npm//@angular/platform-browser",
5860
"@npm//@angular/router",

examples/angular/src/app/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ ts_library(
1717
"//src/app/todos",
1818
"//src/app/todos/reducers",
1919
"//src/shared/material",
20+
# Needed for the angular compiler plugin
21+
"@npm//@angular/compiler-cli",
2022
"@npm//@angular/core",
2123
"@npm//@angular/platform-browser",
2224
"@npm//@angular/router",
@@ -31,6 +33,8 @@ ts_library(
3133
use_angular_plugin = True,
3234
deps = [
3335
":app",
36+
# Needed for the angular compiler plugin
37+
"@npm//@angular/compiler-cli",
3438
"@npm//@angular/core",
3539
"@npm//@angular/platform-server",
3640
],

examples/angular/src/app/hello-world/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ ts_library(
2424
deps = [
2525
"//src/lib/shorten",
2626
"//src/shared/material",
27+
# Needed for the angular compiler plugin
28+
"@npm//@angular/compiler-cli",
2729
"@npm//@angular/core",
2830
"@npm//@angular/forms",
2931
"@npm//@angular/router",

examples/angular/src/app/home/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ ts_library(
99
tsconfig = "//src:tsconfig.json",
1010
use_angular_plugin = True,
1111
deps = [
12+
# Needed for the angular compiler plugin
13+
"@npm//@angular/compiler-cli",
1214
"@npm//@angular/core",
1315
"@npm//@angular/router",
1416
],

examples/angular/src/app/todos/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ ts_library(
2323
deps = [
2424
"//src/app/todos/reducers",
2525
"//src/shared/material",
26+
# Needed for the angular compiler plugin
27+
"@npm//@angular/compiler-cli",
2628
"@npm//@angular/common",
2729
"@npm//@angular/core",
2830
"@npm//@angular/forms",

examples/angular/src/shared/material/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ ts_library(
88
tsconfig = "//src:tsconfig.json",
99
use_angular_plugin = True,
1010
deps = [
11+
# Needed for the angular compiler plugin
12+
"@npm//@angular/compiler-cli",
1113
"@npm//@angular/core",
1214
"@npm//@angular/material",
1315
],

examples/angular/yarn.lock

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
shelljs "0.8.2"
4545
tsickle "^0.38.0"
4646

47-
"@angular/cdk@9.0.0":
48-
version "9.0.0"
49-
resolved "https://registry.yarnpkg.com/@angular/cdk/-/cdk-9.0.0.tgz#5734817ae97044f90d304fa0f25c9c1a7fa0bf96"
50-
integrity sha512-2kYpyYbewIB6fubSIDMvSprJLNplRZoL/AtXW3od4dLyRxtzX+7iWTAtzUG/dhq8CKev0lpd1HENh5lLR/Lhjw==
47+
"@angular/cdk@9.2.0":
48+
version "9.2.0"
49+
resolved "https://registry.yarnpkg.com/@angular/cdk/-/cdk-9.2.0.tgz#587e4a9d5046fa89a68d8eddaee6b185e2915842"
50+
integrity sha512-jeeznvNDpR9POuxzz8Y0zFvMynG9HCJo3ZPTqOjlOq8Lj8876+rLsHDvKEMeLdwlkdi1EweYJW1CLQzI+TwqDA==
5151
optionalDependencies:
5252
parse5 "^5.0.0"
5353

@@ -115,10 +115,10 @@
115115
resolved "https://registry.yarnpkg.com/@angular/forms/-/forms-9.1.0.tgz#de14e34aa37bd41a28f93fee8666cd7f6393078c"
116116
integrity sha512-5GC8HQlPChPV+168zLlm4yj4syA6N9ChSKV0tmzj1zIfMcub1UAOaB9IYaXRHQsjPFh9OuQXwmkzScyAfhEVjA==
117117

118-
"@angular/material@9.0.0":
119-
version "9.0.0"
120-
resolved "https://registry.yarnpkg.com/@angular/material/-/material-9.0.0.tgz#655bfd4d4047337e84480b9f92be8e81af375b92"
121-
integrity sha512-QxN2rmR5mvg2YE1NoIGWLpbnmcJq0iFidzy6odzvN17+XkoCJBZ65IdYsHrJgfwGpoIy6bywuixrDHHcSh9I5w==
118+
"@angular/material@9.2.0":
119+
version "9.2.0"
120+
resolved "https://registry.yarnpkg.com/@angular/material/-/material-9.2.0.tgz#1b6f0a2e115f93885d7fc2dc4b258d8c9cf6821f"
121+
integrity sha512-KKzEIVh6/m56m+Ao8p4PK0SyEr0574l3VP2swj1qPag3u+FYgemmXCGTaChrKdDsez+zeTCPXImBGXzE6NQ80Q==
122122

123123
"@angular/platform-browser-dynamic@9.1.0":
124124
version "9.1.0"
@@ -6907,10 +6907,10 @@ typedarray@^0.0.6:
69076907
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
69086908
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
69096909

6910-
typescript@3.6.4:
6911-
version "3.6.4"
6912-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.4.tgz#b18752bb3792bc1a0281335f7f6ebf1bbfc5b91d"
6913-
integrity sha512-unoCll1+l+YK4i4F8f22TaNVPRHcD9PA3yCuZ8g5e0qGqlVlJ/8FSateOLLSagn+Yg5+ZwuPkL8LFUc0Jcvksg==
6910+
typescript@3.8.3:
6911+
version "3.8.3"
6912+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
6913+
integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==
69146914

69156915
typescript@~3.5.3:
69166916
version "3.5.3"

packages/typescript/src/internal/build_defs.bzl

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -140,34 +140,54 @@ def _compile_action(ctx, inputs, outputs, tsconfig_file, node_opts, description
140140
# Pass actual options for the node binary in the special "--node_options" argument.
141141
arguments = ["--node_options=%s" % opt for opt in node_opts]
142142

143-
# One at-sign makes this a params-file, enabling the worker strategy.
144-
# Two at-signs escapes the argument so it's passed through to tsc_wrapped
145-
# rather than the contents getting expanded.
146-
if ctx.attr.supports_workers:
143+
# We don't try to use the linker to launch the worker process
144+
# because it causes bazel to spawn a new worker for every action
145+
# See https://github.com/bazelbuild/rules_nodejs/issues/1803
146+
# TODO: understand the interaction between linker and workers better
147+
# When using plugins, we need the linker, so we disable workers for that case as well
148+
if ctx.attr.supports_workers and not ctx.attr.use_angular_plugin:
149+
# One at-sign makes this a params-file, enabling the worker strategy.
150+
# Two at-signs escapes the argument so it's passed through to tsc_wrapped
151+
# rather than the contents getting expanded.
147152
arguments.append("@@" + tsconfig_file.path)
148-
mnemonic = "TypeScriptCompile"
153+
154+
# Spawn a plain action that runs worker process with no linker
155+
ctx.actions.run(
156+
progress_message = "Compiling TypeScript (%s) %s" % (description, ctx.label),
157+
mnemonic = "TypeScriptCompile",
158+
inputs = action_inputs,
159+
outputs = action_outputs,
160+
# Use the built-in shell environment
161+
# Allow for users who set a custom shell that can locate standard binaries like tr and uname
162+
# See https://github.com/NixOS/nixpkgs/issues/43955#issuecomment-407546331
163+
use_default_shell_env = True,
164+
arguments = arguments,
165+
executable = ctx.executable.compiler,
166+
execution_requirements = {
167+
"supports-workers": "1",
168+
},
169+
env = {"COMPILATION_MODE": ctx.var["COMPILATION_MODE"]},
170+
)
149171
else:
150-
arguments.append("-p")
172+
# TODO: if compiler is vanilla tsc, then we need the '-p' argument too
173+
# arguments.append("-p")
151174
arguments.append(tsconfig_file.path)
152-
mnemonic = "tsc"
153175

154-
run_node(
155-
ctx,
156-
progress_message = "Compiling TypeScript (%s) %s" % (description, ctx.label),
157-
mnemonic = mnemonic,
158-
inputs = action_inputs,
159-
outputs = action_outputs,
160-
# Use the built-in shell environment
161-
# Allow for users who set a custom shell that can locate standard binaries like tr and uname
162-
# See https://github.com/NixOS/nixpkgs/issues/43955#issuecomment-407546331
163-
use_default_shell_env = True,
164-
arguments = arguments,
165-
executable = "compiler",
166-
execution_requirements = {
167-
"supports-workers": str(int(ctx.attr.supports_workers)),
168-
},
169-
env = {"COMPILATION_MODE": ctx.var["COMPILATION_MODE"]},
170-
)
176+
# Run with linker but not as a worker process
177+
run_node(
178+
ctx,
179+
progress_message = "Compiling TypeScript (%s) %s" % (description, ctx.label),
180+
mnemonic = "tsc",
181+
inputs = action_inputs,
182+
outputs = action_outputs,
183+
# Use the built-in shell environment
184+
# Allow for users who set a custom shell that can locate standard binaries like tr and uname
185+
# See https://github.com/NixOS/nixpkgs/issues/43955#issuecomment-407546331
186+
use_default_shell_env = True,
187+
arguments = arguments,
188+
executable = "compiler",
189+
env = {"COMPILATION_MODE": ctx.var["COMPILATION_MODE"]},
190+
)
171191

172192
# Enable the replay_params in case an aspect needs to re-build this library.
173193
return struct(

packages/typescript/test/lit_plugin/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ ts_library(
2626
"TS2322: \\[lit\\] Type '444' is not assignable to 'string",
2727
"TS2322: \\[lit\\] Type '{ field: number; }' is not assignable to '{ field: string; }'",
2828
],
29+
# We need the linker to set up a node_modules tree to discover the plugin
30+
# but it isn't compatible with worker mode;
31+
# see https://github.com/bazelbuild/rules_nodejs/issues/1803
32+
supports_workers = False,
2933
tsconfig = ":tsconfig.json",
3034
deps = [
3135
"@npm//lit-element",

0 commit comments

Comments
 (0)