fix(path-checker): resolve workspace aliases and filter URLs#17
fix(path-checker): resolve workspace aliases and filter URLs#17adelin-b wants to merge 1 commit intotheDakshJaitly:mainfrom
Conversation
The path checker was flagging workspace package references (e.g. `@acme/ui`, `@acme/shared/utils`) as MISSING_PATH errors because it only checked the filesystem. In monorepos, these are valid import aliases that resolve via the package manager. Changes: - Add workspace name collection from root package.json `workspaces` field — reads each workspace's package.json `name` to build a lookup set. Works with all package managers (npm, yarn, pnpm, bun). - Try Node's `require.resolve` first for installed npm packages, fall back to workspace name check for package managers that don't symlink all workspaces into node_modules (e.g. bun). - Filter URLs (http://, https://) which are never filesystem paths. Example: a monorepo with `packages/ui/package.json` containing `"name": "@acme/ui"` will now correctly resolve references like `@acme/ui/button` in scaffold files instead of reporting them as missing paths.
theDakshJaitly
left a comment
There was a problem hiding this comment.
Thanks for the contribution! The approach is solid: clean separation with collectWorkspaceNames, good normalization of the workspaces field, and the require.resolve → workspace fallback chain is well-structured.
A few things to address before merging:
HIGH: pnpm workspace support missing
The JSDoc says "Works with any package manager (npm, yarn, pnpm, bun)" but pnpm uses pnpm-workspace.yaml, not the workspaces field in package.json. This means pnpm monorepos will get an empty workspace set and still produce false-positive MISSING_PATH errors.
Fix: Either parse pnpm-workspace.yaml as a fallback when patterns is empty, or update the comment to exclude pnpm.
MEDIUM: URL regex only covers http/https
URL_PATTERN won't catch ftp://, file:///, or protocol-relative // URLs. Consider broadening to:
const URL_PATTERN = /^(?:https?|ftp|file):\/\//;MEDIUM: createRequire anchor path
createRequire(resolve(projectRoot, "package.json")) works incidentally but the canonical pattern is createRequire(resolve(projectRoot, "noop.js")) or using pathToFileURL(), since createRequire expects a module filename.
LOW: No tests for new behavior
There are no tests for the path checker module at all. Would be great to add coverage for at least: URL skipping, require.resolve resolution, and workspace name resolution.
Summary
MISSING_PATHerrors. In monorepos, references like@acme/uior@acme/shared/utilsin scaffold files are valid import aliases, not filesystem paths.http://,https://) which were being treated as filesystem paths because they contain/.How it works
require.resolvefirst — tries Node's built-in module resolution for installed npm packages (handlesnode_modulespackages regardless of hoisting strategy)package.jsonworkspacesfield, globs each pattern, and collects thenamefrom each workspace'spackage.json. This handles package managers like bun that don't symlink all workspaces intonode_modules/http://andhttps://prefixed values before path checkingExample
A monorepo with this structure:
Previously, scaffold references like
@acme/ui/buttonor@acme/shared/typeswould trigger:Now they resolve correctly via the workspace name lookup.
Test plan
@scope/*aliases now resolve correctlynode_modulesstill resolve viarequire.resolve