feat: support keepNames and ignoreAnnotations options of esm.sh field in package.json#1341
Conversation
… field in package.json
There was a problem hiding this comment.
Pull request overview
Adds support for package-author-controlled esbuild behaviors via the esm.sh field in package.json, specifically enabling packages to opt into preserving function/class names and ignoring side-effect annotations without requiring consumers to pass query flags.
Changes:
- Read
esm.sh.keepNamesandesm.sh.ignoreAnnotationsfrompackage.jsonand apply them to esbuild options. - Refactor bundling decision logic by replacing
isNoBundle()withshouldBundle(). - Consolidate
types/typingshandling by mappingtypingsintoTypes, and update routing/type resolution logic accordingly. - Document
esm.shconfiguration in the README.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| server/build.go | Applies keepNames / ignoreAnnotations from package.json and refactors bundling decision logic. |
| internal/npm/package_json.go | Removes Typings from the normalized struct and falls back Types to raw typings. |
| server/router.go | Drops explicit typings handling for @types/* redirects, relying on Types fallback. |
| server/build_resolver.go | Drops explicit typings handling and updates DTS resolution condition. |
| README.md | Documents esm.sh configuration options in package.json. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "keepNames": false, | ||
| // set to true to ignore side-effect annotations | ||
| "ignoreAnnotations": false |
There was a problem hiding this comment.
The example values for keepNames and ignoreAnnotations are set to false, but the inline comments describe enabling those behaviors (preserving names / ignoring annotations). This is likely to confuse users; consider setting these to true in the example (or rewording the comments to clarify these are defaults and true enables the behavior).
| "keepNames": false, | |
| // set to true to ignore side-effect annotations | |
| "ignoreAnnotations": false | |
| "keepNames": true, | |
| // set to true to ignore side-effect annotations | |
| "ignoreAnnotations": true |
| if p.Types == "" { | ||
| p.Types = a.Typings.String() | ||
| } |
There was a problem hiding this comment.
This change introduces a new behavior where typings is treated as a fallback for types by populating PackageJSON.Types when types is empty. There are existing tests in internal/npm but none covering this mapping; adding a unit test for ToNpmPackage (or PackageJSON.UnmarshalJSON) would help prevent regressions for packages that only specify typings.
esm.sh supports configuring the build options by adding the
esm.shfield to yourpackage.json:{ "name": "your-package", "esm.sh": { // disable the default bundling behavior "bundle": false, // prevent class/function names erasing "keepNames": false, // some libs maybe use wrong side-effect annotations "ignoreAnnotations": false } }close #1340