Repository navigation
build(esm): migrate action and test suite to ESM - #74
Merged
Merged
Conversation
The @actions/* toolkit is ESM-only at its next major -- its exports map has no "require" condition at all -- so @actions/core v3, @actions/github v9 and @actions/http-client v4 could not land individually and move together here. - package.json: "type": "module"; drop the @actions/http-client and undici overrides. The http-client pin (3.0.2) was what blocked the v4 major, and the undici pin is now redundant: http-client v4 depends on undici ^6.23.0, which resolves to the same 6.27.0 the pin forced. npm audit is clean. - tsconfig: module/moduleResolution -> nodenext; relative imports carry explicit .js extensions. - ncc now emits an ESM bundle plus a dist/package.json declaring the bundle's module type. Track it alongside dist/index.js and re-admit it in .gitignore, which #70 had narrowed to dist/index.js alone. - Jest runs in ESM mode (--experimental-vm-modules): module mocks move from jest.mock + a __mocks__ manual mock to jest.unstable_mockModule with dynamic imports, so src/__tests__/setup.ts is gone and each suite registers its own mocks. All 84 tests preserved; titles and assertion counts unchanged. Two things the migration surfaced, both invisible to the test suite: The CJS `require.main === module` entry guard does not survive bundling to ESM. ncc rewrites it to a webpack shim that evaluates false, so the bundled action loaded, exited 0, and committed nothing -- a silent no-op. Replaced with an import.meta.url/argv[1] comparison and verified by executing the bundle: it now logs and reaches the API path. Classic `moduleResolution: node` ignores exports maps, so @octokit/core/types never resolved and every octokit.rest.* call in commit.ts silently degraded to `any` -- the whole signed-commit REST flow was unchecked. nodenext restores real Octokit types and the flow type-checks clean. Also unblocks TypeScript 7, which removes moduleResolution: node outright. Closes: #49, #50, #51 Refs: #58, #54
Nothing in this repo ever ran the artifact consumers actually execute. The unit tests import main() directly, and the repo dogfoods commit-action at a pinned released SHA -- never at ./ -- so dist/index.js was never exercised. That gap is not theoretical: the ESM migration found that the CommonJS `require.main === module` entry guard does not survive bundling to ESM. The bundled action loaded, exited 0, and committed nothing, with 84 unit tests passing throughout. Run the action as a consumer does (`uses: ./`) on every PR: create a scratch branch, commit a file to it through the real createBlob -> createTree -> createCommit -> updateRef flow, then assert via the API that the commit exists, is signed, and carries the expected content. Delete the branch afterwards, on success or failure. A non-empty commit-sha output is the specific assertion that catches the silent no-op. The signature assertion keeps the action's core promise honest: the repo's "Signed commits" ruleset covers ~ALL branches, so an unsigned commit would be rejected by the API outright. Skipped on fork PRs, whose GITHUB_TOKEN is read-only and cannot create the scratch branch. Refs: #58
This was referenced Jul 14, 2026
Closed
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.
Refs #58. Closes #49, #50, #51. Unblocks #54.
The
@actions/*toolkit is ESM-only at its next major — itsexportsmap has no"require"condition at all — so@actions/corev3,@actions/githubv9 and@actions/http-clientv4 cannot land individually. They move together here.Changes
package.json—"type": "module". Dropped the@actions/http-clientandundicioverrides: thehttp-clientpin (3.0.2) was what actually blocked the v4 major, and theundicipin is now redundant, sincehttp-clientv4 depends onundici: ^6.23.0which resolves to the same6.27.0the pin was added to force.npm audit --omit=devreports 0 vulnerabilities.tsconfig.json—module/moduleResolution→nodenext; relative imports carry explicit.jsextensions.dist/index.jsplus adist/package.jsondeclaring the bundle's module type. That second file is real shipped output, so it is now tracked and re-admitted in.gitignore(which [TASK] Remove accidentally committed tsc byproducts under dist/src/ and fix the .gitignore rule #70 had just narrowed todist/index.jsalone — it would otherwise have been silently dropped).--experimental-vm-modules). Mocks move fromjest.mock+ a__mocks__manual mock tojest.unstable_mockModule+ dynamic imports;src/__tests__/setup.tsis deleted and each suite registers its own mocks. All 84 tests preserved —describe/ittitles andexpect()counts are byte-identical toHEAD, no skips.Two latent problems this surfaced — both invisible to the test suite
1. The bundled action was a silent no-op. The CJS
require.main === moduleentry guard does not survive bundling to ESM: ncc rewrites it to__nccwpck_require__.c[__nccwpck_require__.s] === module, which evaluates false. Executing that bundle:No output.
main()never ran — the action would have exited 0 having committed nothing. Replaced with an ESM guard comparingimport.meta.urlagainstpathToFileURL(process.argv[1]). Same invocation now:Nothing in CI would have caught this: unit tests import
main()directly, and the repo dogfoodscommit-actionat a pinned released SHA, so no workflow ever executes the locally-built bundle.2. The signed-commit REST flow was never type-checked. Classic
moduleResolution: nodeignoresexportsmaps, so@octokit/core/typesnever resolved and everyoctokit.rest.*call insrc/commit.tssilently degraded toany. Probe on the old config —r.data.shatyped asany; undernodenextit types asstring. The flow now type-checks clean against real Octokit types (no latent errors surfaced —commit.tswas already correct, just unverified).Verification
npm test— 84/84 passing, 3/3 suites.npx tsc --noEmit— 0 errors.npm run test:coverage— 92.5% statements / 82.1% branches, above the 70% thresholds.npm run bundle— clean ESM bundle.main()fires, reaches the API path.just precommit(full suite) — green.Not yet verified
The live REST flow against the real GitHub API (
createBlob→createTree→createCommit→updateRef) under Octokit v7 has not been exercised — only type-checked. Per the issue, unit tests are explicitly not sufficient evidence here. Worth an end-to-end run before this reaches a tag.Refs: #58