Skip to content

Commit 965d82c

Browse files
committed
Build packages with unbuild to improve CJS support
1 parent 2264d1d commit 965d82c

File tree

13 files changed

+103
-416
lines changed

13 files changed

+103
-416
lines changed

.changeset/itchy-turkeys-cheat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"openapi-fetch": minor.
3+
---
4+
5+
Build package with unbuild. Also remove the minified version (openapi-fetch is only useful in a TypeScript/bundler environment, so there’s no sense in loading it from a CDN clientside).

.changeset/shy-cars-sin.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"openapi-react-query": minor
3+
"openapi-typescript": minor
4+
"swr-openapi": minor
5+
---
6+
7+
Build package with unbuild to improve CJS support

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
"@playwright/test": "^1.52.0",
2626
"@size-limit/preset-small-lib": "^11.2.0",
2727
"@types/node": "^22.15.3",
28-
"del-cli": "^6.0.0",
2928
"prettier": "^3.5.3",
3029
"size-limit": "^11.2.0",
3130
"turbo": "^2.5.2",
3231
"typescript": "^5.8.3",
32+
"unbuild": "^3.5.0",
3333
"vitest": "^3.1.3"
3434
},
3535
"size-limit": [
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineBuildConfig } from "unbuild";
2+
3+
export default defineBuildConfig({
4+
entries: ["./src/index.ts"],
5+
declaration: "compatible",
6+
clean: true,
7+
sourcemap: true,
8+
rollup: {
9+
emitCJS: true,
10+
},
11+
});

packages/openapi-fetch/package.json

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,18 @@
4747
"svelte"
4848
],
4949
"scripts": {
50-
"build": "pnpm run build:clean && pnpm run build:js && pnpm run build:js-min && pnpm run build:cjs",
51-
"build:clean": "del-cli dist",
52-
"build:js": "mkdir -p dist && cp src/* dist",
53-
"build:js-min": "esbuild --bundle src/index.js --format=esm --minify --outfile=dist/index.min.js && cp dist/index.d.ts dist/index.min.d.ts",
54-
"build:cjs": "esbuild --bundle src/index.js --format=cjs --outfile=dist/cjs/index.cjs && cp dist/index.d.ts dist/cjs/index.d.cts",
50+
"build": "unbuild",
5551
"format": "biome format . --write",
56-
"lint": "biome check .",
52+
"lint": "pnpm run lint:js && pnpm run lint:ts && pnpm run lint:ts-no-strict",
53+
"lint:js": "biome check .",
54+
"lint:ts": "tsc --noEmit",
55+
"lint:ts-no-strict": "tsc --noEmit -p test/no-strict-null-checks/tsconfig.json",
5756
"generate-types": "openapi-typescript -c test/redocly.yaml",
57+
"prepack": "pnpm run build",
5858
"pretest": "pnpm run generate-types",
59-
"test": "pnpm run \"/^test:/\"",
59+
"test": "pnpm run test:js && pnpm run test:exports",
6060
"test:js": "vitest run",
61-
"test:ts": "tsc --noEmit",
62-
"test:ts-no-strict": "tsc --noEmit -p test/no-strict-null-checks/tsconfig.json",
61+
"test:exports": "pnpm run build && attw --pack . --ignore-rules=cjs-resolves-to-esm",
6362
"test-e2e": "playwright test",
6463
"bench:js": "vitest bench",
6564
"e2e-vite-build": "vite build test/e2e/app",
@@ -71,8 +70,6 @@
7170
},
7271
"devDependencies": {
7372
"axios": "^1.9.0",
74-
"del-cli": "^6.0.0",
75-
"esbuild": "^0.25.3",
7673
"execa": "^9.5.2",
7774
"express": "^5.0.0",
7875
"feature-fetch": "^0.0.43",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineBuildConfig } from "unbuild";
2+
3+
export default defineBuildConfig({
4+
entries: ["./src/index.ts"],
5+
declaration: "compatible",
6+
clean: true,
7+
sourcemap: true,
8+
rollup: {
9+
emitCJS: true,
10+
},
11+
});

packages/openapi-react-query/package.json

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,17 @@
4747
"tanstack"
4848
],
4949
"scripts": {
50-
"build": "pnpm run build:clean && pnpm run build:esm && pnpm run build:cjs",
51-
"build:clean": "del-cli dist",
52-
"build:esm": "tsc -p tsconfig.build.json",
53-
"build:cjs": "esbuild --bundle --platform=node --target=es2019 --outfile=dist/index.cjs --external:typescript src/index.ts",
50+
"build": "unbuild",
5451
"dev": "tsc -p tsconfig.build.json --watch",
5552
"format": "biome format . --write",
56-
"lint": "biome check .",
53+
"lint": "pnpm run lint:js && pnpm run lint:ts",
54+
"lint:js": "biome check .",
55+
"lint:ts": "tsc --noEmit",
5756
"generate-types": "openapi-typescript test/fixtures/api.yaml -o test/fixtures/api.d.ts",
58-
"pretest": "pnpm run generate-types",
59-
"test": "pnpm run \"/^test:/\"",
57+
"prepack": "pnpm run build",
58+
"test": "pnpm run generate-types && pnpm run test:js && pnpm run test:exports",
6059
"test:js": "vitest run",
61-
"test:ts": "tsc --noEmit",
60+
"test:exports": "pnpm run build && attw --pack . --ignore-rules=cjs-resolves-to-esm",
6261
"version": "pnpm run prepare && pnpm run build"
6362
},
6463
"dependencies": {
@@ -69,8 +68,6 @@
6968
"@testing-library/react": "^16.3.0",
7069
"@types/react": "18.3.21",
7170
"@vitejs/plugin-react": "^4.4.1",
72-
"del-cli": "^6.0.0",
73-
"esbuild": "^0.25.0",
7471
"execa": "^9.0.0",
7572
"msw": "^2.7.5",
7673
"openapi-fetch": "workspace:^",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineBuildConfig } from "unbuild";
2+
3+
export default defineBuildConfig({
4+
entries: ["./src/index.ts"],
5+
declaration: "compatible",
6+
clean: true,
7+
sourcemap: true,
8+
rollup: {
9+
emitCJS: true,
10+
},
11+
});

packages/openapi-typescript/package.json

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
"openapi-typescript": "bin/cli.js"
1212
},
1313
"type": "module",
14-
"main": "./dist/index.js",
14+
"main": "./dist/index.mjs",
1515
"exports": {
1616
".": {
17-
"import": "./dist/index.js",
18-
"require": "./dist/index.cjs"
17+
"require": "./dist/index.cjs",
18+
"default": "./dist/index.mjs"
1919
},
2020
"./*": "./*"
2121
},
@@ -40,17 +40,18 @@
4040
"url": "https://github.com/openapi-ts/openapi-typescript/issues"
4141
},
4242
"scripts": {
43-
"build": "pnpm run build:clean && pnpm run build:esm && pnpm run build:cjs",
44-
"build:clean": "del-cli dist",
45-
"build:esm": "tsc -p tsconfig.build.json",
46-
"build:cjs": "esbuild --bundle --platform=node --target=es2019 --outfile=dist/index.cjs --external:@redocly/ajv --external:@redocly/openapi-core --external:typescript src/index.ts",
43+
"build": "unbuild",
4744
"dev": "tsc -p tsconfig.build.json --watch",
4845
"download:schemas": "vite-node ./scripts/download-schemas.ts",
4946
"format": "biome format . --write",
50-
"lint": "biome check .",
51-
"test": "pnpm run \"/^test:/\"",
52-
"test:examples": "tsc -p tsconfig.examples.json --noEmit",
47+
"lint": "pnpm run lint:js && pnpm run lint:ts",
48+
"lint:js": "biome check .",
49+
"lint:ts": "tsc --noEmit",
50+
"prepack": "pnpm run build",
51+
"test": "pnpm run test:js && pnpm run test:examples && pnpm run test:exports",
5352
"test:js": "vitest run",
53+
"test:exports": "pnpm run build && attw --pack . --ignore-rules=cjs-resolves-to-esm",
54+
"test:examples": "tsc -p tsconfig.examples.json --noEmit",
5455
"test:ts": "tsc --noEmit",
5556
"update:examples": "pnpm run build && pnpm run download:schemas && vite-node ./scripts/update-examples.ts",
5657
"prepublish": "pnpm run build",
@@ -60,7 +61,7 @@
6061
"typescript": "^5.x"
6162
},
6263
"dependencies": {
63-
"@redocly/openapi-core": "^1.34.2",
64+
"@redocly/openapi-core": "^1.34.3",
6465
"ansi-colors": "^4.1.3",
6566
"change-case": "^5.4.4",
6667
"parse-json": "^8.3.0",
@@ -71,11 +72,9 @@
7172
"@types/degit": "^2.8.6",
7273
"@types/js-yaml": "^4.0.9",
7374
"degit": "^2.8.4",
74-
"del-cli": "^6.0.0",
75-
"esbuild": "^0.25.0",
76-
"execa": "^9.0.0",
75+
"execa": "^9.5.3",
7776
"strip-ansi": "^7.1.0",
7877
"typescript": "^5.8.3",
79-
"vite-node": "^3.0.0"
78+
"vite-node": "^3.1.3"
8079
}
8180
}

packages/swr-openapi/build.config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineBuildConfig } from "unbuild";
2+
3+
export default defineBuildConfig({
4+
entries: ["./src/index.ts"],
5+
declaration: "compatible",
6+
clean: true,
7+
sourcemap: true,
8+
rollup: {
9+
emitCJS: true,
10+
},
11+
});

packages/swr-openapi/package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@
4242
"README.md"
4343
],
4444
"scripts": {
45-
"build": "pnpm run build:clean && pnpm run build:esm",
46-
"build:clean": "del-cli dist",
47-
"build:esm": "tsc -p tsconfig.build.json",
45+
"build": "unbuild",
4846
"dev": "vitest --typecheck",
4947
"format": "biome format . --write",
50-
"lint": "biome check .",
51-
"test": "pnpm run --sequential \"/^test:/\"",
48+
"lint": "pnpm run lint:js && pnpm run lint:ts",
49+
"lint:js": "biome check .",
50+
"lint:ts": "tsc --noEmit",
51+
"prepack": "pnpm run build",
52+
"test": "pnpm run test:js && pnpm run test:exports",
5253
"test:js": "vitest run --typecheck",
53-
"test:ts": "tsc --noEmit",
5454
"test:exports": "pnpm run build && attw --pack . --ignore-rules=cjs-resolves-to-esm",
5555
"prepublish": "pnpm run build",
5656
"version": "pnpm run build"
@@ -75,7 +75,6 @@
7575
"@arethetypeswrong/cli": "^0.18.0",
7676
"@types/lodash": "^4.17.16",
7777
"@types/react": "^18.3.20",
78-
"del-cli": "^6.0.0",
7978
"husky": "^9.1.7",
8079
"lint-staged": "15.5.2",
8180
"lodash": "^4.17.21",

0 commit comments

Comments
 (0)