Convert to native ESM (vitest + oxc toolchain)#12
Merged
Conversation
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.
9f05e58 to
3d05f9f
Compare
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
"type": "module", single.export with a co-locatedlib/index.d.ts).@hapi/lab+@hapi/code→vitest+@vitest/coverage-v8+oxlint+oxfmt(shared@hapi/oxc-pluginconfig).engines.nodeto>= 22; move CI to themin-node-22-hapi-21reusable workflow.What this solves
Wave-1 leaf of the hapi ESM migration, on the
bourneJS-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 afile://URL rather than a filesystem path, which would changelocation().filenamefor every caller. It is normalized back to a path withfileURLToPath, 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.