Skip to content

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

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/long-poems-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"openapi-typescript": minor
---

Ship CJS bundle
2 changes: 1 addition & 1 deletion packages/openapi-fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"devDependencies": {
"del-cli": "^5.0.0",
"esbuild": "^0.18.16",
"esbuild": "^0.18.17",
"nanostores": "^0.9.3",
"openapi-typescript": "*",
"prettier": "^2.8.8",
Expand Down
4 changes: 4 additions & 0 deletions packages/openapi-typescript/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
examples/
scripts/
test/
vitest.config.ts
17 changes: 11 additions & 6 deletions packages/openapi-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
},
"type": "module",
"main": "./dist/index.js",
"files": [
"bin",
"dist",
"src"
],
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"./*": "./*"
},
"homepage": "https://openapi-ts.pages.dev",
"repository": {
"type": "git",
Expand All @@ -38,7 +40,9 @@
"url": "https://github.com/drwpow/openapi-typescript/issues"
},
"scripts": {
"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;\"",
Copy link
Contributor Author

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

Copy link
Contributor Author

@drwpow drwpow Jul 31, 2023

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

"dev": "tsc -p tsconfig.build.json --watch",
"download:schemas": "vite-node ./scripts/download-schemas.ts",
"format": "prettier --write \"src/**/*\"",
Expand Down Expand Up @@ -67,6 +71,7 @@
"@types/node": "^20.4.0",
"degit": "^2.8.4",
"del-cli": "^5.0.0",
"esbuild": "^0.18.17",
"execa": "^6.1.0",
"vite": "^4.4.1",
"vite-node": "^0.33.0",
Expand Down
11 changes: 11 additions & 0 deletions packages/openapi-typescript/test/cjs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fs = require('node:fs');
const openapiTS = require('../dist/index.cjs');
const yaml = require('js-yaml');

describe('CJS bundle', () => {
it('basic', async () => {
const input = yaml.load(fs.readFileSync(new URL('../examples/stripe-api.yaml', import.meta.url), 'utf8'));
const output = await openapiTS(input);
expect(output).toBe(fs.readFileSync(new URL('../examples/stripe-api.ts', import.meta.url), 'utf8'));
})
})
Loading