Skip to content

Convert to native ESM (vitest + oxc toolchain) - #46

Merged
Marsup merged 15 commits into
hapijs:masterfrom
damusix:esm-conversion
Oct 28, 2026
Merged

Marsup merged 15 commits into
hapijs:masterfrom
damusix:esm-conversion

Conversation

@damusix

@damusix damusix commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Convert from CommonJS to native ESM across lib/index.js, lib/encoder.js, lib/decoder.js ("type": "module", single . export).
  • Add a hand-written lib/index.d.ts — b64 previously shipped without types.
  • Swap the test/lint toolchain: @hapi/lab + @hapi/code + @hapi/eslint-plugin → vitest + @vitest/coverage-v8 + oxlint + oxfmt (shared @hapi/oxc-plugin config).
  • Raise engines.node to >= 22; move CI to the min-node-22-hapi-21 reusable workflow.

What this solves

Wave-2 package of the hapi ESM migration (deps already ESM), on the bourne JS-ESM archetype. 100% coverage preserved under vitest; the new .d.ts matches the runtime surface (decode/encode/Decoder/Encoder/base64urlEncode/base64urlDecode).

Important

The @hapi/hoek dependency is a temporary pre-publish pointer. It is set to github:damusix/hoek#wip/ts because the ESM @hapi/hoek is not on npm yet. This installs cleanly (npm builds it via hoek's prepare) and is safe because b64 uses only hoek's main export (Hoek.assert), not the per-function subpath exports. It must be repinned to a published semver range before merge/release — a git-branch dependency cannot ship to npm.

ESM-only: drops the CommonJS build (breaking for require() consumers). Version bump left to the release process.

Convert @hapi/b64 from CommonJS to native ESM and replace the
@hapi/lab + @hapi/code + @hapi/eslint-plugin toolchain with vitest +
@vitest/coverage-v8 and oxlint + oxfmt (via @hapi/oxc-plugin).

- "type": "module"; single "." export with a new hand-written
  lib/index.d.ts (b64 previously shipped untyped); ship API.md + README.md
- convert lib/index.js, lib/encoder.js, lib/decoder.js to ESM
- engines.node >= 22; CI on the min-node-22-hapi-21 reusable workflow

Depends on the ESM @hapi/hoek; while that is unpublished the dependency
points at the wip/ts branch (github:damusix/hoek#wip/ts) and must be
repinned to a published range before release.

ESM-only — CommonJS require('@hapi/b64') no longer resolves.
@damusix
damusix force-pushed the esm-conversion branch 2 times, most recently from 34f47fd to 3dd9e04 Compare June 27, 2026 03:42
damusix added 2 commits June 26, 2026 23:49
Pure rename (no content change) so the move is tracked as a rename; reference fixups follow in the next commit.
package.json exports/types -> src/index.mjs + src/index.d.mts; vitest coverage include -> src/**; test imports -> ../src/index.mjs; b64 also updates index.mjs internal re-exports.
@Marsup Marsup added this to the 7.0.0 milestone Oct 28, 2026
@Marsup Marsup self-assigned this Oct 28, 2026
@Marsup Marsup added the breaking changes Change that can breaking existing code label Oct 28, 2026
hapijs#43

Co-authored-by: geek <wpreul@gmail.com>
@Marsup
Marsup merged commit b9b1fed into hapijs:master Oct 28, 2026
12 checks passed
@Marsup Marsup mentioned this pull request Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking changes Change that can breaking existing code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants