@tanstack/start-plugin-core 1.132.0-alpha.8 → 1.132.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/dist/esm/constants.d.ts +2 -1
- package/dist/esm/constants.js +3 -2
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/create-server-fn-plugin/compiler.d.ts +64 -0
- package/dist/esm/create-server-fn-plugin/compiler.js +364 -0
- package/dist/esm/create-server-fn-plugin/compiler.js.map +1 -0
- package/dist/esm/create-server-fn-plugin/handleCreateMiddleware.d.ts +5 -0
- package/dist/esm/{start-compiler-plugin/middleware.js → create-server-fn-plugin/handleCreateMiddleware.js} +11 -11
- package/dist/esm/create-server-fn-plugin/handleCreateMiddleware.js.map +1 -0
- package/dist/esm/create-server-fn-plugin/handleCreateServerFn.d.ts +6 -0
- package/dist/esm/{start-compiler-plugin/serverFn.js → create-server-fn-plugin/handleCreateServerFn.js} +15 -17
- package/dist/esm/create-server-fn-plugin/handleCreateServerFn.js.map +1 -0
- package/dist/esm/create-server-fn-plugin/plugin.d.ts +3 -0
- package/dist/esm/create-server-fn-plugin/plugin.js +128 -0
- package/dist/esm/create-server-fn-plugin/plugin.js.map +1 -0
- package/dist/esm/dev-server-plugin/plugin.d.ts +4 -2
- package/dist/esm/dev-server-plugin/plugin.js +6 -2
- package/dist/esm/dev-server-plugin/plugin.js.map +1 -1
- package/dist/esm/plugin.d.ts +12 -6
- package/dist/esm/plugin.js +56 -68
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/resolve-entries.d.ts +0 -1
- package/dist/esm/resolve-entries.js +1 -1
- package/dist/esm/resolve-entries.js.map +1 -1
- package/dist/esm/schema.d.ts +375 -308
- package/dist/esm/schema.js +23 -11
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/start-compiler-plugin/compilers.js +17 -55
- package/dist/esm/start-compiler-plugin/compilers.js.map +1 -1
- package/dist/esm/start-compiler-plugin/constants.d.ts +1 -1
- package/dist/esm/start-compiler-plugin/constants.js +1 -6
- package/dist/esm/start-compiler-plugin/constants.js.map +1 -1
- package/dist/esm/start-compiler-plugin/plugin.d.ts +1 -8
- package/dist/esm/start-compiler-plugin/plugin.js +6 -13
- package/dist/esm/start-compiler-plugin/plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/constants.d.ts +1 -0
- package/dist/esm/start-router-plugin/constants.js +5 -0
- package/dist/esm/start-router-plugin/constants.js.map +1 -0
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js +3 -9
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/plugin.d.ts +3 -2
- package/dist/esm/start-router-plugin/plugin.js +191 -31
- package/dist/esm/start-router-plugin/plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.d.ts +8 -0
- package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.js +34 -0
- package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.js.map +1 -0
- package/package.json +8 -8
- package/src/constants.ts +3 -2
- package/src/create-server-fn-plugin/compiler.ts +498 -0
- package/src/{start-compiler-plugin/middleware.ts → create-server-fn-plugin/handleCreateMiddleware.ts} +15 -12
- package/src/{start-compiler-plugin/serverFn.ts → create-server-fn-plugin/handleCreateServerFn.ts} +32 -39
- package/src/create-server-fn-plugin/plugin.ts +153 -0
- package/src/dev-server-plugin/plugin.ts +6 -3
- package/src/plugin.ts +78 -87
- package/src/resolve-entries.ts +1 -2
- package/src/schema.ts +31 -14
- package/src/start-compiler-plugin/compilers.ts +18 -57
- package/src/start-compiler-plugin/constants.ts +0 -5
- package/src/start-compiler-plugin/plugin.ts +7 -22
- package/src/start-router-plugin/constants.ts +1 -0
- package/src/start-router-plugin/generator-plugins/routes-manifest-plugin.ts +3 -9
- package/src/start-router-plugin/plugin.ts +233 -45
- package/src/start-router-plugin/pruneServerOnlySubtrees.ts +51 -0
- package/dist/esm/debug.js +0 -5
- package/dist/esm/debug.js.map +0 -1
- package/dist/esm/start-compiler-plugin/middleware.d.ts +0 -4
- package/dist/esm/start-compiler-plugin/middleware.js.map +0 -1
- package/dist/esm/start-compiler-plugin/serverFileRoute.d.ts +0 -4
- package/dist/esm/start-compiler-plugin/serverFileRoute.js +0 -38
- package/dist/esm/start-compiler-plugin/serverFileRoute.js.map +0 -1
- package/dist/esm/start-compiler-plugin/serverFn.d.ts +0 -4
- package/dist/esm/start-compiler-plugin/serverFn.js.map +0 -1
- package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.d.ts +0 -2
- package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js +0 -119
- package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js.map +0 -1
- package/dist/esm/start-router-plugin/route-tree-client-plugin.d.ts +0 -6
- package/dist/esm/start-router-plugin/route-tree-client-plugin.js +0 -56
- package/dist/esm/start-router-plugin/route-tree-client-plugin.js.map +0 -1
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.d.ts +0 -3
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js +0 -29
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js.map +0 -1
- package/src/start-compiler-plugin/serverFileRoute.ts +0 -59
- package/src/start-router-plugin/generator-plugins/server-routes-plugin.ts +0 -138
- package/src/start-router-plugin/route-tree-client-plugin.ts +0 -77
- package/src/start-router-plugin/virtual-route-tree-plugin.ts +0 -29
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { hasChildWithExport, checkRouteFullPathUniqueness, ensureStringArgument } from "@tanstack/router-generator";
|
|
2
|
-
const EXPORT_NAME = "ServerRoute";
|
|
3
|
-
function serverRoutesPlugin() {
|
|
4
|
-
return {
|
|
5
|
-
name: "server-routes-plugin",
|
|
6
|
-
transformPlugin: {
|
|
7
|
-
name: "server-routes-transform",
|
|
8
|
-
exportName: EXPORT_NAME,
|
|
9
|
-
imports: (ctx) => {
|
|
10
|
-
const targetModule = `@tanstack/${ctx.target}-start/server`;
|
|
11
|
-
const imports = {};
|
|
12
|
-
if (ctx.verboseFileRoutes === false) {
|
|
13
|
-
imports.banned = [
|
|
14
|
-
{
|
|
15
|
-
source: targetModule,
|
|
16
|
-
specifiers: [{ imported: "createServerFileRoute" }]
|
|
17
|
-
}
|
|
18
|
-
];
|
|
19
|
-
} else {
|
|
20
|
-
imports.required = [
|
|
21
|
-
{
|
|
22
|
-
source: targetModule,
|
|
23
|
-
specifiers: [{ imported: "createServerFileRoute" }]
|
|
24
|
-
}
|
|
25
|
-
];
|
|
26
|
-
}
|
|
27
|
-
return imports;
|
|
28
|
-
},
|
|
29
|
-
onExportFound: ({ ctx, decl }) => {
|
|
30
|
-
let appliedChanges = false;
|
|
31
|
-
if (decl.init?.type === "CallExpression") {
|
|
32
|
-
let call = decl.init;
|
|
33
|
-
let callee = call.callee;
|
|
34
|
-
while (callee.type === "MemberExpression" && callee.object.type === "CallExpression") {
|
|
35
|
-
call = callee.object;
|
|
36
|
-
callee = call.callee;
|
|
37
|
-
}
|
|
38
|
-
if (call.callee.type === "Identifier" && call.callee.name === "createServerFileRoute") {
|
|
39
|
-
if (!ctx.verboseFileRoutes) {
|
|
40
|
-
if (call.arguments.length) {
|
|
41
|
-
call.arguments = [];
|
|
42
|
-
appliedChanges = true;
|
|
43
|
-
}
|
|
44
|
-
} else {
|
|
45
|
-
appliedChanges = ensureStringArgument(
|
|
46
|
-
call,
|
|
47
|
-
ctx.routeId,
|
|
48
|
-
ctx.preferredQuote
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
} else {
|
|
52
|
-
throw new Error(
|
|
53
|
-
`Expected "createServerFileRoute" call, but got "${call.callee.type}"`
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return appliedChanges;
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
moduleAugmentation: ({ generator }) => ({
|
|
61
|
-
module: `@tanstack/${generator.config.target}-start/server`,
|
|
62
|
-
interfaceName: "ServerFileRoutesByPath"
|
|
63
|
-
}),
|
|
64
|
-
onRouteTreesChanged: ({ routeTrees, generator }) => {
|
|
65
|
-
const tree = routeTrees.find((tree2) => tree2.exportName === EXPORT_NAME);
|
|
66
|
-
if (tree) {
|
|
67
|
-
checkRouteFullPathUniqueness(tree.sortedRouteNodes, generator.config);
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
imports: (ctx) => {
|
|
71
|
-
const imports = [];
|
|
72
|
-
const targetModule = `@tanstack/${ctx.generator.config.target}-start/server`;
|
|
73
|
-
if (ctx.generator.config.verboseFileRoutes === false) {
|
|
74
|
-
imports.push({
|
|
75
|
-
specifiers: [
|
|
76
|
-
{ imported: "CreateServerFileRoute" },
|
|
77
|
-
{ imported: "ServerFileRoutesByPath" }
|
|
78
|
-
],
|
|
79
|
-
source: targetModule,
|
|
80
|
-
importKind: "type"
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
const hasMatchingRouteFiles = ctx.acc.routeNodes.length > 0;
|
|
84
|
-
if (hasMatchingRouteFiles) {
|
|
85
|
-
if (!ctx.rootRouteNode.exports?.includes(EXPORT_NAME)) {
|
|
86
|
-
imports.push({
|
|
87
|
-
specifiers: [{ imported: "createServerRootRoute" }],
|
|
88
|
-
source: targetModule
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return imports;
|
|
93
|
-
},
|
|
94
|
-
routeModuleAugmentation: ({ routeNode }) => {
|
|
95
|
-
if (routeNode._fsRouteType === "lazy") {
|
|
96
|
-
return void 0;
|
|
97
|
-
}
|
|
98
|
-
return `const createServerFileRoute: CreateServerFileRoute<
|
|
99
|
-
ServerFileRoutesByPath['${routeNode.routePath}']['parentRoute'],
|
|
100
|
-
ServerFileRoutesByPath['${routeNode.routePath}']['id'],
|
|
101
|
-
ServerFileRoutesByPath['${routeNode.routePath}']['path'],
|
|
102
|
-
ServerFileRoutesByPath['${routeNode.routePath}']['fullPath'],
|
|
103
|
-
${hasChildWithExport(routeNode, "ServerRoute") ? `${routeNode.variableName}ServerRouteChildren` : "unknown"}
|
|
104
|
-
>`;
|
|
105
|
-
},
|
|
106
|
-
createRootRouteCode: () => `createServerRootRoute()`,
|
|
107
|
-
createVirtualRouteCode: ({ node }) => `createServerFileRoute('${node.routePath}')`,
|
|
108
|
-
config: ({ sortedRouteNodes }) => {
|
|
109
|
-
const hasMatchingRouteFiles = sortedRouteNodes.length > 0;
|
|
110
|
-
return {
|
|
111
|
-
virtualRootRoute: hasMatchingRouteFiles
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
export {
|
|
117
|
-
serverRoutesPlugin
|
|
118
|
-
};
|
|
119
|
-
//# sourceMappingURL=server-routes-plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server-routes-plugin.js","sources":["../../../../src/start-router-plugin/generator-plugins/server-routes-plugin.ts"],"sourcesContent":["import {\n checkRouteFullPathUniqueness,\n ensureStringArgument,\n hasChildWithExport,\n} from '@tanstack/router-generator'\n\nimport type {\n GeneratorPluginWithTransform,\n ImportDeclaration,\n TransformImportsConfig,\n} from '@tanstack/router-generator'\n\nconst EXPORT_NAME = 'ServerRoute'\nexport function serverRoutesPlugin(): GeneratorPluginWithTransform {\n return {\n name: 'server-routes-plugin',\n transformPlugin: {\n name: 'server-routes-transform',\n exportName: EXPORT_NAME,\n imports: (ctx) => {\n const targetModule = `@tanstack/${ctx.target}-start/server`\n const imports: TransformImportsConfig = {}\n if (ctx.verboseFileRoutes === false) {\n imports.banned = [\n {\n source: targetModule,\n specifiers: [{ imported: 'createServerFileRoute' }],\n },\n ]\n } else {\n imports.required = [\n {\n source: targetModule,\n specifiers: [{ imported: 'createServerFileRoute' }],\n },\n ]\n }\n return imports\n },\n onExportFound: ({ ctx, decl }) => {\n let appliedChanges = false\n if (decl.init?.type === 'CallExpression') {\n let call = decl.init\n let callee = call.callee\n\n while (\n callee.type === 'MemberExpression' &&\n callee.object.type === 'CallExpression'\n ) {\n call = callee.object\n callee = call.callee\n }\n if (\n call.callee.type === 'Identifier' &&\n call.callee.name === 'createServerFileRoute'\n ) {\n if (!ctx.verboseFileRoutes) {\n if (call.arguments.length) {\n call.arguments = []\n appliedChanges = true\n }\n } else {\n appliedChanges = ensureStringArgument(\n call,\n ctx.routeId,\n ctx.preferredQuote,\n )\n }\n } else {\n throw new Error(\n `Expected \"createServerFileRoute\" call, but got \"${call.callee.type}\"`,\n )\n }\n }\n return appliedChanges\n },\n },\n moduleAugmentation: ({ generator }) => ({\n module: `@tanstack/${generator.config.target}-start/server`,\n interfaceName: 'ServerFileRoutesByPath',\n }),\n onRouteTreesChanged: ({ routeTrees, generator }) => {\n const tree = routeTrees.find((tree) => tree.exportName === EXPORT_NAME)\n if (tree) {\n checkRouteFullPathUniqueness(tree.sortedRouteNodes, generator.config)\n }\n },\n imports: (ctx) => {\n const imports: Array<ImportDeclaration> = []\n\n const targetModule = `@tanstack/${ctx.generator.config.target}-start/server`\n if (ctx.generator.config.verboseFileRoutes === false) {\n imports.push({\n specifiers: [\n { imported: 'CreateServerFileRoute' },\n { imported: 'ServerFileRoutesByPath' },\n ],\n source: targetModule,\n importKind: 'type',\n })\n }\n // don't add the import if there are no server routes defined\n const hasMatchingRouteFiles = ctx.acc.routeNodes.length > 0\n if (hasMatchingRouteFiles) {\n // needs a virtual root route\n if (!ctx.rootRouteNode.exports?.includes(EXPORT_NAME)) {\n imports.push({\n specifiers: [{ imported: 'createServerRootRoute' }],\n source: targetModule,\n })\n }\n }\n return imports\n },\n routeModuleAugmentation: ({ routeNode }) => {\n // server routes don't support lazy routes\n if (routeNode._fsRouteType === 'lazy') {\n return undefined\n }\n return `const createServerFileRoute: CreateServerFileRoute<\n ServerFileRoutesByPath['${routeNode.routePath}']['parentRoute'],\n ServerFileRoutesByPath['${routeNode.routePath}']['id'],\n ServerFileRoutesByPath['${routeNode.routePath}']['path'],\n ServerFileRoutesByPath['${routeNode.routePath}']['fullPath'],\n ${hasChildWithExport(routeNode, 'ServerRoute') ? `${routeNode.variableName}ServerRouteChildren` : 'unknown'}\n >`\n },\n createRootRouteCode: () => `createServerRootRoute()`,\n createVirtualRouteCode: ({ node }) =>\n `createServerFileRoute('${node.routePath}')`,\n config: ({ sortedRouteNodes }) => {\n const hasMatchingRouteFiles = sortedRouteNodes.length > 0\n return {\n virtualRootRoute: hasMatchingRouteFiles,\n }\n },\n }\n}\n"],"names":["tree"],"mappings":"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"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
2
|
-
import { Config } from '@tanstack/router-generator';
|
|
3
|
-
/**
|
|
4
|
-
* This removes the server part from the generated route tree so that it can be used on the client.
|
|
5
|
-
*/
|
|
6
|
-
export declare function routeTreeClientPlugin(config: Config): Plugin;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import * as t from "@babel/types";
|
|
3
|
-
import { parseAst, generateFromAst, logDiff } from "@tanstack/router-utils";
|
|
4
|
-
import { normalizePath } from "vite";
|
|
5
|
-
import { deadCodeElimination } from "babel-dead-code-elimination";
|
|
6
|
-
import { debug } from "../debug.js";
|
|
7
|
-
import { VITE_ENVIRONMENT_NAMES } from "../constants.js";
|
|
8
|
-
function routeTreeClientPlugin(config) {
|
|
9
|
-
const generatedRouteTreePath = normalizePath(
|
|
10
|
-
path.resolve(config.generatedRouteTree)
|
|
11
|
-
);
|
|
12
|
-
return {
|
|
13
|
-
name: "tanstack-start:route-tree-client-plugin",
|
|
14
|
-
enforce: "pre",
|
|
15
|
-
// only run this plugin in the client environment
|
|
16
|
-
applyToEnvironment: (env) => env.name === VITE_ENVIRONMENT_NAMES.client,
|
|
17
|
-
transform: {
|
|
18
|
-
filter: { id: generatedRouteTreePath },
|
|
19
|
-
handler(code, id) {
|
|
20
|
-
if (id !== generatedRouteTreePath) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
if (debug) console.info(`Compiling route tree for the client`, id);
|
|
24
|
-
const ast = parseAst({ code, sourceFilename: id });
|
|
25
|
-
const filteredBody = ast.program.body.filter((node) => {
|
|
26
|
-
if (t.isExportNamedDeclaration(node)) {
|
|
27
|
-
if (node.declaration && t.isVariableDeclaration(node.declaration) && node.declaration.declarations.length === 1 && node.declaration.declarations[0] && t.isVariableDeclarator(node.declaration.declarations[0]) && t.isIdentifier(node.declaration.declarations[0].id) && node.declaration.declarations[0].id.name === "routeTree") {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
if (t.isTSInterfaceDeclaration(node) || t.isTSModuleDeclaration(node)) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
return true;
|
|
36
|
-
});
|
|
37
|
-
ast.program.body = filteredBody;
|
|
38
|
-
deadCodeElimination(ast);
|
|
39
|
-
const compiled = generateFromAst(ast, {
|
|
40
|
-
sourceMaps: true,
|
|
41
|
-
sourceFileName: id,
|
|
42
|
-
filename: id
|
|
43
|
-
});
|
|
44
|
-
if (debug) {
|
|
45
|
-
logDiff(code, compiled.code);
|
|
46
|
-
console.log("Output:\n", compiled.code, "\n\n");
|
|
47
|
-
}
|
|
48
|
-
return compiled;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
export {
|
|
54
|
-
routeTreeClientPlugin
|
|
55
|
-
};
|
|
56
|
-
//# sourceMappingURL=route-tree-client-plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"route-tree-client-plugin.js","sources":["../../../src/start-router-plugin/route-tree-client-plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport * as t from '@babel/types'\nimport { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'\nimport { normalizePath } from 'vite'\nimport { deadCodeElimination } from 'babel-dead-code-elimination'\nimport { debug } from '../debug'\nimport { VITE_ENVIRONMENT_NAMES } from '../constants'\nimport type { Plugin } from 'vite'\nimport type { Config } from '@tanstack/router-generator'\n\n/**\n * This removes the server part from the generated route tree so that it can be used on the client.\n */\nexport function routeTreeClientPlugin(config: Config): Plugin {\n const generatedRouteTreePath = normalizePath(\n path.resolve(config.generatedRouteTree),\n )\n\n return {\n name: 'tanstack-start:route-tree-client-plugin',\n enforce: 'pre',\n // only run this plugin in the client environment\n applyToEnvironment: (env) => env.name === VITE_ENVIRONMENT_NAMES.client,\n transform: {\n filter: { id: generatedRouteTreePath },\n handler(code, id) {\n if (id !== generatedRouteTreePath) {\n return null\n }\n if (debug) console.info(`Compiling route tree for the client`, id)\n const ast = parseAst({ code, sourceFilename: id })\n\n // only keep `export const routeTree = ... `\n const filteredBody = ast.program.body.filter((node) => {\n if (t.isExportNamedDeclaration(node)) {\n if (\n node.declaration &&\n t.isVariableDeclaration(node.declaration) &&\n node.declaration.declarations.length === 1 &&\n node.declaration.declarations[0] &&\n t.isVariableDeclarator(node.declaration.declarations[0]) &&\n t.isIdentifier(node.declaration.declarations[0].id) &&\n node.declaration.declarations[0].id.name === 'routeTree'\n ) {\n return true\n }\n return false\n }\n // strip off the typescript interface & module declarations since they also reference the server routes\n if (\n t.isTSInterfaceDeclaration(node) ||\n t.isTSModuleDeclaration(node)\n ) {\n return false\n }\n return true\n })\n\n ast.program.body = filteredBody\n\n deadCodeElimination(ast)\n\n const compiled = generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: id,\n filename: id,\n })\n if (debug) {\n logDiff(code, compiled.code)\n console.log('Output:\\n', compiled.code, '\\n\\n')\n }\n\n return compiled\n },\n },\n }\n}\n"],"names":[],"mappings":";;;;;;;AAaO,SAAS,sBAAsB,QAAwB;AAC5D,QAAM,yBAAyB;AAAA,IAC7B,KAAK,QAAQ,OAAO,kBAAkB;AAAA,EAAA;AAGxC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA;AAAA,IAET,oBAAoB,CAAC,QAAQ,IAAI,SAAS,uBAAuB;AAAA,IACjE,WAAW;AAAA,MACT,QAAQ,EAAE,IAAI,uBAAA;AAAA,MACd,QAAQ,MAAM,IAAI;AAChB,YAAI,OAAO,wBAAwB;AACjC,iBAAO;AAAA,QACT;AACA,YAAI,MAAO,SAAQ,KAAK,uCAAuC,EAAE;AACjE,cAAM,MAAM,SAAS,EAAE,MAAM,gBAAgB,IAAI;AAGjD,cAAM,eAAe,IAAI,QAAQ,KAAK,OAAO,CAAC,SAAS;AACrD,cAAI,EAAE,yBAAyB,IAAI,GAAG;AACpC,gBACE,KAAK,eACL,EAAE,sBAAsB,KAAK,WAAW,KACxC,KAAK,YAAY,aAAa,WAAW,KACzC,KAAK,YAAY,aAAa,CAAC,KAC/B,EAAE,qBAAqB,KAAK,YAAY,aAAa,CAAC,CAAC,KACvD,EAAE,aAAa,KAAK,YAAY,aAAa,CAAC,EAAE,EAAE,KAClD,KAAK,YAAY,aAAa,CAAC,EAAE,GAAG,SAAS,aAC7C;AACA,qBAAO;AAAA,YACT;AACA,mBAAO;AAAA,UACT;AAEA,cACE,EAAE,yBAAyB,IAAI,KAC/B,EAAE,sBAAsB,IAAI,GAC5B;AACA,mBAAO;AAAA,UACT;AACA,iBAAO;AAAA,QACT,CAAC;AAED,YAAI,QAAQ,OAAO;AAEnB,4BAAoB,GAAG;AAEvB,cAAM,WAAW,gBAAgB,KAAK;AAAA,UACpC,YAAY;AAAA,UACZ,gBAAgB;AAAA,UAChB,UAAU;AAAA,QAAA,CACX;AACD,YAAI,OAAO;AACT,kBAAQ,MAAM,SAAS,IAAI;AAC3B,kBAAQ,IAAI,aAAa,SAAS,MAAM,MAAM;AAAA,QAChD;AAEA,eAAO;AAAA,MACT;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { normalizePath } from "vite";
|
|
3
|
-
import { VIRTUAL_MODULES } from "@tanstack/start-server-core";
|
|
4
|
-
import { debug } from "../debug.js";
|
|
5
|
-
function virtualRouteTreePlugin(config) {
|
|
6
|
-
const generatedRouteTreePath = normalizePath(
|
|
7
|
-
path.resolve(config.generatedRouteTree)
|
|
8
|
-
);
|
|
9
|
-
return {
|
|
10
|
-
name: "tanstack-start:virtual-route-tree",
|
|
11
|
-
enforce: "pre",
|
|
12
|
-
sharedDuringBuild: true,
|
|
13
|
-
resolveId: {
|
|
14
|
-
filter: { id: new RegExp(VIRTUAL_MODULES.routeTree) },
|
|
15
|
-
handler(id) {
|
|
16
|
-
let resolvedId = null;
|
|
17
|
-
if (id === VIRTUAL_MODULES.routeTree) {
|
|
18
|
-
if (debug) console.info("resolving id", id, generatedRouteTreePath);
|
|
19
|
-
resolvedId = generatedRouteTreePath;
|
|
20
|
-
}
|
|
21
|
-
return resolvedId;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
export {
|
|
27
|
-
virtualRouteTreePlugin
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=virtual-route-tree-plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-route-tree-plugin.js","sources":["../../../src/start-router-plugin/virtual-route-tree-plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { normalizePath } from 'vite'\nimport { VIRTUAL_MODULES } from '@tanstack/start-server-core'\nimport { debug } from '../debug'\nimport type { Config } from '@tanstack/router-generator'\nimport type { Plugin } from 'vite'\n\nexport function virtualRouteTreePlugin(config: Config): Plugin {\n const generatedRouteTreePath = normalizePath(\n path.resolve(config.generatedRouteTree),\n )\n\n return {\n name: 'tanstack-start:virtual-route-tree',\n enforce: 'pre',\n sharedDuringBuild: true,\n resolveId: {\n filter: { id: new RegExp(VIRTUAL_MODULES.routeTree) },\n handler(id) {\n let resolvedId: string | null = null\n if (id === VIRTUAL_MODULES.routeTree) {\n if (debug) console.info('resolving id', id, generatedRouteTreePath)\n resolvedId = generatedRouteTreePath\n }\n return resolvedId\n },\n },\n }\n}\n"],"names":[],"mappings":";;;;AAOO,SAAS,uBAAuB,QAAwB;AAC7D,QAAM,yBAAyB;AAAA,IAC7B,KAAK,QAAQ,OAAO,kBAAkB;AAAA,EAAA;AAGxC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,mBAAmB;AAAA,IACnB,WAAW;AAAA,MACT,QAAQ,EAAE,IAAI,IAAI,OAAO,gBAAgB,SAAS,EAAA;AAAA,MAClD,QAAQ,IAAI;AACV,YAAI,aAA4B;AAChC,YAAI,OAAO,gBAAgB,WAAW;AACpC,cAAI,MAAO,SAAQ,KAAK,gBAAgB,IAAI,sBAAsB;AAClE,uBAAa;AAAA,QACf;AACA,eAAO;AAAA,MACT;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import * as t from '@babel/types'
|
|
2
|
-
import type * as babel from '@babel/core'
|
|
3
|
-
|
|
4
|
-
import type { CompileOptions, CompileStartFrameworkOptions } from './compilers'
|
|
5
|
-
|
|
6
|
-
export function handleCreateServerFileRouteCallExpressionFactory(
|
|
7
|
-
framework: CompileStartFrameworkOptions,
|
|
8
|
-
method:
|
|
9
|
-
| 'createServerFileRoute'
|
|
10
|
-
| 'createServerRoute'
|
|
11
|
-
| 'createServerRootRoute',
|
|
12
|
-
) {
|
|
13
|
-
return function handleCreateServerFileRouteCallExpression(
|
|
14
|
-
path: babel.NodePath<t.CallExpression>,
|
|
15
|
-
opts: CompileOptions,
|
|
16
|
-
) {
|
|
17
|
-
const PACKAGES = { start: `@tanstack/${framework}-start/server` }
|
|
18
|
-
|
|
19
|
-
let highestParent: babel.NodePath<any> = path
|
|
20
|
-
|
|
21
|
-
while (highestParent.parentPath && !highestParent.parentPath.isProgram()) {
|
|
22
|
-
highestParent = highestParent.parentPath
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const programPath = highestParent.parentPath as babel.NodePath<t.Program>
|
|
26
|
-
|
|
27
|
-
// If we're on the client, remove the entire variable
|
|
28
|
-
if (opts.env === 'client') {
|
|
29
|
-
highestParent.remove()
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let isCreateServerFileRouteImported = false as boolean
|
|
34
|
-
|
|
35
|
-
programPath.traverse({
|
|
36
|
-
ImportDeclaration(importPath) {
|
|
37
|
-
const importSource = importPath.node.source.value
|
|
38
|
-
if (importSource === PACKAGES.start) {
|
|
39
|
-
const specifiers = importPath.node.specifiers
|
|
40
|
-
isCreateServerFileRouteImported ||= specifiers.some((specifier) => {
|
|
41
|
-
return (
|
|
42
|
-
t.isImportSpecifier(specifier) &&
|
|
43
|
-
t.isIdentifier(specifier.imported) &&
|
|
44
|
-
specifier.imported.name === method
|
|
45
|
-
)
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
if (!isCreateServerFileRouteImported) {
|
|
52
|
-
const importDeclaration = t.importDeclaration(
|
|
53
|
-
[t.importSpecifier(t.identifier(method), t.identifier(method))],
|
|
54
|
-
t.stringLiteral(PACKAGES.start),
|
|
55
|
-
)
|
|
56
|
-
programPath.node.body.unshift(importDeclaration)
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
checkRouteFullPathUniqueness,
|
|
3
|
-
ensureStringArgument,
|
|
4
|
-
hasChildWithExport,
|
|
5
|
-
} from '@tanstack/router-generator'
|
|
6
|
-
|
|
7
|
-
import type {
|
|
8
|
-
GeneratorPluginWithTransform,
|
|
9
|
-
ImportDeclaration,
|
|
10
|
-
TransformImportsConfig,
|
|
11
|
-
} from '@tanstack/router-generator'
|
|
12
|
-
|
|
13
|
-
const EXPORT_NAME = 'ServerRoute'
|
|
14
|
-
export function serverRoutesPlugin(): GeneratorPluginWithTransform {
|
|
15
|
-
return {
|
|
16
|
-
name: 'server-routes-plugin',
|
|
17
|
-
transformPlugin: {
|
|
18
|
-
name: 'server-routes-transform',
|
|
19
|
-
exportName: EXPORT_NAME,
|
|
20
|
-
imports: (ctx) => {
|
|
21
|
-
const targetModule = `@tanstack/${ctx.target}-start/server`
|
|
22
|
-
const imports: TransformImportsConfig = {}
|
|
23
|
-
if (ctx.verboseFileRoutes === false) {
|
|
24
|
-
imports.banned = [
|
|
25
|
-
{
|
|
26
|
-
source: targetModule,
|
|
27
|
-
specifiers: [{ imported: 'createServerFileRoute' }],
|
|
28
|
-
},
|
|
29
|
-
]
|
|
30
|
-
} else {
|
|
31
|
-
imports.required = [
|
|
32
|
-
{
|
|
33
|
-
source: targetModule,
|
|
34
|
-
specifiers: [{ imported: 'createServerFileRoute' }],
|
|
35
|
-
},
|
|
36
|
-
]
|
|
37
|
-
}
|
|
38
|
-
return imports
|
|
39
|
-
},
|
|
40
|
-
onExportFound: ({ ctx, decl }) => {
|
|
41
|
-
let appliedChanges = false
|
|
42
|
-
if (decl.init?.type === 'CallExpression') {
|
|
43
|
-
let call = decl.init
|
|
44
|
-
let callee = call.callee
|
|
45
|
-
|
|
46
|
-
while (
|
|
47
|
-
callee.type === 'MemberExpression' &&
|
|
48
|
-
callee.object.type === 'CallExpression'
|
|
49
|
-
) {
|
|
50
|
-
call = callee.object
|
|
51
|
-
callee = call.callee
|
|
52
|
-
}
|
|
53
|
-
if (
|
|
54
|
-
call.callee.type === 'Identifier' &&
|
|
55
|
-
call.callee.name === 'createServerFileRoute'
|
|
56
|
-
) {
|
|
57
|
-
if (!ctx.verboseFileRoutes) {
|
|
58
|
-
if (call.arguments.length) {
|
|
59
|
-
call.arguments = []
|
|
60
|
-
appliedChanges = true
|
|
61
|
-
}
|
|
62
|
-
} else {
|
|
63
|
-
appliedChanges = ensureStringArgument(
|
|
64
|
-
call,
|
|
65
|
-
ctx.routeId,
|
|
66
|
-
ctx.preferredQuote,
|
|
67
|
-
)
|
|
68
|
-
}
|
|
69
|
-
} else {
|
|
70
|
-
throw new Error(
|
|
71
|
-
`Expected "createServerFileRoute" call, but got "${call.callee.type}"`,
|
|
72
|
-
)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return appliedChanges
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
moduleAugmentation: ({ generator }) => ({
|
|
79
|
-
module: `@tanstack/${generator.config.target}-start/server`,
|
|
80
|
-
interfaceName: 'ServerFileRoutesByPath',
|
|
81
|
-
}),
|
|
82
|
-
onRouteTreesChanged: ({ routeTrees, generator }) => {
|
|
83
|
-
const tree = routeTrees.find((tree) => tree.exportName === EXPORT_NAME)
|
|
84
|
-
if (tree) {
|
|
85
|
-
checkRouteFullPathUniqueness(tree.sortedRouteNodes, generator.config)
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
imports: (ctx) => {
|
|
89
|
-
const imports: Array<ImportDeclaration> = []
|
|
90
|
-
|
|
91
|
-
const targetModule = `@tanstack/${ctx.generator.config.target}-start/server`
|
|
92
|
-
if (ctx.generator.config.verboseFileRoutes === false) {
|
|
93
|
-
imports.push({
|
|
94
|
-
specifiers: [
|
|
95
|
-
{ imported: 'CreateServerFileRoute' },
|
|
96
|
-
{ imported: 'ServerFileRoutesByPath' },
|
|
97
|
-
],
|
|
98
|
-
source: targetModule,
|
|
99
|
-
importKind: 'type',
|
|
100
|
-
})
|
|
101
|
-
}
|
|
102
|
-
// don't add the import if there are no server routes defined
|
|
103
|
-
const hasMatchingRouteFiles = ctx.acc.routeNodes.length > 0
|
|
104
|
-
if (hasMatchingRouteFiles) {
|
|
105
|
-
// needs a virtual root route
|
|
106
|
-
if (!ctx.rootRouteNode.exports?.includes(EXPORT_NAME)) {
|
|
107
|
-
imports.push({
|
|
108
|
-
specifiers: [{ imported: 'createServerRootRoute' }],
|
|
109
|
-
source: targetModule,
|
|
110
|
-
})
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return imports
|
|
114
|
-
},
|
|
115
|
-
routeModuleAugmentation: ({ routeNode }) => {
|
|
116
|
-
// server routes don't support lazy routes
|
|
117
|
-
if (routeNode._fsRouteType === 'lazy') {
|
|
118
|
-
return undefined
|
|
119
|
-
}
|
|
120
|
-
return `const createServerFileRoute: CreateServerFileRoute<
|
|
121
|
-
ServerFileRoutesByPath['${routeNode.routePath}']['parentRoute'],
|
|
122
|
-
ServerFileRoutesByPath['${routeNode.routePath}']['id'],
|
|
123
|
-
ServerFileRoutesByPath['${routeNode.routePath}']['path'],
|
|
124
|
-
ServerFileRoutesByPath['${routeNode.routePath}']['fullPath'],
|
|
125
|
-
${hasChildWithExport(routeNode, 'ServerRoute') ? `${routeNode.variableName}ServerRouteChildren` : 'unknown'}
|
|
126
|
-
>`
|
|
127
|
-
},
|
|
128
|
-
createRootRouteCode: () => `createServerRootRoute()`,
|
|
129
|
-
createVirtualRouteCode: ({ node }) =>
|
|
130
|
-
`createServerFileRoute('${node.routePath}')`,
|
|
131
|
-
config: ({ sortedRouteNodes }) => {
|
|
132
|
-
const hasMatchingRouteFiles = sortedRouteNodes.length > 0
|
|
133
|
-
return {
|
|
134
|
-
virtualRootRoute: hasMatchingRouteFiles,
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
}
|
|
138
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import * as t from '@babel/types'
|
|
3
|
-
import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'
|
|
4
|
-
import { normalizePath } from 'vite'
|
|
5
|
-
import { deadCodeElimination } from 'babel-dead-code-elimination'
|
|
6
|
-
import { debug } from '../debug'
|
|
7
|
-
import { VITE_ENVIRONMENT_NAMES } from '../constants'
|
|
8
|
-
import type { Plugin } from 'vite'
|
|
9
|
-
import type { Config } from '@tanstack/router-generator'
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* This removes the server part from the generated route tree so that it can be used on the client.
|
|
13
|
-
*/
|
|
14
|
-
export function routeTreeClientPlugin(config: Config): Plugin {
|
|
15
|
-
const generatedRouteTreePath = normalizePath(
|
|
16
|
-
path.resolve(config.generatedRouteTree),
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
name: 'tanstack-start:route-tree-client-plugin',
|
|
21
|
-
enforce: 'pre',
|
|
22
|
-
// only run this plugin in the client environment
|
|
23
|
-
applyToEnvironment: (env) => env.name === VITE_ENVIRONMENT_NAMES.client,
|
|
24
|
-
transform: {
|
|
25
|
-
filter: { id: generatedRouteTreePath },
|
|
26
|
-
handler(code, id) {
|
|
27
|
-
if (id !== generatedRouteTreePath) {
|
|
28
|
-
return null
|
|
29
|
-
}
|
|
30
|
-
if (debug) console.info(`Compiling route tree for the client`, id)
|
|
31
|
-
const ast = parseAst({ code, sourceFilename: id })
|
|
32
|
-
|
|
33
|
-
// only keep `export const routeTree = ... `
|
|
34
|
-
const filteredBody = ast.program.body.filter((node) => {
|
|
35
|
-
if (t.isExportNamedDeclaration(node)) {
|
|
36
|
-
if (
|
|
37
|
-
node.declaration &&
|
|
38
|
-
t.isVariableDeclaration(node.declaration) &&
|
|
39
|
-
node.declaration.declarations.length === 1 &&
|
|
40
|
-
node.declaration.declarations[0] &&
|
|
41
|
-
t.isVariableDeclarator(node.declaration.declarations[0]) &&
|
|
42
|
-
t.isIdentifier(node.declaration.declarations[0].id) &&
|
|
43
|
-
node.declaration.declarations[0].id.name === 'routeTree'
|
|
44
|
-
) {
|
|
45
|
-
return true
|
|
46
|
-
}
|
|
47
|
-
return false
|
|
48
|
-
}
|
|
49
|
-
// strip off the typescript interface & module declarations since they also reference the server routes
|
|
50
|
-
if (
|
|
51
|
-
t.isTSInterfaceDeclaration(node) ||
|
|
52
|
-
t.isTSModuleDeclaration(node)
|
|
53
|
-
) {
|
|
54
|
-
return false
|
|
55
|
-
}
|
|
56
|
-
return true
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
ast.program.body = filteredBody
|
|
60
|
-
|
|
61
|
-
deadCodeElimination(ast)
|
|
62
|
-
|
|
63
|
-
const compiled = generateFromAst(ast, {
|
|
64
|
-
sourceMaps: true,
|
|
65
|
-
sourceFileName: id,
|
|
66
|
-
filename: id,
|
|
67
|
-
})
|
|
68
|
-
if (debug) {
|
|
69
|
-
logDiff(code, compiled.code)
|
|
70
|
-
console.log('Output:\n', compiled.code, '\n\n')
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return compiled
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import { normalizePath } from 'vite'
|
|
3
|
-
import { VIRTUAL_MODULES } from '@tanstack/start-server-core'
|
|
4
|
-
import { debug } from '../debug'
|
|
5
|
-
import type { Config } from '@tanstack/router-generator'
|
|
6
|
-
import type { Plugin } from 'vite'
|
|
7
|
-
|
|
8
|
-
export function virtualRouteTreePlugin(config: Config): Plugin {
|
|
9
|
-
const generatedRouteTreePath = normalizePath(
|
|
10
|
-
path.resolve(config.generatedRouteTree),
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
return {
|
|
14
|
-
name: 'tanstack-start:virtual-route-tree',
|
|
15
|
-
enforce: 'pre',
|
|
16
|
-
sharedDuringBuild: true,
|
|
17
|
-
resolveId: {
|
|
18
|
-
filter: { id: new RegExp(VIRTUAL_MODULES.routeTree) },
|
|
19
|
-
handler(id) {
|
|
20
|
-
let resolvedId: string | null = null
|
|
21
|
-
if (id === VIRTUAL_MODULES.routeTree) {
|
|
22
|
-
if (debug) console.info('resolving id', id, generatedRouteTreePath)
|
|
23
|
-
resolvedId = generatedRouteTreePath
|
|
24
|
-
}
|
|
25
|
-
return resolvedId
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
}
|
|
29
|
-
}
|