Skip to content

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

Closed
adelin-b wants to merge 1 commit into
mex-memory:mainfrom
adelin-b:fix/skip-scoped-packages-and-urls
Closed

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

Conversation

@adelin-b

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

Copy link
Copy Markdown

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

@theDakshJaitly theDakshJaitly left a comment

Copy link
Copy Markdown
Collaborator

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.

@advancedresearcharray

Copy link
Copy Markdown
Contributor

Addressed all review feedback in https://github.com/advancedresearcharray/mex/commit/72efcdf (branch fix/skip-scoped-packages-and-urls).

Changes

HIGH — pnpm workspace support

  • Added collectWorkspacePatterns() that falls back to parsing pnpm-workspace.yaml when the root package.json has no workspaces field (or it is empty).
  • Updated JSDoc to document both resolution paths.

MEDIUM — URL regex

  • Broadened URL_PATTERN to ^(?:https?|ftp|file):\/\/|^\/\/ so ftp://, file:///, and protocol-relative // URLs are skipped.

MEDIUM — createRequire anchor

  • Switched from createRequire(resolve(projectRoot, "package.json")) to createRequire(resolve(projectRoot, "noop.js")).

LOW — Tests

  • Added 4 tests covering URL skipping, package.json workspace alias resolution, pnpm-workspace.yaml resolution, and require.resolve for installed scoped packages.

All 87 tests pass; tsc --noEmit clean.

@adelin-b — could you cherry-pick or merge 72efcdf into this branch when you have a moment? I don't have push access to your fork.

@advancedresearcharray

Copy link
Copy Markdown
Contributor

Review feedback is implemented on branch fix/skip-scoped-packages-and-urls at advancedresearcharray/mex@6617ed6.

@adelin-b — to update this PR in one step, merge adelin-b/mex#1 (review fixes into your fix/skip-scoped-packages-and-urls branch). Alternatively, cherry-pick 6617ed6.

All four review items are covered:

  • pnpm pnpm-workspace.yaml fallback when package.json has no workspaces
  • broader URL filter (ftp://, file:///, protocol-relative //)
  • canonical createRequire(resolve(projectRoot, "noop.js")) anchor
  • 4 new path-checker tests (87 total passing, typecheck clean)

@advancedresearcharray

Copy link
Copy Markdown
Contributor

Updated commit (no co-author trailers): advancedresearcharray/mex@fdbb507.

Merge via adelin-b/mex#1 when ready.

@advancedresearcharray

Copy link
Copy Markdown
Contributor

All four review items are addressed in commit fdbb507 on branch fix/skip-scoped-packages-and-urls.

Review responses

HIGH — pnpm workspace support
Added collectWorkspacePatterns() that reads root package.json workspaces first, then falls back to pnpm-workspace.yaml when that field is absent or empty.

MEDIUM — URL regex
URL_PATTERN is now ^(?:https?|ftp|file):\/\/|^\/\/ so ftp://, file:///, and protocol-relative // URLs are skipped.

MEDIUM — createRequire anchor
Switched to createRequire(resolve(projectRoot, "noop.js")).

LOW — Tests
Added four path-checker tests: URL skipping, package.json workspace aliases, pnpm-workspace.yaml resolution, and require.resolve for installed scoped packages.

All 87 tests pass; tsc --noEmit clean.

Updating this PR

The fix branch lives on advancedresearcharray/mex. Because maintainer_can_modify is enabled, @theDakshJaitly you can update this PR's branch directly:

git fetch https://github.com/advancedresearcharray/mex.git fix/skip-scoped-packages-and-urls
git push https://github.com/adelin-b/mex.git FETCH_HEAD:fix/skip-scoped-packages-and-urls

Alternatively, @adelin-b can merge adelin-b/mex#1, or merge #68 which contains the same commits ready for review.

theDakshJaitly pushed a commit that referenced this pull request Jun 6, 2026
Skip URL-valued claims and resolve scoped workspace package aliases: npm/yarn/bun workspaces plus a pnpm-workspace.yaml fallback, anchored via createRequire(noop.js). Builds on #17 by adelin-b; review fixes and tests by advancedresearcharray.
@theDakshJaitly

Copy link
Copy Markdown
Collaborator

Thanks @adelin-b for the original fix here. The four review items (pnpm-workspace.yaml support, broader URL filter, canonical createRequire anchor, and tests) were all addressed and just merged as #68, which builds directly on your branch and commits. Closing this as superseded by #68 - the feature is now on main. Appreciate the contribution.

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.

3 participants