@meituan-nocode/vite-plugin-nocode-compiler 0.3.1-beta.13 → 0.3.1-beta.15
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/dist/index.cjs +1 -33
- package/dist/index.js +1 -33
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -178,7 +178,7 @@ function readJsonBody(req) {
|
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
// package.json
|
|
181
|
-
var version = "0.3.1-beta.
|
|
181
|
+
var version = "0.3.1-beta.15";
|
|
182
182
|
|
|
183
183
|
// src/design-mode/types.ts
|
|
184
184
|
var SANDBOX_SCRIPT_PATH = "/sandbox-script.js";
|
|
@@ -210,12 +210,6 @@ function hasVirtualCode(id) {
|
|
|
210
210
|
if (!relativePath) return false;
|
|
211
211
|
return virtualCodeMap.has(relativePath) || virtualCodeMap.has("/" + relativePath);
|
|
212
212
|
}
|
|
213
|
-
function hasVirtualCodeByAbsolutePath(absolutePath, projectRoot) {
|
|
214
|
-
if (virtualCodeMap.size === 0) return false;
|
|
215
|
-
const relativePath = absolutePath.startsWith(projectRoot) ? absolutePath.slice(projectRoot.length).replace(/^\//, "") : null;
|
|
216
|
-
if (!relativePath) return false;
|
|
217
|
-
return virtualCodeMap.has(relativePath) || virtualCodeMap.has("/" + relativePath);
|
|
218
|
-
}
|
|
219
213
|
function shouldSkipDesignModeTransform(id, options) {
|
|
220
214
|
if (!matchesDesignModePattern(id, options)) return true;
|
|
221
215
|
if (hasVirtualCode(id)) return true;
|
|
@@ -260,8 +254,6 @@ function createVirtualCodeMiddleware(server, options, projectRoot) {
|
|
|
260
254
|
if (verbose) {
|
|
261
255
|
console.log(`[DnD] Virtual code set for: ${filePath}`);
|
|
262
256
|
}
|
|
263
|
-
const fullPath = path.resolve(projectRoot, filePath);
|
|
264
|
-
triggerHmrUpdate(server, fullPath, verbose);
|
|
265
257
|
res.end(JSON.stringify({ success: true, filePath }));
|
|
266
258
|
} catch (error) {
|
|
267
259
|
res.statusCode = 500;
|
|
@@ -508,30 +500,6 @@ function componentCompiler(options = {}) {
|
|
|
508
500
|
console.log(`[DesignMode] Virtual code API enabled at ${designModeOptions.virtualCodeApiPath}`);
|
|
509
501
|
}
|
|
510
502
|
},
|
|
511
|
-
/**
|
|
512
|
-
* 处理 HMR 更新:
|
|
513
|
-
* 当文件变更被 Vite file watcher 检测到时,如果该文件已有虚拟代码,
|
|
514
|
-
* 则拦截 Vite 的默认 HMR 处理,返回空数组阻止重复/冲突的 HMR 更新。
|
|
515
|
-
*
|
|
516
|
-
* 背景:Design Mode 使用双通道同步机制:
|
|
517
|
-
* 1. 虚拟代码通道:通过 /api/virtual-code POST → triggerHmrUpdate 触发 HMR
|
|
518
|
-
* 2. 磁盘写入通道:干净代码写入磁盘 → Vite file watcher 检测到变化
|
|
519
|
-
*
|
|
520
|
-
* 如果不拦截通道 2 触发的 HMR,两次 HMR 之间可能产生竞态条件:
|
|
521
|
-
* - triggerHmrUpdate 先 invalidateModule 重置了 isSelfAccepting
|
|
522
|
-
* - file watcher 触发的 HMR 在模块重新 transform 前执行 propagateUpdate
|
|
523
|
-
* - propagateUpdate 发现 isSelfAccepting === undefined,停止传播
|
|
524
|
-
* - 导致 "no update happened",样式修改不生效
|
|
525
|
-
*/
|
|
526
|
-
handleHotUpdate(ctx) {
|
|
527
|
-
if (!designModeOptions.enableVirtualCode) return;
|
|
528
|
-
if (hasVirtualCodeByAbsolutePath(ctx.file, projectRoot)) {
|
|
529
|
-
if (designModeOptions.verbose) {
|
|
530
|
-
console.log(`[DesignMode] Intercepted file watcher HMR for: ${ctx.file} (managed by virtual code)`);
|
|
531
|
-
}
|
|
532
|
-
return [];
|
|
533
|
-
}
|
|
534
|
-
},
|
|
535
503
|
/**
|
|
536
504
|
* 转换 index.html:
|
|
537
505
|
* 1. 在 <body> 标签上注入组件库版本信息和编译插件版本
|
package/dist/index.js
CHANGED
|
@@ -143,7 +143,7 @@ function readJsonBody(req) {
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
// package.json
|
|
146
|
-
var version = "0.3.1-beta.
|
|
146
|
+
var version = "0.3.1-beta.15";
|
|
147
147
|
|
|
148
148
|
// src/design-mode/types.ts
|
|
149
149
|
var SANDBOX_SCRIPT_PATH = "/sandbox-script.js";
|
|
@@ -175,12 +175,6 @@ function hasVirtualCode(id) {
|
|
|
175
175
|
if (!relativePath) return false;
|
|
176
176
|
return virtualCodeMap.has(relativePath) || virtualCodeMap.has("/" + relativePath);
|
|
177
177
|
}
|
|
178
|
-
function hasVirtualCodeByAbsolutePath(absolutePath, projectRoot) {
|
|
179
|
-
if (virtualCodeMap.size === 0) return false;
|
|
180
|
-
const relativePath = absolutePath.startsWith(projectRoot) ? absolutePath.slice(projectRoot.length).replace(/^\//, "") : null;
|
|
181
|
-
if (!relativePath) return false;
|
|
182
|
-
return virtualCodeMap.has(relativePath) || virtualCodeMap.has("/" + relativePath);
|
|
183
|
-
}
|
|
184
178
|
function shouldSkipDesignModeTransform(id, options) {
|
|
185
179
|
if (!matchesDesignModePattern(id, options)) return true;
|
|
186
180
|
if (hasVirtualCode(id)) return true;
|
|
@@ -225,8 +219,6 @@ function createVirtualCodeMiddleware(server, options, projectRoot) {
|
|
|
225
219
|
if (verbose) {
|
|
226
220
|
console.log(`[DnD] Virtual code set for: ${filePath}`);
|
|
227
221
|
}
|
|
228
|
-
const fullPath = path.resolve(projectRoot, filePath);
|
|
229
|
-
triggerHmrUpdate(server, fullPath, verbose);
|
|
230
222
|
res.end(JSON.stringify({ success: true, filePath }));
|
|
231
223
|
} catch (error) {
|
|
232
224
|
res.statusCode = 500;
|
|
@@ -473,30 +465,6 @@ function componentCompiler(options = {}) {
|
|
|
473
465
|
console.log(`[DesignMode] Virtual code API enabled at ${designModeOptions.virtualCodeApiPath}`);
|
|
474
466
|
}
|
|
475
467
|
},
|
|
476
|
-
/**
|
|
477
|
-
* 处理 HMR 更新:
|
|
478
|
-
* 当文件变更被 Vite file watcher 检测到时,如果该文件已有虚拟代码,
|
|
479
|
-
* 则拦截 Vite 的默认 HMR 处理,返回空数组阻止重复/冲突的 HMR 更新。
|
|
480
|
-
*
|
|
481
|
-
* 背景:Design Mode 使用双通道同步机制:
|
|
482
|
-
* 1. 虚拟代码通道:通过 /api/virtual-code POST → triggerHmrUpdate 触发 HMR
|
|
483
|
-
* 2. 磁盘写入通道:干净代码写入磁盘 → Vite file watcher 检测到变化
|
|
484
|
-
*
|
|
485
|
-
* 如果不拦截通道 2 触发的 HMR,两次 HMR 之间可能产生竞态条件:
|
|
486
|
-
* - triggerHmrUpdate 先 invalidateModule 重置了 isSelfAccepting
|
|
487
|
-
* - file watcher 触发的 HMR 在模块重新 transform 前执行 propagateUpdate
|
|
488
|
-
* - propagateUpdate 发现 isSelfAccepting === undefined,停止传播
|
|
489
|
-
* - 导致 "no update happened",样式修改不生效
|
|
490
|
-
*/
|
|
491
|
-
handleHotUpdate(ctx) {
|
|
492
|
-
if (!designModeOptions.enableVirtualCode) return;
|
|
493
|
-
if (hasVirtualCodeByAbsolutePath(ctx.file, projectRoot)) {
|
|
494
|
-
if (designModeOptions.verbose) {
|
|
495
|
-
console.log(`[DesignMode] Intercepted file watcher HMR for: ${ctx.file} (managed by virtual code)`);
|
|
496
|
-
}
|
|
497
|
-
return [];
|
|
498
|
-
}
|
|
499
|
-
},
|
|
500
468
|
/**
|
|
501
469
|
* 转换 index.html:
|
|
502
470
|
* 1. 在 <body> 标签上注入组件库版本信息和编译插件版本
|