Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve ESM compatibility #1383

Closed
bd82 opened this issue Feb 27, 2021 · 2 comments · Fixed by #1384
Closed

improve ESM compatibility #1383

bd82 opened this issue Feb 27, 2021 · 2 comments · Fixed by #1384

Comments

@bd82
Copy link
Member

bd82 commented Feb 27, 2021

Update (released in version 8.0)

  • esm import/export syntax is now fully supported with Chevrotain, see runnable example.
  • bundled and (optionally) minified versions of the library in ESM format are now available as part of the npm package.
    • https://unpkg.com/chevrotain/lib_esm/chevrotain.mjs
    • https://unpkg.com/chevrotain/lib_esm/chevrotain.min.mjs
    • Consult the unpkg.com docs how to refer to a specific version: https://unpkg.com

This is a follow up to issues:

Current status

  • There is an ESM build in addition to the CJS build (lib_esm folder)
  • There is missing metadata in package.json making the consumption of the ESM build from pure nodejs (no TypeScript) less Intuitive (no named exports).
  • There is no ESM minified build included in the package.

Preferred Approach

A thin ESM wrapper with one a single TSC compilation output.

Current issues

I've had issues with implementing a thin ESM wrapper myself, possibly due to to how Typescript implements "exporting".

References

This was referenced Feb 27, 2021
@StoneCypher
Copy link

the easiest thing to do by far is to write modern javascript today - not an esm wrapper, but real esm output, which will also dramatically drop the size of your bundle - then use a tool like rollup or webpack to produce your old-world cjs module

here's how i do it

bd82 added a commit that referenced this issue Feb 27, 2021
- Use thin ESM wrapper for CJS output instead of double tsc compilation.
- Replace webpack with esbuild
- Add bundled versions of ESM build.

fixes #1383
bd82 added a commit that referenced this issue Feb 27, 2021
- Use thin ESM wrapper for CJS output instead of double tsc compilation.
- Replace webpack with esbuild
- Add bundled versions of ESM build.

fixes #1383
bd82 added a commit that referenced this issue Feb 27, 2021
- Use thin ESM wrapper for CJS output instead of double tsc compilation.
- Replace webpack with esbuild
- Add bundled versions of ESM build.

fixes #1383
bd82 added a commit that referenced this issue Feb 27, 2021
- Use thin ESM wrapper for CJS output instead of double tsc compilation.
- Replace webpack with esbuild
- Add bundled versions of ESM build.

fixes #1383
bd82 added a commit that referenced this issue Feb 27, 2021
- Use thin ESM wrapper for CJS output instead of double tsc compilation.
- Replace webpack with esbuild
- Add bundled versions of ESM build.

fixes #1383
bd82 added a commit that referenced this issue Feb 27, 2021
- Use thin ESM wrapper for CJS output instead of double tsc compilation.
- Replace webpack with esbuild
- Add bundled versions of ESM build.

fixes #1383
bd82 added a commit that referenced this issue Feb 27, 2021
- Use thin ESM wrapper for CJS output instead of double tsc compilation.
- Replace webpack with esbuild
- Add bundled versions of ESM build.

fixes #1383
bd82 added a commit that referenced this issue Feb 27, 2021
- Use thin ESM wrapper for CJS output instead of double tsc compilation.
- Replace webpack with esbuild
- Add bundled versions of ESM build.

fixes #1383
bd82 added a commit that referenced this issue Feb 27, 2021
- Use thin ESM wrapper for CJS output instead of double tsc compilation.
- Replace webpack with esbuild
- Add bundled versions of ESM build.

fixes #1383
bd82 added a commit that referenced this issue Feb 27, 2021
- Use thin ESM wrapper for CJS output instead of double tsc compilation.
- Replace webpack with esbuild
- Add bundled versions of ESM build.

fixes #1383
bd82 added a commit that referenced this issue Feb 27, 2021
- Use thin ESM wrapper for CJS output instead of double tsc compilation.
- Replace webpack with esbuild
- Add bundled versions of ESM build.

fixes #1383
@bd82
Copy link
Member Author

bd82 commented Feb 27, 2021

the easiest thing to do by far is to write modern javascript today - not an esm wrapper, but real esm output, which will also dramatically drop the size of your bundle - then use a tool like rollup or webpack to produce your old-world cjs module

I prefer to avoid multiple (unbundled) versions of the code inside the npm package.
Particularly as there is still an issue with package level state (#1056).

Seems like I've managed to get it working in the upcoming PR.
Just need to update the BREAKING changes notes as adding the exports property seems to be a breaking change as it prevents access any not exported files in one's package.

@bd82 bd82 changed the title esm compatibility take 2 improve ESM compatibility Feb 28, 2021
bd82 added a commit that referenced this issue Feb 28, 2021
- Use thin ESM wrapper for CJS output instead of double tsc compilation.
- Replace webpack with esbuild
- Add bundled versions of ESM build.

fixes #1383
bd82 added a commit that referenced this issue Feb 28, 2021
- Use thin ESM wrapper for CJS output instead of double tsc compilation.
- Replace webpack with esbuild
- Add bundled versions of ESM build.

fixes #1383
bd82 added a commit that referenced this issue Feb 28, 2021
- Use thin ESM wrapper for CJS output instead of double tsc compilation.
- Replace webpack with esbuild
- Add bundled versions of ESM build.

fixes #1383
bd82 added a commit that referenced this issue Feb 28, 2021
- Use thin ESM wrapper for CJS output instead of double tsc compilation.
- Replace webpack with esbuild
- Add bundled versions of ESM build.

fixes #1383
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 a pull request may close this issue.

2 participants