Skip to content

Commit 81c3e2a

Browse files
Merge pull request #4 from codenickycode/change-server-types-gen
Change server types gen
2 parents f908da7 + c728f1f commit 81c3e2a

File tree

10 files changed

+87
-7
lines changed

10 files changed

+87
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ repo.txt
88
/playwright-report/
99
/blob-report/
1010
/playwright/.cache/
11+
*.tsbuildinfo

client/.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.eslintrc.cjs
1+
.eslintrc.cjs
2+
src/server-types.d.ts

client/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"version": "0.0.0",
44
"type": "module",
55
"scripts": {
6-
"build": "tsc -b && vite build",
6+
"build": "pnpm run build:server-types && tsc -b && vite build",
7+
"build:server-types": "tsc -p ../server/tsconfig.shared.json --declaration --emitDeclarationOnly --outFile ./src/server-types.d.ts",
78
"build:test": "tsc -b && E2E=true vite build",
89
"deploy:stage": "pnpm wrangler pages deploy ./dist --project-name todo:rename --branch \"stage\" --commit-hash \"$GITHUB_SHA\" --commit-message \"stage deployment\"",
910
"deploy:prod": "pnpm wrangler pages deploy ./dist --project-name todo:rename",

client/src/example.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Example } from './example';
1010

1111
// Mock only the react-query hook
1212
vi.mock('@tanstack/react-query', async (importOriginal) => {
13+
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
1314
const mod = await importOriginal<typeof import('@tanstack/react-query')>();
1415
return {
1516
...mod,

client/src/example.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { Modal } from './components/ui.modal';
44
import { useQuery } from '@tanstack/react-query';
55
import { getServerUrl } from './config';
66
import { hc } from 'hono/client';
7-
import type { ServerApi } from '../../server/src/types';
87
import { useMonitor } from './services/monitor.use-monitor';
8+
import type { ServerApi } from 'types.shared';
99

1010
const serverUrl = getServerUrl();
1111

client/src/server-types.d.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
declare module "types" {
2+
import type { KVNamespace } from '@cloudflare/workers-types';
3+
import type { Context as HonoContext } from 'hono';
4+
export interface Env {
5+
ALLOWED_HOST: string;
6+
DB: KVNamespace;
7+
LOCAL_DB: KVNamespace;
8+
TEST_DB: KVNamespace;
9+
ENV: 'dev' | 'prod' | 'stage' | 'test';
10+
GITHUB_REF_NAME: string;
11+
GITHUB_SHA: string;
12+
}
13+
export type Context = HonoContext<{
14+
Bindings: Env;
15+
}>;
16+
}
17+
declare module "test" {
18+
import type { Env } from "types";
19+
export const testRoute: import("hono/hono-base").HonoBase<{
20+
Bindings: Env;
21+
}, {
22+
"/reset": {
23+
$post: {
24+
input: {};
25+
output: {};
26+
outputFormat: string;
27+
status: import("hono/utils/http-status").StatusCode;
28+
};
29+
};
30+
}, "/">;
31+
}
32+
declare module "index" {
33+
import type { Env } from "types";
34+
const app: import("hono/hono-base").HonoBase<{
35+
Bindings: Env;
36+
}, ({
37+
"*": {};
38+
} & {
39+
"/": {
40+
$get: {
41+
input: {};
42+
output: "ok";
43+
outputFormat: "text";
44+
status: 200;
45+
};
46+
};
47+
}) | import("hono/types").MergeSchemaPath<{
48+
"/reset": {
49+
$post: {
50+
input: {};
51+
output: {};
52+
outputFormat: string;
53+
status: import("hono/utils/http-status").StatusCode;
54+
};
55+
};
56+
}, "/test">, "/">;
57+
export default app;
58+
}
59+
declare module "types.shared" {
60+
import type app from "index";
61+
export type ServerApi = typeof app;
62+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "create-react-spa-cloudflare",
33
"type": "module",
4-
"version": "0.0.19",
4+
"version": "0.0.20",
55
"description": "Starter package for react spa with cloudflare pages, workers, and kv",
66
"bin": "./bin/cli.js",
77
"scripts": {

server/src/types.shared.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type app from './index';
2+
3+
export type ServerApi = typeof app;

server/src/types.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { KVNamespace } from '@cloudflare/workers-types';
22
import type { Context as HonoContext } from 'hono';
3-
import type app from './index';
43

54
export interface Env {
65
ALLOWED_HOST: string;
@@ -15,5 +14,3 @@ export interface Env {
1514
export type Context = HonoContext<{
1615
Bindings: Env;
1716
}>;
18-
19-
export type ServerApi = typeof app;

server/tsconfig.shared.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"noEmit": false,
5+
"types": [
6+
"@cloudflare/workers-types",
7+
"@cloudflare/workers-types/experimental",
8+
"@cloudflare/vitest-pool-workers"
9+
],
10+
"noUnusedLocals": true,
11+
"noUnusedParameters": true
12+
},
13+
"include": ["src/types.shared.ts"]
14+
}

0 commit comments

Comments
 (0)