Skip to content

Commit a0bce6f

Browse files
committed
perf: reduce per-action overhead registering NpmPackageExtract
Build the tar argument list with a single add_all call, hoist the constant execution_requirements dict, and skip the --exclude pass when exclude_package_contents is empty. The rendered command line is unchanged.
1 parent 370d022 commit a0bce6f

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

npm/private/npm_package_store.bzl

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ _SUPPORTS_SYMLINK_TARGET_TYPE = bazel_features.rules.symlink_action_has_target_t
1414

1515
_PACKAGE_STORE_PREFIX_LEN = len("node_modules/{}/".format(utils.package_store_root))
1616

17+
_EXTRACT_EXECUTION_REQUIREMENTS = {
18+
"supports-path-mapping": "1",
19+
}
20+
1721
_DOC = """Defines a npm package that is linked into a node_modules tree.
1822
1923
The npm package is linked with a pnpm style symlinked node_modules output tree.
@@ -242,13 +246,22 @@ def _npm_package_store_impl(ctx):
242246
bsdtar = ctx.toolchains[tar_lib.toolchain_type]
243247

244248
args = ctx.actions.args()
245-
args.add("--extract")
246-
args.add("--no-same-owner")
247-
args.add("--no-same-permissions")
248-
args.add("--strip-components", "1")
249-
args.add("--file", src)
250-
args.add_all("--directory", [package_store_directory], expand_directories = False)
251-
args.add_all(ctx.attr.exclude_package_contents, before_each = "--exclude")
249+
args.add_all(
250+
[
251+
"--extract",
252+
"--no-same-owner",
253+
"--no-same-permissions",
254+
"--strip-components",
255+
"1",
256+
"--file",
257+
src,
258+
"--directory",
259+
package_store_directory,
260+
],
261+
expand_directories = False,
262+
)
263+
if ctx.attr.exclude_package_contents:
264+
args.add_all(ctx.attr.exclude_package_contents, before_each = "--exclude")
252265

253266
ctx.actions.run(
254267
executable = bsdtar.tarinfo.binary,
@@ -257,9 +270,7 @@ def _npm_package_store_impl(ctx):
257270
arguments = [args],
258271
mnemonic = "NpmPackageExtract",
259272
progress_message = "Extracting npm package {}@{}".format(package, version),
260-
execution_requirements = {
261-
"supports-path-mapping": "1",
262-
},
273+
execution_requirements = _EXTRACT_EXECUTION_REQUIREMENTS,
263274
toolchain = Label("@tar.bzl//tar/toolchain:type"),
264275

265276
# Always override the locale to give better hermeticity.

0 commit comments

Comments
 (0)