Skip to content

fix(linker): hoist workspace deps from shared root#3

Open
timbrinded wants to merge 3 commits into
nubjs:mainfrom
timbrinded:fix/hoisted-workspace-linker
Open

fix(linker): hoist workspace deps from shared root#3
timbrinded wants to merge 3 commits into
nubjs:mainfrom
timbrinded:fix/hoisted-workspace-linker

Conversation

@timbrinded

Copy link
Copy Markdown

Summary

This updates the hoisted workspace linker so workspace member dependencies are planned against a shared workspace-root tree instead of independent per-importer trees.

In pnpm nodeLinker: hoisted workspaces, a non-conflicting dependency declared only by a workspace member can still be placed at the workspace root. Aube was placing those dependencies only under the member's own node_modules, which diverged from pnpm and made installs fragile when a root lifecycle script pruned member-local dependency trees.

Example

Setup:

pnpm-workspace.yaml

packages:
  - packages/*
nodeLinker: hoisted

package.json

  {
    "name": "root",
    "private": true,
    "packageManager": "pnpm@11.0.0",
    "scripts": {
      "postinstall": "node -e \"require('fs').rmSync('packages/app/node_modules',{recursive:true,force:true})\""
    }
  }

packages/app/package.json

  {
    "name": "app",
    "version": "1.0.0",
    "dependencies": {
      "@scope/scoped-dep": "file:../../vendor/scoped-dep"
    }
  }

Expected behaviour

openclaw builds

Actual behaviour

Caution

Building using nub run build fails with:

 ✘ [ERROR] Could not resolve "@pierre/diffs"

     extensions/diffs/src/viewer-client.ts:2:45:
       2 │ import { FileDiff, preloadHighlighter } from "@pierre/diffs";
  1. node_modules/@scope/scoped-dep/index.js does not exist
  2. packages/app/node_modules/@scope/scoped-dep is created during linking
  3. packages/app/node_modules is then removed by root postinstall
  4. require.resolve("@scope/scoped-dep", { paths: ["packages/app"] }) fails

Testing nub in the openclaw repo, @pierre/diffs was a valid dependency in the lockfile and showed up in nub why, but it was not resolvable after nub install. The package had only been installed under extensions/diffs/node_modules, and OpenClaw's root postinstall removes bundled plugin node_modules directories. pnpm avoids this by hoisting the non-conflicting dependency to the workspace root, where Node can still resolve it from the workspace member.

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.

1 participant