You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* docs(track): add setup-monorepo-scan-20260329
* chore(track): setup-monorepo-scan-20260329 start implementation
* feat(please-plugins): add monorepo workspace dependency scanning
Add resolveWorkspacePackages() and collectAllDependencies() to scan
workspace package.json files in monorepos. Supports npm/yarn/Bun
workspaces field and pnpm-workspace.yaml. Integrates into both
scanForSetup() and detectForEvent() with workspace-aware source
tracking (e.g., "apps/web: @nuxt/ui").
Closes#132
* refactor(please-plugins): extract workspace resolver to separate module
Move resolveWorkspacePackages, collectAllDependencies, and
resolveGlobPatterns to workspace-resolver.ts to keep
check-dependencies.ts under 500 LOC guideline.
* docs(track): add retrospective for setup-monorepo-scan-20260329
* chore: apply AI code review suggestions
- Replace custom glob resolver with Bun.Glob for accurate multi-segment
pattern matching (fixes patterns like "apps/*/src" truncation bug)
- Deduplicate resolved workspace paths to avoid duplicate entries when
npm workspaces and pnpm-workspace.yaml share the same patterns
- Improve pnpm-workspace.yaml parsing to handle inline comments and
more robust top-level key detection
- Tighten test assertions for deduplication (exact length 1) and
negation patterns (exact length 2 with both expected dirs)
After this change, users running `/please-plugins:setup` in a monorepo project will see plugin recommendations based on dependencies from all workspace packages, not just the root. They can verify it works by running the setup command in a monorepo and confirming that dependencies from sub-packages (e.g., `apps/web/package.json`) trigger the correct plugin recommendations.
16
+
17
+
## Context
18
+
19
+
The `check-dependencies.ts` hook currently reads only the root `package.json` to detect dependencies that match plugin mappings. In monorepo projects using npm/yarn/Bun workspaces or pnpm workspaces, the root `package.json` often contains only shared dev dependencies (e.g., `vitest`, `eslint`), while framework-specific packages (e.g., `@nuxt/ui`, `vue`, `prisma`) live in workspace packages like `apps/web/package.json` or `packages/api/package.json`.
20
+
21
+
This means the plugin recommender misses most relevant plugins in monorepo setups. The fix requires resolving workspace package paths from the root configuration, reading each workspace `package.json`, and merging all dependencies before running detection.
22
+
23
+
Key constraints:
24
+
- Must support npm/yarn/Bun `workspaces` field (array of glob patterns) and `pnpm-workspace.yaml`
25
+
- Must use synchronous fs + glob only (no child processes) to keep hook latency low
26
+
- Must gracefully skip missing or malformed workspace `package.json` files
27
+
- Must not break non-monorepo projects (backward compatible)
The approach adds workspace resolution as a layer between `loadPackageJson()` and the existing detection functions. A new `resolveWorkspacePackages(cwd, rootPkg)` function resolves glob patterns from the `workspaces` field or `pnpm-workspace.yaml` into concrete directory paths. A new `collectAllDependencies(cwd)` function calls `loadPackageJson()` for each workspace package and merges all `dependencies` + `devDependencies` into a single record, tagging each entry with its source path for later source attribution.
34
+
35
+
This is minimally invasive: `detectPackages()` continues to receive a flat deps record, `scanForSetup()` and `detectForEvent()` simply call `collectAllDependencies()` instead of `loadPackageJson()`. Source tracking is enhanced to show `apps/web: @nuxt/ui` when a dependency was found in a workspace package.
36
+
37
+
Bun's built-in `Bun.Glob` provides synchronous, fast glob resolution without adding dependencies.
38
+
39
+
## Tasks
40
+
41
+
-[x] T001 Add workspace resolution function `resolveWorkspacePackages` (file: plugins/please-plugins/hooks/check-dependencies.ts)
42
+
-[x] T002 Add dependency aggregation function `collectAllDependencies` (file: plugins/please-plugins/hooks/check-dependencies.ts) (depends on T001)
43
+
-[x] T003 Integrate workspace scanning into `scanForSetup` and `detectForEvent` (file: plugins/please-plugins/hooks/check-dependencies.ts) (depends on T002)
44
+
-[x] T004 Enhance source tracking for workspace-origin dependencies (file: plugins/please-plugins/hooks/check-dependencies.ts) (depends on T003)
-[ ] Source field shows workspace path prefix for workspace-origin deps
70
+
-[ ] Non-monorepo projects continue to work unchanged
71
+
72
+
### Observable Outcomes
73
+
74
+
- Running `bun run plugins/please-plugins/hooks/check-dependencies.ts --setup` in this repo detects dependencies from `apps/web/package.json` (e.g., `@nuxt/ui`, `@nuxt/content`)
75
+
- Running the same in a non-monorepo project produces identical output as before
76
+
77
+
### Acceptance Criteria Check
78
+
79
+
-[ ] AC-1: Dependencies from `apps/web/package.json` detected in a monorepo with `workspaces`
80
+
-[ ] AC-2: Dependencies detected from `pnpm-workspace.yaml` projects
# Monorepo Workspace Dependency Scanning for Setup Command
2
+
3
+
> Track: setup-monorepo-scan-20260329
4
+
5
+
## Overview
6
+
7
+
Enhance the `please-plugins` dependency scanner (`check-dependencies.ts`) to discover and aggregate dependencies from all workspace packages in monorepo projects. Currently, only the root `package.json` is read, which misses dependencies declared in workspace packages (e.g., `apps/web/package.json`, `packages/shared/package.json`).
8
+
9
+
## Requirements
10
+
11
+
### Functional Requirements
12
+
13
+
-[ ] FR-1: Resolve workspace package paths from the root `package.json``workspaces` field (npm/yarn/Bun format — array of glob patterns)
14
+
-[ ] FR-2: Resolve workspace package paths from `pnpm-workspace.yaml` (`packages` field — array of glob patterns)
15
+
-[ ] FR-3: Read `package.json` from each resolved workspace directory and merge all `dependencies` + `devDependencies` into a single aggregated set
16
+
-[ ] FR-4: Use the aggregated dependency set for plugin detection in both `scanForSetup()` and `detectForEvent()` (SessionStart hook)
17
+
-[ ] FR-5: When a plugin is detected from a workspace package (not root), include the workspace path in the `source` field (e.g., `apps/web: @nuxt/ui`)
18
+
19
+
### Non-functional Requirements
20
+
21
+
-[ ] NFR-1: Workspace resolution must not significantly increase hook latency — use synchronous `fs` and `glob` only, no external processes
22
+
-[ ] NFR-2: Gracefully handle missing or malformed workspace package.json files (skip with no error)
23
+
24
+
## Acceptance Criteria
25
+
26
+
-[ ] AC-1: In a monorepo with `workspaces: ["apps/*", "packages/*"]`, dependencies from `apps/web/package.json` are detected by the scanner
27
+
-[ ] AC-2: In a monorepo with `pnpm-workspace.yaml`, workspace packages are resolved and scanned
28
+
-[ ] AC-3: The SessionStart hook detects workspace dependencies, not just root dependencies
29
+
-[ ] AC-4: The `--setup` mode aggregates all workspace dependencies for plugin detection
30
+
-[ ] AC-5: Non-monorepo projects (no `workspaces` field, no `pnpm-workspace.yaml`) continue to work unchanged
31
+
32
+
## Out of Scope
33
+
34
+
- Nested workspace resolution (monorepo within a monorepo)
35
+
- Per-package detection reporting (we merge all deps, not per-package)
36
+
- Yarn PnP resolution or Yarn Berry-specific behaviors
37
+
- Workspace dependency graph analysis
38
+
39
+
## Assumptions
40
+
41
+
- Glob resolution for workspace patterns uses `Bun.glob` or Node.js `glob` with synchronous API
42
+
- The root `package.json` is always the entry point; workspace files are additive
43
+
- Duplicate dependencies across workspaces are deduplicated naturally (merged into a single key set)
0 commit comments