Skip to content

Commit 187989c

Browse files
authored
Build packages with unbuild to improve CJS support (openapi-ts#2310)
1 parent 3c26e04 commit 187989c

File tree

5 files changed

+32
-25
lines changed

5 files changed

+32
-25
lines changed

.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
scripts/
45
test/

bin/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import fs from "node:fs";
55
import path from "node:path";
66
import { performance } from "node:perf_hooks";
77
import parser from "yargs-parser";
8-
import openapiTS, { COMMENT_HEADER, astToString, c, error, formatTime, warn } from "../dist/index.js";
8+
import openapiTS, { COMMENT_HEADER, astToString, c, error, formatTime, warn } from "../dist/index.mjs";
99

1010
const HELP = `Usage
1111
$ openapi-typescript [input] [options]

build.config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
// Ship CommonJS-compatible bundle
10+
emitCJS: true,
11+
// Don’t bundle .js files together to more closely match old exports (can remove in next major)
12+
output: { preserveModules: true },
13+
},
14+
});

package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
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+
"import": "./dist/index.mjs",
18+
"require": "./dist/index.cjs",
19+
"default": "./dist/index.mjs"
1920
},
21+
"./*.js": "./*.mjs",
2022
"./*": "./*"
2123
},
2224
"homepage": "https://openapi-ts.dev",
@@ -40,18 +42,18 @@
4042
"url": "https://github.com/openapi-ts/openapi-typescript/issues"
4143
},
4244
"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",
45+
"build": "unbuild",
4746
"dev": "tsc -p tsconfig.build.json --watch",
4847
"download:schemas": "vite-node ./scripts/download-schemas.ts",
4948
"format": "biome format . --write",
50-
"lint": "biome check .",
51-
"test": "pnpm run \"/^test:/\"",
52-
"test:examples": "tsc -p tsconfig.examples.json --noEmit",
49+
"lint": "pnpm run lint:js && pnpm run lint:ts",
50+
"lint:js": "biome check .",
51+
"lint:ts": "tsc --noEmit",
52+
"prepack": "pnpm run build",
53+
"test": "pnpm run test:js && pnpm run test:examples && pnpm run test:exports",
5354
"test:js": "vitest run",
54-
"test:ts": "tsc --noEmit",
55+
"test:exports": "pnpm run build && attw --pack .",
56+
"test:examples": "tsc -p tsconfig.examples.json --noEmit",
5557
"update:examples": "pnpm run build && pnpm run download:schemas && vite-node ./scripts/update-examples.ts",
5658
"prepublish": "pnpm run build",
5759
"version": "pnpm run build"
@@ -60,7 +62,7 @@
6062
"typescript": "^5.x"
6163
},
6264
"dependencies": {
63-
"@redocly/openapi-core": "^1.34.2",
65+
"@redocly/openapi-core": "^1.34.3",
6466
"ansi-colors": "^4.1.3",
6567
"change-case": "^5.4.4",
6668
"parse-json": "^8.3.0",
@@ -71,11 +73,9 @@
7173
"@types/degit": "^2.8.6",
7274
"@types/js-yaml": "^4.0.9",
7375
"degit": "^2.8.4",
74-
"del-cli": "^6.0.0",
75-
"esbuild": "^0.25.0",
76-
"execa": "^9.0.0",
76+
"execa": "^9.5.3",
7777
"strip-ansi": "^7.1.0",
7878
"typescript": "^5.8.3",
79-
"vite-node": "^3.0.0"
79+
"vite-node": "^3.1.3"
8080
}
8181
}

tsconfig.build.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)