AGENT SKILL

link-workspace-packages

Link workspace packages in monorepos (npm, yarn, pnpm, bun). DO NOT patch around with tsconfig paths or manual package.json edits - use the package manager's workspace commands to fix actual linking.

License 许可
MIT
最近更新
2026-11-15
Stars
★ 2
Forks
0

01 前言 Front Matter

name
link-workspace-packages
description
Link workspace packages in monorepos (npm, yarn, pnpm, bun). DO NOT patch around with tsconfig paths or manual package.json edits - use the package manager's workspace commands to fix actual linking.
when_to_use
Use after generating packages whose dependencies need wiring, when code imports a sibling package that must become a dependency, or on workspace resolution errors (@org/*) like "cannot find module", "TS2307", or "cannot resolve".

03 SKILL.md 正文

Link Workspace Packages

Add dependencies between packages in a monorepo. All package managers support workspaces but with different syntax.

Detect Package Manager

Check whether there's a packageManager field in the root-level package.json.

Alternatively check lockfile in repo root:

  • pnpm-lock.yaml → pnpm
  • yarn.lock → yarn
  • bun.lock / bun.lockb → bun
  • package-lock.json → npm

Workflow

  1. Identify consumer package (the one importing)
  2. Identify provider package(s) (being imported)
  3. Add dependency using package manager's workspace syntax
  4. Verify symlinks created in consumer's node_modules/

pnpm

Uses workspace: protocol - symlinks only created when explicitly declared.

# From consumer directory
pnpm add @org/ui --workspace

# Or with --filter from anywhere
pnpm add @org/ui --filter @org/app --workspace

Result in package.json:

{ "dependencies": { "@org/ui": "workspace:*" } }

yarn (v2+/berry)

Also uses workspace: protocol.

yarn workspace @org/app add @org/ui

Result in package.json:

{ "dependencies": { "@org/ui": "workspace:^" } }

npm

No workspace: protocol. npm auto-symlinks workspace packages.

npm install @org/ui --workspace @org/app

Result in package.json:

{ "dependencies": { "@org/ui": "*" } }

npm resolves to local workspace automatically during install.


bun

Supports workspace: protocol (pnpm-compatible).

cd packages/app && bun add @org/ui

Result in package.json:

{ "dependencies": { "@org/ui": "workspace:*" } }

Examples

Example 1: pnpm - link ui lib to app

pnpm add @org/ui --filter @org/app --workspace

Example 2: npm - link multiple packages

npm install @org/data-access @org/ui --workspace @org/dashboard

Example 3: Debug "Cannot find module"

  1. Check if dependency is declared in consumer's package.json
  2. If not, add it using appropriate command above
  3. Run install (pnpm install, npm install, etc.)

Notes

  • Symlinks appear in <consumer>/node_modules/@org/<package>
  • Hoisting differs by manager:
    • npm/bun: hoist shared deps to root node_modules
    • pnpm: no hoisting (strict isolation, prevents phantom deps)
    • yarn berry: uses Plug'n'Play by default (no node_modules)
  • Root package.json should have "private": true to prevent accidental publish

04 同仓库更多 Skills

wahidyankf
wahidyankf/beaver-nest

writing-browser-e2e-tests

Guides writing browser end-to-end tests that find elements as users do, wait on what the action produced, keep page knowledge in page objects, organize one feature per file, and run scenario-backed suites from generated specs.

★ 2
wahidyankf
wahidyankf/beaver-nest

usability-heuristic-evaluation

Guides judging a running interface as a first-time user would, without its specifications: citing a named principle for every finding, walking each task step, reading labels and addresses for scent, and rating severity.

★ 2
wahidyankf
wahidyankf/beaver-nest

tooling-nx

Guides Nx workspace work under the Nx standard: selecting projects by the graph, adding a target only where a capability exists, tracing a stale cached pass to its missing input, and answering a module-boundary finding.

★ 2
wahidyankf
wahidyankf/beaver-nest

programming-typescript

Guides the procedure for writing or changing TypeScript: loading the TypeScript standard first, driving each increment test-first, finding which rule a decision falls under, and confirming the gates before handing off.

★ 2
wahidyankf
wahidyankf/beaver-nest

programming-shell

Guides shell work under the shell standards: checking the declared dialect first, deciding whether logic belongs in shell at all, tracing where exit-on-error does not reach, and testing the script as its callers run it.

★ 2
wahidyankf
wahidyankf/beaver-nest

programming-javascript

Guides JavaScript work under the JavaScript standard: confirming the file is type-checked, typing through JSDoc, validating input the checker cannot see, and noticing floating promises and swallowed errors before handing off.

★ 2