@quicktvui/web-cli 2.1.1 → 2.2.0

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/bin/qt-web-cli.js CHANGED
@@ -194,6 +194,8 @@ async function main() {
194
194
  },
195
195
  onReady: () => {
196
196
  // 构建完成后,通知浏览器
197
+ // notifyBuildStatus 会更新 lastEvent 为 build-status:ready
198
+ // 这样 SSE 重连后收到的是 ready 而不是旧的 bundle-update
197
199
  hotReloader.notifyBuildStatus('ready', '构建完成')
198
200
 
199
201
  // 更新 bundle URL
@@ -209,10 +211,6 @@ async function main() {
209
211
  const url = `http://localhost:${args.port}?bundle=${urlPath}`
210
212
  openBrowser(url)
211
213
  }
212
-
213
- // 清除 HotReloader 中缓存的 bundle-update 事件
214
- // 防止 SSE 重连后再次触发页面刷新导致无限循环
215
- hotReloader.clearLastEvent()
216
214
  },
217
215
  })
218
216
 
package/lib/DevServer.js CHANGED
@@ -65,18 +65,34 @@ class DevServer {
65
65
 
66
66
  /**
67
67
  * 查找 web-runtime 的 dist 目录
68
+ *
69
+ * 查找优先级:
70
+ * 1. web-cli 内嵌的 runtime/ 目录(全局安装时也能工作)
71
+ * 2. 同级 packages 目录(monorepo 开发时)
72
+ * 3. 项目 node_modules 中的包
68
73
  */
69
74
  _findWebRuntimeDist() {
70
75
  const candidates = [
71
- // 同级 packages 目录
76
+ // web-cli 内嵌的 runtime 目录(优先级最高,全局安装时也能找到)
77
+ path.resolve(__dirname, '../runtime'),
78
+ // 同级 packages 目录(monorepo 开发时)
72
79
  path.resolve(__dirname, '../../web-runtime/dist'),
73
- // node_modules 中的包
80
+ // 项目 node_modules 中的包
74
81
  path.join(this.projectRoot, 'node_modules/@quicktvui/web-runtime/dist'),
75
82
  ]
76
83
  for (const dir of candidates) {
77
84
  if (fs.existsSync(dir)) {
78
- signale.info(`找到 web-runtime: ${dir}`)
79
- return dir
85
+ // 验证目录中是否有 JS 文件
86
+ try {
87
+ const files = fs.readdirSync(dir)
88
+ const hasJs = files.some((f) => f.endsWith('.js'))
89
+ if (hasJs) {
90
+ signale.info(`找到 web-runtime: ${dir}`)
91
+ return dir
92
+ }
93
+ } catch (e) {
94
+ // 忽略读取错误,继续查找下一个
95
+ }
80
96
  }
81
97
  }
82
98
  signale.warn('未找到 web-runtime dist 目录,bundle 加载功能将不可用')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quicktvui/web-cli",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "description": "CLI tool for QuickTVUI web development v2 - delegate build & bundle loading",
5
5
  "author": "QuickTVUI Team",
6
6
  "license": "Apache-2.0",
@@ -8,9 +8,14 @@
8
8
  "qt-web-cli": "./bin/qt-web-cli.js"
9
9
  },
10
10
  "main": "lib/index.js",
11
+ "scripts": {
12
+ "sync-runtime": "rm -rf runtime/*.js && cp ../web-runtime/dist/web-runtime.*.js runtime/",
13
+ "prepublishOnly": "npm run sync-runtime"
14
+ },
11
15
  "files": [
12
16
  "bin",
13
17
  "lib",
18
+ "runtime",
14
19
  "templates"
15
20
  ],
16
21
  "keywords": [