Skip to content

Commit 9d073e3

Browse files
committed
Optimize package store symlink creation
1 parent fcad60f commit 9d073e3

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

npm/private/npm_package_store.bzl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ If set, takes precendance over the package version in the `NpmPackageInfo` src.
157157
),
158158
}
159159

160+
_PACKAGE_STORE_PREFIX_LEN = len("node_modules/" + utils.package_store_root)
161+
160162
def _npm_package_store_impl(ctx):
161163
if ctx.attr.src:
162164
if NpmPackageInfo in ctx.attr.src:
@@ -184,6 +186,10 @@ def _npm_package_store_impl(ctx):
184186
if not version:
185187
fail("No package version specified to link to. Package version must either be specified explicitly via 'version' attribute or come from the 'src' 'JsInfo|NpmPackageInfo', typically a 'js_library|npm_package' target")
186188

189+
package_store_prefix_len = _PACKAGE_STORE_PREFIX_LEN
190+
if ctx.label.package:
191+
package_store_prefix_len += len(ctx.label.package) + 1
192+
187193
package_store_name = utils.package_store_name(package, version)
188194
package_store_directory = None
189195

@@ -369,10 +375,16 @@ deps of npm_package_store must be in the same package.""" % (ctx.label.package,
369375
actual_dep = deps_map[dep_ref_dep_package_store_name]
370376
dep_ref_def_package_store_directory = actual_dep[NpmPackageStoreInfo].package_store_directory
371377
if dep_ref_def_package_store_directory:
378+
target = dep_ref_def_package_store_directory.short_path[package_store_prefix_len:]
372379
for dep_ref_dep_alias in dep_ref_dep_aliases:
373380
# "node_modules/{package_store_root}/{package_store_name}/node_modules/{package}"
374381
dep_ref_dep_symlink_path = "node_modules/{}/{}/node_modules/{}".format(utils.package_store_root, dep_package_store_name, dep_ref_dep_alias)
375-
files.append(utils.make_symlink(ctx, dep_ref_dep_symlink_path, dep_ref_def_package_store_directory.path))
382+
symlink = ctx.actions.declare_symlink(dep_ref_dep_symlink_path)
383+
ctx.actions.symlink(
384+
output = symlink,
385+
target_path = ("../../.." if "/" in dep_ref_dep_alias else "../..") + target,
386+
)
387+
files.append(symlink)
376388
else:
377389
# We should _never_ get here
378390
fail("Internal error")

0 commit comments

Comments
 (0)