@tanstack/router-vite-plugin 1.23.0 → 1.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/cjs/compilers.cjs +335 -0
  2. package/dist/cjs/compilers.cjs.map +1 -0
  3. package/dist/cjs/compilers.d.cts +38 -0
  4. package/dist/cjs/constants.cjs +5 -0
  5. package/dist/cjs/constants.cjs.map +1 -0
  6. package/dist/cjs/constants.d.cts +1 -0
  7. package/dist/cjs/eliminateUnreferencedIdentifiers.cjs +144 -0
  8. package/dist/cjs/eliminateUnreferencedIdentifiers.cjs.map +1 -0
  9. package/dist/cjs/eliminateUnreferencedIdentifiers.d.cts +8 -0
  10. package/dist/cjs/index.cjs +141 -13
  11. package/dist/cjs/index.cjs.map +1 -1
  12. package/dist/cjs/index.d.cts +55 -2
  13. package/dist/cjs/tests/index.test.d.cts +1 -0
  14. package/dist/cjs/tests/shared/imported.d.cts +5 -0
  15. package/dist/esm/compilers.d.ts +38 -0
  16. package/dist/esm/compilers.js +316 -0
  17. package/dist/esm/compilers.js.map +1 -0
  18. package/dist/esm/constants.d.ts +1 -0
  19. package/dist/esm/constants.js +5 -0
  20. package/dist/esm/constants.js.map +1 -0
  21. package/dist/esm/eliminateUnreferencedIdentifiers.d.ts +8 -0
  22. package/dist/esm/eliminateUnreferencedIdentifiers.js +127 -0
  23. package/dist/esm/eliminateUnreferencedIdentifiers.js.map +1 -0
  24. package/dist/esm/index.d.ts +55 -2
  25. package/dist/esm/index.js +142 -14
  26. package/dist/esm/index.js.map +1 -1
  27. package/dist/esm/tests/index.test.d.ts +1 -0
  28. package/dist/esm/tests/shared/imported.d.ts +5 -0
  29. package/package.json +18 -1
  30. package/src/compilers.ts +420 -0
  31. package/src/constants.ts +1 -0
  32. package/src/eliminateUnreferencedIdentifiers.ts +287 -0
  33. package/src/index.ts +181 -16
  34. package/src/tests/index.test.ts +60 -0
  35. package/src/tests/shared/imported.tsx +11 -0
  36. package/src/tests/snapshots/function-declaration.tsx +10 -0
  37. package/src/tests/snapshots/function-declaration?split.tsx +29 -0
  38. package/src/tests/snapshots/imported.tsx +10 -0
  39. package/src/tests/snapshots/imported?split.tsx +5 -0
  40. package/src/tests/snapshots/inline.tsx +8 -0
  41. package/src/tests/snapshots/inline?split.tsx +18 -0
  42. package/src/tests/snapshots/random-number.tsx +11 -0
  43. package/src/tests/snapshots/random-number?split.tsx +27 -0
  44. package/src/tests/test-files/function-declaration.tsx +39 -0
  45. package/src/tests/test-files/imported.tsx +8 -0
  46. package/src/tests/test-files/inline.tsx +25 -0
  47. package/src/tests/test-files/random-number.tsx +83 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compilers.js","sources":["../../src/compilers.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport * as template from '@babel/template'\nimport * as babel from '@babel/core'\nimport { splitPrefix } from './constants'\nimport { eliminateUnreferencedIdentifiers } from './eliminateUnreferencedIdentifiers'\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 type CompileFn = (compileOpts: {\n code: string\n filename: string\n getBabelConfig: () => { plugins: Array<any> }\n}) => Promise<{\n code: string\n map: any\n}>\n\nexport function makeCompile(makeOpts: { root: string }) {\n return async (opts: {\n code: string\n filename: string\n getBabelConfig: () => { plugins: Array<any> }\n }): Promise<{\n code: string\n map: any\n }> => {\n const res = await babel.transform(opts.code, {\n plugins: [\n ['@babel/plugin-syntax-jsx', {}],\n [\n '@babel/plugin-syntax-typescript',\n {\n isTSX: true,\n },\n ],\n ...opts.getBabelConfig().plugins,\n ],\n root: makeOpts.root,\n filename: opts.filename,\n sourceMaps: true,\n })\n\n if (res?.code) {\n return {\n code: res.code,\n map: res.map,\n }\n }\n\n return {\n code: opts.code,\n map: null,\n }\n }\n}\n\nexport async function compileFile(opts: {\n code: string\n compile: CompileFn\n filename: string\n}) {\n return await opts.compile({\n code: opts.code,\n filename: opts.filename,\n getBabelConfig: () => ({\n plugins: [\n [\n {\n visitor: {\n Program: {\n enter(programPath: babel.NodePath<t.Program>, state: State) {\n const splitUrl = `${splitPrefix}:${state.filename}?${splitPrefix}`\n\n programPath.traverse(\n {\n CallExpression: (path) => {\n if (path.node.callee.type === 'Identifier') {\n if (\n path.node.callee.name === 'createRoute' ||\n path.node.callee.name === 'createFileRoute'\n ) {\n if (\n path.parentPath.node.type === 'CallExpression'\n ) {\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n let found = false\n\n if (t.isObjectExpression(options)) {\n options.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n if (t.isIdentifier(prop.key)) {\n if (prop.key.name === 'component') {\n const value = prop.value\n\n if (t.isIdentifier(value)) {\n removeIdentifierLiteral(path, value)\n }\n\n // Prepend the import statement to the program along with the importer function\n\n programPath.unshiftContainer('body', [\n template.smart(\n `import { lazyRouteComponent } from '@tanstack/react-router'`,\n )() as t.Statement,\n template.smart(\n `const $$splitComponentImporter = () => import('${splitUrl}')`,\n )() as t.Statement,\n ])\n\n prop.value = template.expression(\n `lazyRouteComponent($$splitComponentImporter, 'component')`,\n )() as any\n\n programPath.pushContainer('body', [\n template.smart(\n `function DummyComponent() { return null }`,\n )() as t.Statement,\n ])\n\n found = true\n } else if (prop.key.name === 'loader') {\n const value = prop.value\n\n if (t.isIdentifier(value)) {\n removeIdentifierLiteral(path, value)\n }\n\n // Prepend the import statement to the program along with the importer function\n\n programPath.unshiftContainer('body', [\n template.smart(\n `import { lazyFn } from '@tanstack/react-router'`,\n )() as t.Statement,\n template.smart(\n `const $$splitLoaderImporter = () => import('${splitUrl}')`,\n )() as t.Statement,\n ])\n\n prop.value = template.expression(\n `lazyFn($$splitLoaderImporter, 'loader')`,\n )() as any\n\n found = true\n }\n }\n }\n })\n }\n\n if (found as boolean) {\n programPath.pushContainer('body', [\n template.smart(\n `function TSR_Dummy_Component() {}`,\n )() as t.Statement,\n ])\n }\n }\n }\n }\n },\n },\n state,\n )\n\n eliminateUnreferencedIdentifiers(programPath)\n },\n },\n },\n },\n {\n root: process.cwd(),\n minify: process.env.NODE_ENV === 'production',\n },\n ],\n ].filter(Boolean),\n }),\n })\n}\n\n// Reusable function to get literal value or resolve variable to literal\nfunction resolveIdentifier(path: any, node: any) {\n if (t.isIdentifier(node)) {\n const binding = path.scope.getBinding(node.name)\n if (\n binding\n // && binding.kind === 'const'\n ) {\n const declarator = binding.path.node\n if (t.isObjectExpression(declarator.init)) {\n return declarator.init\n } else if (t.isFunctionDeclaration(declarator.init)) {\n return declarator.init\n }\n }\n return undefined\n }\n\n return node\n}\n\nfunction removeIdentifierLiteral(path: any, node: any) {\n if (t.isIdentifier(node)) {\n const binding = path.scope.getBinding(node.name)\n if (binding) {\n binding.path.remove()\n }\n }\n}\n\nconst splitNodeTypes = ['component', 'loader'] as const\ntype SplitNodeType = (typeof splitNodeTypes)[number]\n\nexport async function splitFile(opts: {\n code: string\n compile: CompileFn\n filename: string\n // ref: string\n}) {\n return await opts.compile({\n code: opts.code,\n filename: opts.filename,\n getBabelConfig: () => ({\n plugins: [\n [\n {\n visitor: {\n Program: {\n enter(programPath: babel.NodePath<t.Program>, state: State) {\n const splitNodesByType: Record<\n SplitNodeType,\n t.Node | undefined\n > = {\n component: undefined,\n loader: undefined,\n }\n\n // Find the node\n programPath.traverse(\n {\n CallExpression: (path) => {\n if (path.node.callee.type === 'Identifier') {\n if (path.node.callee.name === 'createFileRoute') {\n if (\n path.parentPath.node.type === 'CallExpression'\n ) {\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n if (t.isObjectExpression(options)) {\n options.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n splitNodeTypes.forEach((type) => {\n if (t.isIdentifier(prop.key)) {\n if (prop.key.name === type) {\n splitNodesByType[type] = prop.value\n }\n }\n })\n }\n })\n\n // Remove all of the options\n options.properties = []\n }\n }\n }\n }\n },\n },\n state,\n )\n\n splitNodeTypes.forEach((splitType) => {\n let splitNode = splitNodesByType[splitType]\n\n if (!splitNode) {\n return\n }\n\n while (t.isIdentifier(splitNode)) {\n const binding = programPath.scope.getBinding(\n splitNode.name,\n )\n splitNode = binding?.path.node\n }\n\n // Add the node to the program\n if (splitNode) {\n if (t.isFunctionDeclaration(splitNode)) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitType),\n t.functionExpression(\n splitNode.id || null, // Anonymize the function expression\n splitNode.params,\n splitNode.body,\n splitNode.generator,\n splitNode.async,\n ),\n ),\n ]),\n )\n } else if (\n t.isFunctionExpression(splitNode) ||\n t.isArrowFunctionExpression(splitNode)\n ) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitType),\n splitNode as any,\n ),\n ]),\n )\n } else if (t.isImportSpecifier(splitNode)) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitType),\n splitNode.local,\n ),\n ]),\n )\n } else {\n console.log(splitNode)\n throw new Error(\n `Unexpected splitNode type: ${splitNode.type}`,\n )\n }\n }\n\n // If the splitNode exists at the top of the program\n // then we need to remove that copy\n programPath.node.body = programPath.node.body.filter(\n (node) => {\n // console.log(node)\n return node !== splitNode\n },\n )\n\n // Export the node\n programPath.pushContainer('body', [\n t.exportNamedDeclaration(null, [\n t.exportSpecifier(\n t.identifier(splitType),\n t.identifier(splitType),\n ),\n ]),\n ])\n })\n\n // convert exports to imports from the original file\n programPath.traverse({\n ExportNamedDeclaration(path) {\n // e.g. export const x = 1 or export { x }\n // becomes\n // import { x } from '${opts.id}'\n\n if (path.node.declaration) {\n if (t.isVariableDeclaration(path.node.declaration)) {\n path.replaceWith(\n t.importDeclaration(\n path.node.declaration.declarations.map((decl) =>\n t.importSpecifier(\n t.identifier((decl.id as any).name),\n t.identifier((decl.id as any).name),\n ),\n ),\n t.stringLiteral(\n opts.filename.split(\n `?${splitPrefix}`,\n )[0] as string,\n ),\n ),\n )\n }\n }\n },\n })\n\n eliminateUnreferencedIdentifiers(programPath)\n },\n },\n },\n },\n {\n root: process.cwd(),\n minify: process.env.NODE_ENV === 'production',\n },\n ],\n ].filter(Boolean),\n }),\n })\n}\n"],"names":[],"mappings":";;;;;AAiCO,SAAS,YAAY,UAA4B;AACtD,SAAO,OAAO,SAOR;AACJ,UAAM,MAAM,MAAM,MAAM,UAAU,KAAK,MAAM;AAAA,MAC3C,SAAS;AAAA,QACP,CAAC,4BAA4B,CAAA,CAAE;AAAA,QAC/B;AAAA,UACE;AAAA,UACA;AAAA,YACE,OAAO;AAAA,UACT;AAAA,QACF;AAAA,QACA,GAAG,KAAK,eAAA,EAAiB;AAAA,MAC3B;AAAA,MACA,MAAM,SAAS;AAAA,MACf,UAAU,KAAK;AAAA,MACf,YAAY;AAAA,IAAA,CACb;AAED,QAAI,2BAAK,MAAM;AACN,aAAA;AAAA,QACL,MAAM,IAAI;AAAA,QACV,KAAK,IAAI;AAAA,MAAA;AAAA,IAEb;AAEO,WAAA;AAAA,MACL,MAAM,KAAK;AAAA,MACX,KAAK;AAAA,IAAA;AAAA,EACP;AAEJ;AAEA,eAAsB,YAAY,MAI/B;AACM,SAAA,MAAM,KAAK,QAAQ;AAAA,IACxB,MAAM,KAAK;AAAA,IACX,UAAU,KAAK;AAAA,IACf,gBAAgB,OAAO;AAAA,MACrB,SAAS;AAAA,QACP;AAAA,UACE;AAAA,YACE,SAAS;AAAA,cACP,SAAS;AAAA,gBACP,MAAM,aAAwC,OAAc;AAC1D,wBAAM,WAAW,GAAG,WAAW,IAAI,MAAM,QAAQ,IAAI,WAAW;AAEpD,8BAAA;AAAA,oBACV;AAAA,sBACE,gBAAgB,CAAC,SAAS;AACxB,4BAAI,KAAK,KAAK,OAAO,SAAS,cA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K,aAAa;AACzB,4BAAI,EAAE,sBAAsB,KAAK,KAAK,WAAW,GAAG;AAC7C,+BAAA;AAAA,4BACH,EAAE;AAAA,8BACA,KAAK,KAAK,YAAY,aAAa;AAAA,gCAAI,CAAC,SACtC,EAAE;AAAA,kCACA,EAAE,WAAY,KAAK,GAAW,IAAI;AAAA,kCAClC,EAAE,WAAY,KAAK,GAAW,IAAI;AAAA,gCACpC;AAAA,8BACF;AAAA,8BACA,EAAE;AAAA,gCACA,KAAK,SAAS;AAAA,kCACZ,IAAI,WAAW;AAAA,kCACf,CAAC;AAAA,8BACL;AAAA,4BACF;AAAA,0BAAA;AAAA,wBAEJ;AAAA,sBACF;AAAA,oBACF;AAAA,kBAAA,CACD;AAED,mDAAiC,WAAW;AAAA,gBAC9C;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,UACA;AAAA,YACE,MAAM,QAAQ,IAAI;AAAA,YAClB,QAAQ,QAAQ,IAAI,aAAa;AAAA,UACnC;AAAA,QACF;AAAA,MAAA,EACA,OAAO,OAAO;AAAA,IAAA;AAAA,EAClB,CACD;AACH;"}
@@ -0,0 +1 @@
1
+ export declare const splitPrefix = "tsr-split";
@@ -0,0 +1,5 @@
1
+ const splitPrefix = "tsr-split";
2
+ export {
3
+ splitPrefix
4
+ };
5
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["export const splitPrefix = 'tsr-split'\n"],"names":[],"mappings":"AAAO,MAAM,cAAc;"}
@@ -0,0 +1,8 @@
1
+ import type { types as BabelTypes } from '@babel/core';
2
+ import type { NodePath } from '@babel/traverse';
3
+ type IdentifierPath = NodePath<BabelTypes.Identifier>;
4
+ /**
5
+ * @param refs - If provided, only these identifiers will be considered for removal.
6
+ */
7
+ export declare const eliminateUnreferencedIdentifiers: (programPath: NodePath<BabelTypes.Program>, refs?: Set<IdentifierPath>) => void;
8
+ export {};
@@ -0,0 +1,127 @@
1
+ import * as t from "@babel/types";
2
+ const eliminateUnreferencedIdentifiers = (programPath, refs) => {
3
+ let referencesRemovedInThisPass;
4
+ const shouldBeRemoved = (ident) => {
5
+ if (isIdentifierReferenced(ident))
6
+ return false;
7
+ if (!refs)
8
+ return true;
9
+ return refs.has(ident);
10
+ };
11
+ const sweepFunction = (path) => {
12
+ const identifier = getIdentifier(path);
13
+ if ((identifier == null ? void 0 : identifier.node) && shouldBeRemoved(identifier)) {
14
+ ++referencesRemovedInThisPass;
15
+ if (t.isAssignmentExpression(path.parentPath.node) || t.isVariableDeclarator(path.parentPath.node)) {
16
+ path.parentPath.remove();
17
+ } else {
18
+ path.remove();
19
+ }
20
+ }
21
+ };
22
+ const sweepImport = (path) => {
23
+ const local = path.get("local");
24
+ if (shouldBeRemoved(local)) {
25
+ ++referencesRemovedInThisPass;
26
+ path.remove();
27
+ if (path.parent.specifiers.length === 0) {
28
+ path.parentPath.remove();
29
+ }
30
+ }
31
+ };
32
+ do {
33
+ referencesRemovedInThisPass = 0;
34
+ programPath.scope.crawl();
35
+ programPath.traverse({
36
+ VariableDeclarator(path) {
37
+ if (path.node.id.type === "Identifier") {
38
+ const local = path.get("id");
39
+ if (shouldBeRemoved(local)) {
40
+ ++referencesRemovedInThisPass;
41
+ path.remove();
42
+ }
43
+ } else if (path.node.id.type === "ObjectPattern") {
44
+ const pattern = path.get("id");
45
+ const beforeCount = referencesRemovedInThisPass;
46
+ const properties = pattern.get("properties");
47
+ properties.forEach((property) => {
48
+ const local = property.get(
49
+ property.node.type === "ObjectProperty" ? "value" : (
50
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
51
+ property.node.type === "RestElement" ? "argument" : function() {
52
+ throw new Error("invariant");
53
+ }()
54
+ )
55
+ );
56
+ if (shouldBeRemoved(local)) {
57
+ ++referencesRemovedInThisPass;
58
+ property.remove();
59
+ }
60
+ });
61
+ if (beforeCount !== referencesRemovedInThisPass && pattern.get("properties").length < 1) {
62
+ path.remove();
63
+ }
64
+ } else if (path.node.id.type === "ArrayPattern") {
65
+ const pattern = path.get("id");
66
+ const beforeCount = referencesRemovedInThisPass;
67
+ const elements = pattern.get("elements");
68
+ elements.forEach((e) => {
69
+ var _a, _b;
70
+ let local;
71
+ if (((_a = e.node) == null ? void 0 : _a.type) === "Identifier") {
72
+ local = e;
73
+ } else if (((_b = e.node) == null ? void 0 : _b.type) === "RestElement") {
74
+ local = e.get("argument");
75
+ } else {
76
+ return;
77
+ }
78
+ if (shouldBeRemoved(local)) {
79
+ ++referencesRemovedInThisPass;
80
+ e.remove();
81
+ }
82
+ });
83
+ if (beforeCount !== referencesRemovedInThisPass && pattern.get("elements").length < 1) {
84
+ path.remove();
85
+ }
86
+ }
87
+ },
88
+ FunctionDeclaration: sweepFunction,
89
+ FunctionExpression: sweepFunction,
90
+ ArrowFunctionExpression: sweepFunction,
91
+ ImportSpecifier: sweepImport,
92
+ ImportDefaultSpecifier: sweepImport,
93
+ ImportNamespaceSpecifier: sweepImport
94
+ });
95
+ } while (referencesRemovedInThisPass);
96
+ };
97
+ function getIdentifier(path) {
98
+ const parentPath = path.parentPath;
99
+ if (parentPath.type === "VariableDeclarator") {
100
+ const variablePath = parentPath;
101
+ const name = variablePath.get("id");
102
+ return name.node.type === "Identifier" ? name : null;
103
+ }
104
+ if (parentPath.type === "AssignmentExpression") {
105
+ const variablePath = parentPath;
106
+ const name = variablePath.get("left");
107
+ return name.node.type === "Identifier" ? name : null;
108
+ }
109
+ if (path.node.type === "ArrowFunctionExpression") {
110
+ return null;
111
+ }
112
+ return path.node.id && path.node.id.type === "Identifier" ? path.get("id") : null;
113
+ }
114
+ function isIdentifierReferenced(ident) {
115
+ const binding = ident.scope.getBinding(ident.node.name);
116
+ if (binding == null ? void 0 : binding.referenced) {
117
+ if (binding.path.type === "FunctionDeclaration") {
118
+ return !binding.constantViolations.concat(binding.referencePaths).every((ref) => ref.findParent((parent) => parent === binding.path));
119
+ }
120
+ return true;
121
+ }
122
+ return false;
123
+ }
124
+ export {
125
+ eliminateUnreferencedIdentifiers
126
+ };
127
+ //# sourceMappingURL=eliminateUnreferencedIdentifiers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eliminateUnreferencedIdentifiers.js","sources":["../../src/eliminateUnreferencedIdentifiers.ts"],"sourcesContent":["// Copied from https://github.com/pcattori/vite-env-only/blob/main/src/dce.ts\n// Adapted with some minor changes for the purpose of this project\n\nimport * as t from '@babel/types'\nimport type { types as BabelTypes } from '@babel/core'\nimport type { NodePath } from '@babel/traverse'\n\ntype IdentifierPath = NodePath<BabelTypes.Identifier>\n\n// export function findReferencedIdentifiers(\n// programPath: NodePath<BabelTypes.Program>,\n// ): Set<IdentifierPath> {\n// const refs = new Set<IdentifierPath>()\n\n// function markFunction(\n// path: NodePath<\n// | BabelTypes.FunctionDeclaration\n// | BabelTypes.FunctionExpression\n// | BabelTypes.ArrowFunctionExpression\n// >,\n// ) {\n// const ident = getIdentifier(path)\n// if (ident?.node && isIdentifierReferenced(ident)) {\n// refs.add(ident)\n// }\n// }\n\n// function markImport(\n// path: NodePath<\n// | BabelTypes.ImportSpecifier\n// | BabelTypes.ImportDefaultSpecifier\n// | BabelTypes.ImportNamespaceSpecifier\n// >,\n// ) {\n// const local = path.get('local')\n// if (isIdentifierReferenced(local)) {\n// refs.add(local)\n// }\n// }\n\n// programPath.traverse({\n// VariableDeclarator(path) {\n// if (path.node.id.type === 'Identifier') {\n// const local = path.get('id') as NodePath<BabelTypes.Identifier>\n// if (isIdentifierReferenced(local)) {\n// refs.add(local)\n// }\n// } else if (path.node.id.type === 'ObjectPattern') {\n// const pattern = path.get('id') as NodePath<BabelTypes.ObjectPattern>\n\n// const properties = pattern.get('properties')\n// properties.forEach((p) => {\n// const local = p.get(\n// p.node.type === 'ObjectProperty'\n// ? 'value'\n// : p.node.type === 'RestElement'\n// ? 'argument'\n// : (function () {\n// throw new Error('invariant')\n// })(),\n// ) as NodePath<BabelTypes.Identifier>\n// if (isIdentifierReferenced(local)) {\n// refs.add(local)\n// }\n// })\n// } else if (path.node.id.type === 'ArrayPattern') {\n// const pattern = path.get('id') as NodePath<BabelTypes.ArrayPattern>\n\n// const elements = pattern.get('elements')\n// elements.forEach((e) => {\n// let local: NodePath<BabelTypes.Identifier>\n// if (e.node?.type === 'Identifier') {\n// local = e as NodePath<BabelTypes.Identifier>\n// } else if (e.node?.type === 'RestElement') {\n// local = e.get('argument') as NodePath<BabelTypes.Identifier>\n// } else {\n// return\n// }\n\n// if (isIdentifierReferenced(local)) {\n// refs.add(local)\n// }\n// })\n// }\n// },\n\n// FunctionDeclaration: markFunction,\n// FunctionExpression: markFunction,\n// ArrowFunctionExpression: markFunction,\n// ImportSpecifier: markImport,\n// ImportDefaultSpecifier: markImport,\n// ImportNamespaceSpecifier: markImport,\n// })\n// return refs\n// }\n\n/**\n * @param refs - If provided, only these identifiers will be considered for removal.\n */\nexport const eliminateUnreferencedIdentifiers = (\n programPath: NodePath<BabelTypes.Program>,\n refs?: Set<IdentifierPath>,\n) => {\n let referencesRemovedInThisPass: number\n\n const shouldBeRemoved = (ident: IdentifierPath) => {\n if (isIdentifierReferenced(ident)) return false\n if (!refs) return true\n return refs.has(ident)\n }\n\n const sweepFunction = (\n path: NodePath<\n | BabelTypes.FunctionDeclaration\n | BabelTypes.FunctionExpression\n | BabelTypes.ArrowFunctionExpression\n >,\n ) => {\n const identifier = getIdentifier(path)\n if (identifier?.node && shouldBeRemoved(identifier)) {\n ++referencesRemovedInThisPass\n\n if (\n t.isAssignmentExpression(path.parentPath.node) ||\n t.isVariableDeclarator(path.parentPath.node)\n ) {\n path.parentPath.remove()\n } else {\n path.remove()\n }\n }\n }\n\n const sweepImport = (\n path: NodePath<\n | BabelTypes.ImportSpecifier\n | BabelTypes.ImportDefaultSpecifier\n | BabelTypes.ImportNamespaceSpecifier\n >,\n ) => {\n const local = path.get('local')\n if (shouldBeRemoved(local)) {\n ++referencesRemovedInThisPass\n path.remove()\n if (\n (path.parent as BabelTypes.ImportDeclaration).specifiers.length === 0\n ) {\n path.parentPath.remove()\n }\n }\n }\n\n // Traverse again to remove unused references. This happens at least once,\n // then repeats until no more references are removed.\n do {\n referencesRemovedInThisPass = 0\n\n programPath.scope.crawl()\n\n programPath.traverse({\n VariableDeclarator(path) {\n if (path.node.id.type === 'Identifier') {\n const local = path.get('id') as NodePath<BabelTypes.Identifier>\n if (shouldBeRemoved(local)) {\n ++referencesRemovedInThisPass\n path.remove()\n }\n } else if (path.node.id.type === 'ObjectPattern') {\n const pattern = path.get('id') as NodePath<BabelTypes.ObjectPattern>\n\n const beforeCount = referencesRemovedInThisPass\n const properties = pattern.get('properties')\n properties.forEach((property) => {\n const local = property.get(\n property.node.type === 'ObjectProperty'\n ? 'value'\n : // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n property.node.type === 'RestElement'\n ? 'argument'\n : (function () {\n throw new Error('invariant')\n })(),\n ) as NodePath<BabelTypes.Identifier>\n\n if (shouldBeRemoved(local)) {\n ++referencesRemovedInThisPass\n property.remove()\n }\n })\n\n if (\n beforeCount !== referencesRemovedInThisPass &&\n pattern.get('properties').length < 1\n ) {\n path.remove()\n }\n } else if (path.node.id.type === 'ArrayPattern') {\n const pattern = path.get('id') as NodePath<BabelTypes.ArrayPattern>\n\n const beforeCount = referencesRemovedInThisPass\n const elements = pattern.get('elements')\n elements.forEach((e) => {\n let local: NodePath<BabelTypes.Identifier>\n if (e.node?.type === 'Identifier') {\n local = e as NodePath<BabelTypes.Identifier>\n } else if (e.node?.type === 'RestElement') {\n local = e.get('argument') as NodePath<BabelTypes.Identifier>\n } else {\n return\n }\n\n if (shouldBeRemoved(local)) {\n ++referencesRemovedInThisPass\n e.remove()\n }\n })\n\n if (\n beforeCount !== referencesRemovedInThisPass &&\n pattern.get('elements').length < 1\n ) {\n path.remove()\n }\n }\n },\n FunctionDeclaration: sweepFunction,\n FunctionExpression: sweepFunction,\n ArrowFunctionExpression: sweepFunction,\n ImportSpecifier: sweepImport,\n ImportDefaultSpecifier: sweepImport,\n ImportNamespaceSpecifier: sweepImport,\n })\n } while (referencesRemovedInThisPass)\n}\n\nfunction getIdentifier(\n path: NodePath<\n | BabelTypes.FunctionDeclaration\n | BabelTypes.FunctionExpression\n | BabelTypes.ArrowFunctionExpression\n >,\n): NodePath<BabelTypes.Identifier> | null {\n const parentPath = path.parentPath\n if (parentPath.type === 'VariableDeclarator') {\n const variablePath = parentPath as NodePath<BabelTypes.VariableDeclarator>\n const name = variablePath.get('id')\n return name.node.type === 'Identifier'\n ? (name as NodePath<BabelTypes.Identifier>)\n : null\n }\n\n if (parentPath.type === 'AssignmentExpression') {\n const variablePath = parentPath as NodePath<BabelTypes.AssignmentExpression>\n const name = variablePath.get('left')\n return name.node.type === 'Identifier'\n ? (name as NodePath<BabelTypes.Identifier>)\n : null\n }\n\n if (path.node.type === 'ArrowFunctionExpression') {\n return null\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n return path.node.id && path.node.id.type === 'Identifier'\n ? (path.get('id') as NodePath<BabelTypes.Identifier>)\n : null\n}\n\nfunction isIdentifierReferenced(\n ident: NodePath<BabelTypes.Identifier>,\n): boolean {\n const binding = ident.scope.getBinding(ident.node.name)\n if (binding?.referenced) {\n // Functions can reference themselves, so we need to check if there's a\n // binding outside the function scope or not.\n if (binding.path.type === 'FunctionDeclaration') {\n return !binding.constantViolations\n .concat(binding.referencePaths)\n // Check that every reference is contained within the function:\n .every((ref) => ref.findParent((parent) => parent === binding.path))\n }\n\n return true\n }\n return false\n}\n"],"names":[],"mappings":";AAmGa,MAAA,mCAAmC,CAC9C,aACA,SACG;AACC,MAAA;AAEE,QAAA,kBAAkB,CAAC,UAA0B;AACjD,QAAI,uBAAuB,KAAK;AAAU,aAAA;AAC1C,QAAI,CAAC;AAAa,aAAA;AACX,WAAA,KAAK,IAAI,KAAK;AAAA,EAAA;AAGjB,QAAA,gBAAgB,CACpB,SAKG;AACG,UAAA,aAAa,cAAc,IAAI;AACrC,SAAI,yCAAY,SA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UAAU,MAAM,MAAM,WAAW,MAAM,KAAK,IAAI;AACtD,MAAI,mCAAS,YAAY;AAGnB,QAAA,QAAQ,KAAK,SAAS,uBAAuB;AAC/C,aAAO,CAAC,QAAQ,mBACb,OAAO,QAAQ,cAAc,EAE7B,MAAM,CAAC,QAAQ,IAAI,WAAW,CAAC,WAAW,WAAW,QAAQ,IAAI,CAAC;AAAA,IACvE;AAEO,WAAA;AAAA,EACT;AACO,SAAA;AACT;"}
@@ -1,3 +1,56 @@
1
- import { type Config } from '@tanstack/router-generator';
1
+ import { z } from 'zod';
2
2
  import type { Plugin } from 'vite';
3
- export declare function TanStackRouterVite(inlineConfig?: Partial<Config>): Plugin;
3
+ export declare const configSchema: z.ZodObject<{
4
+ routeFilePrefix: z.ZodOptional<z.ZodString>;
5
+ routeFileIgnorePrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
6
+ routeFileIgnorePattern: z.ZodOptional<z.ZodString>;
7
+ routesDirectory: z.ZodDefault<z.ZodOptional<z.ZodString>>;
8
+ generatedRouteTree: z.ZodDefault<z.ZodOptional<z.ZodString>>;
9
+ quoteStyle: z.ZodDefault<z.ZodOptional<z.ZodEnum<["single", "double"]>>>;
10
+ semicolons: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
11
+ disableTypes: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
12
+ addExtensions: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
13
+ disableLogging: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
14
+ enableRouteGeneration: z.ZodOptional<z.ZodBoolean>;
15
+ experimental: z.ZodOptional<z.ZodObject<{
16
+ enableCodeSplitting: z.ZodOptional<z.ZodBoolean>;
17
+ }, "strip", z.ZodTypeAny, {
18
+ enableCodeSplitting?: boolean | undefined;
19
+ }, {
20
+ enableCodeSplitting?: boolean | undefined;
21
+ }>>;
22
+ }, "strip", z.ZodTypeAny, {
23
+ routeFileIgnorePrefix: string;
24
+ routesDirectory: string;
25
+ generatedRouteTree: string;
26
+ quoteStyle: "single" | "double";
27
+ semicolons: boolean;
28
+ disableTypes: boolean;
29
+ addExtensions: boolean;
30
+ disableLogging: boolean;
31
+ routeFilePrefix?: string | undefined;
32
+ routeFileIgnorePattern?: string | undefined;
33
+ enableRouteGeneration?: boolean | undefined;
34
+ experimental?: {
35
+ enableCodeSplitting?: boolean | undefined;
36
+ } | undefined;
37
+ }, {
38
+ routeFilePrefix?: string | undefined;
39
+ routeFileIgnorePrefix?: string | undefined;
40
+ routeFileIgnorePattern?: string | undefined;
41
+ routesDirectory?: string | undefined;
42
+ generatedRouteTree?: string | undefined;
43
+ quoteStyle?: "single" | "double" | undefined;
44
+ semicolons?: boolean | undefined;
45
+ disableTypes?: boolean | undefined;
46
+ addExtensions?: boolean | undefined;
47
+ disableLogging?: boolean | undefined;
48
+ enableRouteGeneration?: boolean | undefined;
49
+ experimental?: {
50
+ enableCodeSplitting?: boolean | undefined;
51
+ } | undefined;
52
+ }>;
53
+ export type Config = z.infer<typeof configSchema>;
54
+ export declare function TanStackRouterVite(inlineConfig?: Partial<Config>): Array<Plugin>;
55
+ export declare function TanStackRouterViteGenerator(inlineConfig?: Partial<Config>): Plugin;
56
+ export declare function TanStackRouterViteCodeSplitter(inlineConfig?: Partial<Config>): Plugin;
package/dist/esm/index.js CHANGED
@@ -1,8 +1,28 @@
1
1
  import { normalize, join, isAbsolute } from "path";
2
- import { getConfig, generator } from "@tanstack/router-generator";
2
+ import { pathToFileURL, fileURLToPath } from "url";
3
+ import { z } from "zod";
4
+ import { configSchema as configSchema$1, getConfig as getConfig$1, generator } from "@tanstack/router-generator";
5
+ import { splitFile, compileFile, makeCompile } from "./compilers.js";
6
+ import { splitPrefix } from "./constants.js";
7
+ const configSchema = configSchema$1.extend({
8
+ enableRouteGeneration: z.boolean().optional(),
9
+ experimental: z.object({
10
+ enableCodeSplitting: z.boolean().optional()
11
+ }).optional()
12
+ });
3
13
  const CONFIG_FILE_NAME = "tsr.config.json";
14
+ const getConfig = async (inlineConfig, root) => {
15
+ const config = await getConfig$1(inlineConfig, root);
16
+ return configSchema.parse({ ...inlineConfig, ...config });
17
+ };
4
18
  function TanStackRouterVite(inlineConfig = {}) {
5
- const ROOT = process.cwd();
19
+ return [
20
+ TanStackRouterViteGenerator(inlineConfig),
21
+ TanStackRouterViteCodeSplitter(inlineConfig)
22
+ ];
23
+ }
24
+ function TanStackRouterViteGenerator(inlineConfig = {}) {
25
+ let ROOT = process.cwd();
6
26
  let userConfig;
7
27
  const generate = async () => {
8
28
  try {
@@ -12,26 +32,134 @@ function TanStackRouterVite(inlineConfig = {}) {
12
32
  console.info();
13
33
  }
14
34
  };
15
- return {
16
- name: "vite-plugin-tanstack-router",
17
- configResolved: async () => {
35
+ const handleFile = async (file) => {
36
+ const filePath = normalize(file);
37
+ if (filePath === join(ROOT, CONFIG_FILE_NAME)) {
18
38
  userConfig = await getConfig(inlineConfig, ROOT);
39
+ return;
40
+ }
41
+ const routesDirectoryPath = isAbsolute(userConfig.routesDirectory) ? userConfig.routesDirectory : join(ROOT, userConfig.routesDirectory);
42
+ if (filePath.startsWith(routesDirectoryPath)) {
19
43
  await generate();
44
+ }
45
+ };
46
+ return {
47
+ name: "vite-plugin-tanstack-router-generator",
48
+ configResolved: async (config) => {
49
+ ROOT = config.root;
50
+ userConfig = await getConfig(inlineConfig, ROOT);
51
+ if (userConfig.enableRouteGeneration ?? true) {
52
+ await generate();
53
+ }
20
54
  },
21
- handleHotUpdate: async ({ file }) => {
22
- const filePath = normalize(file);
23
- if (filePath === join(ROOT, CONFIG_FILE_NAME)) {
24
- userConfig = await getConfig(inlineConfig, ROOT);
25
- return;
55
+ watchChange: async (file, context) => {
56
+ if (userConfig.enableRouteGeneration ?? true) {
57
+ if (["create", "update", "delete"].includes(context.event)) {
58
+ await handleFile(file);
59
+ }
26
60
  }
27
- const routesDirectoryPath = isAbsolute(userConfig.routesDirectory) ? userConfig.routesDirectory : join(ROOT, userConfig.routesDirectory);
28
- if (filePath.startsWith(routesDirectoryPath)) {
29
- await generate();
61
+ }
62
+ };
63
+ }
64
+ function fileIsInRoutesDirectory(filePath, routesDirectory) {
65
+ const routesDirectoryPath = isAbsolute(routesDirectory) ? routesDirectory : join(process.cwd(), routesDirectory);
66
+ return filePath.startsWith(routesDirectoryPath);
67
+ }
68
+ function TanStackRouterViteCodeSplitter(inlineConfig = {}) {
69
+ let ROOT = process.cwd();
70
+ let userConfig;
71
+ return {
72
+ name: "vite-plugin-tanstack-router-code-splitter",
73
+ enforce: "pre",
74
+ configResolved: async (config) => {
75
+ ROOT = config.root;
76
+ userConfig = await getConfig(inlineConfig, ROOT);
77
+ },
78
+ resolveId(source) {
79
+ var _a;
80
+ if (!((_a = userConfig.experimental) == null ? void 0 : _a.enableCodeSplitting)) {
81
+ return null;
82
+ }
83
+ if (source.startsWith(splitPrefix + ":")) {
84
+ return source.replace(splitPrefix + ":", "");
85
+ }
86
+ return null;
87
+ },
88
+ async transform(code, id, transformOptions) {
89
+ var _a;
90
+ if (!((_a = userConfig.experimental) == null ? void 0 : _a.enableCodeSplitting)) {
91
+ return null;
92
+ }
93
+ const url = pathToFileURL(id);
94
+ url.searchParams.delete("v");
95
+ id = fileURLToPath(url).replace(/\\/g, "/");
96
+ const compile = makeCompile({
97
+ root: ROOT
98
+ });
99
+ if (id.includes(splitPrefix)) {
100
+ console.info("Splitting route: ", id);
101
+ const compiled = await splitFile({
102
+ code,
103
+ compile,
104
+ filename: id
105
+ // ref,
106
+ });
107
+ console.info("");
108
+ console.info("Split Output");
109
+ console.info("");
110
+ console.info(compiled.code);
111
+ console.info("");
112
+ console.info("");
113
+ console.info("");
114
+ console.info("");
115
+ console.info("");
116
+ console.info("");
117
+ console.info("");
118
+ console.info("");
119
+ return compiled;
120
+ } else if (fileIsInRoutesDirectory(id, userConfig.routesDirectory) && (code.includes("createRoute(") || code.includes("createFileRoute("))) {
121
+ if (code.includes("@react-refresh")) {
122
+ throw new Error(
123
+ `We detected that the '@vitejs/plugin-react' was passed before '@tanstack/router-vite-plugin'. Please make sure that '@tanstack/router-vite-plugin' is passed before '@vitejs/plugin-react' and try again:
124
+ e.g.
125
+
126
+ plugins: [
127
+ TanStackRouterVite(), // Place this before viteReact()
128
+ viteReact(),
129
+ ]
130
+ `
131
+ );
132
+ }
133
+ console.info("Handling createRoute: ", id);
134
+ const compiled = await compileFile({
135
+ code,
136
+ compile,
137
+ filename: id
138
+ });
139
+ console.info("");
140
+ console.info("Compiled Output");
141
+ console.info("");
142
+ console.info(compiled.code);
143
+ console.info("");
144
+ console.info("");
145
+ console.info("");
146
+ console.info("");
147
+ console.info("");
148
+ console.info("");
149
+ console.info("");
150
+ console.info("");
151
+ console.info("");
152
+ console.info("");
153
+ return compiled;
30
154
  }
155
+ return null;
31
156
  }
32
157
  };
33
158
  }
34
159
  export {
35
- TanStackRouterVite
160
+ TanStackRouterVite,
161
+ TanStackRouterViteCodeSplitter,
162
+ TanStackRouterViteGenerator,
163
+ configSchema
36
164
  };
37
165
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { isAbsolute, join, normalize } from 'path'\nimport { type Config, generator, getConfig } from '@tanstack/router-generator'\nimport type { Plugin } from 'vite'\n\nconst CONFIG_FILE_NAME = 'tsr.config.json'\n\nexport function TanStackRouterVite(inlineConfig: Partial<Config> = {}): Plugin {\n const ROOT: string = process.cwd()\n let userConfig: Config\n\n const generate = async () => {\n try {\n await generator(userConfig)\n } catch (err) {\n console.error(err)\n console.info()\n }\n }\n\n return {\n name: 'vite-plugin-tanstack-router',\n configResolved: async () => {\n userConfig = await getConfig(inlineConfig, ROOT)\n await generate()\n },\n handleHotUpdate: async ({ file }) => {\n const filePath = normalize(file)\n if (filePath === join(ROOT, CONFIG_FILE_NAME)) {\n userConfig = await getConfig(inlineConfig, ROOT)\n return\n }\n const routesDirectoryPath = isAbsolute(userConfig.routesDirectory)\n ? userConfig.routesDirectory\n : join(ROOT, userConfig.routesDirectory)\n if (filePath.startsWith(routesDirectoryPath)) {\n await generate()\n }\n },\n }\n}\n"],"names":[],"mappings":";;AAIA,MAAM,mBAAmB;AAET,SAAA,mBAAmB,eAAgC,IAAY;AACvE,QAAA,OAAe,QAAQ;AACzB,MAAA;AAEJ,QAAM,WAAW,YAAY;AACvB,QAAA;AACF,YAAM,UAAU,UAAU;AAAA,aACnB,KAAK;AACZ,cAAQ,MAAM,GAAG;AACjB,cAAQ,KAAK;AAAA,IACf;AAAA,EAAA;AAGK,SAAA;AAAA,IACL,MAAM;AAAA,IACN,gBAAgB,YAAY;AACb,mBAAA,MAAM,UAAU,cAAc,IAAI;AAC/C,YAAM,SAAS;AAAA,IACjB;AAAA,IACA,iBAAiB,OAAO,EAAE,WAAW;AAC7B,YAAA,WAAW,UAAU,IAAI;AAC/B,UAAI,aAAa,KAAK,MAAM,gBAAgB,GAAG;AAChC,qBAAA,MAAM,UAAU,cAAc,IAAI;AAC/C;AAAA,MACF;AACM,YAAA,sBAAsB,WAAW,WAAW,eAAe,IAC7D,WAAW,kBACX,KAAK,MAAM,WAAW,eAAe;AACrC,UAAA,SAAS,WAAW,mBAAmB,GAAG;AAC5C,cAAM,SAAS;AAAA,MACjB;AAAA,IACF;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { isAbsolute, join, normalize } from 'path'\nimport { fileURLToPath, pathToFileURL } from 'url'\nimport { z } from 'zod'\nimport {\n generator,\n configSchema as generatorConfigSchema,\n getConfig as getGeneratorConfig,\n} from '@tanstack/router-generator'\nimport { compileFile, makeCompile, splitFile } from './compilers'\nimport { splitPrefix } from './constants'\nimport type { Plugin } from 'vite'\n\nexport const configSchema = generatorConfigSchema.extend({\n enableRouteGeneration: z.boolean().optional(),\n experimental: z\n .object({\n enableCodeSplitting: z.boolean().optional(),\n })\n .optional(),\n})\n\nexport type Config = z.infer<typeof configSchema>\n\nconst CONFIG_FILE_NAME = 'tsr.config.json'\nconst debug = true as any\n\nconst getConfig = async (inlineConfig: Partial<Config>, root: string) => {\n const config = await getGeneratorConfig(inlineConfig, root)\n\n return configSchema.parse({ ...inlineConfig, ...config })\n}\n\nexport function TanStackRouterVite(\n inlineConfig: Partial<Config> = {},\n): Array<Plugin> {\n return [\n TanStackRouterViteGenerator(inlineConfig),\n TanStackRouterViteCodeSplitter(inlineConfig),\n ]\n}\n\nexport function TanStackRouterViteGenerator(\n inlineConfig: Partial<Config> = {},\n): Plugin {\n let ROOT: string = process.cwd()\n let userConfig: Config\n\n const generate = async () => {\n try {\n await generator(userConfig)\n } catch (err) {\n console.error(err)\n console.info()\n }\n }\n\n const handleFile = async (file: string) => {\n const filePath = normalize(file)\n if (filePath === join(ROOT, CONFIG_FILE_NAME)) {\n userConfig = await getConfig(inlineConfig, ROOT)\n return\n }\n const routesDirectoryPath = isAbsolute(userConfig.routesDirectory)\n ? userConfig.routesDirectory\n : join(ROOT, userConfig.routesDirectory)\n if (filePath.startsWith(routesDirectoryPath)) {\n await generate()\n }\n }\n\n return {\n name: 'vite-plugin-tanstack-router-generator',\n configResolved: async (config) => {\n ROOT = config.root\n userConfig = await getConfig(inlineConfig, ROOT)\n\n if (userConfig.enableRouteGeneration ?? true) {\n await generate()\n }\n },\n watchChange: async (file, context) => {\n if (userConfig.enableRouteGeneration ?? true) {\n if (['create', 'update', 'delete'].includes(context.event)) {\n await handleFile(file)\n }\n }\n },\n }\n}\n\nfunction fileIsInRoutesDirectory(filePath: string, routesDirectory: string) {\n const routesDirectoryPath = isAbsolute(routesDirectory)\n ? routesDirectory\n : join(process.cwd(), routesDirectory)\n\n return filePath.startsWith(routesDirectoryPath)\n}\n\nexport function TanStackRouterViteCodeSplitter(\n inlineConfig: Partial<Config> = {},\n): Plugin {\n let ROOT: string = process.cwd()\n let userConfig: Config\n\n return {\n name: 'vite-plugin-tanstack-router-code-splitter',\n enforce: 'pre',\n configResolved: async (config) => {\n ROOT = config.root\n userConfig = await getConfig(inlineConfig, ROOT)\n },\n resolveId(source) {\n if (!userConfig.experimental?.enableCodeSplitting) {\n return null\n }\n\n if (source.startsWith(splitPrefix + ':')) {\n return source.replace(splitPrefix + ':', '')\n }\n return null\n },\n async transform(code, id, transformOptions) {\n if (!userConfig.experimental?.enableCodeSplitting) {\n return null\n }\n\n const url = pathToFileURL(id)\n url.searchParams.delete('v')\n id = fileURLToPath(url).replace(/\\\\/g, '/')\n\n const compile = makeCompile({\n root: ROOT,\n })\n\n if (id.includes(splitPrefix)) {\n if (debug) console.info('Splitting route: ', id)\n // const ref = new URLSearchParams(id.split('?')[1]).get('ref') || ''\n\n const compiled = await splitFile({\n code,\n compile,\n filename: id,\n // ref,\n })\n\n if (debug) console.info('')\n if (debug) console.info('Split Output')\n if (debug) console.info('')\n if (debug) console.info(compiled.code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n return compiled\n } else if (\n fileIsInRoutesDirectory(id, userConfig.routesDirectory) &&\n (code.includes('createRoute(') || code.includes('createFileRoute('))\n ) {\n if (code.includes('@react-refresh')) {\n throw new Error(\n `We detected that the '@vitejs/plugin-react' was passed before '@tanstack/router-vite-plugin'. Please make sure that '@tanstack/router-vite-plugin' is passed before '@vitejs/plugin-react' and try again: \ne.g.\n\nplugins: [\n TanStackRouterVite(), // Place this before viteReact()\n viteReact(),\n]\n`,\n )\n }\n\n if (debug) console.info('Handling createRoute: ', id)\n const compiled = await compileFile({\n code,\n compile,\n filename: id,\n })\n\n if (debug) console.info('')\n if (debug) console.info('Compiled Output')\n if (debug) console.info('')\n if (debug) console.info(compiled.code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n return compiled\n }\n\n return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
2
+ export declare const importedComponent: () => React.JSX.Element;
3
+ export declare const importedLoader: () => {
4
+ randomNumber: number;
5
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/router-vite-plugin",
3
- "version": "1.23.0",
3
+ "version": "1.25.0",
4
4
  "description": "",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -49,10 +49,27 @@
49
49
  "src/**"
50
50
  ],
51
51
  "dependencies": {
52
+ "@babel/core": "^7.23.7",
53
+ "@babel/generator": "^7.23.6",
54
+ "@babel/plugin-syntax-jsx": "^7.24.1",
55
+ "@babel/plugin-syntax-typescript": "^7.24.1",
56
+ "@babel/plugin-transform-react-jsx": "^7.23.4",
57
+ "@babel/plugin-transform-typescript": "^7.24.1",
58
+ "@babel/template": "^7.24.0",
59
+ "@babel/traverse": "^7.24.1",
60
+ "@babel/types": "^7.24.0",
61
+ "@types/babel__core": "^7.20.5",
62
+ "@types/babel__generator": "^7.6.8",
63
+ "@types/babel__template": "^7.4.4",
64
+ "@types/babel__traverse": "^7.20.5",
65
+ "@vitejs/plugin-react": "^4.2.1",
66
+ "zod": "^3.22.4",
52
67
  "@tanstack/router-generator": "1.23.0"
53
68
  },
54
69
  "scripts": {
55
70
  "clean": "rimraf ./dist && rimraf ./coverage",
71
+ "test": "pnpm test:eslint && pnpm test:types && pnpm test:build && pnpm test:unit",
72
+ "test:unit": "vitest",
56
73
  "test:eslint": "eslint --ext .ts,.tsx ./src",
57
74
  "test:types": "tsc --noEmit",
58
75
  "test:build": "publint --strict",