Skip to content

fix(preferred-pm): detect pnpm via pnpm-workspace.yaml - #238

Merged
zkochan merged 1 commit into
zkochan:mainfrom
fran-mck:fix/preferred-pm-detect-pnpm-workspace
Sep 27, 2026
Merged

zkochan merged 1 commit into
zkochan:mainfrom
fran-mck:fix/preferred-pm-detect-pnpm-workspace

Conversation

@fran-mck

@fran-mck fran-mck commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Fixes #197.

Problem

The README states "Inside a pnpm workspace, pnpm is preferred", but the directory walk only searched for pnpm-lock.yaml:

if (await findUp('pnpm-lock.yaml', { cwd: pkgPath })) { ... }

A pnpm workspace is defined by pnpm-workspace.yaml, and committing a lockfile is optional — repos can set lockfile: false. Such a project is not detected as pnpm. This bites tools built on preferred-pm: @pnpm/prepare-package does const pm = (await preferredPM(gitRootDir))?.name ?? 'npm', so when it prepares a git-hosted dependency that is a lockfile-less pnpm project, it falls back to npm — which then honours that project's .npmrc ignore-scripts=true and skips the prepare/build, leaving no dist/.

As #197 notes, the existing prefer pnpm inside a pnpm workspace test only passes because it runs inside this monorepo, so findUp('pnpm-lock.yaml') climbs up and finds the monorepo's own lockfile — the fixture's pnpm-workspace.yaml is never consulted. Delete the monorepo lockfile and the test fails.

Change

  • index.js: the directory walk also looks for pnpm-workspace.yaml, matching the documented behaviour and pnpm v10+ (where pnpm-workspace.yaml is required for workspace/config).
  • test/index.js: the prefer pnpm inside a pnpm workspace test now copies the fixture to a temp dir (same pattern as the Yarn/npm workspace tests) so detection must come from the fixture's pnpm-workspace.yaml, not an ancestor lockfile. Verified it fails without the index.js change and passes with it.

All 11 tests pass and standard is clean.

The README documents that pnpm is preferred inside a pnpm workspace, but the
directory walk only searched for pnpm-lock.yaml. Repositories that don't commit
a lockfile (e.g. `lockfile: false`) were not detected as pnpm projects, so tools
like `@pnpm/prepare-package` fell back to npm when preparing them as git deps.

Also search up the tree for pnpm-workspace.yaml (required by pnpm v10+ for
workspace/config). The "prefer pnpm inside a pnpm workspace" test now copies the
fixture to a temp dir so it can't pass off this monorepo's own pnpm-lock.yaml.

Fixes zkochan#197

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zkochan pushed a commit to xiechimon/pnpm that referenced this pull request Sep 25, 2026
A pnpm workspace is defined by pnpm-workspace.yaml, and committing a
lockfile is optional (lockfile: false). detect_preferred_pm only sniffed
pnpm-lock.yaml, so a git-hosted dependency that is a pnpm workspace with no
committed lockfile fell through to npm. prepare_package then ran the install
stage with npm, which honours the dependency's own .npmrc ignore-scripts and
skips the build, leaving no dist/.

Consult the manifest once every lockfile has had its say, so it breaks only
the no-lockfile tie: a dependency that ships a lockfile has named what
installs it, and that is stronger evidence than a config file. This is the
precedence preferred-pm uses, consulting the manifest in its fallback stage
(zkochan/packages#238), which keeps the two stacks aligned.

Refs pnpm#14011
zkochan pushed a commit to pnpm/pnpm that referenced this pull request Sep 25, 2026
A pnpm workspace is defined by pnpm-workspace.yaml, and committing a
lockfile is optional (lockfile: false). detect_preferred_pm only sniffed
pnpm-lock.yaml, so a git-hosted dependency that is a pnpm workspace with no
committed lockfile fell through to npm. prepare_package then ran the install
stage with npm, which honours the dependency's own .npmrc ignore-scripts and
skips the build, leaving no dist/.

Consult the manifest once every lockfile has had its say, so it breaks only
the no-lockfile tie: a dependency that ships a lockfile has named what
installs it, and that is stronger evidence than a config file. This is the
precedence preferred-pm uses, consulting the manifest in its fallback stage
(zkochan/packages#238), which keeps the two stacks aligned.

Refs #14011 (the detection half; the v11 side lands via a
preferred-pm bump and the suggested CLI override needs its own design)
@zkochan
zkochan merged commit 1ae3d79 into zkochan:main Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

preferred-pm: Test for pnpm-workspace passes incorrectly

2 participants