@lark-apaas/devtool-kits 1.2.17-alpha.51 → 1.2.17-alpha.52
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/bin/generate-page-routes.cjs +99 -63
- package/dist/bin/generate-page-routes.cjs.map +1 -1
- package/dist/bin/generate-page-routes.js +5 -132
- package/dist/bin/generate-page-routes.js.map +1 -1
- package/dist/chunk-YPNLFWHQ.js +189 -0
- package/dist/chunk-YPNLFWHQ.js.map +1 -0
- package/dist/index.cjs +214 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/route-parser.ts"],"sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport * as crypto from 'crypto';\nimport { parse } from '@babel/parser';\nimport _traverse from '@babel/traverse';\nimport * as t from '@babel/types';\n\n// Handle CJS default export interop in ESM context\nconst traverse = typeof _traverse === 'function' ? _traverse : (_traverse as any).default;\n\nexport interface PageRouteInfo {\n path?: string;\n index?: boolean;\n [key: string]: unknown;\n}\n\nexport interface ParseRoutesOptions {\n /** If true, prefix all routes with basePath. Default: true */\n applyBasePath?: boolean;\n}\n\nexport function routeParserLog(\n level: 'log' | 'warn' | 'error' | 'info',\n message: string,\n ...args: unknown[]\n): void {\n const prefix = '[route-parser]';\n const logMessage = `${prefix} ${message}`;\n switch (level) {\n case 'warn':\n console.warn(logMessage, ...args);\n break;\n case 'error':\n console.error(logMessage, ...args);\n break;\n case 'info':\n console.info(logMessage, ...args);\n break;\n default:\n console.log(logMessage, ...args);\n }\n}\n\nexport function calculateFileHash(filePath: string): string | null {\n try {\n const content = fs.readFileSync(filePath, 'utf-8');\n return crypto.createHash('md5').update(content).digest('hex');\n } catch (error) {\n routeParserLog('warn', 'Failed to calculate file hash:', (error as Error).message);\n return null;\n }\n}\n\nexport function isRouteComponent(openingElement: t.JSXOpeningElement): boolean {\n return (\n t.isJSXIdentifier(openingElement.name) &&\n openingElement.name.name === 'Route'\n );\n}\n\nexport function evaluateTemplateLiteral(templateLiteral: t.TemplateLiteral): string {\n const quasis = templateLiteral.quasis;\n const expressions = templateLiteral.expressions;\n\n if (quasis.length === 1 && expressions.length === 0) {\n return quasis[0].value.raw;\n }\n\n return quasis.map((q) => q.value.raw).join('');\n}\n\nexport function extractPageRouteInfo(openingElement: t.JSXOpeningElement): PageRouteInfo {\n const routeInfo: PageRouteInfo = {};\n\n openingElement.attributes.forEach((attr) => {\n if (t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name)) {\n const name = attr.name.name;\n let value: unknown;\n\n if (attr.value) {\n if (t.isStringLiteral(attr.value)) {\n value = attr.value.value;\n } else if (t.isJSXExpressionContainer(attr.value)) {\n const expression = attr.value.expression;\n if (t.isStringLiteral(expression)) {\n value = expression.value;\n } else if (t.isTemplateLiteral(expression)) {\n value = evaluateTemplateLiteral(expression);\n } else {\n value = true;\n }\n }\n } else {\n value = true;\n }\n\n routeInfo[name] = value;\n }\n });\n\n return routeInfo;\n}\n\nexport function buildFullPath(\n routeStack: PageRouteInfo[],\n currentRoute: PageRouteInfo\n): string | null {\n let fullPath = '';\n\n for (let i = 0; i < routeStack.length; i++) {\n if (routeStack[i].path) {\n let parentPath = routeStack[i].path!;\n if (!parentPath.startsWith('/')) parentPath = `/${parentPath}`;\n if (parentPath.endsWith('/') && parentPath !== '/') {\n parentPath = parentPath.slice(0, -1);\n }\n\n fullPath += parentPath === '/' ? '' : parentPath;\n }\n }\n\n if (currentRoute.index) {\n return fullPath || '/';\n } else if (currentRoute.path) {\n const routePath = currentRoute.path;\n\n if (routePath === '*') {\n return null;\n }\n\n if (!routePath.startsWith('/')) {\n fullPath = `${fullPath}/${routePath}`;\n } else {\n fullPath = routePath;\n }\n\n if (fullPath === '') fullPath = '/';\n if (!fullPath.startsWith('/')) fullPath = `/${fullPath}`;\n\n return fullPath;\n }\n\n return null;\n}\n\n/**\n * Parse routes from the app file at build time.\n * @param appPath - Path to app.tsx (relative to cwd or absolute)\n * @param basePath - Normalized base path prefix (e.g., '/my_plugin', or '' for no prefix)\n * @param options - Parse options\n * @returns Array of route definitions\n */\nexport function parseRoutesFromFile(\n appPath: string,\n basePath: string,\n options: ParseRoutesOptions = {}\n): Array<{ path: string }> {\n const { applyBasePath = true } = options;\n const defaultPath = applyBasePath && basePath ? `${basePath}/` : '/';\n\n try {\n const appFilePath = path.resolve(process.cwd(), appPath);\n\n if (!fs.existsSync(appFilePath)) {\n throw new Error(`App file does not exist: ${appFilePath}`);\n }\n\n const sourceCode = fs.readFileSync(appFilePath, 'utf-8');\n\n const ast = parse(sourceCode, {\n sourceType: 'module',\n plugins: [\n 'jsx',\n 'typescript',\n 'decorators-legacy',\n 'classProperties',\n 'objectRestSpread',\n 'functionBind',\n 'exportDefaultFrom',\n 'exportNamespaceFrom',\n 'dynamicImport',\n 'nullishCoalescingOperator',\n 'optionalChaining',\n ],\n });\n\n const routeSet = new Set<string>();\n const routeStack: PageRouteInfo[] = [];\n\n traverse(ast, {\n JSXElement: {\n enter(nodePath: any) {\n const { openingElement } = nodePath.node;\n if (isRouteComponent(openingElement)) {\n routeStack.push(extractPageRouteInfo(openingElement));\n }\n },\n exit(nodePath: any) {\n const { openingElement } = nodePath.node;\n if (isRouteComponent(openingElement)) {\n const currentRoute = routeStack.pop();\n if (currentRoute && currentRoute.path === '*') return;\n if (currentRoute && (currentRoute.path || currentRoute.index)) {\n const fullPath = buildFullPath(routeStack, currentRoute);\n if (fullPath) routeSet.add(fullPath);\n }\n }\n },\n },\n });\n\n const routes = Array.from(routeSet).map((routePath) => ({\n path: applyBasePath && basePath ? `${basePath}${routePath}` : routePath,\n }));\n return routes.length > 0 ? routes : [{ path: defaultPath }];\n } catch (error) {\n routeParserLog('warn', 'Route parsing failed, using default routes:', (error as Error).message);\n return [{ path: default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,cAAcC,YAAYC,YAAAA;AAC3C,kBAAIC,SAAU0B,UAASS,IAAInC,QAAAA;YAC7B;UACF;QACF;MACF;IACF,CAAA;AAEA,UAAMoC,SAASC,MAAMC,KAAKZ,QAAAA,EAAU1C,IAAI,CAACwB,eAAe;MACtDN,MAAMW,iBAAiBF,WAAW,GAAGA,QAAAA,GAAWH,SAAAA,KAAcA;IAChE,EAAA;AACA,WAAO4B,OAAOvD,SAAS,IAAIuD,SAAS;MAAC;QAAElC,MAAMY;MAAY;;EAC3D,SAASnD,OAAO;AACdR,mBAAe,QAAQ,+CAAgDQ,MAAgBN,OAAO;AAC9F,WAAO;MAAC;QAAE6C,MAAMY;MAAY;;EAC9B;AACF;AAnEgBL;","names":["fs","path","crypto","parse","_traverse","t","traverse","_traverse","default","routeParserLog","level","message","args","prefix","logMessage","console","warn","error","info","log","calculateFileHash","filePath","content","readFileSync","createHash","update","digest","isRouteComponent","openingElement","isJSXIdentifier","name","evaluateTemplateLiteral","templateLiteral","quasis","expressions","length","value","raw","map","q","join","extractPageRouteInfo","routeInfo","attributes","forEach","attr","isJSXAttribute","isStringLiteral","isJSXExpressionContainer","expression","isTemplateLiteral","buildFullPath","routeStack","currentRoute","fullPath","i","path","parentPath","startsWith","endsWith","slice","index","routePath","parseRoutesFromFile","appPath","basePath","options","applyBasePath","defaultPath","appFilePath","resolve","process","cwd","existsSync","Error","sourceCode","ast","parse","sourceType","plugins","routeSet","Set","JSXElement","enter","nodePath","node","push","exit","pop","add","routes","Array","from"]}
|
package/dist/index.cjs
CHANGED
|
@@ -31,17 +31,24 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var index_exports = {};
|
|
33
33
|
__export(index_exports, {
|
|
34
|
+
buildFullPath: () => buildFullPath,
|
|
35
|
+
calculateFileHash: () => calculateFileHash,
|
|
34
36
|
createCollectLogsMiddleware: () => createCollectLogsMiddleware,
|
|
35
37
|
createDevLogsMiddleware: () => createDevLogsMiddleware,
|
|
36
38
|
createOpenapiMiddleware: () => createOpenapiMiddleware,
|
|
39
|
+
evaluateTemplateLiteral: () => evaluateTemplateLiteral,
|
|
40
|
+
extractPageRouteInfo: () => extractPageRouteInfo,
|
|
37
41
|
getQuery: () => getQuery,
|
|
38
42
|
getQueryParam: () => getQueryParam,
|
|
39
43
|
handleDevProxyError: () => handleDevProxyError,
|
|
44
|
+
isRouteComponent: () => isRouteComponent,
|
|
40
45
|
normalizeBasePath: () => normalizeBasePath,
|
|
41
46
|
parseAndGenerateNestResourceTemplate: () => parseAndGenerateNestResourceTemplate,
|
|
42
47
|
parseApiRoutes: () => parseApiRoutes,
|
|
48
|
+
parseRoutesFromFile: () => parseRoutesFromFile,
|
|
43
49
|
postprocessDrizzleSchema: () => postprocessDrizzleSchema,
|
|
44
50
|
registerMiddlewares: () => registerMiddlewares,
|
|
51
|
+
routeParserLog: () => routeParserLog,
|
|
45
52
|
sendError: () => sendError,
|
|
46
53
|
sendJson: () => sendJson,
|
|
47
54
|
sendSuccess: () => sendSuccess
|
|
@@ -1282,7 +1289,7 @@ function isConnectionError(err) {
|
|
|
1282
1289
|
}
|
|
1283
1290
|
__name(isConnectionError, "isConnectionError");
|
|
1284
1291
|
function checkServiceAvailable(targetUrl, timeout = 2e3) {
|
|
1285
|
-
return new Promise((
|
|
1292
|
+
return new Promise((resolve2) => {
|
|
1286
1293
|
try {
|
|
1287
1294
|
const url = new URL(targetUrl);
|
|
1288
1295
|
const isHttps = url.protocol === "https:";
|
|
@@ -1294,18 +1301,18 @@ function checkServiceAvailable(targetUrl, timeout = 2e3) {
|
|
|
1294
1301
|
method: "HEAD",
|
|
1295
1302
|
timeout
|
|
1296
1303
|
}, (res) => {
|
|
1297
|
-
|
|
1304
|
+
resolve2(res.statusCode !== 502);
|
|
1298
1305
|
});
|
|
1299
1306
|
req.on("timeout", () => {
|
|
1300
1307
|
req.destroy();
|
|
1301
|
-
|
|
1308
|
+
resolve2(false);
|
|
1302
1309
|
});
|
|
1303
1310
|
req.on("error", () => {
|
|
1304
|
-
|
|
1311
|
+
resolve2(false);
|
|
1305
1312
|
});
|
|
1306
1313
|
req.end();
|
|
1307
1314
|
} catch {
|
|
1308
|
-
|
|
1315
|
+
resolve2(false);
|
|
1309
1316
|
}
|
|
1310
1317
|
});
|
|
1311
1318
|
}
|
|
@@ -1317,7 +1324,7 @@ async function waitForServiceRecovery(targetUrl, timeout, interval) {
|
|
|
1317
1324
|
if (isAvailable) {
|
|
1318
1325
|
return true;
|
|
1319
1326
|
}
|
|
1320
|
-
await new Promise((
|
|
1327
|
+
await new Promise((resolve2) => setTimeout(resolve2, interval));
|
|
1321
1328
|
}
|
|
1322
1329
|
return false;
|
|
1323
1330
|
}
|
|
@@ -1835,8 +1842,8 @@ function hasSpecialPatterns(pattern) {
|
|
|
1835
1842
|
return /[{*]/.test(pattern);
|
|
1836
1843
|
}
|
|
1837
1844
|
__name(hasSpecialPatterns, "hasSpecialPatterns");
|
|
1838
|
-
function normalizePathForMatching(
|
|
1839
|
-
return
|
|
1845
|
+
function normalizePathForMatching(path8) {
|
|
1846
|
+
return path8.replace(/\/+/g, "/").replace(/\/+$/, "");
|
|
1840
1847
|
}
|
|
1841
1848
|
__name(normalizePathForMatching, "normalizePathForMatching");
|
|
1842
1849
|
|
|
@@ -2385,7 +2392,7 @@ __name(readLogsBySource, "readLogsBySource");
|
|
|
2385
2392
|
// src/middlewares/dev-logs/services/trigger.service.ts
|
|
2386
2393
|
var import_node_fs9 = require("fs");
|
|
2387
2394
|
var import_node_readline3 = require("readline");
|
|
2388
|
-
async function readTriggerList(filePath, trigger,
|
|
2395
|
+
async function readTriggerList(filePath, trigger, path8, limit, triggerID) {
|
|
2389
2396
|
if (!await fileExists(filePath)) {
|
|
2390
2397
|
return void 0;
|
|
2391
2398
|
}
|
|
@@ -2411,7 +2418,7 @@ async function readTriggerList(filePath, trigger, path7, limit, triggerID) {
|
|
|
2411
2418
|
if (alreadyAdded) {
|
|
2412
2419
|
return false;
|
|
2413
2420
|
}
|
|
2414
|
-
const isAutomationTrigger = builder.path?.endsWith(
|
|
2421
|
+
const isAutomationTrigger = builder.path?.endsWith(path8);
|
|
2415
2422
|
if (!isAutomationTrigger) {
|
|
2416
2423
|
return false;
|
|
2417
2424
|
}
|
|
@@ -2494,7 +2501,7 @@ async function readTriggerList(filePath, trigger, path7, limit, triggerID) {
|
|
|
2494
2501
|
};
|
|
2495
2502
|
}
|
|
2496
2503
|
__name(readTriggerList, "readTriggerList");
|
|
2497
|
-
async function readTriggerDetail(filePath,
|
|
2504
|
+
async function readTriggerDetail(filePath, path8, instanceID) {
|
|
2498
2505
|
const exists = await fileExists(filePath);
|
|
2499
2506
|
if (!exists) {
|
|
2500
2507
|
return void 0;
|
|
@@ -2510,7 +2517,7 @@ async function readTriggerDetail(filePath, path7, instanceID) {
|
|
|
2510
2517
|
for await (const line of rl) {
|
|
2511
2518
|
const entry = parseLogLine(line);
|
|
2512
2519
|
if (!entry) continue;
|
|
2513
|
-
const isAutomationTrigger = entry.path?.endsWith(
|
|
2520
|
+
const isAutomationTrigger = entry.path?.endsWith(path8);
|
|
2514
2521
|
const hasInstanceID = entry.instance_id === instanceID && entry.trigger;
|
|
2515
2522
|
if (!isAutomationTrigger || !hasInstanceID) continue;
|
|
2516
2523
|
matches.push(entry);
|
|
@@ -2764,16 +2771,16 @@ function createGetTriggerListHandler(logDir) {
|
|
|
2764
2771
|
});
|
|
2765
2772
|
}
|
|
2766
2773
|
const triggerID = typeof req.query.triggerID === "string" ? req.query.triggerID.trim() : void 0;
|
|
2767
|
-
const
|
|
2774
|
+
const path8 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
|
|
2768
2775
|
const limit = parseLimit(req.query.limit, 10, 200);
|
|
2769
2776
|
try {
|
|
2770
|
-
const result = await readTriggerList(traceLogPath, trigger,
|
|
2777
|
+
const result = await readTriggerList(traceLogPath, trigger, path8, limit, triggerID);
|
|
2771
2778
|
if (!result) {
|
|
2772
2779
|
return handleNotFound(res, traceLogPath);
|
|
2773
2780
|
}
|
|
2774
2781
|
res.json({
|
|
2775
2782
|
file: getRelativePath(traceLogPath),
|
|
2776
|
-
path:
|
|
2783
|
+
path: path8,
|
|
2777
2784
|
...result
|
|
2778
2785
|
});
|
|
2779
2786
|
} catch (error) {
|
|
@@ -2791,9 +2798,9 @@ function createGetTriggerDetailHandler(logDir) {
|
|
|
2791
2798
|
message: "instanceID is required"
|
|
2792
2799
|
});
|
|
2793
2800
|
}
|
|
2794
|
-
const
|
|
2801
|
+
const path8 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
|
|
2795
2802
|
try {
|
|
2796
|
-
const result = await readTriggerDetail(traceLogPath,
|
|
2803
|
+
const result = await readTriggerDetail(traceLogPath, path8, instanceID);
|
|
2797
2804
|
if (!result) {
|
|
2798
2805
|
return handleNotFound(res, traceLogPath);
|
|
2799
2806
|
}
|
|
@@ -2836,7 +2843,7 @@ __name(createGetCapabilityTraceListHandler, "createGetCapabilityTraceListHandler
|
|
|
2836
2843
|
// src/middlewares/dev-logs/health.controller.ts
|
|
2837
2844
|
var import_node_http = __toESM(require("http"), 1);
|
|
2838
2845
|
function checkServiceHealth(host, port, timeout) {
|
|
2839
|
-
return new Promise((
|
|
2846
|
+
return new Promise((resolve2) => {
|
|
2840
2847
|
const startTime = Date.now();
|
|
2841
2848
|
const req = import_node_http.default.request({
|
|
2842
2849
|
hostname: host,
|
|
@@ -2846,20 +2853,20 @@ function checkServiceHealth(host, port, timeout) {
|
|
|
2846
2853
|
timeout
|
|
2847
2854
|
}, (_res) => {
|
|
2848
2855
|
const responseTime = Date.now() - startTime;
|
|
2849
|
-
|
|
2856
|
+
resolve2({
|
|
2850
2857
|
available: true,
|
|
2851
2858
|
responseTime
|
|
2852
2859
|
});
|
|
2853
2860
|
});
|
|
2854
2861
|
req.on("timeout", () => {
|
|
2855
2862
|
req.destroy();
|
|
2856
|
-
|
|
2863
|
+
resolve2({
|
|
2857
2864
|
available: false,
|
|
2858
2865
|
error: "Request timeout"
|
|
2859
2866
|
});
|
|
2860
2867
|
});
|
|
2861
2868
|
req.on("error", (err) => {
|
|
2862
|
-
|
|
2869
|
+
resolve2({
|
|
2863
2870
|
available: false,
|
|
2864
2871
|
error: err.message
|
|
2865
2872
|
});
|
|
@@ -3419,8 +3426,8 @@ __name(createSSEHandler, "createSSEHandler");
|
|
|
3419
3426
|
|
|
3420
3427
|
// src/middlewares/dev-logs/api-list-handler.ts
|
|
3421
3428
|
var SERVER_PORT = process.env.SERVER_PORT || "3000";
|
|
3422
|
-
function extractModuleFromPath(
|
|
3423
|
-
const segments =
|
|
3429
|
+
function extractModuleFromPath(path8) {
|
|
3430
|
+
const segments = path8.split("/").filter(Boolean);
|
|
3424
3431
|
let startIndex = 0;
|
|
3425
3432
|
if (segments[0] === "api") {
|
|
3426
3433
|
startIndex = 1;
|
|
@@ -3435,8 +3442,8 @@ function extractModuleFromPath(path7) {
|
|
|
3435
3442
|
return moduleName;
|
|
3436
3443
|
}
|
|
3437
3444
|
__name(extractModuleFromPath, "extractModuleFromPath");
|
|
3438
|
-
function generateRouteId(method,
|
|
3439
|
-
const cleanPath =
|
|
3445
|
+
function generateRouteId(method, path8) {
|
|
3446
|
+
const cleanPath = path8.replace(/[/:]/g, "_").replace(/^_+|_+$/g, "");
|
|
3440
3447
|
return `${method.toLowerCase()}_${cleanPath}`;
|
|
3441
3448
|
}
|
|
3442
3449
|
__name(generateRouteId, "generateRouteId");
|
|
@@ -3910,19 +3917,201 @@ async function registerMiddlewares(server, middlewares, options) {
|
|
|
3910
3917
|
}
|
|
3911
3918
|
}
|
|
3912
3919
|
__name(registerMiddlewares, "registerMiddlewares");
|
|
3920
|
+
|
|
3921
|
+
// src/route-parser.ts
|
|
3922
|
+
var fs11 = __toESM(require("fs"), 1);
|
|
3923
|
+
var path7 = __toESM(require("path"), 1);
|
|
3924
|
+
var crypto2 = __toESM(require("crypto"), 1);
|
|
3925
|
+
var import_parser = require("@babel/parser");
|
|
3926
|
+
var import_traverse = __toESM(require("@babel/traverse"), 1);
|
|
3927
|
+
var t = __toESM(require("@babel/types"), 1);
|
|
3928
|
+
var traverse = typeof import_traverse.default === "function" ? import_traverse.default : import_traverse.default.default;
|
|
3929
|
+
function routeParserLog(level, message, ...args) {
|
|
3930
|
+
const prefix = "[route-parser]";
|
|
3931
|
+
const logMessage = `${prefix} ${message}`;
|
|
3932
|
+
switch (level) {
|
|
3933
|
+
case "warn":
|
|
3934
|
+
console.warn(logMessage, ...args);
|
|
3935
|
+
break;
|
|
3936
|
+
case "error":
|
|
3937
|
+
console.error(logMessage, ...args);
|
|
3938
|
+
break;
|
|
3939
|
+
case "info":
|
|
3940
|
+
console.info(logMessage, ...args);
|
|
3941
|
+
break;
|
|
3942
|
+
default:
|
|
3943
|
+
console.log(logMessage, ...args);
|
|
3944
|
+
}
|
|
3945
|
+
}
|
|
3946
|
+
__name(routeParserLog, "routeParserLog");
|
|
3947
|
+
function calculateFileHash(filePath) {
|
|
3948
|
+
try {
|
|
3949
|
+
const content = fs11.readFileSync(filePath, "utf-8");
|
|
3950
|
+
return crypto2.createHash("md5").update(content).digest("hex");
|
|
3951
|
+
} catch (error) {
|
|
3952
|
+
routeParserLog("warn", "Failed to calculate file hash:", error.message);
|
|
3953
|
+
return null;
|
|
3954
|
+
}
|
|
3955
|
+
}
|
|
3956
|
+
__name(calculateFileHash, "calculateFileHash");
|
|
3957
|
+
function isRouteComponent(openingElement) {
|
|
3958
|
+
return t.isJSXIdentifier(openingElement.name) && openingElement.name.name === "Route";
|
|
3959
|
+
}
|
|
3960
|
+
__name(isRouteComponent, "isRouteComponent");
|
|
3961
|
+
function evaluateTemplateLiteral(templateLiteral) {
|
|
3962
|
+
const quasis = templateLiteral.quasis;
|
|
3963
|
+
const expressions = templateLiteral.expressions;
|
|
3964
|
+
if (quasis.length === 1 && expressions.length === 0) {
|
|
3965
|
+
return quasis[0].value.raw;
|
|
3966
|
+
}
|
|
3967
|
+
return quasis.map((q) => q.value.raw).join("");
|
|
3968
|
+
}
|
|
3969
|
+
__name(evaluateTemplateLiteral, "evaluateTemplateLiteral");
|
|
3970
|
+
function extractPageRouteInfo(openingElement) {
|
|
3971
|
+
const routeInfo = {};
|
|
3972
|
+
openingElement.attributes.forEach((attr) => {
|
|
3973
|
+
if (t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name)) {
|
|
3974
|
+
const name = attr.name.name;
|
|
3975
|
+
let value;
|
|
3976
|
+
if (attr.value) {
|
|
3977
|
+
if (t.isStringLiteral(attr.value)) {
|
|
3978
|
+
value = attr.value.value;
|
|
3979
|
+
} else if (t.isJSXExpressionContainer(attr.value)) {
|
|
3980
|
+
const expression = attr.value.expression;
|
|
3981
|
+
if (t.isStringLiteral(expression)) {
|
|
3982
|
+
value = expression.value;
|
|
3983
|
+
} else if (t.isTemplateLiteral(expression)) {
|
|
3984
|
+
value = evaluateTemplateLiteral(expression);
|
|
3985
|
+
} else {
|
|
3986
|
+
value = true;
|
|
3987
|
+
}
|
|
3988
|
+
}
|
|
3989
|
+
} else {
|
|
3990
|
+
value = true;
|
|
3991
|
+
}
|
|
3992
|
+
routeInfo[name] = value;
|
|
3993
|
+
}
|
|
3994
|
+
});
|
|
3995
|
+
return routeInfo;
|
|
3996
|
+
}
|
|
3997
|
+
__name(extractPageRouteInfo, "extractPageRouteInfo");
|
|
3998
|
+
function buildFullPath(routeStack, currentRoute) {
|
|
3999
|
+
let fullPath = "";
|
|
4000
|
+
for (let i = 0; i < routeStack.length; i++) {
|
|
4001
|
+
if (routeStack[i].path) {
|
|
4002
|
+
let parentPath = routeStack[i].path;
|
|
4003
|
+
if (!parentPath.startsWith("/")) parentPath = `/${parentPath}`;
|
|
4004
|
+
if (parentPath.endsWith("/") && parentPath !== "/") {
|
|
4005
|
+
parentPath = parentPath.slice(0, -1);
|
|
4006
|
+
}
|
|
4007
|
+
fullPath += parentPath === "/" ? "" : parentPath;
|
|
4008
|
+
}
|
|
4009
|
+
}
|
|
4010
|
+
if (currentRoute.index) {
|
|
4011
|
+
return fullPath || "/";
|
|
4012
|
+
} else if (currentRoute.path) {
|
|
4013
|
+
const routePath = currentRoute.path;
|
|
4014
|
+
if (routePath === "*") {
|
|
4015
|
+
return null;
|
|
4016
|
+
}
|
|
4017
|
+
if (!routePath.startsWith("/")) {
|
|
4018
|
+
fullPath = `${fullPath}/${routePath}`;
|
|
4019
|
+
} else {
|
|
4020
|
+
fullPath = routePath;
|
|
4021
|
+
}
|
|
4022
|
+
if (fullPath === "") fullPath = "/";
|
|
4023
|
+
if (!fullPath.startsWith("/")) fullPath = `/${fullPath}`;
|
|
4024
|
+
return fullPath;
|
|
4025
|
+
}
|
|
4026
|
+
return null;
|
|
4027
|
+
}
|
|
4028
|
+
__name(buildFullPath, "buildFullPath");
|
|
4029
|
+
function parseRoutesFromFile(appPath, basePath, options = {}) {
|
|
4030
|
+
const { applyBasePath = true } = options;
|
|
4031
|
+
const defaultPath = applyBasePath && basePath ? `${basePath}/` : "/";
|
|
4032
|
+
try {
|
|
4033
|
+
const appFilePath = path7.resolve(process.cwd(), appPath);
|
|
4034
|
+
if (!fs11.existsSync(appFilePath)) {
|
|
4035
|
+
throw new Error(`App file does not exist: ${appFilePath}`);
|
|
4036
|
+
}
|
|
4037
|
+
const sourceCode = fs11.readFileSync(appFilePath, "utf-8");
|
|
4038
|
+
const ast = (0, import_parser.parse)(sourceCode, {
|
|
4039
|
+
sourceType: "module",
|
|
4040
|
+
plugins: [
|
|
4041
|
+
"jsx",
|
|
4042
|
+
"typescript",
|
|
4043
|
+
"decorators-legacy",
|
|
4044
|
+
"classProperties",
|
|
4045
|
+
"objectRestSpread",
|
|
4046
|
+
"functionBind",
|
|
4047
|
+
"exportDefaultFrom",
|
|
4048
|
+
"exportNamespaceFrom",
|
|
4049
|
+
"dynamicImport",
|
|
4050
|
+
"nullishCoalescingOperator",
|
|
4051
|
+
"optionalChaining"
|
|
4052
|
+
]
|
|
4053
|
+
});
|
|
4054
|
+
const routeSet = /* @__PURE__ */ new Set();
|
|
4055
|
+
const routeStack = [];
|
|
4056
|
+
traverse(ast, {
|
|
4057
|
+
JSXElement: {
|
|
4058
|
+
enter(nodePath) {
|
|
4059
|
+
const { openingElement } = nodePath.node;
|
|
4060
|
+
if (isRouteComponent(openingElement)) {
|
|
4061
|
+
routeStack.push(extractPageRouteInfo(openingElement));
|
|
4062
|
+
}
|
|
4063
|
+
},
|
|
4064
|
+
exit(nodePath) {
|
|
4065
|
+
const { openingElement } = nodePath.node;
|
|
4066
|
+
if (isRouteComponent(openingElement)) {
|
|
4067
|
+
const currentRoute = routeStack.pop();
|
|
4068
|
+
if (currentRoute && currentRoute.path === "*") return;
|
|
4069
|
+
if (currentRoute && (currentRoute.path || currentRoute.index)) {
|
|
4070
|
+
const fullPath = buildFullPath(routeStack, currentRoute);
|
|
4071
|
+
if (fullPath) routeSet.add(fullPath);
|
|
4072
|
+
}
|
|
4073
|
+
}
|
|
4074
|
+
}
|
|
4075
|
+
}
|
|
4076
|
+
});
|
|
4077
|
+
const routes = Array.from(routeSet).map((routePath) => ({
|
|
4078
|
+
path: applyBasePath && basePath ? `${basePath}${routePath}` : routePath
|
|
4079
|
+
}));
|
|
4080
|
+
return routes.length > 0 ? routes : [
|
|
4081
|
+
{
|
|
4082
|
+
path: defaultPath
|
|
4083
|
+
}
|
|
4084
|
+
];
|
|
4085
|
+
} catch (error) {
|
|
4086
|
+
routeParserLog("warn", "Route parsing failed, using default routes:", error.message);
|
|
4087
|
+
return [
|
|
4088
|
+
{
|
|
4089
|
+
path: defaultPath
|
|
4090
|
+
}
|
|
4091
|
+
];
|
|
4092
|
+
}
|
|
4093
|
+
}
|
|
4094
|
+
__name(parseRoutesFromFile, "parseRoutesFromFile");
|
|
3913
4095
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3914
4096
|
0 && (module.exports = {
|
|
4097
|
+
buildFullPath,
|
|
4098
|
+
calculateFileHash,
|
|
3915
4099
|
createCollectLogsMiddleware,
|
|
3916
4100
|
createDevLogsMiddleware,
|
|
3917
4101
|
createOpenapiMiddleware,
|
|
4102
|
+
evaluateTemplateLiteral,
|
|
4103
|
+
extractPageRouteInfo,
|
|
3918
4104
|
getQuery,
|
|
3919
4105
|
getQueryParam,
|
|
3920
4106
|
handleDevProxyError,
|
|
4107
|
+
isRouteComponent,
|
|
3921
4108
|
normalizeBasePath,
|
|
3922
4109
|
parseAndGenerateNestResourceTemplate,
|
|
3923
4110
|
parseApiRoutes,
|
|
4111
|
+
parseRoutesFromFile,
|
|
3924
4112
|
postprocessDrizzleSchema,
|
|
3925
4113
|
registerMiddlewares,
|
|
4114
|
+
routeParserLog,
|
|
3926
4115
|
sendError,
|
|
3927
4116
|
sendJson,
|
|
3928
4117
|
sendSuccess
|