miaoda-react-devkit 0.1.1-beta.11 → 0.1.1-beta.12
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/vite/index.cjs +50 -59
- package/dist/vite/index.js +50 -59
- package/package.json +1 -1
package/dist/vite/index.cjs
CHANGED
|
@@ -214,6 +214,51 @@ var collectDeps = (mod, seen = /* @__PURE__ */ new Set()) => {
|
|
|
214
214
|
|
|
215
215
|
// src/vite/extractRouterPlugin/routeTransform.ts
|
|
216
216
|
var t2 = __toESM(require("@babel/types"), 1);
|
|
217
|
+
var findResolvableJSXComponent = (jsxEl, importMap, lazyImportMap) => {
|
|
218
|
+
const dfs = (el, map) => {
|
|
219
|
+
const nameNode = el.openingElement.name;
|
|
220
|
+
if (t2.isJSXIdentifier(nameNode) && map.has(nameNode.name)) return nameNode.name;
|
|
221
|
+
for (const child of el.children) {
|
|
222
|
+
if (t2.isJSXElement(child)) {
|
|
223
|
+
const found = dfs(child, map);
|
|
224
|
+
if (found) return found;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return "";
|
|
228
|
+
};
|
|
229
|
+
return dfs(jsxEl, lazyImportMap) || dfs(jsxEl, importMap) || (t2.isJSXIdentifier(jsxEl.openingElement.name) ? jsxEl.openingElement.name.name : "");
|
|
230
|
+
};
|
|
231
|
+
var eachTree = (tree, iterator, level = 1, parents = []) => {
|
|
232
|
+
for (let i = 0; i < tree.length; i++) {
|
|
233
|
+
const item = tree[i];
|
|
234
|
+
const result = iterator(item, i, level, parents);
|
|
235
|
+
if (result === "break") break;
|
|
236
|
+
if (result === "continue") continue;
|
|
237
|
+
if (Array.isArray(item.children)) {
|
|
238
|
+
eachTree(item.children, iterator, level + 1, parents.concat(item));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
var flattenTree = (tree, mapper) => {
|
|
243
|
+
const result = [];
|
|
244
|
+
eachTree(tree, (item, index, level, parents) => result.push(mapper(item, index, level, parents)));
|
|
245
|
+
return result;
|
|
246
|
+
};
|
|
247
|
+
var flattenRouteTree = (routes) => {
|
|
248
|
+
return flattenTree(routes, (item) => {
|
|
249
|
+
if ("pageId" in item) return item;
|
|
250
|
+
return {
|
|
251
|
+
title: item.title,
|
|
252
|
+
pageId: item.path,
|
|
253
|
+
pageName: item.path
|
|
254
|
+
};
|
|
255
|
+
});
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// src/vite/extractRouterPlugin/valueResolver.ts
|
|
259
|
+
var t3 = __toESM(require("@babel/types"), 1);
|
|
260
|
+
var import_fs2 = __toESM(require("fs"), 1);
|
|
261
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
217
262
|
|
|
218
263
|
// src/vite/extractRouterPlugin/pathUtils.ts
|
|
219
264
|
var import_fs = __toESM(require("fs"), 1);
|
|
@@ -281,56 +326,7 @@ var normalizeFilePath = (filePath, projectRoot) => {
|
|
|
281
326
|
return normalized.replace(/\.(tsx?|jsx?)$/, "");
|
|
282
327
|
};
|
|
283
328
|
|
|
284
|
-
// src/vite/extractRouterPlugin/routeTransform.ts
|
|
285
|
-
var findResolvableJSXComponent = (jsxEl, importMap, lazyImportMap) => {
|
|
286
|
-
const dfs = (el, map) => {
|
|
287
|
-
const nameNode = el.openingElement.name;
|
|
288
|
-
if (t2.isJSXIdentifier(nameNode) && map.has(nameNode.name)) return nameNode.name;
|
|
289
|
-
for (const child of el.children) {
|
|
290
|
-
if (t2.isJSXElement(child)) {
|
|
291
|
-
const found = dfs(child, map);
|
|
292
|
-
if (found) return found;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
return "";
|
|
296
|
-
};
|
|
297
|
-
return dfs(jsxEl, lazyImportMap) || dfs(jsxEl, importMap) || (t2.isJSXIdentifier(jsxEl.openingElement.name) ? jsxEl.openingElement.name.name : "");
|
|
298
|
-
};
|
|
299
|
-
var eachTree = (tree, iterator, level = 1, parents = []) => {
|
|
300
|
-
for (let i = 0; i < tree.length; i++) {
|
|
301
|
-
const item = tree[i];
|
|
302
|
-
const result = iterator(item, i, level, parents);
|
|
303
|
-
if (result === "break") break;
|
|
304
|
-
if (result === "continue") continue;
|
|
305
|
-
if (Array.isArray(item.children)) {
|
|
306
|
-
eachTree(item.children, iterator, level + 1, parents.concat(item));
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
var flattenTree = (tree, mapper) => {
|
|
311
|
-
const result = [];
|
|
312
|
-
eachTree(tree, (item, index, level, parents) => result.push(mapper(item, index, level, parents)));
|
|
313
|
-
return result;
|
|
314
|
-
};
|
|
315
|
-
var flattenRouteTree = (routes, option) => {
|
|
316
|
-
const { importMap, lazyImportMap, aliasMap } = option;
|
|
317
|
-
return flattenTree(routes, (item) => {
|
|
318
|
-
if ("pageId" in item) return item;
|
|
319
|
-
const componentName = item.filePath;
|
|
320
|
-
const componentPath = lazyImportMap.get(componentName) ?? importMap.get(componentName) ?? "";
|
|
321
|
-
return {
|
|
322
|
-
title: item.title,
|
|
323
|
-
pageId: item.path,
|
|
324
|
-
pageName: item.path,
|
|
325
|
-
path: toSrcPath(componentPath, aliasMap)
|
|
326
|
-
};
|
|
327
|
-
});
|
|
328
|
-
};
|
|
329
|
-
|
|
330
329
|
// src/vite/extractRouterPlugin/valueResolver.ts
|
|
331
|
-
var t3 = __toESM(require("@babel/types"), 1);
|
|
332
|
-
var import_fs2 = __toESM(require("fs"), 1);
|
|
333
|
-
var import_path2 = __toESM(require("path"), 1);
|
|
334
330
|
var parseFileWithImports = async (filePath) => {
|
|
335
331
|
try {
|
|
336
332
|
const code = await import_fs2.default.promises.readFile(filePath, "utf-8");
|
|
@@ -547,12 +543,8 @@ var resolveArrayExpression = async (arrayExpression, currentFilePath, context, o
|
|
|
547
543
|
for (const property of element.properties) {
|
|
548
544
|
if (!t3.isObjectProperty(property)) continue;
|
|
549
545
|
const key = t3.isIdentifier(property.key) ? property.key.name : t3.isStringLiteral(property.key) ? property.key.value : null;
|
|
550
|
-
if (!key || !["path", "name", "title", "
|
|
551
|
-
if (t3.
|
|
552
|
-
obj[key] = property.value.name;
|
|
553
|
-
} else if (t3.isJSXElement(property.value) && key === "element") {
|
|
554
|
-
obj[key] = findResolvableJSXComponent(property.value, option.importMap, option.lazyImportMap);
|
|
555
|
-
} else if (t3.isStringLiteral(property.value)) {
|
|
546
|
+
if (!key || !["path", "name", "title", "children"].includes(key)) continue;
|
|
547
|
+
if (t3.isStringLiteral(property.value)) {
|
|
556
548
|
obj[key] = property.value.value;
|
|
557
549
|
} else if (t3.isIdentifier(property.value)) {
|
|
558
550
|
const propBinding = context.scope.getBinding(property.value.name);
|
|
@@ -573,11 +565,10 @@ var resolveArrayExpression = async (arrayExpression, currentFilePath, context, o
|
|
|
573
565
|
result.push({
|
|
574
566
|
path: obj.path,
|
|
575
567
|
title: obj.title ?? obj.name ?? obj.path,
|
|
576
|
-
filePath: obj.element,
|
|
577
568
|
children: obj.children ?? []
|
|
578
569
|
});
|
|
579
570
|
}
|
|
580
|
-
return [...spreadRoutes, ...flattenRouteTree(result
|
|
571
|
+
return [...spreadRoutes, ...flattenRouteTree(result)];
|
|
581
572
|
};
|
|
582
573
|
var resolveExpressionValue = async (nodePath, expression, id, option) => {
|
|
583
574
|
if (t3.isStringLiteral(expression)) return expression.value;
|
|
@@ -851,9 +842,9 @@ var extractRouterPlugin = () => {
|
|
|
851
842
|
let finalRoute;
|
|
852
843
|
if (prefix && internal._isRelative) {
|
|
853
844
|
const corrected = joinPaths("/", prefix, route.pageId.replace(/^\//, ""));
|
|
854
|
-
finalRoute = { title: corrected, pageId: corrected, pageName: corrected
|
|
845
|
+
finalRoute = { title: corrected, pageId: corrected, pageName: corrected };
|
|
855
846
|
} else {
|
|
856
|
-
finalRoute = { title: route.title, pageId: route.pageId, pageName: route.pageName
|
|
847
|
+
finalRoute = { title: route.title, pageId: route.pageId, pageName: route.pageName };
|
|
857
848
|
}
|
|
858
849
|
if (finalRoute.pageId === "/*" || finalRoute.pageId === "*") continue;
|
|
859
850
|
merged.set(finalRoute.pageId, finalRoute);
|
package/dist/vite/index.js
CHANGED
|
@@ -171,6 +171,51 @@ var collectDeps = (mod, seen = /* @__PURE__ */ new Set()) => {
|
|
|
171
171
|
|
|
172
172
|
// src/vite/extractRouterPlugin/routeTransform.ts
|
|
173
173
|
import * as t2 from "@babel/types";
|
|
174
|
+
var findResolvableJSXComponent = (jsxEl, importMap, lazyImportMap) => {
|
|
175
|
+
const dfs = (el, map) => {
|
|
176
|
+
const nameNode = el.openingElement.name;
|
|
177
|
+
if (t2.isJSXIdentifier(nameNode) && map.has(nameNode.name)) return nameNode.name;
|
|
178
|
+
for (const child of el.children) {
|
|
179
|
+
if (t2.isJSXElement(child)) {
|
|
180
|
+
const found = dfs(child, map);
|
|
181
|
+
if (found) return found;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return "";
|
|
185
|
+
};
|
|
186
|
+
return dfs(jsxEl, lazyImportMap) || dfs(jsxEl, importMap) || (t2.isJSXIdentifier(jsxEl.openingElement.name) ? jsxEl.openingElement.name.name : "");
|
|
187
|
+
};
|
|
188
|
+
var eachTree = (tree, iterator, level = 1, parents = []) => {
|
|
189
|
+
for (let i = 0; i < tree.length; i++) {
|
|
190
|
+
const item = tree[i];
|
|
191
|
+
const result = iterator(item, i, level, parents);
|
|
192
|
+
if (result === "break") break;
|
|
193
|
+
if (result === "continue") continue;
|
|
194
|
+
if (Array.isArray(item.children)) {
|
|
195
|
+
eachTree(item.children, iterator, level + 1, parents.concat(item));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
var flattenTree = (tree, mapper) => {
|
|
200
|
+
const result = [];
|
|
201
|
+
eachTree(tree, (item, index, level, parents) => result.push(mapper(item, index, level, parents)));
|
|
202
|
+
return result;
|
|
203
|
+
};
|
|
204
|
+
var flattenRouteTree = (routes) => {
|
|
205
|
+
return flattenTree(routes, (item) => {
|
|
206
|
+
if ("pageId" in item) return item;
|
|
207
|
+
return {
|
|
208
|
+
title: item.title,
|
|
209
|
+
pageId: item.path,
|
|
210
|
+
pageName: item.path
|
|
211
|
+
};
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
// src/vite/extractRouterPlugin/valueResolver.ts
|
|
216
|
+
import * as t3 from "@babel/types";
|
|
217
|
+
import fs2 from "fs";
|
|
218
|
+
import path4 from "path";
|
|
174
219
|
|
|
175
220
|
// src/vite/extractRouterPlugin/pathUtils.ts
|
|
176
221
|
import fs from "fs";
|
|
@@ -238,56 +283,7 @@ var normalizeFilePath = (filePath, projectRoot) => {
|
|
|
238
283
|
return normalized.replace(/\.(tsx?|jsx?)$/, "");
|
|
239
284
|
};
|
|
240
285
|
|
|
241
|
-
// src/vite/extractRouterPlugin/routeTransform.ts
|
|
242
|
-
var findResolvableJSXComponent = (jsxEl, importMap, lazyImportMap) => {
|
|
243
|
-
const dfs = (el, map) => {
|
|
244
|
-
const nameNode = el.openingElement.name;
|
|
245
|
-
if (t2.isJSXIdentifier(nameNode) && map.has(nameNode.name)) return nameNode.name;
|
|
246
|
-
for (const child of el.children) {
|
|
247
|
-
if (t2.isJSXElement(child)) {
|
|
248
|
-
const found = dfs(child, map);
|
|
249
|
-
if (found) return found;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
return "";
|
|
253
|
-
};
|
|
254
|
-
return dfs(jsxEl, lazyImportMap) || dfs(jsxEl, importMap) || (t2.isJSXIdentifier(jsxEl.openingElement.name) ? jsxEl.openingElement.name.name : "");
|
|
255
|
-
};
|
|
256
|
-
var eachTree = (tree, iterator, level = 1, parents = []) => {
|
|
257
|
-
for (let i = 0; i < tree.length; i++) {
|
|
258
|
-
const item = tree[i];
|
|
259
|
-
const result = iterator(item, i, level, parents);
|
|
260
|
-
if (result === "break") break;
|
|
261
|
-
if (result === "continue") continue;
|
|
262
|
-
if (Array.isArray(item.children)) {
|
|
263
|
-
eachTree(item.children, iterator, level + 1, parents.concat(item));
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
var flattenTree = (tree, mapper) => {
|
|
268
|
-
const result = [];
|
|
269
|
-
eachTree(tree, (item, index, level, parents) => result.push(mapper(item, index, level, parents)));
|
|
270
|
-
return result;
|
|
271
|
-
};
|
|
272
|
-
var flattenRouteTree = (routes, option) => {
|
|
273
|
-
const { importMap, lazyImportMap, aliasMap } = option;
|
|
274
|
-
return flattenTree(routes, (item) => {
|
|
275
|
-
if ("pageId" in item) return item;
|
|
276
|
-
const componentName = item.filePath;
|
|
277
|
-
const componentPath = lazyImportMap.get(componentName) ?? importMap.get(componentName) ?? "";
|
|
278
|
-
return {
|
|
279
|
-
title: item.title,
|
|
280
|
-
pageId: item.path,
|
|
281
|
-
pageName: item.path,
|
|
282
|
-
path: toSrcPath(componentPath, aliasMap)
|
|
283
|
-
};
|
|
284
|
-
});
|
|
285
|
-
};
|
|
286
|
-
|
|
287
286
|
// src/vite/extractRouterPlugin/valueResolver.ts
|
|
288
|
-
import * as t3 from "@babel/types";
|
|
289
|
-
import fs2 from "fs";
|
|
290
|
-
import path4 from "path";
|
|
291
287
|
var parseFileWithImports = async (filePath) => {
|
|
292
288
|
try {
|
|
293
289
|
const code = await fs2.promises.readFile(filePath, "utf-8");
|
|
@@ -504,12 +500,8 @@ var resolveArrayExpression = async (arrayExpression, currentFilePath, context, o
|
|
|
504
500
|
for (const property of element.properties) {
|
|
505
501
|
if (!t3.isObjectProperty(property)) continue;
|
|
506
502
|
const key = t3.isIdentifier(property.key) ? property.key.name : t3.isStringLiteral(property.key) ? property.key.value : null;
|
|
507
|
-
if (!key || !["path", "name", "title", "
|
|
508
|
-
if (t3.
|
|
509
|
-
obj[key] = property.value.name;
|
|
510
|
-
} else if (t3.isJSXElement(property.value) && key === "element") {
|
|
511
|
-
obj[key] = findResolvableJSXComponent(property.value, option.importMap, option.lazyImportMap);
|
|
512
|
-
} else if (t3.isStringLiteral(property.value)) {
|
|
503
|
+
if (!key || !["path", "name", "title", "children"].includes(key)) continue;
|
|
504
|
+
if (t3.isStringLiteral(property.value)) {
|
|
513
505
|
obj[key] = property.value.value;
|
|
514
506
|
} else if (t3.isIdentifier(property.value)) {
|
|
515
507
|
const propBinding = context.scope.getBinding(property.value.name);
|
|
@@ -530,11 +522,10 @@ var resolveArrayExpression = async (arrayExpression, currentFilePath, context, o
|
|
|
530
522
|
result.push({
|
|
531
523
|
path: obj.path,
|
|
532
524
|
title: obj.title ?? obj.name ?? obj.path,
|
|
533
|
-
filePath: obj.element,
|
|
534
525
|
children: obj.children ?? []
|
|
535
526
|
});
|
|
536
527
|
}
|
|
537
|
-
return [...spreadRoutes, ...flattenRouteTree(result
|
|
528
|
+
return [...spreadRoutes, ...flattenRouteTree(result)];
|
|
538
529
|
};
|
|
539
530
|
var resolveExpressionValue = async (nodePath, expression, id, option) => {
|
|
540
531
|
if (t3.isStringLiteral(expression)) return expression.value;
|
|
@@ -808,9 +799,9 @@ var extractRouterPlugin = () => {
|
|
|
808
799
|
let finalRoute;
|
|
809
800
|
if (prefix && internal._isRelative) {
|
|
810
801
|
const corrected = joinPaths("/", prefix, route.pageId.replace(/^\//, ""));
|
|
811
|
-
finalRoute = { title: corrected, pageId: corrected, pageName: corrected
|
|
802
|
+
finalRoute = { title: corrected, pageId: corrected, pageName: corrected };
|
|
812
803
|
} else {
|
|
813
|
-
finalRoute = { title: route.title, pageId: route.pageId, pageName: route.pageName
|
|
804
|
+
finalRoute = { title: route.title, pageId: route.pageId, pageName: route.pageName };
|
|
814
805
|
}
|
|
815
806
|
if (finalRoute.pageId === "/*" || finalRoute.pageId === "*") continue;
|
|
816
807
|
merged.set(finalRoute.pageId, finalRoute);
|