Repository navigation
Add ESM support - #17
Merged
Merged
Conversation
Replace `export =` syntax with `export default` named functions in index.ts and pattern-to-tree.ts, enabling compatibility with both CJS and ESM module systems. Closes #12 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace tsc with tsdown to generate both CJS and ESM outputs with type declarations. Update package.json with exports map, module field, and proper entry points for both module systems. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add test projects that verify the package works correctly when consumed via both require() and import, runnable with yarn test:integration. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Show both ESM and CJS import styles and remove the CommonJS-only note now that ESM is supported. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Run yarn test:integration in both test-and-build and publish workflows to verify CJS and ESM compatibility on every push and release. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
lfbittencourt
commented
Mar 27, 2026
| const parser = new Parser(); | ||
|
|
||
| export = (pattern: string) => { | ||
| export default function patternToTree(pattern: string) { |
Owner
Author
There was a problem hiding this comment.
Can we type the function's return?
Owner
Author
There was a problem hiding this comment.
Claude here — fixed in 1bd7786. Added LogicalChild as the explicit return type.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds first-class ESM support by switching the library’s public export to export default, generating dual CJS/ESM builds, and validating consumption via integration tests.
Changes:
- Swap
export =entrypoints toexport defaultfor ESM compatibility. - Replace
tscbuild withtsdownto emit CJS/ESM outputs plus declaration files. - Add an
exportsmap and integration tests to verify bothrequire()andimportusage.
Reviewed changes
Copilot reviewed 10 out of 13 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
package.json |
Switch build tool to tsdown, add exports map + dual entry fields, add integration test script. |
tsdown.config.ts |
Configure tsdown to emit CJS + ESM and generate d.ts outputs into dist/. |
src/index.ts |
Change package entrypoint to export default function. |
src/pattern-to-tree.ts |
Convert module export style to export default function. |
tests/integration/package.json |
Add an integration test workspace that installs the package via file:../... |
tests/integration/yarn.lock |
Lockfile for the integration test workspace. |
tests/integration/cjs/index.cjs |
Runtime integration test for CommonJS consumption (require). |
tests/integration/esm/index.mjs |
Runtime integration test for ESM consumption (import). |
.github/workflows/test-and-build.yml |
Run integration tests in CI. |
.github/workflows/publish.yml |
Run integration tests before publishing. |
README.md |
Update usage docs to show ESM import alongside CJS require. |
.gitignore |
Ignore nested node_modules/ (including under integration tests). |
yarn.lock |
Add tsdown and its transitive dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Avoid showing both import styles in one code block, which would not run if copy-pasted. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Prevent silent rewrites of tests/integration/yarn.lock for deterministic CI runs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Lead with a complete ESM example and mention CJS as an alternative, so each block is self-explanatory. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
export =toexport defaultfor ESM compatibilitytscwithtsdownto produce dual CJS (.cjs) and ESM (.mjs) builds with type declarationsexportsmap,module, andtypesfields topackage.jsonyarn test:integration)Closes #12
Test plan
yarn lintpassesyarn test— all 34 unit tests passyarn test:integration— both CJS and ESM consumption work🤖 Generated with Claude Code