Skip to content

Commit d8f8836

Browse files
Migrating to tsdown (#2889)
Due to egoist/tsup#1332 Migration guide: https://tsdown.dev/guide/migrate-from-tsup Findings: - removes augmentation from DTS if it's not a `.d.ts` file — ~~addressed by renaming~~ addressed using banner and extra entrypoint - does not support imports without extension in config file - does not support importing JSON files without import attributes in config file — addressed by `readFile` - surprisingly keeps the import of a runtime dependency in DTS even if unused (had to patch tsup for that) - dts, cleanup and node protocol — are by default - `attw` is integrated when installed <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Switched the project to a new build tool and added corresponding build configurations; removed legacy bundler configs, patches, and related build scripts; bumped package versions and cleaned build-related dependencies. * **Tests** * Updated tests for the new build tooling and added DTS compatibility checks for TypeScript declarations. * **Notes** * No user-facing API or runtime behavior changes expected. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent d8c2fd7 commit d8f8836

24 files changed

Lines changed: 510 additions & 629 deletions

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Version 25
44

5+
### v25.3.0
6+
7+
- Changed bundler from `tsup` to `tsdown`.
8+
59
### v25.2.0
610

711
- Zod Plugin extracted into a standalone package — `@express-zod-api/zod-plugin`:

compat-test/dts.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { describe, test, expect } from "vitest";
2+
import { readFile } from "node:fs/promises";
3+
4+
describe("DTS", () => {
5+
test("Framework must import Zod plugin", async () => {
6+
const fwDts = await readFile(
7+
"./node_modules/express-zod-api/dist/index.d.ts",
8+
"utf-8",
9+
);
10+
expect(fwDts).toMatch(`import "@express-zod-api/zod-plugin";`);
11+
});
12+
13+
test("Zod plugin must import augmentation", async () => {
14+
const pluginDts = await readFile(
15+
"./node_modules/express-zod-api/node_modules/@express-zod-api/zod-plugin/dist/index.d.ts",
16+
"utf-8",
17+
);
18+
expect(pluginDts).toMatch(`import './augmentation.js';`);
19+
});
20+
21+
test("Augmentation must extend Zod", async () => {
22+
const augDts = await readFile(
23+
"./node_modules/express-zod-api/node_modules/@express-zod-api/zod-plugin/dist/augmentation.d.ts",
24+
"utf-8",
25+
);
26+
expect(augDts).toMatch(`declare module "zod"`);
27+
});
28+
});

express-zod-api/package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "express-zod-api",
3-
"version": "25.2.0",
3+
"version": "25.3.0-beta.1",
44
"description": "A Typescript framework to help you get an API server up and running with I/O schema validation and custom middlewares in minutes.",
55
"license": "MIT",
66
"repository": {
@@ -16,8 +16,7 @@
1616
"bugs": "https://github.com/RobinTail/express-zod-api/issues",
1717
"funding": "https://github.com/sponsors/RobinTail",
1818
"scripts": {
19-
"build": "tsup",
20-
"postbuild": "attw --pack --profile esm-only",
19+
"build": "tsdown",
2120
"pretest": "tsc --noEmit",
2221
"test": "vitest run --coverage",
2322
"bench": "vitest bench --run ./bench",
@@ -90,7 +89,6 @@
9089
"@types/http-errors": "catalog:dev",
9190
"@types/node-forge": "^1.3.11",
9291
"@types/ramda": "catalog:dev",
93-
"@types/semver": "^7.7.0",
9492
"camelize-ts": "catalog:dev",
9593
"compression": "catalog:dev",
9694
"cors": "^2.8.5",
@@ -99,7 +97,6 @@
9997
"express-fileupload": "catalog:dev",
10098
"http-errors": "catalog:dev",
10199
"node-forge": "^1.3.1",
102-
"semver": "^7.7.2",
103100
"snakify-ts": "^2.3.0",
104101
"typescript": "catalog:dev",
105102
"undici": "^7.10.0",

express-zod-api/src/common-helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export const isObject = (subject: unknown) =>
139139
typeof subject === "object" && subject !== null;
140140

141141
export const isProduction = R.memoizeWith(
142-
() => process.env.TSUP_STATIC as string, // eslint-disable-line no-restricted-syntax -- substituted by TSUP
142+
() => process.env.TSDOWN_STATIC as string, // eslint-disable-line no-restricted-syntax -- substituted by TSDOWN
143143
() => process.env.NODE_ENV === "production", // eslint-disable-line no-restricted-syntax -- memoized
144144
);
145145

express-zod-api/src/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const makeCommonEntities = (config: CommonConfig) => {
3232
? config.logger
3333
: new BuiltinLogger(config.logger);
3434
logger.debug("Running", {
35-
build: process.env.TSUP_BUILD || "from sources", // eslint-disable-line no-restricted-syntax -- substituted by TSUP
35+
build: process.env.TSDOWN_BUILD || "from sources", // eslint-disable-line no-restricted-syntax -- substituted by TSDOWN
3636
env: process.env.NODE_ENV || "development", // eslint-disable-line no-restricted-syntax -- intentionally for debug
3737
});
3838
installDeprecationListener(logger);

express-zod-api/tests/builtin-logger.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe("BuiltinLogger", () => {
4343
test.each(["development", "production"])(
4444
"Level can be omitted and depends on env",
4545
(mode) => {
46-
vi.stubEnv("TSUP_STATIC", mode);
46+
vi.stubEnv("TSDOWN_STATIC", mode);
4747
vi.stubEnv("NODE_ENV", mode);
4848
const { logger } = makeLogger();
4949
expect(logger["config"]["level"]).toBe(

express-zod-api/tests/last-resort.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe("Last Resort Handler", () => {
1010

1111
describe.each(["development", "production"])("%s mode", (mode) => {
1212
beforeAll(() => {
13-
vi.stubEnv("TSUP_STATIC", mode);
13+
vi.stubEnv("TSDOWN_STATIC", mode);
1414
vi.stubEnv("NODE_ENV", mode);
1515
});
1616
afterAll(() => vi.unstubAllEnvs());

express-zod-api/tests/result-helpers.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ describe("Result helpers", () => {
116116
"getPublicErrorMessage() in %s mode",
117117
(mode) => {
118118
beforeAll(() => {
119-
vi.stubEnv("TSUP_STATIC", mode);
119+
vi.stubEnv("TSDOWN_STATIC", mode);
120120
vi.stubEnv("NODE_ENV", mode);
121121
});
122122
afterAll(() => vi.unstubAllEnvs());

express-zod-api/tests/system.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { givePort } from "../../tools/ports";
1818
import { setTimeout } from "node:timers/promises";
1919

2020
describe("App in production mode", async () => {
21-
vi.stubEnv("TSUP_STATIC", "production");
21+
vi.stubEnv("TSDOWN_STATIC", "production");
2222
vi.stubEnv("NODE_ENV", "production");
2323
const port = givePort();
2424
const logger = new BuiltinLogger({ level: "silent" });

express-zod-api/tsdown.config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { defineConfig } from "tsdown";
2+
import { readFile } from "node:fs/promises";
3+
4+
const { version } = JSON.parse(await readFile("./package.json", "utf8"));
5+
6+
export default defineConfig({
7+
entry: "src/index.ts",
8+
minify: true,
9+
attw: { profile: "esmOnly", level: "error" },
10+
define: {
11+
"process.env.TSDOWN_BUILD": `"v${version}"`, // @since v25.0.0 is pure ESM
12+
"process.env.TSDOWN_STATIC": `"static"`, // used by isProduction()
13+
},
14+
});

0 commit comments

Comments
 (0)