Fix dependency resolution: subpath imports, DTS generation, and bundle deduplication#58
Merged
titouanmathis merged 1 commit intodevelopfrom Mar 10, 2026
Conversation
…ndle deduplication - Add getPackageName/getSubpath helpers to correctly split specifiers like '@studiometa/js-toolkit/utils' into package name + subpath - Fix esm.sh URL format: version goes on package name before subpath (e.g. esm.sh/@scope/pkg@1.0/subpath instead of esm.sh/@scope/pkg/subpath@1.0) - Reject bare npm package names as source values with a warning and esm.sh fallback (source only supports local file paths/globs) - Auto-externalize import map specifiers in self-hosted bundles to prevent duplicating shared dependencies at runtime - Pass merged import map keys from the preset to PlaygroundDependenciesPlugin - Update tests to cover subpath imports, npm source rejection, and importMapKeys constructor parameter - Update README: document subpath imports, clarify source field requirements, add bundle deduplication section, remove duplicated and outdated documentation sections Closes #57 Co-authored-by: Claude <claude@anthropic.com>
Export SizeUnchanged@studiometa/playground
|
Deploying studiometa-playground with
|
| Latest commit: |
2f6994f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://cf52198e.studiometa-playground.pages.dev |
| Branch Preview URL: | https://feature--57-fix-dependency-r.studiometa-playground.pages.dev |
Merged
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #58 +/- ##
===========================================
+ Coverage 16.04% 17.82% +1.77%
===========================================
Files 53 53
Lines 916 937 +21
Branches 156 165 +9
===========================================
+ Hits 147 167 +20
- Misses 756 757 +1
Partials 13 13
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 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.
Summary
Fixes #57 — three related issues in the dependency resolution and bundling pipeline.
1. Subpath specifier handling in
resolveDependenciesProblem: For a dependency like
@studiometa/js-toolkit/utils, the version was looked up using the full specifier (not found) and the esm.sh URL was incorrectly formatted asesm.sh/@studiometa/js-toolkit/utils@3.4.3(404).Fix: Added
getPackageName()andgetSubpath()helpers that correctly split specifiers. The esm.sh URL is now formatted asesm.sh/@studiometa/js-toolkit@3.4.3/utils.2. DTS generation silently fails for npm package
sourcevaluesProblem: Using
source: "morphdom"(a bare npm package name) creates a temporary re-export entry that falls outside tsconfigincludepaths, causing tsdown to silently skip DTS generation.Fix: Bare npm package names are now rejected as
sourcevalues with a clear warning. They fall back to esm.sh resolution automatically. TheDependencyConfigtype JSDoc has been updated to clarify thatsourceonly supports local file paths/globs.3. Self-hosted bundles inline all dependencies, causing duplication
Problem: When
@studiometa/uiis self-hosted, tsdown inlines all its dependencies into the output bundle. If those same dependencies are also imported via esm.sh, the browser ends up with two separate instances.Fix: The plugin now auto-externalizes any specifier that already exists in the import map. The preset passes
Object.keys(mergedImportMap)to the plugin constructor so self-hosted bundles emitimport ... from "@studiometa/js-toolkit"instead of inlining — the browser's import map resolves it at runtime.Changes
resolve-dependencies.ts: NewgetPackageName,getSubpath,isLocalSourcehelpers; fixed esm.sh URL construction; bare npm source rejection with warningPlaygroundDependenciesPlugin.ts: NewimportMapKeysconstructor parameter; passexternalto tsdown buildplayground.tspreset: PassObject.keys(mergedImportMap)to the pluginREADME.md: Document subpath imports, clarify source field, add bundle deduplication section, remove duplicated/outdated docs