@lark-apaas/coding-template-nestjs-react-fullstack 0.1.25-alpha.20260820120346 → 0.1.25

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/coding-template-nestjs-react-fullstack",
3
- "version": "0.1.25-alpha.20260820120346",
3
+ "version": "0.1.25",
4
4
  "description": "NestJS + React fullstack template for miaoda coding",
5
5
  "type": "module",
6
6
  "files": [
@@ -35,8 +35,8 @@
35
35
  "dependencies": {
36
36
  "@lark-apaas/fullstack-nestjs-core": "^1.1.59",
37
37
  "@nestjs/axios": "^4.0.1",
38
- "@nestjs/cache-manager": "^3.1.3",
39
38
  "@nestjs/common": "^10.4.20",
39
+ "@nestjs/cache-manager": "^3.1.3",
40
40
  "@nestjs/config": "^3.3.0",
41
41
  "@nestjs/core": "^10.4.20",
42
42
  "@nestjs/platform-express": "^10.4.20",
@@ -63,8 +63,8 @@
63
63
  "@heroicons/react": "^2.2.0",
64
64
  "@hookform/resolvers": "^5.2.2",
65
65
  "@lark-apaas/client-toolkit": "^1.2.63",
66
- "@lark-apaas/coding-preset-vite-react": "1.0.18-alpha.20260819103004",
67
66
  "@lark-apaas/fullstack-presets": "^1.1.0",
67
+ "@lark-apaas/fullstack-vite-preset": "^1.0.34",
68
68
  "@nestjs/cli": "^10.4.9",
69
69
  "@nestjs/testing": "^10.4.20",
70
70
  "@radix-ui/react-accordion": "^1.2.12",
@@ -181,7 +181,7 @@
181
181
  "typescript-eslint": "^8.44.0",
182
182
  "uuid": "11.0.5",
183
183
  "vaul": "^1.1.2",
184
- "vite": "^8",
184
+ "vite": "^7.3.1",
185
185
  "xlsx": "^0.18.5",
186
186
  "xlsx-js-style": "^1.2.0",
187
187
  "zod": "^3.25.76",
@@ -59,23 +59,10 @@ function timestamp() {
59
59
  );
60
60
  }
61
61
 
62
- // Cap pending async stdout writes so a stalled pty consumer can't grow memory unbounded.
63
- // Each pending fs.write retains ~1.5 KB (msg + libuv/V8 wrappers); 1000 ≈ ~1.5 MB ceiling.
64
- let _stdoutInFlight = 0;
65
- const STDOUT_MAX_INFLIGHT = 1000;
66
-
67
- /** Write to dev.std.log (sync, guaranteed) + mirror to terminal (async, non-blocking) */
62
+ /** Write to terminal + dev.std.log */
68
63
  function writeOutput(msg) {
69
- // File first and synchronously — read-logs reads this file; it must never be gated
70
- // by the terminal consumer.
64
+ try { process.stdout.write(msg); } catch {}
71
65
  try { fs.writeSync(devStdLogFd, msg); } catch {}
72
- // stdout mirror via async fs.write: if process.stdout is a pty/pipe whose consumer
73
- // stalls, the block happens on the libuv threadpool, NOT the event loop — so the
74
- // synchronous log-FILE writes above (and subsequent readline callbacks) keep running.
75
- // Drop overflow when too many writes are already pending (best-effort mirror).
76
- if (_stdoutInFlight >= STDOUT_MAX_INFLIGHT) { return; }
77
- _stdoutInFlight++;
78
- try { fs.write(1, msg, () => { _stdoutInFlight--; }); } catch { _stdoutInFlight--; }
79
66
  }
80
67
 
81
68
  /** Structured event log → terminal + dev.std.log + dev.log */
@@ -252,23 +239,20 @@ process.on('SIGTERM', cleanup);
252
239
  process.on('SIGINT', cleanup);
253
240
  process.on('SIGHUP', cleanup);
254
241
 
255
- // 定向保留 dist/ 里能复用的部分, 替代之前无脑 rm -rf dist/。
256
- // 收益: 保留 dist/server 让 nest --watch 从增量编译起点起 ( 8-13s 冷启动),
257
- // routes JSON 也保留 (build 会覆盖, 无 stale 风险)。dist/client/index.html 按
258
- // preset 打的 <meta name="miaoda-html-mode"> marker 判定:
259
- // marker=dev → 保留 dist/client/ 整个 (dev cache hit)
260
- // marker=prod agent 跑过 build:client 污染, 定向清 index.html + assets/
261
- // 具体逻辑抽到 lib/preserve-dev-cache.cjs 便于单测。
262
- // 降级 escape hatch: FORCE_CLEAN_DIST=true 走原全清路径 (marker 逻辑出 bug 时用)。
263
- const { preserveDevCache } = require('./lib/preserve-dev-cache.cjs');
242
+ // Stale dist makes nest --watch skip missing files; watcher won't self-heal.
243
+ function cleanStaleDist() {
244
+ const distPath = path.join(PROJECT_ROOT, 'dist');
245
+ if (fs.existsSync(distPath)) {
246
+ fs.rmSync(distPath, { recursive: true, force: true });
247
+ logEvent('INFO', 'main', 'Cleaned dist/ to force full rebuild');
248
+ }
249
+ }
264
250
 
265
251
  // ── Main ──────────────────────────────────────────────────────────────────────
266
252
  async function main() {
267
253
  logEvent('INFO', 'main', '========== Dev session started ==========');
268
254
 
269
- preserveDevCache(PROJECT_ROOT, {
270
- log: (level, msg) => logEvent(level, 'main', msg),
271
- });
255
+ cleanStaleDist();
272
256
 
273
257
  // Initialize action plugins
274
258
  writeOutput('\n🔌 Initializing action plugins...\n');
@@ -1,14 +1,18 @@
1
1
  #!/usr/bin/env bash
2
- # `npm run dev` 入口;按 SANDBOX_ID 是否非空判断运行环境:
3
- # - SANDBOX_ID 非空(沙箱平台注入应用所属沙箱 ID)→ 直接跑 dev.js
2
+ # `npm run dev` 入口;按 MIAODA_DEP_CACHE_DIR 是否非空判断运行环境(与 miaoda-cli
3
+ # isSandboxEnv() 同口径):
4
+ # - 非空(沙箱平台注入的依赖缓存目录)→ 直接跑 dev.js
4
5
  # (保活 / restart loop / 文件日志 —— 沙箱生产形态)。脚本同步由平台 pod 启动阶段做过,
5
6
  # dev 入口不再额外 `npm run upgrade`。
6
- # - 否则(本地)→ 走 miaoda app sync 兜底 + 跑 dev-local.sh:纯 stdout、崩了就崩、Agent 友好。
7
- # 显式想跑本地路径可用 `npm run dev:local`(绕过 SANDBOX_ID 判断)。
7
+ # - 否则(本地)→ 走 miaoda app sync 兜底 + 跑 dev-local.js:纯 stdout、崩了就崩、Agent 友好。
8
+ # 显式想跑本地路径可用 `npm run dev:local`(绕过本判断)。
9
+ #
10
+ # 不用 SANDBOX_ID:它由 sandbox_console 在绑定沙箱时才写入 .force/environment/env,预热池实例
11
+ # 在绑定前拿不到,会被误判成本地。保留为附加条件只为兼容,不影响判定结果。
8
12
  set -euo pipefail
9
13
  SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
10
14
 
11
- if [ -n "${SANDBOX_ID:-}" ]; then
15
+ if [ -n "${MIAODA_DEP_CACHE_DIR:-}" ] || [ -n "${SANDBOX_ID:-}" ]; then
12
16
  exec node "$SCRIPT_DIR/dev.js" "$@"
13
17
  fi
14
18
 
@@ -18,7 +22,7 @@ if [ ! -f "$SCRIPT_DIR/dev-local.js" ]; then
18
22
  fi
19
23
 
20
24
  # 本地启动前先跑一次 miaoda app sync:同步 platform-controlled 内容 + 升 @lark-apaas/* 到
21
- # latest + 迁移老 npm scripts。沙箱不走这里(SANDBOX_ID 分支已经 exec return)。
25
+ # latest + 迁移老 npm scripts。沙箱不走这里(上面的沙箱分支已经 exec return)。
22
26
  npx -y @lark-apaas/miaoda-cli@latest app sync || echo "[dev] miaoda app sync 失败,按现状继续" >&2
23
27
 
24
28
  exec node "$SCRIPT_DIR/dev-local.js" "$@"
@@ -1,5 +1,5 @@
1
1
  import path from 'path';
2
- import { defineConfig } from '@lark-apaas/coding-preset-vite-react';
2
+ import { defineConfig } from '@lark-apaas/fullstack-vite-preset';
3
3
 
4
4
  export default defineConfig({
5
5
  resolve: {
@@ -1,123 +0,0 @@
1
- 'use strict';
2
-
3
- // dev.js 启动时替代无脑 rm -rf dist/ 的 lib: 保留 dist/server (nest --watch 增量编译起点)
4
- // + 按 HTML mode marker 决定 dist/client 是保留还是清污染。
5
- // 跟 preset 侧 html-output plugin 的 injectHtmlModeMarker / detectHtmlMode 配套:
6
- // preset 写盘时打 marker (dev 版 vs prod 污染版), 这里读 marker 定去留。
7
-
8
- const fs = require('fs');
9
- const path = require('path');
10
-
11
- /**
12
- * 从 HTML 里回读 <meta name="miaoda-html-mode" content="dev|prod"> marker。
13
- * 与 packages/tools/fullstack-vite-preset/src/vite-plugins/html-output-plugin.ts
14
- * 的 detectHtmlMode 同源, 为了让 dev.js 模板脚本零依赖跑起来这里重复一份。
15
- */
16
- function detectHtmlMode(htmlContent) {
17
- const match = htmlContent.match(
18
- /<meta\s+name=["']miaoda-html-mode["']\s+content=["'](dev|prod)["'][^>]*>/i
19
- );
20
- return (match && match[1]) || 'unknown';
21
- }
22
-
23
- /**
24
- * 定向清理 dist/ 的可复用副本, 替代 dev.js 之前无脑 `rm -rf dist/` 的 cleanStaleDist。
25
- *
26
- * 决策规则:
27
- * - FORCE_CLEAN_DIST=true → 走 escape hatch 全清 (preserveDevCache 逻辑 / 保留的
28
- * dist/server 出 stale 时兜底)
29
- * - dist/ 不存在 → 无动作
30
- * - dist/client/index.html 存在且 marker=dev → 整个 dist/client/ 保留 (dev cache hit)
31
- * - 存在但 marker=prod 或缺失 → 只清 dist/client/index.html + dist/client/assets/
32
- * (build 污染部分), dist/server/ 与 routes JSON 保留
33
- * - 不存在 → 无动作, htmlOutputPlugin 稍后会写入
34
- *
35
- * @param {string} projectRoot 项目根目录
36
- * @param {object} [options]
37
- * @param {(level: string, msg: string) => void} [options.log] 日志回调, 默认 console.log
38
- * @param {boolean} [options.forceClean] 覆盖 FORCE_CLEAN_DIST env var 判断 (给测试用)
39
- * @returns {{ action: 'no_dist' | 'force_cleaned' | 'no_index' | 'preserved' | 'cleaned_polluted' | 'read_failed_cleaned' | 'cleanup_failed', mode: string }}
40
- */
41
- function preserveDevCache(projectRoot, options) {
42
- const log = (options && options.log) || defaultLogger;
43
- const forceClean =
44
- options && typeof options.forceClean === 'boolean'
45
- ? options.forceClean
46
- : process.env.FORCE_CLEAN_DIST === 'true';
47
-
48
- const distPath = path.join(projectRoot, 'dist');
49
- if (!fs.existsSync(distPath)) {
50
- log('INFO', 'preserveDevCache: no dist/, will be created by vite/nest');
51
- return { action: 'no_dist', mode: 'unknown' };
52
- }
53
-
54
- if (forceClean) {
55
- fs.rmSync(distPath, { recursive: true, force: true });
56
- log(
57
- 'INFO',
58
- 'preserveDevCache: FORCE_CLEAN_DIST=true, cleaned entire dist/'
59
- );
60
- return { action: 'force_cleaned', mode: 'unknown' };
61
- }
62
-
63
- const clientDir = path.join(distPath, 'client');
64
- const indexHtml = path.join(clientDir, 'index.html');
65
-
66
- if (!fs.existsSync(indexHtml)) {
67
- log(
68
- 'INFO',
69
- 'preserveDevCache: no dist/client/index.html, other artifacts preserved'
70
- );
71
- return { action: 'no_index', mode: 'unknown' };
72
- }
73
-
74
- let mode = 'unknown';
75
- let readFailed = false;
76
- try {
77
- const content = fs.readFileSync(indexHtml, 'utf-8');
78
- mode = detectHtmlMode(content);
79
- } catch (e) {
80
- log(
81
- 'WARN',
82
- `preserveDevCache: read dist/client/index.html failed: ${e.message}, treating as polluted`
83
- );
84
- readFailed = true;
85
- mode = 'unknown';
86
- }
87
-
88
- if (mode === 'dev') {
89
- log('INFO', 'preserveDevCache: dist/client preserved (dev cache hit)');
90
- return { action: 'preserved', mode: 'dev' };
91
- }
92
-
93
- // marker=prod 或 unknown → build:client 污染 (或人为放的产物), 定向清 index.html + assets/
94
- // dist/server/, dist/*.json 保留
95
- try {
96
- fs.rmSync(indexHtml, { force: true });
97
- const assetsDir = path.join(clientDir, 'assets');
98
- if (fs.existsSync(assetsDir)) {
99
- fs.rmSync(assetsDir, { recursive: true, force: true });
100
- }
101
- log(
102
- 'INFO',
103
- `preserveDevCache: dist/client/index.html was ${mode}, cleaned index.html + assets/ (dist/server preserved)`
104
- );
105
- return {
106
- action: readFailed ? 'read_failed_cleaned' : 'cleaned_polluted',
107
- mode,
108
- };
109
- } catch (e) {
110
- log(
111
- 'WARN',
112
- `preserveDevCache: cleanup failed: ${e.message}, continuing anyway (index.html / assets may still be polluted)`
113
- );
114
- return { action: 'cleanup_failed', mode };
115
- }
116
- }
117
-
118
- function defaultLogger(level, msg) {
119
- // eslint-disable-next-line no-console
120
- console.log(`[${level}] [main] ${msg}`);
121
- }
122
-
123
- module.exports = { detectHtmlMode, preserveDevCache };