@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,385 @@
|
|
|
1
|
+
import MagicString from 'magic-string';
|
|
2
|
+
import * as t from '@babel/types';
|
|
3
|
+
import { parseAst } from '@tanstack/router-utils';
|
|
4
|
+
import { getRouterPackage } from '#tanstack-start/package-names';
|
|
5
|
+
//#region src/transform/transform.ts
|
|
6
|
+
var routeConstructors = ['createFileRoute', 'createLazyFileRoute'];
|
|
7
|
+
function transform({ ctx, source, parseSource, filename, node }) {
|
|
8
|
+
if (parseSource !== void 0 && parseSource.length !== source.length)
|
|
9
|
+
return {
|
|
10
|
+
result: 'error',
|
|
11
|
+
error: /* @__PURE__ */ new Error(
|
|
12
|
+
`expected parseSource for ${filename ?? ctx.routeId} to preserve the original source length`,
|
|
13
|
+
),
|
|
14
|
+
};
|
|
15
|
+
let ast;
|
|
16
|
+
try {
|
|
17
|
+
ast = parseAst({
|
|
18
|
+
code: parseSource ?? source,
|
|
19
|
+
filename,
|
|
20
|
+
});
|
|
21
|
+
} catch (error) {
|
|
22
|
+
return {
|
|
23
|
+
result: 'error',
|
|
24
|
+
error,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const exportedRouteNames = getExportedRouteNames(ast.program.body);
|
|
28
|
+
if (exportedRouteNames.size === 0) return { result: 'no-route-export' };
|
|
29
|
+
const {
|
|
30
|
+
calls: routeCalls,
|
|
31
|
+
hasUnsupportedRouteId,
|
|
32
|
+
hasMalformedRouteCall,
|
|
33
|
+
} = findExportedRouteCalls(ast.program.body, exportedRouteNames);
|
|
34
|
+
if (routeCalls.length === 0 && hasMalformedRouteCall)
|
|
35
|
+
return {
|
|
36
|
+
result: 'error',
|
|
37
|
+
error: /* @__PURE__ */ new Error(
|
|
38
|
+
`expected Route export in ${ctx.routeId} to use createFileRoute('/path')({...}) or createLazyFileRoute('/path')({...})`,
|
|
39
|
+
),
|
|
40
|
+
};
|
|
41
|
+
if (routeCalls.length === 0 && hasUnsupportedRouteId)
|
|
42
|
+
return {
|
|
43
|
+
result: 'error',
|
|
44
|
+
error: /* @__PURE__ */ new Error(
|
|
45
|
+
`expected route id to be a string literal or plain template literal in ${ctx.routeId}`,
|
|
46
|
+
),
|
|
47
|
+
};
|
|
48
|
+
if (routeCalls.length === 0) return { result: 'not-modified' };
|
|
49
|
+
if (routeCalls.length > 1)
|
|
50
|
+
return {
|
|
51
|
+
result: 'error',
|
|
52
|
+
error: /* @__PURE__ */ new Error(
|
|
53
|
+
`expected exactly one createFileRoute/createLazyFileRoute call in ${ctx.routeId}`,
|
|
54
|
+
),
|
|
55
|
+
};
|
|
56
|
+
const routeCall = routeCalls[0];
|
|
57
|
+
const routeIdQuote = getRouteIdQuote(source, routeCall.routeIdArg);
|
|
58
|
+
const createFileRouteProps = getCreateFileRouteProps(routeCall.optionsArg);
|
|
59
|
+
if (createFileRouteProps) node.createFileRouteProps = createFileRouteProps;
|
|
60
|
+
const expectedCallee = getExpectedRouteConstructor(ctx.lazy);
|
|
61
|
+
const expectedRouteId = `${routeIdQuote}${ctx.routeId}${routeIdQuote}`;
|
|
62
|
+
const currentRouteId = source.slice(routeCall.routeIdArg.start, routeCall.routeIdArg.end);
|
|
63
|
+
const targetModule = getRouterPackage(ctx.target);
|
|
64
|
+
const imports = parseTargetImports(ast.program.body, source, targetModule);
|
|
65
|
+
const s = new MagicString(source);
|
|
66
|
+
let modified = false;
|
|
67
|
+
if (routeCall.callee.name !== expectedCallee) {
|
|
68
|
+
s.update(routeCall.callee.start, routeCall.callee.end, expectedCallee);
|
|
69
|
+
modified = true;
|
|
70
|
+
}
|
|
71
|
+
if (currentRouteId !== expectedRouteId) {
|
|
72
|
+
s.update(routeCall.routeIdArg.start, routeCall.routeIdArg.end, expectedRouteId);
|
|
73
|
+
modified = true;
|
|
74
|
+
}
|
|
75
|
+
if (
|
|
76
|
+
updateRouteImports({
|
|
77
|
+
imports,
|
|
78
|
+
source,
|
|
79
|
+
s,
|
|
80
|
+
targetModule,
|
|
81
|
+
required: expectedCallee,
|
|
82
|
+
lineEnding: getLineEnding(source),
|
|
83
|
+
})
|
|
84
|
+
)
|
|
85
|
+
modified = true;
|
|
86
|
+
if (!modified) return { result: 'not-modified' };
|
|
87
|
+
return {
|
|
88
|
+
result: 'modified',
|
|
89
|
+
output: s.toString(),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function getExportedRouteNames(body) {
|
|
93
|
+
const exportedRouteNames = /* @__PURE__ */ new Set();
|
|
94
|
+
for (const statement of body) {
|
|
95
|
+
if (!t.isExportNamedDeclaration(statement) || statement.source) continue;
|
|
96
|
+
if (t.isVariableDeclaration(statement.declaration)) {
|
|
97
|
+
for (const declarator of statement.declaration.declarations)
|
|
98
|
+
if (t.isIdentifier(declarator.id) && declarator.id.name === 'Route')
|
|
99
|
+
exportedRouteNames.add('Route');
|
|
100
|
+
}
|
|
101
|
+
for (const specifier of statement.specifiers) {
|
|
102
|
+
if (!t.isExportSpecifier(specifier) || getExportedName(specifier.exported) !== 'Route')
|
|
103
|
+
continue;
|
|
104
|
+
const localName = getLocalBindingName(specifier.local);
|
|
105
|
+
if (localName) exportedRouteNames.add(localName);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return exportedRouteNames;
|
|
109
|
+
}
|
|
110
|
+
function findExportedRouteCalls(body, exportedRouteNames) {
|
|
111
|
+
const calls = [];
|
|
112
|
+
let hasUnsupportedRouteId = false;
|
|
113
|
+
let hasMalformedRouteCall = false;
|
|
114
|
+
for (const statement of body) {
|
|
115
|
+
const declaration = getVariableDeclaration(statement);
|
|
116
|
+
if (!declaration) continue;
|
|
117
|
+
for (const declarator of declaration.declarations) {
|
|
118
|
+
if (!t.isIdentifier(declarator.id) || !exportedRouteNames.has(declarator.id.name)) continue;
|
|
119
|
+
const init = getRouteConstructorInit(declarator.init);
|
|
120
|
+
if (!init) {
|
|
121
|
+
if (isDirectRouteConstructorCall(declarator.init)) hasMalformedRouteCall = true;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const routeIdArg = init.innerCall.arguments[0];
|
|
125
|
+
if (isSupportedRouteId(routeIdArg))
|
|
126
|
+
calls.push({
|
|
127
|
+
callee: init.callee,
|
|
128
|
+
routeIdArg,
|
|
129
|
+
optionsArg: init.outerCall.arguments[0],
|
|
130
|
+
});
|
|
131
|
+
else hasUnsupportedRouteId = true;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
calls,
|
|
136
|
+
hasUnsupportedRouteId,
|
|
137
|
+
hasMalformedRouteCall,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function getVariableDeclaration(statement) {
|
|
141
|
+
const declaration = t.isExportNamedDeclaration(statement) ? statement.declaration : statement;
|
|
142
|
+
return t.isVariableDeclaration(declaration) ? declaration : null;
|
|
143
|
+
}
|
|
144
|
+
function getExportedName(node) {
|
|
145
|
+
return t.isIdentifier(node) ? node.name : node.value;
|
|
146
|
+
}
|
|
147
|
+
function getLocalBindingName(node) {
|
|
148
|
+
return t.isIdentifier(node) ? node.name : null;
|
|
149
|
+
}
|
|
150
|
+
function getRouteConstructorInit(expression) {
|
|
151
|
+
if (!expression || !t.isCallExpression(expression)) return null;
|
|
152
|
+
if (!t.isCallExpression(expression.callee)) return null;
|
|
153
|
+
const innerCall = expression.callee;
|
|
154
|
+
if (!t.isIdentifier(innerCall.callee) || !isRouteConstructor(innerCall.callee)) return null;
|
|
155
|
+
return {
|
|
156
|
+
callee: innerCall.callee,
|
|
157
|
+
outerCall: expression,
|
|
158
|
+
innerCall,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function isDirectRouteConstructorCall(expression) {
|
|
162
|
+
return (
|
|
163
|
+
!!expression &&
|
|
164
|
+
t.isCallExpression(expression) &&
|
|
165
|
+
t.isIdentifier(expression.callee) &&
|
|
166
|
+
isRouteConstructor(expression.callee)
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
function isRouteConstructor(callee) {
|
|
170
|
+
return routeConstructors.includes(callee.name);
|
|
171
|
+
}
|
|
172
|
+
function isSupportedRouteId(arg) {
|
|
173
|
+
return (
|
|
174
|
+
!!arg && (t.isStringLiteral(arg) || (t.isTemplateLiteral(arg) && arg.expressions.length === 0))
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
function getRouteIdQuote(source, arg) {
|
|
178
|
+
const raw = source.slice(arg.start, arg.end);
|
|
179
|
+
if (raw.startsWith("'")) return "'";
|
|
180
|
+
if (raw.startsWith('"')) return '"';
|
|
181
|
+
return '`';
|
|
182
|
+
}
|
|
183
|
+
function getCreateFileRouteProps(arg) {
|
|
184
|
+
if (!arg || !t.isObjectExpression(arg)) return;
|
|
185
|
+
const props = /* @__PURE__ */ new Set();
|
|
186
|
+
for (const property of arg.properties) {
|
|
187
|
+
if (!t.isObjectProperty(property) || property.computed) continue;
|
|
188
|
+
if (t.isIdentifier(property.key)) {
|
|
189
|
+
props.add(property.key.name);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (t.isStringLiteral(property.key)) props.add(property.key.value);
|
|
193
|
+
}
|
|
194
|
+
return props;
|
|
195
|
+
}
|
|
196
|
+
function parseTargetImports(body, source, targetModule) {
|
|
197
|
+
const imports = [];
|
|
198
|
+
for (const statement of body) {
|
|
199
|
+
if (
|
|
200
|
+
!t.isImportDeclaration(statement) ||
|
|
201
|
+
statement.importKind === 'type' ||
|
|
202
|
+
statement.source.value !== targetModule
|
|
203
|
+
)
|
|
204
|
+
continue;
|
|
205
|
+
const rawSource = source.slice(statement.source.start, statement.source.end);
|
|
206
|
+
const importStatement = source.slice(statement.start, statement.end);
|
|
207
|
+
imports.push({
|
|
208
|
+
declaration: statement,
|
|
209
|
+
defaultImport: statement.specifiers.find((specifier) => t.isImportDefaultSpecifier(specifier))
|
|
210
|
+
?.local.name,
|
|
211
|
+
namespace: statement.specifiers.find((specifier) => t.isImportNamespaceSpecifier(specifier))
|
|
212
|
+
?.local.name,
|
|
213
|
+
named: statement.specifiers
|
|
214
|
+
.filter((specifier) => t.isImportSpecifier(specifier))
|
|
215
|
+
.map((specifier) => ({
|
|
216
|
+
imported: t.isIdentifier(specifier.imported)
|
|
217
|
+
? specifier.imported.name
|
|
218
|
+
: specifier.imported.value,
|
|
219
|
+
local: specifier.local.name,
|
|
220
|
+
importKind: specifier.importKind ?? void 0,
|
|
221
|
+
})),
|
|
222
|
+
moduleName: statement.source.value,
|
|
223
|
+
quote: rawSource[0],
|
|
224
|
+
semicolon: importStatement.trimEnd().endsWith(';'),
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
return imports;
|
|
228
|
+
}
|
|
229
|
+
function updateRouteImports({ imports, source, s, targetModule, required, lineEnding }) {
|
|
230
|
+
const analysis = analyzeRouteImports(imports, required);
|
|
231
|
+
if (analysis.kind === 'ok') return false;
|
|
232
|
+
if (analysis.kind === 'rename') {
|
|
233
|
+
s.update(analysis.imported.start, analysis.imported.end, analysis.next);
|
|
234
|
+
s.update(analysis.local.start, analysis.local.end, analysis.next);
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
return normalizeRouteImports({
|
|
238
|
+
imports,
|
|
239
|
+
source,
|
|
240
|
+
s,
|
|
241
|
+
targetModule,
|
|
242
|
+
required,
|
|
243
|
+
lineEnding,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
function analyzeRouteImports(imports, required) {
|
|
247
|
+
const opposite = getOtherRouteConstructor(required);
|
|
248
|
+
let requiredCount = 0;
|
|
249
|
+
let oppositeCount = 0;
|
|
250
|
+
let renameCandidate;
|
|
251
|
+
for (const declaration of imports)
|
|
252
|
+
for (const specifier of declaration.declaration.specifiers) {
|
|
253
|
+
if (!t.isImportSpecifier(specifier)) continue;
|
|
254
|
+
const imported = specifier.imported;
|
|
255
|
+
if (!t.isIdentifier(imported)) return { kind: 'normalize' };
|
|
256
|
+
if (!isRouteConstructorName(imported.name)) continue;
|
|
257
|
+
if (specifier.local.name !== imported.name) return { kind: 'normalize' };
|
|
258
|
+
if (imported.name === required) {
|
|
259
|
+
requiredCount++;
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
if (imported.name === opposite) {
|
|
263
|
+
oppositeCount++;
|
|
264
|
+
renameCandidate = {
|
|
265
|
+
imported,
|
|
266
|
+
local: specifier.local,
|
|
267
|
+
next: required,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (requiredCount === 1 && oppositeCount === 0) return { kind: 'ok' };
|
|
272
|
+
if (requiredCount === 0 && oppositeCount === 1 && renameCandidate)
|
|
273
|
+
return {
|
|
274
|
+
kind: 'rename',
|
|
275
|
+
...renameCandidate,
|
|
276
|
+
};
|
|
277
|
+
return { kind: 'normalize' };
|
|
278
|
+
}
|
|
279
|
+
function normalizeRouteImports({ imports, source, s, targetModule, required, lineEnding }) {
|
|
280
|
+
const owner =
|
|
281
|
+
imports.find((declaration) => hasNamedImport(declaration.named, required)) ??
|
|
282
|
+
imports.find((declaration) => !declaration.namespace);
|
|
283
|
+
let modified = false;
|
|
284
|
+
for (const declaration of imports) {
|
|
285
|
+
const named = normalizeNamedImports({
|
|
286
|
+
named: declaration.named,
|
|
287
|
+
required,
|
|
288
|
+
isOwner: declaration === owner,
|
|
289
|
+
});
|
|
290
|
+
if (sameNamedImports(declaration.named, named)) continue;
|
|
291
|
+
const replacement = renderImportDeclaration({
|
|
292
|
+
...declaration,
|
|
293
|
+
named,
|
|
294
|
+
});
|
|
295
|
+
if (replacement === null) {
|
|
296
|
+
s.remove(declaration.declaration.start, getRemovalEnd(source, declaration.declaration.end));
|
|
297
|
+
modified = true;
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
s.update(declaration.declaration.start, declaration.declaration.end, replacement);
|
|
301
|
+
modified = true;
|
|
302
|
+
}
|
|
303
|
+
if (!owner) {
|
|
304
|
+
const quote = imports[0]?.quote ?? "'";
|
|
305
|
+
const semicolon = imports[0]?.semicolon ?? false;
|
|
306
|
+
s.prepend(
|
|
307
|
+
`import { ${required} } from ${quote}${targetModule}${quote}${semicolon ? ';' : ''}${lineEnding}`,
|
|
308
|
+
);
|
|
309
|
+
modified = true;
|
|
310
|
+
}
|
|
311
|
+
return modified;
|
|
312
|
+
}
|
|
313
|
+
function normalizeNamedImports({ named, required, isOwner }) {
|
|
314
|
+
const banned = getOtherRouteConstructor(required);
|
|
315
|
+
const nextNamed = [];
|
|
316
|
+
const seen = /* @__PURE__ */ new Set();
|
|
317
|
+
for (const specifier of named) {
|
|
318
|
+
if (specifier.imported === banned) continue;
|
|
319
|
+
if (specifier.local === required && (specifier.imported !== required || !isOwner)) continue;
|
|
320
|
+
const key = `${specifier.importKind ?? 'value'}:${specifier.imported}:${specifier.local}`;
|
|
321
|
+
if (seen.has(key)) continue;
|
|
322
|
+
seen.add(key);
|
|
323
|
+
nextNamed.push(specifier);
|
|
324
|
+
}
|
|
325
|
+
if (isOwner && !hasNamedImport(nextNamed, required))
|
|
326
|
+
nextNamed.push({
|
|
327
|
+
imported: required,
|
|
328
|
+
local: required,
|
|
329
|
+
});
|
|
330
|
+
return nextNamed;
|
|
331
|
+
}
|
|
332
|
+
function getExpectedRouteConstructor(lazy) {
|
|
333
|
+
return lazy ? 'createLazyFileRoute' : 'createFileRoute';
|
|
334
|
+
}
|
|
335
|
+
function getOtherRouteConstructor(constructor) {
|
|
336
|
+
return constructor === 'createFileRoute' ? 'createLazyFileRoute' : 'createFileRoute';
|
|
337
|
+
}
|
|
338
|
+
function hasNamedImport(named, required) {
|
|
339
|
+
return named.some(
|
|
340
|
+
(specifier) =>
|
|
341
|
+
specifier.imported === required &&
|
|
342
|
+
specifier.local === required &&
|
|
343
|
+
specifier.importKind !== 'type',
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
function sameNamedImports(left, right) {
|
|
347
|
+
return (
|
|
348
|
+
left.length === right.length &&
|
|
349
|
+
left.every(
|
|
350
|
+
(specifier, index) =>
|
|
351
|
+
specifier.imported === right[index].imported &&
|
|
352
|
+
specifier.local === right[index].local &&
|
|
353
|
+
specifier.importKind === right[index].importKind,
|
|
354
|
+
)
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
function isRouteConstructorName(value) {
|
|
358
|
+
return routeConstructors.includes(value);
|
|
359
|
+
}
|
|
360
|
+
function renderImportDeclaration(importDeclaration) {
|
|
361
|
+
const parts = [];
|
|
362
|
+
if (importDeclaration.defaultImport) parts.push(importDeclaration.defaultImport);
|
|
363
|
+
if (importDeclaration.namespace) parts.push(`* as ${importDeclaration.namespace}`);
|
|
364
|
+
if (importDeclaration.named.length > 0)
|
|
365
|
+
parts.push(
|
|
366
|
+
`{ ${importDeclaration.named.map((specifier) => `${specifier.importKind === 'type' ? 'type ' : ''}${specifier.imported === specifier.local ? specifier.imported : `${specifier.imported} as ${specifier.local}`}`).join(', ')} }`,
|
|
367
|
+
);
|
|
368
|
+
if (parts.length === 0) return null;
|
|
369
|
+
return `import ${parts.join(', ')} from ${importDeclaration.quote}${importDeclaration.moduleName}${importDeclaration.quote}${importDeclaration.semicolon ? ';' : ''}`;
|
|
370
|
+
}
|
|
371
|
+
function getLineEnding(source) {
|
|
372
|
+
if (source.includes('\r\n')) return '\r\n';
|
|
373
|
+
if (source.includes('\n')) return '\n';
|
|
374
|
+
if (source.includes('\r')) return '\r';
|
|
375
|
+
return '\n';
|
|
376
|
+
}
|
|
377
|
+
function getRemovalEnd(source, end) {
|
|
378
|
+
let pos = end;
|
|
379
|
+
while (pos < source.length && (source[pos] === ' ' || source[pos] === ' ')) pos++;
|
|
380
|
+
if (source[pos] === '\r' && source[pos + 1] === '\n') return pos + 2;
|
|
381
|
+
if (source[pos] === '\n' || source[pos] === '\r') return pos + 1;
|
|
382
|
+
return end;
|
|
383
|
+
}
|
|
384
|
+
//#endregion
|
|
385
|
+
export { transform };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { RouteNode } from '../types.js';
|
|
2
|
+
import { Config } from '../config.js';
|
|
3
|
+
export interface TransformOptions {
|
|
4
|
+
source: string;
|
|
5
|
+
/**
|
|
6
|
+
* An optional, position-preserving version of `source` that can be parsed as
|
|
7
|
+
* TypeScript/JSX. AST ranges are applied to the original source, so this must
|
|
8
|
+
* have exactly the same length as `source`.
|
|
9
|
+
*/
|
|
10
|
+
parseSource?: string;
|
|
11
|
+
filename?: string;
|
|
12
|
+
ctx: TransformContext;
|
|
13
|
+
node: RouteNode;
|
|
14
|
+
}
|
|
15
|
+
export type TransformResult =
|
|
16
|
+
| {
|
|
17
|
+
result: 'no-route-export';
|
|
18
|
+
}
|
|
19
|
+
| {
|
|
20
|
+
result: 'not-modified';
|
|
21
|
+
}
|
|
22
|
+
| {
|
|
23
|
+
result: 'modified';
|
|
24
|
+
output: string;
|
|
25
|
+
}
|
|
26
|
+
| {
|
|
27
|
+
result: 'error';
|
|
28
|
+
error?: any;
|
|
29
|
+
};
|
|
30
|
+
export interface TransformContext {
|
|
31
|
+
target: Config['target'];
|
|
32
|
+
routeId: string;
|
|
33
|
+
lazy: boolean;
|
|
34
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export type RoutePathSegmentMetadata = {
|
|
2
|
+
literalLeadingUnderscore?: boolean;
|
|
3
|
+
literalTrailingUnderscore?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export type RouteNode = {
|
|
6
|
+
filePath: string;
|
|
7
|
+
fullPath: string;
|
|
8
|
+
variableName: string;
|
|
9
|
+
_fsRouteType: FsRouteType;
|
|
10
|
+
routePath?: string;
|
|
11
|
+
originalRoutePath?: string;
|
|
12
|
+
cleanedPath?: string;
|
|
13
|
+
path?: string;
|
|
14
|
+
isNonPath?: boolean;
|
|
15
|
+
isVirtualParentRoute?: boolean;
|
|
16
|
+
isVirtual?: boolean;
|
|
17
|
+
children?: Array<RouteNode>;
|
|
18
|
+
parent?: RouteNode;
|
|
19
|
+
createFileRouteProps?: Set<string>;
|
|
20
|
+
/**
|
|
21
|
+
* For virtual routes: the routePath of the explicit parent from virtual config.
|
|
22
|
+
* Used to prevent auto-nesting siblings based on path prefix matching (#5822, #5431).
|
|
23
|
+
* Falls back to path-based inference if the explicit parent is not found
|
|
24
|
+
* (e.g., when the parent is a virtual file-less route that gets filtered out).
|
|
25
|
+
*/
|
|
26
|
+
_virtualParentRoutePath?: string;
|
|
27
|
+
/** Internal routePath segment metadata for escaped or explicit literal syntax. */
|
|
28
|
+
_routePathSegmentMetadata?: Array<RoutePathSegmentMetadata | undefined>;
|
|
29
|
+
};
|
|
30
|
+
export interface GetRouteNodesResult {
|
|
31
|
+
rootRouteNode?: RouteNode;
|
|
32
|
+
routeNodes: Array<RouteNode>;
|
|
33
|
+
physicalDirectories: Array<string>;
|
|
34
|
+
}
|
|
35
|
+
export type FsRouteType =
|
|
36
|
+
| '__root'
|
|
37
|
+
| 'static'
|
|
38
|
+
| 'layout'
|
|
39
|
+
| 'pathless_layout'
|
|
40
|
+
| 'lazy'
|
|
41
|
+
| 'loader'
|
|
42
|
+
| 'component'
|
|
43
|
+
| 'pendingComponent'
|
|
44
|
+
| 'errorComponent'
|
|
45
|
+
| 'notFoundComponent';
|
|
46
|
+
export type RouteSubNode = {
|
|
47
|
+
component?: RouteNode;
|
|
48
|
+
errorComponent?: RouteNode;
|
|
49
|
+
notFoundComponent?: RouteNode;
|
|
50
|
+
pendingComponent?: RouteNode;
|
|
51
|
+
loader?: RouteNode;
|
|
52
|
+
lazy?: RouteNode;
|
|
53
|
+
};
|
|
54
|
+
export type ImportSpecifier = {
|
|
55
|
+
imported: string;
|
|
56
|
+
local?: string;
|
|
57
|
+
};
|
|
58
|
+
export type ImportDeclaration = {
|
|
59
|
+
source: string;
|
|
60
|
+
specifiers: Array<ImportSpecifier>;
|
|
61
|
+
importKind?: 'type' | 'value';
|
|
62
|
+
};
|
|
63
|
+
export type HandleNodeAccumulator = {
|
|
64
|
+
routeTree: Array<RouteNode>;
|
|
65
|
+
routePiecesByPath: Record<string, RouteSubNode>;
|
|
66
|
+
routeNodes: Array<RouteNode>;
|
|
67
|
+
/** O(1) lookup by routePath - avoids O(n) .find() on every node */
|
|
68
|
+
routeNodesByPath: Map<string, RouteNode>;
|
|
69
|
+
};
|
|
70
|
+
export type GetRoutesByFileMapResultValue = {
|
|
71
|
+
routeId: string;
|
|
72
|
+
};
|
|
73
|
+
export type GetRoutesByFileMapResult = Map<string, GetRoutesByFileMapResultValue>;
|