feat: migrated codebase to build both esm and cjs #193
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.
Overview
This PR migrates the codebase to native ECMAScript Modules (ESM) while also supporting CommonJS (CJS) builds. The update modernizes the project, improves compatibility with the latest Node.js and tooling, and ensures continued support for consumers requiring CJS.
Key Features
lib/esm
) and CJS (lib/cjs
) distributionspackage.json
with properexports
,main
, andmodule
fields for dual support"type"
in output directoriesdeps.ts
) in favor of direct importsTechnical Details
.js
extensions for local imports.scripts/write-type-package-jsons.mjs
) writes apackage.json
with the correct"type"
field to each output directory.package.json
now uses theexports
field to provide both ESM and CJS entry points, and setsmain
,module
, andtypes
accordingly.deps.ts
indirection is removed; all dependencies are now imported directly.node:
prefix for ESM compatibility.tsconfig.json
updated for ESM output, modern target, and correct module resolution.Testing Instructions
Prerequisites:
rm -rf node_modules lib && npm install
Build:
npm run build
Test:
npm test
fails for now. The test config will be updated before merging.Manual Verification:
npm run build && npm pack
then copy the absolute path of the tarball. Useyarn add
ornpm i -S
and paste the path of the tarball in your test project (Heroku CLI in this case)import { Command } from 'heroku-cli-command'
const { Command } = require('heroku-cli-command')
Expected Results:
Impact
Future Considerations