@@ -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 (
0 commit comments