@tanstack/start-plugin-core 1.166.11 → 1.166.13
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/build-sitemap.js +94 -123
- package/dist/esm/build-sitemap.js.map +1 -1
- package/dist/esm/constants.js +15 -20
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/dev-server-plugin/dev-styles.js +137 -150
- package/dist/esm/dev-server-plugin/dev-styles.js.map +1 -1
- package/dist/esm/dev-server-plugin/extract-html-scripts.js +16 -15
- package/dist/esm/dev-server-plugin/extract-html-scripts.js.map +1 -1
- package/dist/esm/dev-server-plugin/plugin.js +125 -195
- package/dist/esm/dev-server-plugin/plugin.js.map +1 -1
- package/dist/esm/import-protection-plugin/ast.js +6 -5
- package/dist/esm/import-protection-plugin/ast.js.map +1 -1
- package/dist/esm/import-protection-plugin/constants.js +20 -22
- package/dist/esm/import-protection-plugin/constants.js.map +1 -1
- package/dist/esm/import-protection-plugin/defaults.js +35 -25
- package/dist/esm/import-protection-plugin/defaults.js.map +1 -1
- package/dist/esm/import-protection-plugin/extensionlessAbsoluteIdResolver.js +93 -92
- package/dist/esm/import-protection-plugin/extensionlessAbsoluteIdResolver.js.map +1 -1
- package/dist/esm/import-protection-plugin/matchers.js +23 -24
- package/dist/esm/import-protection-plugin/matchers.js.map +1 -1
- package/dist/esm/import-protection-plugin/plugin.js +1045 -1361
- package/dist/esm/import-protection-plugin/plugin.js.map +1 -1
- package/dist/esm/import-protection-plugin/postCompileUsage.js +58 -55
- package/dist/esm/import-protection-plugin/postCompileUsage.js.map +1 -1
- package/dist/esm/import-protection-plugin/rewriteDeniedImports.js +187 -259
- package/dist/esm/import-protection-plugin/rewriteDeniedImports.js.map +1 -1
- package/dist/esm/import-protection-plugin/sourceLocation.js +238 -248
- package/dist/esm/import-protection-plugin/sourceLocation.js.map +1 -1
- package/dist/esm/import-protection-plugin/trace.js +173 -184
- package/dist/esm/import-protection-plugin/trace.js.map +1 -1
- package/dist/esm/import-protection-plugin/utils.js +132 -111
- package/dist/esm/import-protection-plugin/utils.js.map +1 -1
- package/dist/esm/import-protection-plugin/virtualModules.js +214 -194
- package/dist/esm/import-protection-plugin/virtualModules.js.map +1 -1
- package/dist/esm/index.js +2 -7
- package/dist/esm/load-env-plugin/plugin.js +12 -11
- package/dist/esm/load-env-plugin/plugin.js.map +1 -1
- package/dist/esm/output-directory.js +10 -10
- package/dist/esm/output-directory.js.map +1 -1
- package/dist/esm/plugin.js +275 -355
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/post-server-build.js +39 -53
- package/dist/esm/post-server-build.js.map +1 -1
- package/dist/esm/prerender.js +177 -239
- package/dist/esm/prerender.js.map +1 -1
- package/dist/esm/preview-server-plugin/plugin.js +41 -44
- package/dist/esm/preview-server-plugin/plugin.js.map +1 -1
- package/dist/esm/queue.js +115 -126
- package/dist/esm/queue.js.map +1 -1
- package/dist/esm/resolve-entries.js +31 -32
- package/dist/esm/resolve-entries.js.map +1 -1
- package/dist/esm/schema.js +156 -179
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/start-compiler-plugin/compiler.js +655 -812
- package/dist/esm/start-compiler-plugin/compiler.js.map +1 -1
- package/dist/esm/start-compiler-plugin/handleClientOnlyJSX.js +25 -8
- package/dist/esm/start-compiler-plugin/handleClientOnlyJSX.js.map +1 -1
- package/dist/esm/start-compiler-plugin/handleCreateIsomorphicFn.js +22 -19
- package/dist/esm/start-compiler-plugin/handleCreateIsomorphicFn.js.map +1 -1
- package/dist/esm/start-compiler-plugin/handleCreateMiddleware.js +20 -22
- package/dist/esm/start-compiler-plugin/handleCreateMiddleware.js.map +1 -1
- package/dist/esm/start-compiler-plugin/handleCreateServerFn.js +187 -255
- package/dist/esm/start-compiler-plugin/handleCreateServerFn.js.map +1 -1
- package/dist/esm/start-compiler-plugin/handleEnvOnly.js +23 -33
- package/dist/esm/start-compiler-plugin/handleEnvOnly.js.map +1 -1
- package/dist/esm/start-compiler-plugin/plugin.js +247 -291
- package/dist/esm/start-compiler-plugin/plugin.js.map +1 -1
- package/dist/esm/start-compiler-plugin/utils.js +27 -27
- package/dist/esm/start-compiler-plugin/utils.js.map +1 -1
- package/dist/esm/start-manifest-plugin/manifestBuilder.js +272 -378
- package/dist/esm/start-manifest-plugin/manifestBuilder.js.map +1 -1
- package/dist/esm/start-manifest-plugin/plugin.js +35 -44
- package/dist/esm/start-manifest-plugin/plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/constants.js +6 -5
- package/dist/esm/start-router-plugin/constants.js.map +1 -1
- package/dist/esm/start-router-plugin/generator-plugins/prerender-routes-plugin.js +24 -19
- package/dist/esm/start-router-plugin/generator-plugins/prerender-routes-plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js +28 -29
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/plugin.js +146 -199
- package/dist/esm/start-router-plugin/plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.js +32 -31
- package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.js.map +1 -1
- package/dist/esm/utils.js +14 -14
- package/dist/esm/utils.js.map +1 -1
- package/package.json +7 -7
- package/dist/esm/index.js.map +0 -1
|
@@ -1,211 +1,158 @@
|
|
|
1
|
-
import { tanstackRouterGenerator, tanStackRouterCodeSplitter, tanstackRouterAutoImport } from "@tanstack/router-plugin/vite";
|
|
2
|
-
import { normalizePath } from "vite";
|
|
3
|
-
import path__default from "pathe";
|
|
4
1
|
import { VITE_ENVIRONMENT_NAMES } from "../constants.js";
|
|
5
2
|
import { routesManifestPlugin } from "./generator-plugins/routes-manifest-plugin.js";
|
|
6
3
|
import { prerenderRoutesPlugin } from "./generator-plugins/prerender-routes-plugin.js";
|
|
4
|
+
import "./constants.js";
|
|
7
5
|
import { pruneServerOnlySubtrees } from "./pruneServerOnlySubtrees.js";
|
|
8
|
-
import {
|
|
6
|
+
import { normalizePath } from "vite";
|
|
7
|
+
import path from "pathe";
|
|
8
|
+
import { tanStackRouterCodeSplitter, tanstackRouterAutoImport, tanstackRouterGenerator } from "@tanstack/router-plugin/vite";
|
|
9
|
+
//#region src/start-router-plugin/plugin.ts
|
|
9
10
|
function isServerOnlyNode(node) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
return node.createFileRouteProps.has(SERVER_PROP) && node.createFileRouteProps.size === 1;
|
|
11
|
+
if (!node?.createFileRouteProps) return false;
|
|
12
|
+
return node.createFileRouteProps.has("server") && node.createFileRouteProps.size === 1;
|
|
14
13
|
}
|
|
15
|
-
function moduleDeclaration({
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (!relativePath.startsWith(".")) {
|
|
27
|
-
relativePath = "./" + relativePath;
|
|
28
|
-
}
|
|
29
|
-
relativePath = relativePath.split(path__default.sep).join("/");
|
|
30
|
-
return relativePath;
|
|
31
|
-
}
|
|
32
|
-
const result = [
|
|
33
|
-
`import type { getRouter } from '${getImportPath(routerFilePath)}'`
|
|
34
|
-
];
|
|
35
|
-
if (startFilePath) {
|
|
36
|
-
result.push(
|
|
37
|
-
`import type { startInstance } from '${getImportPath(startFilePath)}'`
|
|
38
|
-
);
|
|
39
|
-
} else {
|
|
40
|
-
result.push(
|
|
41
|
-
`import type { createStart } from '@tanstack/${corePluginOpts.framework}-start'`
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
result.push(
|
|
45
|
-
`declare module '@tanstack/${corePluginOpts.framework}-start' {
|
|
14
|
+
function moduleDeclaration({ startFilePath, routerFilePath, corePluginOpts, generatedRouteTreePath }) {
|
|
15
|
+
function getImportPath(absolutePath) {
|
|
16
|
+
let relativePath = path.relative(path.dirname(generatedRouteTreePath), absolutePath);
|
|
17
|
+
if (!relativePath.startsWith(".")) relativePath = "./" + relativePath;
|
|
18
|
+
relativePath = relativePath.split(path.sep).join("/");
|
|
19
|
+
return relativePath;
|
|
20
|
+
}
|
|
21
|
+
const result = [`import type { getRouter } from '${getImportPath(routerFilePath)}'`];
|
|
22
|
+
if (startFilePath) result.push(`import type { startInstance } from '${getImportPath(startFilePath)}'`);
|
|
23
|
+
else result.push(`import type { createStart } from '@tanstack/${corePluginOpts.framework}-start'`);
|
|
24
|
+
result.push(`declare module '@tanstack/${corePluginOpts.framework}-start' {
|
|
46
25
|
interface Register {
|
|
47
26
|
ssr: true
|
|
48
|
-
router: Awaited<ReturnType<typeof getRouter>>`
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
result.push(
|
|
52
|
-
` config: Awaited<ReturnType<typeof startInstance.getOptions>>`
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
result.push(` }
|
|
27
|
+
router: Awaited<ReturnType<typeof getRouter>>`);
|
|
28
|
+
if (startFilePath) result.push(` config: Awaited<ReturnType<typeof startInstance.getOptions>>`);
|
|
29
|
+
result.push(` }
|
|
56
30
|
}`);
|
|
57
|
-
|
|
31
|
+
return result.join("\n");
|
|
58
32
|
}
|
|
59
33
|
function tanStackStartRouter(startPluginOpts, getConfig, corePluginOpts) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return {
|
|
181
|
-
...routerConfig,
|
|
182
|
-
codeSplittingOptions: {
|
|
183
|
-
...routerConfig.codeSplittingOptions,
|
|
184
|
-
deleteNodes: ["ssr", "server", "headers"],
|
|
185
|
-
addHmr: true
|
|
186
|
-
},
|
|
187
|
-
plugin: {
|
|
188
|
-
vite: { environmentName: VITE_ENVIRONMENT_NAMES.client }
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
}),
|
|
192
|
-
tanStackRouterCodeSplitter(() => {
|
|
193
|
-
const routerConfig = getConfig().startConfig.router;
|
|
194
|
-
return {
|
|
195
|
-
...routerConfig,
|
|
196
|
-
codeSplittingOptions: {
|
|
197
|
-
...routerConfig.codeSplittingOptions,
|
|
198
|
-
addHmr: false
|
|
199
|
-
},
|
|
200
|
-
plugin: {
|
|
201
|
-
vite: { environmentName: VITE_ENVIRONMENT_NAMES.server }
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
}),
|
|
205
|
-
tanstackRouterAutoImport(startPluginOpts?.router)
|
|
206
|
-
];
|
|
34
|
+
const getGeneratedRouteTreePath = () => {
|
|
35
|
+
const { startConfig } = getConfig();
|
|
36
|
+
return path.resolve(startConfig.router.generatedRouteTree);
|
|
37
|
+
};
|
|
38
|
+
let clientEnvironment = null;
|
|
39
|
+
function invalidate() {
|
|
40
|
+
if (!clientEnvironment) return;
|
|
41
|
+
const mod = clientEnvironment.moduleGraph.getModuleById(getGeneratedRouteTreePath());
|
|
42
|
+
if (mod) clientEnvironment.moduleGraph.invalidateModule(mod);
|
|
43
|
+
clientEnvironment.hot.send({
|
|
44
|
+
type: "full-reload",
|
|
45
|
+
path: "*"
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
let generatorInstance = null;
|
|
49
|
+
const clientTreeGeneratorPlugin = {
|
|
50
|
+
name: "start-client-tree-plugin",
|
|
51
|
+
init({ generator }) {
|
|
52
|
+
generatorInstance = generator;
|
|
53
|
+
},
|
|
54
|
+
afterTransform({ node, prevNode }) {
|
|
55
|
+
if (isServerOnlyNode(node) !== isServerOnlyNode(prevNode)) invalidate();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
let routeTreeFileFooter = null;
|
|
59
|
+
function getRouteTreeFileFooter() {
|
|
60
|
+
if (routeTreeFileFooter) return routeTreeFileFooter;
|
|
61
|
+
const { startConfig, resolvedStartConfig } = getConfig();
|
|
62
|
+
const ogRouteTreeFileFooter = startConfig.router.routeTreeFileFooter;
|
|
63
|
+
if (ogRouteTreeFileFooter) if (Array.isArray(ogRouteTreeFileFooter)) routeTreeFileFooter = ogRouteTreeFileFooter;
|
|
64
|
+
else routeTreeFileFooter = ogRouteTreeFileFooter();
|
|
65
|
+
routeTreeFileFooter = [moduleDeclaration({
|
|
66
|
+
generatedRouteTreePath: getGeneratedRouteTreePath(),
|
|
67
|
+
corePluginOpts,
|
|
68
|
+
startFilePath: resolvedStartConfig.startFilePath,
|
|
69
|
+
routerFilePath: resolvedStartConfig.routerFilePath
|
|
70
|
+
}), ...routeTreeFileFooter ?? []];
|
|
71
|
+
return routeTreeFileFooter;
|
|
72
|
+
}
|
|
73
|
+
let resolvedGeneratedRouteTreePath = null;
|
|
74
|
+
const clientTreePlugin = {
|
|
75
|
+
name: "tanstack-start:route-tree-client-plugin",
|
|
76
|
+
enforce: "pre",
|
|
77
|
+
applyToEnvironment: (env) => env.name === VITE_ENVIRONMENT_NAMES.client,
|
|
78
|
+
configureServer(server) {
|
|
79
|
+
clientEnvironment = server.environments[VITE_ENVIRONMENT_NAMES.client];
|
|
80
|
+
},
|
|
81
|
+
config() {
|
|
82
|
+
resolvedGeneratedRouteTreePath = normalizePath(getGeneratedRouteTreePath());
|
|
83
|
+
clientTreePlugin.load.filter = { id: { include: new RegExp(resolvedGeneratedRouteTreePath) } };
|
|
84
|
+
},
|
|
85
|
+
load: {
|
|
86
|
+
filter: {},
|
|
87
|
+
async handler() {
|
|
88
|
+
if (!generatorInstance) throw new Error("Generator instance not initialized");
|
|
89
|
+
const crawlingResult = await generatorInstance.getCrawlingResult();
|
|
90
|
+
if (!crawlingResult) throw new Error("Crawling result not available");
|
|
91
|
+
const prunedAcc = pruneServerOnlySubtrees(crawlingResult);
|
|
92
|
+
const acc = {
|
|
93
|
+
...crawlingResult.acc,
|
|
94
|
+
...prunedAcc
|
|
95
|
+
};
|
|
96
|
+
return {
|
|
97
|
+
code: generatorInstance.buildRouteTree({
|
|
98
|
+
...crawlingResult,
|
|
99
|
+
acc,
|
|
100
|
+
config: {
|
|
101
|
+
disableTypes: true,
|
|
102
|
+
enableRouteTreeFormatting: false,
|
|
103
|
+
routeTreeFileHeader: [],
|
|
104
|
+
routeTreeFileFooter: []
|
|
105
|
+
}
|
|
106
|
+
}).routeTreeContent,
|
|
107
|
+
map: null
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
return [
|
|
113
|
+
clientTreePlugin,
|
|
114
|
+
tanstackRouterGenerator(() => {
|
|
115
|
+
const routerConfig = getConfig().startConfig.router;
|
|
116
|
+
const plugins = [clientTreeGeneratorPlugin, routesManifestPlugin()];
|
|
117
|
+
if (startPluginOpts?.prerender?.enabled === true) plugins.push(prerenderRoutesPlugin());
|
|
118
|
+
return {
|
|
119
|
+
...routerConfig,
|
|
120
|
+
target: corePluginOpts.framework,
|
|
121
|
+
routeTreeFileFooter: getRouteTreeFileFooter,
|
|
122
|
+
plugins
|
|
123
|
+
};
|
|
124
|
+
}),
|
|
125
|
+
tanStackRouterCodeSplitter(() => {
|
|
126
|
+
const routerConfig = getConfig().startConfig.router;
|
|
127
|
+
return {
|
|
128
|
+
...routerConfig,
|
|
129
|
+
codeSplittingOptions: {
|
|
130
|
+
...routerConfig.codeSplittingOptions,
|
|
131
|
+
deleteNodes: [
|
|
132
|
+
"ssr",
|
|
133
|
+
"server",
|
|
134
|
+
"headers"
|
|
135
|
+
],
|
|
136
|
+
addHmr: true
|
|
137
|
+
},
|
|
138
|
+
plugin: { vite: { environmentName: VITE_ENVIRONMENT_NAMES.client } }
|
|
139
|
+
};
|
|
140
|
+
}),
|
|
141
|
+
tanStackRouterCodeSplitter(() => {
|
|
142
|
+
const routerConfig = getConfig().startConfig.router;
|
|
143
|
+
return {
|
|
144
|
+
...routerConfig,
|
|
145
|
+
codeSplittingOptions: {
|
|
146
|
+
...routerConfig.codeSplittingOptions,
|
|
147
|
+
addHmr: false
|
|
148
|
+
},
|
|
149
|
+
plugin: { vite: { environmentName: VITE_ENVIRONMENT_NAMES.server } }
|
|
150
|
+
};
|
|
151
|
+
}),
|
|
152
|
+
tanstackRouterAutoImport(startPluginOpts?.router)
|
|
153
|
+
];
|
|
207
154
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
//# sourceMappingURL=plugin.js.map
|
|
155
|
+
//#endregion
|
|
156
|
+
export { tanStackStartRouter };
|
|
157
|
+
|
|
158
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["../../../src/start-router-plugin/plugin.ts"],"sourcesContent":["import {\n tanStackRouterCodeSplitter,\n tanstackRouterAutoImport,\n tanstackRouterGenerator,\n} from '@tanstack/router-plugin/vite'\nimport { normalizePath } from 'vite'\nimport path from 'pathe'\nimport { VITE_ENVIRONMENT_NAMES } from '../constants'\nimport { routesManifestPlugin } from './generator-plugins/routes-manifest-plugin'\nimport { prerenderRoutesPlugin } from './generator-plugins/prerender-routes-plugin'\nimport { pruneServerOnlySubtrees } from './pruneServerOnlySubtrees'\nimport { SERVER_PROP } from './constants'\nimport type { GetConfigFn, TanStackStartVitePluginCoreOptions } from '../types'\nimport type {\n Generator,\n GeneratorPlugin,\n RouteNode,\n} from '@tanstack/router-generator'\nimport type { DevEnvironment, Plugin, PluginOption } from 'vite'\nimport type { TanStackStartInputConfig } from '../schema'\n\nfunction isServerOnlyNode(node: RouteNode | undefined) {\n if (!node?.createFileRouteProps) {\n return false\n }\n return (\n node.createFileRouteProps.has(SERVER_PROP) &&\n node.createFileRouteProps.size === 1\n )\n}\n\nfunction moduleDeclaration({\n startFilePath,\n routerFilePath,\n corePluginOpts,\n generatedRouteTreePath,\n}: {\n startFilePath: string | undefined\n routerFilePath: string\n corePluginOpts: TanStackStartVitePluginCoreOptions\n generatedRouteTreePath: string\n}): string {\n function getImportPath(absolutePath: string) {\n let relativePath = path.relative(\n path.dirname(generatedRouteTreePath),\n absolutePath,\n )\n\n if (!relativePath.startsWith('.')) {\n relativePath = './' + relativePath\n }\n\n // convert to POSIX-style for ESM imports (important on Windows)\n relativePath = relativePath.split(path.sep).join('/')\n return relativePath\n }\n\n const result: Array<string> = [\n `import type { getRouter } from '${getImportPath(routerFilePath)}'`,\n ]\n if (startFilePath) {\n result.push(\n `import type { startInstance } from '${getImportPath(startFilePath)}'`,\n )\n }\n // make sure we import something from start to get the server route declaration merge\n else {\n result.push(\n `import type { createStart } from '@tanstack/${corePluginOpts.framework}-start'`,\n )\n }\n result.push(\n `declare module '@tanstack/${corePluginOpts.framework}-start' {\n interface Register {\n ssr: true\n router: Awaited<ReturnType<typeof getRouter>>`,\n )\n if (startFilePath) {\n result.push(\n ` config: Awaited<ReturnType<typeof startInstance.getOptions>>`,\n )\n }\n result.push(` }\n}`)\n\n return result.join('\\n')\n}\n\nexport function tanStackStartRouter(\n startPluginOpts: TanStackStartInputConfig,\n getConfig: GetConfigFn,\n corePluginOpts: TanStackStartVitePluginCoreOptions,\n): Array<PluginOption> {\n const getGeneratedRouteTreePath = () => {\n const { startConfig } = getConfig()\n return path.resolve(startConfig.router.generatedRouteTree)\n }\n\n let clientEnvironment: DevEnvironment | null = null\n function invalidate() {\n if (!clientEnvironment) {\n return\n }\n\n const mod = clientEnvironment.moduleGraph.getModuleById(\n getGeneratedRouteTreePath(),\n )\n if (mod) {\n clientEnvironment.moduleGraph.invalidateModule(mod)\n }\n clientEnvironment.hot.send({ type: 'full-reload', path: '*' })\n }\n\n let generatorInstance: Generator | null = null\n\n const clientTreeGeneratorPlugin: GeneratorPlugin = {\n name: 'start-client-tree-plugin',\n init({ generator }) {\n generatorInstance = generator\n },\n afterTransform({ node, prevNode }) {\n if (isServerOnlyNode(node) !== isServerOnlyNode(prevNode)) {\n invalidate()\n }\n },\n }\n\n let routeTreeFileFooter: Array<string> | null = null\n\n function getRouteTreeFileFooter() {\n if (routeTreeFileFooter) {\n return routeTreeFileFooter\n }\n const { startConfig, resolvedStartConfig } = getConfig()\n const ogRouteTreeFileFooter = startConfig.router.routeTreeFileFooter\n if (ogRouteTreeFileFooter) {\n if (Array.isArray(ogRouteTreeFileFooter)) {\n routeTreeFileFooter = ogRouteTreeFileFooter\n } else {\n routeTreeFileFooter = ogRouteTreeFileFooter()\n }\n }\n routeTreeFileFooter = [\n moduleDeclaration({\n generatedRouteTreePath: getGeneratedRouteTreePath(),\n corePluginOpts,\n startFilePath: resolvedStartConfig.startFilePath,\n routerFilePath: resolvedStartConfig.routerFilePath,\n }),\n ...(routeTreeFileFooter ?? []),\n ]\n return routeTreeFileFooter\n }\n\n let resolvedGeneratedRouteTreePath: string | null = null\n const clientTreePlugin: Plugin = {\n name: 'tanstack-start:route-tree-client-plugin',\n enforce: 'pre',\n applyToEnvironment: (env) => env.name === VITE_ENVIRONMENT_NAMES.client,\n configureServer(server) {\n clientEnvironment = server.environments[VITE_ENVIRONMENT_NAMES.client]\n },\n config() {\n type LoadObjectHook = Extract<\n typeof clientTreePlugin.load,\n { filter?: unknown }\n >\n resolvedGeneratedRouteTreePath = normalizePath(\n getGeneratedRouteTreePath(),\n )\n ;(clientTreePlugin.load as LoadObjectHook).filter = {\n id: { include: new RegExp(resolvedGeneratedRouteTreePath) },\n }\n },\n\n load: {\n filter: {\n // this will be set in the config hook above since it relies on `config` hook being called first\n },\n async handler() {\n if (!generatorInstance) {\n throw new Error('Generator instance not initialized')\n }\n const crawlingResult = await generatorInstance.getCrawlingResult()\n if (!crawlingResult) {\n throw new Error('Crawling result not available')\n }\n const prunedAcc = pruneServerOnlySubtrees(crawlingResult)\n const acc = {\n ...crawlingResult.acc,\n ...prunedAcc,\n }\n const buildResult = generatorInstance.buildRouteTree({\n ...crawlingResult,\n acc,\n config: {\n // importRoutesUsingAbsolutePaths: true,\n // addExtensions: true,\n disableTypes: true,\n enableRouteTreeFormatting: false,\n routeTreeFileHeader: [],\n routeTreeFileFooter: [],\n },\n })\n return { code: buildResult.routeTreeContent, map: null }\n },\n },\n }\n return [\n clientTreePlugin,\n tanstackRouterGenerator(() => {\n const routerConfig = getConfig().startConfig.router\n const plugins = [clientTreeGeneratorPlugin, routesManifestPlugin()]\n if (startPluginOpts?.prerender?.enabled === true) {\n plugins.push(prerenderRoutesPlugin())\n }\n return {\n ...routerConfig,\n target: corePluginOpts.framework,\n routeTreeFileFooter: getRouteTreeFileFooter,\n plugins,\n }\n }),\n tanStackRouterCodeSplitter(() => {\n const routerConfig = getConfig().startConfig.router\n return {\n ...routerConfig,\n codeSplittingOptions: {\n ...routerConfig.codeSplittingOptions,\n deleteNodes: ['ssr', 'server', 'headers'],\n addHmr: true,\n },\n plugin: {\n vite: { environmentName: VITE_ENVIRONMENT_NAMES.client },\n },\n }\n }),\n tanStackRouterCodeSplitter(() => {\n const routerConfig = getConfig().startConfig.router\n return {\n ...routerConfig,\n codeSplittingOptions: {\n ...routerConfig.codeSplittingOptions,\n addHmr: false,\n },\n plugin: {\n vite: { environmentName: VITE_ENVIRONMENT_NAMES.server },\n },\n }\n }),\n tanstackRouterAutoImport(startPluginOpts?.router),\n ]\n}\n"],"names":["path"],"mappings":";;;;;;;;AAqBA,SAAS,iBAAiB,MAA6B;AACrD,MAAI,CAAC,MAAM,sBAAsB;AAC/B,WAAO;AAAA,EACT;AACA,SACE,KAAK,qBAAqB,IAAI,WAAW,KACzC,KAAK,qBAAqB,SAAS;AAEvC;AAEA,SAAS,kBAAkB;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKW;AACT,WAAS,cAAc,cAAsB;AAC3C,QAAI,eAAeA,cAAK;AAAA,MACtBA,cAAK,QAAQ,sBAAsB;AAAA,MACnC;AAAA,IAAA;AAGF,QAAI,CAAC,aAAa,WAAW,GAAG,GAAG;AACjC,qBAAe,OAAO;AAAA,IACxB;AAGA,mBAAe,aAAa,MAAMA,cAAK,GAAG,EAAE,KAAK,GAAG;AACp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.js","names":[],"sources":["../../../src/start-router-plugin/plugin.ts"],"sourcesContent":["import {\n tanStackRouterCodeSplitter,\n tanstackRouterAutoImport,\n tanstackRouterGenerator,\n} from '@tanstack/router-plugin/vite'\nimport { normalizePath } from 'vite'\nimport path from 'pathe'\nimport { VITE_ENVIRONMENT_NAMES } from '../constants'\nimport { routesManifestPlugin } from './generator-plugins/routes-manifest-plugin'\nimport { prerenderRoutesPlugin } from './generator-plugins/prerender-routes-plugin'\nimport { pruneServerOnlySubtrees } from './pruneServerOnlySubtrees'\nimport { SERVER_PROP } from './constants'\nimport type { GetConfigFn, TanStackStartVitePluginCoreOptions } from '../types'\nimport type {\n Generator,\n GeneratorPlugin,\n RouteNode,\n} from '@tanstack/router-generator'\nimport type { DevEnvironment, Plugin, PluginOption } from 'vite'\nimport type { TanStackStartInputConfig } from '../schema'\n\nfunction isServerOnlyNode(node: RouteNode | undefined) {\n if (!node?.createFileRouteProps) {\n return false\n }\n return (\n node.createFileRouteProps.has(SERVER_PROP) &&\n node.createFileRouteProps.size === 1\n )\n}\n\nfunction moduleDeclaration({\n startFilePath,\n routerFilePath,\n corePluginOpts,\n generatedRouteTreePath,\n}: {\n startFilePath: string | undefined\n routerFilePath: string\n corePluginOpts: TanStackStartVitePluginCoreOptions\n generatedRouteTreePath: string\n}): string {\n function getImportPath(absolutePath: string) {\n let relativePath = path.relative(\n path.dirname(generatedRouteTreePath),\n absolutePath,\n )\n\n if (!relativePath.startsWith('.')) {\n relativePath = './' + relativePath\n }\n\n // convert to POSIX-style for ESM imports (important on Windows)\n relativePath = relativePath.split(path.sep).join('/')\n return relativePath\n }\n\n const result: Array<string> = [\n `import type { getRouter } from '${getImportPath(routerFilePath)}'`,\n ]\n if (startFilePath) {\n result.push(\n `import type { startInstance } from '${getImportPath(startFilePath)}'`,\n )\n }\n // make sure we import something from start to get the server route declaration merge\n else {\n result.push(\n `import type { createStart } from '@tanstack/${corePluginOpts.framework}-start'`,\n )\n }\n result.push(\n `declare module '@tanstack/${corePluginOpts.framework}-start' {\n interface Register {\n ssr: true\n router: Awaited<ReturnType<typeof getRouter>>`,\n )\n if (startFilePath) {\n result.push(\n ` config: Awaited<ReturnType<typeof startInstance.getOptions>>`,\n )\n }\n result.push(` }\n}`)\n\n return result.join('\\n')\n}\n\nexport function tanStackStartRouter(\n startPluginOpts: TanStackStartInputConfig,\n getConfig: GetConfigFn,\n corePluginOpts: TanStackStartVitePluginCoreOptions,\n): Array<PluginOption> {\n const getGeneratedRouteTreePath = () => {\n const { startConfig } = getConfig()\n return path.resolve(startConfig.router.generatedRouteTree)\n }\n\n let clientEnvironment: DevEnvironment | null = null\n function invalidate() {\n if (!clientEnvironment) {\n return\n }\n\n const mod = clientEnvironment.moduleGraph.getModuleById(\n getGeneratedRouteTreePath(),\n )\n if (mod) {\n clientEnvironment.moduleGraph.invalidateModule(mod)\n }\n clientEnvironment.hot.send({ type: 'full-reload', path: '*' })\n }\n\n let generatorInstance: Generator | null = null\n\n const clientTreeGeneratorPlugin: GeneratorPlugin = {\n name: 'start-client-tree-plugin',\n init({ generator }) {\n generatorInstance = generator\n },\n afterTransform({ node, prevNode }) {\n if (isServerOnlyNode(node) !== isServerOnlyNode(prevNode)) {\n invalidate()\n }\n },\n }\n\n let routeTreeFileFooter: Array<string> | null = null\n\n function getRouteTreeFileFooter() {\n if (routeTreeFileFooter) {\n return routeTreeFileFooter\n }\n const { startConfig, resolvedStartConfig } = getConfig()\n const ogRouteTreeFileFooter = startConfig.router.routeTreeFileFooter\n if (ogRouteTreeFileFooter) {\n if (Array.isArray(ogRouteTreeFileFooter)) {\n routeTreeFileFooter = ogRouteTreeFileFooter\n } else {\n routeTreeFileFooter = ogRouteTreeFileFooter()\n }\n }\n routeTreeFileFooter = [\n moduleDeclaration({\n generatedRouteTreePath: getGeneratedRouteTreePath(),\n corePluginOpts,\n startFilePath: resolvedStartConfig.startFilePath,\n routerFilePath: resolvedStartConfig.routerFilePath,\n }),\n ...(routeTreeFileFooter ?? []),\n ]\n return routeTreeFileFooter\n }\n\n let resolvedGeneratedRouteTreePath: string | null = null\n const clientTreePlugin: Plugin = {\n name: 'tanstack-start:route-tree-client-plugin',\n enforce: 'pre',\n applyToEnvironment: (env) => env.name === VITE_ENVIRONMENT_NAMES.client,\n configureServer(server) {\n clientEnvironment = server.environments[VITE_ENVIRONMENT_NAMES.client]\n },\n config() {\n type LoadObjectHook = Extract<\n typeof clientTreePlugin.load,\n { filter?: unknown }\n >\n resolvedGeneratedRouteTreePath = normalizePath(\n getGeneratedRouteTreePath(),\n )\n ;(clientTreePlugin.load as LoadObjectHook).filter = {\n id: { include: new RegExp(resolvedGeneratedRouteTreePath) },\n }\n },\n\n load: {\n filter: {\n // this will be set in the config hook above since it relies on `config` hook being called first\n },\n async handler() {\n if (!generatorInstance) {\n throw new Error('Generator instance not initialized')\n }\n const crawlingResult = await generatorInstance.getCrawlingResult()\n if (!crawlingResult) {\n throw new Error('Crawling result not available')\n }\n const prunedAcc = pruneServerOnlySubtrees(crawlingResult)\n const acc = {\n ...crawlingResult.acc,\n ...prunedAcc,\n }\n const buildResult = generatorInstance.buildRouteTree({\n ...crawlingResult,\n acc,\n config: {\n // importRoutesUsingAbsolutePaths: true,\n // addExtensions: true,\n disableTypes: true,\n enableRouteTreeFormatting: false,\n routeTreeFileHeader: [],\n routeTreeFileFooter: [],\n },\n })\n return { code: buildResult.routeTreeContent, map: null }\n },\n },\n }\n return [\n clientTreePlugin,\n tanstackRouterGenerator(() => {\n const routerConfig = getConfig().startConfig.router\n const plugins = [clientTreeGeneratorPlugin, routesManifestPlugin()]\n if (startPluginOpts?.prerender?.enabled === true) {\n plugins.push(prerenderRoutesPlugin())\n }\n return {\n ...routerConfig,\n target: corePluginOpts.framework,\n routeTreeFileFooter: getRouteTreeFileFooter,\n plugins,\n }\n }),\n tanStackRouterCodeSplitter(() => {\n const routerConfig = getConfig().startConfig.router\n return {\n ...routerConfig,\n codeSplittingOptions: {\n ...routerConfig.codeSplittingOptions,\n deleteNodes: ['ssr', 'server', 'headers'],\n addHmr: true,\n },\n plugin: {\n vite: { environmentName: VITE_ENVIRONMENT_NAMES.client },\n },\n }\n }),\n tanStackRouterCodeSplitter(() => {\n const routerConfig = getConfig().startConfig.router\n return {\n ...routerConfig,\n codeSplittingOptions: {\n ...routerConfig.codeSplittingOptions,\n addHmr: false,\n },\n plugin: {\n vite: { environmentName: VITE_ENVIRONMENT_NAMES.server },\n },\n }\n }),\n tanstackRouterAutoImport(startPluginOpts?.router),\n ]\n}\n"],"mappings":";;;;;;;;;AAqBA,SAAS,iBAAiB,MAA6B;AACrD,KAAI,CAAC,MAAM,qBACT,QAAO;AAET,QACE,KAAK,qBAAqB,IAAA,SAAgB,IAC1C,KAAK,qBAAqB,SAAS;;AAIvC,SAAS,kBAAkB,EACzB,eACA,gBACA,gBACA,0BAMS;CACT,SAAS,cAAc,cAAsB;EAC3C,IAAI,eAAe,KAAK,SACtB,KAAK,QAAQ,uBAAuB,EACpC,aACD;AAED,MAAI,CAAC,aAAa,WAAW,IAAI,CAC/B,gBAAe,OAAO;AAIxB,iBAAe,aAAa,MAAM,KAAK,IAAI,CAAC,KAAK,IAAI;AACrD,SAAO;;CAGT,MAAM,SAAwB,CAC5B,mCAAmC,cAAc,eAAe,CAAC,GAClE;AACD,KAAI,cACF,QAAO,KACL,uCAAuC,cAAc,cAAc,CAAC,GACrE;KAID,QAAO,KACL,+CAA+C,eAAe,UAAU,SACzE;AAEH,QAAO,KACL,6BAA6B,eAAe,UAAU;;;mDAIvD;AACD,KAAI,cACF,QAAO,KACL,mEACD;AAEH,QAAO,KAAK;GACX;AAED,QAAO,OAAO,KAAK,KAAK;;AAG1B,SAAgB,oBACd,iBACA,WACA,gBACqB;CACrB,MAAM,kCAAkC;EACtC,MAAM,EAAE,gBAAgB,WAAW;AACnC,SAAO,KAAK,QAAQ,YAAY,OAAO,mBAAmB;;CAG5D,IAAI,oBAA2C;CAC/C,SAAS,aAAa;AACpB,MAAI,CAAC,kBACH;EAG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AAY,wBAAwB,eAAe;IACzD,MAAM,MAAM;KACV,GAAG,eAAe;KAClB,GAAG;KACJ;AAaD,WAAO;KAAE,MAZW,kBAAkB,eAAe;MACnD,GAAG;MACH;MACA,QAAQ;OAGN,cAAc;OACd,2BAA2B;OAC3B,qBAAqB,EAAE;OACvB,qBAAqB,EAAE;OACxB;MACF,CAAC,CACyB;KAAkB,KAAK;KAAM;;GAE3D;EACF;AACD,QAAO;EACL;EACA,8BAA8B;GAC5B,MAAM,eAAe,WAAW,CAAC,YAAY;GAC7C,MAAM,UAAU,CAAC,2BAA2B,sBAAsB,CAAC;AACnE,OAAI,iBAAiB,WAAW,YAAY,KAC1C,SAAQ,KAAK,uBAAuB,CAAC;AAEvC,UAAO;IACL,GAAG;IACH,QAAQ,eAAe;IACvB,qBAAqB;IACrB;IACD;IACD;EACF,iCAAiC;GAC/B,MAAM,eAAe,WAAW,CAAC,YAAY;AAC7C,UAAO;IACL,GAAG;IACH,sBAAsB;KACpB,GAAG,aAAa;KAChB,aAAa;MAAC;MAAO;MAAU;MAAU;KACzC,QAAQ;KACT;IACD,QAAQ,EACN,MAAM,EAAE,iBAAiB,uBAAuB,QAAQ,EACzD;IACF;IACD;EACF,iCAAiC;GAC/B,MAAM,eAAe,WAAW,CAAC,YAAY;AAC7C,UAAO;IACL,GAAG;IACH,sBAAsB;KACpB,GAAG,aAAa;KAChB,QAAQ;KACT;IACD,QAAQ,EACN,MAAM,EAAE,iBAAiB,uBAAuB,QAAQ,EACzD;IACF;IACD;EACF,yBAAyB,iBAAiB,OAAO;EAClD"}
|
|
@@ -1,34 +1,35 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import "./constants.js";
|
|
2
|
+
//#region src/start-router-plugin/pruneServerOnlySubtrees.ts
|
|
3
|
+
function pruneServerOnlySubtrees({ rootRouteNode, acc }) {
|
|
4
|
+
const routeNodes = [];
|
|
5
|
+
const routeTree = prune({
|
|
6
|
+
...rootRouteNode,
|
|
7
|
+
children: acc.routeTree
|
|
8
|
+
}, routeNodes)?.children || [];
|
|
9
|
+
routeNodes.pop();
|
|
10
|
+
return {
|
|
11
|
+
routeTree,
|
|
12
|
+
routeNodes
|
|
13
|
+
};
|
|
13
14
|
}
|
|
14
15
|
function prune(node, collectedRouteNodes) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
16
|
+
const newChildren = [];
|
|
17
|
+
let allChildrenServerOnly = true;
|
|
18
|
+
for (const child of node.children || []) {
|
|
19
|
+
const newChild = prune(child, collectedRouteNodes);
|
|
20
|
+
if (newChild) {
|
|
21
|
+
newChildren.push(newChild);
|
|
22
|
+
allChildrenServerOnly = false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (node.createFileRouteProps?.has("server") && node.createFileRouteProps.size === 1 && allChildrenServerOnly) return null;
|
|
26
|
+
collectedRouteNodes.push(node);
|
|
27
|
+
return {
|
|
28
|
+
...node,
|
|
29
|
+
children: newChildren
|
|
30
|
+
};
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
//# sourceMappingURL=pruneServerOnlySubtrees.js.map
|
|
32
|
+
//#endregion
|
|
33
|
+
export { pruneServerOnlySubtrees };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=pruneServerOnlySubtrees.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pruneServerOnlySubtrees.js","sources":["../../../src/start-router-plugin/pruneServerOnlySubtrees.ts"],"sourcesContent":["import { SERVER_PROP } from './constants'\nimport type {\n HandleNodeAccumulator,\n RouteNode,\n} from '@tanstack/router-generator'\n\nexport function pruneServerOnlySubtrees({\n rootRouteNode,\n acc,\n}: {\n rootRouteNode: RouteNode\n acc: HandleNodeAccumulator\n}) {\n const routeNodes: Array<RouteNode> = []\n const routeTree =\n prune({ ...rootRouteNode, children: acc.routeTree }, routeNodes)\n ?.children || []\n // remove root node from routeNodes\n routeNodes.pop()\n return {\n routeTree,\n routeNodes,\n }\n}\nfunction prune(\n node: RouteNode,\n collectedRouteNodes: Array<RouteNode>,\n): RouteNode | null {\n const newChildren: Array<RouteNode> = []\n let allChildrenServerOnly = true\n\n for (const child of node.children || []) {\n const newChild = prune(child, collectedRouteNodes)\n if (newChild) {\n newChildren.push(newChild)\n // at least one child survived pruning\n allChildrenServerOnly = false\n }\n }\n\n const allServerOnly =\n node.createFileRouteProps?.has(SERVER_PROP) &&\n node.createFileRouteProps.size === 1 &&\n allChildrenServerOnly\n // prune this subtree\n if (allServerOnly) {\n return null\n }\n collectedRouteNodes.push(node)\n return { ...node, children: newChildren }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"pruneServerOnlySubtrees.js","names":[],"sources":["../../../src/start-router-plugin/pruneServerOnlySubtrees.ts"],"sourcesContent":["import { SERVER_PROP } from './constants'\nimport type {\n HandleNodeAccumulator,\n RouteNode,\n} from '@tanstack/router-generator'\n\nexport function pruneServerOnlySubtrees({\n rootRouteNode,\n acc,\n}: {\n rootRouteNode: RouteNode\n acc: HandleNodeAccumulator\n}) {\n const routeNodes: Array<RouteNode> = []\n const routeTree =\n prune({ ...rootRouteNode, children: acc.routeTree }, routeNodes)\n ?.children || []\n // remove root node from routeNodes\n routeNodes.pop()\n return {\n routeTree,\n routeNodes,\n }\n}\nfunction prune(\n node: RouteNode,\n collectedRouteNodes: Array<RouteNode>,\n): RouteNode | null {\n const newChildren: Array<RouteNode> = []\n let allChildrenServerOnly = true\n\n for (const child of node.children || []) {\n const newChild = prune(child, collectedRouteNodes)\n if (newChild) {\n newChildren.push(newChild)\n // at least one child survived pruning\n allChildrenServerOnly = false\n }\n }\n\n const allServerOnly =\n node.createFileRouteProps?.has(SERVER_PROP) &&\n node.createFileRouteProps.size === 1 &&\n allChildrenServerOnly\n // prune this subtree\n if (allServerOnly) {\n return null\n }\n collectedRouteNodes.push(node)\n return { ...node, children: newChildren }\n}\n"],"mappings":";;AAMA,SAAgB,wBAAwB,EACtC,eACA,OAIC;CACD,MAAM,aAA+B,EAAE;CACvC,MAAM,YACJ,MAAM;EAAE,GAAG;EAAe,UAAU,IAAI;EAAW,EAAE,WAAW,EAC5D,YAAY,EAAE;AAEpB,YAAW,KAAK;AAChB,QAAO;EACL;EACA;EACD;;AAEH,SAAS,MACP,MACA,qBACkB;CAClB,MAAM,cAAgC,EAAE;CACxC,IAAI,wBAAwB;AAE5B,MAAK,MAAM,SAAS,KAAK,YAAY,EAAE,EAAE;EACvC,MAAM,WAAW,MAAM,OAAO,oBAAoB;AAClD,MAAI,UAAU;AACZ,eAAY,KAAK,SAAS;AAE1B,2BAAwB;;;AAS5B,KAJE,KAAK,sBAAsB,IAAA,SAAgB,IAC3C,KAAK,qBAAqB,SAAS,KACnC,sBAGA,QAAO;AAET,qBAAoB,KAAK,KAAK;AAC9B,QAAO;EAAE,GAAG;EAAM,UAAU;EAAa"}
|
package/dist/esm/utils.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
+
//#region src/utils.ts
|
|
1
2
|
function resolveViteId(id) {
|
|
2
|
-
|
|
3
|
+
return `\0${id}`;
|
|
3
4
|
}
|
|
4
5
|
function createLogger(prefix) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
const label = `[${prefix}]`;
|
|
7
|
+
return {
|
|
8
|
+
log: (...args) => console.log(label, ...args),
|
|
9
|
+
debug: (...args) => console.debug(label, ...args),
|
|
10
|
+
info: (...args) => console.info(label, ...args),
|
|
11
|
+
warn: (...args) => console.warn(label, ...args),
|
|
12
|
+
error: (...args) => console.error(label, ...args)
|
|
13
|
+
};
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
//# sourceMappingURL=utils.js.map
|
|
15
|
+
//#endregion
|
|
16
|
+
export { createLogger, resolveViteId };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=utils.js.map
|
package/dist/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["export function resolveViteId(id: string) {\n return `\\0${id}`\n}\n\nexport function createLogger(prefix: string) {\n const label = `[${prefix}]`\n return {\n log: (...args: any) => console.log(label, ...args),\n debug: (...args: any) => console.debug(label, ...args),\n info: (...args: any) => console.info(label, ...args),\n warn: (...args: any) => console.warn(label, ...args),\n error: (...args: any) => console.error(label, ...args),\n }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["export function resolveViteId(id: string) {\n return `\\0${id}`\n}\n\nexport function createLogger(prefix: string) {\n const label = `[${prefix}]`\n return {\n log: (...args: any) => console.log(label, ...args),\n debug: (...args: any) => console.debug(label, ...args),\n info: (...args: any) => console.info(label, ...args),\n warn: (...args: any) => console.warn(label, ...args),\n error: (...args: any) => console.error(label, ...args),\n }\n}\n"],"mappings":";AAAA,SAAgB,cAAc,IAAY;AACxC,QAAO,KAAK;;AAGd,SAAgB,aAAa,QAAgB;CAC3C,MAAM,QAAQ,IAAI,OAAO;AACzB,QAAO;EACL,MAAM,GAAG,SAAc,QAAQ,IAAI,OAAO,GAAG,KAAK;EAClD,QAAQ,GAAG,SAAc,QAAQ,MAAM,OAAO,GAAG,KAAK;EACtD,OAAO,GAAG,SAAc,QAAQ,KAAK,OAAO,GAAG,KAAK;EACpD,OAAO,GAAG,SAAc,QAAQ,KAAK,OAAO,GAAG,KAAK;EACpD,QAAQ,GAAG,SAAc,QAAQ,MAAM,OAAO,GAAG,KAAK;EACvD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/start-plugin-core",
|
|
3
|
-
"version": "1.166.
|
|
3
|
+
"version": "1.166.13",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -60,12 +60,12 @@
|
|
|
60
60
|
"vitefu": "^1.1.1",
|
|
61
61
|
"xmlbuilder2": "^4.0.3",
|
|
62
62
|
"zod": "^3.24.2",
|
|
63
|
-
"@tanstack/router-core": "1.167.
|
|
64
|
-
"@tanstack/router-generator": "1.166.
|
|
65
|
-
"@tanstack/router-plugin": "1.166.
|
|
66
|
-
"@tanstack/router-utils": "1.161.
|
|
67
|
-
"@tanstack/start-client-core": "1.166.
|
|
68
|
-
"@tanstack/start-server-core": "1.166.
|
|
63
|
+
"@tanstack/router-core": "1.167.2",
|
|
64
|
+
"@tanstack/router-generator": "1.166.10",
|
|
65
|
+
"@tanstack/router-plugin": "1.166.11",
|
|
66
|
+
"@tanstack/router-utils": "1.161.6",
|
|
67
|
+
"@tanstack/start-client-core": "1.166.10",
|
|
68
|
+
"@tanstack/start-server-core": "1.166.10"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@types/babel__code-frame": "^7.0.6",
|
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|