Skip to content

Commit

Permalink
chore: remove duplicate npm_package_internal from npm_import (#1536)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan authored Mar 21, 2024
1 parent 3c7bda8 commit 75db89a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def npm_imported_package_store(name):
# post-lifecycle target with reference deps for use in terminal target with transitive closure
_npm_package_store(
name = "{}/pkg".format(store_target_name),
src = "{}/pkg_lc".format(store_target_name) if True else "@npm//:npm__segfault-handler__1.3.0_source_directory",
src = "{}/pkg_lc".format(store_target_name) if True else "@npm//:npm__segfault-handler__1.3.0_pkg",
package = "segfault-handler",
version = "1.3.0",
dev = False,
Expand All @@ -160,7 +160,7 @@ def npm_imported_package_store(name):
# virtual store target with transitive closure of all npm package dependencies
_npm_package_store(
name = store_target_name,
src = None if True else "@npm//:npm__segfault-handler__1.3.0_source_directory",
src = None if True else "@npm//:npm__segfault-handler__1.3.0_pkg",
package = "segfault-handler",
version = "1.3.0",
dev = False,
Expand Down
21 changes: 4 additions & 17 deletions npm/private/npm_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ _LINK_JS_PACKAGE_LIFECYCLE_TMPL = """\
_js_run_binary(
name = "{{}}/lc".format(store_target_name),
srcs = [
"{npm_package_target_lc}",
"{npm_package_target}",
":{{}}/pkg_pre_lc".format(store_target_name),
],
# js_run_binary runs in the output dir; must add "../../../" because paths are relative to the exec root
args = [
"{package}",
"../../../$(execpath {npm_package_target_lc})",
"../../../$(execpath {npm_package_target})",
"../../../$(@D)",
] +
select({{
Expand Down Expand Up @@ -356,14 +356,6 @@ def {bin_name}_binary(name, **kwargs):
"""

_JS_PACKAGE_TMPL = """
_npm_package_internal(
name = "source_directory",
src = ":{extract_to_dirname}",
package = "{package}",
version = "{version}",
visibility = ["//visibility:public"],
)
_npm_package_internal(
name = "pkg",
src = ":{extract_to_dirname}",
Expand Down Expand Up @@ -715,19 +707,15 @@ def _npm_import_links_rule_impl(rctx):
if rctx.attr.replace_package:
npm_package_target = rctx.attr.replace_package
elif rctx.attr.npm_translate_lock_repo:
npm_package_target = "@{}//:{}_source_directory".format(
npm_package_target = "@{}//:{}_pkg".format(
rctx.attr.npm_translate_lock_repo,
npm_import_sources_repo_name,
)
else:
npm_package_target = "{}{}//:source_directory".format(
npm_package_target = "{}{}//:pkg".format(
"@@" if bzlmod_supported else "@",
npm_import_sources_repo_name,
)
npm_package_target_lc = "{}{}//:pkg".format(
"@@" if bzlmod_supported else "@",
npm_import_sources_repo_name,
)

link_packages = {}
for package, link_aliases in rctx.attr.link_packages.items():
Expand Down Expand Up @@ -766,7 +754,6 @@ def _npm_import_links_rule_impl(rctx):
link_default = "None" if rctx.attr.link_packages else "True",
extract_to_dirname = _EXTRACT_TO_DIRNAME,
npm_package_target = npm_package_target,
npm_package_target_lc = npm_package_target_lc,
lc_deps = starlark_codegen_utils.to_dict_attr(lc_deps, 1, quote_key = False),
has_lifecycle_build_target = str(rctx.attr.lifecycle_build_target),
lifecycle_hooks_execution_requirements = starlark_codegen_utils.to_dict_attr(lifecycle_hooks_execution_requirements, 2),
Expand Down
4 changes: 2 additions & 2 deletions npm/private/npm_translate_lock_generate.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ def npm_link_all_packages(name = "node_modules", imported_links = []):
visibility = ["//visibility:public"],
)
""".format(
name = "{}_source_directory".format(_import.name),
actual = "{}{}//:source_directory".format(
name = "{}_pkg".format(_import.name),
actual = "{}{}//:pkg".format(
"@@" if utils.bzlmod_supported else "@",
_import.name,
),
Expand Down
8 changes: 4 additions & 4 deletions npm/private/test/fsevents_links_defs_checked.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def npm_imported_package_store(name):
# post-lifecycle target with reference deps for use in terminal target with transitive closure
_npm_package_store(
name = "{}/pkg".format(store_target_name),
src = "{}/pkg_lc".format(store_target_name) if True else "@npm//:npm__fsevents__2.3.2_source_directory",
src = "{}/pkg_lc".format(store_target_name) if True else "@npm//:npm__fsevents__2.3.2_pkg",
package = "fsevents",
version = "2.3.2",
dev = True,
Expand All @@ -56,7 +56,7 @@ def npm_imported_package_store(name):
# virtual store target with transitive closure of all npm package dependencies
_npm_package_store(
name = store_target_name,
src = None if True else "@npm//:npm__fsevents__2.3.2_source_directory",
src = None if True else "@npm//:npm__fsevents__2.3.2_pkg",
package = "fsevents",
version = "2.3.2",
dev = True,
Expand Down Expand Up @@ -115,13 +115,13 @@ def npm_imported_package_store(name):
_js_run_binary(
name = "{}/lc".format(store_target_name),
srcs = [
"@@npm__fsevents__2.3.2//:pkg",
"@npm//:npm__fsevents__2.3.2_pkg",
":{}/pkg_pre_lc".format(store_target_name),
],
# js_run_binary runs in the output dir; must add "../../../" because paths are relative to the exec root
args = [
"fsevents",
"../../../$(execpath @@npm__fsevents__2.3.2//:pkg)",
"../../../$(execpath @npm//:npm__fsevents__2.3.2_pkg)",
"../../../$(@D)",
] +
select({
Expand Down
4 changes: 2 additions & 2 deletions npm/private/test/rollup_links_defs_checked.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def npm_imported_package_store(name):
# post-lifecycle target with reference deps for use in terminal target with transitive closure
_npm_package_store(
name = "{}/pkg".format(store_target_name),
src = "{}/pkg_lc".format(store_target_name) if False else "@npm//:npm__rollup__2.70.2_source_directory",
src = "{}/pkg_lc".format(store_target_name) if False else "@npm//:npm__rollup__2.70.2_pkg",
package = "rollup",
version = "2.70.2",
dev = True,
Expand All @@ -57,7 +57,7 @@ def npm_imported_package_store(name):
# virtual store target with transitive closure of all npm package dependencies
_npm_package_store(
name = store_target_name,
src = None if True else "@npm//:npm__rollup__2.70.2_source_directory",
src = None if True else "@npm//:npm__rollup__2.70.2_pkg",
package = "rollup",
version = "2.70.2",
dev = True,
Expand Down
4 changes: 2 additions & 2 deletions npm/private/test/unused_links_defs_checked.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def npm_imported_package_store(name):
# post-lifecycle target with reference deps for use in terminal target with transitive closure
_npm_package_store(
name = "{}/pkg".format(store_target_name),
src = "{}/pkg_lc".format(store_target_name) if False else "@npm//:npm__unused__0.2.2_source_directory",
src = "{}/pkg_lc".format(store_target_name) if False else "@npm//:npm__unused__0.2.2_pkg",
package = "unused",
version = "0.2.2",
dev = True,
Expand All @@ -61,7 +61,7 @@ def npm_imported_package_store(name):
# virtual store target with transitive closure of all npm package dependencies
_npm_package_store(
name = store_target_name,
src = None if True else "@npm//:npm__unused__0.2.2_source_directory",
src = None if True else "@npm//:npm__unused__0.2.2_pkg",
package = "unused",
version = "0.2.2",
dev = True,
Expand Down

0 comments on commit 75db89a

Please sign in to comment.