Skip to content

feat: support keepNames and ignoreAnnotations options of esm.sh field in package.json#1341

Merged
ije merged 2 commits into
mainfrom
esmsh-field
Apr 3, 2026
Merged

feat: support keepNames and ignoreAnnotations options of esm.sh field in package.json#1341
ije merged 2 commits into
mainfrom
esmsh-field

Conversation

@ije
Copy link
Copy Markdown
Member

@ije ije commented Apr 3, 2026

esm.sh supports configuring the build options by adding the esm.sh field to your package.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

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.keepNames and esm.sh.ignoreAnnotations from package.json and apply them to esbuild options.
  • Refactor bundling decision logic by replacing isNoBundle() with shouldBundle().
  • Consolidate types/typings handling by mapping typings into Types, and update routing/type resolution logic accordingly.
  • Document esm.sh configuration 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.

Comment thread README.md
Comment on lines +396 to +398
"keepNames": false,
// set to true to ignore side-effect annotations
"ignoreAnnotations": false
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
"keepNames": false,
// set to true to ignore side-effect annotations
"ignoreAnnotations": false
"keepNames": true,
// set to true to ignore side-effect annotations
"ignoreAnnotations": true

Copilot uses AI. Check for mistakes.
Comment on lines +188 to +190
if p.Types == "" {
p.Types = a.Typings.String()
}
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@ije ije merged commit 85207a7 into main Apr 3, 2026
5 checks passed
@ije ije deleted the esmsh-field branch April 3, 2026 01:07
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.

Set keep names to on by default (or allow package authors to specify it is necessary)

2 participants