@tbox.cn/app-template-h5 0.1.27 → 1.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/._.gitignore +0 -0
  2. package/._.npmignore +0 -0
  3. package/._.nvmrc +0 -0
  4. package/._AGENTS.md +0 -0
  5. package/._LEGAL.md +0 -0
  6. package/._LICENSE +0 -0
  7. package/._README.md +0 -0
  8. package/._eslint.config.mjs +0 -0
  9. package/._package.json +0 -0
  10. package/._pnpm-lock.template.yaml +0 -0
  11. package/._pnpm-workspace.template.yaml +0 -0
  12. package/._tsconfig.base.json +0 -0
  13. package/.gitignore +11 -7
  14. package/.npmignore +7 -0
  15. package/.tbox/._app.json +0 -0
  16. package/.tbox/app.json +3 -2
  17. package/AGENTS.md +22 -62
  18. package/README.md +20 -31
  19. package/apps/._AGENTS.md +0 -0
  20. package/apps/AGENTS.md +13 -0
  21. package/apps/client/._index.html +0 -0
  22. package/apps/client/._package.json +0 -0
  23. package/apps/client/._tsconfig.json +0 -0
  24. package/apps/client/._vite.config.ts +0 -0
  25. package/apps/client/._vitest.config.ts +0 -0
  26. package/apps/client/index.html +0 -4
  27. package/apps/client/package.json +7 -6
  28. package/apps/client/src/._app.config.ts +0 -0
  29. package/apps/client/src/._vite-env.d.ts +0 -0
  30. package/apps/client/src/app.config.ts +10 -0
  31. package/apps/client/src/pages/._page.tsx +0 -0
  32. package/apps/client/src/pages/page.tsx +37 -0
  33. package/apps/client/src/styles/._tailwind.css +0 -0
  34. package/apps/client/src/styles/tailwind.css +101 -0
  35. package/apps/client/tsconfig.json +3 -6
  36. package/apps/client/vite.config.ts +36 -39
  37. package/apps/client/vitest.config.ts +10 -0
  38. package/apps/server/._package.json +0 -0
  39. package/apps/server/._tsconfig.json +0 -0
  40. package/apps/server/._tsup.config.ts +0 -0
  41. package/apps/server/._vitest.config.ts +0 -0
  42. package/apps/server/package.json +6 -4
  43. package/apps/server/src/._app.ts +0 -0
  44. package/apps/server/src/._dev.ts +0 -0
  45. package/apps/server/src/._index.ts +0 -0
  46. package/apps/server/src/app.ts +2 -35
  47. package/apps/server/src/dev.ts +37 -123
  48. package/apps/server/src/functions/._greet.server.ts +0 -0
  49. package/apps/server/src/functions/greet.server.ts +5 -0
  50. package/apps/server/src/index.ts +17 -39
  51. package/apps/server/tests/._app.test.ts +0 -0
  52. package/apps/server/tests/app.test.ts +30 -5
  53. package/apps/server/tsconfig.json +5 -3
  54. package/apps/server/tsup.config.ts +4 -7
  55. package/apps/server/vitest.config.ts +0 -1
  56. package/eslint.config.mjs +1 -1
  57. package/modules/._.gitkeep +0 -0
  58. package/modules/.gitkeep +0 -0
  59. package/package.json +37 -16
  60. package/packages/shared/._AGENTS.md +0 -0
  61. package/packages/shared/._package.json +0 -0
  62. package/packages/shared/._tsconfig.json +0 -0
  63. package/packages/shared/AGENTS.md +11 -0
  64. package/packages/shared/package.json +13 -0
  65. package/packages/shared/src/._index.ts +0 -0
  66. package/packages/shared/src/index.ts +7 -0
  67. package/packages/shared/tsconfig.json +7 -0
  68. package/pnpm-lock.template.yaml +554 -187
  69. package/pnpm-workspace.template.yaml +13 -18
  70. package/scripts/._build.sh +0 -0
  71. package/scripts/._check-css-target.mjs +0 -0
  72. package/scripts/._check.mjs +0 -0
  73. package/scripts/._dev.sh +0 -0
  74. package/scripts/._generate.mjs +0 -0
  75. package/scripts/._start.sh +0 -0
  76. package/scripts/._stop.sh +0 -0
  77. package/scripts/build.sh +2 -26
  78. package/scripts/check-css-target.mjs +54 -0
  79. package/scripts/check.mjs +7 -0
  80. package/scripts/dev.sh +1 -9
  81. package/scripts/generate.mjs +3 -0
  82. package/scripts/start.sh +1 -7
  83. package/apps/client/src/business/App.tsx +0 -3
  84. package/apps/client/src/business/routes.json +0 -3
  85. package/apps/client/src/main.tsx +0 -29
  86. package/apps/client/src/platform/bootstrap.ts +0 -18
  87. package/apps/client/src/platform/mount-page.tsx +0 -34
  88. package/apps/client/src/styles/base.css +0 -16
  89. package/scripts/check-workspace.mjs +0 -144
  90. package/scripts/prepare.sh +0 -11
@@ -1,35 +1,2 @@
1
- /**
2
- * 装配主体(模块级单例):express 链 + /api/health + start()。客户端供给由入口决定——
3
- * 静态产物见 index.ts(唯一 tsup entry),vite dev 见 dev.ts(仅 tsx)。
4
- * 平台微调(inspector)在入口级接线(index.ts / dev.ts),保持本模块测试纯净。
5
- */
6
- import { createServer } from 'http';
7
- import express from 'express';
8
- import { createLogger } from '@tbox.cn/app-sdk-server';
9
-
10
- export const app = express();
11
- const logger = createLogger('server');
12
-
13
- app.use(express.json());
14
-
15
- // 健康检查契约(平台探活):GET /api/health → {"status":"ok"}
16
- app.get('/api/health', (_req, res) => {
17
- res.json({ status: 'ok' });
18
- });
19
-
20
- // 未知 /api/* 恒 JSON 404(不落 SPA 兜底)
21
- app.use('/api', (_req, res) => {
22
- res.status(404).json({ error: 'Not Found' });
23
- });
24
-
25
- export function start() {
26
- const port = Number(process.env.PORT ?? 8000);
27
- const host = process.env.HOST ?? '0.0.0.0';
28
- const server = createServer(app);
29
- server.on('error', (err) => {
30
- logger.error('server error:', err);
31
- process.exit(1);
32
- });
33
- server.listen(port, host, () => logger.info(`listening on http://${host}:${port}`));
34
- return server;
35
- }
1
+ export { createApp, createPageRuntime, start } from '@tbox.cn/app-sdk-server';
2
+ export type { AppManifest, AppServerModule, ServerRegistry } from '@tbox.cn/app-sdk-server';
@@ -1,129 +1,43 @@
1
- /**
2
- * vite dev 入口(仅 tsx 运行:pnpm dev;物理不进 tsup bundle——forbid-vite 插件拦截)。
3
- * middlewareMode + 单端口 8000:HTTP 与 HMR WS 全走应用端口。
4
- * 部署形态一律走 dist/index.js(静态产物,零 HMR WS)。
5
- *
6
- * 方案 W(沙箱 dev server 鉴权保护):TBOX_DEV_TOKEN 在场 → protected 双面裁决
7
- * (dev 面 = 凭据 + 导航/同源信号放行 vite;static 面 = 纯 dist + SSE 刷新,零源码泄漏);
8
- * 缺席 → classic,与历史行为字节级等价。裁决机制真源 = SDK platform/dev-runtime
9
- * (createTboxDevRuntime),本文件只做装配:vite 实例 + fs.allow 收窄 + 面无关自由区。
10
- */
11
- import { createServer } from 'http';
12
- import path from 'path';
13
- import { existsSync } from 'node:fs';
14
- import { fileURLToPath } from 'url';
15
- import { build as viteBuild, createServer as createViteServer, searchForWorkspaceRoot } from 'vite';
16
- import {
17
- createTboxDevRuntime,
18
- injectScript,
19
- installInspector,
20
- isReady,
21
- resolveDevTokenFromEnv,
22
- } from '@tbox.cn/app-sdk-server/platform';
23
- import { createLogger } from '@tbox.cn/app-sdk-server';
24
- import { app, start } from './app.js';
25
-
26
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
27
- const serverLogger = createLogger('server');
28
- const clientRoot = path.resolve(__dirname, '../../client');
29
- const appRoot = path.resolve(__dirname, '../..');
30
-
31
- // HMR WS 独立路径与协议常量(scripts/smoke-dev-hmr.sh 断言消费,不得改名):
32
- // dev 基础设施命名空间(双下划线),与业务命名空间解耦。协议白名单与 Spanner 子协议
33
- // 补写内聚于 SDK handleUpgrade(本模板 upgrade 形态 = server.on 直连,见文件尾)。
34
- const HMR_WS_PATH = '/__vite_hmr';
35
-
36
- // HMR WS hub:永不 listen 的纯事件载体。hmr.server 在场 → vite 不自建独立端口,
37
- // 客户端按页面同源端口连接。vite 对 hub 仅 on/off('upgrade')。
38
- const hmrHub = createServer();
39
-
40
- const tokenState = resolveDevTokenFromEnv(process.env);
41
- const protectedMode = tokenState.mode === 'protected';
42
-
43
- // protected 面 fs.allow 收窄(classic 恒默认不传——红线):client 源 + 工作区依赖真源
44
- // (filter(existsSync):生成应用无 packages/ 时自动滤除,不影响沙箱半径)。
45
- const workspaceRoot = searchForWorkspaceRoot(clientRoot);
46
- const fsAllowNarrowed = protectedMode
47
- ? [
48
- ...new Set(
49
- [
50
- clientRoot,
51
- path.join(appRoot, 'packages'),
52
- path.join(appRoot, 'node_modules'),
53
- path.join(workspaceRoot, 'packages'),
54
- path.join(workspaceRoot, 'node_modules'),
55
- ].filter((p) => existsSync(p)),
56
- ),
57
- ]
58
- : undefined;
59
-
1
+ import path from 'node:path';
2
+ import { createServer } from 'node:http';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { createServer as createViteServer } from 'vite';
5
+ import { generateApp } from '@tbox.cn/app-build';
6
+ import { createApp, start } from '@tbox.cn/app-sdk-server';
7
+
8
+ const here = path.dirname(fileURLToPath(import.meta.url));
9
+ const root = path.resolve(here, '../../..');
10
+ const clientDir = path.join(root, 'apps', 'client');
11
+
12
+ const generated = await generateApp({ root, watch: true });
13
+ const [{ registry }] = await Promise.all([
14
+ import('../../client/.tbox-gen/registry.server.ts'),
15
+ ]);
16
+ const { appKind } = generated;
17
+
18
+ const httpServer = createServer();
60
19
  const vite = await createViteServer({
61
- root: clientRoot,
62
- server: {
63
- middlewareMode: true,
64
- allowedHosts: true, // 沙箱域名 Host 透传放行(dev-only;dist 物理不含 vite)
65
- fs: {
66
- ...(fsAllowNarrowed ? { allow: fsAllowNarrowed } : {}),
67
- deny: ['.env', '.env.*', '*.{crt,pem}', '**/.git/**'],
68
- },
69
- hmr: { server: hmrHub, path: HMR_WS_PATH },
70
- },
71
- appType: 'custom', // 不加 Vite 自己的 SPA fallback,HTML 路由由 runtime.final() 统一处理
20
+ configFile: path.join(clientDir, 'vite.config.ts'),
21
+ server: { middlewareMode: true, hmr: { server: httpServer } },
22
+ appType: 'custom',
72
23
  });
73
24
 
74
- const runtime = createTboxDevRuntime({
75
- vite: { middlewares: vite.middlewares, transformIndexHtml: vite.transformIndexHtml, ws: vite.ws },
76
- hmrHub,
77
- hmrPath: path.posix.join(vite.config.base, HMR_WS_PATH),
78
- tokenState,
79
- clientRoot,
80
- clientDist: path.join(clientRoot, 'dist'),
81
- spaExcludePrefixes: ['/api'],
82
- decorateHtml: (html) => (isReady() ? injectScript(html) : html),
83
- logger: serverLogger,
84
- sseKeepaliveMs: process.env.TBOX_DEV_SSE_KEEPALIVE_MS ? Number(process.env.TBOX_DEV_SSE_KEEPALIVE_MS) : undefined,
85
- // v3.2 严格文档模式(G8 模式开关):routes.json 在场 ⇔ strict(dev 面 entry 替换 +
86
- // public 目录索引;static 面 dist 文件真源)。缺席 = legacy SPA fallback,零变化。
87
- pagePolicy: {
88
- routesModule: path.join(clientRoot, 'src/business/routes.json'),
89
- },
25
+ const app = await createApp({
26
+ manifest: generated.manifest,
27
+ getManifest: () => generated.manifest,
28
+ appKind,
29
+ registry,
30
+ mode: 'dev',
31
+ htmlFile: path.join(clientDir, 'index.html'),
32
+ vite,
90
33
  });
91
34
 
92
- // 面裁决:dev 面 → vite middlewares;static 面 → next()(落 final 的 dist 静态)
93
- app.use(runtime.gate);
35
+ const server = await start(app, { server: httpServer });
36
+ const close = async () => {
37
+ await generated.close();
38
+ await vite.close();
39
+ server.close();
40
+ };
94
41
 
95
- // ── 自由区(模板差异 + 应用自定义 middleware;dev/static 两面恒可见)──
96
- // 平台微调(inspector):入口级接线(RUNTIME_PATH 路由 + text/html 装配),两面共用
97
- installInspector(app);
98
- // 探针路由:smoke-dev-protected.sh ⑩ 断言两面可见性(dev 基础设施,dist 物理不含)
99
- app.get('/__tbox_dev_freezone_probe', (_req, res) => {
100
- res.type('text/plain').send('freezone-ok');
101
- });
102
- // ── 自由区结束 ──
103
-
104
- app.use(runtime.final);
105
-
106
- // protected 面构建通知:watch 增量构建 → BUNDLE_END → SSE 广播 → static 面 reload。
107
- // fire-and-forget;watch 启动 emptyOutDir 清空 dist 为已定价行为(首建完成前 static 面纯 404)。
108
- if (protectedMode) {
109
- viteBuild({ root: clientRoot, build: { watch: {}, sourcemap: false } })
110
- .then((result) => {
111
- const watcher = Array.isArray(result) ? result[0] : result;
112
- if (!watcher || !('on' in watcher)) return;
113
- watcher.on('event', (e) => {
114
- if (e.code === 'BUNDLE_START') runtime.notifyBuildStart();
115
- if (e.code === 'BUNDLE_END') runtime.notifyBuildEnd();
116
- });
117
- })
118
- .catch((err) => console.error('[dev] watch build failed:', err));
119
- }
120
-
121
- const server = start();
122
-
123
- // 升级处理:唯一 WS 入口 = runtime.handleUpgrade(认领 /__vite_hmr + 子协议白名单 +
124
- // protected token 校验失败 401;其余一律销毁——本模板无业务 WS,smoke-dev-hmr 断言消费)
125
- server.on('upgrade', (request, socket, head) => {
126
- if (!runtime.handleUpgrade(request, socket, head)) {
127
- socket.destroy();
128
- }
129
- });
42
+ process.once('SIGINT', () => void close());
43
+ process.once('SIGTERM', () => void close());
@@ -0,0 +1,5 @@
1
+ import type { GreetInput, GreetOutput } from '@app/shared';
2
+
3
+ export default async function greet(input: GreetInput): Promise<GreetOutput> {
4
+ return { message: `你好,${input.name ?? '世界'}` };
5
+ }
@@ -1,42 +1,20 @@
1
- /**
2
- * 静态入口(唯一 tsup entry → dist/index.js):express.static 供给 client/dist。
3
- * dist 形态恒静态——vite dev 仅存在于 src/dev.ts(tsx 运行,禁入 tsup entry,
4
- * tsup.config.ts forbid-vite 插件拦截)。
5
- */
6
- import path from 'path';
7
- import { existsSync } from 'node:fs';
8
- import { fileURLToPath } from 'url';
9
- import express from 'express';
10
- import { createLogger } from '@tbox.cn/app-sdk-server';
11
- import { createStrictStaticHandler, installInspector } from '@tbox.cn/app-sdk-server/platform';
12
- import { app, start } from './app.js';
1
+ import path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { createApp, start, type AppManifest } from '@tbox.cn/app-sdk-server';
4
+ import manifest from '../../client/.tbox-gen/manifest.json';
5
+ import appMeta from '../../../.tbox/app.json';
6
+ import { registry } from '../../client/.tbox-gen/registry.server';
13
7
 
14
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
15
- const logger = createLogger('server');
8
+ const here = path.dirname(fileURLToPath(import.meta.url));
9
+ const clientDir = path.resolve(here, '../../client/dist');
16
10
 
17
- // 平台微调(inspector):点选元素→定位源码(接线契约由 pnpm check:inspector 守卫)。
18
- // 入口级调用(index.ts / dev.ts 对称),app.ts 保持测试纯净。
19
- installInspector(app);
11
+ const app = await createApp({
12
+ manifest: manifest as AppManifest,
13
+ appKind: appMeta.appKind as 'web',
14
+ registry,
15
+ mode: 'prod',
16
+ clientDir,
17
+ });
20
18
 
21
- const clientDistPath = path.join(__dirname, '../../client/dist');
22
- if (!existsSync(path.join(clientDistPath, 'index.html'))) {
23
- logger.warn(`client/dist 缺失(${clientDistPath})——页面将不可用;请先执行 pnpm build:client`);
24
- }
25
-
26
- // v3.2 严格文档模式(G8 模式开关):routes.json 在场 ⇔ strict(dist 文件存在性 =
27
- // 唯一路由真源,未知页面 404 是文件系统的自然结果);缺席 = legacy SPA fallback(等价历史)。
28
- const routesModule = path.join(__dirname, '../../client/src/business/routes.json');
29
- if (existsSync(routesModule)) {
30
- logger.info('page_mode', { mode: 'strict-pages' });
31
- app.use(createStrictStaticHandler({ distDir: clientDistPath }));
32
- } else {
33
- logger.info('page_mode', { mode: 'legacy-spa' });
34
- app.use(express.static(clientDistPath));
35
- app.get('*', (req, res) => {
36
- if (!req.path.startsWith('/api')) {
37
- res.sendFile(path.join(clientDistPath, 'index.html'));
38
- }
39
- });
40
- }
41
-
42
- start();
19
+ const server = await start(app);
20
+ process.once('SIGTERM', () => server.close());
Binary file
@@ -1,17 +1,42 @@
1
1
  import request from 'supertest';
2
- import { describe, expect, it } from 'vitest';
3
- import { app } from '../src/app.js';
2
+ import { beforeAll, describe, expect, it } from 'vitest';
3
+ import { createApp } from '@tbox.cn/app-sdk-server';
4
+
5
+ const manifest = {
6
+ schemaVersion: 1 as const,
7
+ pages: [{ path: '/', document: 'index.html', title: '首页' }],
8
+ };
9
+
10
+ const registry = {
11
+ functions: {
12
+ 'hello.world': async (input: unknown) => ({ input }),
13
+ },
14
+ tools: [],
15
+ skills: [],
16
+ cards: {},
17
+ modules: [],
18
+ };
4
19
 
5
20
  describe('HTTP API', () => {
6
- it('GET /api/health → {"status":"ok"}(平台探活契约)', async () => {
21
+ let app: Awaited<ReturnType<typeof createApp>>;
22
+ beforeAll(async () => {
23
+ app = await createApp({ manifest, appKind: 'web', registry, mode: 'dev' });
24
+ });
25
+
26
+ it('GET /api/health', async () => {
7
27
  const res = await request(app).get('/api/health');
8
28
  expect(res.status).toBe(200);
9
29
  expect(res.body).toEqual({ status: 'ok' });
10
30
  });
11
31
 
12
- it('未知 /api/* → JSON 404(不落 SPA 兜底)', async () => {
32
+ it('RPC uses bare body', async () => {
33
+ const res = await request(app).post('/api/fn/hello.world').send({ ok: true }).expect(200);
34
+ expect(res.body).toEqual({ input: { ok: true } });
35
+ });
36
+
37
+ it('unknown /api/* is JSON 404', async () => {
13
38
  const res = await request(app).get('/api/nope');
14
39
  expect(res.status).toBe(404);
15
- expect(res.body).toEqual({ error: 'Not Found' });
40
+ expect(res.body.error.code).toBe('API_NOT_FOUND');
16
41
  });
17
42
  });
@@ -1,5 +1,7 @@
1
1
  {
2
2
  "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {},
4
- "include": ["src", "tests"]
5
- }
3
+ "compilerOptions": {
4
+ "types": ["node"]
5
+ },
6
+ "include": ["src", "tests", "../../client/.tbox-gen"]
7
+ }
@@ -8,19 +8,16 @@ export default defineConfig({
8
8
  outDir: 'dist',
9
9
  clean: true,
10
10
  sourcemap: true,
11
- // vite 禁进 bundle 的结构防线:静态入口图(entry: index.ts → app.ts 链)任何 vite 引用
12
- // (含 dev.ts 误入 entry)在 onResolve 即失败——dev 形态仅存在于 src/dev.ts(tsx 运行)。
11
+ external: ['express'],
12
+ noExternal: [/^@tbox\.cn\//, /^@app\//],
13
13
  esbuildPlugins: [
14
14
  {
15
15
  name: 'forbid-vite-in-bundle',
16
16
  setup(build) {
17
17
  build.onResolve({ filter: /^vite(\/|$)/ }, () => ({
18
- errors: [
19
- { text: 'vite 禁止进入 server bundle:dev 形态走 src/dev.ts(仅 tsx),禁入 tsup entry' },
20
- ],
18
+ errors: [{ text: 'vite 禁止进入 server bundle:dev 形态走 src/dev.ts(仅 tsx)' }],
21
19
  }));
22
20
  },
23
21
  },
24
22
  ],
25
- external: ['express', 'path', 'url', 'http', 'fs'],
26
- });
23
+ });
@@ -2,7 +2,6 @@ import { defineConfig } from 'vitest/config';
2
2
 
3
3
  export default defineConfig({
4
4
  test: {
5
- globals: true,
6
5
  environment: 'node',
7
6
  },
8
7
  });
package/eslint.config.mjs CHANGED
@@ -3,7 +3,7 @@ import reactHooks from "eslint-plugin-react-hooks";
3
3
 
4
4
  export default [
5
5
  {
6
- files: ["apps/**/*.ts", "apps/**/*.tsx"],
6
+ files: ["apps/**/*.ts", "apps/**/*.tsx", "modules/**/*.ts", "modules/**/*.tsx"],
7
7
  plugins: {
8
8
  "@typescript-eslint": tseslint.plugin,
9
9
  "react-hooks": reactHooks,
Binary file
File without changes
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@tbox.cn/app-template-h5",
3
- "version": "0.1.27",
4
- "description": "tbox Web 全栈模板(单 workspace:apps/client + apps/server;h5 为家族历史名,不预设端形态),运行时与页面微调经 @tbox.cn/app-sdk。",
3
+ "version": "1.0.0-alpha.10",
5
4
  "type": "module",
5
+ "description": "tbox-app 1.0 Web 全栈模板:apps/client + apps/server 唯一应用代码根 + modules/ 源码根;appKind=web。",
6
6
  "engines": {
7
7
  "node": ">=24.0.0 <25.0.0"
8
8
  },
@@ -12,14 +12,19 @@
12
12
  },
13
13
  "files": [
14
14
  "apps",
15
+ "packages",
15
16
  "!apps/**/dist",
16
- "!apps/**/dist-ssr",
17
- "!apps/**/.vite",
17
+ "!apps/**/.tbox-gen",
18
18
  "!apps/**/node_modules",
19
+ "!apps/**/.vite",
19
20
  "!apps/**/*.tsbuildinfo",
21
+ "!packages/**/node_modules",
22
+ "!packages/**/*.tsbuildinfo",
23
+ "modules",
20
24
  "scripts",
21
25
  ".tbox",
22
26
  ".gitignore",
27
+ ".npmignore",
23
28
  ".nvmrc",
24
29
  "AGENTS.md",
25
30
  "LEGAL.md",
@@ -30,24 +35,40 @@
30
35
  "pnpm-lock.template.yaml",
31
36
  "tsconfig.base.json"
32
37
  ],
38
+ "dependencies": {
39
+ "express": "4.22.2"
40
+ },
33
41
  "devDependencies": {
42
+ "@tbox.cn/app-build": "1.0.0-alpha.10",
43
+ "@tbox.cn/app-sdk-client": "1.0.0-alpha.10",
44
+ "@tbox.cn/app-sdk-server": "1.0.0-alpha.10",
45
+ "@types/node": "24.13.3",
46
+ "@vitejs/plugin-react": "4.7.0",
34
47
  "eslint": "9.39.5",
35
48
  "eslint-plugin-react-hooks": "5.2.0",
49
+ "typescript": "5.9.3",
36
50
  "typescript-eslint": "8.67.0",
37
- "vite": "6.4.3",
38
- "@tbox.cn/app-sdk-server": "0.26.8"
51
+ "vite": "6.4.3"
52
+ },
53
+ "tbox": {
54
+ "compat": {
55
+ "baseline": {
56
+ "safari": 16.4,
57
+ "chrome": 105
58
+ }
59
+ }
39
60
  },
40
61
  "scripts": {
41
- "dev": "pnpm --filter ./apps/server dev",
42
- "build": "pnpm check && pnpm --filter ./apps/server build && pnpm --filter ./apps/client build",
43
- "build:client": "pnpm check && pnpm --filter ./apps/client build",
44
- "typecheck": "pnpm -r --filter \"./apps/*\" typecheck",
62
+ "dev": "pnpm --dir apps/server dev",
63
+ "build": "node scripts/generate.mjs && vite build --config apps/client/vite.config.ts && pnpm --dir apps/server build && node scripts/check-css-target.mjs",
64
+ "start": "node apps/server/dist/index.js",
65
+ "generate": "node scripts/generate.mjs",
66
+ "typecheck": "node scripts/generate.mjs && tsc -p packages/shared/tsconfig.json --noEmit && pnpm -r --filter \"./apps/*\" typecheck",
45
67
  "test": "pnpm -r --filter \"./apps/*\" test",
46
- "lint": "eslint apps",
47
- "verify": "pnpm typecheck && pnpm test && pnpm lint && pnpm build && pnpm check:inspector",
48
- "check": "pnpm check:workspace && pnpm check:inspector",
49
- "check:workspace": "node scripts/check-workspace.mjs",
50
- "check:inspector": "tbox-inspector-check",
51
- "verify:fast": "pnpm typecheck && pnpm test && pnpm check"
68
+ "lint": "eslint apps packages scripts",
69
+ "check": "node scripts/check.mjs",
70
+ "verify:fast": "pnpm typecheck && pnpm test && pnpm check",
71
+ "verify": "pnpm verify:fast && pnpm build",
72
+ "check:css": "node scripts/check-css-target.mjs"
52
73
  }
53
74
  }
Binary file
Binary file
Binary file
@@ -0,0 +1,11 @@
1
+ # packages/shared
2
+
3
+ 这是应用唯一的跨端 DTO 包,包名 `@app/shared`。
4
+
5
+ - 只放纯类型、常量、可序列化数据结构。
6
+ - 不 import React、Node、Express、数据库、网络客户端。
7
+ - 不 import `apps/*` 或 `modules/*`。
8
+ - 不放服务端实现、鉴权逻辑、HTTP 客户端。
9
+ - client 与 server 都使用 `import type { ... } from '@app/shared'`。
10
+ - 新增类型按 `<Domain><Action>Input` / `<Domain><Action>Output` 命名。
11
+ - 不放空 `export {}`;至少有一个真实导出。
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@app/shared",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "exports": {
8
+ ".": {
9
+ "types": "./src/index.ts",
10
+ "import": "./src/index.ts"
11
+ }
12
+ }
13
+ }
Binary file
@@ -0,0 +1,7 @@
1
+ export interface GreetInput {
2
+ name?: string;
3
+ }
4
+
5
+ export interface GreetOutput {
6
+ message: string;
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src"
5
+ },
6
+ "include": ["src"]
7
+ }