Skip to content

Conversation

@christopher-buss
Copy link

Summary

This PR adds proper ES Module (ESM) support to the WASM package while maintaining full backwards compatibility with CommonJS. The package now works seamlessly in both module systems without requiring any changes from existing users.

Changes

  • Dual module support: The package now generates both .cjs (CommonJS) and .mjs (ESM) files from a single source
  • Build process improvements: Updated the build script to use Rollup for generating both module formats
  • Simplified exports: Uses standard Node.js export conditions (require/import) that work across all environments
  • Type definitions: Single TypeScript definition file that works for both module systems

Technical Details

The implementation uses Rollup to transform a single ESM source file into both CommonJS and ESM outputs. This ensures consistency between the two formats and reduces maintenance burden. The WASM module is automatically initialized when imported, making the API identical for both module systems.

- Add dual package support (ESM and CommonJS)
- Update exports configuration for proper module resolution
- Add rollup build process for generating .cjs and .mjs files
- Add type definitions for both module formats
- Update build script to generate both module formats

This enables the package to be used in both ESM and CommonJS environments.
- Remove bundler-specific JS files (stylua_lib_bundler.js, stylua_lib_bundler_wbg.cjs)
- Remove extra type definition files (.d.cts, .d.mts, bundler.d.ts)
- Clean up package.json files array and remove browser field
- Update sideEffects to include the actual generated files

The simpler exports configuration handles all environments correctly without
needing separate bundler files or multiple type definitions.
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.

1 participant