Auto-detect dependency export subpaths from package.json - #75
Merged
Conversation
Introduce a `subpaths` option on `DependencyConfig` that expands a package's export subpaths automatically instead of declaring each one by hand. - esm.sh dependencies: `subpaths: true` reads the package's `exports` (disk node_modules first, npm registry fallback) and adds each subpath to the import map as its own esm.sh URL; the array form takes an explicit subset. - Local self-hosted dependencies: `subpaths: true` derives the multi-entry code-split `entries` from `exports`, collapsing `.js` export aliases onto the canonical entry to avoid duplicate chunks. Explicit `entries` still win. resolveDependencies is now async to allow the registry fallback. The demo uses `subpaths: true` for both @studiometa/js-toolkit (esm.sh) and demo-lib (local) as an end-to-end proof. Co-authored-by: Claude <claude@anthropic.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Botz34NmFLdgRgm2QJpKkZ
Co-authored-by: Claude <claude@anthropic.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Botz34NmFLdgRgm2QJpKkZ
Co-authored-by: Claude <claude@anthropic.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Botz34NmFLdgRgm2QJpKkZ
Deploying studiometa-playground with
|
| Latest commit: |
85520b4
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://c626e7d9.studiometa-playground.pages.dev |
| Branch Preview URL: | https://feat-auto-detect-subpaths.studiometa-playground.pages.dev |
|
Size Change: +1.46 kB (+2.8%) Total Size: 53.5 kB 📦 View Changed
ℹ️ View Unchanged
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #75 +/- ##
==========================================
+ Coverage 29.96% 33.95% +3.99%
==========================================
Files 55 55
Lines 1038 1128 +90
Branches 203 230 +27
==========================================
+ Hits 311 383 +72
- Misses 709 717 +8
- Partials 18 28 +10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Registering a package that exposes many export subpaths means declaring each one by hand. For esm.sh deps you have to list both
@studiometa/js-toolkitand@studiometa/js-toolkit/utils; for self-hosted deps you have to spell out every entry in theentriesmap (added in #74). This does not scale for a package like@studiometa/uiwith ~190 subpaths.Fix
Add a
subpathsoption toDependencyConfigthat auto-detects a package's export subpaths from itspackage.jsonexportsfield:esm.sh dependencies (no
source)subpaths: truereads the package'sexports— from disk (node_modules) first, falling back to the npm registry when the package is not installed locally — and adds each subpath to the import map as its own esm.sh URL. So@studiometa/js-toolkit/utilsappears automatically.subpaths: ['./utils']uses an explicit list and reads nothing.Local self-hosted dependencies (local
source)subpaths: truereads the package root'spackage.jsonexports(root derived by stripping the glob fromsource) and derives the multi-entry code-splitentries— each subpath mapped to its.tstarget. Subpaths that resolve to the same file (e.g../Fooand./Foo.js) are grouped: the non-.jskey becomes the built entry, the.jskey becomes an import-map alias to the same emitted file (avoids aFoo.js.jsfilename). Explicitentriesstill take precedence.resolveDependenciesis nowasyncto allow the registry fallback.End-to-end proof (demo)
The demo switches both dependency kinds to
subpaths: true:A new
packages/demo/lib/package.jsondeclares the localexportsmap.npm run demo:buildemitsstatic/deps/demo-lib/{index,manifest}.js(+ the sharedgreeterchunk) and an import map containing@studiometa/js-toolkit,@studiometa/js-toolkit/utils,demo-lib, anddemo-lib/manifest.Backward compatibility
Purely additive. String deps,
{ specifier },{ source },{ entry }, and explicit{ entries }forms are unchanged. Existing tests remain green.Tests
true(disk read via the real@studiometa/js-toolkit), and registry fallback (stubbedfetch).exports→ entries,.js-alias dedup (one entry, alias import-map key), explicit-entries-wins.extractSubpathKeys/resolveExportTargetunits (skip./package.json+ wildcards, resolve conditions objects).publicPathprefix alongside entry specifiers.152 tests pass (+17); lint, type-check, and
npm run buildclean.Release
Additive, backward-compatible — would ship as 0.3.12. Not published here.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Botz34NmFLdgRgm2QJpKkZ