@tanstack/router-plugin 1.58.1 → 1.58.4

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.
@@ -47,69 +47,83 @@ function compileCodeSplitReferenceRoute(opts) {
47
47
  if (t.isIdentifier(prop.key)) {
48
48
  if (prop.key.name === "component") {
49
49
  const value = prop.value;
50
+ let shouldSplit = true;
50
51
  if (t.isIdentifier(value)) {
51
52
  existingCompImportPath = getImportSpecifierAndPathFromLocalName(
52
53
  programPath,
53
54
  value.name
54
55
  ).path;
55
- removeIdentifierLiteral(path, value);
56
+ const isExported = hasExport(ast, value);
57
+ shouldSplit = !isExported;
58
+ if (shouldSplit) {
59
+ removeIdentifierLiteral(path, value);
60
+ }
56
61
  }
57
- if (!hasImportedOrDefinedIdentifier(
58
- "lazyRouteComponent"
59
- )) {
60
- programPath.unshiftContainer("body", [
62
+ if (shouldSplit) {
63
+ if (!hasImportedOrDefinedIdentifier(
64
+ "lazyRouteComponent"
65
+ )) {
66
+ programPath.unshiftContainer("body", [
67
+ template.statement(
68
+ `import { lazyRouteComponent } from '@tanstack/react-router'`
69
+ )()
70
+ ]);
71
+ }
72
+ if (!hasImportedOrDefinedIdentifier(
73
+ "$$splitComponentImporter"
74
+ )) {
75
+ programPath.unshiftContainer("body", [
76
+ template.statement(
77
+ `const $$splitComponentImporter = () => import('${splitUrl}')`
78
+ )()
79
+ ]);
80
+ }
81
+ prop.value = template.expression(
82
+ `lazyRouteComponent($$splitComponentImporter, 'component')`
83
+ )();
84
+ programPath.pushContainer("body", [
61
85
  template.statement(
62
- `import { lazyRouteComponent } from '@tanstack/react-router'`
86
+ `function DummyComponent() { return null }`
63
87
  )()
64
88
  ]);
89
+ found = true;
65
90
  }
66
- if (!hasImportedOrDefinedIdentifier(
67
- "$$splitComponentImporter"
68
- )) {
69
- programPath.unshiftContainer("body", [
70
- template.statement(
71
- `const $$splitComponentImporter = () => import('${splitUrl}')`
72
- )()
73
- ]);
74
- }
75
- prop.value = template.expression(
76
- `lazyRouteComponent($$splitComponentImporter, 'component')`
77
- )();
78
- programPath.pushContainer("body", [
79
- template.statement(
80
- `function DummyComponent() { return null }`
81
- )()
82
- ]);
83
- found = true;
84
91
  } else if (prop.key.name === "loader") {
85
92
  const value = prop.value;
93
+ let shouldSplit = true;
86
94
  if (t.isIdentifier(value)) {
87
95
  existingLoaderImportPath = getImportSpecifierAndPathFromLocalName(
88
96
  programPath,
89
97
  value.name
90
98
  ).path;
91
- removeIdentifierLiteral(path, value);
99
+ const isExported = hasExport(ast, value);
100
+ shouldSplit = !isExported;
101
+ if (shouldSplit) {
102
+ removeIdentifierLiteral(path, value);
103
+ }
92
104
  }
93
- if (!hasImportedOrDefinedIdentifier("lazyFn")) {
94
- programPath.unshiftContainer("body", [
95
- template.smart(
96
- `import { lazyFn } from '@tanstack/react-router'`
97
- )()
98
- ]);
105
+ if (shouldSplit) {
106
+ if (!hasImportedOrDefinedIdentifier("lazyFn")) {
107
+ programPath.unshiftContainer("body", [
108
+ template.smart(
109
+ `import { lazyFn } from '@tanstack/react-router'`
110
+ )()
111
+ ]);
112
+ }
113
+ if (!hasImportedOrDefinedIdentifier(
114
+ "$$splitLoaderImporter"
115
+ )) {
116
+ programPath.unshiftContainer("body", [
117
+ template.statement(
118
+ `const $$splitLoaderImporter = () => import('${splitUrl}')`
119
+ )()
120
+ ]);
121
+ }
122
+ prop.value = template.expression(
123
+ `lazyFn($$splitLoaderImporter, 'loader')`
124
+ )();
125
+ found = true;
99
126
  }
100
- if (!hasImportedOrDefinedIdentifier(
101
- "$$splitLoaderImporter"
102
- )) {
103
- programPath.unshiftContainer("body", [
104
- template.statement(
105
- `const $$splitLoaderImporter = () => import('${splitUrl}')`
106
- )()
107
- ]);
108
- }
109
- prop.value = template.expression(
110
- `lazyFn($$splitLoaderImporter, 'loader')`
111
- )();
112
- found = true;
113
127
  }
114
128
  }
115
129
  }
@@ -152,6 +166,7 @@ function compileCodeSplitVirtualRoute(opts) {
152
166
  `Failed to compile ast for compileCodeSplitVirtualRoute() for the file: ${opts.filename}`
153
167
  );
154
168
  }
169
+ const knownExportedIdents = /* @__PURE__ */ new Set();
155
170
  babel__default.traverse(ast, {
156
171
  Program: {
157
172
  enter(programPath, programState) {
@@ -177,12 +192,23 @@ function compileCodeSplitVirtualRoute(opts) {
177
192
  if (t.isObjectExpression(options)) {
178
193
  options.properties.forEach((prop) => {
179
194
  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;
195
+ splitNodeTypes.forEach((splitType) => {
196
+ if (!t.isIdentifier(prop.key) || prop.key.name !== splitType) {
197
+ return;
198
+ }
199
+ const value = prop.value;
200
+ let isExported = false;
201
+ if (t.isIdentifier(value)) {
202
+ isExported = hasExport(ast, value);
203
+ if (isExported) {
204
+ knownExportedIdents.add(value.name);
184
205
  }
185
206
  }
207
+ if (isExported && t.isIdentifier(value)) {
208
+ removeExports(ast, value);
209
+ } else {
210
+ splitNodesByType[splitType] = prop.value;
211
+ }
186
212
  });
187
213
  }
188
214
  });
@@ -309,6 +335,22 @@ function compileCodeSplitVirtualRoute(opts) {
309
335
  }
310
336
  });
311
337
  deadCodeElimination(ast);
338
+ if (knownExportedIdents.size > 0) {
339
+ const list = Array.from(knownExportedIdents).reduce((str, ident) => {
340
+ str += `
341
+ - ${ident}`;
342
+ return str;
343
+ }, "");
344
+ const warningMessage = `These exports from "${opts.filename.replace("?" + splitPrefix, "")}" are not being code-split and will increase your bundle size: ${list}
345
+ These should either have their export statements removed or be imported from another file that is not a route.`;
346
+ console.warn(warningMessage);
347
+ if (process.env.NODE_ENV !== "production") {
348
+ const warningTemplate = template.statement(
349
+ `console.warn(${JSON.stringify(warningMessage)})`
350
+ )();
351
+ ast.program.body.unshift(warningTemplate);
352
+ }
353
+ }
312
354
  return generate(ast, {
313
355
  sourceMaps: true
314
356
  });
@@ -352,6 +394,78 @@ function removeIdentifierLiteral(path, node) {
352
394
  }
353
395
  }
354
396
  }
397
+ function hasExport(ast, node) {
398
+ let found = false;
399
+ babel__default.traverse(ast, {
400
+ ExportNamedDeclaration(path) {
401
+ if (path.node.declaration) {
402
+ if (t.isVariableDeclaration(path.node.declaration)) {
403
+ path.node.declaration.declarations.forEach((decl) => {
404
+ if (t.isVariableDeclarator(decl)) {
405
+ if (t.isIdentifier(decl.id)) {
406
+ if (decl.id.name === node.name) {
407
+ found = true;
408
+ }
409
+ }
410
+ }
411
+ });
412
+ }
413
+ if (t.isFunctionDeclaration(path.node.declaration)) {
414
+ if (t.isIdentifier(path.node.declaration.id)) {
415
+ if (path.node.declaration.id.name === node.name) {
416
+ found = true;
417
+ }
418
+ }
419
+ }
420
+ }
421
+ },
422
+ ExportDefaultDeclaration(path) {
423
+ if (t.isIdentifier(path.node.declaration)) {
424
+ if (path.node.declaration.name === node.name) {
425
+ found = true;
426
+ }
427
+ }
428
+ }
429
+ });
430
+ return found;
431
+ }
432
+ function removeExports(ast, node) {
433
+ let removed = false;
434
+ babel__default.traverse(ast, {
435
+ ExportNamedDeclaration(path) {
436
+ if (path.node.declaration) {
437
+ if (t.isVariableDeclaration(path.node.declaration)) {
438
+ path.node.declaration.declarations.forEach((decl) => {
439
+ if (t.isVariableDeclarator(decl)) {
440
+ if (t.isIdentifier(decl.id)) {
441
+ if (decl.id.name === node.name) {
442
+ path.remove();
443
+ removed = true;
444
+ }
445
+ }
446
+ }
447
+ });
448
+ } else if (t.isFunctionDeclaration(path.node.declaration)) {
449
+ if (t.isIdentifier(path.node.declaration.id)) {
450
+ if (path.node.declaration.id.name === node.name) {
451
+ path.remove();
452
+ removed = true;
453
+ }
454
+ }
455
+ }
456
+ }
457
+ },
458
+ ExportDefaultDeclaration(path) {
459
+ if (t.isIdentifier(path.node.declaration)) {
460
+ if (path.node.declaration.name === node.name) {
461
+ path.remove();
462
+ removed = true;
463
+ }
464
+ }
465
+ }
466
+ });
467
+ return removed;
468
+ }
355
469
  export {
356
470
  compileCodeSplitReferenceRoute,
357
471
  compileCodeSplitVirtualRoute
@@ -1 +1 @@
1
- {"version":3,"file":"compilers.js","sources":["../../../../src/core/code-splitter/compilers.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport babel from '@babel/core'\nimport _generate from '@babel/generator'\nimport * as template from '@babel/template'\nimport { deadCodeElimination } from 'babel-dead-code-elimination'\n\nimport { splitPrefix } from '../constants'\nimport { parseAst } from './ast'\nimport type { ParseAstOptions } from './ast'\n\n// Babel is a CJS package and uses `default` as named binding (`exports.default =`).\n// https://github.com/babel/babel/issues/15269.\nlet generate = (_generate as any)['default'] as typeof _generate\n\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\nif (!generate) {\n generate = _generate\n}\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 function compileCodeSplitReferenceRoute(opts: ParseAstOptions) {\n const ast = parseAst(opts)\n\n if (!ast) {\n throw new Error(\n `Failed to compile ast for compileCodeSplitReferenceRoute() for the file: ${opts.filename}`,\n )\n }\n\n babel.traverse(ast, {\n Program: {\n enter(programPath, programState) {\n const state = programState as unknown as State\n\n const splitUrl = `${splitPrefix}:${opts.filename}?${splitPrefix}`\n\n /**\n * If the component for the route is being imported from\n * another file, this is to track the path to that file\n * the path itself doesn't matter, we just need to keep\n * track of it so that we can remove it from the imports\n * list if it's not being used like:\n *\n * `import '../shared/imported'`\n */\n let existingCompImportPath: string | null = null\n let existingLoaderImportPath: string | null = null\n\n programPath.traverse(\n {\n CallExpression: (path) => {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n\n if (\n !(\n path.node.callee.name === 'createRoute' ||\n path.node.callee.name === 'createFileRoute'\n )\n ) {\n return\n }\n\n if (t.isCallExpression(path.parentPath.node)) {\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n let found = false\n\n const hasImportedOrDefinedIdentifier = (name: string) => {\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 existingCompImportPath =\n getImportSpecifierAndPathFromLocalName(\n programPath,\n value.name,\n ).path\n\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.statement(\n `import { lazyRouteComponent } from '@tanstack/react-router'`,\n )(),\n ])\n }\n\n if (\n !hasImportedOrDefinedIdentifier(\n '$$splitComponentImporter',\n )\n ) {\n programPath.unshiftContainer('body', [\n template.statement(\n `const $$splitComponentImporter = () => import('${splitUrl}')`,\n )(),\n ])\n }\n\n prop.value = template.expression(\n `lazyRouteComponent($$splitComponentImporter, 'component')`,\n )()\n\n programPath.pushContainer('body', [\n template.statement(\n `function DummyComponent() { return null }`,\n )(),\n ])\n\n found = true\n } else if (prop.key.name === 'loader') {\n const value = prop.value\n\n if (t.isIdentifier(value)) {\n existingLoaderImportPath =\n getImportSpecifierAndPathFromLocalName(\n programPath,\n value.name,\n ).path\n\n removeIdentifierLiteral(path, value)\n }\n\n // Prepend the import statement to the program along with the importer function\n\n if (!hasImportedOrDefinedIdentifier('lazyFn')) {\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.statement(\n `const $$splitLoaderImporter = () => import('${splitUrl}')`,\n )(),\n ])\n }\n\n prop.value = template.expression(\n `lazyFn($$splitLoaderImporter, 'loader')`,\n )()\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.statement(`function TSR_Dummy_Component() {}`)(),\n ])\n }\n }\n },\n },\n state,\n )\n\n /**\n * If the component for the route is being imported,\n * and it's not being used, remove the import statement\n * from the program, by checking that the import has no\n * specifiers\n */\n if (\n (existingCompImportPath as string | null) ||\n (existingLoaderImportPath as string | null)\n ) {\n programPath.traverse({\n ImportDeclaration(path) {\n if (path.node.specifiers.length > 0) return\n if (\n path.node.source.value === existingCompImportPath ||\n path.node.source.value === existingLoaderImportPath\n ) {\n path.remove()\n }\n },\n })\n }\n },\n },\n })\n\n deadCodeElimination(ast)\n\n return generate(ast, {\n sourceMaps: true,\n })\n}\n\nconst splitNodeTypes = ['component', 'loader'] as const\ntype SplitNodeType = (typeof splitNodeTypes)[number]\n\nexport function compileCodeSplitVirtualRoute(opts: ParseAstOptions) {\n const ast = parseAst(opts)\n\n if (!ast) {\n throw new Error(\n `Failed to compile ast for compileCodeSplitVirtualRoute() for the file: ${opts.filename}`,\n )\n }\n\n babel.traverse(ast, {\n Program: {\n enter(programPath, programState) {\n const state = programState as unknown as State\n\n const splitNodesByType: Record<SplitNodeType, t.Node | undefined> = {\n component: undefined,\n loader: undefined,\n }\n\n // Find the node\n programPath.traverse(\n {\n CallExpression: (path) => {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n\n if (\n !(\n path.node.callee.name === 'createRoute' ||\n path.node.callee.name === 'createFileRoute'\n )\n ) {\n return\n }\n\n if (t.isCallExpression(path.parentPath.node)) {\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 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(splitNode.name)\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 (\n t.isImportSpecifier(splitNode) ||\n t.isImportDefaultSpecifier(splitNode)\n ) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitType),\n splitNode.local,\n ),\n ]),\n )\n } else if (t.isCallExpression(splitNode)) {\n const outputSplitNodeCode = generate(splitNode).code\n const splitNodeAst = babel.parse(outputSplitNodeCode)\n\n if (!splitNodeAst) {\n throw new Error(\n `Failed to parse the generated code for \"${splitType}\" in the node type \"${splitNode.type}\"`,\n )\n }\n\n const statement = splitNodeAst.program.body[0]\n\n if (!statement) {\n throw new Error(\n `Failed to parse the generated code for \"${splitType}\" in the node type \"${splitNode.type}\" as no statement was found in the program body`,\n )\n }\n\n if (t.isExpressionStatement(statement)) {\n const expression = statement.expression\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(t.identifier(splitType), expression),\n ]),\n )\n } else {\n throw new Error(\n `Unexpected expression type encounter for \"${splitType}\" in the node type \"${splitNode.type}\"`,\n )\n }\n } else {\n console.info('Unexpected splitNode type:', splitNode)\n throw new Error(`Unexpected splitNode type ☝️: ${splitNode.type}`)\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((node) => {\n return node !== splitNode\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(`?${splitPrefix}`)[0] as string,\n ),\n ),\n )\n }\n }\n },\n })\n },\n },\n })\n\n deadCodeElimination(ast)\n\n return generate(ast, {\n sourceMaps: true,\n })\n}\n\nfunction getImportSpecifierAndPathFromLocalName(\n programPath: babel.NodePath<t.Program>,\n name: string,\n): {\n specifier:\n | t.ImportSpecifier\n | t.ImportDefaultSpecifier\n | t.ImportNamespaceSpecifier\n | null\n path: string | null\n} {\n let specifier:\n | t.ImportSpecifier\n | t.ImportDefaultSpecifier\n | t.ImportNamespaceSpecifier\n | null = null\n let path: string | null = null\n\n programPath.traverse({\n ImportDeclaration(importPath) {\n const found = importPath.node.specifiers.find(\n (targetSpecifier) => targetSpecifier.local.name === name,\n )\n if (found) {\n specifier = found\n path = importPath.node.source.value\n }\n },\n })\n\n return { specifier, path }\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"],"names":["babel"],"mappings":";;;;;;;AAYA,IAAI,WAAY,UAAkB,SAAS;AAG3C,IAAI,CAAC,UAAU;AACF,aAAA;AACb;AAoBO,SAAS,+BAA+B,MAAuB;AAC9D,QAAA,MAAM,SAAS,IAAI;AAEzB,MAAI,CAAC,KAAK;AACR,UAAM,IAAI;AAAA,MACR,4EAA4E,KAAK,QAAQ;AAAA,IAAA;AAAA,EAE7F;AAEAA,iBAAM,SAAS,KAAK;AAAA,IAClB,SAAS;AAAA,MACP,MAAM,aAAa,cAAc;AAC/B,cAAM,QAAQ;AAEd,cAAM,WAAW,GAAG,WAAW,IAAI,KAAK,QAAQ,IAAI,WAAW;AAW/D,YAAI,yBAAwC;AAC5C,YAAI,2BAA0C;AAElC,oBAAA;AAAA,UACV;AAAA,YACE,gBAAgB,CAAC,SAAS;AACxB,kBAAI,CAAC,EAAE,aAAa,KAAK,KAAK,MAAM,GAAG;AACrC;AAAA,cACF;AAGE,kBAAA,EACE,KAAK,KAAK,OAAO,SAAS,iBAC1B,KAAK,KAAK,OAAO,SAAS,oBAE5B;AACA;AAAA,cACF;AAEA,kBAAI,EAAE,iBAAiB,KAAK,WAAW,IAAI,GAAG;AAC5C,sBAAM,UAAU;AAAA,kBACd;AAAA,kBACA,KAAK,WAAW,KAAK,UAAU,CAAC;AAAA,gBAAA;AAGlC,oBAAI,QAAQ;AAEN,sBAAA,iCAAiC,CAAC,SAAiB;AAChD,yBAAA,YAAY,MAAM,WAAW,IAAI;AAAA,gBAAA;AAGtC,oBAAA,EAAE,mBAAmB,OAAO,GAAG;AACzB,0BAAA,WAAW,QAAQ,CAAC,S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,CAAC,oBAAoB,gBAAgB,MAAM,SAAS;AAAA,MAAA;AAEtD,UAAI,OAAO;AACG,oBAAA;AACL,eAAA,WAAW,KAAK,OAAO;AAAA,MAChC;AAAA,IACF;AAAA,EAAA,CACD;AAEM,SAAA,EAAE,WAAW;AACtB;AAGA,SAAS,kBAAkB,MAAW,MAAW;AAC3C,MAAA,EAAE,aAAa,IAAI,GAAG;AACxB,UAAM,UAAU,KAAK,MAAM,WAAW,KAAK,IAAI;AAC/C,QACE,SAEA;AACM,YAAA,aAAa,QAAQ,KAAK;AAChC,UAAI,EAAE,mBAAmB,WAAW,IAAI,GAAG;AACzC,eAAO,WAAW;AAAA,MACT,WAAA,EAAE,sBAAsB,WAAW,IAAI,GAAG;AACnD,eAAO,WAAW;AAAA,MACpB;AAAA,IACF;AACO,WAAA;AAAA,EACT;AAEO,SAAA;AACT;AAEA,SAAS,wBAAwB,MAAW,MAAW;AACjD,MAAA,EAAE,aAAa,IAAI,GAAG;AACxB,UAAM,UAAU,KAAK,MAAM,WAAW,KAAK,IAAI;AAC/C,QAAI,SAAS;AACX,cAAQ,KAAK;IACf;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"compilers.js","sources":["../../../../src/core/code-splitter/compilers.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport babel from '@babel/core'\nimport _generate from '@babel/generator'\nimport * as template from '@babel/template'\nimport { deadCodeElimination } from 'babel-dead-code-elimination'\n\nimport { splitPrefix } from '../constants'\nimport { parseAst } from './ast'\nimport type { ParseAstOptions } from './ast'\n\n// Babel is a CJS package and uses `default` as named binding (`exports.default =`).\n// https://github.com/babel/babel/issues/15269.\nlet generate = (_generate as any)['default'] as typeof _generate\n\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\nif (!generate) {\n generate = _generate\n}\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 function compileCodeSplitReferenceRoute(opts: ParseAstOptions) {\n const ast = parseAst(opts)\n\n if (!ast) {\n throw new Error(\n `Failed to compile ast for compileCodeSplitReferenceRoute() for the file: ${opts.filename}`,\n )\n }\n\n babel.traverse(ast, {\n Program: {\n enter(programPath, programState) {\n const state = programState as unknown as State\n\n const splitUrl = `${splitPrefix}:${opts.filename}?${splitPrefix}`\n\n /**\n * If the component for the route is being imported from\n * another file, this is to track the path to that file\n * the path itself doesn't matter, we just need to keep\n * track of it so that we can remove it from the imports\n * list if it's not being used like:\n *\n * `import '../shared/imported'`\n */\n let existingCompImportPath: string | null = null\n let existingLoaderImportPath: string | null = null\n\n programPath.traverse(\n {\n CallExpression: (path) => {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n\n if (\n !(\n path.node.callee.name === 'createRoute' ||\n path.node.callee.name === 'createFileRoute'\n )\n ) {\n return\n }\n\n if (t.isCallExpression(path.parentPath.node)) {\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n let found = false\n\n const hasImportedOrDefinedIdentifier = (name: string) => {\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 let shouldSplit = true\n\n if (t.isIdentifier(value)) {\n existingCompImportPath =\n getImportSpecifierAndPathFromLocalName(\n programPath,\n value.name,\n ).path\n\n // exported identifiers should not be split\n // since they are already being imported\n // and need to be retained in the compiled file\n const isExported = hasExport(ast, value)\n shouldSplit = !isExported\n\n if (shouldSplit) {\n removeIdentifierLiteral(path, value)\n }\n }\n\n if (shouldSplit) {\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.statement(\n `import { lazyRouteComponent } from '@tanstack/react-router'`,\n )(),\n ])\n }\n\n if (\n !hasImportedOrDefinedIdentifier(\n '$$splitComponentImporter',\n )\n ) {\n programPath.unshiftContainer('body', [\n template.statement(\n `const $$splitComponentImporter = () => import('${splitUrl}')`,\n )(),\n ])\n }\n\n prop.value = template.expression(\n `lazyRouteComponent($$splitComponentImporter, 'component')`,\n )()\n\n programPath.pushContainer('body', [\n template.statement(\n `function DummyComponent() { return null }`,\n )(),\n ])\n\n found = true\n }\n } else if (prop.key.name === 'loader') {\n const value = prop.value\n\n let shouldSplit = true\n\n if (t.isIdentifier(value)) {\n existingLoaderImportPath =\n getImportSpecifierAndPathFromLocalName(\n programPath,\n value.name,\n ).path\n\n // exported identifiers should not be split\n // since they are already being imported\n // and need to be retained in the compiled file\n const isExported = hasExport(ast, value)\n shouldSplit = !isExported\n\n if (shouldSplit) {\n removeIdentifierLiteral(path, value)\n }\n }\n\n if (shouldSplit) {\n // Prepend the import statement to the program along with the importer function\n if (!hasImportedOrDefinedIdentifier('lazyFn')) {\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.statement(\n `const $$splitLoaderImporter = () => import('${splitUrl}')`,\n )(),\n ])\n }\n\n prop.value = template.expression(\n `lazyFn($$splitLoaderImporter, 'loader')`,\n )()\n\n found = true\n }\n }\n }\n }\n\n programPath.scope.crawl()\n })\n }\n\n if (found as boolean) {\n programPath.pushContainer('body', [\n template.statement(`function TSR_Dummy_Component() {}`)(),\n ])\n }\n }\n },\n },\n state,\n )\n\n /**\n * If the component for the route is being imported,\n * and it's not being used, remove the import statement\n * from the program, by checking that the import has no\n * specifiers\n */\n if (\n (existingCompImportPath as string | null) ||\n (existingLoaderImportPath as string | null)\n ) {\n programPath.traverse({\n ImportDeclaration(path) {\n if (path.node.specifiers.length > 0) return\n if (\n path.node.source.value === existingCompImportPath ||\n path.node.source.value === existingLoaderImportPath\n ) {\n path.remove()\n }\n },\n })\n }\n },\n },\n })\n\n deadCodeElimination(ast)\n\n return generate(ast, {\n sourceMaps: true,\n })\n}\n\nconst splitNodeTypes = ['component', 'loader'] as const\ntype SplitNodeType = (typeof splitNodeTypes)[number]\n\nexport function compileCodeSplitVirtualRoute(opts: ParseAstOptions) {\n const ast = parseAst(opts)\n\n if (!ast) {\n throw new Error(\n `Failed to compile ast for compileCodeSplitVirtualRoute() for the file: ${opts.filename}`,\n )\n }\n\n const knownExportedIdents = new Set<string>()\n\n babel.traverse(ast, {\n Program: {\n enter(programPath, programState) {\n const state = programState as unknown as State\n\n const splitNodesByType: Record<SplitNodeType, t.Node | undefined> = {\n component: undefined,\n loader: undefined,\n }\n\n // Find the node\n programPath.traverse(\n {\n CallExpression: (path) => {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n\n if (\n !(\n path.node.callee.name === 'createRoute' ||\n path.node.callee.name === 'createFileRoute'\n )\n ) {\n return\n }\n\n if (t.isCallExpression(path.parentPath.node)) {\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((splitType) => {\n if (\n !t.isIdentifier(prop.key) ||\n prop.key.name !== splitType\n ) {\n return\n }\n\n const value = prop.value\n\n let isExported = false\n if (t.isIdentifier(value)) {\n isExported = hasExport(ast, value)\n if (isExported) {\n knownExportedIdents.add(value.name)\n }\n }\n\n // If the node is exported, we need to remove\n // the export from the split file\n if (isExported && t.isIdentifier(value)) {\n removeExports(ast, value)\n } else {\n splitNodesByType[splitType] = prop.value\n }\n })\n }\n })\n\n // Remove all of the options\n options.properties = []\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(splitNode.name)\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 (\n t.isImportSpecifier(splitNode) ||\n t.isImportDefaultSpecifier(splitNode)\n ) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitType),\n splitNode.local,\n ),\n ]),\n )\n } else if (t.isCallExpression(splitNode)) {\n const outputSplitNodeCode = generate(splitNode).code\n const splitNodeAst = babel.parse(outputSplitNodeCode)\n\n if (!splitNodeAst) {\n throw new Error(\n `Failed to parse the generated code for \"${splitType}\" in the node type \"${splitNode.type}\"`,\n )\n }\n\n const statement = splitNodeAst.program.body[0]\n\n if (!statement) {\n throw new Error(\n `Failed to parse the generated code for \"${splitType}\" in the node type \"${splitNode.type}\" as no statement was found in the program body`,\n )\n }\n\n if (t.isExpressionStatement(statement)) {\n const expression = statement.expression\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(t.identifier(splitType), expression),\n ]),\n )\n } else {\n throw new Error(\n `Unexpected expression type encounter for \"${splitType}\" in the node type \"${splitNode.type}\"`,\n )\n }\n } else {\n console.info('Unexpected splitNode type:', splitNode)\n throw new Error(`Unexpected splitNode type ☝️: ${splitNode.type}`)\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((node) => {\n return node !== splitNode\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(`?${splitPrefix}`)[0] as string,\n ),\n ),\n )\n }\n }\n },\n })\n },\n },\n })\n\n deadCodeElimination(ast)\n\n // if there are exported identifiers, then we need to add a warning\n // to the file to let the user know that the exported identifiers\n // will not in the split file but in the original file, therefore\n // increasing the bundle size\n if (knownExportedIdents.size > 0) {\n const list = Array.from(knownExportedIdents).reduce((str, ident) => {\n str += `\\n- ${ident}`\n return str\n }, '')\n\n const warningMessage = `These exports from \"${opts.filename.replace('?' + splitPrefix, '')}\" are not being code-split and will increase your bundle size: ${list}\\nThese should either have their export statements removed or be imported from another file that is not a route.`\n console.warn(warningMessage)\n\n // append this warning to the file using a template\n if (process.env.NODE_ENV !== 'production') {\n const warningTemplate = template.statement(\n `console.warn(${JSON.stringify(warningMessage)})`,\n )()\n ast.program.body.unshift(warningTemplate)\n }\n }\n\n return generate(ast, {\n sourceMaps: true,\n })\n}\n\nfunction getImportSpecifierAndPathFromLocalName(\n programPath: babel.NodePath<t.Program>,\n name: string,\n): {\n specifier:\n | t.ImportSpecifier\n | t.ImportDefaultSpecifier\n | t.ImportNamespaceSpecifier\n | null\n path: string | null\n} {\n let specifier:\n | t.ImportSpecifier\n | t.ImportDefaultSpecifier\n | t.ImportNamespaceSpecifier\n | null = null\n let path: string | null = null\n\n programPath.traverse({\n ImportDeclaration(importPath) {\n const found = importPath.node.specifiers.find(\n (targetSpecifier) => targetSpecifier.local.name === name,\n )\n if (found) {\n specifier = found\n path = importPath.node.source.value\n }\n },\n })\n\n return { specifier, path }\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\nfunction hasExport(ast: t.File, node: t.Identifier): boolean {\n let found = false\n\n babel.traverse(ast, {\n ExportNamedDeclaration(path) {\n if (path.node.declaration) {\n // declared as `const loaderFn = () => {}`\n if (t.isVariableDeclaration(path.node.declaration)) {\n path.node.declaration.declarations.forEach((decl) => {\n if (t.isVariableDeclarator(decl)) {\n if (t.isIdentifier(decl.id)) {\n if (decl.id.name === node.name) {\n found = true\n }\n }\n }\n })\n }\n\n // declared as `function loaderFn() {}`\n if (t.isFunctionDeclaration(path.node.declaration)) {\n if (t.isIdentifier(path.node.declaration.id)) {\n if (path.node.declaration.id.name === node.name) {\n found = true\n }\n }\n }\n }\n },\n ExportDefaultDeclaration(path) {\n if (t.isIdentifier(path.node.declaration)) {\n if (path.node.declaration.name === node.name) {\n found = true\n }\n }\n },\n })\n\n return found\n}\n\nfunction removeExports(ast: t.File, node: t.Identifier): boolean {\n let removed = false\n\n babel.traverse(ast, {\n ExportNamedDeclaration(path) {\n if (path.node.declaration) {\n // declared as `const loaderFn = () => {}`\n if (t.isVariableDeclaration(path.node.declaration)) {\n path.node.declaration.declarations.forEach((decl) => {\n if (t.isVariableDeclarator(decl)) {\n if (t.isIdentifier(decl.id)) {\n if (decl.id.name === node.name) {\n path.remove()\n removed = true\n }\n }\n }\n })\n } else if (t.isFunctionDeclaration(path.node.declaration)) {\n if (t.isIdentifier(path.node.declaration.id)) {\n if (path.node.declaration.id.name === node.name) {\n path.remove()\n removed = true\n }\n }\n }\n }\n },\n ExportDefaultDeclaration(path) {\n if (t.isIdentifier(path.node.declaration)) {\n if (path.node.declaration.name === node.name) {\n path.remove()\n removed = true\n }\n }\n },\n })\n\n return removed\n}\n"],"names":["babel"],"mappings":";;;;;;;AAYA,IAAI,WAAY,UAAkB,SAAS;AAG3C,IAAI,CAAC,UAAU;AACF,aAAA;AACb;AAoBO,SAAS,+BAA+B,MAAuB;AAC9D,QAAA,MAAM,SAAS,IAAI;AAEzB,MAAI,CAAC,KAAK;AACR,UAAM,IAAI;AAAA,MACR,4EAA4E,KAAK,QAAQ;AAAA,IAAA;AAAA,EAE7F;AAEAA,iBAAM,SAAS,KAAK;AAAA,IAClB,SAAS;AAAA,MACP,MAAM,aAAa,cAAc;AAC/B,cAAM,QAAQ;AAEd,cAAM,WAAW,GAAG,WAAW,IAAI,KAAK,QAAQ,IAAI,WAAW;AAW/D,YAAI,yBAAwC;AAC5C,YAAI,2BAA0C;AAElC,oBAAA;AAAA,UACV;AAAA,YACE,gBAAgB,CAAC,SAAS;AACxB,kBAAI,CAAC,EAAE,aAAa,KAAK,KAAK,MAAM,GAAG;AACrC;AAAA,cACF;AAGE,kBAAA,EACE,KAAK,KAAK,OAAO,SAAS,iBAC1B,KAAK,KAAK,OAAO,SAAS,oBAE5B;AACA;AAAA,cACF;AAEA,kBAAI,EAAE,iBAAiB,KAAK,WAAW,IAAI,GAAG;AAC5C,sBAAM,UAAU;AAAA,kBACd;AAAA,kBACA,KAAK,WAAW,KAAK,UAAU,CAAC;AAAA,gBAAA;AAGlC,oBAAI,QAAQ;AAEN,sBAAA,iCAAiC,CAAC,SAAiB;AAChD,yBA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from "node:path";
1
+ import { isAbsolute, join, normalize } from "node:path";
2
2
  import { pathToFileURL, fileURLToPath } from "node:url";
3
3
  import { getConfig } from "./config.js";
4
4
  import { compileCodeSplitVirtualRoute, compileCodeSplitReferenceRoute } from "./code-splitter/compilers.js";
@@ -8,7 +8,8 @@ function capitalizeFirst(str) {
8
8
  }
9
9
  function fileIsInRoutesDirectory(filePath, routesDirectory) {
10
10
  const routesDirectoryPath = isAbsolute(routesDirectory) ? routesDirectory : join(process.cwd(), routesDirectory);
11
- return filePath.startsWith(routesDirectoryPath);
11
+ const path = normalize(filePath);
12
+ return path.startsWith(routesDirectoryPath);
12
13
  }
13
14
  const bannedBeforeExternalPlugins = [
14
15
  {
@@ -1 +1 @@
1
- {"version":3,"file":"router-code-splitter-plugin.js","sources":["../../../src/core/router-code-splitter-plugin.ts"],"sourcesContent":["import { isAbsolute, join } from 'node:path'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\n\nimport { getConfig } from './config'\nimport {\n compileCodeSplitReferenceRoute,\n compileCodeSplitVirtualRoute,\n} from './code-splitter/compilers'\nimport { splitPrefix } from './constants'\n\nimport type { Config } from './config'\nimport type { UnpluginContextMeta, 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\ntype BannedBeforeExternalPlugin = {\n identifier: string\n pkg: string\n usage: string\n frameworks: Array<UnpluginContextMeta['framework']>\n}\n\nconst bannedBeforeExternalPlugins: Array<BannedBeforeExternalPlugin> = [\n {\n identifier: '@react-refresh',\n pkg: '@vitejs/plugin-react',\n usage: 'viteReact()',\n frameworks: ['vite'],\n },\n]\n\nclass FoundPluginInBeforeCode extends Error {\n constructor(externalPlugin: BannedBeforeExternalPlugin, framework: string) {\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\nconst PLUGIN_NAME = 'unplugin:router-code-splitter'\nconst JoinedSplitPrefix = splitPrefix + ':'\n\nexport const unpluginRouterCodeSplitterFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}, { framework }) => {\n const debug = Boolean(process.env.TSR_VITE_DEBUG)\n\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n const handleSplittingFile = (code: string, id: string) => {\n if (debug) console.info('Splitting route: ', id)\n\n const compiledVirtualRoute = compileCodeSplitVirtualRoute({\n code,\n root: ROOT,\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(compiledVirtualRoute.code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n return compiledVirtualRoute\n }\n\n const handleCompilingFile = (code: string, id: string) => {\n if (debug) console.info('Handling createRoute: ', id)\n\n const compiledReferenceRoute = compileCodeSplitReferenceRoute({\n code,\n root: ROOT,\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(compiledReferenceRoute.code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n return compiledReferenceRoute\n }\n\n return {\n name: 'router-code-splitter-plugin',\n enforce: 'pre',\n\n resolveId(source) {\n if (!userConfig.autoCodeSplitting) {\n return null\n }\n\n if (source.startsWith(splitPrefix + ':')) {\n return source.replace(splitPrefix + ':', '')\n }\n return null\n },\n\n transform(code, id) {\n if (!userConfig.autoCodeSplitting) {\n return null\n }\n\n const url = pathToFileURL(id)\n url.searchParams.delete('v')\n id = fileURLToPath(url).replace(/\\\\/g, '/')\n\n if (id.includes(splitPrefix)) {\n return 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 (!externalPlugin.frameworks.includes(framework)) {\n continue\n }\n\n if (code.includes(externalPlugin.identifier)) {\n throw new FoundPluginInBeforeCode(externalPlugin, framework)\n }\n }\n\n return handleCompilingFile(code, id)\n }\n\n return null\n },\n\n transformInclude(transformId) {\n if (!userConfig.autoCodeSplitting) {\n return undefined\n }\n\n let id = transformId\n\n if (id.startsWith(JoinedSplitPrefix)) {\n id = id.replace(JoinedSplitPrefix, '')\n }\n\n if (\n fileIsInRoutesDirectory(id, userConfig.routesDirectory) ||\n id.includes(splitPrefix)\n ) {\n return true\n }\n return false\n },\n\n vite: {\n configResolved(config) {\n ROOT = config.root\n\n userConfig = getConfig(options, ROOT)\n },\n },\n\n rspack(compiler) {\n ROOT = process.cwd()\n\n compiler.hooks.beforeCompile.tap(PLUGIN_NAME, (self) => {\n self.normalModuleFactory.hooks.beforeResolve.tap(\n PLUGIN_NAME,\n (resolveData: { request: string }) => {\n if (resolveData.request.includes(JoinedSplitPrefix)) {\n resolveData.request = resolveData.request.replace(\n JoinedSplitPrefix,\n '',\n )\n }\n },\n )\n })\n\n userConfig = getConfig(options, ROOT)\n },\n\n webpack(compiler) {\n ROOT = process.cwd()\n\n compiler.hooks.beforeCompile.tap(PLUGIN_NAME, (self) => {\n self.normalModuleFactory.hooks.beforeResolve.tap(\n PLUGIN_NAME,\n (resolveData: { request: string }) => {\n if (resolveData.request.includes(JoinedSplitPrefix)) {\n resolveData.request = resolveData.request.replace(\n JoinedSplitPrefix,\n '',\n )\n }\n },\n )\n })\n\n userConfig = getConfig(options, ROOT)\n\n if (\n userConfig.autoCodeSplitting &&\n compiler.options.mode === 'production'\n ) {\n compiler.hooks.done.tap(PLUGIN_NAME, () => {\n console.info('✅ ' +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SAAS,iBAAiB,GAAG;AACvC,0BAAA,UAAU,YAAY,QAAQ;AAAA,gBACxC;AAAA,gBACA;AAAA,cAAA;AAAA,YAEJ;AAAA,UACF;AAAA,QAAA;AAAA,MACF,CACD;AAEY,mBAAA,UAAU,SAAS,IAAI;AAEpC,UACE,WAAW,qBACX,SAAS,QAAQ,SAAS,cAC1B;AACA,iBAAS,MAAM,KAAK,IAAI,aAAa,MAAM;AACjC,kBAAA,KAAK,OAAO,cAAc,wBAAwB;AAC1D,qBAAW,MAAM;AACf,oBAAQ,KAAK,CAAC;AAAA,UAAA,CACf;AAAA,QAAA,CACF;AAAA,MACH;AAAA,IACF;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"router-code-splitter-plugin.js","sources":["../../../src/core/router-code-splitter-plugin.ts"],"sourcesContent":["import { isAbsolute, join, normalize } from 'node:path'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\n\nimport { getConfig } from './config'\nimport {\n compileCodeSplitReferenceRoute,\n compileCodeSplitVirtualRoute,\n} from './code-splitter/compilers'\nimport { splitPrefix } from './constants'\n\nimport type { Config } from './config'\nimport type { UnpluginContextMeta, UnpluginFactory } from 'unplugin'\n\nfunction capitalizeFirst(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1)\n}\n\nfunction fileIsInRoutesDirectory(\n filePath: string,\n routesDirectory: string,\n): boolean {\n const routesDirectoryPath = isAbsolute(routesDirectory)\n ? routesDirectory\n : join(process.cwd(), routesDirectory)\n\n const path = normalize(filePath)\n\n return path.startsWith(routesDirectoryPath)\n}\n\ntype BannedBeforeExternalPlugin = {\n identifier: string\n pkg: string\n usage: string\n frameworks: Array<UnpluginContextMeta['framework']>\n}\n\nconst bannedBeforeExternalPlugins: Array<BannedBeforeExternalPlugin> = [\n {\n identifier: '@react-refresh',\n pkg: '@vitejs/plugin-react',\n usage: 'viteReact()',\n frameworks: ['vite'],\n },\n]\n\nclass FoundPluginInBeforeCode extends Error {\n constructor(externalPlugin: BannedBeforeExternalPlugin, framework: string) {\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\nconst PLUGIN_NAME = 'unplugin:router-code-splitter'\nconst JoinedSplitPrefix = splitPrefix + ':'\n\nexport const unpluginRouterCodeSplitterFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}, { framework }) => {\n const debug = Boolean(process.env.TSR_VITE_DEBUG)\n\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n const handleSplittingFile = (code: string, id: string) => {\n if (debug) console.info('Splitting route: ', id)\n\n const compiledVirtualRoute = compileCodeSplitVirtualRoute({\n code,\n root: ROOT,\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(compiledVirtualRoute.code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n return compiledVirtualRoute\n }\n\n const handleCompilingFile = (code: string, id: string) => {\n if (debug) console.info('Handling createRoute: ', id)\n\n const compiledReferenceRoute = compileCodeSplitReferenceRoute({\n code,\n root: ROOT,\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(compiledReferenceRoute.code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n return compiledReferenceRoute\n }\n\n return {\n name: 'router-code-splitter-plugin',\n enforce: 'pre',\n\n resolveId(source) {\n if (!userConfig.autoCodeSplitting) {\n return null\n }\n\n if (source.startsWith(splitPrefix + ':')) {\n return source.replace(splitPrefix + ':', '')\n }\n return null\n },\n\n transform(code, id) {\n if (!userConfig.autoCodeSplitting) {\n return null\n }\n\n const url = pathToFileURL(id)\n url.searchParams.delete('v')\n id = fileURLToPath(url).replace(/\\\\/g, '/')\n\n if (id.includes(splitPrefix)) {\n return 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 (!externalPlugin.frameworks.includes(framework)) {\n continue\n }\n\n if (code.includes(externalPlugin.identifier)) {\n throw new FoundPluginInBeforeCode(externalPlugin, framework)\n }\n }\n\n return handleCompilingFile(code, id)\n }\n\n return null\n },\n\n transformInclude(transformId) {\n if (!userConfig.autoCodeSplitting) {\n return undefined\n }\n\n let id = transformId\n\n if (id.startsWith(JoinedSplitPrefix)) {\n id = id.replace(JoinedSplitPrefix, '')\n }\n\n if (\n fileIsInRoutesDirectory(id, userConfig.routesDirectory) ||\n id.includes(splitPrefix)\n ) {\n return true\n }\n return false\n },\n\n vite: {\n configResolved(config) {\n ROOT = config.root\n\n userConfig = getConfig(options, ROOT)\n },\n },\n\n rspack(compiler) {\n ROOT = process.cwd()\n\n compiler.hooks.beforeCompile.tap(PLUGIN_NAME, (self) => {\n self.normalModuleFactory.hooks.beforeResolve.tap(\n PLUGIN_NAME,\n (resolveData: { request: string }) => {\n if (resolveData.request.includes(JoinedSplitPrefix)) {\n resolveData.request = resolveData.request.replace(\n JoinedSplitPrefix,\n '',\n )\n }\n },\n )\n })\n\n userConfig = getConfig(options, ROOT)\n },\n\n webpack(compiler) {\n ROOT = process.cwd()\n\n compiler.hooks.beforeCompile.tap(PLUGIN_NAME, (self) => {\n self.normalModuleFactory.hooks.beforeResolve.tap(\n PLUGIN_NAME,\n (resolveData: { request: string }) => {\n if (resolveData.request.includes(JoinedSplitPrefix)) {\n resolveData.request = resolveData.request.replace(\n JoinedSplitPrefix,\n '',\n )\n }\n },\n )\n })\n\n userConfig = getConfig(options, ROOT)\n\n if (\n userConfig.autoCodeSplitting &&\n compiler.options.mode === 'production'\n ) {\n compiler.hooks.done.tap(PLUGIN_NAME, () => {\n console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gBAAqC;AACpC,gBAAI,YAAY,QAAQ,SAAS,iBAAiB,GAAG;AACvC,0BAAA,UAAU,YAAY,QAAQ;AAAA,gBACxC;AAAA,gBACA;AAAA,cAAA;AAAA,YAEJ;AAAA,UACF;AAAA,QAAA;AAAA,MACF,CACD;AAEY,mBAAA,UAAU,SAAS,IAAI;AAEpC,UACE,WAAW,qBACX,SAAS,QAAQ,SAAS,cAC1B;AACA,iBAAS,MAAM,KAAK,IAAI,aAAa,MAAM;AACjC,kBAAA,KAAK,OAAO,cAAc,wBAAwB;AAC1D,qBAAW,MAAM;AACf,oBAAQ,KAAK,CAAC;AAAA,UAAA,CACf;AAAA,QAAA,CACF;AAAA,MACH;AAAA,IACF;AAAA,EAAA;AAEJ;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/router-plugin",
3
- "version": "1.58.1",
3
+ "version": "1.58.4",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -92,8 +92,8 @@
92
92
  "chokidar": "^3.6.0",
93
93
  "unplugin": "^1.12.2",
94
94
  "zod": "^3.23.8",
95
- "@tanstack/router-generator": "^1.58.1",
96
- "@tanstack/virtual-file-routes": "^1.56.0"
95
+ "@tanstack/virtual-file-routes": "^1.56.0",
96
+ "@tanstack/router-generator": "^1.58.1"
97
97
  },
98
98
  "peerDependencies": {
99
99
  "@rsbuild/core": ">=1.0.2",