Skip to content

Commit

Permalink
refactor: yet more cleanup; this time breaking (#141)
Browse files Browse the repository at this point in the history
* refactor: rename npm_import generated link_js_package.bzl to defs.bzl

* refactor: rename direct__ and store__ generated links targets prefixes to direct_link__ and store_link__ so it is obvious on a bazel query what they are
  • Loading branch information
gregmagolan authored May 31, 2022
1 parent 8f6be12 commit 4b4a6ab
Show file tree
Hide file tree
Showing 12 changed files with 380 additions and 371 deletions.
2 changes: 1 addition & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
load("@npm//:defs.bzl", "link_js_packages")
load("@acorn__8.4.0__links//:link_js_package.bzl", link_acorn = "link_js_package")
load("@acorn__8.4.0__links//:defs.bzl", link_acorn = "link_js_package")
load("//js:defs.bzl", "link_js_package", "link_js_package_dep")

# Link all packages from the /WORKSPACE translate_pnpm_lock in /package.json to
Expand Down
2 changes: 1 addition & 1 deletion docs/npm_import.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/genrule/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@acorn__8.4.0__links//:link_js_package.bzl", link_acorn = "link_js_package")
load("@acorn__8.4.0__links//:defs.bzl", link_acorn = "link_js_package")

# Link the acorn package, which was fetched separately with npm_import from /WORKSPACE, as
# a direct dependency in bazel-bin/examples/genrule/node_modules
Expand Down
2 changes: 1 addition & 1 deletion examples/js_binary/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@acorn__8.4.0__links//:link_js_package.bzl", link_acorn = "link_js_package")
load("@acorn__8.4.0__links//:defs.bzl", link_acorn = "link_js_package")
load("@aspect_bazel_lib//lib:directory_path.bzl", "directory_path")
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
Expand Down
2 changes: 1 addition & 1 deletion examples/npm_deps/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@acorn__8.4.0__links//:link_js_package.bzl", link_acorn = "link_js_package")
load("@acorn__8.4.0__links//:defs.bzl", link_acorn = "link_js_package")
load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_test")
load("@aspect_rules_js//js:run_js_binary.bzl", "run_js_binary")
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
Expand Down
2 changes: 1 addition & 1 deletion js/npm_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def npm_import(
package's `BUILD.bazel` file:
```
load("@npm__at_types_node__15.12.2__links//:link_js_package.bzl", link_types_node = "link_js_package")
load("@npm__at_types_node__15.12.2__links//:defs.bzl", link_types_node = "link_js_package")
link_types_node()
```
Expand Down
15 changes: 8 additions & 7 deletions js/private/npm_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ _js_package(

_TARBALL_FILENAME = "package.tgz"
_EXTRACT_TO_DIRNAME = "package"
_LINK_JS_PACKAGE_BZL_FILENAME = "link_js_package.bzl"
_DEFS_BZL_FILENAME = "defs.bzl"
_PACKAGE_JSON_BZL_FILENAME = "package_json.bzl"

def _impl(rctx):
numeric_version = pnpm_utils.strip_peer_dep_version(rctx.attr.version)
Expand Down Expand Up @@ -304,9 +305,9 @@ def _impl(rctx):
root_package_json_bzl = True
else:
rctx.file(paths.normalize(paths.join(link_package, "BUILD.bazel")), "\n".join(generated_by_lines + [
"exports_files(%s)" % starlark_codegen_utils.to_list_attr(["package_json.bzl"]),
"exports_files({})".format(starlark_codegen_utils.to_list_attr([_PACKAGE_JSON_BZL_FILENAME])),
]))
rctx.file(paths.normalize(paths.join(link_package, "package_json.bzl")), "\n".join(bin_bzl))
rctx.file(paths.normalize(paths.join(link_package, _PACKAGE_JSON_BZL_FILENAME)), "\n".join(bin_bzl))

if rctx.attr.run_lifecycle_hooks:
_inject_run_lifecycle_hooks(rctx, pkg_json_path)
Expand All @@ -328,7 +329,7 @@ def _impl(rctx):
))

if root_package_json_bzl:
build_file.append("exports_files(%s)" % starlark_codegen_utils.to_list_attr(["package_json.bzl"]))
build_file.append("exports_files(%s)" % starlark_codegen_utils.to_list_attr([_PACKAGE_JSON_BZL_FILENAME]))

rctx.file("BUILD.bazel", "\n".join(build_file))

Expand Down Expand Up @@ -405,7 +406,7 @@ def _impl_links(rctx):
lc_deps = starlark_codegen_utils.to_list_attr(lc_deps, 1),
lifecycle_build_target = str(rctx.attr.lifecycle_build_target),
lifecycle_target_name = lifecycle_target_name,
link_js_package_bzl = "@%s//:%s" % (rctx.name, _LINK_JS_PACKAGE_BZL_FILENAME),
link_js_package_bzl = "@%s//:%s" % (rctx.name, _DEFS_BZL_FILENAME),
link_packages = rctx.attr.link_packages,
package = rctx.attr.package,
package_directory_output_group = pnpm_utils.package_directory_output_group,
Expand All @@ -420,9 +421,9 @@ def _impl_links(rctx):

generated_by_lines = _make_generated_by_lines(rctx.attr.package, rctx.attr.version)

rctx.file(_LINK_JS_PACKAGE_BZL_FILENAME, "\n".join(generated_by_lines + link_js_package_bzl))
rctx.file(_DEFS_BZL_FILENAME, "\n".join(generated_by_lines + link_js_package_bzl))

rctx.file("BUILD.bazel", "exports_files(%s)" % starlark_codegen_utils.to_list_attr([_LINK_JS_PACKAGE_BZL_FILENAME]))
rctx.file("BUILD.bazel", "exports_files(%s)" % starlark_codegen_utils.to_list_attr([_DEFS_BZL_FILENAME]))

_COMMON_ATTRS = {
"package": attr.string(mandatory = True),
Expand Down
4 changes: 2 additions & 2 deletions js/private/pnpm_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ pnpm_utils = struct(
# Symlinked node_modules structure virtual store path under node_modules
virtual_store_root = ".aspect_rules_js",
# Prefix namespace to use for js_package direct links
direct_link_target_namespace = "direct__",
direct_link_target_namespace = "direct_link__",
# Prefix namespace to use for js_package store links
store_link_target_namespace = "store__",
store_link_target_namespace = "store_link__",
# Postfix for npm_import links repository
links_postfix = "__links",
# Postfix for package directory filegroup and alias targets
Expand Down
Loading

0 comments on commit 4b4a6ab

Please sign in to comment.