Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ For full architecture details, see `docs/explanations/architecture/`.

## Common pitfalls

- Dependencies are isolated, not hoisted: `.npmrc` sets `install-strategy = "linked"`. Packages live in `node_modules/.store/` and are symlinked only into the `node_modules` of the workspaces that declare them, so a near-empty root `node_modules` (or a missing `node_modules/typescript`) is expected and does not mean the install failed. To check an install, look for `node_modules/.store/` (`ls -a`, since it is a dotfile) or just run the npm script you need.
- Do not add dependencies to the root `package.json`. Add them to the workspace that uses them, or create a new workspace under `tools/` (or `test/` for test infrastructure). See [Workspace Development](docs/contributors/code/workspace-development.md).
- Published package runtime files and emitted type declarations must resolve through the package's declared dependency surface; never rely on root hoisting or workspace links. Prefer fixing accidentally leaked public types over adding an unrelated heavy dependency, and run `npm run lint:published-deps` when changing package dependencies or exported types.
- PHP features in `lib/compat/` MUST go in the `wordpress-X.Y/` directory for their intended WordPress release. Inspect the available compatibility directories first; do not assume the newest one is right.
Expand Down
2 changes: 1 addition & 1 deletion docs/contributors/code/workspace-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Anything added to the root `package.json` becomes implicitly available to every
- **Separation of concerns.** Each workspace declares the dependencies it needs to function, making the relationship between code and dependencies explicit.
- **Cleaner root.** The root `package.json` only contains repo-wide tooling (lint, format, type-check, git hooks, monorepo orchestration). Reviewing dependency changes is easier when the root is small.
- **Fewer merge conflicts.** Contributors can update a workspace's dependencies without touching the root.
- **Phantom dependency prevention.** With npm's hoisted install strategy, dependencies are hoisted to the root `node_modules`, so a workspace can accidentally import a dependency it never declared. A clean root keeps these relationships honest now, and is a prerequisite for moving to an isolated dependency approach in the future (one proposal under discussion is a [migration to pnpm](https://github.com/WordPress/gutenberg/pull/74689)), where workspaces can only see their own declared dependencies.
- **Phantom dependency prevention.** The repository uses npm's isolated install strategy (`install-strategy = "linked"` in `.npmrc`, adopted in [#83847](https://github.com/WordPress/gutenberg/pull/83847)). Dependencies are stored in `node_modules/.store/` and symlinked only into the workspaces that declare them, so a workspace cannot import a dependency it never declared. Root dependencies are the exception: Node still finds them by walking up to the root `node_modules`, which is another reason to keep the root lean.

The default answer for "where does this dependency go?" is **a workspace**, not the root. If you find yourself reaching for the root `package.json`, consider whether the dependency can live in:

Expand Down
Loading