Skip to content

Commit

Permalink
chore: tweak make_symlink util to take a path instead of a File (#1647)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan committed May 10, 2024
1 parent c0c6c57 commit 78f0236
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion npm/private/npm_link_package_store.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _npm_link_package_store_impl(ctx):
# "node_modules/{package}" so it is available as a direct dependency
root_symlink_path = paths.join("node_modules", package)

files = [utils.make_symlink(ctx, root_symlink_path, package_store_directory)]
files = [utils.make_symlink(ctx, root_symlink_path, package_store_directory.path)]

for bin_name, bin_path in ctx.attr.bins.items():
bin_file = ctx.actions.declare_file(paths.join("node_modules", ".bin", bin_name))
Expand Down
6 changes: 3 additions & 3 deletions npm/private/npm_package_store.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ deps of npm_package_store must be in the same package.""" % (ctx.label.package,
for dep_alias in dep_aliases:
# "node_modules/{package_store_root}/{package_store_name}/node_modules/{package}"
dep_symlink_path = paths.join("node_modules", utils.package_store_root, package_store_name, "node_modules", dep_alias)
files.append(utils.make_symlink(ctx, dep_symlink_path, dep_package_store_directory))
files.append(utils.make_symlink(ctx, dep_symlink_path, dep_package_store_directory.path))
else:
# this is a ref npm_link_package, a downstream terminal npm_link_package
# for this npm dependency will create the dep symlinks for this dep;
Expand All @@ -251,7 +251,7 @@ deps of npm_package_store must be in the same package.""" % (ctx.label.package,
if dep_package_store_directory not in linked_package_store_directories:
# "node_modules/{package_store_root}/{package_store_name}/node_modules/{package}"
dep_symlink_path = paths.join("node_modules", utils.package_store_root, package_store_name, "node_modules", dep_package)
files.append(utils.make_symlink(ctx, dep_symlink_path, dep_package_store_directory))
files.append(utils.make_symlink(ctx, dep_symlink_path, dep_package_store_directory.path))
npm_package_store_infos.append(store)
else:
# if ctx.attr.src is _not_ set then this is a terminal 3p package with ctx.attr.deps is
Expand Down Expand Up @@ -290,7 +290,7 @@ deps of npm_package_store must be in the same package.""" % (ctx.label.package,
for dep_ref_dep_alias in dep_ref_dep_aliases:
# "node_modules/{package_store_root}/{package_store_name}/node_modules/{package}"
dep_ref_dep_symlink_path = paths.join("node_modules", utils.package_store_root, dep_package_store_name, "node_modules", dep_ref_dep_alias)
files.append(utils.make_symlink(ctx, dep_ref_dep_symlink_path, dep_ref_def_package_store_directory))
files.append(utils.make_symlink(ctx, dep_ref_dep_symlink_path, dep_ref_def_package_store_directory.path))

if package_store_directory:
files.append(package_store_directory)
Expand Down
4 changes: 2 additions & 2 deletions npm/private/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,14 @@ def _package_store_name(name, version):
escaped_version = version.replace("/", "+")
return "%s@%s" % (escaped_name, escaped_version)

def _make_symlink(ctx, symlink_path, target_file):
def _make_symlink(ctx, symlink_path, target_path):
if not bazel_lib_utils.is_bazel_6_or_greater():
# ctx.actions.declare_symlink was added in Bazel 6
fail("A minimum version of Bazel 6 required to use rules_js")
symlink = ctx.actions.declare_symlink(symlink_path)
ctx.actions.symlink(
output = symlink,
target_path = relative_file(target_file.path, symlink.path),
target_path = relative_file(target_path, symlink.path),
)
return symlink

Expand Down

0 comments on commit 78f0236

Please sign in to comment.