Add ESM build output for graphql-ruby-client#5621
Open
mattander wants to merge 1 commit intormosolgo:masterfrom
Open
Add ESM build output for graphql-ruby-client#5621mattander wants to merge 1 commit intormosolgo:masterfrom
mattander wants to merge 1 commit intormosolgo:masterfrom
Conversation
8dc728f to
43b111a
Compare
Generate an ESM copy of the JavaScript client during publish and expose it through conditional package exports while keeping the existing CommonJS output as the default require path. The ESM preparation step marks the generated output as module code and normalizes extensionless imports that Node's ESM resolver cannot load directly.
43b111a to
498b8ff
Compare
rmosolgo
reviewed
May 6, 2026
Owner
There was a problem hiding this comment.
Hey, thanks for contributing this improvement! I have one question about the changes below.
IIUC, I won't need to do anything extra to include these new esm files in the next release. Does that sound right to you?
One more thought: it sounds like you validated the module structure with some local scripts. Is there a way we could work this into CI? Maybe write a spec that runs those same commands?
Comment on lines
+22
to
+25
| "./CHANGELOG.md": "./CHANGELOG.md", | ||
| "./DumpPayloadExample.json": "./DumpPayloadExample.json", | ||
| "./LICENSE.md": "./LICENSE.md", | ||
| "./readme.md": "./readme.md", |
Owner
There was a problem hiding this comment.
Why should these be included in the 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.
Summary
This adds an ES module build for
graphql-ruby-clientwhile keeping the existing CommonJS build intact for current consumers.The package now publishes:
main/requireesm/throughmodule/ conditionalimportexportssyncandsubscriptionsmodules, including.jssubpaths for existing direct import usersThe ESM build runs from
prepack, sonpm pack,npm publish, and Git dependency installs generate the ESM output before packaging. The ESM preparation step also normalizes generated import specifiers that Node's ESM resolver cannot load as-is, such as extensionless relative imports and directory-style package subpaths.Why
Modern bundlers and ESM-only app setups can otherwise end up consuming the CommonJS build or needing local aliases/workarounds for imports such as
graphql-ruby-client/subscriptions/ActionCableLink.Verification
npm testnpm pack --dry-runnode --input-type=module -e 'import { sync, ActionCableLink } from "graphql-ruby-client"; console.log(typeof sync, typeof ActionCableLink)'node --input-type=module -e 'import ActionCableLink from "graphql-ruby-client/subscriptions/ActionCableLink.js"; console.log(typeof ActionCableLink)'node -e 'const ActionCableLink = require("graphql-ruby-client/subscriptions/ActionCableLink.js"); console.log(typeof ActionCableLink.default || typeof ActionCableLink)'node -e 'require.resolve("graphql-ruby-client/cli.js"); require.resolve("graphql-ruby-client/readme.md"); require.resolve("graphql-ruby-client/CHANGELOG.md"); console.log("ok")'