-
-
Notifications
You must be signed in to change notification settings - Fork 539
Build packages with unbuild to improve CJS support #2310
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"openapi-fetch": minor | ||
--- | ||
|
||
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). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"openapi-react-query": minor | ||
"openapi-typescript": minor | ||
"swr-openapi": minor | ||
--- | ||
|
||
Build package with unbuild to improve CJS support |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.turbo | ||
*.config.* | ||
examples | ||
test | ||
test-results | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { defineBuildConfig } from "unbuild"; | ||
|
||
export default defineBuildConfig({ | ||
entries: ["./src/index.js"], | ||
declaration: "compatible", | ||
clean: true, | ||
sourcemap: true, | ||
rollup: { | ||
// Ship CommonJS-compatible bundle | ||
emitCJS: true, | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,19 +8,12 @@ | |
}, | ||
"license": "MIT", | ||
"type": "module", | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for |
||
"main": "./dist/index.mjs", | ||
"exports": { | ||
".": { | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/cjs/index.d.cts", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With separate |
||
"default": "./dist/cjs/index.cjs" | ||
} | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.cjs", | ||
"default": "./dist/index.mjs" | ||
}, | ||
"./*": "./*" | ||
}, | ||
|
@@ -47,19 +40,18 @@ | |
"svelte" | ||
], | ||
"scripts": { | ||
"build": "pnpm run build:clean && pnpm run build:js && pnpm run build:js-min && pnpm run build:cjs", | ||
"build:clean": "del-cli dist", | ||
"build:js": "mkdir -p dist && cp src/* dist", | ||
"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", | ||
"build:cjs": "esbuild --bundle src/index.js --format=cjs --outfile=dist/cjs/index.cjs && cp dist/index.d.ts dist/cjs/index.d.cts", | ||
"build": "unbuild", | ||
"format": "biome format . --write", | ||
"lint": "biome check .", | ||
"lint": "pnpm run lint:js && pnpm run lint:ts && pnpm run lint:ts-no-strict", | ||
"lint:js": "biome check .", | ||
"lint:ts": "tsc --noEmit", | ||
"lint:ts-no-strict": "tsc --noEmit -p test/no-strict-null-checks/tsconfig.json", | ||
"generate-types": "openapi-typescript -c test/redocly.yaml", | ||
"prepack": "pnpm run build", | ||
"pretest": "pnpm run generate-types", | ||
"test": "pnpm run \"/^test:/\"", | ||
"test": "pnpm run test:js && pnpm run test:exports", | ||
"test:js": "vitest run", | ||
"test:ts": "tsc --noEmit", | ||
"test:ts-no-strict": "tsc --noEmit -p test/no-strict-null-checks/tsconfig.json", | ||
"test:exports": "pnpm run build && attw --pack .", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really like the “are the types wrong” type tests, so added to all packages. We were also able to remove the |
||
"test-e2e": "playwright test", | ||
"bench:js": "vitest bench", | ||
"e2e-vite-build": "vite build test/e2e/app", | ||
|
@@ -71,8 +63,6 @@ | |
}, | ||
"devDependencies": { | ||
"axios": "^1.9.0", | ||
"del-cli": "^6.0.0", | ||
"esbuild": "^0.25.3", | ||
"execa": "^9.5.2", | ||
"express": "^5.0.0", | ||
"feature-fetch": "^0.0.43", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.turbo | ||
*.config.* | ||
test | ||
tsconfig*.json | ||
vitest.config.ts | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { defineBuildConfig } from "unbuild"; | ||
|
||
export default defineBuildConfig({ | ||
entries: [ | ||
"./src/index.ts", | ||
"./src/decorators/index.ts", | ||
"./src/metadata/index.ts", | ||
"./src/errors/index.ts", | ||
"./src/ui/index.ts", | ||
], | ||
declaration: "compatible", | ||
clean: true, | ||
sourcemap: true, | ||
rollup: { | ||
// Ship CommonJS-compatible bundle | ||
emitCJS: true, | ||
// Don’t bundle .js files together to more closely match old exports (can remove in next major) | ||
output: { preserveModules: true }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. openapi-metadata was already using unbuild! But adding this config just shores it up more closely with the other packages without changing output too much. |
||
}, | ||
}); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.turbo | ||
*.config.* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ignore |
||
test | ||
vitest.config.ts | ||
tsconfig*.json | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { defineBuildConfig } from "unbuild"; | ||
|
||
export default defineBuildConfig({ | ||
entries: ["./src/index.ts"], | ||
declaration: "compatible", | ||
clean: true, | ||
sourcemap: true, | ||
rollup: { | ||
// Ship CommonJS-compatible bundle | ||
emitCJS: true, | ||
}, | ||
}); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.turbo | ||
*.config.* | ||
biome.json | ||
src | ||
tsconfig*.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { defineBuildConfig } from "unbuild"; | ||
|
||
export default defineBuildConfig({ | ||
entries: ["./src/index.ts"], | ||
declaration: "compatible", | ||
clean: true, | ||
sourcemap: true, | ||
rollup: { | ||
// Ship CommonJS-compatible bundle | ||
emitCJS: true, | ||
// Don’t bundle .js files together to more closely match old exports (can remove in next major) | ||
output: { preserveModules: true }, | ||
}, | ||
}); |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": ".", | ||
"skipLibCheck": false | ||
}, | ||
"include": ["."] | ||
"include": ["src"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.turbo | ||
*.config.* | ||
examples/ | ||
scripts/ | ||
test/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { defineBuildConfig } from "unbuild"; | ||
|
||
export default defineBuildConfig({ | ||
entries: ["./src/index.ts"], | ||
declaration: "compatible", | ||
clean: true, | ||
sourcemap: true, | ||
rollup: { | ||
// Ship CommonJS-compatible bundle | ||
emitCJS: true, | ||
// Don’t bundle .js files together to more closely match old exports (can remove in next major) | ||
output: { preserveModules: true }, | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"module"
has never been standardized, but was just a common community convention—common enough it started to sneak into some bundle setups. All Node LTS versions and all bundlers I’m aware of now respect"exports"
, which means this is no longer needed."main"
is still standard. And technically it’s superceded byexports
, but we’ll just keep it around for safety. But"module"
is safe to remove at this point.