Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ repo.txt
/playwright-report/
/blob-report/
/playwright/.cache/
*.tsbuildinfo
3 changes: 2 additions & 1 deletion client/.eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.eslintrc.cjs
.eslintrc.cjs
src/server-types.d.ts
3 changes: 2 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"build": "tsc -b && vite build",
"build": "pnpm run build:server-types && tsc -b && vite build",
"build:server-types": "tsc -p ../server/tsconfig.shared.json --declaration --emitDeclarationOnly --outFile ./src/server-types.d.ts",
"build:test": "tsc -b && E2E=true vite build",
"deploy:stage": "pnpm wrangler pages deploy ./dist --project-name todo:rename --branch \"stage\" --commit-hash \"$GITHUB_SHA\" --commit-message \"stage deployment\"",
"deploy:prod": "pnpm wrangler pages deploy ./dist --project-name todo:rename",
Expand Down
1 change: 1 addition & 0 deletions client/src/example.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Example } from './example';

// Mock only the react-query hook
vi.mock('@tanstack/react-query', async (importOriginal) => {
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
const mod = await importOriginal<typeof import('@tanstack/react-query')>();
return {
...mod,
Expand Down
2 changes: 1 addition & 1 deletion client/src/example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Modal } from './components/ui.modal';
import { useQuery } from '@tanstack/react-query';
import { getServerUrl } from './config';
import { hc } from 'hono/client';
import type { ServerApi } from '../../server/src/types';
import { useMonitor } from './services/monitor.use-monitor';
import type { ServerApi } from 'types.shared';

const serverUrl = getServerUrl();

Expand Down
62 changes: 62 additions & 0 deletions client/src/server-types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
declare module "types" {
import type { KVNamespace } from '@cloudflare/workers-types';
import type { Context as HonoContext } from 'hono';
export interface Env {
ALLOWED_HOST: string;
DB: KVNamespace;
LOCAL_DB: KVNamespace;
TEST_DB: KVNamespace;
ENV: 'dev' | 'prod' | 'stage' | 'test';
GITHUB_REF_NAME: string;
GITHUB_SHA: string;
}
export type Context = HonoContext<{
Bindings: Env;
}>;
}
declare module "test" {
import type { Env } from "types";
export const testRoute: import("hono/hono-base").HonoBase<{
Bindings: Env;
}, {
"/reset": {
$post: {
input: {};
output: {};
outputFormat: string;
status: import("hono/utils/http-status").StatusCode;
};
};
}, "/">;
}
declare module "index" {
import type { Env } from "types";
const app: import("hono/hono-base").HonoBase<{
Bindings: Env;
}, ({
"*": {};
} & {
"/": {
$get: {
input: {};
output: "ok";
outputFormat: "text";
status: 200;
};
};
}) | import("hono/types").MergeSchemaPath<{
"/reset": {
$post: {
input: {};
output: {};
outputFormat: string;
status: import("hono/utils/http-status").StatusCode;
};
};
}, "/test">, "/">;
export default app;
}
declare module "types.shared" {
import type app from "index";
export type ServerApi = typeof app;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "create-react-spa-cloudflare",
"type": "module",
"version": "0.0.19",
"version": "0.0.20",
"description": "Starter package for react spa with cloudflare pages, workers, and kv",
"bin": "./bin/cli.js",
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions server/src/types.shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type app from './index';

export type ServerApi = typeof app;
3 changes: 0 additions & 3 deletions server/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { KVNamespace } from '@cloudflare/workers-types';
import type { Context as HonoContext } from 'hono';
import type app from './index';

export interface Env {
ALLOWED_HOST: string;
Expand All @@ -15,5 +14,3 @@ export interface Env {
export type Context = HonoContext<{
Bindings: Env;
}>;

export type ServerApi = typeof app;
14 changes: 14 additions & 0 deletions server/tsconfig.shared.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"types": [
"@cloudflare/workers-types",
"@cloudflare/workers-types/experimental",
"@cloudflare/vitest-pool-workers"
],
"noUnusedLocals": true,
"noUnusedParameters": true
},
"include": ["src/types.shared.ts"]
}