Skip to content

fix: load CLI version in ESM#47

Merged
dmchaledev merged 1 commit into
HailBytes:mainfrom
iccccccccccccc:fix-esm-cli-version
May 29, 2026
Merged

fix: load CLI version in ESM#47
dmchaledev merged 1 commit into
HailBytes:mainfrom
iccccccccccccc:fix-esm-cli-version

Conversation

@iccccccccccccc
Copy link
Copy Markdown
Contributor

Fixes #24

Changes

  • create a require function with createRequire(import.meta.url) for the ESM CLI
  • read package.json through that ESM-compatible require instead of relying on a missing global require
  • keep the existing 0.0.0 fallback if the package metadata cannot be read

Verification

  • npm run build
  • node dist/cli.js --version -> 1.0.1
  • node dist/cli.js --help shows @hailbytes/security-headers v1.0.1
  • npm run typecheck

I also ran npm test; it currently gets through 55/59 tests, with four existing Permissions-Policy / grade-boundary assertions failing outside this CLI version path.

@dmchaledev dmchaledev merged commit afa3364 into HailBytes:main May 29, 2026
Copy link
Copy Markdown
Contributor

Merged — thanks so much for the fix, @iccccccccccccc! 🎉

This was a real bug: with "type": "module" + NodeNext, the global require doesn't exist in the compiled dist/cli.js, so getVersion() was silently falling back to 0.0.0. Using createRequire(import.meta.url) is exactly the right approach, and the ?? '0.0.0' hardening is a nice touch.

Appreciate you also being upfront about the 4 pre-existing test failures — confirmed those are unrelated to this change and already present on main; we're tracking them separately. Thanks again for the clean, well-described PR, and welcome! 🙌


Generated by Claude Code

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.

[REVIEW] CLI: getVersion() uses require() in ESM module — --version and --help always display 0.0.0

2 participants