@octanejs/tanstack-start 0.1.0
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/LICENSE +22 -0
- package/README.md +52 -0
- package/THIRD_PARTY_NOTICES.md +11 -0
- package/package.json +149 -0
- package/src/client-only.d.ts +1 -0
- package/src/client-only.js +0 -0
- package/src/client-rpc.d.ts +1 -0
- package/src/client-rpc.js +1 -0
- package/src/client.d.ts +3 -0
- package/src/client.js +2 -0
- package/src/default-entry/client.js +12 -0
- package/src/default-entry/server.js +13 -0
- package/src/default-entry/start.js +1 -0
- package/src/default-entry-paths.d.ts +5 -0
- package/src/default-entry-paths.js +11 -0
- package/src/index.d.ts +11 -0
- package/src/index.js +22 -0
- package/src/internal/README.md +15 -0
- package/src/internal/router-generator/config.d.ts +255 -0
- package/src/internal/router-generator/config.js +134 -0
- package/src/internal/router-generator/filesystem/physical/getRouteNodes.d.ts +53 -0
- package/src/internal/router-generator/filesystem/physical/getRouteNodes.js +335 -0
- package/src/internal/router-generator/filesystem/physical/rootPathId.d.ts +1 -0
- package/src/internal/router-generator/filesystem/physical/rootPathId.js +4 -0
- package/src/internal/router-generator/filesystem/virtual/config.d.ts +3 -0
- package/src/internal/router-generator/filesystem/virtual/config.js +36 -0
- package/src/internal/router-generator/filesystem/virtual/getRouteNodes.d.ts +31 -0
- package/src/internal/router-generator/filesystem/virtual/getRouteNodes.js +272 -0
- package/src/internal/router-generator/filesystem/virtual/loadConfigFile.d.ts +1 -0
- package/src/internal/router-generator/filesystem/virtual/loadConfigFile.js +10 -0
- package/src/internal/router-generator/generator.d.ts +119 -0
- package/src/internal/router-generator/generator.js +1080 -0
- package/src/internal/router-generator/index.d.ts +40 -0
- package/src/internal/router-generator/index.js +49 -0
- package/src/internal/router-generator/logger.d.ts +8 -0
- package/src/internal/router-generator/logger.js +30 -0
- package/src/internal/router-generator/plugin/types.d.ts +37 -0
- package/src/internal/router-generator/template.d.ts +38 -0
- package/src/internal/router-generator/template.js +220 -0
- package/src/internal/router-generator/transform/transform.d.ts +8 -0
- package/src/internal/router-generator/transform/transform.js +385 -0
- package/src/internal/router-generator/transform/types.d.ts +34 -0
- package/src/internal/router-generator/types.d.ts +73 -0
- package/src/internal/router-generator/utils.d.ts +270 -0
- package/src/internal/router-generator/utils.js +864 -0
- package/src/internal/router-generator/validate-route-params.d.ts +13 -0
- package/src/internal/router-generator/validate-route-params.js +75 -0
- package/src/internal/router-plugin/context.d.ts +2 -0
- package/src/internal/router-plugin/context.js +2 -0
- package/src/internal/router-plugin/core/code-splitter/compilers.d.ts +69 -0
- package/src/internal/router-plugin/core/code-splitter/compilers.js +1042 -0
- package/src/internal/router-plugin/core/code-splitter/framework-options.d.ts +11 -0
- package/src/internal/router-plugin/core/code-splitter/framework-options.js +41 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/framework-plugins.d.ts +12 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/framework-plugins.js +35 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/octane-hmr-split-route-components.d.ts +5 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/octane-hmr-split-route-components.js +106 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/octane-split-route-components.d.ts +8 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/octane-split-route-components.js +85 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-ignored-route-exports.d.ts +2 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-ignored-route-exports.js +55 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-route-components.d.ts +2 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-route-components.js +50 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/react-stable-hmr-split-route-components.d.ts +5 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/react-stable-hmr-split-route-components.js +54 -0
- package/src/internal/router-plugin/core/code-splitter/plugins.d.ts +62 -0
- package/src/internal/router-plugin/core/code-splitter/types.d.ts +9 -0
- package/src/internal/router-plugin/core/config.d.ts +294 -0
- package/src/internal/router-plugin/core/config.js +56 -0
- package/src/internal/router-plugin/core/constants.d.ts +12 -0
- package/src/internal/router-plugin/core/constants.js +13 -0
- package/src/internal/router-plugin/core/framework-plugin-order.d.ts +8 -0
- package/src/internal/router-plugin/core/framework-plugin-order.js +78 -0
- package/src/internal/router-plugin/core/hmr/handle-route-update.d.ts +1 -0
- package/src/internal/router-plugin/core/hmr/handle-route-update.js +126 -0
- package/src/internal/router-plugin/core/hmr/index.d.ts +5 -0
- package/src/internal/router-plugin/core/hmr/select-adapter.d.ts +17 -0
- package/src/internal/router-plugin/core/hmr/select-adapter.js +24 -0
- package/src/internal/router-plugin/core/hmr/vite-adapter.d.ts +18 -0
- package/src/internal/router-plugin/core/hmr/vite-adapter.js +73 -0
- package/src/internal/router-plugin/core/hmr/webpack-adapter.d.ts +22 -0
- package/src/internal/router-plugin/core/hmr/webpack-adapter.js +78 -0
- package/src/internal/router-plugin/core/router-code-splitter-plugin.d.ts +10 -0
- package/src/internal/router-plugin/core/router-code-splitter-plugin.js +244 -0
- package/src/internal/router-plugin/core/router-composed-plugin.d.ts +5 -0
- package/src/internal/router-plugin/core/router-composed-plugin.js +62 -0
- package/src/internal/router-plugin/core/router-generator-plugin.d.ts +10 -0
- package/src/internal/router-plugin/core/router-generator-plugin.js +125 -0
- package/src/internal/router-plugin/core/router-hmr-plugin.d.ts +13 -0
- package/src/internal/router-plugin/core/router-hmr-plugin.js +101 -0
- package/src/internal/router-plugin/core/router-plugin-context.d.ts +5 -0
- package/src/internal/router-plugin/core/router-plugin-context.js +6 -0
- package/src/internal/router-plugin/core/utils.d.ts +17 -0
- package/src/internal/router-plugin/core/utils.js +47 -0
- package/src/internal/router-plugin/esbuild.d.ts +197 -0
- package/src/internal/router-plugin/esbuild.js +58 -0
- package/src/internal/router-plugin/index.d.ts +19 -0
- package/src/internal/router-plugin/index.js +17 -0
- package/src/internal/router-plugin/rspack.d.ts +61 -0
- package/src/internal/router-plugin/rspack.js +92 -0
- package/src/internal/router-plugin/vite.d.ts +201 -0
- package/src/internal/router-plugin/vite.js +62 -0
- package/src/internal/router-plugin/webpack.d.ts +50 -0
- package/src/internal/router-plugin/webpack.js +77 -0
- package/src/internal/start-plugin-core/build-sitemap.d.ts +34 -0
- package/src/internal/start-plugin-core/build-sitemap.js +125 -0
- package/src/internal/start-plugin-core/config-context.d.ts +30 -0
- package/src/internal/start-plugin-core/config-context.js +89 -0
- package/src/internal/start-plugin-core/constants.d.ts +20 -0
- package/src/internal/start-plugin-core/constants.js +24 -0
- package/src/internal/start-plugin-core/debug.d.ts +1 -0
- package/src/internal/start-plugin-core/hydrate-when-transform.d.ts +5 -0
- package/src/internal/start-plugin-core/hydrate-when-transform.js +661 -0
- package/src/internal/start-plugin-core/hydration-constants.d.ts +1 -0
- package/src/internal/start-plugin-core/hydration-constants.js +4 -0
- package/src/internal/start-plugin-core/import-protection/adapterUtils.d.ts +40 -0
- package/src/internal/start-plugin-core/import-protection/adapterUtils.js +42 -0
- package/src/internal/start-plugin-core/import-protection/analysis.d.ts +63 -0
- package/src/internal/start-plugin-core/import-protection/analysis.js +533 -0
- package/src/internal/start-plugin-core/import-protection/constants.d.ts +11 -0
- package/src/internal/start-plugin-core/import-protection/constants.js +39 -0
- package/src/internal/start-plugin-core/import-protection/defaults.d.ts +19 -0
- package/src/internal/start-plugin-core/import-protection/defaults.js +34 -0
- package/src/internal/start-plugin-core/import-protection/extensionlessAbsoluteIdResolver.d.ts +22 -0
- package/src/internal/start-plugin-core/import-protection/extensionlessAbsoluteIdResolver.js +94 -0
- package/src/internal/start-plugin-core/import-protection/matchers.d.ts +18 -0
- package/src/internal/start-plugin-core/import-protection/matchers.js +39 -0
- package/src/internal/start-plugin-core/import-protection/rewrite.d.ts +29 -0
- package/src/internal/start-plugin-core/import-protection/rewrite.js +184 -0
- package/src/internal/start-plugin-core/import-protection/sourceLocation.d.ts +170 -0
- package/src/internal/start-plugin-core/import-protection/sourceLocation.js +376 -0
- package/src/internal/start-plugin-core/import-protection/trace.d.ts +89 -0
- package/src/internal/start-plugin-core/import-protection/trace.js +186 -0
- package/src/internal/start-plugin-core/import-protection/utils.d.ts +78 -0
- package/src/internal/start-plugin-core/import-protection/utils.js +171 -0
- package/src/internal/start-plugin-core/import-protection/virtualModules.d.ts +38 -0
- package/src/internal/start-plugin-core/import-protection/virtualModules.js +241 -0
- package/src/internal/start-plugin-core/index.d.ts +8 -0
- package/src/internal/start-plugin-core/index.js +2 -0
- package/src/internal/start-plugin-core/planning.d.ts +44 -0
- package/src/internal/start-plugin-core/planning.js +98 -0
- package/src/internal/start-plugin-core/post-build.d.ts +12 -0
- package/src/internal/start-plugin-core/post-build.js +40 -0
- package/src/internal/start-plugin-core/prerender.d.ts +17 -0
- package/src/internal/start-plugin-core/prerender.js +172 -0
- package/src/internal/start-plugin-core/queue.d.ts +37 -0
- package/src/internal/start-plugin-core/queue.js +118 -0
- package/src/internal/start-plugin-core/resolve-entries.d.ts +10 -0
- package/src/internal/start-plugin-core/resolve-entries.js +32 -0
- package/src/internal/start-plugin-core/schema.d.ts +1799 -0
- package/src/internal/start-plugin-core/schema.js +252 -0
- package/src/internal/start-plugin-core/serialization-adapters-module.d.ts +18 -0
- package/src/internal/start-plugin-core/serialization-adapters-module.js +37 -0
- package/src/internal/start-plugin-core/start-compiler/compiler.d.ts +181 -0
- package/src/internal/start-plugin-core/start-compiler/compiler.js +1078 -0
- package/src/internal/start-plugin-core/start-compiler/config.d.ts +20 -0
- package/src/internal/start-plugin-core/start-compiler/config.js +84 -0
- package/src/internal/start-plugin-core/start-compiler/handleClientOnlyJSX.d.ts +24 -0
- package/src/internal/start-plugin-core/start-compiler/handleClientOnlyJSX.js +25 -0
- package/src/internal/start-plugin-core/start-compiler/handleCreateIsomorphicFn.d.ts +11 -0
- package/src/internal/start-plugin-core/start-compiler/handleCreateIsomorphicFn.js +24 -0
- package/src/internal/start-plugin-core/start-compiler/handleCreateMiddleware.d.ts +11 -0
- package/src/internal/start-plugin-core/start-compiler/handleCreateMiddleware.js +35 -0
- package/src/internal/start-plugin-core/start-compiler/handleCreateServerFn.d.ts +22 -0
- package/src/internal/start-plugin-core/start-compiler/handleCreateServerFn.js +292 -0
- package/src/internal/start-plugin-core/start-compiler/handleEnvOnly.d.ts +14 -0
- package/src/internal/start-plugin-core/start-compiler/handleEnvOnly.js +41 -0
- package/src/internal/start-plugin-core/start-compiler/host.d.ts +44 -0
- package/src/internal/start-plugin-core/start-compiler/host.js +75 -0
- package/src/internal/start-plugin-core/start-compiler/server-fn-resolver-module.d.ts +10 -0
- package/src/internal/start-plugin-core/start-compiler/server-fn-resolver-module.js +87 -0
- package/src/internal/start-plugin-core/start-compiler/types.d.ts +119 -0
- package/src/internal/start-plugin-core/start-compiler/utils.d.ts +27 -0
- package/src/internal/start-plugin-core/start-compiler/utils.js +36 -0
- package/src/internal/start-plugin-core/start-manifest-plugin/inlineCss.d.ts +16 -0
- package/src/internal/start-plugin-core/start-manifest-plugin/inlineCss.js +131 -0
- package/src/internal/start-plugin-core/start-manifest-plugin/manifestBuilder.d.ts +64 -0
- package/src/internal/start-plugin-core/start-manifest-plugin/manifestBuilder.js +441 -0
- package/src/internal/start-plugin-core/start-router-plugin/constants.d.ts +1 -0
- package/src/internal/start-plugin-core/start-router-plugin/constants.js +4 -0
- package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/compose-generator-plugins.d.ts +6 -0
- package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/compose-generator-plugins.js +6 -0
- package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/prerender-routes-plugin.d.ts +6 -0
- package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/prerender-routes-plugin.js +27 -0
- package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/routes-manifest-plugin.d.ts +6 -0
- package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/routes-manifest-plugin.js +34 -0
- package/src/internal/start-plugin-core/start-router-plugin/pruneServerOnlySubtrees.d.ts +11 -0
- package/src/internal/start-plugin-core/start-router-plugin/pruneServerOnlySubtrees.js +42 -0
- package/src/internal/start-plugin-core/start-router-plugin/route-tree-footer.d.ts +6 -0
- package/src/internal/start-plugin-core/start-router-plugin/route-tree-footer.js +59 -0
- package/src/internal/start-plugin-core/types.d.ts +135 -0
- package/src/internal/start-plugin-core/types.js +4 -0
- package/src/internal/start-plugin-core/utils.d.ts +13 -0
- package/src/internal/start-plugin-core/utils.js +42 -0
- package/src/internal/start-plugin-core/vite/createVirtualModule.d.ts +15 -0
- package/src/internal/start-plugin-core/vite/createVirtualModule.js +27 -0
- package/src/internal/start-plugin-core/vite/dev-server-plugin/dev-styles.d.ts +26 -0
- package/src/internal/start-plugin-core/vite/dev-server-plugin/dev-styles.js +165 -0
- package/src/internal/start-plugin-core/vite/dev-server-plugin/plugin.d.ts +11 -0
- package/src/internal/start-plugin-core/vite/dev-server-plugin/plugin.js +170 -0
- package/src/internal/start-plugin-core/vite/import-protection-plugin/plugin.d.ts +4 -0
- package/src/internal/start-plugin-core/vite/import-protection-plugin/plugin.js +1553 -0
- package/src/internal/start-plugin-core/vite/import-protection-plugin/types.d.ts +103 -0
- package/src/internal/start-plugin-core/vite/import-protection-plugin/virtualModules.d.ts +40 -0
- package/src/internal/start-plugin-core/vite/import-protection-plugin/virtualModules.js +68 -0
- package/src/internal/start-plugin-core/vite/index.d.ts +13 -0
- package/src/internal/start-plugin-core/vite/index.js +4 -0
- package/src/internal/start-plugin-core/vite/load-env-plugin/plugin.d.ts +2 -0
- package/src/internal/start-plugin-core/vite/load-env-plugin/plugin.js +13 -0
- package/src/internal/start-plugin-core/vite/output-directory.d.ts +7 -0
- package/src/internal/start-plugin-core/vite/output-directory.js +18 -0
- package/src/internal/start-plugin-core/vite/planning.d.ts +112 -0
- package/src/internal/start-plugin-core/vite/planning.js +152 -0
- package/src/internal/start-plugin-core/vite/plugin.d.ts +7 -0
- package/src/internal/start-plugin-core/vite/plugin.js +208 -0
- package/src/internal/start-plugin-core/vite/plugins.d.ts +17 -0
- package/src/internal/start-plugin-core/vite/plugins.js +72 -0
- package/src/internal/start-plugin-core/vite/post-server-build.d.ts +9 -0
- package/src/internal/start-plugin-core/vite/post-server-build.js +22 -0
- package/src/internal/start-plugin-core/vite/prerender.d.ts +9 -0
- package/src/internal/start-plugin-core/vite/prerender.js +52 -0
- package/src/internal/start-plugin-core/vite/preview-server-plugin/plugin.d.ts +2 -0
- package/src/internal/start-plugin-core/vite/preview-server-plugin/plugin.js +54 -0
- package/src/internal/start-plugin-core/vite/schema.d.ts +2423 -0
- package/src/internal/start-plugin-core/vite/schema.js +17 -0
- package/src/internal/start-plugin-core/vite/serialization-adapters-plugin.d.ts +5 -0
- package/src/internal/start-plugin-core/vite/serialization-adapters-plugin.js +63 -0
- package/src/internal/start-plugin-core/vite/start-compiler-plugin/hot-update.d.ts +5 -0
- package/src/internal/start-plugin-core/vite/start-compiler-plugin/hot-update.js +14 -0
- package/src/internal/start-plugin-core/vite/start-compiler-plugin/module-specifier.d.ts +5 -0
- package/src/internal/start-plugin-core/vite/start-compiler-plugin/module-specifier.js +25 -0
- package/src/internal/start-plugin-core/vite/start-compiler-plugin/plugin.d.ts +29 -0
- package/src/internal/start-plugin-core/vite/start-compiler-plugin/plugin.js +380 -0
- package/src/internal/start-plugin-core/vite/start-manifest-plugin/normalized-client-build.d.ts +11 -0
- package/src/internal/start-plugin-core/vite/start-manifest-plugin/normalized-client-build.js +114 -0
- package/src/internal/start-plugin-core/vite/start-manifest-plugin/plugin.d.ts +3 -0
- package/src/internal/start-plugin-core/vite/start-manifest-plugin/plugin.js +103 -0
- package/src/internal/start-plugin-core/vite/start-router-plugin/plugin.d.ts +9 -0
- package/src/internal/start-plugin-core/vite/start-router-plugin/plugin.js +143 -0
- package/src/internal/start-plugin-core/vite/types.d.ts +17 -0
- package/src/package-names.js +10 -0
- package/src/plugin-vite.d.ts +23 -0
- package/src/plugin-vite.js +62 -0
- package/src/runtime/client/StartClient.d.ts +11 -0
- package/src/runtime/client/StartClient.js +16 -0
- package/src/runtime/client/hydrateStart.d.ts +4 -0
- package/src/runtime/client/hydrateStart.js +30 -0
- package/src/runtime/server/StartServer.d.ts +10 -0
- package/src/runtime/server/StartServer.js +6 -0
- package/src/runtime/server/defaultRenderHandler.d.ts +3 -0
- package/src/runtime/server/defaultRenderHandler.js +11 -0
- package/src/runtime/server/defaultStreamHandler.d.ts +3 -0
- package/src/runtime/server/defaultStreamHandler.js +13 -0
- package/src/server-entry.d.ts +11 -0
- package/src/server-entry.js +13 -0
- package/src/server-only.d.ts +1 -0
- package/src/server-only.js +0 -0
- package/src/server-rpc.d.ts +1 -0
- package/src/server-rpc.js +1 -0
- package/src/server.d.ts +6 -0
- package/src/server.js +4 -0
- package/src/ssr-rpc.d.ts +1 -0
- package/src/ssr-rpc.js +1 -0
- package/src/use-server-fn.d.ts +3 -0
- package/src/use-server-fn.js +18 -0
- package/src/validate-options.js +7 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { virtualRootRouteSchema } from './config.js';
|
|
2
|
+
import { rootPathId } from '../physical/rootPathId.js';
|
|
3
|
+
import {
|
|
4
|
+
cleanPath,
|
|
5
|
+
createLiteralRoutePathSegmentMetadata,
|
|
6
|
+
createRoutePathSegmentMetadata,
|
|
7
|
+
determineInitialRoutePathFromExplicitPath,
|
|
8
|
+
joinRoutePathSegmentMetadata,
|
|
9
|
+
removeExt,
|
|
10
|
+
removeLeadingSlash,
|
|
11
|
+
removeTrailingSlash,
|
|
12
|
+
replaceBackslash,
|
|
13
|
+
routePathToVariable,
|
|
14
|
+
} from '../../utils.js';
|
|
15
|
+
import { loadConfigFile } from './loadConfigFile.js';
|
|
16
|
+
import { getRouteNodes as getRouteNodes$1 } from '../physical/getRouteNodes.js';
|
|
17
|
+
import path, { join, resolve } from 'node:path';
|
|
18
|
+
//#region src/filesystem/virtual/getRouteNodes.ts
|
|
19
|
+
function ensureLeadingUnderScore(id) {
|
|
20
|
+
if (id.startsWith('_')) return id;
|
|
21
|
+
return `_${id}`;
|
|
22
|
+
}
|
|
23
|
+
function flattenTree(node) {
|
|
24
|
+
const result = [node];
|
|
25
|
+
if (node.children) for (const child of node.children) result.push(...flattenTree(child));
|
|
26
|
+
delete node.children;
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
async function getRouteNodes(tsrConfig, root, tokenRegexes) {
|
|
30
|
+
const fullDir = resolve(tsrConfig.routesDirectory);
|
|
31
|
+
if (tsrConfig.virtualRouteConfig === void 0) throw new Error(`virtualRouteConfig is undefined`);
|
|
32
|
+
let virtualRouteConfig;
|
|
33
|
+
if (typeof tsrConfig.virtualRouteConfig === 'string')
|
|
34
|
+
virtualRouteConfig = await getVirtualRouteConfigFromFileExport(tsrConfig, root);
|
|
35
|
+
else virtualRouteConfig = tsrConfig.virtualRouteConfig;
|
|
36
|
+
const { children, physicalDirectories } = await getRouteNodesRecursive(
|
|
37
|
+
tsrConfig,
|
|
38
|
+
root,
|
|
39
|
+
fullDir,
|
|
40
|
+
virtualRouteConfig.children,
|
|
41
|
+
tokenRegexes,
|
|
42
|
+
);
|
|
43
|
+
const allNodes = flattenTree({
|
|
44
|
+
children,
|
|
45
|
+
filePath: virtualRouteConfig.file,
|
|
46
|
+
fullPath: replaceBackslash(join(fullDir, virtualRouteConfig.file)),
|
|
47
|
+
variableName: 'root',
|
|
48
|
+
routePath: `/${rootPathId}`,
|
|
49
|
+
_fsRouteType: '__root',
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
rootRouteNode: allNodes[0],
|
|
53
|
+
routeNodes: allNodes.slice(1),
|
|
54
|
+
physicalDirectories,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get the virtual route config from a file export
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* // routes.ts
|
|
63
|
+
* import { rootRoute } from '@tanstack/virtual-file-routes'
|
|
64
|
+
*
|
|
65
|
+
* export const routes = rootRoute({ ... })
|
|
66
|
+
* // or
|
|
67
|
+
* export default rootRoute({ ... })
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
*/
|
|
71
|
+
async function getVirtualRouteConfigFromFileExport(tsrConfig, root) {
|
|
72
|
+
if (
|
|
73
|
+
tsrConfig.virtualRouteConfig === void 0 ||
|
|
74
|
+
typeof tsrConfig.virtualRouteConfig !== 'string' ||
|
|
75
|
+
tsrConfig.virtualRouteConfig === ''
|
|
76
|
+
)
|
|
77
|
+
throw new Error(`virtualRouteConfig is undefined or empty`);
|
|
78
|
+
const exports = await loadConfigFile(join(root, tsrConfig.virtualRouteConfig));
|
|
79
|
+
if (!('routes' in exports) && !('default' in exports))
|
|
80
|
+
throw new Error(
|
|
81
|
+
`routes not found in ${tsrConfig.virtualRouteConfig}. The routes export must be named like 'export const routes = ...' or done using 'export default ...'`,
|
|
82
|
+
);
|
|
83
|
+
const virtualRouteConfig = 'routes' in exports ? exports.routes : exports.default;
|
|
84
|
+
return virtualRootRouteSchema.parse(virtualRouteConfig);
|
|
85
|
+
}
|
|
86
|
+
async function getRouteNodesRecursive(tsrConfig, root, fullDir, nodes, tokenRegexes, parent) {
|
|
87
|
+
if (nodes === void 0)
|
|
88
|
+
return {
|
|
89
|
+
children: [],
|
|
90
|
+
physicalDirectories: [],
|
|
91
|
+
};
|
|
92
|
+
const allPhysicalDirectories = [];
|
|
93
|
+
return {
|
|
94
|
+
children: (
|
|
95
|
+
await Promise.all(
|
|
96
|
+
nodes.map(async (node) => {
|
|
97
|
+
if (node.type === 'physical') {
|
|
98
|
+
const { routePath: routePathPrefix, originalRoutePath: originalRoutePathPrefix } =
|
|
99
|
+
node.pathPrefix
|
|
100
|
+
? determineInitialRoutePathFromExplicitPath(removeLeadingSlash(node.pathPrefix))
|
|
101
|
+
: {
|
|
102
|
+
routePath: '',
|
|
103
|
+
originalRoutePath: '',
|
|
104
|
+
};
|
|
105
|
+
const { routeNodes, physicalDirectories } = await getRouteNodes$1(
|
|
106
|
+
{
|
|
107
|
+
...tsrConfig,
|
|
108
|
+
routesDirectory: resolve(fullDir, node.directory),
|
|
109
|
+
},
|
|
110
|
+
root,
|
|
111
|
+
tokenRegexes,
|
|
112
|
+
);
|
|
113
|
+
allPhysicalDirectories.push(resolve(fullDir, node.directory), ...physicalDirectories);
|
|
114
|
+
routeNodes.forEach((subtreeNode) => {
|
|
115
|
+
const pathPrefix = cleanPath(`${parent?.routePath ?? ''}${routePathPrefix}`);
|
|
116
|
+
const originalPathPrefix = cleanPath(
|
|
117
|
+
`${parent?.originalRoutePath ?? parent?.routePath ?? ''}${originalRoutePathPrefix}`,
|
|
118
|
+
);
|
|
119
|
+
const literalPathPrefixSegments = createLiteralRoutePathSegmentMetadata(
|
|
120
|
+
pathPrefix,
|
|
121
|
+
parent,
|
|
122
|
+
true,
|
|
123
|
+
);
|
|
124
|
+
const routePath = cleanPath(`${pathPrefix}${subtreeNode.routePath}`);
|
|
125
|
+
subtreeNode.variableName = routePathToVariable(
|
|
126
|
+
`${routePathPrefix}/${removeExt(subtreeNode.filePath)}`,
|
|
127
|
+
);
|
|
128
|
+
subtreeNode._routePathSegmentMetadata = joinRoutePathSegmentMetadata(
|
|
129
|
+
routePath,
|
|
130
|
+
pathPrefix,
|
|
131
|
+
literalPathPrefixSegments,
|
|
132
|
+
subtreeNode._routePathSegmentMetadata,
|
|
133
|
+
);
|
|
134
|
+
subtreeNode.routePath = routePath;
|
|
135
|
+
if (subtreeNode.originalRoutePath)
|
|
136
|
+
subtreeNode.originalRoutePath = cleanPath(
|
|
137
|
+
`${originalPathPrefix}${subtreeNode.originalRoutePath}`,
|
|
138
|
+
);
|
|
139
|
+
subtreeNode.filePath = `${node.directory}/${subtreeNode.filePath}`;
|
|
140
|
+
});
|
|
141
|
+
return routeNodes;
|
|
142
|
+
}
|
|
143
|
+
function getFile(file) {
|
|
144
|
+
const filePath = file;
|
|
145
|
+
return {
|
|
146
|
+
filePath,
|
|
147
|
+
variableName: routePathToVariable(removeExt(filePath)),
|
|
148
|
+
fullPath: replaceBackslash(join(fullDir, filePath)),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const parentRoutePath = removeTrailingSlash(parent?.routePath ?? '/');
|
|
152
|
+
const parentOriginalRoutePath = removeTrailingSlash(
|
|
153
|
+
parent?.originalRoutePath ?? parent?.routePath ?? '/',
|
|
154
|
+
);
|
|
155
|
+
const virtualParentRoutePath = parent?.routePath ?? `/__root`;
|
|
156
|
+
switch (node.type) {
|
|
157
|
+
case 'index': {
|
|
158
|
+
const { filePath, variableName, fullPath } = getFile(node.file);
|
|
159
|
+
return {
|
|
160
|
+
filePath,
|
|
161
|
+
fullPath,
|
|
162
|
+
variableName,
|
|
163
|
+
routePath: `${parentRoutePath}/`,
|
|
164
|
+
originalRoutePath: `${parentOriginalRoutePath}/`,
|
|
165
|
+
_routePathSegmentMetadata: parent?._routePathSegmentMetadata
|
|
166
|
+
? [...parent._routePathSegmentMetadata]
|
|
167
|
+
: void 0,
|
|
168
|
+
_fsRouteType: 'static',
|
|
169
|
+
_virtualParentRoutePath: virtualParentRoutePath,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
case 'route': {
|
|
173
|
+
const lastSegment = node.path;
|
|
174
|
+
let routeNode;
|
|
175
|
+
const { routePath: escapedSegment, originalRoutePath: originalSegment } =
|
|
176
|
+
determineInitialRoutePathFromExplicitPath(removeLeadingSlash(lastSegment));
|
|
177
|
+
const routePath = `${parentRoutePath}${escapedSegment}`;
|
|
178
|
+
const originalRoutePath = `${parentOriginalRoutePath}${originalSegment}`;
|
|
179
|
+
const routePathSegmentMetadata = createLiteralRoutePathSegmentMetadata(
|
|
180
|
+
routePath,
|
|
181
|
+
parent,
|
|
182
|
+
true,
|
|
183
|
+
);
|
|
184
|
+
if (node.file) {
|
|
185
|
+
const { filePath, variableName, fullPath } = getFile(node.file);
|
|
186
|
+
routeNode = {
|
|
187
|
+
filePath,
|
|
188
|
+
fullPath,
|
|
189
|
+
variableName,
|
|
190
|
+
routePath,
|
|
191
|
+
originalRoutePath,
|
|
192
|
+
_routePathSegmentMetadata: routePathSegmentMetadata,
|
|
193
|
+
_fsRouteType: 'static',
|
|
194
|
+
_virtualParentRoutePath: virtualParentRoutePath,
|
|
195
|
+
};
|
|
196
|
+
} else
|
|
197
|
+
routeNode = {
|
|
198
|
+
filePath: '',
|
|
199
|
+
fullPath: '',
|
|
200
|
+
variableName: routePathToVariable(routePath),
|
|
201
|
+
routePath,
|
|
202
|
+
originalRoutePath,
|
|
203
|
+
_routePathSegmentMetadata: routePathSegmentMetadata,
|
|
204
|
+
isVirtual: true,
|
|
205
|
+
_fsRouteType: 'static',
|
|
206
|
+
_virtualParentRoutePath: virtualParentRoutePath,
|
|
207
|
+
};
|
|
208
|
+
if (node.children !== void 0) {
|
|
209
|
+
const { children, physicalDirectories } = await getRouteNodesRecursive(
|
|
210
|
+
tsrConfig,
|
|
211
|
+
root,
|
|
212
|
+
fullDir,
|
|
213
|
+
node.children,
|
|
214
|
+
tokenRegexes,
|
|
215
|
+
routeNode,
|
|
216
|
+
);
|
|
217
|
+
routeNode.children = children;
|
|
218
|
+
allPhysicalDirectories.push(...physicalDirectories);
|
|
219
|
+
routeNode._fsRouteType = 'layout';
|
|
220
|
+
}
|
|
221
|
+
return routeNode;
|
|
222
|
+
}
|
|
223
|
+
case 'layout': {
|
|
224
|
+
const { filePath, variableName, fullPath } = getFile(node.file);
|
|
225
|
+
if (node.id !== void 0) node.id = ensureLeadingUnderScore(node.id);
|
|
226
|
+
else {
|
|
227
|
+
const baseName = path.basename(filePath);
|
|
228
|
+
const fileNameWithoutExt = path.parse(baseName).name;
|
|
229
|
+
node.id = ensureLeadingUnderScore(fileNameWithoutExt);
|
|
230
|
+
}
|
|
231
|
+
const lastSegment = node.id;
|
|
232
|
+
const { routePath: escapedSegment, originalRoutePath: originalSegment } =
|
|
233
|
+
determineInitialRoutePathFromExplicitPath(removeLeadingSlash(lastSegment));
|
|
234
|
+
const routePath = `${parentRoutePath}${escapedSegment}`;
|
|
235
|
+
const routeNode = {
|
|
236
|
+
fullPath,
|
|
237
|
+
filePath,
|
|
238
|
+
variableName,
|
|
239
|
+
routePath,
|
|
240
|
+
originalRoutePath: `${parentOriginalRoutePath}${originalSegment}`,
|
|
241
|
+
_routePathSegmentMetadata: joinRoutePathSegmentMetadata(
|
|
242
|
+
routePath,
|
|
243
|
+
parentRoutePath,
|
|
244
|
+
parent?._routePathSegmentMetadata,
|
|
245
|
+
createRoutePathSegmentMetadata(escapedSegment, originalSegment),
|
|
246
|
+
),
|
|
247
|
+
_fsRouteType: 'pathless_layout',
|
|
248
|
+
_virtualParentRoutePath: virtualParentRoutePath,
|
|
249
|
+
};
|
|
250
|
+
if (node.children !== void 0) {
|
|
251
|
+
const { children, physicalDirectories } = await getRouteNodesRecursive(
|
|
252
|
+
tsrConfig,
|
|
253
|
+
root,
|
|
254
|
+
fullDir,
|
|
255
|
+
node.children,
|
|
256
|
+
tokenRegexes,
|
|
257
|
+
routeNode,
|
|
258
|
+
);
|
|
259
|
+
routeNode.children = children;
|
|
260
|
+
allPhysicalDirectories.push(...physicalDirectories);
|
|
261
|
+
}
|
|
262
|
+
return routeNode;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}),
|
|
266
|
+
)
|
|
267
|
+
).flat(),
|
|
268
|
+
physicalDirectories: allPhysicalDirectories,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
//#endregion
|
|
272
|
+
export { getRouteNodes };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function loadConfigFile(filePath: string): Promise<any>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createJiti } from 'jiti';
|
|
2
|
+
//#region src/filesystem/virtual/loadConfigFile.ts
|
|
3
|
+
async function loadConfigFile(filePath) {
|
|
4
|
+
return await createJiti(filePath, {
|
|
5
|
+
interopDefault: false,
|
|
6
|
+
tsconfigPaths: true,
|
|
7
|
+
}).import(filePath);
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { loadConfigFile };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { TargetTemplate } from './template.js';
|
|
2
|
+
import { GetRoutesByFileMapResult, HandleNodeAccumulator, RouteNode } from './types.js';
|
|
3
|
+
import { Config } from './config.js';
|
|
4
|
+
interface fs {
|
|
5
|
+
stat: (filePath: string) => Promise<{
|
|
6
|
+
mtimeMs: bigint;
|
|
7
|
+
mode: number;
|
|
8
|
+
uid: number;
|
|
9
|
+
gid: number;
|
|
10
|
+
}>;
|
|
11
|
+
rename: (oldPath: string, newPath: string) => Promise<void>;
|
|
12
|
+
writeFile: (filePath: string, content: string) => Promise<void>;
|
|
13
|
+
readFile: (filePath: string) => Promise<
|
|
14
|
+
| {
|
|
15
|
+
stat: {
|
|
16
|
+
mtimeMs: bigint;
|
|
17
|
+
};
|
|
18
|
+
fileContent: string;
|
|
19
|
+
}
|
|
20
|
+
| 'file-not-existing'
|
|
21
|
+
>;
|
|
22
|
+
chmod: (filePath: string, mode: number) => Promise<void>;
|
|
23
|
+
chown: (filePath: string, uid: number, gid: number) => Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export type FileEventType = 'create' | 'update' | 'delete';
|
|
26
|
+
export type FileEvent = {
|
|
27
|
+
type: FileEventType;
|
|
28
|
+
path: string;
|
|
29
|
+
};
|
|
30
|
+
export type GeneratorEvent =
|
|
31
|
+
| FileEvent
|
|
32
|
+
| {
|
|
33
|
+
type: 'rerun';
|
|
34
|
+
};
|
|
35
|
+
interface CrawlingResult {
|
|
36
|
+
rootRouteNode: RouteNode;
|
|
37
|
+
routeFileResult: Array<RouteNode>;
|
|
38
|
+
acc: HandleNodeAccumulator;
|
|
39
|
+
}
|
|
40
|
+
export declare class Generator {
|
|
41
|
+
/**
|
|
42
|
+
* why do we have two caches for the route files?
|
|
43
|
+
* During processing, we READ from the cache and WRITE to the shadow cache.
|
|
44
|
+
*
|
|
45
|
+
* After a route file is processed, we write to the shadow cache.
|
|
46
|
+
* If during processing we bail out and re-run, we don't lose this modification
|
|
47
|
+
* but still can track whether the file contributed changes and thus the route tree file needs to be regenerated.
|
|
48
|
+
* After all files are processed, we swap the shadow cache with the main cache and initialize a new shadow cache.
|
|
49
|
+
* That way we also ensure deleted/renamed files don't stay in the cache forever.
|
|
50
|
+
*/
|
|
51
|
+
private routeNodeCache;
|
|
52
|
+
private routeNodeShadowCache;
|
|
53
|
+
private routeTreeFileCache;
|
|
54
|
+
private crawlingResult;
|
|
55
|
+
config: Config;
|
|
56
|
+
targetTemplate: TargetTemplate;
|
|
57
|
+
private root;
|
|
58
|
+
private routesDirectoryPath;
|
|
59
|
+
private sessionId?;
|
|
60
|
+
private fs;
|
|
61
|
+
private logger;
|
|
62
|
+
private generatedRouteTreePath;
|
|
63
|
+
private runPromise;
|
|
64
|
+
private fileEventQueue;
|
|
65
|
+
private plugins;
|
|
66
|
+
private static routeGroupPatternRegex;
|
|
67
|
+
private physicalDirectories;
|
|
68
|
+
/**
|
|
69
|
+
* Token regexes are pre-compiled once here and reused throughout route processing.
|
|
70
|
+
* We need TWO types of regex for each token because they match against different inputs:
|
|
71
|
+
*
|
|
72
|
+
* 1. FILENAME regexes: Match token patterns within full file path strings.
|
|
73
|
+
* Example: For file "routes/dashboard.index.tsx", we want to detect ".index."
|
|
74
|
+
* Pattern: `[./](?:token)[.]` - matches token bounded by path separators/dots
|
|
75
|
+
* Used in: sorting route nodes by file path
|
|
76
|
+
*
|
|
77
|
+
* 2. SEGMENT regexes: Match token against a single logical route segment.
|
|
78
|
+
* Example: For segment "index" (extracted from path), match the whole segment
|
|
79
|
+
* Pattern: `^(?:token)$` - matches entire segment exactly
|
|
80
|
+
* Used in: route parsing, determining route types, escape detection
|
|
81
|
+
*
|
|
82
|
+
* We cannot reuse one for the other without false positives or missing matches.
|
|
83
|
+
*/
|
|
84
|
+
private indexTokenFilenameRegex;
|
|
85
|
+
private routeTokenFilenameRegex;
|
|
86
|
+
private indexTokenSegmentRegex;
|
|
87
|
+
private routeTokenSegmentRegex;
|
|
88
|
+
private static componentPieceRegex;
|
|
89
|
+
constructor(opts: { config: Config; root: string; fs?: fs });
|
|
90
|
+
private getGeneratedRouteTreePath;
|
|
91
|
+
private getRoutesDirectoryPath;
|
|
92
|
+
getRoutesByFileMap(): GetRoutesByFileMapResult;
|
|
93
|
+
private fillRouteTemplate;
|
|
94
|
+
private getParseSource;
|
|
95
|
+
run(event?: GeneratorEvent): Promise<void>;
|
|
96
|
+
private generatorInternal;
|
|
97
|
+
private swapCaches;
|
|
98
|
+
buildRouteTree(opts: {
|
|
99
|
+
rootRouteNode: RouteNode;
|
|
100
|
+
acc: HandleNodeAccumulator;
|
|
101
|
+
routeFileResult: Array<RouteNode>;
|
|
102
|
+
config?: Partial<Config>;
|
|
103
|
+
}): {
|
|
104
|
+
routeTreeContent: string;
|
|
105
|
+
routeTree: RouteNode[];
|
|
106
|
+
routeNodes: RouteNode[];
|
|
107
|
+
};
|
|
108
|
+
private processRouteNodeFile;
|
|
109
|
+
private didRouteFileChangeComparedToCache;
|
|
110
|
+
private didFileChangeComparedToCache;
|
|
111
|
+
private safeFileWrite;
|
|
112
|
+
private getTempFileName;
|
|
113
|
+
private isRouteFileCacheFresh;
|
|
114
|
+
private handleRootNode;
|
|
115
|
+
getCrawlingResult(): Promise<CrawlingResult | undefined>;
|
|
116
|
+
private static handleNode;
|
|
117
|
+
private isFileRelevantForRouteTreeGeneration;
|
|
118
|
+
}
|
|
119
|
+
export {};
|