Skip to content

Commit 1bf2d4d

Browse files
authored
Add CJS package (#1263)
1 parent efbc449 commit 1bf2d4d

File tree

6 files changed

+110
-90
lines changed

6 files changed

+110
-90
lines changed

.changeset/long-poems-study.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"openapi-typescript": minor
3+
---
4+
5+
Ship CJS bundle

packages/openapi-fetch/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
},
6060
"devDependencies": {
6161
"del-cli": "^5.0.0",
62-
"esbuild": "^0.18.16",
62+
"esbuild": "^0.18.17",
6363
"nanostores": "^0.9.3",
6464
"openapi-typescript": "*",
6565
"prettier": "^2.8.8",
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
examples/
2+
scripts/
3+
test/
4+
vitest.config.ts

packages/openapi-typescript/package.json

+11-6
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
},
1313
"type": "module",
1414
"main": "./dist/index.js",
15-
"files": [
16-
"bin",
17-
"dist",
18-
"src"
19-
],
15+
"exports": {
16+
".": {
17+
"import": "./dist/index.js",
18+
"require": "./dist/index.cjs"
19+
},
20+
"./*": "./*"
21+
},
2022
"homepage": "https://openapi-ts.pages.dev",
2123
"repository": {
2224
"type": "git",
@@ -38,7 +40,9 @@
3840
"url": "https://github.com/drwpow/openapi-typescript/issues"
3941
},
4042
"scripts": {
41-
"build": "del dist && tsc -p tsconfig.build.json",
43+
"build": "run-s -s build:*",
44+
"build:esm": "tsc -p tsconfig.build.json",
45+
"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;\"",
4246
"dev": "tsc -p tsconfig.build.json --watch",
4347
"download:schemas": "vite-node ./scripts/download-schemas.ts",
4448
"format": "prettier --write \"src/**/*\"",
@@ -67,6 +71,7 @@
6771
"@types/node": "^20.4.0",
6872
"degit": "^2.8.4",
6973
"del-cli": "^5.0.0",
74+
"esbuild": "^0.18.17",
7075
"execa": "^6.1.0",
7176
"vite": "^4.4.1",
7277
"vite-node": "^0.33.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const fs = require('node:fs');
2+
const openapiTS = require('../dist/index.cjs');
3+
const yaml = require('js-yaml');
4+
5+
describe('CJS bundle', () => {
6+
it('basic', async () => {
7+
const input = yaml.load(fs.readFileSync(new URL('../examples/stripe-api.yaml', import.meta.url), 'utf8'));
8+
const output = await openapiTS(input);
9+
expect(output).toBe(fs.readFileSync(new URL('../examples/stripe-api.ts', import.meta.url), 'utf8'));
10+
})
11+
})

0 commit comments

Comments
 (0)