@tanstack/router-plugin 1.39.2

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.
Files changed (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/dist/cjs/ast.cjs +51 -0
  4. package/dist/cjs/ast.cjs.map +1 -0
  5. package/dist/cjs/ast.d.cts +22 -0
  6. package/dist/cjs/code-splitter.cjs +157 -0
  7. package/dist/cjs/code-splitter.cjs.map +1 -0
  8. package/dist/cjs/code-splitter.d.cts +22 -0
  9. package/dist/cjs/compilers.cjs +327 -0
  10. package/dist/cjs/compilers.cjs.map +1 -0
  11. package/dist/cjs/compilers.d.cts +18 -0
  12. package/dist/cjs/config.cjs +16 -0
  13. package/dist/cjs/config.cjs.map +1 -0
  14. package/dist/cjs/config.d.cts +79 -0
  15. package/dist/cjs/constants.cjs +7 -0
  16. package/dist/cjs/constants.cjs.map +1 -0
  17. package/dist/cjs/constants.d.cts +2 -0
  18. package/dist/cjs/eliminateUnreferencedIdentifiers.cjs +149 -0
  19. package/dist/cjs/eliminateUnreferencedIdentifiers.cjs.map +1 -0
  20. package/dist/cjs/eliminateUnreferencedIdentifiers.d.cts +9 -0
  21. package/dist/cjs/index.cjs +7 -0
  22. package/dist/cjs/index.cjs.map +1 -0
  23. package/dist/cjs/index.d.cts +2 -0
  24. package/dist/cjs/router-generator.cjs +67 -0
  25. package/dist/cjs/router-generator.cjs.map +1 -0
  26. package/dist/cjs/router-generator.d.cts +18 -0
  27. package/dist/cjs/vite.cjs +16 -0
  28. package/dist/cjs/vite.cjs.map +1 -0
  29. package/dist/cjs/vite.d.cts +41 -0
  30. package/dist/esm/ast.d.ts +22 -0
  31. package/dist/esm/ast.js +34 -0
  32. package/dist/esm/ast.js.map +1 -0
  33. package/dist/esm/code-splitter.d.ts +22 -0
  34. package/dist/esm/code-splitter.js +157 -0
  35. package/dist/esm/code-splitter.js.map +1 -0
  36. package/dist/esm/compilers.d.ts +18 -0
  37. package/dist/esm/compilers.js +309 -0
  38. package/dist/esm/compilers.js.map +1 -0
  39. package/dist/esm/config.d.ts +79 -0
  40. package/dist/esm/config.js +16 -0
  41. package/dist/esm/config.js.map +1 -0
  42. package/dist/esm/constants.d.ts +2 -0
  43. package/dist/esm/constants.js +7 -0
  44. package/dist/esm/constants.js.map +1 -0
  45. package/dist/esm/eliminateUnreferencedIdentifiers.d.ts +9 -0
  46. package/dist/esm/eliminateUnreferencedIdentifiers.js +132 -0
  47. package/dist/esm/eliminateUnreferencedIdentifiers.js.map +1 -0
  48. package/dist/esm/index.d.ts +2 -0
  49. package/dist/esm/index.js +7 -0
  50. package/dist/esm/index.js.map +1 -0
  51. package/dist/esm/router-generator.d.ts +18 -0
  52. package/dist/esm/router-generator.js +67 -0
  53. package/dist/esm/router-generator.js.map +1 -0
  54. package/dist/esm/vite.d.ts +41 -0
  55. package/dist/esm/vite.js +16 -0
  56. package/dist/esm/vite.js.map +1 -0
  57. package/package.json +88 -0
  58. package/src/ast.ts +49 -0
  59. package/src/code-splitter.ts +162 -0
  60. package/src/compilers.ts +414 -0
  61. package/src/config.ts +25 -0
  62. package/src/constants.ts +2 -0
  63. package/src/eliminateUnreferencedIdentifiers.ts +211 -0
  64. package/src/index.ts +2 -0
  65. package/src/router-generator.ts +92 -0
  66. package/src/vite.ts +19 -0
@@ -0,0 +1,157 @@
1
+ import { isAbsolute, join } from "node:path";
2
+ import { pathToFileURL, fileURLToPath } from "node:url";
3
+ import { createUnplugin } from "unplugin";
4
+ import { compileAst } from "./ast.js";
5
+ import { splitFile, compileFile } from "./compilers.js";
6
+ import { getConfig } from "./config.js";
7
+ import { splitPrefix } from "./constants.js";
8
+ function capitalizeFirst(str) {
9
+ return str.charAt(0).toUpperCase() + str.slice(1);
10
+ }
11
+ function fileIsInRoutesDirectory(filePath, routesDirectory) {
12
+ const routesDirectoryPath = isAbsolute(routesDirectory) ? routesDirectory : join(process.cwd(), routesDirectory);
13
+ return filePath.startsWith(routesDirectoryPath);
14
+ }
15
+ const bannedBeforeExternalPlugins = [
16
+ {
17
+ identifier: "@react-refresh",
18
+ pkg: "@vitejs/plugin-react",
19
+ usage: "viteReact()"
20
+ }
21
+ ];
22
+ class FoundPluginInBeforeCode extends Error {
23
+ constructor(externalPlugin, framework) {
24
+ super(`We detected that the '${externalPlugin.pkg}' was passed before '@tanstack/router-plugin'. Please make sure that '@tanstack/router-plugin' is passed before '${externalPlugin.pkg}' and try again:
25
+ e.g.
26
+ plugins: [
27
+ TanStackRouter${capitalizeFirst(framework)}(), // Place this before ${externalPlugin.usage}
28
+ ${externalPlugin.usage},
29
+ ]
30
+ `);
31
+ }
32
+ }
33
+ const unpluginFactory = (options = {}, { framework }) => {
34
+ const debug = Boolean(process.env.TSR_VITE_DEBUG);
35
+ let ROOT = process.cwd();
36
+ let userConfig = options;
37
+ const handleSplittingFile = async (code, id) => {
38
+ const compiledAst = compileAst({
39
+ root: ROOT
40
+ });
41
+ if (debug)
42
+ console.info("Splitting route: ", id);
43
+ const compiled = await splitFile({
44
+ code,
45
+ compileAst: compiledAst,
46
+ filename: id
47
+ });
48
+ if (debug)
49
+ console.info("");
50
+ if (debug)
51
+ console.info("Split Output");
52
+ if (debug)
53
+ console.info("");
54
+ if (debug)
55
+ console.info(compiled.code);
56
+ if (debug)
57
+ console.info("");
58
+ if (debug)
59
+ console.info("");
60
+ if (debug)
61
+ console.info("");
62
+ if (debug)
63
+ console.info("");
64
+ if (debug)
65
+ console.info("");
66
+ if (debug)
67
+ console.info("");
68
+ if (debug)
69
+ console.info("");
70
+ if (debug)
71
+ console.info("");
72
+ return compiled;
73
+ };
74
+ const handleCompilingFile = async (code, id) => {
75
+ const compiledAst = compileAst({
76
+ root: ROOT
77
+ });
78
+ if (debug)
79
+ console.info("Handling createRoute: ", id);
80
+ const compiled = await compileFile({
81
+ code,
82
+ compileAst: compiledAst,
83
+ filename: id
84
+ });
85
+ if (debug)
86
+ console.info("");
87
+ if (debug)
88
+ console.info("Compiled Output");
89
+ if (debug)
90
+ console.info("");
91
+ if (debug)
92
+ console.info(compiled.code);
93
+ if (debug)
94
+ console.info("");
95
+ if (debug)
96
+ console.info("");
97
+ if (debug)
98
+ console.info("");
99
+ if (debug)
100
+ console.info("");
101
+ if (debug)
102
+ console.info("");
103
+ if (debug)
104
+ console.info("");
105
+ if (debug)
106
+ console.info("");
107
+ if (debug)
108
+ console.info("");
109
+ if (debug)
110
+ console.info("");
111
+ if (debug)
112
+ console.info("");
113
+ return compiled;
114
+ };
115
+ return {
116
+ name: "router-code-splitter-plugin",
117
+ enforce: "pre",
118
+ resolveId(source) {
119
+ var _a;
120
+ if (!((_a = userConfig.experimental) == null ? void 0 : _a.enableCodeSplitting)) {
121
+ return null;
122
+ }
123
+ if (source.startsWith(splitPrefix + ":")) {
124
+ return source.replace(splitPrefix + ":", "");
125
+ }
126
+ return null;
127
+ },
128
+ async transform(code, id) {
129
+ const url = pathToFileURL(id);
130
+ url.searchParams.delete("v");
131
+ id = fileURLToPath(url).replace(/\\/g, "/");
132
+ if (id.includes(splitPrefix)) {
133
+ return await handleSplittingFile(code, id);
134
+ } else if (fileIsInRoutesDirectory(id, userConfig.routesDirectory) && (code.includes("createRoute(") || code.includes("createFileRoute("))) {
135
+ for (const externalPlugin of bannedBeforeExternalPlugins) {
136
+ if (code.includes(externalPlugin.identifier)) {
137
+ throw new FoundPluginInBeforeCode(externalPlugin, framework);
138
+ }
139
+ }
140
+ return await handleCompilingFile(code, id);
141
+ }
142
+ return null;
143
+ },
144
+ vite: {
145
+ async configResolved(config) {
146
+ ROOT = config.root;
147
+ userConfig = await getConfig(options, ROOT);
148
+ }
149
+ }
150
+ };
151
+ };
152
+ const unpluginRouterCodeSplitter = /* @__PURE__ */ createUnplugin(unpluginFactory);
153
+ export {
154
+ unpluginFactory,
155
+ unpluginRouterCodeSplitter
156
+ };
157
+ //# sourceMappingURL=code-splitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-splitter.js","sources":["../../src/code-splitter.ts"],"sourcesContent":["import { isAbsolute, join } from 'node:path'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { createUnplugin } from 'unplugin'\n\nimport { compileAst } from './ast'\nimport { compileFile, splitFile } from './compilers'\nimport { getConfig } from './config'\nimport { splitPrefix } from './constants'\n\nimport type { PluginOptions } from './config'\nimport type { UnpluginFactory } from 'unplugin'\n\nfunction capitalizeFirst(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1)\n}\n\nfunction fileIsInRoutesDirectory(filePath: string, routesDirectory: string) {\n const routesDirectoryPath = isAbsolute(routesDirectory)\n ? routesDirectory\n : join(process.cwd(), routesDirectory)\n\n return filePath.startsWith(routesDirectoryPath)\n}\n\nconst bannedBeforeExternalPlugins = [\n {\n identifier: '@react-refresh',\n pkg: '@vitejs/plugin-react',\n usage: 'viteReact()',\n },\n]\n\nclass FoundPluginInBeforeCode extends Error {\n constructor(\n externalPlugin: (typeof bannedBeforeExternalPlugins)[number],\n framework: string,\n ) {\n super(`We detected that the '${externalPlugin.pkg}' was passed before '@tanstack/router-plugin'. Please make sure that '@tanstack/router-plugin' is passed before '${externalPlugin.pkg}' and try again: \ne.g.\nplugins: [\n TanStackRouter${capitalizeFirst(framework)}(), // Place this before ${externalPlugin.usage}\n ${externalPlugin.usage},\n]\n`)\n }\n}\n\nexport const unpluginFactory: UnpluginFactory<Partial<PluginOptions>> = (\n options = {},\n { framework },\n) => {\n const debug = Boolean(process.env.TSR_VITE_DEBUG)\n\n let ROOT: string = process.cwd()\n let userConfig = options as PluginOptions\n\n const handleSplittingFile = async (code: string, id: string) => {\n const compiledAst = compileAst({\n root: ROOT,\n })\n\n if (debug) console.info('Splitting route: ', id)\n\n const compiled = await splitFile({\n code,\n compileAst: compiledAst,\n filename: id,\n })\n\n if (debug) console.info('')\n if (debug) console.info('Split Output')\n if (debug) console.info('')\n if (debug) console.info(compiled.code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n return compiled\n }\n\n const handleCompilingFile = async (code: string, id: string) => {\n const compiledAst = compileAst({\n root: ROOT,\n })\n\n if (debug) console.info('Handling createRoute: ', id)\n\n const compiled = await compileFile({\n code,\n compileAst: compiledAst,\n filename: id,\n })\n\n if (debug) console.info('')\n if (debug) console.info('Compiled Output')\n if (debug) console.info('')\n if (debug) console.info(compiled.code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n return compiled\n }\n\n return {\n name: 'router-code-splitter-plugin',\n enforce: 'pre',\n resolveId(source) {\n if (!userConfig.experimental?.enableCodeSplitting) {\n return null\n }\n\n if (source.startsWith(splitPrefix + ':')) {\n return source.replace(splitPrefix + ':', '')\n }\n return null\n },\n async transform(code, id) {\n const url = pathToFileURL(id)\n url.searchParams.delete('v')\n id = fileURLToPath(url).replace(/\\\\/g, '/')\n\n if (id.includes(splitPrefix)) {\n return await handleSplittingFile(code, id)\n } else if (\n fileIsInRoutesDirectory(id, userConfig.routesDirectory) &&\n (code.includes('createRoute(') || code.includes('createFileRoute('))\n ) {\n for (const externalPlugin of bannedBeforeExternalPlugins) {\n if (code.includes(externalPlugin.identifier)) {\n throw new FoundPluginInBeforeCode(externalPlugin, framework)\n }\n }\n\n return await handleCompilingFile(code, id)\n }\n\n return null\n },\n vite: {\n async configResolved(config) {\n ROOT = config.root\n userConfig = await getConfig(options, ROOT)\n },\n },\n }\n}\n\nexport const unpluginRouterCodeSplitter =\n /* #__PURE__ */ createUnplugin(unpluginFactory)\n"],"names":[],"mappings":";;;;;;;AAYA,SAAS,gBAAgB,KAAqB;AACrC,SAAA,IAAI,OAAO,CAAC,EAAE,gBAAgB,IAAI,MAAM,CAAC;AAClD;AAEA,SAAS,wBAAwB,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GAAG;AAC3B,WAAK,cAAc,GAAG,EAAE,QAAQ,OAAO,GAAG;AAEtC,UAAA,GAAG,SAAS,WAAW,GAAG;AACrB,eAAA,MAAM,oBAAoB,MAAM,EAAE;AAAA,MAEzC,WAAA,wBAAwB,IAAI,WAAW,eAAe,MACrD,KAAK,SAAS,cAAc,KAAK,KAAK,SAAS,kBAAkB,IAClE;AACA,mBAAW,kBAAkB,6BAA6B;AACxD,cAAI,KAAK,SAAS,eAAe,UAAU,GAAG;AACtC,kBAAA,IAAI,wBAAwB,gBAAgB,SAAS;AAAA,UAC7D;AAAA,QACF;AAEO,eAAA,MAAM,oBAAoB,MAAM,EAAE;AAAA,MAC3C;AAEO,aAAA;AAAA,IACT;AAAA,IACA,MAAM;AAAA,MACJ,MAAM,eAAe,QAAQ;AAC3B,eAAO,OAAO;AACD,qBAAA,MAAM,UAAU,SAAS,IAAI;AAAA,MAC5C;AAAA,IACF;AAAA,EAAA;AAEJ;AAEa,MAAA,4DACoB,eAAe;"}
@@ -0,0 +1,18 @@
1
+ import { CompileAstFn } from './ast.js';
2
+
3
+ export declare function compileFile(opts: {
4
+ code: string;
5
+ compileAst: CompileAstFn;
6
+ filename: string;
7
+ }): Promise<{
8
+ code: string;
9
+ map: any;
10
+ }>;
11
+ export declare function splitFile(opts: {
12
+ code: string;
13
+ compileAst: CompileAstFn;
14
+ filename: string;
15
+ }): Promise<{
16
+ code: string;
17
+ map: any;
18
+ }>;
@@ -0,0 +1,309 @@
1
+ import * as t from "@babel/types";
2
+ import * as template from "@babel/template";
3
+ import { splitPrefix } from "./constants.js";
4
+ import { eliminateUnreferencedIdentifiers } from "./eliminateUnreferencedIdentifiers.js";
5
+ async function compileFile(opts) {
6
+ return await opts.compileAst({
7
+ code: opts.code,
8
+ filename: opts.filename,
9
+ getBabelConfig: () => ({
10
+ plugins: [
11
+ [
12
+ {
13
+ visitor: {
14
+ Program: {
15
+ enter(programPath, state) {
16
+ const splitUrl = `${splitPrefix}:${opts.filename}?${splitPrefix}`;
17
+ programPath.traverse(
18
+ {
19
+ CallExpression: (path) => {
20
+ if (path.node.callee.type === "Identifier") {
21
+ if (path.node.callee.name === "createRoute" || path.node.callee.name === "createFileRoute") {
22
+ if (path.parentPath.node.type === "CallExpression") {
23
+ const options = resolveIdentifier(
24
+ path,
25
+ path.parentPath.node.arguments[0]
26
+ );
27
+ let found = false;
28
+ const hasImportedOrDefinedIdentifier = (name) => {
29
+ return programPath.scope.hasBinding(name);
30
+ };
31
+ if (t.isObjectExpression(options)) {
32
+ options.properties.forEach((prop) => {
33
+ if (t.isObjectProperty(prop)) {
34
+ if (t.isIdentifier(prop.key)) {
35
+ if (prop.key.name === "component") {
36
+ const value = prop.value;
37
+ if (t.isIdentifier(value)) {
38
+ removeIdentifierLiteral(path, value);
39
+ }
40
+ if (!hasImportedOrDefinedIdentifier(
41
+ "lazyRouteComponent"
42
+ )) {
43
+ programPath.unshiftContainer("body", [
44
+ template.smart(
45
+ `import { lazyRouteComponent } from '@tanstack/react-router'`
46
+ )()
47
+ ]);
48
+ }
49
+ if (!hasImportedOrDefinedIdentifier(
50
+ "$$splitComponentImporter"
51
+ )) {
52
+ programPath.unshiftContainer("body", [
53
+ template.smart(
54
+ `const $$splitComponentImporter = () => import('${splitUrl}')`
55
+ )()
56
+ ]);
57
+ }
58
+ prop.value = template.expression(
59
+ `lazyRouteComponent($$splitComponentImporter, 'component')`
60
+ )();
61
+ programPath.pushContainer("body", [
62
+ template.smart(
63
+ `function DummyComponent() { return null }`
64
+ )()
65
+ ]);
66
+ found = true;
67
+ } else if (prop.key.name === "loader") {
68
+ const value = prop.value;
69
+ if (t.isIdentifier(value)) {
70
+ removeIdentifierLiteral(path, value);
71
+ }
72
+ if (!hasImportedOrDefinedIdentifier(
73
+ "lazyFn"
74
+ )) {
75
+ programPath.unshiftContainer("body", [
76
+ template.smart(
77
+ `import { lazyFn } from '@tanstack/react-router'`
78
+ )()
79
+ ]);
80
+ }
81
+ if (!hasImportedOrDefinedIdentifier(
82
+ "$$splitLoaderImporter"
83
+ )) {
84
+ programPath.unshiftContainer("body", [
85
+ template.smart(
86
+ `const $$splitLoaderImporter = () => import('${splitUrl}')`
87
+ )()
88
+ ]);
89
+ }
90
+ prop.value = template.expression(
91
+ `lazyFn($$splitLoaderImporter, 'loader')`
92
+ )();
93
+ found = true;
94
+ }
95
+ }
96
+ }
97
+ programPath.scope.crawl();
98
+ });
99
+ }
100
+ if (found) {
101
+ programPath.pushContainer("body", [
102
+ template.smart(
103
+ `function TSR_Dummy_Component() {}`
104
+ )()
105
+ ]);
106
+ }
107
+ }
108
+ }
109
+ }
110
+ }
111
+ },
112
+ state
113
+ );
114
+ eliminateUnreferencedIdentifiers(programPath);
115
+ }
116
+ }
117
+ }
118
+ },
119
+ {
120
+ root: process.cwd(),
121
+ minify: process.env.NODE_ENV === "production"
122
+ }
123
+ ]
124
+ ].filter(Boolean)
125
+ })
126
+ });
127
+ }
128
+ function resolveIdentifier(path, node) {
129
+ if (t.isIdentifier(node)) {
130
+ const binding = path.scope.getBinding(node.name);
131
+ if (binding) {
132
+ const declarator = binding.path.node;
133
+ if (t.isObjectExpression(declarator.init)) {
134
+ return declarator.init;
135
+ } else if (t.isFunctionDeclaration(declarator.init)) {
136
+ return declarator.init;
137
+ }
138
+ }
139
+ return void 0;
140
+ }
141
+ return node;
142
+ }
143
+ function removeIdentifierLiteral(path, node) {
144
+ if (t.isIdentifier(node)) {
145
+ const binding = path.scope.getBinding(node.name);
146
+ if (binding) {
147
+ binding.path.remove();
148
+ }
149
+ }
150
+ }
151
+ const splitNodeTypes = ["component", "loader"];
152
+ async function splitFile(opts) {
153
+ return await opts.compileAst({
154
+ code: opts.code,
155
+ filename: opts.filename,
156
+ getBabelConfig: () => ({
157
+ plugins: [
158
+ [
159
+ {
160
+ visitor: {
161
+ Program: {
162
+ enter(programPath, state) {
163
+ const splitNodesByType = {
164
+ component: void 0,
165
+ loader: void 0
166
+ };
167
+ programPath.traverse(
168
+ {
169
+ CallExpression: (path) => {
170
+ if (path.node.callee.type === "Identifier") {
171
+ if (path.node.callee.name === "createRoute" || path.node.callee.name === "createFileRoute") {
172
+ if (path.parentPath.node.type === "CallExpression") {
173
+ const options = resolveIdentifier(
174
+ path,
175
+ path.parentPath.node.arguments[0]
176
+ );
177
+ if (t.isObjectExpression(options)) {
178
+ options.properties.forEach((prop) => {
179
+ if (t.isObjectProperty(prop)) {
180
+ splitNodeTypes.forEach((type) => {
181
+ if (t.isIdentifier(prop.key)) {
182
+ if (prop.key.name === type) {
183
+ splitNodesByType[type] = prop.value;
184
+ }
185
+ }
186
+ });
187
+ }
188
+ });
189
+ options.properties = [];
190
+ }
191
+ }
192
+ }
193
+ }
194
+ }
195
+ },
196
+ state
197
+ );
198
+ splitNodeTypes.forEach((splitType) => {
199
+ let splitNode = splitNodesByType[splitType];
200
+ if (!splitNode) {
201
+ return;
202
+ }
203
+ while (t.isIdentifier(splitNode)) {
204
+ const binding = programPath.scope.getBinding(
205
+ splitNode.name
206
+ );
207
+ splitNode = binding == null ? void 0 : binding.path.node;
208
+ }
209
+ if (splitNode) {
210
+ if (t.isFunctionDeclaration(splitNode)) {
211
+ programPath.pushContainer(
212
+ "body",
213
+ t.variableDeclaration("const", [
214
+ t.variableDeclarator(
215
+ t.identifier(splitType),
216
+ t.functionExpression(
217
+ splitNode.id || null,
218
+ // Anonymize the function expression
219
+ splitNode.params,
220
+ splitNode.body,
221
+ splitNode.generator,
222
+ splitNode.async
223
+ )
224
+ )
225
+ ])
226
+ );
227
+ } else if (t.isFunctionExpression(splitNode) || t.isArrowFunctionExpression(splitNode)) {
228
+ programPath.pushContainer(
229
+ "body",
230
+ t.variableDeclaration("const", [
231
+ t.variableDeclarator(
232
+ t.identifier(splitType),
233
+ splitNode
234
+ )
235
+ ])
236
+ );
237
+ } else if (t.isImportSpecifier(splitNode)) {
238
+ programPath.pushContainer(
239
+ "body",
240
+ t.variableDeclaration("const", [
241
+ t.variableDeclarator(
242
+ t.identifier(splitType),
243
+ splitNode.local
244
+ )
245
+ ])
246
+ );
247
+ } else {
248
+ console.info(splitNode);
249
+ throw new Error(
250
+ `Unexpected splitNode type ☝️: ${splitNode.type}`
251
+ );
252
+ }
253
+ }
254
+ programPath.node.body = programPath.node.body.filter(
255
+ (node) => {
256
+ return node !== splitNode;
257
+ }
258
+ );
259
+ programPath.pushContainer("body", [
260
+ t.exportNamedDeclaration(null, [
261
+ t.exportSpecifier(
262
+ t.identifier(splitType),
263
+ t.identifier(splitType)
264
+ )
265
+ ])
266
+ ]);
267
+ });
268
+ programPath.traverse({
269
+ ExportNamedDeclaration(path) {
270
+ if (path.node.declaration) {
271
+ if (t.isVariableDeclaration(path.node.declaration)) {
272
+ path.replaceWith(
273
+ t.importDeclaration(
274
+ path.node.declaration.declarations.map(
275
+ (decl) => t.importSpecifier(
276
+ t.identifier(decl.id.name),
277
+ t.identifier(decl.id.name)
278
+ )
279
+ ),
280
+ t.stringLiteral(
281
+ opts.filename.split(
282
+ `?${splitPrefix}`
283
+ )[0]
284
+ )
285
+ )
286
+ );
287
+ }
288
+ }
289
+ }
290
+ });
291
+ eliminateUnreferencedIdentifiers(programPath);
292
+ }
293
+ }
294
+ }
295
+ },
296
+ {
297
+ root: process.cwd(),
298
+ minify: process.env.NODE_ENV === "production"
299
+ }
300
+ ]
301
+ ].filter(Boolean)
302
+ })
303
+ });
304
+ }
305
+ export {
306
+ compileFile,
307
+ splitFile
308
+ };
309
+ //# sourceMappingURL=compilers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compilers.js","sources":["../../src/compilers.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport * as template from '@babel/template'\nimport { splitPrefix } from './constants'\nimport { eliminateUnreferencedIdentifiers } from './eliminateUnreferencedIdentifiers'\nimport type * as babel from '@babel/core'\nimport type { CompileAstFn } from './ast'\n\ntype SplitModulesById = Record<\n string,\n { id: string; node: t.FunctionExpression }\n>\n\ninterface State {\n filename: string\n opts: {\n minify: boolean\n root: string\n }\n imported: Record<string, boolean>\n refs: Set<any>\n serverIndex: number\n splitIndex: number\n splitModulesById: SplitModulesById\n}\n\nexport async function compileFile(opts: {\n code: string\n compileAst: CompileAstFn\n filename: string\n}) {\n return await opts.compileAst({\n code: opts.code,\n filename: opts.filename,\n getBabelConfig: () => ({\n plugins: [\n [\n {\n visitor: {\n Program: {\n enter(programPath: babel.NodePath<t.Program>, state: State) {\n const splitUrl = `${splitPrefix}:${opts.filename}?${splitPrefix}`\n\n programPath.traverse(\n {\n CallExpression: (path) => {\n if (path.node.callee.type === 'Identifier') {\n if (\n path.node.callee.name === 'createRoute' ||\n path.node.callee.name === 'createFileRoute'\n ) {\n if (\n path.parentPath.node.type === 'CallExpression'\n ) {\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n let found = false\n\n const hasImportedOrDefinedIdentifier = (\n name: string,\n ) => {\n return programPath.scope.hasBinding(name)\n }\n\n if (t.isObjectExpression(options)) {\n options.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n if (t.isIdentifier(prop.key)) {\n if (prop.key.name === 'component') {\n const value = prop.value\n\n if (t.isIdentifier(value)) {\n removeIdentifierLiteral(path, value)\n }\n\n // Prepend the import statement to the program along with the importer function\n // Check to see if lazyRouteComponent is already imported before attempting\n // to import it again\n\n if (\n !hasImportedOrDefinedIdentifier(\n 'lazyRouteComponent',\n )\n ) {\n programPath.unshiftContainer('body', [\n template.smart(\n `import { lazyRouteComponent } from '@tanstack/react-router'`,\n )() as t.Statement,\n ])\n }\n\n if (\n !hasImportedOrDefinedIdentifier(\n '$$splitComponentImporter',\n )\n ) {\n programPath.unshiftContainer('body', [\n template.smart(\n `const $$splitComponentImporter = () => import('${splitUrl}')`,\n )() as t.Statement,\n ])\n }\n\n prop.value = template.expression(\n `lazyRouteComponent($$splitComponentImporter, 'component')`,\n )() as any\n\n programPath.pushContainer('body', [\n template.smart(\n `function DummyComponent() { return null }`,\n )() as t.Statement,\n ])\n\n found = true\n } else if (prop.key.name === 'loader') {\n const value = prop.value\n\n if (t.isIdentifier(value)) {\n removeIdentifierLiteral(path, value)\n }\n\n // Prepend the import statement to the program along with the importer function\n\n if (\n !hasImportedOrDefinedIdentifier(\n 'lazyFn',\n )\n ) {\n programPath.unshiftContainer('body', [\n template.smart(\n `import { lazyFn } from '@tanstack/react-router'`,\n )() as t.Statement,\n ])\n }\n\n if (\n !hasImportedOrDefinedIdentifier(\n '$$splitLoaderImporter',\n )\n ) {\n programPath.unshiftContainer('body', [\n template.smart(\n `const $$splitLoaderImporter = () => import('${splitUrl}')`,\n )() as t.Statement,\n ])\n }\n\n prop.value = template.expression(\n `lazyFn($$splitLoaderImporter, 'loader')`,\n )() as any\n\n found = true\n }\n }\n }\n\n programPath.scope.crawl()\n })\n }\n\n if (found as boolean) {\n programPath.pushContainer('body', [\n template.smart(\n `function TSR_Dummy_Component() {}`,\n )() as t.Statement,\n ])\n }\n }\n }\n }\n },\n },\n state,\n )\n\n eliminateUnreferencedIdentifiers(programPath)\n },\n },\n },\n },\n {\n root: process.cwd(),\n minify: process.env.NODE_ENV === 'production',\n },\n ],\n ].filter(Boolean),\n }),\n })\n}\n\n// Reusable function to get literal value or resolve variable to literal\nfunction resolveIdentifier(path: any, node: any) {\n if (t.isIdentifier(node)) {\n const binding = path.scope.getBinding(node.name)\n if (\n binding\n // && binding.kind === 'const'\n ) {\n const declarator = binding.path.node\n if (t.isObjectExpression(declarator.init)) {\n return declarator.init\n } else if (t.isFunctionDeclaration(declarator.init)) {\n return declarator.init\n }\n }\n return undefined\n }\n\n return node\n}\n\nfunction removeIdentifierLiteral(path: any, node: any) {\n if (t.isIdentifier(node)) {\n const binding = path.scope.getBinding(node.name)\n if (binding) {\n binding.path.remove()\n }\n }\n}\n\nconst splitNodeTypes = ['component', 'loader'] as const\ntype SplitNodeType = (typeof splitNodeTypes)[number]\n\nexport async function splitFile(opts: {\n code: string\n compileAst: CompileAstFn\n filename: string\n}) {\n return await opts.compileAst({\n code: opts.code,\n filename: opts.filename,\n getBabelConfig: () => ({\n plugins: [\n [\n {\n visitor: {\n Program: {\n enter(programPath: babel.NodePath<t.Program>, state: State) {\n const splitNodesByType: Record<\n SplitNodeType,\n t.Node | undefined\n > = {\n component: undefined,\n loader: undefined,\n }\n\n // Find the node\n programPath.traverse(\n {\n CallExpression: (path) => {\n if (path.node.callee.type === 'Identifier') {\n if (\n path.node.callee.name === 'createRoute' ||\n path.node.callee.name === 'createFileRoute'\n ) {\n if (\n path.parentPath.node.type === 'CallExpression'\n ) {\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n if (t.isObjectExpression(options)) {\n options.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n splitNodeTypes.forEach((type) => {\n if (t.isIdentifier(prop.key)) {\n if (prop.key.name === type) {\n splitNodesByType[type] = prop.value\n }\n }\n })\n }\n })\n\n // Remove all of the options\n options.properties = []\n }\n }\n }\n }\n },\n },\n state,\n )\n\n splitNodeTypes.forEach((splitType) => {\n let splitNode = splitNodesByType[splitType]\n\n if (!splitNode) {\n return\n }\n\n while (t.isIdentifier(splitNode)) {\n const binding = programPath.scope.getBinding(\n splitNode.name,\n )\n splitNode = binding?.path.node\n }\n\n // Add the node to the program\n if (splitNode) {\n if (t.isFunctionDeclaration(splitNode)) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitType),\n t.functionExpression(\n splitNode.id || null, // Anonymize the function expression\n splitNode.params,\n splitNode.body,\n splitNode.generator,\n splitNode.async,\n ),\n ),\n ]),\n )\n } else if (\n t.isFunctionExpression(splitNode) ||\n t.isArrowFunctionExpression(splitNode)\n ) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitType),\n splitNode as any,\n ),\n ]),\n )\n } else if (t.isImportSpecifier(splitNode)) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitType),\n splitNode.local,\n ),\n ]),\n )\n } else {\n console.info(splitNode)\n throw new Error(\n `Unexpected splitNode type ☝️: ${splitNode.type}`,\n )\n }\n }\n\n // If the splitNode exists at the top of the program\n // then we need to remove that copy\n programPath.node.body = programPath.node.body.filter(\n (node) => {\n return node !== splitNode\n },\n )\n\n // Export the node\n programPath.pushContainer('body', [\n t.exportNamedDeclaration(null, [\n t.exportSpecifier(\n t.identifier(splitType),\n t.identifier(splitType),\n ),\n ]),\n ])\n })\n\n // convert exports to imports from the original file\n programPath.traverse({\n ExportNamedDeclaration(path) {\n // e.g. export const x = 1 or export { x }\n // becomes\n // import { x } from '${opts.id}'\n\n if (path.node.declaration) {\n if (t.isVariableDeclaration(path.node.declaration)) {\n path.replaceWith(\n t.importDeclaration(\n path.node.declaration.declarations.map((decl) =>\n t.importSpecifier(\n t.identifier((decl.id as any).name),\n t.identifier((decl.id as any).name),\n ),\n ),\n t.stringLiteral(\n opts.filename.split(\n `?${splitPrefix}`,\n )[0] as string,\n ),\n ),\n )\n }\n }\n },\n })\n\n eliminateUnreferencedIdentifiers(programPath)\n },\n },\n },\n },\n {\n root: process.cwd(),\n minify: process.env.NODE_ENV === 'production',\n },\n ],\n ].filter(Boolean),\n }),\n })\n}\n"],"names":[],"mappings":";;;;AAyBA,eAAsB,YAAY,MAI/B;AACM,SAAA,MAAM,KAAK,WAAW;AAAA,IAC3B,MAAM,KAAK;AAAA,IACX,UAAU,KAAK;AAAA,IACf,gBAAgB,OAAO;AAAA,MACrB,SAAS;AAAA,QACP;AAAA,UACE;AAAA,YACE,SAAS;AAAA,cACP,SAAS;AAAA,gBACP,MAAM,aAAwC,OAAc;AAC1D,wBAAM,WAAW,GAAG,WAAW,IAAI,KAAK,QAAQ,IAAI,WAAW;AAEnD,8BAAA;AAAA,oBACV;AAAA,sBACE,gBAAgB,CAAC,SAAS;AACxB,4BAAI,KAAK,KAAK,OAAO,SAAS,cAAc;AAExC,8BAAA,KAAK,KAAK,OAAO,SAAS,iBA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;AAAA,sBAEnD;AAAA,oBACF;AAIA,gCAAY,KAAK,OAAO,YAAY,KAAK,KAAK;AAAA,sBAC5C,CAAC,SAAS;AACR,+BAAO,SAAS;AAAA,sBAClB;AAAA,oBAAA;AAIF,gCAAY,cAAc,QAAQ;AAAA,sBAChC,EAAE,uBAAuB,MAAM;AAAA,wBAC7B,EAAE;AAAA,0BACA,EAAE,WAAW,SAAS;AAAA,0BACtB,EAAE,WAAW,SAAS;AAAA,wBACxB;AAAA,sBAAA,CACD;AAAA,oBAAA,CACF;AAAA,kBAAA,CACF;AAGD,8BAAY,SAAS;AAAA,oBACnB,uBAAuB,MAAM;AAKvB,0BAAA,KAAK,KAAK,aAAa;AACzB,4BAAI,EAAE,sBAAsB,KAAK,KAAK,WAAW,GAAG;AAC7C,+BAAA;AAAA,4BACH,EAAE;AAAA,8BACA,KAAK,KAAK,YAAY,aAAa;AAAA,gCAAI,CAAC,SACtC,EAAE;AAAA,kCACA,EAAE,WAAY,KAAK,GAAW,IAAI;AAAA,kCAClC,EAAE,WAAY,KAAK,GAAW,IAAI;AAAA,gCACpC;AAAA,8BACF;AAAA,8BACA,EAAE;AAAA,gCACA,KAAK,SAAS;AAAA,kCACZ,IAAI,WAAW;AAAA,kCACf,CAAC;AAAA,8BACL;AAAA,4BACF;AAAA,0BAAA;AAAA,wBAEJ;AAAA,sBACF;AAAA,oBACF;AAAA,kBAAA,CACD;AAED,mDAAiC,WAAW;AAAA,gBAC9C;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,UACA;AAAA,YACE,MAAM,QAAQ,IAAI;AAAA,YAClB,QAAQ,QAAQ,IAAI,aAAa;AAAA,UACnC;AAAA,QACF;AAAA,MAAA,EACA,OAAO,OAAO;AAAA,IAAA;AAAA,EAClB,CACD;AACH;"}
@@ -0,0 +1,79 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const configSchema: z.ZodObject<z.objectUtil.extendShape<{
4
+ routeFilePrefix: z.ZodOptional<z.ZodString>;
5
+ routeFileIgnorePrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
6
+ routeFileIgnorePattern: z.ZodOptional<z.ZodString>;
7
+ routesDirectory: z.ZodDefault<z.ZodOptional<z.ZodString>>;
8
+ generatedRouteTree: z.ZodDefault<z.ZodOptional<z.ZodString>>;
9
+ quoteStyle: z.ZodDefault<z.ZodOptional<z.ZodEnum<["single", "double"]>>>;
10
+ semicolons: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
11
+ disableTypes: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
12
+ addExtensions: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
13
+ disableLogging: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
14
+ routeTreeFileHeader: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
15
+ routeTreeFileFooter: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
16
+ }, {
17
+ enableRouteGeneration: z.ZodOptional<z.ZodBoolean>;
18
+ experimental: z.ZodOptional<z.ZodObject<{
19
+ enableCodeSplitting: z.ZodOptional<z.ZodBoolean>;
20
+ }, "strip", z.ZodTypeAny, {
21
+ enableCodeSplitting?: boolean | undefined;
22
+ }, {
23
+ enableCodeSplitting?: boolean | undefined;
24
+ }>>;
25
+ }>, "strip", z.ZodTypeAny, {
26
+ routeFileIgnorePrefix: string;
27
+ routesDirectory: string;
28
+ generatedRouteTree: string;
29
+ quoteStyle: "single" | "double";
30
+ semicolons: boolean;
31
+ disableTypes: boolean;
32
+ addExtensions: boolean;
33
+ disableLogging: boolean;
34
+ routeTreeFileHeader: string[];
35
+ routeTreeFileFooter: string[];
36
+ enableRouteGeneration?: boolean | undefined;
37
+ experimental?: {
38
+ enableCodeSplitting?: boolean | undefined;
39
+ } | undefined;
40
+ routeFilePrefix?: string | undefined;
41
+ routeFileIgnorePattern?: string | undefined;
42
+ }, {
43
+ enableRouteGeneration?: boolean | undefined;
44
+ experimental?: {
45
+ enableCodeSplitting?: boolean | undefined;
46
+ } | undefined;
47
+ routeFilePrefix?: string | undefined;
48
+ routeFileIgnorePrefix?: string | undefined;
49
+ routeFileIgnorePattern?: string | undefined;
50
+ routesDirectory?: string | undefined;
51
+ generatedRouteTree?: string | undefined;
52
+ quoteStyle?: "single" | "double" | undefined;
53
+ semicolons?: boolean | undefined;
54
+ disableTypes?: boolean | undefined;
55
+ addExtensions?: boolean | undefined;
56
+ disableLogging?: boolean | undefined;
57
+ routeTreeFileHeader?: string[] | undefined;
58
+ routeTreeFileFooter?: string[] | undefined;
59
+ }>;
60
+ export declare const getConfig: (inlineConfig: Partial<PluginOptions>, root: string) => Promise<{
61
+ routeFileIgnorePrefix: string;
62
+ routesDirectory: string;
63
+ generatedRouteTree: string;
64
+ quoteStyle: "single" | "double";
65
+ semicolons: boolean;
66
+ disableTypes: boolean;
67
+ addExtensions: boolean;
68
+ disableLogging: boolean;
69
+ routeTreeFileHeader: string[];
70
+ routeTreeFileFooter: string[];
71
+ enableRouteGeneration?: boolean | undefined;
72
+ experimental?: {
73
+ enableCodeSplitting?: boolean | undefined;
74
+ } | undefined;
75
+ routeFilePrefix?: string | undefined;
76
+ routeFileIgnorePattern?: string | undefined;
77
+ }>;
78
+ export type PluginOptions = z.infer<typeof configSchema>;
79
+ export {};
@@ -0,0 +1,16 @@
1
+ import { z } from "zod";
2
+ import { configSchema as configSchema$1, getConfig as getConfig$1 } from "@tanstack/router-generator";
3
+ const configSchema = configSchema$1.extend({
4
+ enableRouteGeneration: z.boolean().optional(),
5
+ experimental: z.object({
6
+ enableCodeSplitting: z.boolean().optional()
7
+ }).optional()
8
+ });
9
+ const getConfig = async (inlineConfig, root) => {
10
+ const config = await getConfig$1(inlineConfig, root);
11
+ return configSchema.parse({ ...config, ...inlineConfig });
12
+ };
13
+ export {
14
+ getConfig
15
+ };
16
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sources":["../../src/config.ts"],"sourcesContent":["import { z } from 'zod'\nimport {\n configSchema as generatorConfigSchema,\n getConfig as getGeneratorConfig,\n} from '@tanstack/router-generator'\n\nconst configSchema = generatorConfigSchema.extend({\n enableRouteGeneration: z.boolean().optional(),\n experimental: z\n .object({\n enableCodeSplitting: z.boolean().optional(),\n })\n .optional(),\n})\n\nexport const getConfig = async (\n inlineConfig: Partial<PluginOptions>,\n root: string,\n) => {\n const config = await getGeneratorConfig(inlineConfig, root)\n\n return configSchema.parse({ ...config, ...inlineConfig })\n}\n\nexport type PluginOptions = z.infer<typeof configSchema>\n"],"names":["generatorConfigSchema","getGeneratorConfig"],"mappings":";;AAMA,MAAM,eAAeA,eAAsB,OAAO;AAAA,EAChD,uBAAuB,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC5C,cAAc,EACX,OAAO;AAAA,IACN,qBAAqB,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC3C,CAAA,EACA,SAAS;AACd,CAAC;AAEY,MAAA,YAAY,OACvB,cACA,SACG;AACH,QAAM,SAAS,MAAMC,YAAmB,cAAc,IAAI;AAE1D,SAAO,aAAa,MAAM,EAAE,GAAG,QAAQ,GAAG,cAAc;AAC1D;"}
@@ -0,0 +1,2 @@
1
+ export declare const CONFIG_FILE_NAME = "tsr.config.json";
2
+ export declare const splitPrefix = "tsr-split";
@@ -0,0 +1,7 @@
1
+ const CONFIG_FILE_NAME = "tsr.config.json";
2
+ const splitPrefix = "tsr-split";
3
+ export {
4
+ CONFIG_FILE_NAME,
5
+ splitPrefix
6
+ };
7
+ //# sourceMappingURL=constants.js.map