@@ -122,6 +122,10 @@ See the section on stamping in the [README](stamping)
122122 cfg = "host" ,
123123 executable = True ,
124124 ),
125+ "_run_npm_bat_template" : attr .label (
126+ default = Label ("@nodejs//:run_npm.bat.template" ),
127+ allow_single_file = True ,
128+ ),
125129 "_run_npm_template" : attr .label (
126130 default = Label ("@nodejs//:run_npm.sh.template" ),
127131 allow_single_file = True ,
@@ -130,8 +134,10 @@ See the section on stamping in the [README](stamping)
130134
131135# Used in angular/angular /packages/bazel/src/ng_package/ng_package.bzl
132136PKG_NPM_OUTPUTS = {
133- "pack" : "%{name}.pack" ,
134- "publish" : "%{name}.publish" ,
137+ "pack_bat" : "%{name}.pack.bat" ,
138+ "pack_sh" : "%{name}.pack.sh" ,
139+ "publish_bat" : "%{name}.publish.bat" ,
140+ "publish_sh" : "%{name}.publish.sh" ,
135141}
136142
137143# Takes a depset of files and returns a corresponding list of file paths without any files
@@ -240,19 +246,23 @@ def create_package(ctx, deps_files, nested_packages):
240246
241247def _create_npm_scripts (ctx , package_dir ):
242248 args = ctx .actions .args ()
249+
243250 args .add_all ([
244251 package_dir .path ,
245- ctx .outputs .pack .path ,
246- ctx .outputs .publish .path ,
252+ ctx .outputs .pack_sh .path ,
253+ ctx .outputs .publish_sh .path ,
247254 ctx .file ._run_npm_template .path ,
255+ ctx .outputs .pack_bat .path ,
256+ ctx .outputs .publish_bat .path ,
257+ ctx .file ._run_npm_bat_template .path ,
248258 ])
249259
250260 ctx .actions .run (
251261 progress_message = "Generating npm pack & publish scripts" ,
252262 mnemonic = "GenerateNpmScripts" ,
253263 executable = ctx .executable ._npm_script_generator ,
254- inputs = [ctx .file ._run_npm_template , package_dir ],
255- outputs = [ctx .outputs .pack , ctx .outputs .publish ],
264+ inputs = [ctx .file ._run_npm_template , ctx . file . _run_npm_bat_template , package_dir ],
265+ outputs = [ctx .outputs .pack_sh , ctx .outputs .publish_sh , ctx . outputs . pack_bat , ctx . outputs . publish_bat ],
256266 arguments = [args ],
257267 # Must be run local (no sandbox) so that the pwd is the actual execroot
258268 # in the script which is used to generate the path in the pack & publish
@@ -307,3 +317,23 @@ pkg_npm = rule(
307317 doc = _DOC ,
308318 outputs = PKG_NPM_OUTPUTS ,
309319)
320+
321+ def pkg_npm_macro (name , ** kwargs ):
322+ pkg_npm (
323+ name = name ,
324+ ** kwargs
325+ )
326+ native .alias (
327+ name = name + ".pack" ,
328+ actual = select ({
329+ "@bazel_tools//src/conditions:host_windows" : name + ".pack.bat" ,
330+ "//conditions:default" : name + ".pack.sh" ,
331+ }),
332+ )
333+ native .alias (
334+ name = name + ".publish" ,
335+ actual = select ({
336+ "@bazel_tools//src/conditions:host_windows" : name + ".publish.bat" ,
337+ "//conditions:default" : name + ".publish.sh" ,
338+ }),
339+ )
0 commit comments