build(type-plus): drop the redundant esm/package.json marker - #666
Open
unional wants to merge 1 commit into
Open
build(type-plus): drop the redundant esm/package.json marker#666unional wants to merge 1 commit into
unional wants to merge 1 commit into
Conversation
The package root already declares `"type": "module"`, so `esm/*.js` are ESM by inheritance and the marker restated what was already true. It also became the nearest `package.json` for every ESM entry point, shadowing the root `"sideEffects": false` and costing webpack consumers tree-shaking. The `cjs/package.json` marker stays — it is what keeps Node from reading `cjs/index.js` as ESM — and now carries `"sideEffects": false` itself, since it shadows the root field for CJS consumers the same way. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019f2P5bUGxqe1niopUctKqP
🦋 Changeset detectedLatest commit: e4a3bc0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #666 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 43 43
Lines 232 232
Branches 51 51
=========================================
Hits 232 232 ☔ 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.
What
build:esmno longer runsemit-module-type-marker.mjs, soesm/package.jsonis no longer emitted.cjs/package.jsonmarker now writes{"type":"commonjs","sideEffects":false}.scripts/emit-module-type-marker.mjsdrops its two-arg form (it only ever has one job now) and its header comment is rewritten to explain whycjs/needs a marker andesm/must not have one.Why
The package root declares
"type": "module", so everything underesm/is already ESM by inheritance. Theesm/package.jsonmarker shipped in8.0.0-beta.10(e58fac6) "for symmetry" and restated what was already true.It was not free.
packages/type-plus/package.jsoncarries"sideEffects": false. Bundlers read that field from the nearestpackage.jsondescribing a module, andesm/package.jsonbecame that file for every ESM entry point — while carrying nosideEffectsfield of its own. So bundlers fell back to assuming side effects on exactly the build consumers tree-shake.Tree-shaking evidence
Built the package, symlinked it into a throwaway project, and bundled this consumer:
webpack 5.110.3,
mode: 'production',optimization.minimize: false, ESM output:esm/package.jsonWith the marker present webpack pulled in
esm/index.jsand dragged alongnominal/{index,brand,flavor,constants,nominal_match}.js,testing/{stub,test_type}.js,assertion/assert_type.jsand the rest of the barrel. Without it, onlyarray/reduce_while.jssurvives. The regression is real.One correction to the premise: rollup 4 with
@rollup/plugin-node-resolveproduced byte-identical output (522 bytes) in both configurations. Its own static side-effect analysis eliminated the unused modules regardless of thesideEffectshint, so this is a webpack-class regression, not a universal one. The changeset says so rather than overclaiming.require()regression checkThe cjs marker is load-bearing — without it Node reads
cjs/index.jsas ESM and itsrequire()calls resolve against the caller. Verified against the actual clean build output, not in theory:Both entry points resolve, and re-running the webpack test after the change reproduces the 707-byte bundle.
Verification
pnpm -w turbo build lint test— 4/4 greenpnpm --filter type-plus test:type— 5.4, 5.5, 5.6, 6.0 and latest greenpatchchangeset included (the package is inbetapre mode on the open 8.0.0 train).🤖 Generated with Claude Code
https://claude.ai/code/session_019f2P5bUGxqe1niopUctKqP