Repository navigation
Add CJS + ESM support to the TypeScript and npm package - #438
Merged
Merged
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Add CJS + ESM support to the TypeScript package
Builds on the merged lib/→TypeScript conversion (#436). Adds dual CommonJS/ESM entry points while keeping one shared runtime instance for both module modes.
What
4b20e69index.mjs— hand-written ESM wrapper:export default pemplus all 19 named re-exports (createCertificate,createCSR,CA,convert,promisified, …) pulled from the CJS bundleb0578depackage.json—exportsmap (types→types/pem.d.ts,import→index.mjs,require→dist/index.js), two-pattern./lib/*deep-import continuation,files+ lint glob updated; README## ESMsectiondd818d8test/esm.spec.js— provesimport('pem')andrequire('pem')return the same module instance (reference identity, not a copy), the full named surface, and a PEM↔DER roundtrip through the ESM entryWhy a wrapper instead of a second build
lib/pem.tsis deliberately script-form (noimport/exportstatements) so the emitted bundle has no live__esModulemarker — that's what makesimport pem from 'pem'interop work against the CJS bundle. Compiling a real ESM build would change that invariant and split the pem↔ca lazy circular dependency across two module registries. The wrapper keeps both modes on one cached module instance:config()state, theCAclass, andopensslsettings are identical whether yourequireorimport.Package resolution after this change
The
exportsmap adds one inherent side effect worth noting: previously reachable but undocumented paths (pem/dist/index.js,pem/types/*) are no longer resolvable on modern Node. Documented deep imports (pem/lib/*) continue to work — verified in probes and from an installed tarball.Verification
dist/byte-identically, API-surface equality vs the pre-conversion JS (all 6 modules structurally identical), ESM surface (default identity + 19 named re-exports), deep-import resolution probes, realnpm pack→ bare-directory install → require + import probes, and frozenness asserts (lib/,types/,yarn.lockuntouched in this range).pem/lib/cafrom a freshly installed tarball).lib/andtypes/are byte-identical to the feat: convert lib/ JavaScript to TypeScript (behavior-identical) #436 tip; diff is exactlyindex.mjs,package.json,test/esm.spec.js,README.md.