Skip to content

Commit f42a49f

Browse files
authored
feat: support bazel path-mapping (#2575) (#2576)
Ref #2574 ### Changes are visible to end-users: yes - Searched for relevant documentation and updated as needed: yes - Breaking change (forces users to change their own code or config): no - Suggested release notes appear below: yes Support npm package usage across compilation modes. ### Test plan - Covered by existing test cases
1 parent 409b866 commit f42a49f

1 file changed

Lines changed: 13 additions & 20 deletions

File tree

npm/private/npm_package_store.bzl

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -231,32 +231,25 @@ def _npm_package_store_impl(ctx):
231231
# executable which make the directories not listable ([email protected] for example).
232232
bsdtar = ctx.toolchains["@aspect_bazel_lib//lib:tar_toolchain_type"]
233233

234-
tar_exclude_package_contents = []
235-
if ctx.attr.exclude_package_contents:
236-
for pattern in ctx.attr.exclude_package_contents:
237-
if pattern == "":
238-
continue
239-
tar_exclude_package_contents.append("--exclude")
240-
tar_exclude_package_contents.append(pattern)
234+
args = ctx.actions.args()
235+
args.add("--extract")
236+
args.add("--no-same-owner")
237+
args.add("--no-same-permissions")
238+
args.add("--strip-components", "1")
239+
args.add("--file", src)
240+
args.add_all("--directory", [package_store_directory], expand_directories = False)
241+
args.add_all(ctx.attr.exclude_package_contents, before_each = "--exclude")
241242

242243
ctx.actions.run(
243244
executable = bsdtar.tarinfo.binary,
244-
inputs = depset(direct = [src], transitive = [bsdtar.default.files]),
245+
inputs = [src],
245246
outputs = [package_store_directory],
246-
arguments = [
247-
"--extract",
248-
] + tar_exclude_package_contents + [
249-
"--no-same-owner",
250-
"--no-same-permissions",
251-
"--strip-components",
252-
"1",
253-
"--file",
254-
src.path,
255-
"--directory",
256-
package_store_directory.path,
257-
],
247+
arguments = [args],
258248
mnemonic = "NpmPackageExtract",
259249
progress_message = "Extracting npm package {}@{}".format(package, version),
250+
execution_requirements = {
251+
"supports-path-mapping": "1",
252+
},
260253

261254
# Always override the locale to give better hermeticity.
262255
# See https://github.com/aspect-build/rules_js/issues/2039

0 commit comments

Comments
 (0)