Skip to content

Add ESM support - #17

Merged
lfbittencourt merged 9 commits into
mainfrom
issue-12-esm-support
Mar 28, 2026
Merged

lfbittencourt merged 9 commits into
mainfrom
issue-12-esm-support

Conversation

@lfbittencourt

Copy link
Copy Markdown
Owner

Summary

  • Convert export = to export default for ESM compatibility
  • Replace tsc with tsdown to produce dual CJS (.cjs) and ESM (.mjs) builds with type declarations
  • Add exports map, module, and types fields to package.json
  • Add CJS and ESM integration tests (yarn test:integration)

Closes #12

Test plan

  • yarn lint passes
  • yarn test — all 34 unit tests pass
  • yarn test:integration — both CJS and ESM consumption work

🤖 Generated with Claude Code

lfbittencourt and others added 5 commits March 27, 2026 20:37
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>
Comment thread src/pattern-to-tree.ts Outdated
const parser = new Parser();

export = (pattern: string) => {
export default function patternToTree(pattern: string) {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Can we type the function's return?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Claude here — fixed in 1bd7786. Added LogicalChild as the explicit return type.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 to export default for ESM compatibility.
  • Replace tsc build with tsdown to emit CJS/ESM outputs plus declaration files.
  • Add an exports map and integration tests to verify both require() and import usage.

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.

Comment thread package.json Outdated
Comment thread .github/workflows/test-and-build.yml
Comment thread .github/workflows/publish.yml
Comment thread README.md
Comment thread package.json
lfbittencourt and others added 3 commits March 27, 2026 21:05
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>
@lfbittencourt
lfbittencourt merged commit 6b5e190 into main Mar 28, 2026
1 check passed
@lfbittencourt
lfbittencourt deleted the issue-12-esm-support branch March 28, 2026 00:18
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.

Add ESM support

2 participants