@quicktvui/web-cli 2.3.0 → 2.4.1

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.
File without changes
package/lib/DevServer.js CHANGED
@@ -369,9 +369,16 @@ class DevServer {
369
369
 
370
370
  // dist/dev/ 下的文件 - 映射到项目的 dist/dev 目录
371
371
  if (pathname.startsWith('/dist/dev/')) {
372
- const relativePath = pathname.replace('/dist/dev/', '')
372
+ let relativePath = pathname.replace('/dist/dev/', '')
373
+ // 剥离 bundles-dev 中间段:web-runtime 的 publicPath 包含 bundles-dev,
374
+ // 导致 webpack 管理的资源(如图片)URL 会变成 /dist/dev/bundles-dev/assets/xxx.png
375
+ // 但实际文件在 dist/dev/assets/xxx.png,bundles-dev 只是 Hippy debug server 的路径约定
376
+ if (relativePath.startsWith('bundles-dev/')) {
377
+ relativePath = relativePath.replace('bundles-dev/', '')
378
+ }
373
379
  const filePath = path.join(this.distDir, relativePath)
374
- this._serveStaticFile(res, filePath, this.distDir)
380
+ const isVendor = /^vendor\./.test(path.basename(relativePath))
381
+ this._serveStaticFile(res, filePath, this.distDir, isVendor)
375
382
  return
376
383
  }
377
384
 
@@ -387,7 +394,8 @@ class DevServer {
387
394
  if (pathname.startsWith('/bundles-dev/')) {
388
395
  const relativePath = pathname.replace('/bundles-dev/', '')
389
396
  const filePath = path.join(this.distDir, relativePath)
390
- this._serveStaticFile(res, filePath, this.distDir)
397
+ const isVendor = /^vendor\./.test(path.basename(relativePath))
398
+ this._serveStaticFile(res, filePath, this.distDir, isVendor)
391
399
  return
392
400
  }
393
401
 
@@ -456,7 +464,7 @@ class DevServer {
456
464
  * @param {string} filePath - 文件绝对路径
457
465
  * @param {string} allowedDir - 允许的根目录(安全检查)
458
466
  */
459
- _serveStaticFile(res, filePath, allowedDir) {
467
+ _serveStaticFile(res, filePath, allowedDir, optional = false) {
460
468
  // 安全检查:防止路径遍历
461
469
  const resolvedPath = path.resolve(filePath)
462
470
  const allowedRoot = path.resolve(allowedDir || this.distDir)
@@ -467,6 +475,11 @@ class DevServer {
467
475
  }
468
476
 
469
477
  if (!fs.existsSync(resolvedPath)) {
478
+ if (optional) {
479
+ res.writeHead(204)
480
+ res.end()
481
+ return
482
+ }
470
483
  res.writeHead(404, { 'Content-Type': 'text/plain' })
471
484
  res.end('Not Found')
472
485
  return
@@ -566,11 +579,22 @@ class DevServer {
566
579
  })
567
580
 
568
581
  proxyReq.on('error', (err) => {
569
- console.error(`[Proxy] Error: ${err.message} -> ${protocol}://${hostname}:${port}${proxyPath}`)
582
+ console.error(
583
+ `[Proxy] Error: ${err.message} -> ${protocol}://${hostname}:${port}${proxyPath}`
584
+ )
570
585
  if (!res.headersSent) {
571
- res.writeHead(502, { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': this.corsOrigin })
586
+ res.writeHead(502, {
587
+ 'Content-Type': 'application/json',
588
+ 'Access-Control-Allow-Origin': this.corsOrigin,
589
+ })
572
590
  }
573
- res.end(JSON.stringify({ error: 'Proxy error', message: err.message, target: `${protocol}://${hostname}:${port}${proxyPath}` }))
591
+ res.end(
592
+ JSON.stringify({
593
+ error: 'Proxy error',
594
+ message: err.message,
595
+ target: `${protocol}://${hostname}:${port}${proxyPath}`,
596
+ })
597
+ )
574
598
  })
575
599
 
576
600
  // 转发请求体(POST/PUT 等)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quicktvui/web-cli",
3
- "version": "2.3.0",
3
+ "version": "2.4.1",
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,10 +8,6 @@
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
- },
15
11
  "files": [
16
12
  "bin",
17
13
  "lib",
@@ -86,5 +82,8 @@
86
82
  },
87
83
  "engines": {
88
84
  "node": ">=16.0.0"
85
+ },
86
+ "scripts": {
87
+ "sync-runtime": "rm -rf runtime/*.js && cp ../web-runtime/dist/web-runtime.*.js runtime/"
89
88
  }
90
- }
89
+ }