judge: fix cac load#1158
Conversation
Resolves hydro-dev#1154.
WalkthroughThis pull request fixes a single-line bug in the hydrojudge CLI entry point. The initialization chain for the Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/hydrojudge/bin/hydrojudge.js`:
- Line 3: The current call uses require('cac').cac() which fails with cac 7
because the module exports the caf function directly; update the code that sets
argv (the expression using require('cac').cac()) to call the default export
instead: either change to require('cac')().parse() for CommonJS on Node
>=20.19.0, or migrate the file to ESM and import the default (import cac from
'cac'; const argv = cac().parse()) so argv is created from a proper cac() call.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3d1e2ec2-92cb-475a-a054-fa5e1a028af8
📒 Files selected for processing (1)
packages/hydrojudge/bin/hydrojudge.js
| #!/usr/bin/env node | ||
|
|
||
| const argv = require('cac')().cac().parse(); | ||
| const argv = require('cac').cac().parse(); |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
Does cac 7.0.0 npm package export a named cac function accessible via require('cac').cac in CommonJS?
💡 Result:
No, the cac 7.0.0 npm package does not export a named cac function accessible via require('cac').cac in CommonJS. In version 7.0.0, CAC removed its CJS build and is now ESM-only, with "type": "module" in package.json and exports pointing to./dist/index.js.[1][2] The official release notes explicitly state: "Remove CJS build. CAC is now ESM-only. If you rely on require(), either migrate to ESM imports or upgrade to Node.js ≥ 20.19.0, which supports require() for ES modules natively."[1] While Node.js >=20.19.0 allows require on ESM modules (returning the default export), it provides the default export directly as require('cac'), not as a named property.cac. All documentation and examples use import cac from 'cac' or const cli = cac(), confirming cac is the default export, with no evidence of named exports like { cac }.[3][4][5]
Citations:
- 1: https://github.com/cacjs/cac/releases/tag/v7.0.0
- 2: https://github.com/cacjs/cac/blob/master/package.json
- 3: https://npmx.dev/package/cac/v/%5E7.0.0
- 4: https://www.npmjs.com/package/cac
- 5: cacjs/cac@ace7d3d
The fix require('cac').cac() is incorrect for cac 7.0.0.
cac 7.0.0 removed its CJS build and is now ESM-only. According to the official release notes, require('cac') on Node.js ≥20.19.0 returns the default export directly—the cac function itself. There is no named cac property; accessing require('cac').cac will fail.
For CommonJS with Node ≥20.19.0, use:
const argv = require('cac')().parse();For ESM (recommended), migrate to:
import cac from 'cac';
const argv = cac().parse();🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/hydrojudge/bin/hydrojudge.js` at line 3, The current call uses
require('cac').cac() which fails with cac 7 because the module exports the caf
function directly; update the code that sets argv (the expression using
require('cac').cac()) to call the default export instead: either change to
require('cac')().parse() for CommonJS on Node >=20.19.0, or migrate the file to
ESM and import the default (import cac from 'cac'; const argv = cac().parse())
so argv is created from a proper cac() call.
Resolves #1154. Fixes 7bb29b8.
Summary by CodeRabbit