perf: make the published package tree-shakeable - #1841
saurabhraghuvanshii wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (11)
Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthroughThe package now exposes conditional ESM and CommonJS entry points. ESLint rejects MUI icon barrel imports. Existing source imports use individual icon paths and explicit module bindings. ChangesModule resolution updates
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~15 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The package entry points and import migrations are ready to merge without a supported merge-blocking risk. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Consumers could not tree-shake @sistent/sistent at all. Importing one
component from 0.22.6 pulls ~14,000 modules and 14.7 MB into a webpack build,
10,775 of those modules being @mui/icons-material. In layer5.io this was the
largest single contributor to build memory.
Three causes, all fixed here:
- `module` pointed at the CommonJS build. `main` and `module` were both
`./dist/index.js`, so no bundler ever selected `dist/index.mjs`. `module`
now points at the ESM build, and an `exports` map routes `import` and
`require` to the matching build and declarations.
- There was no `sideEffects` field, so bundlers had to keep every export.
The package has no top-level side effects (no CSS imports, no global
registration), so it is now marked `sideEffects: false`.
- Six components imported icons from the `@mui/icons-material` barrel,
which re-exports ~10,800 modules. They now import by path, and a
`no-restricted-imports` rule keeps the barrel out.
Serving the ESM build exposed two imports that only worked through CJS
interop, and would have broken strict ESM consumers:
- `import jsyaml from 'js-yaml'` has no default export in js-yaml's ESM
build; now `import * as jsyaml`.
- `lodash/debounce` has no extension and lodash has no exports map, which
webpack rejects from an `.mjs` file (`fullySpecified`); now
`lodash/debounce.js`.
Measured with webpack 5, a consumer that imports only `Box`:
published 0.22.6 this change*
modules 14,132 5,288
@mui/icons-material 10,775 55
output 14.68 MB 2.27 MB
* with the matching @sistent/mui-datatables deep-import fix
(layer5io/mui-datatables), which removes the remaining barrel.
The build succeeds (ESM, CJS and declarations), all 515 tests pass, and lint
is clean. The public API is unchanged.
Not changed: `noExternal: [/^@meshery\/schemas/]` (c34bfaa) is what grew the
package from 2.3 MB in 0.18.0 to 9.3 MB in 0.18.1, but it was added to fix a
schema version mismatch in the Meshery UI, so un-bundling it needs a
maintainer decision rather than a drive-by change.
Signed-off-by: saurabhraghuvanshii <saurabhsraghuvanshi@gmail.com>
8b46a58 to
d492352
Compare
Consumers could not tree-shake @sistent/sistent at all. Importing one component from 0.22.6 pulls ~14,000 modules and 14.7 MB into a webpack build, 10,775 of those modules being @mui/icons-material. In layer5.io this was the largest single contributor to build memory.
Three causes, all fixed here:
modulepointed at the CommonJS build.mainandmodulewere both./dist/index.js, so no bundler ever selecteddist/index.mjs.modulenow points at the ESM build, and anexportsmap routesimportandrequireto the matching build and declarations.There was no
sideEffectsfield, so bundlers had to keep every export. The package has no top-level side effects (no CSS imports, no global registration), so it is now markedsideEffects: false.Six components imported icons from the
@mui/icons-materialbarrel, which re-exports ~10,800 modules. They now import by path, and ano-restricted-importsrule keeps the barrel out.Serving the ESM build exposed two imports that only worked through CJS interop, and would have broken strict ESM consumers:
import jsyaml from 'js-yaml'has no default export in js-yaml's ESM build; nowimport * as jsyaml.lodash/debouncehas no extension and lodash has no exports map, which webpack rejects from an.mjsfile (fullySpecified); nowlodash/debounce.js.Measured with webpack 5, a consumer that imports only
Box:published 0.22.6 this change*
modules 14,132 5,288
@mui/icons-material 10,775 55
output 14.68 MB 2.27 MB
The build succeeds (ESM, CJS and declarations), all 515 tests pass, and lint is clean. The public API is unchanged.
Not changed:
noExternal: [/^@meshery\/schemas/](c34bfaa) is what grew the package from 2.3 MB in 0.18.0 to 9.3 MB in 0.18.1, but it was added to fix a schema version mismatch in the Meshery UI, so un-bundling it needs a maintainer decision rather than a drive-by change.Notes for Reviewers
This PR fixes #
Signed commits
Summary by CodeRabbit
Compatibility
Maintenance