Skip to content

Convert to native ESM (vitest + oxc toolchain)#12

Merged
Marsup merged 7 commits into
hapijs:masterfrom
damusix:esm-conversion
Jul 1, 2026
Merged

Convert to native ESM (vitest + oxc toolchain)#12
Marsup merged 7 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 ("type": "module", single . export with a co-located lib/index.d.ts).
  • Swap the test/lint toolchain: @hapi/lab + @hapi/codevitest + @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-1 leaf of the hapi ESM migration, on the bourne JS-ESM archetype (source stays JS, typed by a hand-written .d.ts, 100% coverage under vitest).

One behavior-preservation fix: under ESM, V8's CallSite.getFileName() returns a file:// URL rather than a filesystem path, which would change location().filename for every caller. It is normalized back to a path with fileURLToPath, keeping the CommonJS-era contract that consumers (e.g. joi) rely on. The line-number test asserts relative deltas instead of absolute lines, since a test runner's module transform shifts raw V8 stack-frame line numbers by a constant offset.

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

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

- "type": "module"; single "." export with a co-located lib/index.d.ts;
  ship API.md + README.md in the published package
- drop the internals namespace
- engines.node >= 22; CI on the min-node-22-hapi-21 reusable workflow

Preserve the path contract: under ESM, V8's CallSite.getFileName()
returns a file:// URL, so location().filename is normalized back to a
filesystem path with fileURLToPath (matching the CommonJS output).

ESM-only — CommonJS require('@hapi/pinpoint') no longer resolves.
@damusix damusix force-pushed the esm-conversion branch 2 times, most recently from 9f05e58 to 3d05f9f Compare June 27, 2026 03:42
damusix added 2 commits June 26, 2026 23:48
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 self-assigned this Jul 1, 2026
@Marsup Marsup added the breaking changes Change that can breaking existing code label Jul 1, 2026
@Marsup Marsup added this to the 3.0.0 milestone Jul 1, 2026
@Marsup Marsup merged commit b906ec9 into hapijs:master Jul 1, 2026
12 checks passed
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