Skip to content

ESM entry point#314

Merged
bdeitte merged 7 commits intomainfrom
esm-entry-point
Apr 3, 2026
Merged

ESM entry point#314
bdeitte merged 7 commits intomainfrom
esm-entry-point

Conversation

@bdeitte
Copy link
Copy Markdown
Owner

@bdeitte bdeitte commented Mar 31, 2026

Add ESM support via exports field in package.json and index.mjs wrapper, enabling import StatsD from 'hot-shots' in ES module projects

bdeitte added 5 commits March 30, 2026 19:36
Add index.mjs as an ESM wrapper and the exports field in package.json
so that ES module consumers can use `import StatsD from 'hot-shots'`.
CJS require continues to work as before.
Add wildcard subpath export ("./*": "./*") so existing consumers
importing deep paths like hot-shots/lib/statsd.js or
hot-shots/package.json are not broken by the new exports map.

Update test script to run the ESM test in CI, and change the ESM
test to import via the package name so the exports map is exercised.
Test that deep imports with extensions (lib/statsd.js, lib/helpers.js)
and package.json remain accessible through the exports map.
Switch deep subpath assertions from createRequire() to
await import() so they actually test ESM resolution. Keep
createRequire only for package.json where JSON import
compatibility across Node 18 is a concern.

Also update CHANGES.md to use Unreleased heading.
Copilot AI review requested due to automatic review settings March 31, 2026 00:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class ES module entrypoint support for hot-shots by introducing an ESM wrapper and configuring package.json exports, enabling import StatsD from 'hot-shots' (and a named StatsD export) while keeping CommonJS behavior intact.

Changes:

  • Add package.json exports map plus index.mjs ESM wrapper for dual ESM/CJS entrypoints.
  • Export StatsD as a named export in the type definitions to match the new ESM surface.
  • Add an ESM import smoke test and document ESM usage in the README.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
types.d.ts Adds named export StatsD in typings.
test/esm-import.mjs New test validating ESM default + named import behavior and deep imports.
README.md Documents ESM import usage alongside existing CommonJS example.
package.json Adds exports map and runs the new ESM import test in npm test.
index.mjs Provides ESM entrypoint that re-exports from existing CJS entry.
CLAUDE.md Updates internal documentation to mention the ESM entrypoint and Node requirement.
CHANGES.md Records the ESM entrypoint change under “Unreleased”.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread package.json Outdated
"coverage": "nyc --reporter=lcov --reporter=text npm test",
"test": "mocha -R spec --timeout 5000 test/*.js",
"test": "mocha -R spec --timeout 5000 test/*.js && node test/esm-import.mjs",
"lint": "eslint \"./lib/**/*.js\" \"./test/**/*.js\"",
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm test now runs test/esm-import.mjs, but the lint script still only targets ./test/**/*.js, so this new test file won’t be linted (even though pretest runs lint). Consider updating the lint glob(s) to include .mjs tests to keep the same lint coverage for all executed tests.

Suggested change
"lint": "eslint \"./lib/**/*.js\" \"./test/**/*.js\"",
"lint": "eslint \"./lib/**/*.js\" \"./test/**/*.{js,mjs}\"",

Copilot uses AI. Check for mistakes.
bdeitte added 2 commits March 30, 2026 20:24
Update lint glob to cover test/*.mjs files. Add ESLint override
for .mjs files with sourceType: module and ecmaVersion 2022 to
support ES module syntax and top-level await.
Add ./*.mjs to the lint glob so index.mjs is also linted.
@bdeitte bdeitte merged commit 9daac9e into main Apr 3, 2026
11 checks passed
@bdeitte bdeitte deleted the esm-entry-point branch April 3, 2026 22:18
@marklai1998 marklai1998 mentioned this pull request Apr 6, 2026
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.

2 participants