@lark-apaas/devtool-kits 1.2.19 → 1.2.20
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-api-routes.cjs +189 -0
- package/dist/bin/generate-api-routes.cjs.map +1 -0
- package/dist/bin/generate-api-routes.d.cts +1 -0
- package/dist/bin/generate-api-routes.d.ts +1 -0
- package/dist/bin/generate-api-routes.js +43 -0
- package/dist/bin/generate-api-routes.js.map +1 -0
- package/dist/bin/generate-page-routes.cjs +227 -0
- package/dist/bin/generate-page-routes.cjs.map +1 -0
- package/dist/bin/generate-page-routes.d.cts +1 -0
- package/dist/bin/generate-page-routes.d.ts +1 -0
- package/dist/bin/generate-page-routes.js +43 -0
- package/dist/bin/generate-page-routes.js.map +1 -0
- package/dist/chunk-7QVYU63E.js +7 -0
- package/dist/chunk-7QVYU63E.js.map +1 -0
- package/dist/chunk-LSHFHCDF.js +350 -0
- package/dist/chunk-LSHFHCDF.js.map +1 -0
- package/dist/chunk-YPNLFWHQ.js +189 -0
- package/dist/chunk-YPNLFWHQ.js.map +1 -0
- package/dist/index.cjs +332 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -3
- package/dist/index.d.ts +39 -3
- package/dist/index.js +67 -271
- package/dist/index.js.map +1 -1
- package/package.json +9 -2
package/dist/index.cjs
CHANGED
|
@@ -31,16 +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,
|
|
47
|
+
parseApiRoutes: () => parseApiRoutes,
|
|
48
|
+
parseRoutesFromFile: () => parseRoutesFromFile,
|
|
42
49
|
postprocessDrizzleSchema: () => postprocessDrizzleSchema,
|
|
43
50
|
registerMiddlewares: () => registerMiddlewares,
|
|
51
|
+
routeParserLog: () => routeParserLog,
|
|
44
52
|
sendError: () => sendError,
|
|
45
53
|
sendJson: () => sendJson,
|
|
46
54
|
sendSuccess: () => sendSuccess
|
|
@@ -1281,7 +1289,7 @@ function isConnectionError(err) {
|
|
|
1281
1289
|
}
|
|
1282
1290
|
__name(isConnectionError, "isConnectionError");
|
|
1283
1291
|
function checkServiceAvailable(targetUrl, timeout = 2e3) {
|
|
1284
|
-
return new Promise((
|
|
1292
|
+
return new Promise((resolve2) => {
|
|
1285
1293
|
try {
|
|
1286
1294
|
const url = new URL(targetUrl);
|
|
1287
1295
|
const isHttps = url.protocol === "https:";
|
|
@@ -1293,18 +1301,18 @@ function checkServiceAvailable(targetUrl, timeout = 2e3) {
|
|
|
1293
1301
|
method: "HEAD",
|
|
1294
1302
|
timeout
|
|
1295
1303
|
}, (res) => {
|
|
1296
|
-
|
|
1304
|
+
resolve2(res.statusCode !== 502);
|
|
1297
1305
|
});
|
|
1298
1306
|
req.on("timeout", () => {
|
|
1299
1307
|
req.destroy();
|
|
1300
|
-
|
|
1308
|
+
resolve2(false);
|
|
1301
1309
|
});
|
|
1302
1310
|
req.on("error", () => {
|
|
1303
|
-
|
|
1311
|
+
resolve2(false);
|
|
1304
1312
|
});
|
|
1305
1313
|
req.end();
|
|
1306
1314
|
} catch {
|
|
1307
|
-
|
|
1315
|
+
resolve2(false);
|
|
1308
1316
|
}
|
|
1309
1317
|
});
|
|
1310
1318
|
}
|
|
@@ -1316,7 +1324,7 @@ async function waitForServiceRecovery(targetUrl, timeout, interval) {
|
|
|
1316
1324
|
if (isAvailable) {
|
|
1317
1325
|
return true;
|
|
1318
1326
|
}
|
|
1319
|
-
await new Promise((
|
|
1327
|
+
await new Promise((resolve2) => setTimeout(resolve2, interval));
|
|
1320
1328
|
}
|
|
1321
1329
|
return false;
|
|
1322
1330
|
}
|
|
@@ -1386,6 +1394,7 @@ var import_node_crypto = __toESM(require("crypto"), 1);
|
|
|
1386
1394
|
|
|
1387
1395
|
// src/middlewares/openapi/services.ts
|
|
1388
1396
|
var import_node_fs4 = require("fs");
|
|
1397
|
+
var fsSync = __toESM(require("fs"), 1);
|
|
1389
1398
|
var import_node_path4 = __toESM(require("path"), 1);
|
|
1390
1399
|
var import_typescript = __toESM(require("typescript"), 1);
|
|
1391
1400
|
|
|
@@ -1608,6 +1617,120 @@ function extractControllerMetadata(sourceFile, filePath) {
|
|
|
1608
1617
|
return metadata;
|
|
1609
1618
|
}
|
|
1610
1619
|
__name(extractControllerMetadata, "extractControllerMetadata");
|
|
1620
|
+
var HTTP_DECORATOR_NAMES = [
|
|
1621
|
+
"Get",
|
|
1622
|
+
"Post",
|
|
1623
|
+
"Put",
|
|
1624
|
+
"Delete",
|
|
1625
|
+
"Patch",
|
|
1626
|
+
"Options",
|
|
1627
|
+
"Head",
|
|
1628
|
+
"All"
|
|
1629
|
+
];
|
|
1630
|
+
function findControllerFilesSync(dir) {
|
|
1631
|
+
const files = [];
|
|
1632
|
+
function scan(currentDir) {
|
|
1633
|
+
let entries;
|
|
1634
|
+
try {
|
|
1635
|
+
entries = fsSync.readdirSync(currentDir, {
|
|
1636
|
+
withFileTypes: true
|
|
1637
|
+
});
|
|
1638
|
+
} catch {
|
|
1639
|
+
return;
|
|
1640
|
+
}
|
|
1641
|
+
for (const entry of entries) {
|
|
1642
|
+
const fullPath = import_node_path4.default.join(currentDir, entry.name);
|
|
1643
|
+
if (entry.isDirectory()) {
|
|
1644
|
+
scan(fullPath);
|
|
1645
|
+
} else if (entry.isFile() && entry.name.endsWith(".controller.ts")) {
|
|
1646
|
+
files.push(fullPath);
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
__name(scan, "scan");
|
|
1651
|
+
scan(dir);
|
|
1652
|
+
return files;
|
|
1653
|
+
}
|
|
1654
|
+
__name(findControllerFilesSync, "findControllerFilesSync");
|
|
1655
|
+
function normalizeApiPath(controllerPath, routePath) {
|
|
1656
|
+
const combined = routePath ? `${controllerPath}/${routePath}` : controllerPath;
|
|
1657
|
+
let normalized = combined.replace(/\/+/g, "/");
|
|
1658
|
+
if (!normalized.startsWith("/")) normalized = `/${normalized}`;
|
|
1659
|
+
if (normalized.length > 1 && normalized.endsWith("/")) normalized = normalized.slice(0, -1);
|
|
1660
|
+
return normalized;
|
|
1661
|
+
}
|
|
1662
|
+
__name(normalizeApiPath, "normalizeApiPath");
|
|
1663
|
+
function parseControllerRoutes(filePath) {
|
|
1664
|
+
let content;
|
|
1665
|
+
try {
|
|
1666
|
+
content = fsSync.readFileSync(filePath, "utf-8");
|
|
1667
|
+
} catch {
|
|
1668
|
+
return [];
|
|
1669
|
+
}
|
|
1670
|
+
const sourceFile = import_typescript.default.createSourceFile(filePath, content, import_typescript.default.ScriptTarget.Latest, true);
|
|
1671
|
+
const routes = [];
|
|
1672
|
+
function getDecoratorsCompat(node) {
|
|
1673
|
+
if ("modifiers" in node && Array.isArray(node.modifiers)) {
|
|
1674
|
+
return node.modifiers.filter((mod) => mod.kind === import_typescript.default.SyntaxKind.Decorator);
|
|
1675
|
+
}
|
|
1676
|
+
if ("decorators" in node && Array.isArray(node.decorators)) {
|
|
1677
|
+
return node.decorators;
|
|
1678
|
+
}
|
|
1679
|
+
return [];
|
|
1680
|
+
}
|
|
1681
|
+
__name(getDecoratorsCompat, "getDecoratorsCompat");
|
|
1682
|
+
function getStringArg(expr) {
|
|
1683
|
+
if (expr.arguments.length > 0 && import_typescript.default.isStringLiteral(expr.arguments[0])) {
|
|
1684
|
+
return expr.arguments[0].text;
|
|
1685
|
+
}
|
|
1686
|
+
return "";
|
|
1687
|
+
}
|
|
1688
|
+
__name(getStringArg, "getStringArg");
|
|
1689
|
+
function visit(node) {
|
|
1690
|
+
if (import_typescript.default.isClassDeclaration(node)) {
|
|
1691
|
+
let controllerPath = "";
|
|
1692
|
+
for (const dec of getDecoratorsCompat(node)) {
|
|
1693
|
+
if (import_typescript.default.isCallExpression(dec.expression)) {
|
|
1694
|
+
const name = dec.expression.expression.getText(sourceFile);
|
|
1695
|
+
if (name === "Controller") {
|
|
1696
|
+
controllerPath = getStringArg(dec.expression);
|
|
1697
|
+
break;
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
for (const member of node.members) {
|
|
1702
|
+
if (!import_typescript.default.isMethodDeclaration(member)) continue;
|
|
1703
|
+
for (const dec of getDecoratorsCompat(member)) {
|
|
1704
|
+
if (!import_typescript.default.isCallExpression(dec.expression)) continue;
|
|
1705
|
+
const decoratorName = dec.expression.expression.getText(sourceFile);
|
|
1706
|
+
if (!HTTP_DECORATOR_NAMES.includes(decoratorName)) continue;
|
|
1707
|
+
const routePath = getStringArg(dec.expression);
|
|
1708
|
+
const fullPath = normalizeApiPath(controllerPath, routePath);
|
|
1709
|
+
const method = decoratorName === "All" ? "*" : decoratorName.toUpperCase();
|
|
1710
|
+
routes.push({
|
|
1711
|
+
method,
|
|
1712
|
+
path: fullPath
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
import_typescript.default.forEachChild(node, visit);
|
|
1718
|
+
}
|
|
1719
|
+
__name(visit, "visit");
|
|
1720
|
+
visit(sourceFile);
|
|
1721
|
+
return routes;
|
|
1722
|
+
}
|
|
1723
|
+
__name(parseControllerRoutes, "parseControllerRoutes");
|
|
1724
|
+
function parseApiRoutes(serverDir) {
|
|
1725
|
+
const resolvedDir = import_node_path4.default.resolve(serverDir);
|
|
1726
|
+
const controllerFiles = findControllerFilesSync(resolvedDir);
|
|
1727
|
+
const routes = [];
|
|
1728
|
+
for (const filePath of controllerFiles) {
|
|
1729
|
+
routes.push(...parseControllerRoutes(filePath));
|
|
1730
|
+
}
|
|
1731
|
+
return routes;
|
|
1732
|
+
}
|
|
1733
|
+
__name(parseApiRoutes, "parseApiRoutes");
|
|
1611
1734
|
|
|
1612
1735
|
// src/middlewares/openapi/controller.ts
|
|
1613
1736
|
function createOpenapiHandler(openapiFilePath, enableEnhancement, serverDir) {
|
|
@@ -1719,8 +1842,8 @@ function hasSpecialPatterns(pattern) {
|
|
|
1719
1842
|
return /[{*]/.test(pattern);
|
|
1720
1843
|
}
|
|
1721
1844
|
__name(hasSpecialPatterns, "hasSpecialPatterns");
|
|
1722
|
-
function normalizePathForMatching(
|
|
1723
|
-
return
|
|
1845
|
+
function normalizePathForMatching(path8) {
|
|
1846
|
+
return path8.replace(/\/+/g, "/").replace(/\/+$/, "");
|
|
1724
1847
|
}
|
|
1725
1848
|
__name(normalizePathForMatching, "normalizePathForMatching");
|
|
1726
1849
|
|
|
@@ -2269,7 +2392,7 @@ __name(readLogsBySource, "readLogsBySource");
|
|
|
2269
2392
|
// src/middlewares/dev-logs/services/trigger.service.ts
|
|
2270
2393
|
var import_node_fs9 = require("fs");
|
|
2271
2394
|
var import_node_readline3 = require("readline");
|
|
2272
|
-
async function readTriggerList(filePath, trigger,
|
|
2395
|
+
async function readTriggerList(filePath, trigger, path8, limit, triggerID) {
|
|
2273
2396
|
if (!await fileExists(filePath)) {
|
|
2274
2397
|
return void 0;
|
|
2275
2398
|
}
|
|
@@ -2295,7 +2418,7 @@ async function readTriggerList(filePath, trigger, path7, limit, triggerID) {
|
|
|
2295
2418
|
if (alreadyAdded) {
|
|
2296
2419
|
return false;
|
|
2297
2420
|
}
|
|
2298
|
-
const isAutomationTrigger = builder.path?.endsWith(
|
|
2421
|
+
const isAutomationTrigger = builder.path?.endsWith(path8);
|
|
2299
2422
|
if (!isAutomationTrigger) {
|
|
2300
2423
|
return false;
|
|
2301
2424
|
}
|
|
@@ -2378,7 +2501,7 @@ async function readTriggerList(filePath, trigger, path7, limit, triggerID) {
|
|
|
2378
2501
|
};
|
|
2379
2502
|
}
|
|
2380
2503
|
__name(readTriggerList, "readTriggerList");
|
|
2381
|
-
async function readTriggerDetail(filePath,
|
|
2504
|
+
async function readTriggerDetail(filePath, path8, instanceID) {
|
|
2382
2505
|
const exists = await fileExists(filePath);
|
|
2383
2506
|
if (!exists) {
|
|
2384
2507
|
return void 0;
|
|
@@ -2394,7 +2517,7 @@ async function readTriggerDetail(filePath, path7, instanceID) {
|
|
|
2394
2517
|
for await (const line of rl) {
|
|
2395
2518
|
const entry = parseLogLine(line);
|
|
2396
2519
|
if (!entry) continue;
|
|
2397
|
-
const isAutomationTrigger = entry.path?.endsWith(
|
|
2520
|
+
const isAutomationTrigger = entry.path?.endsWith(path8);
|
|
2398
2521
|
const hasInstanceID = entry.instance_id === instanceID && entry.trigger;
|
|
2399
2522
|
if (!isAutomationTrigger || !hasInstanceID) continue;
|
|
2400
2523
|
matches.push(entry);
|
|
@@ -2648,16 +2771,16 @@ function createGetTriggerListHandler(logDir) {
|
|
|
2648
2771
|
});
|
|
2649
2772
|
}
|
|
2650
2773
|
const triggerID = typeof req.query.triggerID === "string" ? req.query.triggerID.trim() : void 0;
|
|
2651
|
-
const
|
|
2774
|
+
const path8 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
|
|
2652
2775
|
const limit = parseLimit(req.query.limit, 10, 200);
|
|
2653
2776
|
try {
|
|
2654
|
-
const result = await readTriggerList(traceLogPath, trigger,
|
|
2777
|
+
const result = await readTriggerList(traceLogPath, trigger, path8, limit, triggerID);
|
|
2655
2778
|
if (!result) {
|
|
2656
2779
|
return handleNotFound(res, traceLogPath);
|
|
2657
2780
|
}
|
|
2658
2781
|
res.json({
|
|
2659
2782
|
file: getRelativePath(traceLogPath),
|
|
2660
|
-
path:
|
|
2783
|
+
path: path8,
|
|
2661
2784
|
...result
|
|
2662
2785
|
});
|
|
2663
2786
|
} catch (error) {
|
|
@@ -2675,9 +2798,9 @@ function createGetTriggerDetailHandler(logDir) {
|
|
|
2675
2798
|
message: "instanceID is required"
|
|
2676
2799
|
});
|
|
2677
2800
|
}
|
|
2678
|
-
const
|
|
2801
|
+
const path8 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
|
|
2679
2802
|
try {
|
|
2680
|
-
const result = await readTriggerDetail(traceLogPath,
|
|
2803
|
+
const result = await readTriggerDetail(traceLogPath, path8, instanceID);
|
|
2681
2804
|
if (!result) {
|
|
2682
2805
|
return handleNotFound(res, traceLogPath);
|
|
2683
2806
|
}
|
|
@@ -2720,7 +2843,7 @@ __name(createGetCapabilityTraceListHandler, "createGetCapabilityTraceListHandler
|
|
|
2720
2843
|
// src/middlewares/dev-logs/health.controller.ts
|
|
2721
2844
|
var import_node_http = __toESM(require("http"), 1);
|
|
2722
2845
|
function checkServiceHealth(host, port, timeout) {
|
|
2723
|
-
return new Promise((
|
|
2846
|
+
return new Promise((resolve2) => {
|
|
2724
2847
|
const startTime = Date.now();
|
|
2725
2848
|
const req = import_node_http.default.request({
|
|
2726
2849
|
hostname: host,
|
|
@@ -2730,20 +2853,20 @@ function checkServiceHealth(host, port, timeout) {
|
|
|
2730
2853
|
timeout
|
|
2731
2854
|
}, (_res) => {
|
|
2732
2855
|
const responseTime = Date.now() - startTime;
|
|
2733
|
-
|
|
2856
|
+
resolve2({
|
|
2734
2857
|
available: true,
|
|
2735
2858
|
responseTime
|
|
2736
2859
|
});
|
|
2737
2860
|
});
|
|
2738
2861
|
req.on("timeout", () => {
|
|
2739
2862
|
req.destroy();
|
|
2740
|
-
|
|
2863
|
+
resolve2({
|
|
2741
2864
|
available: false,
|
|
2742
2865
|
error: "Request timeout"
|
|
2743
2866
|
});
|
|
2744
2867
|
});
|
|
2745
2868
|
req.on("error", (err) => {
|
|
2746
|
-
|
|
2869
|
+
resolve2({
|
|
2747
2870
|
available: false,
|
|
2748
2871
|
error: err.message
|
|
2749
2872
|
});
|
|
@@ -3303,8 +3426,8 @@ __name(createSSEHandler, "createSSEHandler");
|
|
|
3303
3426
|
|
|
3304
3427
|
// src/middlewares/dev-logs/api-list-handler.ts
|
|
3305
3428
|
var SERVER_PORT = process.env.SERVER_PORT || "3000";
|
|
3306
|
-
function extractModuleFromPath(
|
|
3307
|
-
const segments =
|
|
3429
|
+
function extractModuleFromPath(path8) {
|
|
3430
|
+
const segments = path8.split("/").filter(Boolean);
|
|
3308
3431
|
let startIndex = 0;
|
|
3309
3432
|
if (segments[0] === "api") {
|
|
3310
3433
|
startIndex = 1;
|
|
@@ -3319,8 +3442,8 @@ function extractModuleFromPath(path7) {
|
|
|
3319
3442
|
return moduleName;
|
|
3320
3443
|
}
|
|
3321
3444
|
__name(extractModuleFromPath, "extractModuleFromPath");
|
|
3322
|
-
function generateRouteId(method,
|
|
3323
|
-
const cleanPath =
|
|
3445
|
+
function generateRouteId(method, path8) {
|
|
3446
|
+
const cleanPath = path8.replace(/[/:]/g, "_").replace(/^_+|_+$/g, "");
|
|
3324
3447
|
return `${method.toLowerCase()}_${cleanPath}`;
|
|
3325
3448
|
}
|
|
3326
3449
|
__name(generateRouteId, "generateRouteId");
|
|
@@ -3571,7 +3694,7 @@ function handleError2(res, error, message = "Failed to collect logs") {
|
|
|
3571
3694
|
__name(handleError2, "handleError");
|
|
3572
3695
|
|
|
3573
3696
|
// src/middlewares/collect-logs/router.ts
|
|
3574
|
-
var DEFAULT_BODY_SIZE_LIMIT = "
|
|
3697
|
+
var DEFAULT_BODY_SIZE_LIMIT = "20mb";
|
|
3575
3698
|
function getBodySizeLimit() {
|
|
3576
3699
|
return process.env.BODY_SIZE_LIMIT || DEFAULT_BODY_SIZE_LIMIT;
|
|
3577
3700
|
}
|
|
@@ -3794,18 +3917,201 @@ async function registerMiddlewares(server, middlewares, options) {
|
|
|
3794
3917
|
}
|
|
3795
3918
|
}
|
|
3796
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");
|
|
3797
4095
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3798
4096
|
0 && (module.exports = {
|
|
4097
|
+
buildFullPath,
|
|
4098
|
+
calculateFileHash,
|
|
3799
4099
|
createCollectLogsMiddleware,
|
|
3800
4100
|
createDevLogsMiddleware,
|
|
3801
4101
|
createOpenapiMiddleware,
|
|
4102
|
+
evaluateTemplateLiteral,
|
|
4103
|
+
extractPageRouteInfo,
|
|
3802
4104
|
getQuery,
|
|
3803
4105
|
getQueryParam,
|
|
3804
4106
|
handleDevProxyError,
|
|
4107
|
+
isRouteComponent,
|
|
3805
4108
|
normalizeBasePath,
|
|
3806
4109
|
parseAndGenerateNestResourceTemplate,
|
|
4110
|
+
parseApiRoutes,
|
|
4111
|
+
parseRoutesFromFile,
|
|
3807
4112
|
postprocessDrizzleSchema,
|
|
3808
4113
|
registerMiddlewares,
|
|
4114
|
+
routeParserLog,
|
|
3809
4115
|
sendError,
|
|
3810
4116
|
sendJson,
|
|
3811
4117
|
sendSuccess
|