Skip to content

Publish ESM and CommonJS runtime artifacts - #58

Merged
zth merged 1 commit into
mainfrom
agent/dual-module-runtime
Aug 5, 2026
Merged

Publish ESM and CommonJS runtime artifacts#58
zth merged 1 commit into
mainfrom
agent/dual-module-runtime

Conversation

@zth

@zth zth commented Aug 5, 2026

Copy link
Copy Markdown
Owner

What

  • compile and publish ResGraph runtime modules as both ESM (.mjs) and CommonJS (.js)
  • require ReScript 12.3+, whose runtime correctly marks CommonJS helpers
  • add a package regression test that loads both formats and verifies both are included in the npm tarball
  • prepare the 1.3.3 release and run the package check in release CI

Why

ReScript CommonJS consumers generate imports such as resgraph/src/res/ResGraph.js. ResGraph 1.3.2 only published .mjs, so production-only installs crash at startup when generated authorization code loads the missing .js runtime.

Impact

This is additive for existing ESM users. CommonJS consumers can now load generated ResGraph runtime imports. The minimum supported ReScript version becomes 12.3.0.

Tests

  • npm run build
  • npm run test:package
  • opam exec -- make test
  • authored-file git diff --check

@zth
zth marked this pull request as ready for review August 5, 2026 10:43
@zth
zth merged commit 2470474 into main Aug 5, 2026
5 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4be16ca1e6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/res/DataLoader.js
// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';

let Dataloader = require("dataloader").default;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Use DataLoader's CommonJS export directly

CommonJS consumers that use the published DataLoader.js runtime still fail once makeSingle/makeBatched constructs the loader: dataloader@2.x exposes the constructor as module.exports, so require("dataloader").default is undefined and new Dataloader(...) throws TypeError: Dataloader is not a constructor. The ESM build worked because ESM maps a CJS module.exports value to the default import, but this CJS artifact needs to require the value itself or otherwise unwrap both shapes.

Useful? React with 👍 / 👎.

// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';

let GraphqlRelayConnectionsMjs = require("./graphqlRelayConnections.mjs");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Don't require ESM helpers from CJS runtime files

On supported Node versions before require(esm) is enabled by default, such as Node 20.11–20.18 under the package's >=20.11.0 engine, loading this CommonJS runtime module throws at startup because it synchronously require()s a .mjs helper. The same pattern appears in ResGraph__Utils.js and DataLoader.js, so CommonJS consumers using connections, base64 utilities, or data loaders are still broken unless the helpers also have CJS outputs or the supported Node range is raised.

Useful? React with 👍 / 👎.

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