@@ -71,9 +71,18 @@ You can pass arguments to npm by escaping them from Bazel using a double-hyphen,
7171
7272`bazel run my_package.publish -- --tag=next`
7373
74- It is also possible to use the resulting tar file file from the `.pack` as an action input via the `.tar` label:
74+ It is also possible to use the resulting tar file file from the `.pack` as an action input via the `.tar` label.
75+ To make use of this label, the `tgz` attribute must be set, and the generating `pkg_npm` rule must have a valid `package.json` file
76+ as part of its sources:
7577
7678```python
79+ pkg_npm(
80+ name = "my_package",
81+ srcs = ["package.json"],
82+ deps = [":my_typescript_lib"],
83+ tgz = "my_package.tgz",
84+ )
85+
7786my_rule(
7887 name = "foo",
7988 srcs = [
@@ -109,6 +118,12 @@ You can use values from the workspace status command using curly braces, for exa
109118See the section on stamping in the [README](stamping)
110119""" ,
111120 ),
121+ "tgz" : attr .string (
122+ doc = """If set, will create a `.tgz` file that can be used as an input to another rule, the tar will be given the name assigned to this attribute.
123+
124+ NOTE: If this attribute is set, a valid `package.json` file must be included in the sources of this target
125+ """ ,
126+ ),
112127 "vendor_external" : attr .string_list (
113128 doc = """External workspaces whose contents should be vendored into this workspace.
114129 Avoids `external/foo` path segments in the resulting package.""" ,
@@ -313,7 +328,14 @@ pkg_npm = rule(
313328 outputs = PKG_NPM_OUTPUTS ,
314329)
315330
316- def pkg_npm_macro (name , ** kwargs ):
331+ def pkg_npm_macro (name , tgz = None , ** kwargs ):
332+ """Wrapper macro around pkg_npm
333+
334+ Args:
335+ name: Unique name for this target
336+ tgz: If provided, creates a `.tar` target that can be used as an action input version of `.pack`
337+ **kwargs: All other args forwarded to pkg_npm
338+ """
317339 pkg_npm (
318340 name = name ,
319341 ** kwargs
@@ -335,20 +357,25 @@ def pkg_npm_macro(name, **kwargs):
335357 }),
336358 )
337359
338- native .genrule (
339- name = "%s.tar" % name ,
340- outs = ["%s.tgz" % name ],
341- cmd = "$(location :%s.pack) | xargs -I {} cp {} $@" % name ,
342- # NOTE(mattem): on windows, it seems to output a buch of other stuff on stdout when piping, so pipe to tail
343- # and grab the last line
344- cmd_bat = "$(location :%s.pack) | tail -1 | xargs -I {} cp {} $@" % name ,
345- tools = [
346- ":%s.pack" % name ,
347- ],
348- # tagged as manual so this doesn't case two actions for each input with builds for "host" (as used as a tool)
349- tags = [
350- "local" ,
351- "manual" ,
352- ],
353- visibility = kwargs .get ("visibility" ),
354- )
360+ if tgz != None :
361+ if not tgz .endswith (".tgz" ):
362+ fail ("tgz output for pkg_npm %s must produce a .tgz file" % name )
363+
364+ native .genrule (
365+ name = "%s.tar" % name ,
366+ outs = [tgz ],
367+ cmd = "$(location :%s.pack) | xargs -I {} cp {} $@" % name ,
368+ # NOTE(mattem): on windows, it seems to output a buch of other stuff on stdout when piping, so pipe to tail
369+ # and grab the last line
370+ cmd_bat = "$(location :%s.pack) | tail -1 | xargs -I {} cp {} $@" % name ,
371+ srcs = [
372+ name ,
373+ ],
374+ tools = [
375+ ":%s.pack" % name ,
376+ ],
377+ tags = [
378+ "local" ,
379+ ],
380+ visibility = kwargs .get ("visibility" ),
381+ )
0 commit comments