@chuckcchen/vite-plugin 1.0.19 → 1.0.21
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/bundler.d.ts +5 -18
- package/dist/bundler.d.ts.map +1 -1
- package/dist/bundler.js +43 -30
- package/dist/bundler.js.map +1 -1
- package/dist/core.d.ts +2 -18
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +125 -248
- package/dist/core.js.map +1 -1
- package/dist/factory/detectors.d.ts +5 -15
- package/dist/factory/detectors.d.ts.map +1 -1
- package/dist/factory/detectors.js +8 -22
- package/dist/factory/detectors.js.map +1 -1
- package/dist/factory/hooks.d.ts +4 -59
- package/dist/factory/hooks.d.ts.map +1 -1
- package/dist/factory/hooks.js +18 -117
- package/dist/factory/hooks.js.map +1 -1
- package/dist/factory/index.d.ts +7 -51
- package/dist/factory/index.d.ts.map +1 -1
- package/dist/factory/index.js +10 -55
- package/dist/factory/index.js.map +1 -1
- package/dist/factory/presets.d.ts +16 -121
- package/dist/factory/presets.d.ts.map +1 -1
- package/dist/factory/presets.js +143 -174
- package/dist/factory/presets.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -35
- package/dist/index.js.map +1 -1
- package/dist/route/index.d.ts +1 -1
- package/dist/route/index.d.ts.map +1 -1
- package/dist/route/index.js +1 -3
- package/dist/route/index.js.map +1 -1
- package/dist/route/parser.d.ts +0 -37
- package/dist/route/parser.d.ts.map +1 -1
- package/dist/route/parser.js +11 -124
- package/dist/route/parser.js.map +1 -1
- package/dist/route/regex.d.ts +15 -80
- package/dist/route/regex.d.ts.map +1 -1
- package/dist/route/regex.js +65 -169
- package/dist/route/regex.js.map +1 -1
- package/dist/route/regex.test.d.ts +7 -0
- package/dist/route/regex.test.d.ts.map +1 -0
- package/dist/route/regex.test.js +662 -0
- package/dist/route/regex.test.js.map +1 -0
- package/dist/route/types.d.ts +0 -58
- package/dist/route/types.d.ts.map +1 -1
- package/dist/types.d.ts +36 -147
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -3
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +1 -78
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +11 -144
- package/dist/utils.js.map +1 -1
- package/dist/vite-config-parser.d.ts +4 -141
- package/dist/vite-config-parser.d.ts.map +1 -1
- package/dist/vite-config-parser.js +25 -235
- package/dist/vite-config-parser.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEvD,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,sBAAsB,GACvB,MAAM,cAAc,CAAC;AAItB,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,eAAe;AACf,2CAA2C;AAC3C,0BAA0B,EAC1B,0BAA0B,EAC1B,4BAA4B,GAC7B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,eAAe,EACf,QAAQ,EACR,SAAS,EACT,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,2BAA2B,EAC3B,yBAAyB,GAC1B,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,0BAA0B,EAC1B,yBAAyB,EACzB,aAAa,EACb,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,yBAAyB,EACzB,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,qBAAqB,EACrB,gBAAgB,EAChB,sBAAsB,EACtB,WAAW,EACX,gBAAgB,GACjB,MAAM,kBAAkB,CAAC"}
|
package/dist/route/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Route Module - Unified exports for route parsing utilities
|
|
3
3
|
*/
|
|
4
4
|
export type { RouteNode, RouteParserConfig, RouteTreeParserOptions, ServerBuildRouteSource, RouteTreeFileSource, DirectoryScanSource, RouteSource, FlattenRouteTreeOptions, InternalRouteInfo, } from "./types.js";
|
|
5
|
-
export { type RouteSyntax, type RouteToRegexOptions, isDynamicRoute, routeToRegex, addRegexToRoutes, convertRoutesToMetaFormat, } from "./regex.js";
|
|
5
|
+
export { type RouteSyntax, type RouteToRegexOptions, isDynamicRoute, isCatchAllRoute, routeToRegex, addRegexToRoutes, convertRoutesToMetaFormat, sortRoutesByPriority, } from "./regex.js";
|
|
6
6
|
export { parseRouteTreeContent, parseRouteTreeFile, scanRoutesDirectory, scanRoutesFromDirectories, loadServerBuildRoutes, flattenRouteTree, parseRoutesFromSources, toRouteInfo, toRouteInfoArray, } from "./parser.js";
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/route/index.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/route/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,cAAc,EACd,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,qBAAqB,EACrB,gBAAgB,EAChB,sBAAsB,EACtB,WAAW,EACX,gBAAgB,GACjB,MAAM,aAAa,CAAC"}
|
package/dist/route/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Route Module - Unified exports for route parsing utilities
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
export { isDynamicRoute, routeToRegex, addRegexToRoutes, convertRoutesToMetaFormat, } from "./regex.js";
|
|
6
|
-
// Parser utilities
|
|
4
|
+
export { isDynamicRoute, isCatchAllRoute, routeToRegex, addRegexToRoutes, convertRoutesToMetaFormat, sortRoutesByPriority, } from "./regex.js";
|
|
7
5
|
export { parseRouteTreeContent, parseRouteTreeFile, scanRoutesDirectory, scanRoutesFromDirectories, loadServerBuildRoutes, flattenRouteTree, parseRoutesFromSources, toRouteInfo, toRouteInfoArray, } from "./parser.js";
|
|
8
6
|
//# sourceMappingURL=index.js.map
|
package/dist/route/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/route/index.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/route/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAcH,OAAO,EAGL,cAAc,EACd,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,qBAAqB,EACrB,gBAAgB,EAChB,sBAAsB,EACtB,WAAW,EACX,gBAAgB,GACjB,MAAM,aAAa,CAAC"}
|
package/dist/route/parser.d.ts
CHANGED
|
@@ -1,55 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Route Parser - Parse routes from various sources
|
|
3
|
-
*
|
|
4
|
-
* This module provides utilities to extract route information from:
|
|
5
|
-
* - Route tree files (e.g., routeTree.gen.ts)
|
|
6
|
-
* - Directory scanning (file-based routing)
|
|
7
|
-
* - Server build modules
|
|
8
3
|
*/
|
|
9
4
|
import type { RouteInfo, Logger } from "../types.js";
|
|
10
5
|
import type { RouteNode, RouteParserConfig, RouteTreeParserOptions, RouteSource, FlattenRouteTreeOptions, InternalRouteInfo } from "./types.js";
|
|
11
|
-
/**
|
|
12
|
-
* Parse routes from route tree file content
|
|
13
|
-
*/
|
|
14
6
|
export declare function parseRouteTreeContent(content: string, options?: RouteTreeParserOptions): InternalRouteInfo[];
|
|
15
|
-
/**
|
|
16
|
-
* Load and parse route tree from file
|
|
17
|
-
*/
|
|
18
7
|
export declare function parseRouteTreeFile(projectRoot: string, candidatePaths: string[], options?: RouteTreeParserOptions, logger?: Logger): Promise<InternalRouteInfo[]>;
|
|
19
|
-
/**
|
|
20
|
-
* Scan directory for route files
|
|
21
|
-
*/
|
|
22
8
|
export declare function scanRoutesDirectory(dir: string, basePath?: string, config?: RouteParserConfig): Promise<InternalRouteInfo[]>;
|
|
23
|
-
/**
|
|
24
|
-
* Scan multiple candidate directories for routes
|
|
25
|
-
*/
|
|
26
9
|
export declare function scanRoutesFromDirectories(projectRoot: string, candidateDirs: string[], config?: RouteParserConfig, logger?: Logger): Promise<InternalRouteInfo[]>;
|
|
27
|
-
/**
|
|
28
|
-
* Load server build module and extract routes
|
|
29
|
-
*/
|
|
30
10
|
export declare function loadServerBuildRoutes<T = unknown>(serverEntryPath: string, logger?: Logger): Promise<T | null>;
|
|
31
|
-
/**
|
|
32
|
-
* Flatten nested route tree to flat route list
|
|
33
|
-
*
|
|
34
|
-
* This is a generic utility that works with any route tree structure.
|
|
35
|
-
* Framework-specific behavior (like generating .data routes) should be
|
|
36
|
-
* implemented via the onRouteProcessed callback.
|
|
37
|
-
*/
|
|
38
11
|
export declare function flattenRouteTree(routes: Record<string, RouteNode>, options?: FlattenRouteTreeOptions): RouteInfo[];
|
|
39
|
-
/**
|
|
40
|
-
* Parse routes from multiple sources with fallback
|
|
41
|
-
*/
|
|
42
12
|
export declare function parseRoutesFromSources(projectRoot: string, sources: RouteSource[], options?: {
|
|
43
13
|
isSSR?: boolean;
|
|
44
14
|
logger?: Logger;
|
|
45
15
|
}): Promise<RouteInfo[]>;
|
|
46
|
-
/**
|
|
47
|
-
* Convert internal route info to standard RouteInfo
|
|
48
|
-
* Strips internal-only properties
|
|
49
|
-
*/
|
|
50
16
|
export declare function toRouteInfo(internal: InternalRouteInfo): RouteInfo;
|
|
51
|
-
/**
|
|
52
|
-
* Convert array of internal route info to standard RouteInfo array
|
|
53
|
-
*/
|
|
54
17
|
export declare function toRouteInfoArray(internals: InternalRouteInfo[]): RouteInfo[];
|
|
55
18
|
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/route/parser.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/route/parser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,KAAK,EACV,SAAS,EACT,iBAAiB,EACjB,sBAAsB,EACtB,WAAW,EACX,uBAAuB,EACvB,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAUpB,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,sBAA2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1
|
/**
|
|
2
2
|
* Route Parser - Parse routes from various sources
|
|
3
|
-
*
|
|
4
|
-
* This module provides utilities to extract route information from:
|
|
5
|
-
* - Route tree files (e.g., routeTree.gen.ts)
|
|
6
|
-
* - Directory scanning (file-based routing)
|
|
7
|
-
* - Server build modules
|
|
8
3
|
*/
|
|
9
4
|
import path from "path";
|
|
10
5
|
import { pathToFileURL } from "url";
|
|
11
6
|
import { pathExists, readFile, listFiles, normalizeRoutePath } from "../utils.js";
|
|
12
|
-
// ============================================================================
|
|
13
|
-
// Default configurations
|
|
14
|
-
// ============================================================================
|
|
15
7
|
const DEFAULT_PARSER_CONFIG = {
|
|
16
8
|
paramPattern: /^\$/,
|
|
17
9
|
paramReplacement: ":",
|
|
@@ -19,53 +11,30 @@ const DEFAULT_PARSER_CONFIG = {
|
|
|
19
11
|
layoutFiles: ["__root", "_root", "_layout", "__layout"],
|
|
20
12
|
extensions: [".tsx", ".ts", ".jsx", ".js"],
|
|
21
13
|
};
|
|
22
|
-
// ============================================================================
|
|
23
|
-
// Route Tree Parsing
|
|
24
|
-
// ============================================================================
|
|
25
|
-
/**
|
|
26
|
-
* Parse routes from route tree file content
|
|
27
|
-
*/
|
|
28
14
|
export function parseRouteTreeContent(content, options = {}) {
|
|
29
15
|
const { pathPattern = /path:\s*['"]([^'"]+)['"]/g, fullPathPattern = /fullPath:\s*['"]([^'"]+)['"]/g, } = options;
|
|
30
16
|
const routes = [];
|
|
31
17
|
const seenPaths = new Set();
|
|
32
|
-
// Try to extract full paths first
|
|
33
18
|
const fullPathMatches = content.matchAll(fullPathPattern);
|
|
34
19
|
for (const match of fullPathMatches) {
|
|
35
20
|
const routePath = normalizeRoutePath(match[1]);
|
|
36
21
|
if (!seenPaths.has(routePath)) {
|
|
37
22
|
seenPaths.add(routePath);
|
|
38
|
-
routes.push({
|
|
39
|
-
id: routePath,
|
|
40
|
-
path: routePath,
|
|
41
|
-
fullPath: routePath,
|
|
42
|
-
filePath: "",
|
|
43
|
-
isStatic: false,
|
|
44
|
-
});
|
|
23
|
+
routes.push({ id: routePath, path: routePath, fullPath: routePath, filePath: "", isStatic: false });
|
|
45
24
|
}
|
|
46
25
|
}
|
|
47
|
-
// If no full paths found, try path pattern
|
|
48
26
|
if (routes.length === 0) {
|
|
49
27
|
const pathMatches = content.matchAll(pathPattern);
|
|
50
28
|
for (const match of pathMatches) {
|
|
51
29
|
const routePath = normalizeRoutePath(match[1]);
|
|
52
30
|
if (!seenPaths.has(routePath)) {
|
|
53
31
|
seenPaths.add(routePath);
|
|
54
|
-
routes.push({
|
|
55
|
-
id: routePath,
|
|
56
|
-
path: routePath,
|
|
57
|
-
fullPath: routePath,
|
|
58
|
-
filePath: "",
|
|
59
|
-
isStatic: false,
|
|
60
|
-
});
|
|
32
|
+
routes.push({ id: routePath, path: routePath, fullPath: routePath, filePath: "", isStatic: false });
|
|
61
33
|
}
|
|
62
34
|
}
|
|
63
35
|
}
|
|
64
36
|
return routes;
|
|
65
37
|
}
|
|
66
|
-
/**
|
|
67
|
-
* Load and parse route tree from file
|
|
68
|
-
*/
|
|
69
38
|
export async function parseRouteTreeFile(projectRoot, candidatePaths, options = {}, logger) {
|
|
70
39
|
for (const relativePath of candidatePaths) {
|
|
71
40
|
const fullPath = path.join(projectRoot, relativePath);
|
|
@@ -86,63 +55,36 @@ export async function parseRouteTreeFile(projectRoot, candidatePaths, options =
|
|
|
86
55
|
}
|
|
87
56
|
return [];
|
|
88
57
|
}
|
|
89
|
-
// ============================================================================
|
|
90
|
-
// Directory Scanning
|
|
91
|
-
// ============================================================================
|
|
92
|
-
/**
|
|
93
|
-
* Scan directory for route files
|
|
94
|
-
*/
|
|
95
58
|
export async function scanRoutesDirectory(dir, basePath = "/", config = {}) {
|
|
96
59
|
const mergedConfig = { ...DEFAULT_PARSER_CONFIG, ...config };
|
|
97
60
|
const routes = [];
|
|
98
61
|
try {
|
|
99
62
|
const files = await listFiles(dir);
|
|
100
63
|
for (const file of files) {
|
|
101
|
-
// Check file extension
|
|
102
64
|
const ext = path.extname(file);
|
|
103
65
|
if (!mergedConfig.extensions.includes(ext))
|
|
104
66
|
continue;
|
|
105
|
-
// Get file name without extension
|
|
106
67
|
const fileName = file.replace(ext, "");
|
|
107
|
-
// Skip layout files
|
|
108
68
|
if (mergedConfig.layoutFiles.includes(fileName))
|
|
109
69
|
continue;
|
|
110
|
-
// Convert file name to route path
|
|
111
70
|
let routePath = fileName;
|
|
112
|
-
|
|
113
|
-
if (mergedConfig.indexFiles.includes(fileName)) {
|
|
71
|
+
if (mergedConfig.indexFiles.includes(fileName))
|
|
114
72
|
routePath = "";
|
|
115
|
-
}
|
|
116
|
-
// Apply param pattern transformation
|
|
117
73
|
if (mergedConfig.paramPattern) {
|
|
118
74
|
routePath = routePath.replace(mergedConfig.paramPattern, mergedConfig.paramReplacement);
|
|
119
75
|
}
|
|
120
|
-
// Handle catch-all routes ($ at end -> *)
|
|
121
76
|
routePath = routePath.replace(/\$$/, "*");
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
? "/"
|
|
125
|
-
: normalizeRoutePath(`${basePath}/${routePath}`);
|
|
126
|
-
routes.push({
|
|
127
|
-
id: fullPath,
|
|
128
|
-
path: routePath || "/",
|
|
129
|
-
fullPath,
|
|
130
|
-
filePath: path.join(dir, file),
|
|
131
|
-
isStatic: false,
|
|
132
|
-
});
|
|
77
|
+
const fullPath = basePath === "/" && routePath === "" ? "/" : normalizeRoutePath(`${basePath}/${routePath}`);
|
|
78
|
+
routes.push({ id: fullPath, path: routePath || "/", fullPath, filePath: path.join(dir, file), isStatic: false });
|
|
133
79
|
}
|
|
134
80
|
}
|
|
135
81
|
catch (error) {
|
|
136
|
-
// Log error but continue - directory might not exist or be inaccessible
|
|
137
82
|
if (error instanceof Error && !error.message.includes("ENOENT")) {
|
|
138
83
|
console.warn(`[route-parser] Failed to scan directory ${dir}: ${error.message}`);
|
|
139
84
|
}
|
|
140
85
|
}
|
|
141
86
|
return routes;
|
|
142
87
|
}
|
|
143
|
-
/**
|
|
144
|
-
* Scan multiple candidate directories for routes
|
|
145
|
-
*/
|
|
146
88
|
export async function scanRoutesFromDirectories(projectRoot, candidateDirs, config = {}, logger) {
|
|
147
89
|
for (const relativeDir of candidateDirs) {
|
|
148
90
|
const dir = path.join(projectRoot, relativeDir);
|
|
@@ -156,12 +98,6 @@ export async function scanRoutesFromDirectories(projectRoot, candidateDirs, conf
|
|
|
156
98
|
}
|
|
157
99
|
return [];
|
|
158
100
|
}
|
|
159
|
-
// ============================================================================
|
|
160
|
-
// Server Build Parsing
|
|
161
|
-
// ============================================================================
|
|
162
|
-
/**
|
|
163
|
-
* Load server build module and extract routes
|
|
164
|
-
*/
|
|
165
101
|
export async function loadServerBuildRoutes(serverEntryPath, logger) {
|
|
166
102
|
try {
|
|
167
103
|
const fileUrl = pathToFileURL(serverEntryPath).href;
|
|
@@ -174,19 +110,11 @@ export async function loadServerBuildRoutes(serverEntryPath, logger) {
|
|
|
174
110
|
return null;
|
|
175
111
|
}
|
|
176
112
|
}
|
|
177
|
-
/**
|
|
178
|
-
* Flatten nested route tree to flat route list
|
|
179
|
-
*
|
|
180
|
-
* This is a generic utility that works with any route tree structure.
|
|
181
|
-
* Framework-specific behavior (like generating .data routes) should be
|
|
182
|
-
* implemented via the onRouteProcessed callback.
|
|
183
|
-
*/
|
|
184
113
|
export function flattenRouteTree(routes, options = {}) {
|
|
185
114
|
const { parentPath = "", isSSR = true, isSpaMode = false, skipRootId = "root", onRouteProcessed, isStaticRoute, } = options;
|
|
186
115
|
const routeList = [];
|
|
187
116
|
const processedPaths = new Set();
|
|
188
117
|
function processRoute(route, currentParentPath) {
|
|
189
|
-
// Skip root route, process its children
|
|
190
118
|
if (route.id === skipRootId) {
|
|
191
119
|
route.children?.forEach(child => processRoute(child, currentParentPath));
|
|
192
120
|
return;
|
|
@@ -198,24 +126,15 @@ export function flattenRouteTree(routes, options = {}) {
|
|
|
198
126
|
const isStatic = isStaticRoute
|
|
199
127
|
? isStaticRoute(route, isSSR, isSpaMode)
|
|
200
128
|
: determineIsStatic(route, isSSR, isSpaMode);
|
|
201
|
-
routeList.push({
|
|
202
|
-
path: routePath,
|
|
203
|
-
isStatic,
|
|
204
|
-
srcRoute: routePath,
|
|
205
|
-
});
|
|
206
|
-
// Call custom callback for framework-specific route generation
|
|
129
|
+
routeList.push({ path: routePath, isStatic, srcRoute: routePath });
|
|
207
130
|
if (onRouteProcessed) {
|
|
208
|
-
|
|
209
|
-
routeList.push(...additionalRoutes);
|
|
131
|
+
routeList.push(...onRouteProcessed(route, routePath, isStatic));
|
|
210
132
|
}
|
|
211
133
|
route.children?.forEach(child => processRoute(child, routePath));
|
|
212
134
|
}
|
|
213
135
|
Object.values(routes).forEach(route => processRoute(route, parentPath));
|
|
214
136
|
return routeList;
|
|
215
137
|
}
|
|
216
|
-
/**
|
|
217
|
-
* Calculate full route path from route node
|
|
218
|
-
*/
|
|
219
138
|
function calculateRoutePath(route, parentPath) {
|
|
220
139
|
if (route.index)
|
|
221
140
|
return parentPath || "/";
|
|
@@ -223,28 +142,16 @@ function calculateRoutePath(route, parentPath) {
|
|
|
223
142
|
return parentPath || "/";
|
|
224
143
|
if (route.path.startsWith("/"))
|
|
225
144
|
return normalizeRoutePath(route.path);
|
|
226
|
-
const fullPath = parentPath === "/"
|
|
227
|
-
? `/${route.path}`
|
|
228
|
-
: `${parentPath}/${route.path}`;
|
|
145
|
+
const fullPath = parentPath === "/" ? `/${route.path}` : `${parentPath}/${route.path}`;
|
|
229
146
|
return normalizeRoutePath(fullPath);
|
|
230
147
|
}
|
|
231
|
-
/**
|
|
232
|
-
* Determine if route should be static
|
|
233
|
-
*/
|
|
234
148
|
function determineIsStatic(route, isSSR, isSpaMode) {
|
|
235
149
|
if (isSpaMode || !isSSR)
|
|
236
150
|
return true;
|
|
237
|
-
// CSR routes (client loader only) can be static
|
|
238
151
|
if (route.hasClientLoader && !route.hasLoader)
|
|
239
152
|
return true;
|
|
240
153
|
return false;
|
|
241
154
|
}
|
|
242
|
-
// ============================================================================
|
|
243
|
-
// Unified Route Parser
|
|
244
|
-
// ============================================================================
|
|
245
|
-
/**
|
|
246
|
-
* Parse routes from multiple sources with fallback
|
|
247
|
-
*/
|
|
248
155
|
export async function parseRoutesFromSources(projectRoot, sources, options = {}) {
|
|
249
156
|
const { isSSR = true, logger } = options;
|
|
250
157
|
for (const source of sources) {
|
|
@@ -253,12 +160,7 @@ export async function parseRoutesFromSources(projectRoot, sources, options = {})
|
|
|
253
160
|
case "serverBuild": {
|
|
254
161
|
const serverBuild = await loadServerBuildRoutes(source.serverEntry, logger);
|
|
255
162
|
if (serverBuild?.routes) {
|
|
256
|
-
|
|
257
|
-
routes = source.transform(serverBuild.routes);
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
routes = flattenRouteTree(serverBuild.routes, { isSSR });
|
|
261
|
-
}
|
|
163
|
+
routes = source.transform ? source.transform(serverBuild.routes) : flattenRouteTree(serverBuild.routes, { isSSR });
|
|
262
164
|
}
|
|
263
165
|
break;
|
|
264
166
|
}
|
|
@@ -271,29 +173,14 @@ export async function parseRoutesFromSources(projectRoot, sources, options = {})
|
|
|
271
173
|
break;
|
|
272
174
|
}
|
|
273
175
|
}
|
|
274
|
-
if (routes.length > 0)
|
|
176
|
+
if (routes.length > 0)
|
|
275
177
|
return routes;
|
|
276
|
-
}
|
|
277
178
|
}
|
|
278
179
|
return [];
|
|
279
180
|
}
|
|
280
|
-
// ============================================================================
|
|
281
|
-
// Utility Functions
|
|
282
|
-
// ============================================================================
|
|
283
|
-
/**
|
|
284
|
-
* Convert internal route info to standard RouteInfo
|
|
285
|
-
* Strips internal-only properties
|
|
286
|
-
*/
|
|
287
181
|
export function toRouteInfo(internal) {
|
|
288
|
-
return {
|
|
289
|
-
path: internal.path,
|
|
290
|
-
isStatic: internal.isStatic,
|
|
291
|
-
srcRoute: internal.srcRoute,
|
|
292
|
-
};
|
|
182
|
+
return { path: internal.path, isStatic: internal.isStatic, srcRoute: internal.srcRoute };
|
|
293
183
|
}
|
|
294
|
-
/**
|
|
295
|
-
* Convert array of internal route info to standard RouteInfo array
|
|
296
|
-
*/
|
|
297
184
|
export function toRouteInfoArray(internals) {
|
|
298
185
|
return internals.map(toRouteInfo);
|
|
299
186
|
}
|
package/dist/route/parser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/route/parser.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/route/parser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAUlF,MAAM,qBAAqB,GAAgC;IACzD,YAAY,EAAE,KAAK;IACnB,gBAAgB,EAAE,GAAG;IACrB,UAAU,EAAE,CAAC,OAAO,CAAC;IACrB,WAAW,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,CAAC;IACvD,UAAU,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC;CAC3C,CAAC;AAEF,MAAM,UAAU,qBAAqB,CACnC,OAAe,EACf,UAAkC,EAAE;IAEpC,MAAM,EACJ,WAAW,GAAG,2BAA2B,EACzC,eAAe,GAAG,+BAA+B,GAClD,GAAG,OAAO,CAAC;IAEZ,MAAM,MAAM,GAAwB,EAAE,CAAC;IACvC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAU,CAAC;IAEpC,MAAM,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;IAC1D,KAAK,MAAM,KAAK,IAAI,eAAe,EAAE,CAAC;QACpC,MAAM,SAAS,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC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AC,gBAAgB,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;gBACrH,CAAC;gBACD,MAAM;YACR,CAAC;YAED,KAAK,WAAW,CAAC,CAAC,CAAC;gBACjB,MAAM,GAAG,MAAM,kBAAkB,CAAC,WAAW,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;gBAC3F,MAAM;YACR,CAAC;YAED,KAAK,WAAW,CAAC,CAAC,CAAC;gBACjB,MAAM,GAAG,MAAM,yBAAyB,CAAC,WAAW,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAC3F,MAAM;YACR,CAAC;QACH,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,MAAM,CAAC;IACvC,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,QAA2B;IACrD,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC;AAC3F,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,SAA8B;IAC7D,OAAO,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AACpC,CAAC"}
|
package/dist/route/regex.d.ts
CHANGED
|
@@ -1,96 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Route Regex - Convert dynamic routes to regular expressions
|
|
3
|
-
*
|
|
4
|
-
* This module provides utilities to convert dynamic route paths from various
|
|
5
|
-
* framework syntaxes into regular expression patterns for route matching.
|
|
6
3
|
*/
|
|
7
4
|
import type { RouteInfo, MetaRouteInfo } from "../types.js";
|
|
8
5
|
/**
|
|
9
|
-
* Route parameter syntax
|
|
10
|
-
*
|
|
11
|
-
* - "
|
|
12
|
-
* - "
|
|
13
|
-
* - "
|
|
14
|
-
* - "auto":
|
|
15
|
-
*/
|
|
16
|
-
export type RouteSyntax = "colon" | "dollar" | "bracket" | "auto";
|
|
17
|
-
/**
|
|
18
|
-
* Options for converting route path to regex
|
|
6
|
+
* Route parameter syntax:
|
|
7
|
+
* - "colon": :param (Express/React Router)
|
|
8
|
+
* - "dollar": $param (Remix/TanStack)
|
|
9
|
+
* - "bracket": [param] (Next.js/Nuxt)
|
|
10
|
+
* - "at": @param (Vike)
|
|
11
|
+
* - "auto": auto-detect
|
|
19
12
|
*/
|
|
13
|
+
export type RouteSyntax = "colon" | "dollar" | "bracket" | "at" | "auto";
|
|
20
14
|
export interface RouteToRegexOptions {
|
|
21
|
-
/** Route parameter syntax to use for parsing. Default: "auto" (auto-detect) */
|
|
22
15
|
syntax?: RouteSyntax;
|
|
23
|
-
/** Whether to make the trailing slash optional. Default: true */
|
|
24
16
|
trailingSlashOptional?: boolean;
|
|
25
|
-
/** Whether to anchor the regex at start and end. Default: true */
|
|
26
17
|
anchored?: boolean;
|
|
27
18
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Check if a route path contains dynamic segments
|
|
30
|
-
*
|
|
31
|
-
* Detects patterns from multiple syntaxes:
|
|
32
|
-
* - Colon syntax: :param, :param?, * (React Router, Remix, Express)
|
|
33
|
-
* - Dollar syntax: $param, $ (TanStack Start)
|
|
34
|
-
* - Bracket syntax: [param], [[param]], [...param] (Next.js, Nuxt, SvelteKit)
|
|
35
|
-
*/
|
|
19
|
+
/** Check if a route path contains dynamic segments */
|
|
36
20
|
export declare function isDynamicRoute(routePath: string): boolean;
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
* Supports multiple route parameter syntaxes:
|
|
41
|
-
*
|
|
42
|
-
* **Colon syntax** (React Router, Remix, Express, Vue Router):
|
|
43
|
-
* - `:slug` → `([^/]+)` - Required dynamic parameter
|
|
44
|
-
* - `:slug?` → `([^/]+)?` - Optional dynamic parameter
|
|
45
|
-
* - `*` → `(.*)` - Wildcard/splat (catches everything)
|
|
46
|
-
*
|
|
47
|
-
* **Dollar syntax** (TanStack Start):
|
|
48
|
-
* - `$slug` → `([^/]+)` - Required dynamic parameter
|
|
49
|
-
* - `$` (at end) → `(.*)` - Wildcard/splat
|
|
50
|
-
*
|
|
51
|
-
* **Bracket syntax** (Next.js, Nuxt, SvelteKit):
|
|
52
|
-
* - `[slug]` → `([^/]+)` - Required dynamic parameter
|
|
53
|
-
* - `[[slug]]` → `([^/]+)?` - Optional dynamic parameter
|
|
54
|
-
* - `[...slug]` → `(.*)` - Catch-all
|
|
55
|
-
* - `[[...slug]]` → `(.*)?` - Optional catch-all
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* // Colon syntax
|
|
59
|
-
* routeToRegex("/blog/:slug") // "^/blog/([^/]+)/?$"
|
|
60
|
-
* routeToRegex("/files/*") // "^/files(?:/(.*))?$"
|
|
61
|
-
*
|
|
62
|
-
* // Dollar syntax
|
|
63
|
-
* routeToRegex("/blog/$slug") // "^/blog/([^/]+)/?$"
|
|
64
|
-
* routeToRegex("/files/$") // "^/files(?:/(.*))?$"
|
|
65
|
-
*
|
|
66
|
-
* // Bracket syntax
|
|
67
|
-
* routeToRegex("/blog/[slug]") // "^/blog/([^/]+)/?$"
|
|
68
|
-
* routeToRegex("/files/[...path]") // "^/files(?:/(.*))?$"
|
|
69
|
-
*/
|
|
21
|
+
/** Check if a route is a catch-all route */
|
|
22
|
+
export declare function isCatchAllRoute(routePath: string): boolean;
|
|
23
|
+
/** Convert a route path to a regular expression pattern */
|
|
70
24
|
export declare function routeToRegex(routePath: string, options?: RouteToRegexOptions): string;
|
|
71
|
-
/**
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
* This function processes an array of RouteInfo and adds the `regex` field
|
|
75
|
-
* to routes that contain dynamic parameters.
|
|
76
|
-
*
|
|
77
|
-
* @param routes - Array of route info objects
|
|
78
|
-
* @param options - Options for regex conversion
|
|
79
|
-
* @returns Routes with regex patterns added where applicable
|
|
80
|
-
*/
|
|
25
|
+
/** Sort routes by priority for correct matching order */
|
|
26
|
+
export declare function sortRoutesByPriority(routes: RouteInfo[]): RouteInfo[];
|
|
27
|
+
/** Add regex patterns to routes with dynamic segments */
|
|
81
28
|
export declare function addRegexToRoutes(routes: RouteInfo[], options?: RouteToRegexOptions): RouteInfo[];
|
|
82
|
-
/**
|
|
83
|
-
* Convert routes to simplified meta.json format
|
|
84
|
-
*
|
|
85
|
-
* This function converts RouteInfo array to MetaRouteInfo array,
|
|
86
|
-
* keeping only `regexPath` and `isStatic` fields for EdgeOne runtime.
|
|
87
|
-
*
|
|
88
|
-
* - Dynamic routes (with parameters like :id, $id, [id]) are converted to regex patterns
|
|
89
|
-
* - Static routes keep their original path without conversion
|
|
90
|
-
*
|
|
91
|
-
* @param routes - Array of route info objects
|
|
92
|
-
* @param options - Options for regex conversion
|
|
93
|
-
* @returns Simplified routes for meta.json
|
|
94
|
-
*/
|
|
29
|
+
/** Convert routes to simplified meta.json format */
|
|
95
30
|
export declare function convertRoutesToMetaFormat(routes: RouteInfo[], options?: RouteToRegexOptions): MetaRouteInfo[];
|
|
96
31
|
//# sourceMappingURL=regex.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../../src/route/regex.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../../src/route/regex.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5D;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,CAAC;AAEzE,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,sDAAsD;AACtD,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAOzD;AAED,4CAA4C;AAC5C,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAK1D;AASD,2DAA2D;AAC3D,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,MAAM,CAgCzF;AAyDD,yDAAyD;AACzD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAMrE;AAED,yDAAyD;AACzD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,OAAO,GAAE,mBAAwB,GAAG,SAAS,EAAE,CAQpG;AAED,oDAAoD;AACpD,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,OAAO,GAAE,mBAAwB,GAAG,aAAa,EAAE,CAMjH"}
|