feat: switch prettier-plugin-glsl output to ESM#45
Merged
Merged
Conversation
b66e226 to
09c660e
Compare
Fixes #44 - ESM chevrotain import error when combined with another plugin. - Change rollup output format from commonjs to es - Set package.json type to module - Update exports path to .es.js - Rename babel.config.js and jest.config.js to .cjs (they use module.exports)
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.
Fixes #44
Problem
When
prettier-plugin-glsl(CJS) is loaded alongside another ESM plugin that also importschevrotain(e.g.prettier-plugin-wgsl), Node throws:This happens because Prettier loads all plugins concurrently via
Promise.all, andchevrotainv12+ is ESM-only. When one pluginimport()s chevrotain and anotherrequire()s it simultaneously, Node hits a race condition.Solution
Switch the rollup output format from CommonJS to ESM:
format: "commonjs"→format: "es""type": "module", exports path updated to.es.jsmodule.exports)module.exports)This is safe for all current Node LTS versions — ESM has been stable (unflagged) since Node 14+, and the package already requires
>=22.0.0. Prettier 3.x natively supports ESM plugins.Testing
test-esm-compat/) that reproduces the exact issue scenario: loadingprettier-plugin-glslalongside a fake ESM chevrotain-based plugin viaPromise.all, then formatting a GLSL file. This passes cleanly with the ESM output.