Skip to content

Commit e66b5ce

Browse files
authored
Build packages with unbuild to improve CJS support (#2310)
1 parent fb385a3 commit e66b5ce

36 files changed

+255
-572
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,23 @@
1919
"version": "pnpm run build && changeset version && pnpm i"
2020
},
2121
"devDependencies": {
22+
"@arethetypeswrong/cli": "^0.18.1",
2223
"@biomejs/biome": "^1.9.4",
2324
"@changesets/changelog-github": "^0.5.1",
2425
"@changesets/cli": "^2.29.2",
2526
"@playwright/test": "^1.52.0",
2627
"@size-limit/preset-small-lib": "^11.2.0",
2728
"@types/node": "^22.15.3",
28-
"del-cli": "^6.0.0",
2929
"prettier": "^3.5.3",
3030
"size-limit": "^11.2.0",
3131
"turbo": "^2.5.2",
3232
"typescript": "^5.8.3",
33+
"unbuild": "^3.5.0",
3334
"vitest": "^3.1.3"
3435
},
3536
"size-limit": [
3637
{
37-
"path": "packages/openapi-fetch/dist/index.min.js",
38+
"path": "packages/openapi-fetch/dist/index.mjs",
3839
"limit": "7 kB",
3940
"brotli": false
4041
}

packages/openapi-fetch/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.turbo
2+
*.config.*
23
examples
34
test
45
test-results
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineBuildConfig } from "unbuild";
2+
3+
export default defineBuildConfig({
4+
entries: ["./src/index.js"],
5+
declaration: "compatible",
6+
clean: true,
7+
sourcemap: true,
8+
rollup: {
9+
// Ship CommonJS-compatible bundle
10+
emitCJS: true,
11+
},
12+
});

packages/openapi-fetch/examples/vue-3/tsconfig.node.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"composite": true,
1212
"noEmit": true,
1313
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
14-
1514
"module": "ESNext",
1615
"moduleResolution": "Bundler",
1716
"types": ["node"]

packages/openapi-fetch/package.json

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,12 @@
88
},
99
"license": "MIT",
1010
"type": "module",
11-
"main": "./dist/index.js",
12-
"module": "./dist/index.js",
13-
"types": "./dist/index.d.ts",
11+
"main": "./dist/index.mjs",
1412
"exports": {
1513
".": {
16-
"import": {
17-
"types": "./dist/index.d.ts",
18-
"default": "./dist/index.js"
19-
},
20-
"require": {
21-
"types": "./dist/cjs/index.d.cts",
22-
"default": "./dist/cjs/index.cjs"
23-
}
14+
"import": "./dist/index.mjs",
15+
"require": "./dist/index.cjs",
16+
"default": "./dist/index.mjs"
2417
},
2518
"./*": "./*"
2619
},
@@ -47,19 +40,18 @@
4740
"svelte"
4841
],
4942
"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",
43+
"build": "unbuild",
5544
"format": "biome format . --write",
56-
"lint": "biome check .",
45+
"lint": "pnpm run lint:js && pnpm run lint:ts && pnpm run lint:ts-no-strict",
46+
"lint:js": "biome check .",
47+
"lint:ts": "tsc --noEmit",
48+
"lint:ts-no-strict": "tsc --noEmit -p test/no-strict-null-checks/tsconfig.json",
5749
"generate-types": "openapi-typescript -c test/redocly.yaml",
50+
"prepack": "pnpm run build",
5851
"pretest": "pnpm run generate-types",
59-
"test": "pnpm run \"/^test:/\"",
52+
"test": "pnpm run test:js && pnpm run test:exports",
6053
"test:js": "vitest run",
61-
"test:ts": "tsc --noEmit",
62-
"test:ts-no-strict": "tsc --noEmit -p test/no-strict-null-checks/tsconfig.json",
54+
"test:exports": "pnpm run build && attw --pack .",
6355
"test-e2e": "playwright test",
6456
"bench:js": "vitest bench",
6557
"e2e-vite-build": "vite build test/e2e/app",
@@ -71,8 +63,6 @@
7163
},
7264
"devDependencies": {
7365
"axios": "^1.9.0",
74-
"del-cli": "^6.0.0",
75-
"esbuild": "^0.25.3",
7666
"execa": "^9.5.2",
7767
"express": "^5.0.0",
7868
"feature-fetch": "^0.0.43",

packages/openapi-fetch/test/bench/index.bench.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Fetcher } from "openapi-typescript-fetch";
33
import { createApiFetchClient } from "feature-fetch";
44
import superagent from "superagent";
55
import { afterAll, bench, describe, vi } from "vitest";
6-
import createClient, { createPathBasedClient } from "../../dist/index.js";
6+
import createClient, { createPathBasedClient } from "../../dist/index.mjs";
77
import * as openapiTSCodegen from "./openapi-typescript-codegen.min.js";
88

99
const BASE_URL = "https://api.test.local";

packages/openapi-metadata/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.turbo
2+
*.config.*
23
test
34
tsconfig*.json
45
vitest.config.ts
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { defineBuildConfig } from "unbuild";
2+
3+
export default defineBuildConfig({
4+
entries: [
5+
"./src/index.ts",
6+
"./src/decorators/index.ts",
7+
"./src/metadata/index.ts",
8+
"./src/errors/index.ts",
9+
"./src/ui/index.ts",
10+
],
11+
declaration: "compatible",
12+
clean: true,
13+
sourcemap: true,
14+
rollup: {
15+
// Ship CommonJS-compatible bundle
16+
emitCJS: true,
17+
// Don’t bundle .js files together to more closely match old exports (can remove in next major)
18+
output: { preserveModules: true },
19+
},
20+
});

0 commit comments

Comments
 (0)