Skip to content

fix(path-checker): resolve workspace aliases and filter URLs#17

Open
adelin-b wants to merge 1 commit intotheDakshJaitly:mainfrom
adelin-b:fix/skip-scoped-packages-and-urls
Open

fix(path-checker): resolve workspace aliases and filter URLs#17
adelin-b wants to merge 1 commit intotheDakshJaitly:mainfrom
adelin-b:fix/skip-scoped-packages-and-urls

Conversation

@adelin-b
Copy link
Copy Markdown

@adelin-b adelin-b commented Apr 6, 2026

Summary

  • Resolve workspace package aliases in the path checker instead of flagging them as MISSING_PATH errors. In monorepos, references like @acme/ui or @acme/shared/utils in scaffold files are valid import aliases, not filesystem paths.
  • Filter URLs (http://, https://) which were being treated as filesystem paths because they contain /.

How it works

  1. require.resolve first — tries Node's built-in module resolution for installed npm packages (handles node_modules packages regardless of hoisting strategy)
  2. Workspace name fallback — reads the root package.json workspaces field, globs each pattern, and collects the name from each workspace's package.json. This handles package managers like bun that don't symlink all workspaces into node_modules/
  3. URL filter — skips http:// and https:// prefixed values before path checking

Example

A monorepo with this structure:

packages/ui/package.json    → { "name": "@acme/ui" }
packages/shared/package.json → { "name": "@acme/shared" }

Previously, scaffold references like @acme/ui/button or @acme/shared/types would trigger:

✗ MISSING_PATH: Referenced path does not exist: @acme/ui/button

Now they resolve correctly via the workspace name lookup.

Test plan

  • All 83 existing tests pass
  • Build succeeds
  • Tested against a real Turborepo + bun monorepo with 8 workspace packages — all @scope/* aliases now resolve correctly
  • npm packages in node_modules still resolve via require.resolve
  • URLs no longer flagged as missing paths

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 theDakshJaitly self-requested a review April 7, 2026 03:40
Copy link
Copy Markdown
Owner

@theDakshJaitly theDakshJaitly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants