Skip to content

Add ESM build output for graphql-ruby-client#5621

Open
mattander wants to merge 1 commit intormosolgo:masterfrom
mattander:add-esm-build-for-js-client
Open

Add ESM build output for graphql-ruby-client#5621
mattander wants to merge 1 commit intormosolgo:masterfrom
mattander:add-esm-build-for-js-client

Conversation

@mattander
Copy link
Copy Markdown

@mattander mattander commented May 6, 2026

Summary

This adds an ES module build for graphql-ruby-client while keeping the existing CommonJS build intact for current consumers.

The package now publishes:

  • existing CommonJS output through main / require
  • generated ESM output under esm/ through module / conditional import exports
  • subpath exports for sync and subscriptions modules, including .js subpaths for existing direct import users

The ESM build runs from prepack, so npm 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 test
  • npm pack --dry-run
  • node --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")'

@mattander mattander force-pushed the add-esm-build-for-js-client branch from 8dc728f to 43b111a Compare May 6, 2026 16:35
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.
@mattander mattander force-pushed the add-esm-build-for-js-client branch from 43b111a to 498b8ff Compare May 6, 2026 16:43
Copy link
Copy Markdown
Owner

@rmosolgo rmosolgo left a comment

Choose a reason for hiding this comment

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

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",
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why should these be included in the exports?

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.

2 participants