Skip to content

Commit ada7413

Browse files
committed
Stop reading pnpm_lock from label_store
1 parent 57fee21 commit ada7413

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

npm/private/npm_translate_lock.bzl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def _npm_translate_lock_impl(rctx):
139139
INFO: {} file updated. Please run your build again.
140140
141141
See https://github.com/aspect-build/rules_js/issues/1445
142-
""".format(state.label_store.relative_path("pnpm_lock"))
142+
""".format(rctx.attr.pnpm_lock)
143143
fail(msg)
144144

145145
helpers.verify_node_modules_ignored(rctx, state.importers(), state.root_package())
@@ -148,7 +148,7 @@ See https://github.com/aspect-build/rules_js/issues/1445
148148

149149
helpers.verify_lifecycle_hooks_specified(rctx, state)
150150

151-
rctx.report_progress("Translating {}".format(state.label_store.relative_path("pnpm_lock")))
151+
rctx.report_progress("Translating %s" % str(rctx.attr.pnpm_lock))
152152

153153
importers, packages = translate_to_transitive_closure(
154154
state.importers(),
@@ -162,7 +162,6 @@ See https://github.com/aspect-build/rules_js/issues/1445
162162

163163
generate_repository_files(
164164
rctx,
165-
state.label_store.label("pnpm_lock"),
166165
importers,
167166
packages,
168167
state.patched_dependencies(),
@@ -691,8 +690,8 @@ def list_patches(name, out = None, include_patterns = ["*.diff", "*.patch"], exc
691690

692691
################################################################################
693692
def _bootstrap_import(rctx, state):
694-
pnpm_lock_label = state.label_store.label("pnpm_lock")
695-
pnpm_lock_path = state.label_store.path("pnpm_lock")
693+
pnpm_lock_label = rctx.attr.pnpm_lock
694+
pnpm_lock_path = paths.join(pnpm_lock_label.package, pnpm_lock_label.name)
696695

697696
# Check if the pnpm lock file already exists and copy it over if it does.
698697
# When we do this, warn the user that we do.

npm/private/npm_translate_lock_generate.bzl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ _PACKAGE_JSON_BZL_FILENAME = "package_json.bzl"
9393
_RESOLVED_JSON_FILENAME = "resolved.json"
9494

9595
# buildifier: disable=function-docstring
96-
def generate_repository_files(rctx, pnpm_lock_label, importers, packages, patched_dependencies, only_built_dependencies, root_package, default_registry, npm_registries, npm_auth, link_workspace):
96+
def generate_repository_files(rctx, importers, packages, patched_dependencies, only_built_dependencies, root_package, default_registry, npm_registries, npm_auth, link_workspace):
9797
# empty line after bzl docstring since buildifier expects this if this file is vendored in
98-
generated_by_prefix = "\"\"\"@generated by npm_translate_lock(name = \"{}\", pnpm_lock = \"{}\")\"\"\"\n".format(helpers.to_apparent_repo_name(rctx.name), str(pnpm_lock_label))
98+
generated_by_prefix = "\"\"\"@generated by npm_translate_lock(name = \"{}\", pnpm_lock = \"{}\")\"\"\"\n".format(helpers.to_apparent_repo_name(rctx.name), str(rctx.attr.pnpm_lock))
9999

100100
npm_imports = helpers.get_npm_imports(importers, packages, patched_dependencies, only_built_dependencies, root_package, rctx.name, rctx.attr, rctx.attr.lifecycle_hooks, rctx.attr.lifecycle_hooks_execution_requirements, rctx.attr.lifecycle_hooks_use_default_shell_env, npm_registries, default_registry, npm_auth)
101101

@@ -248,7 +248,7 @@ def npm_link_all_packages(name = "node_modules", imported_links = []):
248248
defs_bzl_file = "@{}//:{}".format(rctx.name, rctx.attr.defs_bzl_filename),
249249
link_packages_comma_separated = "\"'\" + \"', '\".join(_LINK_PACKAGES) + \"'\"" if len(link_packages) else "\"\"",
250250
root_package = root_package,
251-
pnpm_lock_label = pnpm_lock_label,
251+
pnpm_lock_label = rctx.attr.pnpm_lock,
252252
),
253253
]
254254

@@ -480,21 +480,20 @@ def npm_link_all_packages(name = "node_modules", imported_links = []):
480480
rctx_files[rctx.attr.repositories_bzl_filename] = _generate_repositories(
481481
rctx,
482482
npm_imports,
483-
pnpm_lock_label,
484483
link_workspace,
485484
)
486485

487486
for filename, contents in rctx_files.items():
488487
rctx.file(filename, generated_by_prefix + "\n" + "\n".join(contents))
489488

490-
def _generate_repositories(rctx, npm_imports, pnpm_lock_label, link_workspace):
489+
def _generate_repositories(rctx, npm_imports, link_workspace):
491490
repositories_bzl = []
492491

493492
if len(npm_imports) > 0:
494493
repositories_bzl.append("""load("@aspect_rules_js//npm:repositories.bzl", "npm_import")""")
495494
repositories_bzl.append("")
496495

497-
repositories_bzl.append("# Generated npm_import repository rules corresponding to npm packages in {}".format(str(pnpm_lock_label)))
496+
repositories_bzl.append("# Generated npm_import repository rules corresponding to npm packages in {}".format(str(rctx.attr.pnpm_lock)))
498497
repositories_bzl.append("# buildifier: disable=function-docstring")
499498
repositories_bzl.append("def npm_repositories():")
500499
if len(npm_imports) == 0:

npm/private/npm_translate_lock_state.bzl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ WARNING: `update_pnpm_lock` attribute in `npm_translate_lock(name = "{rctx_name}
4646
# labels only needed when updating the pnpm lock file
4747
_init_update_labels(priv, rctx, attr, label_store)
4848

49-
_init_link_workspace(priv, rctx, attr, label_store)
49+
_init_link_workspace(priv, attr)
5050

5151
# parse the pnpm lock file incase since we need the importers list for additional init
5252
# TODO(windows): utils.exists is not yet support on Windows
@@ -134,7 +134,7 @@ def _init_pnpm_labels(priv, rctx, attr, label_store):
134134

135135
################################################################################
136136
def _init_update_labels(priv, _, attr, label_store):
137-
pnpm_lock_label = label_store.label("pnpm_lock")
137+
pnpm_lock_label = attr.pnpm_lock
138138
pnpm_lock_label_str = "//{}:{}".format(pnpm_lock_label.package, pnpm_lock_label.name)
139139
action_cache_path = paths.join(
140140
priv["external_repository_action_cache"],
@@ -170,7 +170,7 @@ def _init_patched_dependencies_labels(priv, _, attr, label_store):
170170
# Read patches from pnpm-lock.yaml `patchedDependencies`
171171
patches = []
172172
for patch_info in priv["patched_dependencies"].values():
173-
patches.append("//%s:%s" % (label_store.label("pnpm_lock").package, patch_info.get("path")))
173+
patches.append("//%s:%s" % (attr.pnpm_lock.package, patch_info.get("path")))
174174

175175
# Convert patch label strings to labels
176176
patches = [attr.pnpm_lock.relative(p) for p in patches]
@@ -186,9 +186,9 @@ def _init_importer_labels(priv, label_store):
186186
label_store.add_sibling("lock", "package_json_{}".format(i), paths.join(p, PACKAGE_JSON_FILENAME))
187187

188188
################################################################################
189-
def _init_link_workspace(priv, _, attr, label_store):
189+
def _init_link_workspace(priv, attr):
190190
# initialize link_workspace either from pnpm_lock label or from override
191-
priv["link_workspace"] = attr.link_workspace if attr.link_workspace else label_store.label("pnpm_lock").repo_name
191+
priv["link_workspace"] = attr.link_workspace if attr.link_workspace else attr.pnpm_lock.repo_name
192192

193193
################################################################################
194194
def _init_external_repository_action_cache(priv, attr):
@@ -197,7 +197,7 @@ def _init_external_repository_action_cache(priv, attr):
197197

198198
################################################################################
199199
def _init_root_package(priv, rctx, attr, label_store):
200-
pnpm_lock_label = label_store.label("pnpm_lock")
200+
pnpm_lock_label = attr.pnpm_lock
201201

202202
# use the directory of the pnpm_lock file as the root_package unless overridden by the root_package attribute
203203
if attr.root_package == DEFAULT_ROOT_PACKAGE:
@@ -284,7 +284,7 @@ def _copy_update_input_files(priv, rctx, attr, label_store):
284284
################################################################################
285285
# we can derive input files that should be specified but are not and copy these over; we warn the user when we do this
286286
def _copy_unspecified_input_files(priv, rctx, attr, label_store):
287-
pnpm_lock_label = label_store.label("pnpm_lock")
287+
pnpm_lock_label = attr.pnpm_lock
288288

289289
# pnpm-workspace.yaml
290290
pnpm_workspace_key = "pnpm_workspace"
@@ -480,7 +480,7 @@ WARNING: Cannot determine home directory in order to load home `.npmrc` file in
480480
_load_npmrc(priv, rctx, home_npmrc_path)
481481

482482
################################################################################
483-
def _load_lockfile(priv, rctx, _, label_store):
483+
def _load_lockfile(priv, rctx, attr, label_store):
484484
importers = {}
485485
packages = {}
486486
patched_dependencies = {}
@@ -489,7 +489,7 @@ def _load_lockfile(priv, rctx, _, label_store):
489489

490490
yq_args = [
491491
str(label_store.path("host_yq")),
492-
str(label_store.path("pnpm_lock")),
492+
attr.pnpm_lock,
493493
"-o=json",
494494
]
495495
result = rctx.execute(yq_args)

0 commit comments

Comments
 (0)