@meituan-nocode/vite-plugin-nocode-compiler 0.3.1-beta.12 → 0.3.1-beta.14
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 +30 -8
- package/dist/index.js +30 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -102,6 +102,9 @@ function safeGetModulesByFile(server, filePath) {
|
|
|
102
102
|
}
|
|
103
103
|
function triggerHmrUpdate(server, fullPath, verbose = false) {
|
|
104
104
|
const modules = server.moduleGraph.getModulesByFile(fullPath);
|
|
105
|
+
if (verbose) {
|
|
106
|
+
console.log(`[triggerHmrUpdate] fullPath=${fullPath}, modulesFound=${modules ? modules.size : 0}`);
|
|
107
|
+
}
|
|
105
108
|
if (modules && modules.size > 0) {
|
|
106
109
|
for (const mod of modules) {
|
|
107
110
|
safeInvalidateModule(server, mod);
|
|
@@ -116,9 +119,6 @@ function triggerHmrUpdate(server, fullPath, verbose = false) {
|
|
|
116
119
|
}
|
|
117
120
|
]
|
|
118
121
|
});
|
|
119
|
-
if (verbose) {
|
|
120
|
-
console.log(`[vite-compat] HMR triggered for: ${mod.url}`);
|
|
121
|
-
}
|
|
122
122
|
}
|
|
123
123
|
} else {
|
|
124
124
|
const mod = server.moduleGraph.getModuleById(fullPath);
|
|
@@ -135,6 +135,8 @@ function triggerHmrUpdate(server, fullPath, verbose = false) {
|
|
|
135
135
|
}
|
|
136
136
|
]
|
|
137
137
|
});
|
|
138
|
+
} else if (verbose) {
|
|
139
|
+
console.warn(`[triggerHmrUpdate] No module found for: ${fullPath}`);
|
|
138
140
|
}
|
|
139
141
|
}
|
|
140
142
|
}
|
|
@@ -178,7 +180,7 @@ function readJsonBody(req) {
|
|
|
178
180
|
}
|
|
179
181
|
|
|
180
182
|
// package.json
|
|
181
|
-
var version = "0.3.1-beta.
|
|
183
|
+
var version = "0.3.1-beta.14";
|
|
182
184
|
|
|
183
185
|
// src/design-mode/types.ts
|
|
184
186
|
var SANDBOX_SCRIPT_PATH = "/sandbox-script.js";
|
|
@@ -210,6 +212,12 @@ function hasVirtualCode(id) {
|
|
|
210
212
|
if (!relativePath) return false;
|
|
211
213
|
return virtualCodeMap.has(relativePath) || virtualCodeMap.has("/" + relativePath);
|
|
212
214
|
}
|
|
215
|
+
function hasVirtualCodeByAbsolutePath(absolutePath, projectRoot) {
|
|
216
|
+
if (virtualCodeMap.size === 0) return false;
|
|
217
|
+
const relativePath = absolutePath.startsWith(projectRoot) ? absolutePath.slice(projectRoot.length).replace(/^\//, "") : null;
|
|
218
|
+
if (!relativePath) return false;
|
|
219
|
+
return virtualCodeMap.has(relativePath) || virtualCodeMap.has("/" + relativePath);
|
|
220
|
+
}
|
|
213
221
|
function shouldSkipDesignModeTransform(id, options) {
|
|
214
222
|
if (!matchesDesignModePattern(id, options)) return true;
|
|
215
223
|
if (hasVirtualCode(id)) return true;
|
|
@@ -221,7 +229,7 @@ function loadVirtualCode(id, options) {
|
|
|
221
229
|
if (!relativePath) return void 0;
|
|
222
230
|
const code = virtualCodeMap.get(relativePath) || virtualCodeMap.get("/" + relativePath);
|
|
223
231
|
if (code && options.verbose) {
|
|
224
|
-
console.log(`[
|
|
232
|
+
console.log(`[loadVirtualCode] Returning virtual code for: ${relativePath} (length=${code.length})`);
|
|
225
233
|
}
|
|
226
234
|
return code;
|
|
227
235
|
}
|
|
@@ -252,10 +260,8 @@ function createVirtualCodeMiddleware(server, options, projectRoot) {
|
|
|
252
260
|
const { filePath, content } = JSON.parse(body);
|
|
253
261
|
virtualCodeMap.set(filePath, content);
|
|
254
262
|
if (verbose) {
|
|
255
|
-
console.log(`[
|
|
263
|
+
console.log(`[VirtualCode POST] filePath=${filePath}, contentLength=${content == null ? void 0 : content.length}, mapSize=${virtualCodeMap.size}`);
|
|
256
264
|
}
|
|
257
|
-
const fullPath = path.resolve(projectRoot, filePath);
|
|
258
|
-
triggerHmrUpdate(server, fullPath, verbose);
|
|
259
265
|
res.end(JSON.stringify({ success: true, filePath }));
|
|
260
266
|
} catch (error) {
|
|
261
267
|
res.statusCode = 500;
|
|
@@ -502,6 +508,22 @@ function componentCompiler(options = {}) {
|
|
|
502
508
|
console.log(`[DesignMode] Virtual code API enabled at ${designModeOptions.virtualCodeApiPath}`);
|
|
503
509
|
}
|
|
504
510
|
},
|
|
511
|
+
/**
|
|
512
|
+
* 处理 HMR 更新:
|
|
513
|
+
* 当磁盘文件变更触发 Vite file watcher 时,如果该文件存在虚拟代码,
|
|
514
|
+
* 让 Vite 原生 HMR 正常执行(不拦截),这样 Vite 内部的 updateModules
|
|
515
|
+
* 会走完整流程(propagateUpdate → 客户端 fetch → load 钩子返回虚拟代码)。
|
|
516
|
+
*
|
|
517
|
+
* 此钩子仅用于诊断日志,不做任何拦截操作。
|
|
518
|
+
*/
|
|
519
|
+
handleHotUpdate(ctx) {
|
|
520
|
+
if (!designModeOptions.enableVirtualCode) return;
|
|
521
|
+
if (hasVirtualCodeByAbsolutePath(ctx.file, projectRoot)) {
|
|
522
|
+
if (designModeOptions.verbose) {
|
|
523
|
+
console.log(`[DesignMode] File watcher HMR for virtual-code file: ${ctx.file} (allowing native HMR)`);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
},
|
|
505
527
|
/**
|
|
506
528
|
* 转换 index.html:
|
|
507
529
|
* 1. 在 <body> 标签上注入组件库版本信息和编译插件版本
|
package/dist/index.js
CHANGED
|
@@ -67,6 +67,9 @@ function safeGetModulesByFile(server, filePath) {
|
|
|
67
67
|
}
|
|
68
68
|
function triggerHmrUpdate(server, fullPath, verbose = false) {
|
|
69
69
|
const modules = server.moduleGraph.getModulesByFile(fullPath);
|
|
70
|
+
if (verbose) {
|
|
71
|
+
console.log(`[triggerHmrUpdate] fullPath=${fullPath}, modulesFound=${modules ? modules.size : 0}`);
|
|
72
|
+
}
|
|
70
73
|
if (modules && modules.size > 0) {
|
|
71
74
|
for (const mod of modules) {
|
|
72
75
|
safeInvalidateModule(server, mod);
|
|
@@ -81,9 +84,6 @@ function triggerHmrUpdate(server, fullPath, verbose = false) {
|
|
|
81
84
|
}
|
|
82
85
|
]
|
|
83
86
|
});
|
|
84
|
-
if (verbose) {
|
|
85
|
-
console.log(`[vite-compat] HMR triggered for: ${mod.url}`);
|
|
86
|
-
}
|
|
87
87
|
}
|
|
88
88
|
} else {
|
|
89
89
|
const mod = server.moduleGraph.getModuleById(fullPath);
|
|
@@ -100,6 +100,8 @@ function triggerHmrUpdate(server, fullPath, verbose = false) {
|
|
|
100
100
|
}
|
|
101
101
|
]
|
|
102
102
|
});
|
|
103
|
+
} else if (verbose) {
|
|
104
|
+
console.warn(`[triggerHmrUpdate] No module found for: ${fullPath}`);
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
107
|
}
|
|
@@ -143,7 +145,7 @@ function readJsonBody(req) {
|
|
|
143
145
|
}
|
|
144
146
|
|
|
145
147
|
// package.json
|
|
146
|
-
var version = "0.3.1-beta.
|
|
148
|
+
var version = "0.3.1-beta.14";
|
|
147
149
|
|
|
148
150
|
// src/design-mode/types.ts
|
|
149
151
|
var SANDBOX_SCRIPT_PATH = "/sandbox-script.js";
|
|
@@ -175,6 +177,12 @@ function hasVirtualCode(id) {
|
|
|
175
177
|
if (!relativePath) return false;
|
|
176
178
|
return virtualCodeMap.has(relativePath) || virtualCodeMap.has("/" + relativePath);
|
|
177
179
|
}
|
|
180
|
+
function hasVirtualCodeByAbsolutePath(absolutePath, projectRoot) {
|
|
181
|
+
if (virtualCodeMap.size === 0) return false;
|
|
182
|
+
const relativePath = absolutePath.startsWith(projectRoot) ? absolutePath.slice(projectRoot.length).replace(/^\//, "") : null;
|
|
183
|
+
if (!relativePath) return false;
|
|
184
|
+
return virtualCodeMap.has(relativePath) || virtualCodeMap.has("/" + relativePath);
|
|
185
|
+
}
|
|
178
186
|
function shouldSkipDesignModeTransform(id, options) {
|
|
179
187
|
if (!matchesDesignModePattern(id, options)) return true;
|
|
180
188
|
if (hasVirtualCode(id)) return true;
|
|
@@ -186,7 +194,7 @@ function loadVirtualCode(id, options) {
|
|
|
186
194
|
if (!relativePath) return void 0;
|
|
187
195
|
const code = virtualCodeMap.get(relativePath) || virtualCodeMap.get("/" + relativePath);
|
|
188
196
|
if (code && options.verbose) {
|
|
189
|
-
console.log(`[
|
|
197
|
+
console.log(`[loadVirtualCode] Returning virtual code for: ${relativePath} (length=${code.length})`);
|
|
190
198
|
}
|
|
191
199
|
return code;
|
|
192
200
|
}
|
|
@@ -217,10 +225,8 @@ function createVirtualCodeMiddleware(server, options, projectRoot) {
|
|
|
217
225
|
const { filePath, content } = JSON.parse(body);
|
|
218
226
|
virtualCodeMap.set(filePath, content);
|
|
219
227
|
if (verbose) {
|
|
220
|
-
console.log(`[
|
|
228
|
+
console.log(`[VirtualCode POST] filePath=${filePath}, contentLength=${content == null ? void 0 : content.length}, mapSize=${virtualCodeMap.size}`);
|
|
221
229
|
}
|
|
222
|
-
const fullPath = path.resolve(projectRoot, filePath);
|
|
223
|
-
triggerHmrUpdate(server, fullPath, verbose);
|
|
224
230
|
res.end(JSON.stringify({ success: true, filePath }));
|
|
225
231
|
} catch (error) {
|
|
226
232
|
res.statusCode = 500;
|
|
@@ -467,6 +473,22 @@ function componentCompiler(options = {}) {
|
|
|
467
473
|
console.log(`[DesignMode] Virtual code API enabled at ${designModeOptions.virtualCodeApiPath}`);
|
|
468
474
|
}
|
|
469
475
|
},
|
|
476
|
+
/**
|
|
477
|
+
* 处理 HMR 更新:
|
|
478
|
+
* 当磁盘文件变更触发 Vite file watcher 时,如果该文件存在虚拟代码,
|
|
479
|
+
* 让 Vite 原生 HMR 正常执行(不拦截),这样 Vite 内部的 updateModules
|
|
480
|
+
* 会走完整流程(propagateUpdate → 客户端 fetch → load 钩子返回虚拟代码)。
|
|
481
|
+
*
|
|
482
|
+
* 此钩子仅用于诊断日志,不做任何拦截操作。
|
|
483
|
+
*/
|
|
484
|
+
handleHotUpdate(ctx) {
|
|
485
|
+
if (!designModeOptions.enableVirtualCode) return;
|
|
486
|
+
if (hasVirtualCodeByAbsolutePath(ctx.file, projectRoot)) {
|
|
487
|
+
if (designModeOptions.verbose) {
|
|
488
|
+
console.log(`[DesignMode] File watcher HMR for virtual-code file: ${ctx.file} (allowing native HMR)`);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
},
|
|
470
492
|
/**
|
|
471
493
|
* 转换 index.html:
|
|
472
494
|
* 1. 在 <body> 标签上注入组件库版本信息和编译插件版本
|