build: migrate to ESM and bump @actions/tool-cache to 4.x#458
Conversation
@actions/tool-cache 4.0.0 および @actions/core/io/exec 3.x は pure ESM (package.json "type":"module"、exports に require エントリなし) のため、 バージョンを上げるにはプロジェクト全体を CommonJS から ESM へ移行する 必要がある。一連の移行をまとめて行う。 - package.json: "type":"module" 化、toolkit 依存を 4.x/3.x へ更新、 src/テストで未使用の @actions/github を削除、test を experimental-vm-modules で起動 - tsconfig: module/moduleResolution を NodeNext、isolatedModules を有効化 - src: 相対 import に .js 拡張子を付与。NodeNext は CJS パッケージの サブパスにも拡張子を要求するため typed-rest-client/HttpClient を 明示拡張子付きで import - jest: ESM 化 (jest.config.mjs + ts-jest useESM)。ESM では jest.mock の 巻き上げが効かないため、テストの jest.mock を jest.unstable_mockModule + 動的 import へ書き換え。equivalence は __dirname を import.meta.url 由来へ - lib/ dist/ を ESM で再生成。ncc 0.38.4 も type:module を見て ESM 出力し、 sourcemap-register を .cjs 化、dist/package.json を生成する download/extract から /usr/local/bin・C:\SeleniumWebDrivers への配置まで 実行パスの parity は不変。lib のレガシー shell/ps1 も従来どおり残置。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ESM 移行で触れたファイルに加え、master 時点で既に prettier 非準拠だった ファイル (src/chromedriver-helper.ts, __tests__/chromedriver.ts 等) も整形し、 format-check を全面的に通過させる。整形は tsc/ncc の出力に影響しないため lib/ dist/ の再生成差分は無し。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request migrates the project to ES Modules (ESM), updating package.json, tsconfig.json, and jest.config.mjs to support ESM. Relative imports have been updated with .js extensions, and unit tests have been refactored to use jest.unstable_mockModule and dynamic imports. Feedback was provided to use cross-env in the test script to ensure cross-platform compatibility on Windows when setting NODE_OPTIONS.
| "format": "prettier --write **/*.ts", | ||
| "format-check": "prettier --check **/*.ts", | ||
| "test": "jest" | ||
| "test": "NODE_OPTIONS=--experimental-vm-modules jest" |
There was a problem hiding this comment.
On Windows platforms (such as standard cmd.exe or PowerShell), prepending environment variables directly to a command (e.g., NODE_OPTIONS=... jest) is not supported and will result in a syntax error.
To ensure the test suite can be run locally on Windows, consider using cross-env to set the environment variable in a cross-platform manner. Remember to also add cross-env to your devDependencies.
| "test": "NODE_OPTIONS=--experimental-vm-modules jest" | |
| "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest" |
|
Warning Review limit reached
More reviews will be available in 17 minutes and 48 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. 📝 WalkthroughウォークスルーこのPRはプロジェクト全体をCommonJSからES ModulesへMigrationさせます。パッケージ設定と 変更内容CommonJS から ESM への全体移行
推定レビュー労力🎯 4 (複雑) | ⏱️ ~50分 関連するPR
詩
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
CI の selenium スモークテスト (ts-node __tests__/chromedriver.ts) が ERR_MODULE_NOT_FOUND で失敗していた。プロジェクトが "type":"module" に なったことで ts-node が ESM モードで動作し、拡張子なしの CJS サブパス import `selenium-webdriver/chrome` を解決できなくなったため。 `selenium-webdriver/chrome.js` と明示する。 action 本体・build・package・jest は実 runner で既に成功しており、 この E2E ステップのみの修正。test.yml と windows.yml の両方をカバーする。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…cache # Conflicts: # dist/index.js # dist/index.js.map
`NODE_OPTIONS=--experimental-vm-modules jest` はインライン環境変数代入で、 Windows の cmd.exe では `'NODE_OPTIONS' is not recognized` となり CI が失敗 していた (jest ESM には --experimental-vm-modules が必須)。 jest 公式ドキュメント記載の `node --experimental-vm-modules node_modules/jest/bin/jest.js` 形式へ変更。環境変数プレフィックスが不要で cmd.exe/pwsh/bash すべてで動作し、新規依存 (cross-env 等) も追加しない。 `pnpm test <path>` の単体指定も従来どおり機能する。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
Bumps
@actions/tool-cachefrom2.0.2to4.0.0(and@actions/core/@actions/io/@actions/execto3.x).These releases are pure ESM —
"type": "module"with norequireentry in theirexportsmap — so a version bump alone fails at runtime withERR_REQUIRE_ESM. Migrating the project from CommonJS to ESM is therefore a hard prerequisite, and this PR does the whole migration in one shot.What changed
package.json: add"type": "module"; bump toolkit deps to4.x/3.x; drop the unused@actions/githubdependency; add@jest/globalsas a devDependency (needed for type resolution under pnpm strict + NodeNext); run the test script withNODE_OPTIONS=--experimental-vm-modules.tsconfig.json:module/moduleResolution→NodeNext; enableisolatedModules(silences ts-jest's hybrid-module warning).src/: add.jsextensions to relative imports (required by NodeNext). NodeNext also requires an explicit extension for CJS package subpaths, sotyped-rest-client/HttpClientis imported astyped-rest-client/HttpClient.js.jest.config.mjs+ ts-jestuseESM).jest.mockhoisting does not work under ESM, so every mocking test was rewritten toimport { jest } from "@jest/globals"+jest.unstable_mockModule(...)+ dynamicawait import()+jest.mocked().__dirname(equivalence test) is derived fromimport.meta.url.lib/anddist/regenerated as ESM. ncc0.38.4detectstype: moduleand emits an ESM bundle, renamessourcemap-register.js→.cjs, and generatesdist/package.json({"type":"module"}).prettier --writeapplied across all*.ts(some files were already non-conforming onmaster).Parity
Behavioral parity with the shell scripts is preserved: the install locations (
/usr/local/bin/chromedriver,C:\SeleniumWebDrivers\ChromeDriver) and the implicit PATH resolution are unchanged, and the legacylib/*.sh/*.ps1are retained as an emergency rollback option.Verification
pnpm build(tsc / NodeNext) — clean.pnpm test— 97 passed, 4 skipped (7 suites).pnpm package— ncc emits an ESMdist/index.js.pnpm format-check— all files conform.node dist/index.jsand confirmed@actions/tool-cache@4downloadTool→extractZip→ install to/usr/local/binworks (the only failure was the local sandbox'ssudo/RUNNER_TEMPconstraints, not a module issue).🤖 Generated with Claude Code
Summary by CodeRabbit
リリースノート