@@ -137,12 +137,12 @@ See the section on stamping in the [README](stamping)
137137 ),
138138 "_npm_script_generator" : attr .label (
139139 default = Label ("//internal/pkg_npm:npm_script_generator" ),
140- cfg = "host " ,
140+ cfg = "exec " ,
141141 executable = True ,
142142 ),
143143 "_packager" : attr .label (
144144 default = Label ("//internal/pkg_npm:packager" ),
145- cfg = "host " ,
145+ cfg = "exec " ,
146146 executable = True ,
147147 ),
148148 "_run_npm_bat_template" : attr .label (
@@ -206,7 +206,7 @@ def create_package(ctx, deps_files, nested_packages):
206206 # that single directory and there is no work to do
207207 package_dir = all_files [0 ]
208208
209- _create_npm_scripts (ctx , package_dir )
209+ _create_npm_scripts (ctx )
210210
211211 return package_dir
212212
@@ -260,15 +260,14 @@ def create_package(ctx, deps_files, nested_packages):
260260 arguments = [args ],
261261 )
262262
263- _create_npm_scripts (ctx , package_dir )
263+ _create_npm_scripts (ctx )
264264
265265 return package_dir
266266
267- def _create_npm_scripts (ctx , package_dir ):
267+ def _create_npm_scripts (ctx ):
268268 args = ctx .actions .args ()
269269
270270 args .add_all ([
271- package_dir .path ,
272271 ctx .outputs .pack_sh .path ,
273272 ctx .outputs .publish_sh .path ,
274273 ctx .file ._run_npm_template .path ,
@@ -281,13 +280,16 @@ def _create_npm_scripts(ctx, package_dir):
281280 progress_message = "Generating npm pack & publish scripts" ,
282281 mnemonic = "GenerateNpmScripts" ,
283282 executable = ctx .executable ._npm_script_generator ,
284- inputs = [ctx .file ._run_npm_template , ctx .file ._run_npm_bat_template , package_dir ],
283+ inputs = [ctx .file ._run_npm_template , ctx .file ._run_npm_bat_template ],
285284 outputs = [ctx .outputs .pack_sh , ctx .outputs .publish_sh , ctx .outputs .pack_bat , ctx .outputs .publish_bat ],
286285 arguments = [args ],
287- # Must be run local (no sandbox) so that the pwd is the actual execroot
288- # in the script which is used to generate the path in the pack & publish
289- # scripts.
290- execution_requirements = {"local" : "1" },
286+ # Cannot be built remotely (template contains absolute path to npm executable).
287+ # Cannot be built with sandboxing (references files outside sandbox).
288+ # Can be cached, because absolute path is a standard input from a repo rule.
289+ execution_requirements = {
290+ "no-remote-exec" : "" ,
291+ "no-sandbox" : "" ,
292+ },
291293 )
292294
293295def _pkg_npm (ctx ):
@@ -326,7 +328,6 @@ def _pkg_npm(ctx):
326328 result = [
327329 DefaultInfo (
328330 files = package_dir_depset ,
329- runfiles = ctx .runfiles ([package_dir ]),
330331 ),
331332 ]
332333
@@ -385,15 +386,18 @@ def pkg_npm_macro(name, tgz = None, **kwargs):
385386 outs = [tgz ],
386387 # NOTE(mattem): on windows, it seems to output a buch of other stuff on stdout when piping, so pipe to tail
387388 # and grab the last line
388- cmd = "$(location :%s.pack) 2>/dev/null | tail -1 | xargs -I {} cp {} $@" % name ,
389+ # pass in package path
390+ cmd = "$(location :%s.pack) $(location :%s) | tail -1 | xargs -I {} cp {} $@" % (name , name ),
389391 srcs = [
390392 name ,
391393 ],
392394 tools = [
393395 ":%s.pack" % name ,
394396 ],
395397 tags = [
396- "local" ,
398+ # Inherits limitations of %s.pack (due to absolute path to npm)
399+ "no-remote-exec" ,
400+ "no-sandbox" ,
397401 ],
398402 visibility = kwargs .get ("visibility" ),
399403 )
0 commit comments