build: declare workspace dependencies and check them in CI (P0.2)
Packages relied on npm hoisting for imports they never declared, so a package installed on its own fails (UF-024). - server: + @waggle/marketplace, @waggle/sdk, @waggle/weaver, zod (MIT), @anthropic-ai/sdk (MIT), @ax-llm/ax (Apache-2.0); - @waggle/hive-mind-shim-core and stripe (unused) - agent: + pdf-parse (Apache-2.0); playwright-core (Apache-2.0) as an optional peer, since it is loaded only when available - worker: + @waggle/waggle-dance; web: + @waggle/shared - launcher: + @waggle/server as a dev dependency (bundled by tsup); - stripe; cli: - @waggle/weaver (unused); root: - stripe scripts/check-workspace-deps.mjs (npm run check:deps) compares the imports in each community-edition package's src/ with its manifest and runs in CI. Two imports wait for P1.4 (optimizer, evolution wiring).
This commit is contained in:
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@@ -44,6 +44,9 @@ jobs:
|
|||||||
- name: Lint (root flat config)
|
- name: Lint (root flat config)
|
||||||
run: npm run lint
|
run: npm run lint
|
||||||
|
|
||||||
|
- name: Workspace dependency declarations
|
||||||
|
run: npm run check:deps
|
||||||
|
|
||||||
- name: Tauri TS typecheck (app/scripts)
|
- name: Tauri TS typecheck (app/scripts)
|
||||||
run: npx tsc -p app/tsconfig.json
|
run: npx tsc -p app/tsconfig.json
|
||||||
|
|
||||||
|
|||||||
@@ -155,7 +155,9 @@ npx tsc --noEmit --project packages/server/tsconfig.json # the sidecar runs vi
|
|||||||
npx tsc --noEmit --project app/tsconfig.json
|
npx tsc --noEmit --project app/tsconfig.json
|
||||||
npm run test # root Vitest: packages, tests/, scripts/ (excludes apps/**)
|
npm run test # root Vitest: packages, tests/, scripts/ (excludes apps/**)
|
||||||
(cd apps/web && npx vitest run) # web UI tests use their own config
|
(cd apps/web && npx vitest run) # web UI tests use their own config
|
||||||
npm run lint
|
npm run lint # root config; ignores apps/web
|
||||||
|
(cd apps/web && npx eslint .) # web config; 49 errors pre-exist (docs/oss/baseline.md)
|
||||||
|
npm run check:deps # every imported package is declared in its package.json
|
||||||
```
|
```
|
||||||
|
|
||||||
- Playwright e2e reuses any server already listening on :3333 and its data directory. For an
|
- Playwright e2e reuses any server already listening on :3333 and its data directory. For an
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
"@tauri-apps/api": "^2.10.1",
|
"@tauri-apps/api": "^2.10.1",
|
||||||
"@tauri-apps/plugin-dialog": "^2.7.0",
|
"@tauri-apps/plugin-dialog": "^2.7.0",
|
||||||
"@types/qrcode": "^1.5.6",
|
"@types/qrcode": "^1.5.6",
|
||||||
|
"@waggle/shared": "*",
|
||||||
"class-variance-authority": "^0.7.1",
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"cmdk": "^1.1.1",
|
"cmdk": "^1.1.1",
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ Baseline: commit `b20b138` of `git.os-dev.tech/oleg.m/waggle-os`.
|
|||||||
| UF-021 | Settings visual-regression baseline is ignored by git | Fixed | Tests, git |
|
| UF-021 | Settings visual-regression baseline is ignored by git | Fixed | Tests, git |
|
||||||
| UF-022 | Unit tests write into the developer's real `~/.waggle` | Fixed | Tests |
|
| UF-022 | Unit tests write into the developer's real `~/.waggle` | Fixed | Tests |
|
||||||
| UF-023 | Four unit-test files fail on macOS | Open | Tests, macOS |
|
| UF-023 | Four unit-test files fail on macOS | Open | Tests, macOS |
|
||||||
|
| UF-024 | Workspace packages import packages they do not declare | Fixed | Build, packaging |
|
||||||
|
|
||||||
## Entries
|
## Entries
|
||||||
|
|
||||||
@@ -234,3 +235,12 @@ Entries UF-010 to UF-019 come from the UI audit `anti-slop/audit-001-2026-10-14.
|
|||||||
- Cause: the runtime fixtures appear to assume the Windows archive layout, and the path checks do not account for `/var` being a symlink to `/private/var` on macOS. The OpenClaw timeout is not investigated yet.
|
- Cause: the runtime fixtures appear to assume the Windows archive layout, and the path checks do not account for `/var` being a symlink to `/private/var` on macOS. The OpenClaw timeout is not investigated yet.
|
||||||
- What we did: nothing yet. The failures are recorded as known in `docs/oss/baseline.md`.
|
- What we did: nothing yet. The failures are recorded as known in `docs/oss/baseline.md`.
|
||||||
- Recommendation: make the runtime fixtures platform-aware, compare resolved paths (`fs.realpathSync`) in path assertions, and run the unit suite on macOS and Linux in CI.
|
- Recommendation: make the runtime fixtures platform-aware, compare resolved paths (`fs.realpathSync`) in path assertions, and run the unit suite on macOS and Linux in CI.
|
||||||
|
|
||||||
|
### UF-024. Workspace packages import packages they do not declare
|
||||||
|
- Status: Fixed
|
||||||
|
- Found: 2026-10-15
|
||||||
|
- Where: `package.json` of `packages/server`, `packages/agent`, `packages/launcher`, `packages/worker`, `packages/cli` and `apps/web`
|
||||||
|
- Symptom: inside the monorepo everything works because npm hoists all dependencies to the root `node_modules`, but a package installed on its own fails to resolve imports. `server` imports `@waggle/marketplace`, `@waggle/sdk`, `@waggle/weaver`, `zod`, `@anthropic-ai/sdk` and `@ax-llm/ax` without declaring them; `agent` imports `pdf-parse` and `playwright-core`; `worker` imports `@waggle/waggle-dance`; `launcher` imports `@waggle/server`; `apps/web` imports `@waggle/shared`. `server` declares `@waggle/hive-mind-shim-core` and `cli` declares `@waggle/weaver` without using them.
|
||||||
|
- Cause: no check compares imports with declared dependencies.
|
||||||
|
- What we did: declared the missing dependencies (`playwright-core` as an optional peer, because `agent` loads it only when available; `@waggle/server` as a dev dependency of `launcher`, because its build bundles `@waggle/*`), removed the unused ones, and added `scripts/check-workspace-deps.mjs` (`npm run check:deps`) to CI.
|
||||||
|
- Recommendation: apply the same declarations in the main project and run the check in CI.
|
||||||
|
|||||||
23
package-lock.json
generated
23
package-lock.json
generated
@@ -20,7 +20,6 @@
|
|||||||
"@tauri-apps/plugin-shell": "^2.3.5",
|
"@tauri-apps/plugin-shell": "^2.3.5",
|
||||||
"@vitejs/plugin-react": "5.1.1",
|
"@vitejs/plugin-react": "5.1.1",
|
||||||
"sharp": "0.35.3",
|
"sharp": "0.35.3",
|
||||||
"stripe": "^21.0.1",
|
|
||||||
"tailwind-merge": "^3.5.0"
|
"tailwind-merge": "^3.5.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -89,6 +88,7 @@
|
|||||||
"@tauri-apps/api": "^2.10.1",
|
"@tauri-apps/api": "^2.10.1",
|
||||||
"@tauri-apps/plugin-dialog": "^2.7.0",
|
"@tauri-apps/plugin-dialog": "^2.7.0",
|
||||||
"@types/qrcode": "^1.5.6",
|
"@types/qrcode": "^1.5.6",
|
||||||
|
"@waggle/shared": "*",
|
||||||
"class-variance-authority": "^0.7.1",
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"cmdk": "^1.1.1",
|
"cmdk": "^1.1.1",
|
||||||
@@ -23953,12 +23953,21 @@
|
|||||||
"exceljs": "^4.4.0",
|
"exceljs": "^4.4.0",
|
||||||
"glob": "^13.0.6",
|
"glob": "^13.0.6",
|
||||||
"jszip": "^3.10.1",
|
"jszip": "^3.10.1",
|
||||||
|
"pdf-parse": "^2.4.5",
|
||||||
"pdfmake": "^0.3.7",
|
"pdfmake": "^0.3.7",
|
||||||
"undici": "^6.27.0"
|
"undici": "^6.27.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/pdfmake": "^0.3.2",
|
"@types/pdfmake": "^0.3.2",
|
||||||
"pptxgenjs": "file:../../vendor/pptxgenjs"
|
"pptxgenjs": "file:../../vendor/pptxgenjs"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"playwright-core": "^1.60.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"playwright-core": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"packages/agent/node_modules/pptxgenjs": {
|
"packages/agent/node_modules/pptxgenjs": {
|
||||||
@@ -23973,7 +23982,6 @@
|
|||||||
"@anthropic-ai/sdk": "^0.78.0",
|
"@anthropic-ai/sdk": "^0.78.0",
|
||||||
"@waggle/agent": "*",
|
"@waggle/agent": "*",
|
||||||
"@waggle/core": "*",
|
"@waggle/core": "*",
|
||||||
"@waggle/weaver": "*",
|
|
||||||
"chalk": "^5.4.1"
|
"chalk": "^5.4.1"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
@@ -24549,7 +24557,6 @@
|
|||||||
"pdf-parse": "^2.4.5",
|
"pdf-parse": "^2.4.5",
|
||||||
"postgres": "^3.4.0",
|
"postgres": "^3.4.0",
|
||||||
"sqlite-vec": "^0.1.7-alpha.2",
|
"sqlite-vec": "^0.1.7-alpha.2",
|
||||||
"stripe": "^21.0.1",
|
|
||||||
"undici": "^6.27.0",
|
"undici": "^6.27.0",
|
||||||
"ws": "^8.21.0",
|
"ws": "^8.21.0",
|
||||||
"zod": "^3.24.0"
|
"zod": "^3.24.0"
|
||||||
@@ -24558,6 +24565,7 @@
|
|||||||
"waggle": "dist/cli.js"
|
"waggle": "dist/cli.js"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@waggle/server": "*",
|
||||||
"tsup": "^8.5.1",
|
"tsup": "^8.5.1",
|
||||||
"tsx": "^4.21.0"
|
"tsx": "^4.21.0"
|
||||||
},
|
},
|
||||||
@@ -24884,15 +24892,19 @@
|
|||||||
"name": "@waggle/server",
|
"name": "@waggle/server",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@anthropic-ai/sdk": "^0.78.0",
|
||||||
|
"@ax-llm/ax": "^19.0.12",
|
||||||
"@clerk/fastify": "^3.1.3",
|
"@clerk/fastify": "^3.1.3",
|
||||||
"@fastify/cors": "^10.0.0",
|
"@fastify/cors": "^10.0.0",
|
||||||
"@fastify/static": "^10.1.2",
|
"@fastify/static": "^10.1.2",
|
||||||
"@fastify/websocket": "^11.0.0",
|
"@fastify/websocket": "^11.0.0",
|
||||||
"@waggle/agent": "*",
|
"@waggle/agent": "*",
|
||||||
"@waggle/core": "*",
|
"@waggle/core": "*",
|
||||||
"@waggle/hive-mind-shim-core": "*",
|
"@waggle/marketplace": "*",
|
||||||
|
"@waggle/sdk": "*",
|
||||||
"@waggle/shared": "*",
|
"@waggle/shared": "*",
|
||||||
"@waggle/waggle-dance": "*",
|
"@waggle/waggle-dance": "*",
|
||||||
|
"@waggle/weaver": "*",
|
||||||
"@waggle/wiki-compiler": "*",
|
"@waggle/wiki-compiler": "*",
|
||||||
"@whiskeysockets/baileys": "^7.0.0-rc13",
|
"@whiskeysockets/baileys": "^7.0.0-rc13",
|
||||||
"adm-zip": "^0.6.0",
|
"adm-zip": "^0.6.0",
|
||||||
@@ -24908,7 +24920,7 @@
|
|||||||
"mammoth": "^1.11.0",
|
"mammoth": "^1.11.0",
|
||||||
"pdf-parse": "^2.4.5",
|
"pdf-parse": "^2.4.5",
|
||||||
"postgres": "^3.4.0",
|
"postgres": "^3.4.0",
|
||||||
"stripe": "^21.0.1"
|
"zod": "^3.24.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/archiver": "^7.0.0",
|
"@types/archiver": "^7.0.0",
|
||||||
@@ -24959,6 +24971,7 @@
|
|||||||
"@waggle/agent": "*",
|
"@waggle/agent": "*",
|
||||||
"@waggle/core": "*",
|
"@waggle/core": "*",
|
||||||
"@waggle/shared": "*",
|
"@waggle/shared": "*",
|
||||||
|
"@waggle/waggle-dance": "*",
|
||||||
"bullmq": "^5.0.0",
|
"bullmq": "^5.0.0",
|
||||||
"drizzle-orm": "^0.45.2",
|
"drizzle-orm": "^0.45.2",
|
||||||
"ioredis": "^5.4.0",
|
"ioredis": "^5.4.0",
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
"dev:www": "npm run dev -w apps/www",
|
"dev:www": "npm run dev -w apps/www",
|
||||||
"build:www": "npm run build -w apps/www",
|
"build:www": "npm run build -w apps/www",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
|
"check:deps": "node scripts/check-workspace-deps.mjs",
|
||||||
"lint:no-invalid-snapshots": "node scripts/check-no-invalid-snapshots.mjs",
|
"lint:no-invalid-snapshots": "node scripts/check-no-invalid-snapshots.mjs",
|
||||||
"ux:contrast": "node scripts/ux-gates/contrast-tokens.mjs",
|
"ux:contrast": "node scripts/ux-gates/contrast-tokens.mjs",
|
||||||
"ux:color-guard": "node scripts/ux-gates/text-color-guard.mjs",
|
"ux:color-guard": "node scripts/ux-gates/text-color-guard.mjs",
|
||||||
@@ -103,7 +104,6 @@
|
|||||||
"@tauri-apps/plugin-shell": "^2.3.5",
|
"@tauri-apps/plugin-shell": "^2.3.5",
|
||||||
"@vitejs/plugin-react": "5.1.1",
|
"@vitejs/plugin-react": "5.1.1",
|
||||||
"sharp": "0.35.3",
|
"sharp": "0.35.3",
|
||||||
"stripe": "^21.0.1",
|
|
||||||
"tailwind-merge": "^3.5.0"
|
"tailwind-merge": "^3.5.0"
|
||||||
},
|
},
|
||||||
"//optionalDependencies": "Platform-specific native binaries — optional so npm SKIPS them on os/cpu mismatch (Linux/macOS CI) instead of failing install with EBADPLATFORM. See docs/audits/2026-06-01-full-repo-verification-sweep.md.",
|
"//optionalDependencies": "Platform-specific native binaries — optional so npm SKIPS them on os/cpu mismatch (Linux/macOS CI) instead of failing install with EBADPLATFORM. See docs/audits/2026-06-01-full-repo-verification-sweep.md.",
|
||||||
|
|||||||
@@ -31,9 +31,18 @@
|
|||||||
"exceljs": "^4.4.0",
|
"exceljs": "^4.4.0",
|
||||||
"glob": "^13.0.6",
|
"glob": "^13.0.6",
|
||||||
"jszip": "^3.10.1",
|
"jszip": "^3.10.1",
|
||||||
|
"pdf-parse": "^2.4.5",
|
||||||
"pdfmake": "^0.3.7",
|
"pdfmake": "^0.3.7",
|
||||||
"undici": "^6.27.0"
|
"undici": "^6.27.0"
|
||||||
},
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"playwright-core": "^1.60.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"playwright-core": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/pdfmake": "^0.3.2",
|
"@types/pdfmake": "^0.3.2",
|
||||||
|
|||||||
@@ -51,7 +51,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@waggle/core": "*",
|
"@waggle/core": "*",
|
||||||
"@waggle/agent": "*",
|
"@waggle/agent": "*",
|
||||||
"@waggle/weaver": "*",
|
|
||||||
"@anthropic-ai/sdk": "^0.78.0",
|
"@anthropic-ai/sdk": "^0.78.0",
|
||||||
"chalk": "^5.4.1"
|
"chalk": "^5.4.1"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -56,12 +56,12 @@
|
|||||||
"pdf-parse": "^2.4.5",
|
"pdf-parse": "^2.4.5",
|
||||||
"postgres": "^3.4.0",
|
"postgres": "^3.4.0",
|
||||||
"sqlite-vec": "^0.1.7-alpha.2",
|
"sqlite-vec": "^0.1.7-alpha.2",
|
||||||
"stripe": "^21.0.1",
|
|
||||||
"undici": "^6.27.0",
|
"undici": "^6.27.0",
|
||||||
"ws": "^8.21.0",
|
"ws": "^8.21.0",
|
||||||
"zod": "^3.24.0"
|
"zod": "^3.24.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@waggle/server": "*",
|
||||||
"tsup": "^8.5.1",
|
"tsup": "^8.5.1",
|
||||||
"tsx": "^4.21.0"
|
"tsx": "^4.21.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,15 +17,19 @@
|
|||||||
"start:local": "tsx src/local/start.ts"
|
"start:local": "tsx src/local/start.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@anthropic-ai/sdk": "^0.78.0",
|
||||||
|
"@ax-llm/ax": "^19.0.12",
|
||||||
"@clerk/fastify": "^3.1.3",
|
"@clerk/fastify": "^3.1.3",
|
||||||
"@fastify/cors": "^10.0.0",
|
"@fastify/cors": "^10.0.0",
|
||||||
"@fastify/static": "^10.1.2",
|
"@fastify/static": "^10.1.2",
|
||||||
"@fastify/websocket": "^11.0.0",
|
"@fastify/websocket": "^11.0.0",
|
||||||
"@waggle/agent": "*",
|
"@waggle/agent": "*",
|
||||||
"@waggle/core": "*",
|
"@waggle/core": "*",
|
||||||
"@waggle/hive-mind-shim-core": "*",
|
"@waggle/marketplace": "*",
|
||||||
|
"@waggle/sdk": "*",
|
||||||
"@waggle/shared": "*",
|
"@waggle/shared": "*",
|
||||||
"@waggle/waggle-dance": "*",
|
"@waggle/waggle-dance": "*",
|
||||||
|
"@waggle/weaver": "*",
|
||||||
"@waggle/wiki-compiler": "*",
|
"@waggle/wiki-compiler": "*",
|
||||||
"@whiskeysockets/baileys": "^7.0.0-rc13",
|
"@whiskeysockets/baileys": "^7.0.0-rc13",
|
||||||
"adm-zip": "^0.6.0",
|
"adm-zip": "^0.6.0",
|
||||||
@@ -41,7 +45,7 @@
|
|||||||
"mammoth": "^1.11.0",
|
"mammoth": "^1.11.0",
|
||||||
"pdf-parse": "^2.4.5",
|
"pdf-parse": "^2.4.5",
|
||||||
"postgres": "^3.4.0",
|
"postgres": "^3.4.0",
|
||||||
"stripe": "^21.0.1"
|
"zod": "^3.24.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/archiver": "^7.0.0",
|
"@types/archiver": "^7.0.0",
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
"@waggle/shared": "*",
|
"@waggle/shared": "*",
|
||||||
"@waggle/core": "*",
|
"@waggle/core": "*",
|
||||||
"@waggle/agent": "*",
|
"@waggle/agent": "*",
|
||||||
|
"@waggle/waggle-dance": "*",
|
||||||
"bullmq": "^5.0.0",
|
"bullmq": "^5.0.0",
|
||||||
"drizzle-orm": "^0.45.2",
|
"drizzle-orm": "^0.45.2",
|
||||||
"ioredis": "^5.4.0",
|
"ioredis": "^5.4.0",
|
||||||
|
|||||||
126
scripts/check-workspace-deps.mjs
Normal file
126
scripts/check-workspace-deps.mjs
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
/**
|
||||||
|
* Fails when a workspace package imports a package it does not declare.
|
||||||
|
*
|
||||||
|
* npm hoists every dependency to the root node_modules, so an undeclared
|
||||||
|
* import still works inside the monorepo and only breaks once the package is
|
||||||
|
* installed on its own. This check reads the runtime sources (`src/`) of each
|
||||||
|
* community-edition package and compares the bare import specifiers with the
|
||||||
|
* package's dependencies, devDependencies, peerDependencies and
|
||||||
|
* optionalDependencies.
|
||||||
|
*
|
||||||
|
* Usage: node scripts/check-workspace-deps.mjs
|
||||||
|
*/
|
||||||
|
import fs from 'node:fs';
|
||||||
|
import path from 'node:path';
|
||||||
|
import { builtinModules } from 'node:module';
|
||||||
|
|
||||||
|
const ROOT = path.resolve(path.dirname(new URL(import.meta.url).pathname), '..');
|
||||||
|
|
||||||
|
// Packages leaving the community edition are not checked (AGENTS.md, section 2).
|
||||||
|
const EXCLUDED = new Set([
|
||||||
|
'apps/www',
|
||||||
|
'packages/admin-web',
|
||||||
|
'packages/memory-mcp',
|
||||||
|
'packages/optimizer',
|
||||||
|
'packages/wiki-compiler',
|
||||||
|
]);
|
||||||
|
const EXCLUDED_PREFIX = 'packages/hive-mind-';
|
||||||
|
|
||||||
|
// Known undeclared imports that a work package removes. Each entry needs a reason.
|
||||||
|
const PENDING = {
|
||||||
|
'packages/agent': {
|
||||||
|
'@ax-llm/ax': 'evolution-llm-wiring.ts is removed in P1.4 (ADR-0004)',
|
||||||
|
},
|
||||||
|
'packages/server': {
|
||||||
|
'@waggle/optimizer': 'optimizer-service.ts is removed in P1.4 (ADR-0004)',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const SOURCE_EXT = /\.(?:[cm]?[jt]sx?)$/;
|
||||||
|
// Valid npm package names, so specifier-like text inside strings is ignored.
|
||||||
|
const PACKAGE_NAME = /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i;
|
||||||
|
const BUILTINS = new Set(builtinModules);
|
||||||
|
|
||||||
|
function workspaceDirs() {
|
||||||
|
const dirs = [];
|
||||||
|
for (const parent of ['apps', 'packages']) {
|
||||||
|
for (const name of fs.readdirSync(path.join(ROOT, parent))) {
|
||||||
|
const rel = `${parent}/${name}`;
|
||||||
|
if (EXCLUDED.has(rel) || rel.startsWith(EXCLUDED_PREFIX)) continue;
|
||||||
|
if (fs.existsSync(path.join(ROOT, rel, 'package.json'))) dirs.push(rel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dirs.sort();
|
||||||
|
}
|
||||||
|
|
||||||
|
function sourceFiles(dir) {
|
||||||
|
const out = [];
|
||||||
|
const walk = (d) => {
|
||||||
|
for (const entry of fs.readdirSync(d, { withFileTypes: true })) {
|
||||||
|
if (entry.name === 'node_modules' || entry.name === 'dist') continue;
|
||||||
|
const full = path.join(d, entry.name);
|
||||||
|
if (entry.isDirectory()) walk(full);
|
||||||
|
else if (SOURCE_EXT.test(entry.name) && !/\.(?:test|spec)\./.test(entry.name)) out.push(full);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (fs.existsSync(dir)) walk(dir);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function stripComments(code) {
|
||||||
|
return code
|
||||||
|
.replace(/\/\*[\s\S]*?\*\//g, '')
|
||||||
|
.replace(/(^|[^:'"`\\])\/\/.*$/gm, '$1');
|
||||||
|
}
|
||||||
|
|
||||||
|
const SPECIFIER_PATTERNS = [
|
||||||
|
/\bfrom\s*['"]([^'"\n]+)['"]/g,
|
||||||
|
/\bimport\s*['"]([^'"\n]+)['"]/g,
|
||||||
|
/\bimport\s*\(\s*['"]([^'"\n]+)['"]\s*\)/g,
|
||||||
|
/\brequire\s*\(\s*['"]([^'"\n]+)['"]\s*\)/g,
|
||||||
|
];
|
||||||
|
|
||||||
|
function packageName(specifier) {
|
||||||
|
if (specifier.startsWith('.') || specifier.startsWith('/')) return null;
|
||||||
|
if (specifier.startsWith('node:') || specifier.startsWith('@/') || specifier.startsWith('virtual:')) return null;
|
||||||
|
const parts = specifier.split('/');
|
||||||
|
const name = specifier.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
|
||||||
|
if (BUILTINS.has(name) || !PACKAGE_NAME.test(name)) return null;
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
let failures = 0;
|
||||||
|
for (const rel of workspaceDirs()) {
|
||||||
|
const manifest = JSON.parse(fs.readFileSync(path.join(ROOT, rel, 'package.json'), 'utf8'));
|
||||||
|
const declared = new Set([
|
||||||
|
manifest.name,
|
||||||
|
...Object.keys(manifest.dependencies ?? {}),
|
||||||
|
...Object.keys(manifest.devDependencies ?? {}),
|
||||||
|
...Object.keys(manifest.peerDependencies ?? {}),
|
||||||
|
...Object.keys(manifest.optionalDependencies ?? {}),
|
||||||
|
]);
|
||||||
|
const pending = PENDING[rel] ?? {};
|
||||||
|
const missing = new Map();
|
||||||
|
for (const file of sourceFiles(path.join(ROOT, rel, 'src'))) {
|
||||||
|
const code = stripComments(fs.readFileSync(file, 'utf8'));
|
||||||
|
for (const pattern of SPECIFIER_PATTERNS) {
|
||||||
|
for (const match of code.matchAll(pattern)) {
|
||||||
|
const name = packageName(match[1]);
|
||||||
|
if (!name || declared.has(name) || declared.has(`@types/${name}`) || name in pending) continue;
|
||||||
|
if (!missing.has(name)) missing.set(name, path.relative(ROOT, file));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (missing.size > 0) {
|
||||||
|
failures += missing.size;
|
||||||
|
console.error(`${rel} (${manifest.name}) imports undeclared packages:`);
|
||||||
|
for (const [name, file] of missing) console.error(` ${name} (first seen in ${file})`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failures > 0) {
|
||||||
|
console.error(`\n${failures} undeclared import(s). Declare them in the package's package.json.`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
console.log('All workspace imports are declared.');
|
||||||
Reference in New Issue
Block a user