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.jsonwith properexports,main, andmodulefields for dual support"type"in output directoriesdeps.ts) in favor of direct importsTechnical Details
.jsextensions for local imports.scripts/write-type-package-jsons.mjs) writes apackage.jsonwith the correct"type"field to each output directory.package.jsonnow uses theexportsfield to provide both ESM and CJS entry points, and setsmain,module, andtypesaccordingly.deps.tsindirection is removed; all dependencies are now imported directly.node:prefix for ESM compatibility.tsconfig.jsonupdated for ESM output, modern target, and correct module resolution.Testing Instructions
Prerequisites:
rm -rf node_modules lib && npm installBuild:
npm run buildTest:
npm testfails for now. The test config will be updated before merging.Manual Verification:
npm run build && npm packthen copy the absolute path of the tarball. Useyarn addornpm i -Sand 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