Conversation
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.
There was a problem hiding this comment.
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.jsonexportsmap plusindex.mjsESM wrapper for dual ESM/CJS entrypoints. - Export
StatsDas 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.
| "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\"", |
There was a problem hiding this comment.
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.
| "lint": "eslint \"./lib/**/*.js\" \"./test/**/*.js\"", | |
| "lint": "eslint \"./lib/**/*.js\" \"./test/**/*.{js,mjs}\"", |
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.
Add ESM support via
exportsfield in package.json andindex.mjswrapper, enablingimport StatsD from 'hot-shots'in ES module projects