feat: Make library tree-shakable and add separate entrypoints#214
Merged
Conversation
- add sideEffects: false and move package entry/types to dist/index.js - switch Rollup to preserveModules output and keep dist/toml-patch.min.js for browser/CDN - emit per-module .d.ts files - update benchmark and JS integration test imports from dist/toml-patch.js to dist/index.js - add benchmark/check-tree-shaking.mjs
There was a problem hiding this comment.
Pull request overview
This PR updates the package’s build and public entrypoints to better support bundler tree-shaking by publishing a preserved-modules ESM build, while still shipping a separate minified browser bundle for CDN/direct browser usage.
Changes:
- Switch Rollup output to preserved ESM modules (
dist/index.js,dist/patch.js,dist/format.js) plus a separate minified bundle (dist/toml-patch.min.js). - Introduce new source entrypoints (
src/patch-entry.ts,src/format-entry.ts) and move patch implementation tosrc/patch-toml.ts. - Update docs, demos, benchmarks, and tests to use the new dist/entrypoint layout.
Reviewed changes
Copilot reviewed 27 out of 28 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/toml-document.ts | Update internal import to use the new patch module. |
| src/patch-toml.ts | New patch implementation module (replacing prior entrypoint coupling). |
| src/patch-entry.ts | New subpath entry for ./patch. |
| src/index.ts | Root entry now re-exports patch from patch-toml. |
| src/format-entry.ts | New subpath entry for ./format. |
| src/tests/validate-cst.test.ts | Update test import to new patch module. |
| src/tests/patch.test.ts | Update test import to new patch module. |
| src/tests/patch.spec-example.test.ts | Update test import to new patch module. |
| src/tests/patch.mlbs.test.ts | Update test import to new patch module. |
| src/tests/patch.mlbs.leb.test.ts | Update test import to new patch module. |
| src/tests/patch.ls.test.ts | Update test import to new patch module. |
| src/tests/inlinetablestart.test.ts | Update test import to new patch module. |
| src/tests/comment-alignment.test.ts | Update test import to new patch module. |
| src/tests/js/toml-format.test.mjs | JS integration tests now import from dist/index.js. |
| src/tests/js/toml-document.test.mjs | JS integration tests now import from dist/index.js. |
| src/tests/js/stringify.test.mjs | JS integration tests now import from dist/index.js. |
| src/tests/js/patch.test.mjs | JS integration tests now import from dist/index.js. |
| scripts/build-demo.mjs | Update demo-build script to target the new minified bundle path. |
| rollup.config.js | Produce preserved ESM modules + separate minified browser bundle. |
| README.md | Update browser/CDN usage URL to the new minified bundle path. |
| package.json | Add sideEffects:false, update types/module/exports, and add ./patch + ./format subpath exports. |
| dev_demo.html | Update local demo to import dist/toml-patch.min.js. |
| demo.html | Update demo to import the explicit unpkg minified bundle path. |
| CHANGELOG.md | Document packaging/export changes and new CDN guidance. |
| benchmark/stringify-benchmark.mjs | Update benchmark to import from dist/index.js. |
| benchmark/profile.mjs | Update profiler to import from dist/index.js. |
| benchmark/parse-benchmark.mjs | Update benchmark to import from dist/index.js. |
| benchmark/check-tree-shaking.mjs | Add script to validate tree-shaking size improvements across entrypoints. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- emit dist/toml-patch.js and dist/toml-patch.d.ts as compatibility aliases\n- keep dist/index.js as canonical entrypoint\n- mark shim as deprecated in source comments
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.
This PR is focusing on enabling tree-shaking for bundler consumers. To implement this the previous entrypoint that was minified and bundled had to be unbundled. This means that direct browser/CDN usage will have to use the following URL now to get the actual minified version of the package: https://unpkg.com/@decimalturn/toml-patch/dist/toml-patch.min.js