@tanstack/router-plugin 1.87.6 → 1.87.10

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 (30) hide show
  1. package/dist/cjs/core/code-splitter/ast.cjs +8 -44
  2. package/dist/cjs/core/code-splitter/ast.cjs.map +1 -1
  3. package/dist/cjs/core/code-splitter/ast.d.cts +1 -2
  4. package/dist/cjs/core/code-splitter/compilers.cjs +26 -10
  5. package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -1
  6. package/dist/cjs/core/constants.cjs +0 -2
  7. package/dist/cjs/core/constants.cjs.map +1 -1
  8. package/dist/cjs/core/constants.d.cts +0 -1
  9. package/dist/cjs/core/router-code-splitter-plugin.cjs +9 -2
  10. package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
  11. package/dist/cjs/core/router-generator-plugin.cjs +1 -2
  12. package/dist/cjs/core/router-generator-plugin.cjs.map +1 -1
  13. package/dist/esm/core/code-splitter/ast.d.ts +1 -2
  14. package/dist/esm/core/code-splitter/ast.js +8 -27
  15. package/dist/esm/core/code-splitter/ast.js.map +1 -1
  16. package/dist/esm/core/code-splitter/compilers.js +32 -16
  17. package/dist/esm/core/code-splitter/compilers.js.map +1 -1
  18. package/dist/esm/core/constants.d.ts +0 -1
  19. package/dist/esm/core/constants.js +0 -2
  20. package/dist/esm/core/constants.js.map +1 -1
  21. package/dist/esm/core/router-code-splitter-plugin.js +9 -2
  22. package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
  23. package/dist/esm/core/router-generator-plugin.js +2 -3
  24. package/dist/esm/core/router-generator-plugin.js.map +1 -1
  25. package/package.json +8 -8
  26. package/src/core/code-splitter/ast.ts +7 -32
  27. package/src/core/code-splitter/compilers.ts +31 -12
  28. package/src/core/constants.ts +0 -1
  29. package/src/core/router-code-splitter-plugin.ts +10 -2
  30. package/src/core/router-generator-plugin.ts +2 -3
@@ -1,50 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const babel = require("@babel/core");
4
- require("@babel/parser");
5
- const _babelPluginJsx = require("@babel/plugin-syntax-jsx");
6
- const _babelPluginTypeScript = require("@babel/plugin-syntax-typescript");
7
- function _interopNamespaceDefault(e) {
8
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
9
- if (e) {
10
- for (const k in e) {
11
- if (k !== "default") {
12
- const d = Object.getOwnPropertyDescriptor(e, k);
13
- Object.defineProperty(n, k, d.get ? d : {
14
- enumerable: true,
15
- get: () => e[k]
16
- });
17
- }
18
- }
19
- }
20
- n.default = e;
21
- return Object.freeze(n);
22
- }
23
- const babel__namespace = /* @__PURE__ */ _interopNamespaceDefault(babel);
24
- let babelPluginJsx = _babelPluginJsx;
25
- let babelPluginTypeScript = _babelPluginTypeScript;
26
- if (babelPluginJsx.default) {
27
- babelPluginJsx = babelPluginJsx.default;
28
- }
29
- if (babelPluginTypeScript.default) {
30
- babelPluginTypeScript = babelPluginTypeScript.default;
31
- }
3
+ const parser = require("@babel/parser");
32
4
  function parseAst(opts) {
33
- const babelPlugins = [
34
- babelPluginJsx,
35
- [
36
- babelPluginTypeScript,
37
- {
38
- isTSX: true
39
- }
40
- ]
41
- ];
42
- return babel__namespace.parse(opts.code, {
43
- plugins: babelPlugins,
44
- root: opts.root,
45
- filename: opts.filename,
46
- sourceMaps: true,
47
- sourceType: "module"
5
+ return parser.parse(opts.code, {
6
+ plugins: ["jsx", "typescript"],
7
+ sourceType: "module",
8
+ ...{
9
+ root: opts.root,
10
+ filename: opts.filename
11
+ }
48
12
  });
49
13
  }
50
14
  exports.parseAst = parseAst;
@@ -1 +1 @@
1
- {"version":3,"file":"ast.cjs","sources":["../../../../src/core/code-splitter/ast.ts"],"sourcesContent":["import * as babel from '@babel/core'\nimport '@babel/parser'\n// @ts-expect-error\nimport _babelPluginJsx from '@babel/plugin-syntax-jsx'\n// @ts-expect-error\nimport _babelPluginTypeScript from '@babel/plugin-syntax-typescript'\n\nlet babelPluginJsx = _babelPluginJsx\nlet babelPluginTypeScript = _babelPluginTypeScript\n\nif (babelPluginJsx.default) {\n babelPluginJsx = babelPluginJsx.default\n}\n\nif (babelPluginTypeScript.default) {\n babelPluginTypeScript = babelPluginTypeScript.default\n}\n\nexport type ParseAstOptions = {\n code: string\n filename: string\n root: string\n}\n\nexport function parseAst(opts: ParseAstOptions) {\n const babelPlugins: Array<babel.PluginItem> = [\n babelPluginJsx,\n [\n babelPluginTypeScript,\n {\n isTSX: true,\n },\n ],\n ]\n\n return babel.parse(opts.code, {\n plugins: babelPlugins,\n root: opts.root,\n filename: opts.filename,\n sourceMaps: true,\n sourceType: 'module',\n })\n}\n"],"names":["babel"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAOA,IAAI,iBAAiB;AACrB,IAAI,wBAAwB;AAE5B,IAAI,eAAe,SAAS;AAC1B,mBAAiB,eAAe;AAClC;AAEA,IAAI,sBAAsB,SAAS;AACjC,0BAAwB,sBAAsB;AAChD;AAQO,SAAS,SAAS,MAAuB;AAC9C,QAAM,eAAwC;AAAA,IAC5C;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,QACE,OAAO;AAAA,MAAA;AAAA,IACT;AAAA,EAEJ;AAEO,SAAAA,iBAAM,MAAM,KAAK,MAAM;AAAA,IAC5B,SAAS;AAAA,IACT,MAAM,KAAK;AAAA,IACX,UAAU,KAAK;AAAA,IACf,YAAY;AAAA,IACZ,YAAY;AAAA,EAAA,CACb;AACH;;"}
1
+ {"version":3,"file":"ast.cjs","sources":["../../../../src/core/code-splitter/ast.ts"],"sourcesContent":["import { parse } from '@babel/parser'\n\nexport type ParseAstOptions = {\n code: string\n filename: string\n root: string\n}\n\nexport function parseAst(opts: ParseAstOptions) {\n return parse(opts.code, {\n plugins: ['jsx', 'typescript'],\n sourceType: 'module',\n ...{\n root: opts.root,\n filename: opts.filename,\n },\n })\n}\n"],"names":["parse"],"mappings":";;;AAQO,SAAS,SAAS,MAAuB;AACvC,SAAAA,OAAA,MAAM,KAAK,MAAM;AAAA,IACtB,SAAS,CAAC,OAAO,YAAY;AAAA,IAC7B,YAAY;AAAA,IACZ,GAAG;AAAA,MACD,MAAM,KAAK;AAAA,MACX,UAAU,KAAK;AAAA,IAAA;AAAA,EACjB,CACD;AACH;;"}
@@ -1,7 +1,6 @@
1
- import * as babel from '@babel/core';
2
1
  export type ParseAstOptions = {
3
2
  code: string;
4
3
  filename: string;
5
4
  root: string;
6
5
  };
7
- export declare function parseAst(opts: ParseAstOptions): import('@babel/parser').ParseResult<babel.types.File> | null;
6
+ export declare function parseAst(opts: ParseAstOptions): import('@babel/parser').ParseResult<import('@babel/types').File>;
@@ -25,17 +25,13 @@ function _interopNamespaceDefault(e) {
25
25
  }
26
26
  const t__namespace = /* @__PURE__ */ _interopNamespaceDefault(t);
27
27
  const template__namespace = /* @__PURE__ */ _interopNamespaceDefault(template);
28
+ const debug = process.env.TSR_VITE_DEBUG;
28
29
  let generate = _generate["default"];
29
30
  if (!generate) {
30
31
  generate = _generate;
31
32
  }
32
33
  function compileCodeSplitReferenceRoute(opts) {
33
34
  const ast$1 = ast.parseAst(opts);
34
- if (!ast$1) {
35
- throw new Error(
36
- `Failed to compile ast for compileCodeSplitReferenceRoute() for the file: ${opts.filename}`
37
- );
38
- }
39
35
  babel.traverse(ast$1, {
40
36
  Program: {
41
37
  enter(programPath, programState) {
@@ -173,7 +169,19 @@ function compileCodeSplitReferenceRoute(opts) {
173
169
  }
174
170
  }
175
171
  });
172
+ if (debug) console.info("");
173
+ if (debug) console.info("Dead Code Elimination Input 1:");
174
+ if (debug) console.info(generate(ast$1, { sourceMaps: true }).code);
175
+ if (debug) console.info("");
176
+ if (debug) console.info("");
177
+ if (debug) console.info("");
176
178
  babelDeadCodeElimination.deadCodeElimination(ast$1);
179
+ if (debug) console.info("");
180
+ if (debug) console.info("Dead Code Elimination Output 1:");
181
+ if (debug) console.info(generate(ast$1, { sourceMaps: true }).code);
182
+ if (debug) console.info("");
183
+ if (debug) console.info("");
184
+ if (debug) console.info("");
177
185
  return generate(ast$1, {
178
186
  sourceMaps: true
179
187
  });
@@ -181,11 +189,6 @@ function compileCodeSplitReferenceRoute(opts) {
181
189
  const splitNodeTypes = ["component", "loader"];
182
190
  function compileCodeSplitVirtualRoute(opts) {
183
191
  const ast$1 = ast.parseAst(opts);
184
- if (!ast$1) {
185
- throw new Error(
186
- `Failed to compile ast for compileCodeSplitVirtualRoute() for the file: ${opts.filename}`
187
- );
188
- }
189
192
  const knownExportedIdents = /* @__PURE__ */ new Set();
190
193
  babel.traverse(ast$1, {
191
194
  Program: {
@@ -361,7 +364,20 @@ function compileCodeSplitVirtualRoute(opts) {
361
364
  }
362
365
  }
363
366
  });
367
+ if (debug) console.info("");
368
+ if (debug) console.info("Dead Code Elimination Input 2:");
369
+ console.log(JSON.stringify(ast$1, null, 2));
370
+ if (debug) console.info(generate(ast$1, { sourceMaps: true }).code);
371
+ if (debug) console.info("");
372
+ if (debug) console.info("");
373
+ if (debug) console.info("");
364
374
  babelDeadCodeElimination.deadCodeElimination(ast$1);
375
+ if (debug) console.info("");
376
+ if (debug) console.info("Dead Code Elimination Output 2:");
377
+ if (debug) console.info(generate(ast$1, { sourceMaps: true }).code);
378
+ if (debug) console.info("");
379
+ if (debug) console.info("");
380
+ if (debug) console.info("");
365
381
  if (knownExportedIdents.size > 0) {
366
382
  const list = Array.from(knownExportedIdents).reduce((str, ident) => {
367
383
  str += `
@@ -1 +1 @@
1
- {"version":3,"file":"compilers.cjs","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', () => Route.ssr)`,\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.isVariableDeclarator(splitNode)) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(t.identifier(splitType), splitNode.init),\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":["ast","parseAst","splitPrefix","t","template","deadCodeElimination"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,IAAI,WAAY,UAAkB,SAAS;AAG3C,IAAI,CAAC,UAAU;AACF,aAAA;AACb;AAoBO,SAAS,+BAA+B,MAAuB;AAC9D,QAAAA,QAAMC,aAAS,IAAI;AAEzB,MAAI,CAACD,OAAK;AACR,UAAM,IAAI;AAAA,MACR,4EAA4E,KAAK,QAAQ;AAAA,IAC3F;AAAA,EAAA;AAGF,QAAM,SAASA,OAAK;AAAA,IAClB,SAAS;AAAA,MACP,MAAM,aAAa,cAAc;AAC/B,cAAM,QAAQ;AAEd,cAAM,WAAW,GAAGE,qBAAW,IAAI,KAAK,QAAQ,IAAIA,UAAAA,WAAW;AAW/D,YAAI,yBAAwC;AAC5C,YAAI,2BAA0C;AAElC,oBAAA;AAAA,UACV;AAAA,Y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AAEzB,YAAIG,aAAE,sBAAsB,KAAK,KAAK,WAAW,GAAG;AAClD,eAAK,KAAK,YAAY,aAAa,QAAQ,CAAC,SAAS;AAC/C,gBAAAA,aAAE,qBAAqB,IAAI,GAAG;AAChC,kBAAIA,aAAE,aAAa,KAAK,EAAE,GAAG;AAC3B,oBAAI,KAAK,GAAG,SAAS,KAAK,MAAM;AAC9B,uBAAK,OAAO;AACF,4BAAA;AAAA,gBAAA;AAAA,cACZ;AAAA,YACF;AAAA,UACF,CACD;AAAA,QAAA,WACQA,aAAE,sBAAsB,KAAK,KAAK,WAAW,GAAG;AACzD,cAAIA,aAAE,aAAa,KAAK,KAAK,YAAY,EAAE,GAAG;AAC5C,gBAAI,KAAK,KAAK,YAAY,GAAG,SAAS,KAAK,MAAM;AAC/C,mBAAK,OAAO;AACF,wBAAA;AAAA,YAAA;AAAA,UACZ;AAAA,QACF;AAAA,MACF;AAAA,IAEJ;AAAA,IACA,yBAAyB,MAAM;AAC7B,UAAIA,aAAE,aAAa,KAAK,KAAK,WAAW,GAAG;AACzC,YAAI,KAAK,KAAK,YAAY,SAAS,KAAK,MAAM;AAC5C,eAAK,OAAO;AACF,oBAAA;AAAA,QAAA;AAAA,MACZ;AAAA,IACF;AAAA,EACF,CACD;AAEM,SAAA;AACT;;;"}
1
+ {"version":3,"file":"compilers.cjs","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\nconst debug = process.env.TSR_VITE_DEBUG\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 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', () => Route.ssr)`,\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 if (debug) console.info('')\n if (debug) console.info('Dead Code Elimination Input 1:')\n if (debug) console.info(generate(ast, { sourceMaps: true }).code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n deadCodeElimination(ast)\n\n if (debug) console.info('')\n if (debug) console.info('Dead Code Elimination Output 1:')\n if (debug) console.info(generate(ast, { sourceMaps: true }).code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\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 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.isVariableDeclarator(splitNode)) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(t.identifier(splitType), splitNode.init),\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 if (debug) console.info('')\n if (debug) console.info('Dead Code Elimination Input 2:')\n console.log(JSON.stringify(ast, null, 2))\n if (debug) console.info(generate(ast, { sourceMaps: true }).code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n deadCodeElimination(ast)\n\n if (debug) console.info('')\n if (debug) console.info('Dead Code Elimination Output 2:')\n if (debug) console.info(generate(ast, { sourceMaps: true }).code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\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":["ast","parseAst","splitPrefix","t","template","deadCodeElimination"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAM,QAAQ,QAAQ,IAAI;AAI1B,IAAI,WAAY,UAAkB,SAAS;AAG3C,IAAI,CAAC,UAAU;AACF,aAAA;AACb;AAoBO,SAAS,+BAA+B,MAAuB;AAC9D,QAAAA,QAAMC,aAAS,IAAI;AAEzB,QAAM,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AAE,sBAAsB,KAAK,KAAK,WAAW,GAAG;AAClD,eAAK,KAAK,YAAY,aAAa,QAAQ,CAAC,SAAS;AAC/C,gBAAAA,aAAE,qBAAqB,IAAI,GAAG;AAChC,kBAAIA,aAAE,aAAa,KAAK,EAAE,GAAG;AAC3B,oBAAI,KAAK,GAAG,SAAS,KAAK,MAAM;AAC9B,uBAAK,OAAO;AACF,4BAAA;AAAA,gBAAA;AAAA,cACZ;AAAA,YACF;AAAA,UACF,CACD;AAAA,QAAA,WACQA,aAAE,sBAAsB,KAAK,KAAK,WAAW,GAAG;AACzD,cAAIA,aAAE,aAAa,KAAK,KAAK,YAAY,EAAE,GAAG;AAC5C,gBAAI,KAAK,KAAK,YAAY,GAAG,SAAS,KAAK,MAAM;AAC/C,mBAAK,OAAO;AACF,wBAAA;AAAA,YAAA;AAAA,UACZ;AAAA,QACF;AAAA,MACF;AAAA,IAEJ;AAAA,IACA,yBAAyB,MAAM;AAC7B,UAAIA,aAAE,aAAa,KAAK,KAAK,WAAW,GAAG;AACzC,YAAI,KAAK,KAAK,YAAY,SAAS,KAAK,MAAM;AAC5C,eAAK,OAAO;AACF,oBAAA;AAAA,QAAA;AAAA,MACZ;AAAA,IACF;AAAA,EACF,CACD;AAEM,SAAA;AACT;;;"}
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const CONFIG_FILE_NAME = "tsr.config.json";
4
3
  const splitPrefix = "tsr-split";
5
- exports.CONFIG_FILE_NAME = CONFIG_FILE_NAME;
6
4
  exports.splitPrefix = splitPrefix;
7
5
  //# sourceMappingURL=constants.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.cjs","sources":["../../../src/core/constants.ts"],"sourcesContent":["export const CONFIG_FILE_NAME = 'tsr.config.json'\nexport const splitPrefix = 'tsr-split'\n"],"names":[],"mappings":";;AAAO,MAAM,mBAAmB;AACzB,MAAM,cAAc;;;"}
1
+ {"version":3,"file":"constants.cjs","sources":["../../../src/core/constants.ts"],"sourcesContent":["export const splitPrefix = 'tsr-split'\n"],"names":[],"mappings":";;AAAO,MAAM,cAAc;;"}
@@ -1,2 +1 @@
1
- export declare const CONFIG_FILE_NAME = "tsr.config.json";
2
1
  export declare const splitPrefix = "tsr-split";
@@ -40,13 +40,20 @@ const unpluginRouterCodeSplitterFactory = (options = {}, { framework }) => {
40
40
  let userConfig = options;
41
41
  const handleSplittingFile = (code, id) => {
42
42
  if (debug) console.info("Splitting route: ", id);
43
+ if (debug) console.info("");
44
+ if (debug) console.info("Split Route Input: ", id);
45
+ if (debug) console.info("");
46
+ if (debug) console.info(code);
47
+ if (debug) console.info("");
48
+ if (debug) console.info("");
49
+ if (debug) console.info("");
43
50
  const compiledVirtualRoute = compilers.compileCodeSplitVirtualRoute({
44
51
  code,
45
52
  root: ROOT,
46
53
  filename: id
47
54
  });
48
55
  if (debug) console.info("");
49
- if (debug) console.info("Split Output");
56
+ if (debug) console.info("Split Route Output: ", id);
50
57
  if (debug) console.info("");
51
58
  if (debug) console.info(compiledVirtualRoute.code);
52
59
  if (debug) console.info("");
@@ -62,7 +69,7 @@ const unpluginRouterCodeSplitterFactory = (options = {}, { framework }) => {
62
69
  filename: id
63
70
  });
64
71
  if (debug) console.info("");
65
- if (debug) console.info("Compiled Output");
72
+ if (debug) console.info("Handling createRoute output: ", id);
66
73
  if (debug) console.info("");
67
74
  if (debug) console.info(compiledReferenceRoute.code);
68
75
  if (debug) console.info("");
@@ -1 +1 @@
1
- {"version":3,"file":"router-code-splitter-plugin.cjs","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.info('✅ ' + PLUGIN_NAME + ': code-splitting done!')\n setTimeout(() => {\n process.exit(0)\n })\n })\n }\n },\n }\n}\n"],"names":["isAbsolute","join","normalize","splitPrefix","compileCodeSplitVirtualRoute","compileCodeSplitReferenceRoute","pathToFileURL","fileURLToPath","config","getConfig"],"mappings":";;;;;;;AAaA,SAAS,gBAAgB,KAAqB;AACrC,SAAA,IAAI,OAAO,CAAC,EAAE,gBAAgB,IAAI,MAAM,CAAC;AAClD;AAEA,SAAS,wBACP,UACA,iBACS;AACH,QAAA,sBAAsBA,qBAAW,eAAe,IAClD,kBACAC,UAAAA,KAAK,QAAQ,IAAI,GAAG,eAAe;AAEjC,QAAA,OAAOC,oBAAU,QAAQ;AAExB,SAAA,KAAK,WAAW,mBAAmB;AAC5C;AASA,MAAM,8BAAiE;AAAA,EACrE;AAAA,IACE,YAAY;AAAA,IACZ,KAAK;AAAA,IACL,OAAO;AAAA,IACP,YAAY,CAAC,MAAM;AAAA,EAAA;AAEvB;AAEA,MAAM,gCAAgC,MAAM;AAAA,EAC1C,YAAY,gBAA4C,WAAmB;AACzE,UAAM,yBAAyB,eAAe,GAAG,oHAAoH,eAAe,G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-plugin.cjs","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 if (debug) console.info('')\n if (debug) console.info('Split Route Input: ', id)\n if (debug) console.info('')\n if (debug) console.info(code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\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 Route Output: ', id)\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('Handling createRoute output: ', id)\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('✅ ' + PLUGIN_NAME + ': code-splitting done!')\n setTimeout(() => {\n process.exit(0)\n })\n })\n }\n },\n }\n}\n"],"names":["isAbsolute","join","normalize","splitPrefix","compileCodeSplitVirtualRoute","compileCodeSplitReferenceRoute","pathToFileURL","fileURLToPath","config","getConfig"],"mappings":";;;;;;;AAaA,SAAS,gBAAgB,KAAqB;AACrC,SAAA,IAAI,OAAO,CAAC,EAAE,gBAAgB,IAAI,MAAM,CAAC;AAClD;AAEA,SAAS,wBACP,UACA,iBACS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U,SAAS,IAAI;AAAA,IACtC;AAAA,IAEA,QAAQ,UAAU;AAChB,aAAO,QAAQ,IAAI;AAEnB,eAAS,MAAM,cAAc,IAAI,aAAa,CAAC,SAAS;AACjD,aAAA,oBAAoB,MAAM,cAAc;AAAA,UAC3C;AAAA,UACA,CAAC,gBAAqC;AACpC,gBAAI,YAAY,QAAQ,SAAS,iBAAiB,GAAG;AACvC,0BAAA,UAAU,YAAY,QAAQ;AAAA,gBACxC;AAAA,gBACA;AAAA,cACF;AAAA,YAAA;AAAA,UACF;AAAA,QAEJ;AAAA,MAAA,CACD;AAEY,mBAAAA,OAAAA,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,MAAA;AAAA,IACH;AAAA,EAEJ;AACF;;"}
@@ -25,7 +25,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
25
25
  const node_path = require("node:path");
26
26
  const routerGenerator = require("@tanstack/router-generator");
27
27
  const config = require("./config.cjs");
28
- const constants = require("./constants.cjs");
29
28
  let lock = false;
30
29
  const checkLock = () => lock;
31
30
  const setLock = (bool) => {
@@ -54,7 +53,7 @@ const unpluginRouterGeneratorFactory = (options = {}) => {
54
53
  };
55
54
  const handleFile = async (file, event) => {
56
55
  const filePath = node_path.normalize(file);
57
- if (filePath === node_path.join(ROOT, constants.CONFIG_FILE_NAME)) {
56
+ if (filePath === routerGenerator.resolveConfigPath({ configDirectory: ROOT })) {
58
57
  userConfig = config.getConfig(options, ROOT);
59
58
  return;
60
59
  }
@@ -1 +1 @@
1
- {"version":3,"file":"router-generator-plugin.cjs","sources":["../../../src/core/router-generator-plugin.ts"],"sourcesContent":["import { isAbsolute, join, normalize, resolve } from 'node:path'\nimport { generator } from '@tanstack/router-generator'\n\nimport { getConfig } from './config'\nimport { CONFIG_FILE_NAME } from './constants'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { Config } from './config'\n\nlet lock = false\nconst checkLock = () => lock\nconst setLock = (bool: boolean) => {\n lock = bool\n}\n\nconst PLUGIN_NAME = 'unplugin:router-generator'\n\nexport const unpluginRouterGeneratorFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}) => {\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n const getRoutesDirectoryPath = () => {\n return isAbsolute(userConfig.routesDirectory)\n ? userConfig.routesDirectory\n : join(ROOT, userConfig.routesDirectory)\n }\n\n const generate = async () => {\n if (checkLock()) {\n return\n }\n\n setLock(true)\n\n try {\n await generator(userConfig, process.cwd())\n } catch (err) {\n console.error(err)\n console.info()\n } finally {\n setLock(false)\n }\n }\n\n const handleFile = async (\n file: string,\n event: 'create' | 'update' | 'delete',\n ) => {\n const filePath = normalize(file)\n\n if (filePath === join(ROOT, CONFIG_FILE_NAME)) {\n userConfig = getConfig(options, ROOT)\n return\n }\n\n if (\n event === 'update' &&\n filePath === resolve(userConfig.generatedRouteTree)\n ) {\n // skip generating routes if the generated route tree is updated\n return\n }\n\n const routesDirectoryPath = getRoutesDirectoryPath()\n if (filePath.startsWith(routesDirectoryPath)) {\n await generate()\n }\n }\n\n const run: (cb: () => Promise<void> | void) => Promise<void> = async (cb) => {\n if (userConfig.enableRouteGeneration ?? true) {\n await cb()\n }\n }\n\n return {\n name: 'router-generator-plugin',\n async watchChange(id, { event }) {\n await run(async () => {\n await handleFile(id, event)\n })\n },\n vite: {\n async configResolved(config) {\n ROOT = config.root\n userConfig = getConfig(options, ROOT)\n\n await run(generate)\n },\n },\n async rspack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {\n await run(generate)\n })\n } else {\n // rspack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', async () => {\n await run(generate)\n })\n\n let generated = false\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (!generated) {\n generated = true\n return run(generate)\n }\n })\n }\n },\n async webpack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {\n await run(generate)\n })\n } else {\n // webpack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', async () => {\n await run(generate)\n })\n\n let generated = false\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (!generated) {\n generated = true\n return run(generate)\n }\n })\n }\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {\n console.info('✅ ' + PLUGIN_NAME + ': route-tree generation done')\n setTimeout(() => {\n process.exit(0)\n })\n })\n }\n },\n }\n}\n"],"names":["isAbsolute","join","generator","normalize","CONFIG_FILE_NAME","getConfig","resolve","config"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,IAAI,OAAO;AACX,MAAM,YAAY,MAAM;AACxB,MAAM,UAAU,CAAC,SAAkB;AAC1B,SAAA;AACT;AAEA,MAAM,cAAc;AAEb,MAAM,iCAET,CAAC,UAAU,OAAO;AAChB,MAAA,OAAe,QAAQ,IAAI;AAC/B,MAAI,aAAa;AAEjB,QAAM,yBAAyB,MAAM;AAC5B,WAAAA,UAAA,WAAW,WAAW,eAAe,IACxC,WAAW,kBACXC,eAAK,MAAM,WAAW,eAAe;AAAA,EAC3C;AAEA,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf;AAAA,IAAA;AAGF,YAAQ,IAAI;AAER,QAAA;AAC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OAAO,UAAU;AAErC,iBAAA,MAAM,qBAAqB,EAAE,eAAe,MAAM,EAClD,GAAG,OAAO,YAAY;AACrB,gBAAM,IAAI,QAAQ;AAAA,QAAA,CACnB;AAEH,YAAI,YAAY;AAChB,iBAAS,MAAM,SAAS,WAAW,aAAa,YAAY;AAC1D,cAAI,CAAC,WAAW;AACF,wBAAA;AACZ,mBAAO,IAAI,QAAQ;AAAA,UAAA;AAAA,QACrB,CACD;AAAA,MAAA;AAAA,IAEL;AAAA,IACA,MAAM,QAAQ,UAAU;AACT,mBAAAA,OAAAA,UAAU,SAAS,IAAI;AAEhC,UAAA,SAAS,QAAQ,SAAS,cAAc;AAC1C,iBAAS,MAAM,UAAU,WAAW,aAAa,YAAY;AAC3D,gBAAM,IAAI,QAAQ;AAAA,QAAA,CACnB;AAAA,MAAA,OACI;AAEL,cAAM,sBAAsB,uBAAuB;AAC7C,cAAA,WAAW,MAAM,OAAO,UAAU;AAErC,iBAAA,MAAM,qBAAqB,EAAE,eAAe,MAAM,EAClD,GAAG,OAAO,YAAY;AACrB,gBAAM,IAAI,QAAQ;AAAA,QAAA,CACnB;AAEH,YAAI,YAAY;AAChB,iBAAS,MAAM,SAAS,WAAW,aAAa,YAAY;AAC1D,cAAI,CAAC,WAAW;AACF,wBAAA;AACZ,mBAAO,IAAI,QAAQ;AAAA,UAAA;AAAA,QACrB,CACD;AAAA,MAAA;AAGC,UAAA,SAAS,QAAQ,SAAS,cAAc;AAC1C,iBAAS,MAAM,KAAK,IAAI,aAAa,CAAC,UAAU;AACtC,kBAAA,KAAK,OAAO,cAAc,8BAA8B;AAChE,qBAAW,MAAM;AACf,oBAAQ,KAAK,CAAC;AAAA,UAAA,CACf;AAAA,QAAA,CACF;AAAA,MAAA;AAAA,IACH;AAAA,EAEJ;AACF;;"}
1
+ {"version":3,"file":"router-generator-plugin.cjs","sources":["../../../src/core/router-generator-plugin.ts"],"sourcesContent":["import { isAbsolute, join, normalize, resolve } from 'node:path'\nimport { generator, resolveConfigPath } from '@tanstack/router-generator'\n\nimport { getConfig } from './config'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { Config } from './config'\n\nlet lock = false\nconst checkLock = () => lock\nconst setLock = (bool: boolean) => {\n lock = bool\n}\n\nconst PLUGIN_NAME = 'unplugin:router-generator'\n\nexport const unpluginRouterGeneratorFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}) => {\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n const getRoutesDirectoryPath = () => {\n return isAbsolute(userConfig.routesDirectory)\n ? userConfig.routesDirectory\n : join(ROOT, userConfig.routesDirectory)\n }\n\n const generate = async () => {\n if (checkLock()) {\n return\n }\n\n setLock(true)\n\n try {\n await generator(userConfig, process.cwd())\n } catch (err) {\n console.error(err)\n console.info()\n } finally {\n setLock(false)\n }\n }\n\n const handleFile = async (\n file: string,\n event: 'create' | 'update' | 'delete',\n ) => {\n const filePath = normalize(file)\n\n if (filePath === resolveConfigPath({ configDirectory: ROOT })) {\n userConfig = getConfig(options, ROOT)\n return\n }\n\n if (\n event === 'update' &&\n filePath === resolve(userConfig.generatedRouteTree)\n ) {\n // skip generating routes if the generated route tree is updated\n return\n }\n\n const routesDirectoryPath = getRoutesDirectoryPath()\n if (filePath.startsWith(routesDirectoryPath)) {\n await generate()\n }\n }\n\n const run: (cb: () => Promise<void> | void) => Promise<void> = async (cb) => {\n if (userConfig.enableRouteGeneration ?? true) {\n await cb()\n }\n }\n\n return {\n name: 'router-generator-plugin',\n async watchChange(id, { event }) {\n await run(async () => {\n await handleFile(id, event)\n })\n },\n vite: {\n async configResolved(config) {\n ROOT = config.root\n userConfig = getConfig(options, ROOT)\n\n await run(generate)\n },\n },\n async rspack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {\n await run(generate)\n })\n } else {\n // rspack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', async () => {\n await run(generate)\n })\n\n let generated = false\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (!generated) {\n generated = true\n return run(generate)\n }\n })\n }\n },\n async webpack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {\n await run(generate)\n })\n } else {\n // webpack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', async () => {\n await run(generate)\n })\n\n let generated = false\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (!generated) {\n generated = true\n return run(generate)\n }\n })\n }\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {\n console.info('✅ ' + PLUGIN_NAME + ': route-tree generation done')\n setTimeout(() => {\n process.exit(0)\n })\n })\n }\n },\n }\n}\n"],"names":["isAbsolute","join","generator","normalize","resolveConfigPath","getConfig","resolve","config"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,IAAI,OAAO;AACX,MAAM,YAAY,MAAM;AACxB,MAAM,UAAU,CAAC,SAAkB;AAC1B,SAAA;AACT;AAEA,MAAM,cAAc;AAEb,MAAM,iCAET,CAAC,UAAU,OAAO;AAChB,MAAA,OAAe,QAAQ,IAAI;AAC/B,MAAI,aAAa;AAEjB,QAAM,yBAAyB,MAAM;AAC5B,WAAAA,UAAA,WAAW,WAAW,eAAe,IACxC,WAAW,kBACXC,eAAK,MAAM,WAAW,eAAe;AAAA,EAC3C;AAEA,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf;AAAA,IAAA;AAGF,YAAQ,IAAI;AAER,QAAA;AACF,YAAMC,0BAAU,YAAY,QAAQ,IAAA,CAAK;AAAA,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AAE,eAAe,MAAM,EAClD,GAAG,OAAO,YAAY;AACrB,gBAAM,IAAI,QAAQ;AAAA,QAAA,CACnB;AAEH,YAAI,YAAY;AAChB,iBAAS,MAAM,SAAS,WAAW,aAAa,YAAY;AAC1D,cAAI,CAAC,WAAW;AACF,wBAAA;AACZ,mBAAO,IAAI,QAAQ;AAAA,UAAA;AAAA,QACrB,CACD;AAAA,MAAA;AAAA,IAEL;AAAA,IACA,MAAM,QAAQ,UAAU;AACT,mBAAAA,OAAAA,UAAU,SAAS,IAAI;AAEhC,UAAA,SAAS,QAAQ,SAAS,cAAc;AAC1C,iBAAS,MAAM,UAAU,WAAW,aAAa,YAAY;AAC3D,gBAAM,IAAI,QAAQ;AAAA,QAAA,CACnB;AAAA,MAAA,OACI;AAEL,cAAM,sBAAsB,uBAAuB;AAC7C,cAAA,WAAW,MAAM,OAAO,UAAU;AAErC,iBAAA,MAAM,qBAAqB,EAAE,eAAe,MAAM,EAClD,GAAG,OAAO,YAAY;AACrB,gBAAM,IAAI,QAAQ;AAAA,QAAA,CACnB;AAEH,YAAI,YAAY;AAChB,iBAAS,MAAM,SAAS,WAAW,aAAa,YAAY;AAC1D,cAAI,CAAC,WAAW;AACF,wBAAA;AACZ,mBAAO,IAAI,QAAQ;AAAA,UAAA;AAAA,QACrB,CACD;AAAA,MAAA;AAGC,UAAA,SAAS,QAAQ,SAAS,cAAc;AAC1C,iBAAS,MAAM,KAAK,IAAI,aAAa,CAAC,UAAU;AACtC,kBAAA,KAAK,OAAO,cAAc,8BAA8B;AAChE,qBAAW,MAAM;AACf,oBAAQ,KAAK,CAAC;AAAA,UAAA,CACf;AAAA,QAAA,CACF;AAAA,MAAA;AAAA,IACH;AAAA,EAEJ;AACF;;"}
@@ -1,7 +1,6 @@
1
- import * as babel from '@babel/core';
2
1
  export type ParseAstOptions = {
3
2
  code: string;
4
3
  filename: string;
5
4
  root: string;
6
5
  };
7
- export declare function parseAst(opts: ParseAstOptions): import('@babel/parser').ParseResult<babel.types.File> | null;
6
+ export declare function parseAst(opts: ParseAstOptions): import('@babel/parser').ParseResult<import('@babel/types').File>;
@@ -1,31 +1,12 @@
1
- import * as babel from "@babel/core";
2
- import "@babel/parser";
3
- import _babelPluginJsx from "@babel/plugin-syntax-jsx";
4
- import _babelPluginTypeScript from "@babel/plugin-syntax-typescript";
5
- let babelPluginJsx = _babelPluginJsx;
6
- let babelPluginTypeScript = _babelPluginTypeScript;
7
- if (babelPluginJsx.default) {
8
- babelPluginJsx = babelPluginJsx.default;
9
- }
10
- if (babelPluginTypeScript.default) {
11
- babelPluginTypeScript = babelPluginTypeScript.default;
12
- }
1
+ import { parse } from "@babel/parser";
13
2
  function parseAst(opts) {
14
- const babelPlugins = [
15
- babelPluginJsx,
16
- [
17
- babelPluginTypeScript,
18
- {
19
- isTSX: true
20
- }
21
- ]
22
- ];
23
- return babel.parse(opts.code, {
24
- plugins: babelPlugins,
25
- root: opts.root,
26
- filename: opts.filename,
27
- sourceMaps: true,
28
- sourceType: "module"
3
+ return parse(opts.code, {
4
+ plugins: ["jsx", "typescript"],
5
+ sourceType: "module",
6
+ ...{
7
+ root: opts.root,
8
+ filename: opts.filename
9
+ }
29
10
  });
30
11
  }
31
12
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"ast.js","sources":["../../../../src/core/code-splitter/ast.ts"],"sourcesContent":["import * as babel from '@babel/core'\nimport '@babel/parser'\n// @ts-expect-error\nimport _babelPluginJsx from '@babel/plugin-syntax-jsx'\n// @ts-expect-error\nimport _babelPluginTypeScript from '@babel/plugin-syntax-typescript'\n\nlet babelPluginJsx = _babelPluginJsx\nlet babelPluginTypeScript = _babelPluginTypeScript\n\nif (babelPluginJsx.default) {\n babelPluginJsx = babelPluginJsx.default\n}\n\nif (babelPluginTypeScript.default) {\n babelPluginTypeScript = babelPluginTypeScript.default\n}\n\nexport type ParseAstOptions = {\n code: string\n filename: string\n root: string\n}\n\nexport function parseAst(opts: ParseAstOptions) {\n const babelPlugins: Array<babel.PluginItem> = [\n babelPluginJsx,\n [\n babelPluginTypeScript,\n {\n isTSX: true,\n },\n ],\n ]\n\n return babel.parse(opts.code, {\n plugins: babelPlugins,\n root: opts.root,\n filename: opts.filename,\n sourceMaps: true,\n sourceType: 'module',\n })\n}\n"],"names":[],"mappings":";;;;AAOA,IAAI,iBAAiB;AACrB,IAAI,wBAAwB;AAE5B,IAAI,eAAe,SAAS;AAC1B,mBAAiB,eAAe;AAClC;AAEA,IAAI,sBAAsB,SAAS;AACjC,0BAAwB,sBAAsB;AAChD;AAQO,SAAS,SAAS,MAAuB;AAC9C,QAAM,eAAwC;AAAA,IAC5C;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,QACE,OAAO;AAAA,MAAA;AAAA,IACT;AAAA,EAEJ;AAEO,SAAA,MAAM,MAAM,KAAK,MAAM;AAAA,IAC5B,SAAS;AAAA,IACT,MAAM,KAAK;AAAA,IACX,UAAU,KAAK;AAAA,IACf,YAAY;AAAA,IACZ,YAAY;AAAA,EAAA,CACb;AACH;"}
1
+ {"version":3,"file":"ast.js","sources":["../../../../src/core/code-splitter/ast.ts"],"sourcesContent":["import { parse } from '@babel/parser'\n\nexport type ParseAstOptions = {\n code: string\n filename: string\n root: string\n}\n\nexport function parseAst(opts: ParseAstOptions) {\n return parse(opts.code, {\n plugins: ['jsx', 'typescript'],\n sourceType: 'module',\n ...{\n root: opts.root,\n filename: opts.filename,\n },\n })\n}\n"],"names":[],"mappings":";AAQO,SAAS,SAAS,MAAuB;AACvC,SAAA,MAAM,KAAK,MAAM;AAAA,IACtB,SAAS,CAAC,OAAO,YAAY;AAAA,IAC7B,YAAY;AAAA,IACZ,GAAG;AAAA,MACD,MAAM,KAAK;AAAA,MACX,UAAU,KAAK;AAAA,IAAA;AAAA,EACjB,CACD;AACH;"}
@@ -1,22 +1,18 @@
1
1
  import * as t from "@babel/types";
2
- import babel__default from "@babel/core";
2
+ import babel from "@babel/core";
3
3
  import _generate from "@babel/generator";
4
4
  import * as template from "@babel/template";
5
5
  import { deadCodeElimination } from "babel-dead-code-elimination";
6
6
  import { splitPrefix } from "../constants.js";
7
7
  import { parseAst } from "./ast.js";
8
+ const debug = process.env.TSR_VITE_DEBUG;
8
9
  let generate = _generate["default"];
9
10
  if (!generate) {
10
11
  generate = _generate;
11
12
  }
12
13
  function compileCodeSplitReferenceRoute(opts) {
13
14
  const ast = parseAst(opts);
14
- if (!ast) {
15
- throw new Error(
16
- `Failed to compile ast for compileCodeSplitReferenceRoute() for the file: ${opts.filename}`
17
- );
18
- }
19
- babel__default.traverse(ast, {
15
+ babel.traverse(ast, {
20
16
  Program: {
21
17
  enter(programPath, programState) {
22
18
  const state = programState;
@@ -153,7 +149,19 @@ function compileCodeSplitReferenceRoute(opts) {
153
149
  }
154
150
  }
155
151
  });
152
+ if (debug) console.info("");
153
+ if (debug) console.info("Dead Code Elimination Input 1:");
154
+ if (debug) console.info(generate(ast, { sourceMaps: true }).code);
155
+ if (debug) console.info("");
156
+ if (debug) console.info("");
157
+ if (debug) console.info("");
156
158
  deadCodeElimination(ast);
159
+ if (debug) console.info("");
160
+ if (debug) console.info("Dead Code Elimination Output 1:");
161
+ if (debug) console.info(generate(ast, { sourceMaps: true }).code);
162
+ if (debug) console.info("");
163
+ if (debug) console.info("");
164
+ if (debug) console.info("");
157
165
  return generate(ast, {
158
166
  sourceMaps: true
159
167
  });
@@ -161,13 +169,8 @@ function compileCodeSplitReferenceRoute(opts) {
161
169
  const splitNodeTypes = ["component", "loader"];
162
170
  function compileCodeSplitVirtualRoute(opts) {
163
171
  const ast = parseAst(opts);
164
- if (!ast) {
165
- throw new Error(
166
- `Failed to compile ast for compileCodeSplitVirtualRoute() for the file: ${opts.filename}`
167
- );
168
- }
169
172
  const knownExportedIdents = /* @__PURE__ */ new Set();
170
- babel__default.traverse(ast, {
173
+ babel.traverse(ast, {
171
174
  Program: {
172
175
  enter(programPath, programState) {
173
176
  const state = programState;
@@ -275,7 +278,7 @@ function compileCodeSplitVirtualRoute(opts) {
275
278
  );
276
279
  } else if (t.isCallExpression(splitNode)) {
277
280
  const outputSplitNodeCode = generate(splitNode).code;
278
- const splitNodeAst = babel__default.parse(outputSplitNodeCode);
281
+ const splitNodeAst = babel.parse(outputSplitNodeCode);
279
282
  if (!splitNodeAst) {
280
283
  throw new Error(
281
284
  `Failed to parse the generated code for "${splitType}" in the node type "${splitNode.type}"`
@@ -341,7 +344,20 @@ function compileCodeSplitVirtualRoute(opts) {
341
344
  }
342
345
  }
343
346
  });
347
+ if (debug) console.info("");
348
+ if (debug) console.info("Dead Code Elimination Input 2:");
349
+ console.log(JSON.stringify(ast, null, 2));
350
+ if (debug) console.info(generate(ast, { sourceMaps: true }).code);
351
+ if (debug) console.info("");
352
+ if (debug) console.info("");
353
+ if (debug) console.info("");
344
354
  deadCodeElimination(ast);
355
+ if (debug) console.info("");
356
+ if (debug) console.info("Dead Code Elimination Output 2:");
357
+ if (debug) console.info(generate(ast, { sourceMaps: true }).code);
358
+ if (debug) console.info("");
359
+ if (debug) console.info("");
360
+ if (debug) console.info("");
345
361
  if (knownExportedIdents.size > 0) {
346
362
  const list = Array.from(knownExportedIdents).reduce((str, ident) => {
347
363
  str += `
@@ -403,7 +419,7 @@ function removeIdentifierLiteral(path, node) {
403
419
  }
404
420
  function hasExport(ast, node) {
405
421
  let found = false;
406
- babel__default.traverse(ast, {
422
+ babel.traverse(ast, {
407
423
  ExportNamedDeclaration(path) {
408
424
  if (path.node.declaration) {
409
425
  if (t.isVariableDeclaration(path.node.declaration)) {
@@ -438,7 +454,7 @@ function hasExport(ast, node) {
438
454
  }
439
455
  function removeExports(ast, node) {
440
456
  let removed = false;
441
- babel__default.traverse(ast, {
457
+ babel.traverse(ast, {
442
458
  ExportNamedDeclaration(path) {
443
459
  if (path.node.declaration) {
444
460
  if (t.isVariableDeclaration(path.node.declaration)) {
@@ -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 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', () => Route.ssr)`,\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.isVariableDeclarator(splitNode)) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(t.identifier(splitType), splitNode.init),\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,IAC3F;AAAA,EAAA;AAGFA,iBAAM,SAAS,KAAK;AAAA,IAClB,SAAS;AAAA,MACP,MAAM,aAAa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MAAM;AACvB,UAAA,KAAK,KAAK,aAAa;AAEzB,YAAI,EAAE,sBAAsB,KAAK,KAAK,WAAW,GAAG;AAClD,eAAK,KAAK,YAAY,aAAa,QAAQ,CAAC,SAAS;AAC/C,gBAAA,EAAE,qBAAqB,IAAI,GAAG;AAChC,kBAAI,EAAE,aAAa,KAAK,EAAE,GAAG;AAC3B,oBAAI,KAAK,GAAG,SAAS,KAAK,MAAM;AAC9B,uBAAK,OAAO;AACF,4BAAA;AAAA,gBAAA;AAAA,cACZ;AAAA,YACF;AAAA,UACF,CACD;AAAA,QAAA,WACQ,EAAE,sBAAsB,KAAK,KAAK,WAAW,GAAG;AACzD,cAAI,EAAE,aAAa,KAAK,KAAK,YAAY,EAAE,GAAG;AAC5C,gBAAI,KAAK,KAAK,YAAY,GAAG,SAAS,KAAK,MAAM;AAC/C,mBAAK,OAAO;AACF,wBAAA;AAAA,YAAA;AAAA,UACZ;AAAA,QACF;AAAA,MACF;AAAA,IAEJ;AAAA,IACA,yBAAyB,MAAM;AAC7B,UAAI,EAAE,aAAa,KAAK,KAAK,WAAW,GAAG;AACzC,YAAI,KAAK,KAAK,YAAY,SAAS,KAAK,MAAM;AAC5C,eAAK,OAAO;AACF,oBAAA;AAAA,QAAA;AAAA,MACZ;AAAA,IACF;AAAA,EACF,CACD;AAEM,SAAA;AACT;"}
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\nconst debug = process.env.TSR_VITE_DEBUG\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 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', () => Route.ssr)`,\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 if (debug) console.info('')\n if (debug) console.info('Dead Code Elimination Input 1:')\n if (debug) console.info(generate(ast, { sourceMaps: true }).code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n deadCodeElimination(ast)\n\n if (debug) console.info('')\n if (debug) console.info('Dead Code Elimination Output 1:')\n if (debug) console.info(generate(ast, { sourceMaps: true }).code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\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 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.isVariableDeclarator(splitNode)) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(t.identifier(splitType), splitNode.init),\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 if (debug) console.info('')\n if (debug) console.info('Dead Code Elimination Input 2:')\n console.log(JSON.stringify(ast, null, 2))\n if (debug) console.info(generate(ast, { sourceMaps: true }).code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n deadCodeElimination(ast)\n\n if (debug) console.info('')\n if (debug) console.info('Dead Code Elimination Output 2:')\n if (debug) console.info(generate(ast, { sourceMaps: true }).code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\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":[],"mappings":";;;;;;;AAUA,MAAM,QAAQ,QAAQ,IAAI;AAI1B,IAAI,WAAY,UAAkB,SAAS;AAG3C,IAAI,CAAC,UAAU;AACF,aAAA;AACb;AAoBO,SAAS,+BAA+B,MAAuB;AAC9D,QAAA,MAAM,SAAS,IAAI;AAEzB,QAAM,SAAS,KAAK;AAAA,IAClB,SAAS;AAAA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AI,KAAK,GAAG,SAAS,KAAK,MAAM;AAC9B,uBAAK,OAAO;AACF,4BAAA;AAAA,gBAAA;AAAA,cACZ;AAAA,YACF;AAAA,UACF,CACD;AAAA,QAAA,WACQ,EAAE,sBAAsB,KAAK,KAAK,WAAW,GAAG;AACzD,cAAI,EAAE,aAAa,KAAK,KAAK,YAAY,EAAE,GAAG;AAC5C,gBAAI,KAAK,KAAK,YAAY,GAAG,SAAS,KAAK,MAAM;AAC/C,mBAAK,OAAO;AACF,wBAAA;AAAA,YAAA;AAAA,UACZ;AAAA,QACF;AAAA,MACF;AAAA,IAEJ;AAAA,IACA,yBAAyB,MAAM;AAC7B,UAAI,EAAE,aAAa,KAAK,KAAK,WAAW,GAAG;AACzC,YAAI,KAAK,KAAK,YAAY,SAAS,KAAK,MAAM;AAC5C,eAAK,OAAO;AACF,oBAAA;AAAA,QAAA;AAAA,MACZ;AAAA,IACF;AAAA,EACF,CACD;AAEM,SAAA;AACT;"}
@@ -1,2 +1 @@
1
- export declare const CONFIG_FILE_NAME = "tsr.config.json";
2
1
  export declare const splitPrefix = "tsr-split";
@@ -1,7 +1,5 @@
1
- const CONFIG_FILE_NAME = "tsr.config.json";
2
1
  const splitPrefix = "tsr-split";
3
2
  export {
4
- CONFIG_FILE_NAME,
5
3
  splitPrefix
6
4
  };
7
5
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sources":["../../../src/core/constants.ts"],"sourcesContent":["export const CONFIG_FILE_NAME = 'tsr.config.json'\nexport const splitPrefix = 'tsr-split'\n"],"names":[],"mappings":"AAAO,MAAM,mBAAmB;AACzB,MAAM,cAAc;"}
1
+ {"version":3,"file":"constants.js","sources":["../../../src/core/constants.ts"],"sourcesContent":["export const splitPrefix = 'tsr-split'\n"],"names":[],"mappings":"AAAO,MAAM,cAAc;"}
@@ -38,13 +38,20 @@ const unpluginRouterCodeSplitterFactory = (options = {}, { framework }) => {
38
38
  let userConfig = options;
39
39
  const handleSplittingFile = (code, id) => {
40
40
  if (debug) console.info("Splitting route: ", id);
41
+ if (debug) console.info("");
42
+ if (debug) console.info("Split Route Input: ", id);
43
+ if (debug) console.info("");
44
+ if (debug) console.info(code);
45
+ if (debug) console.info("");
46
+ if (debug) console.info("");
47
+ if (debug) console.info("");
41
48
  const compiledVirtualRoute = compileCodeSplitVirtualRoute({
42
49
  code,
43
50
  root: ROOT,
44
51
  filename: id
45
52
  });
46
53
  if (debug) console.info("");
47
- if (debug) console.info("Split Output");
54
+ if (debug) console.info("Split Route Output: ", id);
48
55
  if (debug) console.info("");
49
56
  if (debug) console.info(compiledVirtualRoute.code);
50
57
  if (debug) console.info("");
@@ -60,7 +67,7 @@ const unpluginRouterCodeSplitterFactory = (options = {}, { framework }) => {
60
67
  filename: id
61
68
  });
62
69
  if (debug) console.info("");
63
- if (debug) console.info("Compiled Output");
70
+ if (debug) console.info("Handling createRoute output: ", id);
64
71
  if (debug) console.info("");
65
72
  if (debug) console.info(compiledReferenceRoute.code);
66
73
  if (debug) console.info("");
@@ -1 +1 @@
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.info('✅ ' + PLUGIN_NAME + ': code-splitting done!')\n setTimeout(() => {\n process.exit(0)\n })\n })\n }\n },\n }\n}\n"],"names":[],"mappings":";;;;;AAaA,SAAS,gBAAgB,KAAqB;AACrC,SAAA,IAAI,OAAO,CAAC,EAAE,gBAAgB,IAAI,MAAM,CAAC;AAClD;AAEA,SAAS,wBACP,UACA,iBACS;AACH,QAAA,sBAAsB,WAAW,eAAe,IAClD,kBACA,KAAK,QAAQ,IAAI,GAAG,eAAe;AAEjC,QAAA,OAAO,UAAU,QAAQ;AAExB,SAAA,KAAK,WAAW,mBAAmB;AAC5C;AASA,MAAM,8BAAiE;AAAA,EACrE;AAAA,IACE,YAAY;AAAA,IACZ,KAAK;AAAA,IACL,OAAO;AAAA,IACP,YAAY,CAAC,MAAM;AAAA,EAAA;AAEvB;AAEA,MAAM,gCAAgC,MAAM;AAAA,EAC1C,YAAY,gBAA4C,WAAmB;AACzE,UAAM,yBAAyB,eAAe,GAAG,oHAAoH,eAAe,GAAG;AAAA;AAAA;AAAA,kBAGzK,gBAAgB,SAAS,CAAC,4BAA4B,eAAe,KAAK;AAAA,IACxF,eAAe,KAAK;AAAA;AAAA,CAEvB;AAAA,EAAA;AAED;AAEA,MAAM,cAAc;AACpB,MAAM,oBAAoB,cAAc;AAEjC,MAAM,oCAET,CAAC,UAAU,IAAI,EAAE,gBAAgB;AACnC,QAAM,QAAQ,QAAQ,QAAQ,IAAI,cAAc;AAE5C,MAAA,OAAe,QAAQ,IAAI;AAC/B,MAAI,aAAa;AAEX,QAAA,sBAAsB,CAAC,MAAc,OAAe;AACxD,QAAI,MAAO,SAAQ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AA,cACF;AAAA,YAAA;AAAA,UACF;AAAA,QAEJ;AAAA,MAAA,CACD;AAEY,mBAAA,UAAU,SAAS,IAAI;AAAA,IACtC;AAAA,IAEA,QAAQ,UAAU;AAChB,aAAO,QAAQ,IAAI;AAEnB,eAAS,MAAM,cAAc,IAAI,aAAa,CAAC,SAAS;AACjD,aAAA,oBAAoB,MAAM,cAAc;AAAA,UAC3C;AAAA,UACA,CAAC,gBAAqC;AACpC,gBAAI,YAAY,QAAQ,SAAS,iBAAiB,GAAG;AACvC,0BAAA,UAAU,YAAY,QAAQ;AAAA,gBACxC;AAAA,gBACA;AAAA,cACF;AAAA,YAAA;AAAA,UACF;AAAA,QAEJ;AAAA,MAAA,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,MAAA;AAAA,IACH;AAAA,EAEJ;AACF;"}
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 if (debug) console.info('')\n if (debug) console.info('Split Route Input: ', id)\n if (debug) console.info('')\n if (debug) console.info(code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\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 Route Output: ', id)\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('Handling createRoute output: ', id)\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('✅ ' + PLUGIN_NAME + ': code-splitting done!')\n setTimeout(() => {\n process.exit(0)\n })\n })\n }\n },\n }\n}\n"],"names":[],"mappings":";;;;;AAaA,SAAS,gBAAgB,KAAqB;AACrC,SAAA,IAAI,OAAO,CAAC,EAAE,gBAAgB,IAAI,MAAM,CAAC;AAClD;AAEA,SAAS,wBACP,UACA,iBACS;AACH,QAAA,sBAAsB,WAAW,eAAe,IAClD,kBACA,KAAK,QAAQ,IAAI,GAAG,eAAe;AAEjC,QAAA,OAAO,UAAU,QAAQ;AAExB,SAAA,KAAK,WAAW,mBAAmB;AAC5C;AASA,MAAM,8BAAiE;AAAA,EACrE;AAAA,IACE,YAAY;AAAA,IACZ,KAAK;AAAA,IACL,OAAO;AAAA,IACP,YAAY,CAAC,MAAM;AAAA,EAAA;AAEvB;AAEA,MAAM,gCAAgC,MAAM;AAAA,EAC1C,YAAY,gBAA4C,WAAmB;AACzE,UAAM,yBAAyB,eAAe,GAAG,oHAAoH,eAAe,GAAG;AAAA;AAAA;AAAA,kBAGzK,gBAAgB,SAAS,CAAC,4BAA4B,eAAe,KAAK;AAAA,IACxF,eAAe,KAAK;AAAA;AAAA,CAEvB;AAAA,EAAA;AAED;AAEA,MAAM,cAAc;AACpB,MAAM,oBAAoB,cAAc;AAEj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7 +1,6 @@
1
1
  import { isAbsolute, join, normalize, resolve } from "node:path";
2
- import { generator } from "@tanstack/router-generator";
2
+ import { generator, resolveConfigPath } from "@tanstack/router-generator";
3
3
  import { getConfig } from "./config.js";
4
- import { CONFIG_FILE_NAME } from "./constants.js";
5
4
  let lock = false;
6
5
  const checkLock = () => lock;
7
6
  const setLock = (bool) => {
@@ -30,7 +29,7 @@ const unpluginRouterGeneratorFactory = (options = {}) => {
30
29
  };
31
30
  const handleFile = async (file, event) => {
32
31
  const filePath = normalize(file);
33
- if (filePath === join(ROOT, CONFIG_FILE_NAME)) {
32
+ if (filePath === resolveConfigPath({ configDirectory: ROOT })) {
34
33
  userConfig = getConfig(options, ROOT);
35
34
  return;
36
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"router-generator-plugin.js","sources":["../../../src/core/router-generator-plugin.ts"],"sourcesContent":["import { isAbsolute, join, normalize, resolve } from 'node:path'\nimport { generator } from '@tanstack/router-generator'\n\nimport { getConfig } from './config'\nimport { CONFIG_FILE_NAME } from './constants'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { Config } from './config'\n\nlet lock = false\nconst checkLock = () => lock\nconst setLock = (bool: boolean) => {\n lock = bool\n}\n\nconst PLUGIN_NAME = 'unplugin:router-generator'\n\nexport const unpluginRouterGeneratorFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}) => {\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n const getRoutesDirectoryPath = () => {\n return isAbsolute(userConfig.routesDirectory)\n ? userConfig.routesDirectory\n : join(ROOT, userConfig.routesDirectory)\n }\n\n const generate = async () => {\n if (checkLock()) {\n return\n }\n\n setLock(true)\n\n try {\n await generator(userConfig, process.cwd())\n } catch (err) {\n console.error(err)\n console.info()\n } finally {\n setLock(false)\n }\n }\n\n const handleFile = async (\n file: string,\n event: 'create' | 'update' | 'delete',\n ) => {\n const filePath = normalize(file)\n\n if (filePath === join(ROOT, CONFIG_FILE_NAME)) {\n userConfig = getConfig(options, ROOT)\n return\n }\n\n if (\n event === 'update' &&\n filePath === resolve(userConfig.generatedRouteTree)\n ) {\n // skip generating routes if the generated route tree is updated\n return\n }\n\n const routesDirectoryPath = getRoutesDirectoryPath()\n if (filePath.startsWith(routesDirectoryPath)) {\n await generate()\n }\n }\n\n const run: (cb: () => Promise<void> | void) => Promise<void> = async (cb) => {\n if (userConfig.enableRouteGeneration ?? true) {\n await cb()\n }\n }\n\n return {\n name: 'router-generator-plugin',\n async watchChange(id, { event }) {\n await run(async () => {\n await handleFile(id, event)\n })\n },\n vite: {\n async configResolved(config) {\n ROOT = config.root\n userConfig = getConfig(options, ROOT)\n\n await run(generate)\n },\n },\n async rspack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {\n await run(generate)\n })\n } else {\n // rspack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', async () => {\n await run(generate)\n })\n\n let generated = false\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (!generated) {\n generated = true\n return run(generate)\n }\n })\n }\n },\n async webpack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {\n await run(generate)\n })\n } else {\n // webpack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', async () => {\n await run(generate)\n })\n\n let generated = false\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (!generated) {\n generated = true\n return run(generate)\n }\n })\n }\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {\n console.info('✅ ' + PLUGIN_NAME + ': route-tree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;AAAA,UAAA;AAAA,QACrB,CACD;AAAA,MAAA;AAGC,UAAA,SAAS,QAAQ,SAAS,cAAc;AAC1C,iBAAS,MAAM,KAAK,IAAI,aAAa,CAAC,UAAU;AACtC,kBAAA,KAAK,OAAO,cAAc,8BAA8B;AAChE,qBAAW,MAAM;AACf,oBAAQ,KAAK,CAAC;AAAA,UAAA,CACf;AAAA,QAAA,CACF;AAAA,MAAA;AAAA,IACH;AAAA,EAEJ;AACF;"}
1
+ {"version":3,"file":"router-generator-plugin.js","sources":["../../../src/core/router-generator-plugin.ts"],"sourcesContent":["import { isAbsolute, join, normalize, resolve } from 'node:path'\nimport { generator, resolveConfigPath } from '@tanstack/router-generator'\n\nimport { getConfig } from './config'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { Config } from './config'\n\nlet lock = false\nconst checkLock = () => lock\nconst setLock = (bool: boolean) => {\n lock = bool\n}\n\nconst PLUGIN_NAME = 'unplugin:router-generator'\n\nexport const unpluginRouterGeneratorFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}) => {\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n const getRoutesDirectoryPath = () => {\n return isAbsolute(userConfig.routesDirectory)\n ? userConfig.routesDirectory\n : join(ROOT, userConfig.routesDirectory)\n }\n\n const generate = async () => {\n if (checkLock()) {\n return\n }\n\n setLock(true)\n\n try {\n await generator(userConfig, process.cwd())\n } catch (err) {\n console.error(err)\n console.info()\n } finally {\n setLock(false)\n }\n }\n\n const handleFile = async (\n file: string,\n event: 'create' | 'update' | 'delete',\n ) => {\n const filePath = normalize(file)\n\n if (filePath === resolveConfigPath({ configDirectory: ROOT })) {\n userConfig = getConfig(options, ROOT)\n return\n }\n\n if (\n event === 'update' &&\n filePath === resolve(userConfig.generatedRouteTree)\n ) {\n // skip generating routes if the generated route tree is updated\n return\n }\n\n const routesDirectoryPath = getRoutesDirectoryPath()\n if (filePath.startsWith(routesDirectoryPath)) {\n await generate()\n }\n }\n\n const run: (cb: () => Promise<void> | void) => Promise<void> = async (cb) => {\n if (userConfig.enableRouteGeneration ?? true) {\n await cb()\n }\n }\n\n return {\n name: 'router-generator-plugin',\n async watchChange(id, { event }) {\n await run(async () => {\n await handleFile(id, event)\n })\n },\n vite: {\n async configResolved(config) {\n ROOT = config.root\n userConfig = getConfig(options, ROOT)\n\n await run(generate)\n },\n },\n async rspack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {\n await run(generate)\n })\n } else {\n // rspack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', async () => {\n await run(generate)\n })\n\n let generated = false\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (!generated) {\n generated = true\n return run(generate)\n }\n })\n }\n },\n async webpack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {\n await run(generate)\n })\n } else {\n // webpack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', async () => {\n await run(generate)\n })\n\n let generated = false\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (!generated) {\n generated = true\n return run(generate)\n }\n })\n }\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {\n console.info('✅ ' + PLUGIN_NAME + ': route-tree generation done')\n setTimeout(() => {\n process.exit(0)\n })\n })\n }\n },\n }\n}\n"],"names":[],"mappings":";;;AAOA,IAAI,OAAO;AACX,MAAM,YAAY,MAAM;AACxB,MAAM,UAAU,CAAC,SAAkB;AAC1B,SAAA;AACT;AAEA,MAAM,cAAc;AAEb,MAAM,iCAET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MAAM;AACf,oBAAQ,KAAK,CAAC;AAAA,UAAA,CACf;AAAA,QAAA,CACF;AAAA,MAAA;AAAA,IACH;AAAA,EAEJ;AACF;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/router-plugin",
3
- "version": "1.87.6",
3
+ "version": "1.87.10",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -86,14 +86,8 @@
86
86
  "node": ">=12"
87
87
  },
88
88
  "dependencies": {
89
- "@babel/core": "^7.26.0",
90
- "@babel/generator": "^7.26.3",
91
- "@babel/parser": "^7.26.3",
92
89
  "@babel/plugin-syntax-jsx": "^7.25.9",
93
- "@babel/plugin-syntax-typescript": "^7.25.9",
94
90
  "@babel/template": "^7.25.9",
95
- "@babel/traverse": "^7.26.4",
96
- "@babel/types": "^7.26.3",
97
91
  "@types/babel__core": "^7.20.5",
98
92
  "@types/babel__generator": "^7.6.8",
99
93
  "@types/babel__template": "^7.4.4",
@@ -102,7 +96,13 @@
102
96
  "chokidar": "^3.6.0",
103
97
  "unplugin": "^1.16.0",
104
98
  "zod": "^3.23.8",
105
- "@tanstack/router-generator": "^1.87.6",
99
+ "@babel/generator": "^7.26.3",
100
+ "@babel/core": "^7.26.0",
101
+ "@babel/parser": "^7.26.3",
102
+ "@babel/plugin-syntax-typescript": "^7.25.9",
103
+ "@babel/traverse": "^7.26.4",
104
+ "@babel/types": "^7.26.3",
105
+ "@tanstack/router-generator": "^1.87.7",
106
106
  "@tanstack/virtual-file-routes": "^1.87.6"
107
107
  },
108
108
  "peerDependencies": {
@@ -1,20 +1,4 @@
1
- import * as babel from '@babel/core'
2
- import '@babel/parser'
3
- // @ts-expect-error
4
- import _babelPluginJsx from '@babel/plugin-syntax-jsx'
5
- // @ts-expect-error
6
- import _babelPluginTypeScript from '@babel/plugin-syntax-typescript'
7
-
8
- let babelPluginJsx = _babelPluginJsx
9
- let babelPluginTypeScript = _babelPluginTypeScript
10
-
11
- if (babelPluginJsx.default) {
12
- babelPluginJsx = babelPluginJsx.default
13
- }
14
-
15
- if (babelPluginTypeScript.default) {
16
- babelPluginTypeScript = babelPluginTypeScript.default
17
- }
1
+ import { parse } from '@babel/parser'
18
2
 
19
3
  export type ParseAstOptions = {
20
4
  code: string
@@ -23,21 +7,12 @@ export type ParseAstOptions = {
23
7
  }
24
8
 
25
9
  export function parseAst(opts: ParseAstOptions) {
26
- const babelPlugins: Array<babel.PluginItem> = [
27
- babelPluginJsx,
28
- [
29
- babelPluginTypeScript,
30
- {
31
- isTSX: true,
32
- },
33
- ],
34
- ]
35
-
36
- return babel.parse(opts.code, {
37
- plugins: babelPlugins,
38
- root: opts.root,
39
- filename: opts.filename,
40
- sourceMaps: true,
10
+ return parse(opts.code, {
11
+ plugins: ['jsx', 'typescript'],
41
12
  sourceType: 'module',
13
+ ...{
14
+ root: opts.root,
15
+ filename: opts.filename,
16
+ },
42
17
  })
43
18
  }
@@ -8,6 +8,8 @@ import { splitPrefix } from '../constants'
8
8
  import { parseAst } from './ast'
9
9
  import type { ParseAstOptions } from './ast'
10
10
 
11
+ const debug = process.env.TSR_VITE_DEBUG
12
+
11
13
  // Babel is a CJS package and uses `default` as named binding (`exports.default =`).
12
14
  // https://github.com/babel/babel/issues/15269.
13
15
  let generate = (_generate as any)['default'] as typeof _generate
@@ -38,12 +40,6 @@ interface State {
38
40
  export function compileCodeSplitReferenceRoute(opts: ParseAstOptions) {
39
41
  const ast = parseAst(opts)
40
42
 
41
- if (!ast) {
42
- throw new Error(
43
- `Failed to compile ast for compileCodeSplitReferenceRoute() for the file: ${opts.filename}`,
44
- )
45
- }
46
-
47
43
  babel.traverse(ast, {
48
44
  Program: {
49
45
  enter(programPath, programState) {
@@ -255,8 +251,22 @@ export function compileCodeSplitReferenceRoute(opts: ParseAstOptions) {
255
251
  },
256
252
  })
257
253
 
254
+ if (debug) console.info('')
255
+ if (debug) console.info('Dead Code Elimination Input 1:')
256
+ if (debug) console.info(generate(ast, { sourceMaps: true }).code)
257
+ if (debug) console.info('')
258
+ if (debug) console.info('')
259
+ if (debug) console.info('')
260
+
258
261
  deadCodeElimination(ast)
259
262
 
263
+ if (debug) console.info('')
264
+ if (debug) console.info('Dead Code Elimination Output 1:')
265
+ if (debug) console.info(generate(ast, { sourceMaps: true }).code)
266
+ if (debug) console.info('')
267
+ if (debug) console.info('')
268
+ if (debug) console.info('')
269
+
260
270
  return generate(ast, {
261
271
  sourceMaps: true,
262
272
  })
@@ -268,12 +278,6 @@ type SplitNodeType = (typeof splitNodeTypes)[number]
268
278
  export function compileCodeSplitVirtualRoute(opts: ParseAstOptions) {
269
279
  const ast = parseAst(opts)
270
280
 
271
- if (!ast) {
272
- throw new Error(
273
- `Failed to compile ast for compileCodeSplitVirtualRoute() for the file: ${opts.filename}`,
274
- )
275
- }
276
-
277
281
  const knownExportedIdents = new Set<string>()
278
282
 
279
283
  babel.traverse(ast, {
@@ -497,8 +501,23 @@ export function compileCodeSplitVirtualRoute(opts: ParseAstOptions) {
497
501
  },
498
502
  })
499
503
 
504
+ if (debug) console.info('')
505
+ if (debug) console.info('Dead Code Elimination Input 2:')
506
+ console.log(JSON.stringify(ast, null, 2))
507
+ if (debug) console.info(generate(ast, { sourceMaps: true }).code)
508
+ if (debug) console.info('')
509
+ if (debug) console.info('')
510
+ if (debug) console.info('')
511
+
500
512
  deadCodeElimination(ast)
501
513
 
514
+ if (debug) console.info('')
515
+ if (debug) console.info('Dead Code Elimination Output 2:')
516
+ if (debug) console.info(generate(ast, { sourceMaps: true }).code)
517
+ if (debug) console.info('')
518
+ if (debug) console.info('')
519
+ if (debug) console.info('')
520
+
502
521
  // if there are exported identifiers, then we need to add a warning
503
522
  // to the file to let the user know that the exported identifiers
504
523
  // will not in the split file but in the original file, therefore
@@ -1,2 +1 @@
1
- export const CONFIG_FILE_NAME = 'tsr.config.json'
2
1
  export const splitPrefix = 'tsr-split'
@@ -70,6 +70,14 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
70
70
  const handleSplittingFile = (code: string, id: string) => {
71
71
  if (debug) console.info('Splitting route: ', id)
72
72
 
73
+ if (debug) console.info('')
74
+ if (debug) console.info('Split Route Input: ', id)
75
+ if (debug) console.info('')
76
+ if (debug) console.info(code)
77
+ if (debug) console.info('')
78
+ if (debug) console.info('')
79
+ if (debug) console.info('')
80
+
73
81
  const compiledVirtualRoute = compileCodeSplitVirtualRoute({
74
82
  code,
75
83
  root: ROOT,
@@ -77,7 +85,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
77
85
  })
78
86
 
79
87
  if (debug) console.info('')
80
- if (debug) console.info('Split Output')
88
+ if (debug) console.info('Split Route Output: ', id)
81
89
  if (debug) console.info('')
82
90
  if (debug) console.info(compiledVirtualRoute.code)
83
91
  if (debug) console.info('')
@@ -97,7 +105,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
97
105
  })
98
106
 
99
107
  if (debug) console.info('')
100
- if (debug) console.info('Compiled Output')
108
+ if (debug) console.info('Handling createRoute output: ', id)
101
109
  if (debug) console.info('')
102
110
  if (debug) console.info(compiledReferenceRoute.code)
103
111
  if (debug) console.info('')
@@ -1,8 +1,7 @@
1
1
  import { isAbsolute, join, normalize, resolve } from 'node:path'
2
- import { generator } from '@tanstack/router-generator'
2
+ import { generator, resolveConfigPath } from '@tanstack/router-generator'
3
3
 
4
4
  import { getConfig } from './config'
5
- import { CONFIG_FILE_NAME } from './constants'
6
5
  import type { UnpluginFactory } from 'unplugin'
7
6
  import type { Config } from './config'
8
7
 
@@ -49,7 +48,7 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
49
48
  ) => {
50
49
  const filePath = normalize(file)
51
50
 
52
- if (filePath === join(ROOT, CONFIG_FILE_NAME)) {
51
+ if (filePath === resolveConfigPath({ configDirectory: ROOT })) {
53
52
  userConfig = getConfig(options, ROOT)
54
53
  return
55
54
  }