-
-
Notifications
You must be signed in to change notification settings - Fork 528
Export CJS bundle #1263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export CJS bundle #1263
Conversation
🦋 Changeset detectedLatest commit: ebb44e8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Deploying with
|
Latest commit: |
ebb44e8
|
Status: | ✅ Deploy successful! |
Preview URL: | https://cdbd5aa2.openapi-ts.pages.dev |
Branch Preview URL: | https://cjs-export.openapi-ts.pages.dev |
"build": "del dist && tsc -p tsconfig.build.json", | ||
"build": "run-s -s build:*", | ||
"build:esm": "tsc -p tsconfig.build.json", | ||
"build:cjs": "esbuild --bundle --platform=node --target=es2019 --outfile=dist/index.cjs src/index.ts --footer:js=\"module.exports = module.exports.default;\"", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With dist/index.cjs
, the hope is that this will just shadow TypeScript types generated for dist/index.js
. But we’ll see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the --footer:js
is a hack to get rid of require(…).default
without affecting the ESM package.
I spent some time trying to bundle with Rollup, but it turned out to be far more complex, and the end result still required similar hacks (just more in number)
"build": "del dist && tsc -p tsconfig.build.json", | ||
"build": "run-s -s build:*", | ||
"build:esm": "tsc -p tsconfig.build.json", | ||
"build:cjs": "esbuild --bundle --platform=node --target=es2019 --outfile=dist/index.cjs --external:js-yaml --external:undici src/index.ts --footer:js=\"module.exports = module.exports.default;\"", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
js-yaml
and undici
are still external because they seemed to pose no problems. Should reduce weirdness without being difficult.
The other deps are ESM, but are tiny, so inlining feels right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 Probably also need to remove undici
, but that will wait until we drop Node 16 support on Sep 11, 2023, as removing undici would require Node 18+. Though there are probably a few Node 16 bugs already that make upgrading worth it, I don’t want to draw a hard line in the sand right here and now
I think some situations (I can't isolate yet) do not pick up the types with this change. |
Changes
Addresses #888. Exports a CJS bundle for
openapi-typescript
. Does so via package.jsonexports
so it requires a fairly-modern version of Node (but all current supported versions do).Bundles via esbuild to gloss over complexities of CJS vs ESM deep imports for dependencies. Since all the dependencies are tiny, the bundle isn’t too bad
How to Review
Tests should pass
Checklist
docs/
updated (if necessary)pnpm run update:examples
run (only applicable for openapi-typescript)