Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions npm/private/npm_translate_lock_state.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ def _init_common_labels(priv, attr, label_store):
label_store.add("npmrc", attr.npmrc)
label_store.add_sibling("lock", "sibling_npmrc", NPM_RC_FILENAME)

# pnpm-workspace.yaml file
label_store.add_sibling("lock", "pnpm_workspace", PNPM_WORKSPACE_FILENAME)

################################################################################
def _init_update_labels(priv, _, attr, label_store):
pnpm_lock_label = label_store.label("pnpm_lock")
Expand Down Expand Up @@ -251,27 +248,35 @@ def _copy_update_input_files(priv, rctx, attr, label_store):
# we can derive input files that should be specified but are not and copy these over; we warn the user when we do this
def _copy_unspecified_input_files(priv, rctx, attr, label_store):
pnpm_lock_label = attr.pnpm_lock
pnpm_workspace_label = pnpm_lock_label.same_package_label(PNPM_WORKSPACE_FILENAME)

# pnpm-workspace.yaml
pnpm_workspace_key = "pnpm_workspace"
if _has_workspaces(priv) and not _has_input_hash(priv, label_store.relative_path(pnpm_workspace_key)):
if _has_workspaces(priv) and not _has_input_hash(priv, PNPM_WORKSPACE_FILENAME):
# there are workspace packages so there must be a pnpm-workspace.yaml file
# buildifier: disable=print
print("""
WARNING: Implicitly using pnpm-workspace.yaml file `{pnpm_workspace}` since the `{pnpm_lock}` file contains workspace packages.
Add `{pnpm_workspace}` to the 'data' attribute of `npm_translate_lock(name = "{rctx_name}")` to suppress this warning.
""".format(
pnpm_lock = pnpm_lock_label,
pnpm_workspace = label_store.label(pnpm_workspace_key),
pnpm_workspace = pnpm_workspace_label,
rctx_name = priv["rctx_name"],
))
if not utils.exists(rctx, label_store.path(pnpm_workspace_key)):
pnpm_workspace_path = rctx.path(pnpm_workspace_label)
if not pnpm_workspace_path.exists:
msg = "ERROR: expected `{path}` to exist since the `{pnpm_lock}` file contains workspace packages".format(
path = label_store.path(pnpm_workspace_key),
path = pnpm_workspace_path,
pnpm_lock = pnpm_lock_label,
)
fail(msg)
_copy_input_file(priv, rctx, attr, label_store, pnpm_workspace_key)
if _should_update_pnpm_lock(priv):
# NB: rctx.read will convert binary files to text but that is acceptable for
# the purposes of calculating a hash of the file
_set_input_hash(
priv,
PNPM_WORKSPACE_FILENAME,
utils.hash(rctx.read(pnpm_workspace_path)),
Comment on lines 259 to +278

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Copy pnpm-workspace.yaml into external repo before running pnpm

When workspaces are present and pnpm-workspace.yaml is not listed in data, _copy_unspecified_input_files now only computes an input hash (lines 272‑278) and never copies the file into the external repository. The pnpm install --lockfile-only/import step later runs in the repository directory, so without copying the workspace file the command executes without any workspace definition and will fail or update the lockfile incorrectly. Prior to this refactor _copy_input_file copied the file; restoring that copy keeps auto‑updates functional for workspace projects.

Useful? React with 👍 / 👎.

)

# package.json files
for i, _ in enumerate(priv["importers"].keys()):
Expand Down
Loading