fix(mosaic): resolve framework scripts via import.meta.url #385

Merged
jason.woltje merged 1 commits from fix/mosaic-doctor-script-resolution into main 2026-04-05 01:41:46 +00:00
Owner

Fixes #383. Root cause: resolveTool() used req.resolve('@mosaic/mosaic/package.json') but published exports only has '.', causing ERR_PACKAGE_PATH_NOT_EXPORTED. Catch swallowed it and fell back to non-existent MOSAIC_HOME path. Fix: fileURLToPath(import.meta.url) + add package.json/framework subpath exports + bump to 0.0.18.

Fixes #383. Root cause: resolveTool() used req.resolve('@mosaic/mosaic/package.json') but published exports only has '.', causing ERR_PACKAGE_PATH_NOT_EXPORTED. Catch swallowed it and fell back to non-existent MOSAIC_HOME path. Fix: fileURLToPath(import.meta.url) + add package.json/framework subpath exports + bump to 0.0.18.
jason.woltje added 1 commit 2026-04-05 01:38:28 +00:00
fix(mosaic): resolve framework scripts via import.meta.url
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/pr/ci Pipeline was successful
ef88f37b9d
Previously, resolveTool() used createRequire + req.resolve('@mosaic/mosaic/package.json')
to locate the bundled framework directory. The published package.json only exports the
root '.' subpath, so Node throws ERR_PACKAGE_PATH_NOT_EXPORTED for './package.json'. The
catch block silently swallowed this error and fell through to the MOSAIC_HOME fallback
path (~/.config/mosaic/tools/_scripts/mosaic-doctor), which does not exist on a user's
machine, causing every framework-delegated subcommand (doctor, coord, etc.) to fail with
'[mosaic] Script not found'.

Two-layer fix:
1. Replace the createRequire approach with import.meta.url-based resolution. The built
   file lives at dist/commands/launch.js, so ../../framework/tools/... always resolves to
   the bundled framework directory regardless of how the package exports field is
   configured. This is layout-stable for both the published package and local dev.
2. Add './package.json' and './framework/*' subpath exports to package.json as belt-and-
   suspenders, keeping subpath access working for any future caller.

Bump version to 0.0.18.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
jason.woltje merged commit 543388e18b into main 2026-04-05 01:41:46 +00:00
jason.woltje deleted branch fix/mosaic-doctor-script-resolution 2026-04-05 01:41:47 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mosaicstack/stack#385