Skip to content

Commit 6753c69

Browse files
committed
feat: Support ESM
1 parent 34a2d26 commit 6753c69

34 files changed

+1402
-3029
lines changed

.changeset/new-carrots-worry.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@ts-rest/core': minor
3+
'@ts-rest/express': minor
4+
'@ts-rest/nest': minor
5+
'@ts-rest/next': minor
6+
'@ts-rest/open-api': minor
7+
'@ts-rest/react-query': minor
8+
'@ts-rest/solid-query': minor
9+
---
10+
11+
Build ESM and CommonJS for improved compatibility

libs/ts-rest/core/package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "@ts-rest/core",
33
"version": "3.5.0",
44
"description": "RPC-like experience over a regular REST API, with type safe server implementations 🪄",
5-
"type": "commonjs",
65
"license": "MIT",
76
"keywords": [
87
"rpc",
@@ -18,5 +17,16 @@
1817
"type": "git",
1918
"url": "https://github.com/ts-rest/ts-rest.git",
2019
"directory": "libs/ts-rest/core"
20+
},
21+
"peerDependenciesMeta": {
22+
"zod": {
23+
"optional": true
24+
},
25+
"tslib": {
26+
"optional": true
27+
}
28+
},
29+
"peerDependencies": {
30+
"zod": "^3.0.0"
2131
}
2232
}

libs/ts-rest/core/project.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
"projectType": "library",
55
"targets": {
66
"build": {
7-
"executor": "@nrwl/js:tsc",
7+
"executor": "@nrwl/rollup:rollup",
88
"outputs": ["{options.outputPath}"],
99
"options": {
10+
"project": "libs/ts-rest/core/package.json",
1011
"outputPath": "dist/libs/ts-rest/core",
1112
"main": "libs/ts-rest/core/src/index.ts",
1213
"tsConfig": "libs/ts-rest/core/tsconfig.lib.json",
13-
"assets": ["libs/ts-rest/core/*.md"]
14+
"format": ["esm", "cjs"],
15+
"compiler": "tsc"
1416
}
1517
},
1618
"publish": {

libs/ts-rest/core/src/lib/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
import { HTTPStatusCode } from './status-codes';
99
import { Without, ZodInferOrType } from './type-utils';
1010

11+
12+
1113
type RecursiveProxyObj<T extends AppRouter> = {
1214
[TKey in keyof T]: T[TKey] extends AppRoute
1315
? DataReturn<T[TKey]>

libs/ts-rest/express/package.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
{
22
"name": "@ts-rest/express",
33
"version": "3.5.0",
4-
"type": "commonjs"
4+
"peerDependenciesMeta": {
5+
"zod": {
6+
"optional": true
7+
},
8+
"@swc/helpers": {
9+
"optional": true
10+
}
11+
},
12+
"peerDependencies": {
13+
"express": "^4.17.0",
14+
"zod": "^3.0.0"
15+
}
516
}

libs/ts-rest/express/src/lib/ts-rest-express.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IRouter, RequestHandler } from 'express';
1+
import { IRouter, Request, Response } from 'express';
22
import { IncomingHttpHeaders } from 'http';
33
import {
44
AppRoute,
@@ -110,12 +110,10 @@ const transformAppRouteQueryImplementation = (
110110
});
111111
}
112112

113-
const result = await route({
113+
const result = await route({ // @ts-ignore
114114
params: req.params,
115115
query: req.query,
116116
headers: req.headers,
117-
118-
// @ts-expect-error because the decorator shape is any
119117
req: req,
120118
});
121119

@@ -133,7 +131,7 @@ const transformAppRouteMutationImplementation = (
133131

134132
const method = schema.method;
135133

136-
const callback: RequestHandler = async (req, res) => {
134+
const callback = async (req: Request, res: Response) => {
137135
try {
138136
const zodBodyIssues = returnZodErrorsIfZodSchema(schema.body, req.body);
139137

@@ -155,6 +153,8 @@ const transformAppRouteMutationImplementation = (
155153
}
156154

157155
const result = await route({
156+
157+
// @ts-ignore
158158
params: req.params,
159159
body: req.body,
160160
query: req.query,
@@ -165,7 +165,6 @@ const transformAppRouteMutationImplementation = (
165165
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
166166
// @ts-ignore
167167
file: req.file,
168-
// @ts-expect-error because the decorator shape is any
169168
req: req,
170169
});
171170

@@ -189,9 +188,6 @@ const transformAppRouteMutationImplementation = (
189188
case 'PATCH':
190189
app.patch(schema.path, callback);
191190
break;
192-
default:
193-
// eslint-disable-next-line no-case-declarations, @typescript-eslint/no-unused-vars
194-
const _exhaustiveCheck: never = method;
195191
}
196192
};
197193

libs/ts-rest/nest/.lib.swcrc

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

libs/ts-rest/nest/package.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "@ts-rest/nest",
33
"version": "3.5.0",
44
"description": "Nest server integration for @ts-rest",
5-
"type": "commonjs",
65
"license": "MIT",
76
"keywords": [
87
"rpc",
@@ -19,5 +18,17 @@
1918
"type": "git",
2019
"url": "https://github.com/ts-rest/ts-rest.git",
2120
"directory": "libs/ts-rest/nest"
21+
},
22+
"peerDependenciesMeta": {
23+
"zod": {
24+
"optional": true
25+
},
26+
"rxjs": {
27+
"optional": true
28+
}
29+
},
30+
"peerDependencies": {
31+
"@nestjs/common": "^9.0.0",
32+
"rxjs": "^7.0.0"
2233
}
2334
}

libs/ts-rest/nest/project.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
"projectType": "library",
55
"targets": {
66
"build": {
7-
"executor": "@nrwl/js:swc",
7+
"executor": "@nrwl/rollup:rollup",
88
"outputs": ["{options.outputPath}"],
99
"options": {
10+
"project": "libs/ts-rest/nest/package.json",
1011
"outputPath": "dist/libs/ts-rest/nest",
1112
"main": "libs/ts-rest/nest/src/index.ts",
1213
"tsConfig": "libs/ts-rest/nest/tsconfig.lib.json",
13-
"assets": ["libs/ts-rest/nest/*.md"]
14+
"format": ["esm", "cjs"],
15+
"compiler": "tsc"
1416
}
1517
},
1618
"publish": {

libs/ts-rest/next/package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
{
22
"name": "@ts-rest/next",
33
"version": "3.5.0",
4-
"type": "commonjs"
4+
"peerDependenciesMeta": {
5+
"zod": {
6+
"optional": true
7+
},
8+
"@swc/helpers": {
9+
"optional": true
10+
}
11+
},
12+
"peerDependencies": {
13+
"next": "^12.0.0"
14+
}
515
}

0 commit comments

Comments
 (0)