@vaadin/hilla-file-router 24.4.0-alpha10
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/.lintstagedrc.js +6 -0
- package/package.json +88 -0
- package/runtime/createMenuItems.d.ts +14 -0
- package/runtime/createMenuItems.d.ts.map +1 -0
- package/runtime/createMenuItems.js +17 -0
- package/runtime/createMenuItems.js.map +7 -0
- package/runtime/createRoute.d.ts +13 -0
- package/runtime/createRoute.d.ts.map +1 -0
- package/runtime/createRoute.js +17 -0
- package/runtime/createRoute.js.map +7 -0
- package/runtime/toReactRouter.d.ts +12 -0
- package/runtime/toReactRouter.d.ts.map +1 -0
- package/runtime/toReactRouter.js +25 -0
- package/runtime/toReactRouter.js.map +7 -0
- package/runtime/useViewConfig.d.ts +6 -0
- package/runtime/useViewConfig.d.ts.map +1 -0
- package/runtime/useViewConfig.js +9 -0
- package/runtime/useViewConfig.js.map +7 -0
- package/runtime/utils.d.ts +11 -0
- package/runtime/utils.d.ts.map +1 -0
- package/runtime/utils.js +11 -0
- package/runtime/utils.js.map +7 -0
- package/runtime.d.ts +5 -0
- package/runtime.d.ts.map +1 -0
- package/runtime.js +5 -0
- package/runtime.js.map +7 -0
- package/shared/convertComponentNameToTitle.d.ts +9 -0
- package/shared/convertComponentNameToTitle.d.ts.map +1 -0
- package/shared/convertComponentNameToTitle.js +18 -0
- package/shared/convertComponentNameToTitle.js.map +7 -0
- package/shared/internal.d.ts +21 -0
- package/shared/routeParamType.d.ts +9 -0
- package/shared/routeParamType.d.ts.map +1 -0
- package/shared/routeParamType.js +10 -0
- package/shared/routeParamType.js.map +7 -0
- package/shared/traverse.d.ts +10 -0
- package/shared/traverse.d.ts.map +1 -0
- package/shared/traverse.js +14 -0
- package/shared/traverse.js.map +7 -0
- package/types.d.ts +72 -0
- package/vite-plugin/collectRoutesFromFS.d.ts +41 -0
- package/vite-plugin/collectRoutesFromFS.d.ts.map +1 -0
- package/vite-plugin/collectRoutesFromFS.js +71 -0
- package/vite-plugin/collectRoutesFromFS.js.map +7 -0
- package/vite-plugin/createRoutesFromMeta.d.ts +10 -0
- package/vite-plugin/createRoutesFromMeta.d.ts.map +1 -0
- package/vite-plugin/createRoutesFromMeta.js +79 -0
- package/vite-plugin/createRoutesFromMeta.js.map +7 -0
- package/vite-plugin/createViewConfigJson.d.ts +9 -0
- package/vite-plugin/createViewConfigJson.d.ts.map +1 -0
- package/vite-plugin/createViewConfigJson.js +70 -0
- package/vite-plugin/createViewConfigJson.js.map +7 -0
- package/vite-plugin/generateRuntimeFiles.d.ts +25 -0
- package/vite-plugin/generateRuntimeFiles.d.ts.map +1 -0
- package/vite-plugin/generateRuntimeFiles.js +36 -0
- package/vite-plugin/generateRuntimeFiles.js.map +7 -0
- package/vite-plugin/utils.d.ts +28 -0
- package/vite-plugin/utils.d.ts.map +1 -0
- package/vite-plugin/utils.js +49 -0
- package/vite-plugin/utils.js.map +7 -0
- package/vite-plugin.d.ts +34 -0
- package/vite-plugin.d.ts.map +1 -0
- package/vite-plugin.js +70 -0
- package/vite-plugin.js.map +7 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { opendir, readFile } from "node:fs/promises";
|
|
2
|
+
import { basename, extname, relative } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { cleanUp } from "./utils.js";
|
|
5
|
+
async function checkFile(url, logger) {
|
|
6
|
+
if (url) {
|
|
7
|
+
const contents = await readFile(url, "utf-8");
|
|
8
|
+
if (contents === "") {
|
|
9
|
+
return void 0;
|
|
10
|
+
} else if (!contents.includes("export default")) {
|
|
11
|
+
logger.error(`The file "${String(url)}" should contain a default export of a component`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return url;
|
|
15
|
+
}
|
|
16
|
+
const collator = new Intl.Collator("en-US");
|
|
17
|
+
async function collectRoutesFromFS(dir, { extensions, logger, parent = dir }) {
|
|
18
|
+
const path = relative(fileURLToPath(parent), fileURLToPath(dir));
|
|
19
|
+
let children = [];
|
|
20
|
+
let layout;
|
|
21
|
+
for await (const d of await opendir(dir)) {
|
|
22
|
+
if (d.isDirectory()) {
|
|
23
|
+
children.push(await collectRoutesFromFS(new URL(`${d.name}/`, dir), { extensions, logger, parent: dir }));
|
|
24
|
+
} else if (d.isFile() && extensions.includes(extname(d.name))) {
|
|
25
|
+
const file = new URL(d.name, dir);
|
|
26
|
+
const name = basename(d.name, extname(d.name));
|
|
27
|
+
if (name.startsWith("$")) {
|
|
28
|
+
if (name === "$layout") {
|
|
29
|
+
layout = file;
|
|
30
|
+
} else if (name === "$index") {
|
|
31
|
+
children.push({
|
|
32
|
+
path: "",
|
|
33
|
+
file,
|
|
34
|
+
children: []
|
|
35
|
+
});
|
|
36
|
+
} else {
|
|
37
|
+
throw new Error('Symbol "$" is reserved for special files; only "$layout" and "$index" are allowed');
|
|
38
|
+
}
|
|
39
|
+
} else if (!name.startsWith("_")) {
|
|
40
|
+
children.push({
|
|
41
|
+
path: name,
|
|
42
|
+
file,
|
|
43
|
+
children: []
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
[children, layout] = await Promise.all([
|
|
49
|
+
Promise.all(
|
|
50
|
+
children.map(async (child) => {
|
|
51
|
+
let { file: f, layout: l } = child;
|
|
52
|
+
[f, l] = await Promise.all([checkFile(f, logger), checkFile(l, logger)]);
|
|
53
|
+
return {
|
|
54
|
+
...child,
|
|
55
|
+
file: f,
|
|
56
|
+
layout: l
|
|
57
|
+
};
|
|
58
|
+
})
|
|
59
|
+
),
|
|
60
|
+
checkFile(layout, logger)
|
|
61
|
+
]);
|
|
62
|
+
return {
|
|
63
|
+
path,
|
|
64
|
+
layout,
|
|
65
|
+
children: children.sort(({ path: a }, { path: b }) => collator.compare(cleanUp(a), cleanUp(b)))
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export {
|
|
69
|
+
collectRoutesFromFS as default
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=collectRoutesFromFS.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/vite-plugin/collectRoutesFromFS.ts"],
|
|
4
|
+
"sourcesContent": ["import { opendir, readFile } from 'node:fs/promises';\nimport { basename, extname, relative } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { Logger } from 'vite';\nimport { cleanUp } from './utils.js';\n\nexport type RouteMeta = Readonly<{\n path: string;\n file?: URL;\n layout?: URL;\n children: RouteMeta[];\n}>;\n\n/**\n * Routes collector options.\n */\nexport type CollectRoutesOptions = Readonly<{\n /**\n * The list of extensions for files that will be collected as routes.\n */\n extensions: readonly string[];\n /**\n * The parent directory of the current directory. This is a\n * nested parameter used inside the function only.\n */\n parent?: URL;\n /**\n * The Vite logger instance.\n */\n logger: Logger;\n}>;\n\nasync function checkFile(url: URL | undefined, logger: Logger): Promise<URL | undefined> {\n if (url) {\n const contents = await readFile(url, 'utf-8');\n if (contents === '') {\n return undefined;\n } else if (!contents.includes('export default')) {\n logger.error(`The file \"${String(url)}\" should contain a default export of a component`);\n }\n }\n\n return url;\n}\n\nconst collator = new Intl.Collator('en-US');\n\n/**\n * Collect route metadata from the file system and build a route tree.\n *\n * It accepts files that start with `$` as special files.\n * - `$layout` contains a component that wraps the child components.\n * - `$index` contains a component that will be used as the index page of the directory.\n *\n * It accepts files that start with `_` as private files. They will be ignored.\n *\n * @param dir - The directory to collect routes from.\n * @param options - The options object.\n *\n * @returns The route metadata tree.\n */\nexport default async function collectRoutesFromFS(\n dir: URL,\n { extensions, logger, parent = dir }: CollectRoutesOptions,\n): Promise<RouteMeta> {\n const path = relative(fileURLToPath(parent), fileURLToPath(dir));\n let children: RouteMeta[] = [];\n let layout: URL | undefined;\n\n for await (const d of await opendir(dir)) {\n if (d.isDirectory()) {\n children.push(await collectRoutesFromFS(new URL(`${d.name}/`, dir), { extensions, logger, parent: dir }));\n } else if (d.isFile() && extensions.includes(extname(d.name))) {\n const file = new URL(d.name, dir);\n const name = basename(d.name, extname(d.name));\n\n if (name.startsWith('$')) {\n if (name === '$layout') {\n layout = file;\n } else if (name === '$index') {\n children.push({\n path: '',\n file,\n children: [],\n });\n } else {\n throw new Error('Symbol \"$\" is reserved for special files; only \"$layout\" and \"$index\" are allowed');\n }\n } else if (!name.startsWith('_')) {\n children.push({\n path: name,\n file,\n children: [],\n });\n }\n }\n }\n\n [children, layout] = await Promise.all([\n Promise.all(\n children.map(async (child) => {\n let { file: f, layout: l } = child;\n [f, l] = await Promise.all([checkFile(f, logger), checkFile(l, logger)]);\n\n return {\n ...child,\n file: f,\n layout: l,\n };\n }),\n ),\n checkFile(layout, logger),\n ]);\n\n return {\n path,\n layout,\n children: children.sort(({ path: a }, { path: b }) => collator.compare(cleanUp(a), cleanUp(b))),\n };\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS,gBAAgB;AAClC,SAAS,UAAU,SAAS,gBAAgB;AAC5C,SAAS,qBAAqB;AAE9B,SAAS,eAAe;AA4BxB,eAAe,UAAU,KAAsB,QAA0C;AACvF,MAAI,KAAK;AACP,UAAM,WAAW,MAAM,SAAS,KAAK,OAAO;AAC5C,QAAI,aAAa,IAAI;AACnB,aAAO;AAAA,IACT,WAAW,CAAC,SAAS,SAAS,gBAAgB,GAAG;AAC/C,aAAO,MAAM,aAAa,OAAO,GAAG,CAAC,kDAAkD;AAAA,IACzF;AAAA,EACF;AAEA,SAAO;AACT;AAEA,MAAM,WAAW,IAAI,KAAK,SAAS,OAAO;AAgB1C,eAAO,oBACL,KACA,EAAE,YAAY,QAAQ,SAAS,IAAI,GACf;AACpB,QAAM,OAAO,SAAS,cAAc,MAAM,GAAG,cAAc,GAAG,CAAC;AAC/D,MAAI,WAAwB,CAAC;AAC7B,MAAI;AAEJ,mBAAiB,KAAK,MAAM,QAAQ,GAAG,GAAG;AACxC,QAAI,EAAE,YAAY,GAAG;AACnB,eAAS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AG,EAAE,MAAM,EAAE,MAAM,SAAS,QAAQ,QAAQ,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC;AAAA,EAChG;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RouteMeta } from './collectRoutesFromFS.js';
|
|
2
|
+
import type { RuntimeFileUrls } from './generateRuntimeFiles.js';
|
|
3
|
+
/**
|
|
4
|
+
* Loads all the files from the received metadata and creates a framework-agnostic route tree.
|
|
5
|
+
*
|
|
6
|
+
* @param views - The abstract route tree.
|
|
7
|
+
* @param generatedDir - The directory where the generated view file will be stored.
|
|
8
|
+
*/
|
|
9
|
+
export default function createRoutesFromMeta(views: RouteMeta, { code: codeFile }: RuntimeFileUrls): string;
|
|
10
|
+
//# sourceMappingURL=createRoutesFromMeta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRoutesFromMeta.d.ts","sourceRoot":"","sources":["../src/vite-plugin/createRoutesFromMeta.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAmDjE;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,eAAe,GAAG,MAAM,CAgD1G"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { sep, relative } from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { template, transform as transformer } from "@vaadin/hilla-generator-utils/ast.js";
|
|
4
|
+
import createSourceFile from "@vaadin/hilla-generator-utils/createSourceFile.js";
|
|
5
|
+
import ts, {
|
|
6
|
+
} from "typescript";
|
|
7
|
+
import { transformRoute } from "../runtime/utils.js";
|
|
8
|
+
import { convertFSRouteSegmentToURLPatternFormat } from "./utils.js";
|
|
9
|
+
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
|
10
|
+
function relativize(url, generatedDir) {
|
|
11
|
+
const result = relative(fileURLToPath(generatedDir), fileURLToPath(url)).replaceAll(sep, "/");
|
|
12
|
+
if (!result.startsWith(".")) {
|
|
13
|
+
return `./${result}`;
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
function createImport(mod, file) {
|
|
18
|
+
const path = `${file.substring(0, file.lastIndexOf("."))}.js`;
|
|
19
|
+
return template(`import * as ${mod} from '${path}';
|
|
20
|
+
`, ([statement]) => statement);
|
|
21
|
+
}
|
|
22
|
+
function createRouteData(path, mod, children) {
|
|
23
|
+
return template(
|
|
24
|
+
`const route = createRoute("${path}"${mod ? `, ${mod}` : ""}${children.length > 0 ? `, CHILDREN` : ""})`,
|
|
25
|
+
([statement]) => statement.declarationList.declarations[0].initializer,
|
|
26
|
+
[
|
|
27
|
+
transformer(
|
|
28
|
+
(node) => ts.isIdentifier(node) && node.text === "CHILDREN" ? ts.factory.createArrayLiteralExpression(children) : node
|
|
29
|
+
)
|
|
30
|
+
]
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
function createRoutesFromMeta(views, { code: codeFile }) {
|
|
34
|
+
const codeDir = new URL("./", codeFile);
|
|
35
|
+
const imports = [
|
|
36
|
+
template(
|
|
37
|
+
'import { createRoute } from "@vaadin/hilla-file-router/runtime.js";',
|
|
38
|
+
([statement]) => statement
|
|
39
|
+
)
|
|
40
|
+
];
|
|
41
|
+
let id = 0;
|
|
42
|
+
const routes = transformRoute(
|
|
43
|
+
views,
|
|
44
|
+
(view) => view.children.values(),
|
|
45
|
+
({ file: file2, layout, path }, children) => {
|
|
46
|
+
const currentId = id;
|
|
47
|
+
id += 1;
|
|
48
|
+
let mod;
|
|
49
|
+
if (file2) {
|
|
50
|
+
mod = `Page${currentId}`;
|
|
51
|
+
imports.push(createImport(mod, relativize(file2, codeDir)));
|
|
52
|
+
} else if (layout) {
|
|
53
|
+
mod = `Layout${currentId}`;
|
|
54
|
+
imports.push(createImport(mod, relativize(layout, codeDir)));
|
|
55
|
+
}
|
|
56
|
+
return createRouteData(convertFSRouteSegmentToURLPatternFormat(path), mod, children);
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
const routeDeclaration = template(
|
|
60
|
+
`import a from 'IMPORTS';
|
|
61
|
+
|
|
62
|
+
const routes = ROUTE;
|
|
63
|
+
|
|
64
|
+
export default routes;
|
|
65
|
+
`,
|
|
66
|
+
[
|
|
67
|
+
transformer(
|
|
68
|
+
(node) => ts.isImportDeclaration(node) && node.moduleSpecifier.text === "IMPORTS" ? imports : node
|
|
69
|
+
),
|
|
70
|
+
transformer((node) => ts.isIdentifier(node) && node.text === "ROUTE" ? routes : node)
|
|
71
|
+
]
|
|
72
|
+
);
|
|
73
|
+
const file = createSourceFile(routeDeclaration, "views.ts");
|
|
74
|
+
return printer.printFile(file);
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
createRoutesFromMeta as default
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=createRoutesFromMeta.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/vite-plugin/createRoutesFromMeta.ts"],
|
|
4
|
+
"sourcesContent": ["import { sep, relative } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { template, transform as transformer } from '@vaadin/hilla-generator-utils/ast.js';\nimport createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';\nimport ts, {\n type CallExpression,\n type ImportDeclaration,\n type StringLiteral,\n type VariableStatement,\n} from 'typescript';\nimport { transformRoute } from '../runtime/utils.js';\nimport type { RouteMeta } from './collectRoutesFromFS.js';\nimport type { RuntimeFileUrls } from './generateRuntimeFiles.js';\nimport { convertFSRouteSegmentToURLPatternFormat } from './utils.js';\n\nconst printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });\n\n/**\n * Convert a file URL to a relative path from the generated directory.\n *\n * @param url - The file URL to convert.\n * @param generatedDir - The directory where the generated view file will be stored.\n */\nfunction relativize(url: URL, generatedDir: URL): string {\n const result = relative(fileURLToPath(generatedDir), fileURLToPath(url)).replaceAll(sep, '/');\n\n if (!result.startsWith('.')) {\n return `./${result}`;\n }\n\n return result;\n}\n\n/**\n * Create an import declaration for a `views` module.\n *\n * @param mod - The name of the route module to import.\n * @param file - The file path of the module.\n */\nfunction createImport(mod: string, file: string): ImportDeclaration {\n const path = `${file.substring(0, file.lastIndexOf('.'))}.js`;\n return template(`import * as ${mod} from '${path}';\\n`, ([statement]) => statement as ts.ImportDeclaration);\n}\n\n/**\n * Create an abstract route creation function call. The nested function calls create a route tree.\n *\n * @param path - The path of the route.\n * @param mod - The name of the route module imported as a namespace.\n * @param children - The list of child route call expressions.\n */\nfunction createRouteData(path: string, mod: string | undefined, children: readonly CallExpression[]): CallExpression {\n return template(\n `const route = createRoute(\"${path}\"${mod ? `, ${mod}` : ''}${children.length > 0 ? `, CHILDREN` : ''})`,\n ([statement]) => (statement as VariableStatement).declarationList.declarations[0].initializer as CallExpression,\n [\n transformer((node) =>\n ts.isIdentifier(node) && node.text === 'CHILDREN' ? ts.factory.createArrayLiteralExpression(children) : node,\n ),\n ],\n );\n}\n\n/**\n * Loads all the files from the received metadata and creates a framework-agnostic route tree.\n *\n * @param views - The abstract route tree.\n * @param generatedDir - The directory where the generated view file will be stored.\n */\nexport default function createRoutesFromMeta(views: RouteMeta, { code: codeFile }: RuntimeFileUrls): string {\n const codeDir = new URL('./', codeFile);\n const imports: ImportDeclaration[] = [\n template(\n 'import { createRoute } from \"@vaadin/hilla-file-router/runtime.js\";',\n ([statement]) => statement as ts.ImportDeclaration,\n ),\n ];\n let id = 0;\n\n const routes = transformRoute<RouteMeta, CallExpression>(\n views,\n (view) => view.children.values(),\n ({ file, layout, path }, children) => {\n const currentId = id;\n id += 1;\n\n let mod: string | undefined;\n if (file) {\n mod = `Page${currentId}`;\n imports.push(createImport(mod, relativize(file, codeDir)));\n } else if (layout) {\n mod = `Layout${currentId}`;\n imports.push(createImport(mod, relativize(layout, codeDir)));\n }\n\n return createRouteData(convertFSRouteSegmentToURLPatternFormat(path), mod, children);\n },\n );\n\n const routeDeclaration = template(\n `import a from 'IMPORTS';\n\nconst routes = ROUTE;\n\nexport default routes;\n`,\n [\n transformer((node) =>\n ts.isImportDeclaration(node) && (node.moduleSpecifier as StringLiteral).text === 'IMPORTS' ? imports : node,\n ),\n transformer((node) => (ts.isIdentifier(node) && node.text === 'ROUTE' ? routes : node)),\n ],\n );\n\n const file = createSourceFile(routeDeclaration, 'views.ts');\n\n return printer.printFile(file);\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,KAAK,gBAAgB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,UAAU,aAAa,mBAAmB;AACnD,OAAO,sBAAsB;AAC7B,OAAO;AAAA,OAKA;AACP,SAAS,sBAAsB;AAG/B,SAAS,+CAA+C;AAExD,MAAM,UAAU,GAAG,cAAc,EAAE,SAAS,GAAG,YAAY,SAAS,CAAC;AAQrE,SAAS,WAAW,KAAU,cAA2B;AACvD,QAAM,SAAS,SAAS,cAAc,YAAY,GAAG,cAAc,GAAG,CAAC,EAAE,WAAW,KAAK,GAAG;AAE5F,MAAI,CAAC,OAAO,WAAW,GAAG,GAAG;AAC3B,WAAO,KAAK,MAAM;AAAA,EACpB;AAEA,SAAO;AACT;AAQA,SAAS,aAAa,KAAa,MAAiC;AAClE,QAAM,OAAO,GAAG,KAAK,UAAU,GAAG,KAAK,YAAY,GAAG,CAAC,CAAC;AACxD,SAAO,SAAS,eAAe,GAAG,UAAU,IAAI;AAAA,GAAQ,CAAC,CAAC,SAAS,MAAM,SAAiC;AAC5G;AASA,SAAS,gBAAgB,MAAc,KAAyB,UAAqD;AACnH,SAAO;AAAA,IACL,8BAA8B,IAAI,IAAI,MAAM,KAAK,GAAG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AAS,IAAK;AAAA,IACxF;AAAA,EACF;AAEA,QAAM,OAAO,iBAAiB,kBAAkB,UAAU;AAE1D,SAAO,QAAQ,UAAU,IAAI;AAC/B;",
|
|
6
|
+
"names": ["file"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RouteMeta } from './collectRoutesFromFS.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a map of all leaf routes to their configuration. This file is used by the server to provide server-side
|
|
4
|
+
* routes along with managing the client-side routes.
|
|
5
|
+
*
|
|
6
|
+
* @param views - The route metadata tree.
|
|
7
|
+
*/
|
|
8
|
+
export default function createViewConfigJson(views: RouteMeta): Promise<string>;
|
|
9
|
+
//# sourceMappingURL=createViewConfigJson.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createViewConfigJson.d.ts","sourceRoot":"","sources":["../src/vite-plugin/createViewConfigJson.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAgB1D;;;;;GAKG;AACH,wBAA8B,oBAAoB,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CA2DpF"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { Script } from "node:vm";
|
|
3
|
+
import ts, {} from "typescript";
|
|
4
|
+
import { convertComponentNameToTitle } from "../shared/convertComponentNameToTitle.js";
|
|
5
|
+
import traverse from "../shared/traverse.js";
|
|
6
|
+
import { convertFSRouteSegmentToURLPatternFormat, extractParameterFromRouteSegment } from "./utils.js";
|
|
7
|
+
function* walkAST(node) {
|
|
8
|
+
yield node;
|
|
9
|
+
for (const child of node.getChildren()) {
|
|
10
|
+
yield* walkAST(child);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
async function createViewConfigJson(views) {
|
|
14
|
+
const res = await Promise.all(
|
|
15
|
+
Array.from(traverse(views), async (branch) => {
|
|
16
|
+
const configs = await Promise.all(
|
|
17
|
+
branch.map(async ({ path, file, layout }) => {
|
|
18
|
+
if (!file && !layout) {
|
|
19
|
+
return [
|
|
20
|
+
convertFSRouteSegmentToURLPatternFormat(path),
|
|
21
|
+
{ params: extractParameterFromRouteSegment(path) }
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
const sourceFile = ts.createSourceFile(
|
|
25
|
+
"f.ts",
|
|
26
|
+
await readFile(file ?? layout, "utf8"),
|
|
27
|
+
ts.ScriptTarget.ESNext,
|
|
28
|
+
true
|
|
29
|
+
);
|
|
30
|
+
let config;
|
|
31
|
+
let waitingForIdentifier = false;
|
|
32
|
+
let componentName;
|
|
33
|
+
for (const node of walkAST(sourceFile)) {
|
|
34
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.name.text === "config") {
|
|
35
|
+
if (node.initializer && ts.isObjectLiteralExpression(node.initializer)) {
|
|
36
|
+
const code = node.initializer.getText(sourceFile);
|
|
37
|
+
const script = new Script(`(${code})`);
|
|
38
|
+
config = script.runInThisContext();
|
|
39
|
+
}
|
|
40
|
+
} else if (node.getText(sourceFile).startsWith("export default")) {
|
|
41
|
+
waitingForIdentifier = true;
|
|
42
|
+
} else if (waitingForIdentifier && ts.isIdentifier(node)) {
|
|
43
|
+
componentName = node.text;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const _path = config?.route ?? path;
|
|
48
|
+
const pattern = convertFSRouteSegmentToURLPatternFormat(_path);
|
|
49
|
+
return [
|
|
50
|
+
pattern,
|
|
51
|
+
{
|
|
52
|
+
...config,
|
|
53
|
+
params: extractParameterFromRouteSegment(_path),
|
|
54
|
+
title: config?.title ?? convertComponentNameToTitle(componentName)
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
})
|
|
58
|
+
);
|
|
59
|
+
const key = configs.map(([path]) => path).join("/");
|
|
60
|
+
const params = configs.reduce((acc, [, { params: p }]) => Object.assign(acc, p), {});
|
|
61
|
+
const [, value] = configs[configs.length - 1];
|
|
62
|
+
return [key, { ...value, params: Object.keys(params).length > 0 ? params : void 0 }];
|
|
63
|
+
})
|
|
64
|
+
);
|
|
65
|
+
return JSON.stringify(Object.fromEntries(res));
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
createViewConfigJson as default
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=createViewConfigJson.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/vite-plugin/createViewConfigJson.ts"],
|
|
4
|
+
"sourcesContent": ["import { readFile } from 'node:fs/promises';\nimport { Script } from 'node:vm';\nimport ts, { type Node } from 'typescript';\nimport { convertComponentNameToTitle } from '../shared/convertComponentNameToTitle.js';\nimport type { ServerViewConfig } from '../shared/internal.js';\nimport traverse from '../shared/traverse.js';\nimport type { ViewConfig } from '../types.js';\nimport type { RouteMeta } from './collectRoutesFromFS.js';\nimport { convertFSRouteSegmentToURLPatternFormat, extractParameterFromRouteSegment } from './utils.js';\n\n/**\n * Walks the TypeScript AST using the deep-first search algorithm.\n *\n * @param node - The node to walk.\n */\nfunction* walkAST(node: Node): Generator<Node> {\n yield node;\n\n for (const child of node.getChildren()) {\n yield* walkAST(child);\n }\n}\n\n/**\n * Creates a map of all leaf routes to their configuration. This file is used by the server to provide server-side\n * routes along with managing the client-side routes.\n *\n * @param views - The route metadata tree.\n */\nexport default async function createViewConfigJson(views: RouteMeta): Promise<string> {\n const res = await Promise.all(\n Array.from(traverse(views), async (branch) => {\n const configs = await Promise.all(\n branch.map(async ({ path, file, layout }): Promise<[string, ServerViewConfig]> => {\n if (!file && !layout) {\n return [\n convertFSRouteSegmentToURLPatternFormat(path),\n { params: extractParameterFromRouteSegment(path) },\n ] as const;\n }\n\n const sourceFile = ts.createSourceFile(\n 'f.ts',\n await readFile(file ?? layout!, 'utf8'),\n ts.ScriptTarget.ESNext,\n true,\n );\n let config: ViewConfig | undefined;\n let waitingForIdentifier = false;\n let componentName: string | undefined;\n\n for (const node of walkAST(sourceFile)) {\n if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.name.text === 'config') {\n if (node.initializer && ts.isObjectLiteralExpression(node.initializer)) {\n const code = node.initializer.getText(sourceFile);\n const script = new Script(`(${code})`);\n config = script.runInThisContext() as ViewConfig;\n }\n } else if (node.getText(sourceFile).startsWith('export default')) {\n waitingForIdentifier = true;\n } else if (waitingForIdentifier && ts.isIdentifier(node)) {\n componentName = node.text;\n break;\n }\n }\n const _path = config?.route ?? path;\n const pattern = convertFSRouteSegmentToURLPatternFormat(_path);\n\n return [\n pattern,\n {\n ...config,\n params: extractParameterFromRouteSegment(_path),\n title: config?.title ?? convertComponentNameToTitle(componentName),\n },\n ] as const;\n }),\n );\n\n const key = configs.map(([path]) => path).join('/');\n const params = configs.reduce((acc, [, { params: p }]) => Object.assign(acc, p), {});\n const [, value] = configs[configs.length - 1];\n\n return [key, { ...value, params: Object.keys(params).length > 0 ? params : undefined }] as const;\n }),\n );\n\n return JSON.stringify(Object.fromEntries(res));\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,OAAO,YAAuB;AAC9B,SAAS,mCAAmC;AAE5C,OAAO,cAAc;AAGrB,SAAS,yCAAyC,wCAAwC;AAO1F,UAAU,QAAQ,MAA6B;AAC7C,QAAM;AAEN,aAAW,SAAS,KAAK,YAAY,GAAG;AACtC,WAAO,QAAQ,KAAK;AAAA,EACtB;AACF;AAQA,eAAO,qBAA4C,OAAmC;AACpF,QAAM,MAAM,MAAM,QAAQ;AAAA,IACxB,MAAM,KAAK,SAAS,KAAK,GAAG,OAAO,WAAW;AAC5C,YAAM,UAAU,MAAM,QAAQ;AAAA,QAC5B,OAAO,IAAI,OAAO,EAAE,MAAM,MAAM,OAAO,MAA2C;AAChF,cAAI,CAAC,QAAQ,CAAC,QAAQ;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C,CAAC;AACnF,YAAM,CAAC,EAAE,KAAK,IAAI,QAAQ,QAAQ,SAAS,CAAC;AAE5C,aAAO,CAAC,KAAK,EAAE,GAAG,OAAO,QAAQ,OAAO,KAAK,MAAM,EAAE,SAAS,IAAI,SAAS,OAAU,CAAC;AAAA,IACxF,CAAC;AAAA,EACH;AAEA,SAAO,KAAK,UAAU,OAAO,YAAY,GAAG,CAAC;AAC/C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Logger } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* The URLs of the files to generate.
|
|
4
|
+
*/
|
|
5
|
+
export type RuntimeFileUrls = Readonly<{
|
|
6
|
+
/**
|
|
7
|
+
* The URL of the JSON file with the leaf routes and their metadata. This file
|
|
8
|
+
* will be processed by the server to provide the final route configuration.
|
|
9
|
+
*/
|
|
10
|
+
json: URL;
|
|
11
|
+
/**
|
|
12
|
+
* The URL of the module with the routes tree in a framework-agnostic format.
|
|
13
|
+
*/
|
|
14
|
+
code: URL;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* Collects all file-based routes from the given directory, and based on them generates two files
|
|
18
|
+
* described by {@link RuntimeFileUrls} type.
|
|
19
|
+
* @param viewsDir - The directory that contains file-based routes (views).
|
|
20
|
+
* @param urls - The URLs of the files to generate.
|
|
21
|
+
* @param extensions - The list of extensions that will be collected as routes.
|
|
22
|
+
* @param logger - The Vite logger instance.
|
|
23
|
+
*/
|
|
24
|
+
export declare function generateRuntimeFiles(viewsDir: URL, urls: RuntimeFileUrls, extensions: readonly string[], logger: Logger): Promise<void>;
|
|
25
|
+
//# sourceMappingURL=generateRuntimeFiles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateRuntimeFiles.d.ts","sourceRoot":"","sources":["../src/vite-plugin/generateRuntimeFiles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAKnC;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;IACrC;;;OAGG;IACH,IAAI,EAAE,GAAG,CAAC;IACV;;OAEG;IACH,IAAI,EAAE,GAAG,CAAC;CACX,CAAC,CAAC;AAyBH;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,GAAG,EACb,IAAI,EAAE,eAAe,EACrB,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAcf"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import collectRoutesFromFS from "./collectRoutesFromFS.js";
|
|
3
|
+
import createRoutesFromMeta from "./createRoutesFromMeta.js";
|
|
4
|
+
import createViewConfigJson from "./createViewConfigJson.js";
|
|
5
|
+
async function generateRuntimeFile(url, data) {
|
|
6
|
+
await mkdir(new URL("./", url), { recursive: true });
|
|
7
|
+
let contents;
|
|
8
|
+
try {
|
|
9
|
+
contents = await readFile(url, "utf-8");
|
|
10
|
+
} catch (e) {
|
|
11
|
+
if (!(e != null && typeof e === "object" && "code" in e && e.code === "ENOENT")) {
|
|
12
|
+
throw e;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (contents !== data) {
|
|
16
|
+
await writeFile(url, data, "utf-8");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async function generateRuntimeFiles(viewsDir, urls, extensions, logger) {
|
|
20
|
+
const routeMeta = await collectRoutesFromFS(viewsDir, { extensions, logger });
|
|
21
|
+
logger.info("Collected file-based routes");
|
|
22
|
+
const runtimeRoutesCode = createRoutesFromMeta(routeMeta, urls);
|
|
23
|
+
const viewConfigJson = await createViewConfigJson(routeMeta);
|
|
24
|
+
await Promise.all([
|
|
25
|
+
generateRuntimeFile(urls.json, viewConfigJson).then(
|
|
26
|
+
() => logger.info(`Frontend route list is generated: ${String(urls.json)}`)
|
|
27
|
+
),
|
|
28
|
+
generateRuntimeFile(urls.code, runtimeRoutesCode).then(
|
|
29
|
+
() => logger.info(`Views module is generated: ${String(urls.code)}`)
|
|
30
|
+
)
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
generateRuntimeFiles
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=generateRuntimeFiles.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/vite-plugin/generateRuntimeFiles.ts"],
|
|
4
|
+
"sourcesContent": ["import { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport type { Logger } from 'vite';\nimport collectRoutesFromFS from './collectRoutesFromFS.js';\nimport createRoutesFromMeta from './createRoutesFromMeta.js';\nimport createViewConfigJson from './createViewConfigJson.js';\n\n/**\n * The URLs of the files to generate.\n */\nexport type RuntimeFileUrls = Readonly<{\n /**\n * The URL of the JSON file with the leaf routes and their metadata. This file\n * will be processed by the server to provide the final route configuration.\n */\n json: URL;\n /**\n * The URL of the module with the routes tree in a framework-agnostic format.\n */\n code: URL;\n}>;\n\n/**\n * Generates a file conditionally. If the file already exists and its content is the same as the\n * given data, the file will not be overwritten. It is useful to avoid unnecessary server\n * reboot during development.\n *\n * @param url - The URL of the file to generate.\n * @param data - The data to write to the file.\n */\nasync function generateRuntimeFile(url: URL, data: string): Promise<void> {\n await mkdir(new URL('./', url), { recursive: true });\n let contents: string | undefined;\n try {\n contents = await readFile(url, 'utf-8');\n } catch (e: unknown) {\n if (!(e != null && typeof e === 'object' && 'code' in e && e.code === 'ENOENT')) {\n throw e;\n }\n }\n if (contents !== data) {\n await writeFile(url, data, 'utf-8');\n }\n}\n\n/**\n * Collects all file-based routes from the given directory, and based on them generates two files\n * described by {@link RuntimeFileUrls} type.\n * @param viewsDir - The directory that contains file-based routes (views).\n * @param urls - The URLs of the files to generate.\n * @param extensions - The list of extensions that will be collected as routes.\n * @param logger - The Vite logger instance.\n */\nexport async function generateRuntimeFiles(\n viewsDir: URL,\n urls: RuntimeFileUrls,\n extensions: readonly string[],\n logger: Logger,\n): Promise<void> {\n const routeMeta = await collectRoutesFromFS(viewsDir, { extensions, logger });\n logger.info('Collected file-based routes');\n const runtimeRoutesCode = createRoutesFromMeta(routeMeta, urls);\n const viewConfigJson = await createViewConfigJson(routeMeta);\n\n await Promise.all([\n generateRuntimeFile(urls.json, viewConfigJson).then(() =>\n logger.info(`Frontend route list is generated: ${String(urls.json)}`),\n ),\n generateRuntimeFile(urls.code, runtimeRoutesCode).then(() =>\n logger.info(`Views module is generated: ${String(urls.code)}`),\n ),\n ]);\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,UAAU,iBAAiB;AAE3C,OAAO,yBAAyB;AAChC,OAAO,0BAA0B;AACjC,OAAO,0BAA0B;AAyBjC,eAAe,oBAAoB,KAAU,MAA6B;AACxE,QAAM,MAAM,IAAI,IAAI,MAAM,GAAG,GAAG,EAAE,WAAW,KAAK,CAAC;AACnD,MAAI;AACJ,MAAI;AACF,eAAW,MAAM,SAAS,KAAK,OAAO;AAAA,EACxC,SAAS,GAAY;AACnB,QAAI,EAAE,KAAK,QAAQ,OAAO,MAAM,YAAY,UAAU,KAAK,EAAE,SAAS,WAAW;AAC/E,YAAM;AAAA,IACR;AAAA,EACF;AACA,MAAI,aAAa,MAAM;AACrB,UAAM,UAAU,KAAK,MAAM,OAAO;AAAA,EACpC;AACF;AAUA,eAAsB,qBACpB,UACA,MACA,YACA,QACe;AACf,QAAM,YAAY,MAAM,oBAAoB,UAAU,EAAE,YAAY,OAAO,CAAC;AAC5E,SAAO,KAAK,6BAA6B;AACzC,QAAM,oBAAoB,qBAAqB,WAAW,IAAI;AAC9D,QAAM,iBAAiB,MAAM,qBAAqB,SAAS;AAE3D,QAAM,QAAQ,IAAI;AAAA,IAChB,oBAAoB,KAAK,MAAM,cAAc,EAAE;AAAA,MAAK,MAClD,OAAO,KAAK,qCAAqC,OAAO,KAAK,IAAI,CAAC,EAAE;AAAA,IACtE;AAAA,IACA,oBAAoB,KAAK,MAAM,iBAAiB,EAAE;AAAA,MAAK,MACrD,OAAO,KAAK,8BAA8B,OAAO,KAAK,IAAI,CAAC,EAAE;AAAA,IAC/D;AAAA,EACF,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { RouteParamType } from '../shared/routeParamType.js';
|
|
2
|
+
/**
|
|
3
|
+
* Converts a file system pattern to a URL pattern string.
|
|
4
|
+
*
|
|
5
|
+
* @param segment - a string representing a file system pattern:
|
|
6
|
+
* - `{param}` - for a required single parameter;
|
|
7
|
+
* - `{{param}}` - for an optional single parameter;
|
|
8
|
+
* - `{...wildcard}` - for multiple parameters, including none.
|
|
9
|
+
*
|
|
10
|
+
* @returns a string representing a URL pattern, respectively:
|
|
11
|
+
* - `:param`;
|
|
12
|
+
* - `:param?`;
|
|
13
|
+
* - `*`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function convertFSRouteSegmentToURLPatternFormat(segment: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Extracts the parameter name and its type from the route segment.
|
|
18
|
+
*
|
|
19
|
+
* @param segment - A part of the FS route URL.
|
|
20
|
+
* @returns A map of parameter names and their types.
|
|
21
|
+
*/
|
|
22
|
+
export declare function extractParameterFromRouteSegment(segment: string): Readonly<Record<string, RouteParamType>>;
|
|
23
|
+
/**
|
|
24
|
+
* A small helper function that clears route path of the control characters in
|
|
25
|
+
* order to sort the routes alphabetically.
|
|
26
|
+
*/
|
|
27
|
+
export declare function cleanUp(path: string): string;
|
|
28
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/vite-plugin/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAqB7D;;;;;;;;;;;;GAYG;AACH,wBAAgB,uCAAuC,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAQ/E;AAED;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAc1G;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ5C"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { RouteParamType } from "../shared/routeParamType.js";
|
|
2
|
+
const routeParamTypeMap = /* @__PURE__ */ new Map([
|
|
3
|
+
[RouteParamType.Wildcard, /\{\.{3}(.+)\}/gu],
|
|
4
|
+
[RouteParamType.Optional, /\{{2}(.+)\}{2}/gu],
|
|
5
|
+
[RouteParamType.Required, /\{(.+)\}/gu]
|
|
6
|
+
]);
|
|
7
|
+
function getReplacer(type) {
|
|
8
|
+
switch (type) {
|
|
9
|
+
case RouteParamType.Wildcard:
|
|
10
|
+
return "*";
|
|
11
|
+
case RouteParamType.Optional:
|
|
12
|
+
return ":$1?";
|
|
13
|
+
case RouteParamType.Required:
|
|
14
|
+
return ":$1";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function convertFSRouteSegmentToURLPatternFormat(segment) {
|
|
18
|
+
let res = segment;
|
|
19
|
+
routeParamTypeMap.forEach((pattern, type) => {
|
|
20
|
+
res = res.replaceAll(pattern, getReplacer(type));
|
|
21
|
+
});
|
|
22
|
+
return res;
|
|
23
|
+
}
|
|
24
|
+
function extractParameterFromRouteSegment(segment) {
|
|
25
|
+
let _segment = segment;
|
|
26
|
+
const params = {};
|
|
27
|
+
for (const [type, pattern] of routeParamTypeMap) {
|
|
28
|
+
const _pattern = new RegExp(pattern.source, pattern.flags);
|
|
29
|
+
_segment = _segment.replaceAll(_pattern, (match) => {
|
|
30
|
+
const key = match.replaceAll(pattern, getReplacer(type));
|
|
31
|
+
params[key] = type;
|
|
32
|
+
return "";
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return params;
|
|
36
|
+
}
|
|
37
|
+
function cleanUp(path) {
|
|
38
|
+
let res = path;
|
|
39
|
+
for (const pattern of routeParamTypeMap.values()) {
|
|
40
|
+
res = res.replaceAll(pattern, "$1");
|
|
41
|
+
}
|
|
42
|
+
return res;
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
cleanUp,
|
|
46
|
+
convertFSRouteSegmentToURLPatternFormat,
|
|
47
|
+
extractParameterFromRouteSegment
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/vite-plugin/utils.ts"],
|
|
4
|
+
"sourcesContent": ["import { RouteParamType } from '../shared/routeParamType.js';\n\nconst routeParamTypeMap: ReadonlyMap<RouteParamType, RegExp> = new Map([\n [RouteParamType.Wildcard, /\\{\\.{3}(.+)\\}/gu],\n [RouteParamType.Optional, /\\{{2}(.+)\\}{2}/gu],\n [RouteParamType.Required, /\\{(.+)\\}/gu],\n]);\n\n// eslint-disable-next-line consistent-return\nfunction getReplacer(type: RouteParamType): string {\n // eslint-disable-next-line default-case\n switch (type) {\n case RouteParamType.Wildcard:\n return '*';\n case RouteParamType.Optional:\n return ':$1?';\n case RouteParamType.Required:\n return ':$1';\n }\n}\n\n/**\n * Converts a file system pattern to a URL pattern string.\n *\n * @param segment - a string representing a file system pattern:\n * - `{param}` - for a required single parameter;\n * - `{{param}}` - for an optional single parameter;\n * - `{...wildcard}` - for multiple parameters, including none.\n *\n * @returns a string representing a URL pattern, respectively:\n * - `:param`;\n * - `:param?`;\n * - `*`.\n */\nexport function convertFSRouteSegmentToURLPatternFormat(segment: string): string {\n let res = segment;\n\n routeParamTypeMap.forEach((pattern, type) => {\n res = res.replaceAll(pattern, getReplacer(type));\n });\n\n return res;\n}\n\n/**\n * Extracts the parameter name and its type from the route segment.\n *\n * @param segment - A part of the FS route URL.\n * @returns A map of parameter names and their types.\n */\nexport function extractParameterFromRouteSegment(segment: string): Readonly<Record<string, RouteParamType>> {\n let _segment = segment;\n const params: Record<string, RouteParamType> = {};\n\n for (const [type, pattern] of routeParamTypeMap) {\n const _pattern = new RegExp(pattern.source, pattern.flags);\n _segment = _segment.replaceAll(_pattern, (match) => {\n const key = match.replaceAll(pattern, getReplacer(type));\n params[key] = type;\n return '';\n });\n }\n\n return params;\n}\n\n/**\n * A small helper function that clears route path of the control characters in\n * order to sort the routes alphabetically.\n */\nexport function cleanUp(path: string): string {\n let res = path;\n\n for (const pattern of routeParamTypeMap.values()) {\n res = res.replaceAll(pattern, '$1');\n }\n\n return res;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,sBAAsB;AAE/B,MAAM,oBAAyD,oBAAI,IAAI;AAAA,EACrE,CAAC,eAAe,UAAU,iBAAiB;AAAA,EAC3C,CAAC,eAAe,UAAU,kBAAkB;AAAA,EAC5C,CAAC,eAAe,UAAU,YAAY;AACxC,CAAC;AAGD,SAAS,YAAY,MAA8B;AAEjD,UAAQ,MAAM;AAAA,IACZ,KAAK,eAAe;AAClB,aAAO;AAAA,IACT,KAAK,eAAe;AAClB,aAAO;AAAA,IACT,KAAK,eAAe;AAClB,aAAO;AAAA,EACX;AACF;AAeO,SAAS,wCAAwC,SAAyB;AAC/E,MAAI,MAAM;AAEV,oBAAkB,QAAQ,CAAC,SAAS,SAAS;AAC3C,UAAM,IAAI,WAAW,SAAS,YAAY,IAAI,CAAC;AAAA,EACjD,CAAC;AAED,SAAO;AACT;AAQO,SAAS,iCAAiC,SAA2D;AAC1G,MAAI,WAAW;AACf,QAAM,SAAyC,CAAC;AAEhD,aAAW,CAAC,MAAM,OAAO,KAAK,mBAAmB;AAC/C,UAAM,WAAW,IAAI,OAAO,QAAQ,QAAQ,QAAQ,KAAK;AACzD,eAAW,SAAS,WAAW,UAAU,CAAC,UAAU;AAClD,YAAM,MAAM,MAAM,WAAW,SAAS,YAAY,IAAI,CAAC;AACvD,aAAO,GAAG,IAAI;AACd,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,SAAO;AACT;AAMO,SAAS,QAAQ,MAAsB;AAC5C,MAAI,MAAM;AAEV,aAAW,WAAW,kBAAkB,OAAO,GAAG;AAChD,UAAM,IAAI,WAAW,SAAS,IAAI;AAAA,EACpC;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/vite-plugin.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* The options for the Vite file-based router plugin.
|
|
4
|
+
*/
|
|
5
|
+
export type PluginOptions = Readonly<{
|
|
6
|
+
/**
|
|
7
|
+
* The base directory for the router. The folders and files in this directory
|
|
8
|
+
* will be used as route paths.
|
|
9
|
+
*
|
|
10
|
+
* @defaultValue `frontend/views`
|
|
11
|
+
*/
|
|
12
|
+
viewsDir?: URL | string;
|
|
13
|
+
/**
|
|
14
|
+
* The directory where the generated view file will be stored.
|
|
15
|
+
*
|
|
16
|
+
* @defaultValue `frontend/generated`
|
|
17
|
+
*/
|
|
18
|
+
generatedDir?: URL | string;
|
|
19
|
+
/**
|
|
20
|
+
* The list of extensions that will be collected as routes of the file-based
|
|
21
|
+
* router.
|
|
22
|
+
*
|
|
23
|
+
* @defaultValue `['.tsx', '.jsx', '.ts', '.js']`
|
|
24
|
+
*/
|
|
25
|
+
extensions?: readonly string[];
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* A Vite plugin that generates a router from the files in the specific directory.
|
|
29
|
+
*
|
|
30
|
+
* @param options - The plugin options.
|
|
31
|
+
* @returns A Vite plugin.
|
|
32
|
+
*/
|
|
33
|
+
export default function vitePluginFileSystemRouter({ viewsDir, generatedDir, extensions, }?: PluginOptions): Plugin;
|
|
34
|
+
//# sourceMappingURL=vite-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["src/vite-plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,MAAM,CAAC;AAG3C;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC;IACnC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC;IACxB;;;;OAIG;IACH,YAAY,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC;IAC5B;;;;;OAKG;IACH,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAChC,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,0BAA0B,CAAC,EACjD,QAA4B,EAC5B,YAAoC,EACpC,UAA2C,GAC5C,GAAE,aAAkB,GAAG,MAAM,CA8E7B"}
|
package/vite-plugin.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
3
|
+
import { generateRuntimeFiles } from "./vite-plugin/generateRuntimeFiles.js";
|
|
4
|
+
function vitePluginFileSystemRouter({
|
|
5
|
+
viewsDir = "frontend/views/",
|
|
6
|
+
generatedDir = "frontend/generated/",
|
|
7
|
+
extensions = [".tsx", ".jsx", ".ts", ".js"]
|
|
8
|
+
} = {}) {
|
|
9
|
+
const hmrInjectionPattern = /(?<=import\.meta\.hot\.accept[\s\S]+)if\s\(!nextExports\)\s+return;/u;
|
|
10
|
+
let _viewsDir;
|
|
11
|
+
let _outDir;
|
|
12
|
+
let _logger;
|
|
13
|
+
let runtimeUrls;
|
|
14
|
+
return {
|
|
15
|
+
name: "vite-plugin-file-router",
|
|
16
|
+
configResolved({ logger, root, build: { outDir } }) {
|
|
17
|
+
const _root = pathToFileURL(root);
|
|
18
|
+
const _generatedDir = new URL(generatedDir, _root);
|
|
19
|
+
_viewsDir = new URL(viewsDir, _root);
|
|
20
|
+
_outDir = pathToFileURL(outDir);
|
|
21
|
+
_logger = logger;
|
|
22
|
+
_logger.info(`The directory of route files: ${String(_viewsDir)}`);
|
|
23
|
+
_logger.info(`The directory of generated files: ${String(_generatedDir)}`);
|
|
24
|
+
_logger.info(`The output directory: ${String(_outDir)}`);
|
|
25
|
+
runtimeUrls = {
|
|
26
|
+
json: new URL("views.json", _outDir),
|
|
27
|
+
code: new URL("views.ts", _generatedDir)
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
async buildStart() {
|
|
31
|
+
try {
|
|
32
|
+
await generateRuntimeFiles(_viewsDir, runtimeUrls, extensions, _logger);
|
|
33
|
+
} catch (e) {
|
|
34
|
+
_logger.error(String(e));
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
configureServer(server) {
|
|
38
|
+
const dir = fileURLToPath(_viewsDir);
|
|
39
|
+
const changeListener = (file) => {
|
|
40
|
+
if (!file.startsWith(dir)) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
generateRuntimeFiles(_viewsDir, runtimeUrls, extensions, _logger).catch(
|
|
44
|
+
(e) => _logger.error(String(e))
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
server.watcher.on("add", changeListener);
|
|
48
|
+
server.watcher.on("change", changeListener);
|
|
49
|
+
server.watcher.on("unlink", changeListener);
|
|
50
|
+
},
|
|
51
|
+
transform(code, id) {
|
|
52
|
+
if (id.startsWith(fileURLToPath(_viewsDir)) && !basename(id).startsWith("_")) {
|
|
53
|
+
return {
|
|
54
|
+
code: code.replace(
|
|
55
|
+
hmrInjectionPattern,
|
|
56
|
+
`if (!nextExports) return;
|
|
57
|
+
if (Object.keys(nextExports).length === 2 && 'default' in nextExports && 'config' in nextExports) {
|
|
58
|
+
nextExports = { ...nextExports, config: currentExports.config };
|
|
59
|
+
}`
|
|
60
|
+
)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
vitePluginFileSystemRouter as default
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=vite-plugin.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["src/vite-plugin.ts"],
|
|
4
|
+
"sourcesContent": ["import { basename } from 'node:path';\nimport { fileURLToPath, pathToFileURL } from 'node:url';\nimport type { TransformResult } from 'rollup';\nimport type { Logger, Plugin } from 'vite';\nimport { generateRuntimeFiles, type RuntimeFileUrls } from './vite-plugin/generateRuntimeFiles.js';\n\n/**\n * The options for the Vite file-based router plugin.\n */\nexport type PluginOptions = Readonly<{\n /**\n * The base directory for the router. The folders and files in this directory\n * will be used as route paths.\n *\n * @defaultValue `frontend/views`\n */\n viewsDir?: URL | string;\n /**\n * The directory where the generated view file will be stored.\n *\n * @defaultValue `frontend/generated`\n */\n generatedDir?: URL | string;\n /**\n * The list of extensions that will be collected as routes of the file-based\n * router.\n *\n * @defaultValue `['.tsx', '.jsx', '.ts', '.js']`\n */\n extensions?: readonly string[];\n}>;\n\n/**\n * A Vite plugin that generates a router from the files in the specific directory.\n *\n * @param options - The plugin options.\n * @returns A Vite plugin.\n */\nexport default function vitePluginFileSystemRouter({\n viewsDir = 'frontend/views/',\n generatedDir = 'frontend/generated/',\n extensions = ['.tsx', '.jsx', '.ts', '.js'],\n}: PluginOptions = {}): Plugin {\n const hmrInjectionPattern = /(?<=import\\.meta\\.hot\\.accept[\\s\\S]+)if\\s\\(!nextExports\\)\\s+return;/u;\n\n let _viewsDir: URL;\n let _outDir: URL;\n let _logger: Logger;\n let runtimeUrls: RuntimeFileUrls;\n\n return {\n name: 'vite-plugin-file-router',\n configResolved({ logger, root, build: { outDir } }) {\n const _root = pathToFileURL(root);\n const _generatedDir = new URL(generatedDir, _root);\n\n _viewsDir = new URL(viewsDir, _root);\n _outDir = pathToFileURL(outDir);\n _logger = logger;\n\n _logger.info(`The directory of route files: ${String(_viewsDir)}`);\n _logger.info(`The directory of generated files: ${String(_generatedDir)}`);\n _logger.info(`The output directory: ${String(_outDir)}`);\n\n runtimeUrls = {\n json: new URL('views.json', _outDir),\n code: new URL('views.ts', _generatedDir),\n };\n },\n async buildStart() {\n try {\n await generateRuntimeFiles(_viewsDir, runtimeUrls, extensions, _logger);\n } catch (e: unknown) {\n _logger.error(String(e));\n }\n },\n configureServer(server) {\n const dir = fileURLToPath(_viewsDir);\n\n const changeListener = (file: string): void => {\n if (!file.startsWith(dir)) {\n return;\n }\n\n generateRuntimeFiles(_viewsDir, runtimeUrls, extensions, _logger).catch((e: unknown) =>\n _logger.error(String(e)),\n );\n };\n\n server.watcher.on('add', changeListener);\n server.watcher.on('change', changeListener);\n server.watcher.on('unlink', changeListener);\n },\n transform(code, id): Promise<TransformResult> | TransformResult {\n if (id.startsWith(fileURLToPath(_viewsDir)) && !basename(id).startsWith('_')) {\n // To enable HMR for route files with exported configurations, we need\n // to address a limitation in `react-refresh`. This library requires\n // strict equality (`===`) for non-component exports. However, the\n // dynamic nature of HMR makes maintaining this equality between object\n // literals challenging.\n //\n // To work around this, we implement a strategy that preserves the\n // reference to the original configuration object (`currentExports.config`),\n // replacing any newly created configuration objects (`nextExports.config`)\n // with it. This ensures that the HMR mechanism perceives the\n // configuration as unchanged.\n return {\n code: code.replace(\n hmrInjectionPattern,\n `if (!nextExports) return;\n if (Object.keys(nextExports).length === 2 && 'default' in nextExports && 'config' in nextExports) {\n nextExports = { ...nextExports, config: currentExports.config };\n }`,\n ),\n };\n }\n\n return undefined;\n },\n };\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAS,eAAe,qBAAqB;AAG7C,SAAS,4BAAkD;AAkC5C,SAAR,2BAA4C;AAAA,EACjD,WAAW;AAAA,EACX,eAAe;A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