@tanstack/router-plugin 1.95.6 → 1.97.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.
- package/dist/cjs/core/code-splitter/compilers.cjs +15 -29
- package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -1
- package/dist/cjs/core/router-code-splitter-plugin.cjs +13 -65
- package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
- package/dist/cjs/logger.cjs +55 -0
- package/dist/cjs/logger.cjs.map +1 -0
- package/dist/cjs/logger.d.cts +1 -0
- package/dist/esm/core/code-splitter/compilers.js +15 -29
- package/dist/esm/core/code-splitter/compilers.js.map +1 -1
- package/dist/esm/core/router-code-splitter-plugin.js +13 -65
- package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
- package/dist/esm/logger.d.ts +1 -0
- package/dist/esm/logger.js +55 -0
- package/dist/esm/logger.js.map +1 -0
- package/package.json +12 -9
- package/src/core/code-splitter/compilers.ts +16 -30
- package/src/core/router-code-splitter-plugin.ts +17 -76
- package/src/logger.ts +59 -0
|
@@ -25,18 +25,26 @@ function _interopNamespaceDefault(e) {
|
|
|
25
25
|
}
|
|
26
26
|
const t__namespace = /* @__PURE__ */ _interopNamespaceDefault(t);
|
|
27
27
|
const template__namespace = /* @__PURE__ */ _interopNamespaceDefault(template);
|
|
28
|
-
|
|
28
|
+
process.env.TSR_VITE_DEBUG;
|
|
29
29
|
let generate = _generate["default"];
|
|
30
30
|
if (!generate) {
|
|
31
31
|
generate = _generate;
|
|
32
32
|
}
|
|
33
|
+
function addSplitSearchParamToFilename(filename) {
|
|
34
|
+
const [bareFilename] = filename.split("?");
|
|
35
|
+
return `${bareFilename}?${constants.splitPrefix}`;
|
|
36
|
+
}
|
|
37
|
+
function removeSplitSearchParamFromFilename(filename) {
|
|
38
|
+
const [bareFilename] = filename.split("?");
|
|
39
|
+
return bareFilename;
|
|
40
|
+
}
|
|
33
41
|
function compileCodeSplitReferenceRoute(opts) {
|
|
34
42
|
const ast$1 = ast.parseAst(opts);
|
|
35
43
|
babel.traverse(ast$1, {
|
|
36
44
|
Program: {
|
|
37
45
|
enter(programPath, programState) {
|
|
38
46
|
const state = programState;
|
|
39
|
-
const splitUrl =
|
|
47
|
+
const splitUrl = addSplitSearchParamToFilename(opts.filename);
|
|
40
48
|
let existingCompImportPath = null;
|
|
41
49
|
let existingLoaderImportPath = null;
|
|
42
50
|
programPath.traverse(
|
|
@@ -169,22 +177,11 @@ function compileCodeSplitReferenceRoute(opts) {
|
|
|
169
177
|
}
|
|
170
178
|
}
|
|
171
179
|
});
|
|
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("");
|
|
178
180
|
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("");
|
|
185
181
|
return generate(ast$1, {
|
|
186
182
|
sourceMaps: true,
|
|
187
|
-
sourceFileName: opts.filename
|
|
183
|
+
sourceFileName: opts.filename,
|
|
184
|
+
minified: process.env.NODE_ENV === "production"
|
|
188
185
|
});
|
|
189
186
|
}
|
|
190
187
|
const splitNodeTypes = ["component", "loader"];
|
|
@@ -354,7 +351,7 @@ function compileCodeSplitVirtualRoute(opts) {
|
|
|
354
351
|
)
|
|
355
352
|
),
|
|
356
353
|
t__namespace.stringLiteral(
|
|
357
|
-
opts.filename
|
|
354
|
+
removeSplitSearchParamFromFilename(opts.filename)
|
|
358
355
|
)
|
|
359
356
|
)
|
|
360
357
|
);
|
|
@@ -365,19 +362,7 @@ function compileCodeSplitVirtualRoute(opts) {
|
|
|
365
362
|
}
|
|
366
363
|
}
|
|
367
364
|
});
|
|
368
|
-
if (debug) console.info("");
|
|
369
|
-
if (debug) console.info("Dead Code Elimination Input 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("");
|
|
374
365
|
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("");
|
|
381
366
|
if (knownExportedIdents.size > 0) {
|
|
382
367
|
const list = Array.from(knownExportedIdents).reduce((str, ident) => {
|
|
383
368
|
str += `
|
|
@@ -396,7 +381,8 @@ These should either have their export statements removed or be imported from ano
|
|
|
396
381
|
}
|
|
397
382
|
return generate(ast$1, {
|
|
398
383
|
sourceMaps: true,
|
|
399
|
-
sourceFileName: opts.filename
|
|
384
|
+
sourceFileName: opts.filename,
|
|
385
|
+
minified: process.env.NODE_ENV === "production"
|
|
400
386
|
});
|
|
401
387
|
}
|
|
402
388
|
function getImportSpecifierAndPathFromLocalName(programPath, name) {
|
|
@@ -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\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 sourceFileName: opts.filename,\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 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 sourceFileName: opts.filename,\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,UAAk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,MAA6B;AAC/D,MAAI,UAAU;AAEd,QAAM,SAASA,MAAK;AAAA,IAClB,uBAAuB,MAAM;AACvB,UAAA,KAAK,KAAK,aAAa;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\nfunction addSplitSearchParamToFilename(filename: string) {\n const [bareFilename] = filename.split('?')\n return `${bareFilename}?${splitPrefix}`\n}\n\nfunction removeSplitSearchParamFromFilename(filename: string) {\n const [bareFilename] = filename.split('?')\n return bareFilename!\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 // We need to extract the existing search params from the filename, if any\n // and add the splitPrefix to them, then write them back to the filename\n const splitUrl = addSplitSearchParamToFilename(opts.filename)\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 sourceFileName: opts.filename,\n minified: process.env.NODE_ENV === 'production',\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 removeSplitSearchParamFromFilename(opts.filename),\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 sourceFileName: opts.filename,\n minified: process.env.NODE_ENV === 'production',\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":["splitPrefix","ast","parseAst","t","template","deadCodeElimination"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAUc,QAAQ,IAAI;AAI1B,IAAI,WAAY,UAAkB,SAAS;AAG3C,IAAI,CAAC,UAAU;AACF,aAAA;AACb;AAoBA,SAAS,8BAA8B,UAAkB;AACvD,QAAM,CAAC,YAAY,IAAI,SAAS,MAAM,GAAG;AAClC,SAAA,GAAG,YAAY,IAAIA,UAAW,WAAA;AACvC;AAEA,SAAS,mCAAmC,UAAkB;AAC5D,QAAM,CAAC,YAAY,IAAI,SAAS,MAAM,GAAG;AAClC,SAAA;AACT;AAEO,SAAS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ACzC,YAAI,KAAK,KAAK,YAAY,SAAS,KAAK,MAAM;AACpC,kBAAA;AAAA,QAAA;AAAA,MACV;AAAA,IACF;AAAA,EACF,CACD;AAEM,SAAA;AACT;AAEA,SAAS,cAAcF,MAAa,MAA6B;AAC/D,MAAI,UAAU;AAEd,QAAM,SAASA,MAAK;AAAA,IAClB,uBAAuB,MAAM;AACvB,UAAA,KAAK,KAAK,aAAa;AAEzB,YAAIE,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;;;"}
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const node_path = require("node:path");
|
|
4
4
|
const node_url = require("node:url");
|
|
5
|
+
const logger = require("../logger.cjs");
|
|
5
6
|
const config = require("./config.cjs");
|
|
6
7
|
const compilers = require("./code-splitter/compilers.cjs");
|
|
7
8
|
const constants = require("./constants.cjs");
|
|
9
|
+
const debug = process.env.TSR_VITE_DEBUG && ["true", "router-plugin"].includes(process.env.TSR_VITE_DEBUG);
|
|
8
10
|
function capitalizeFirst(str) {
|
|
9
11
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
10
12
|
}
|
|
@@ -33,62 +35,38 @@ plugins: [
|
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
const PLUGIN_NAME = "unplugin:router-code-splitter";
|
|
36
|
-
const JoinedSplitPrefix = constants.splitPrefix + ":";
|
|
37
38
|
const unpluginRouterCodeSplitterFactory = (options = {}, { framework }) => {
|
|
38
|
-
const debug = Boolean(process.env.TSR_VITE_DEBUG);
|
|
39
39
|
let ROOT = process.cwd();
|
|
40
40
|
let userConfig = options;
|
|
41
41
|
const handleSplittingFile = (code, id) => {
|
|
42
|
-
if (debug) console.info("Splitting
|
|
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("");
|
|
42
|
+
if (debug) console.info("Splitting Route: ", id);
|
|
50
43
|
const compiledVirtualRoute = compilers.compileCodeSplitVirtualRoute({
|
|
51
44
|
code,
|
|
52
45
|
root: ROOT,
|
|
53
46
|
filename: id
|
|
54
47
|
});
|
|
55
|
-
if (debug)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (debug) console.info("");
|
|
60
|
-
if (debug) console.info("");
|
|
61
|
-
if (debug) console.info("");
|
|
48
|
+
if (debug) {
|
|
49
|
+
logger.logDiff(code, compiledVirtualRoute.code);
|
|
50
|
+
console.log("Output:\n", compiledVirtualRoute.code);
|
|
51
|
+
}
|
|
62
52
|
return compiledVirtualRoute;
|
|
63
53
|
};
|
|
64
54
|
const handleCompilingFile = (code, id) => {
|
|
65
|
-
if (debug) console.info("
|
|
55
|
+
if (debug) console.info("Compiling Route: ", id);
|
|
66
56
|
const compiledReferenceRoute = compilers.compileCodeSplitReferenceRoute({
|
|
67
57
|
code,
|
|
68
58
|
root: ROOT,
|
|
69
59
|
filename: id
|
|
70
60
|
});
|
|
71
|
-
if (debug)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (debug) console.info("");
|
|
76
|
-
if (debug) console.info("");
|
|
77
|
-
if (debug) console.info("");
|
|
61
|
+
if (debug) {
|
|
62
|
+
logger.logDiff(code, compiledReferenceRoute.code);
|
|
63
|
+
console.log("Output:\n", compiledReferenceRoute.code + "\n\n");
|
|
64
|
+
}
|
|
78
65
|
return compiledReferenceRoute;
|
|
79
66
|
};
|
|
80
67
|
return {
|
|
81
68
|
name: "router-code-splitter-plugin",
|
|
82
69
|
enforce: "pre",
|
|
83
|
-
resolveId(source) {
|
|
84
|
-
if (!userConfig.autoCodeSplitting) {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
if (source.startsWith(constants.splitPrefix + ":")) {
|
|
88
|
-
return source.replace(constants.splitPrefix + ":", "");
|
|
89
|
-
}
|
|
90
|
-
return null;
|
|
91
|
-
},
|
|
92
70
|
transform(code, id) {
|
|
93
71
|
if (!userConfig.autoCodeSplitting) {
|
|
94
72
|
return null;
|
|
@@ -111,14 +89,10 @@ const unpluginRouterCodeSplitterFactory = (options = {}, { framework }) => {
|
|
|
111
89
|
}
|
|
112
90
|
return null;
|
|
113
91
|
},
|
|
114
|
-
transformInclude(
|
|
92
|
+
transformInclude(id) {
|
|
115
93
|
if (!userConfig.autoCodeSplitting) {
|
|
116
94
|
return void 0;
|
|
117
95
|
}
|
|
118
|
-
let id = transformId;
|
|
119
|
-
if (id.startsWith(JoinedSplitPrefix)) {
|
|
120
|
-
id = id.replace(JoinedSplitPrefix, "");
|
|
121
|
-
}
|
|
122
96
|
if (fileIsInRoutesDirectory(id, userConfig.routesDirectory) || id.includes(constants.splitPrefix)) {
|
|
123
97
|
return true;
|
|
124
98
|
}
|
|
@@ -132,36 +106,10 @@ const unpluginRouterCodeSplitterFactory = (options = {}, { framework }) => {
|
|
|
132
106
|
},
|
|
133
107
|
rspack(compiler) {
|
|
134
108
|
ROOT = process.cwd();
|
|
135
|
-
compiler.hooks.beforeCompile.tap(PLUGIN_NAME, (self) => {
|
|
136
|
-
self.normalModuleFactory.hooks.beforeResolve.tap(
|
|
137
|
-
PLUGIN_NAME,
|
|
138
|
-
(resolveData) => {
|
|
139
|
-
if (resolveData.request.includes(JoinedSplitPrefix)) {
|
|
140
|
-
resolveData.request = resolveData.request.replace(
|
|
141
|
-
JoinedSplitPrefix,
|
|
142
|
-
""
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
);
|
|
147
|
-
});
|
|
148
109
|
userConfig = config.getConfig(options, ROOT);
|
|
149
110
|
},
|
|
150
111
|
webpack(compiler) {
|
|
151
112
|
ROOT = process.cwd();
|
|
152
|
-
compiler.hooks.beforeCompile.tap(PLUGIN_NAME, (self) => {
|
|
153
|
-
self.normalModuleFactory.hooks.beforeResolve.tap(
|
|
154
|
-
PLUGIN_NAME,
|
|
155
|
-
(resolveData) => {
|
|
156
|
-
if (resolveData.request.includes(JoinedSplitPrefix)) {
|
|
157
|
-
resolveData.request = resolveData.request.replace(
|
|
158
|
-
JoinedSplitPrefix,
|
|
159
|
-
""
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
);
|
|
164
|
-
});
|
|
165
113
|
userConfig = config.getConfig(options, ROOT);
|
|
166
114
|
if (userConfig.autoCodeSplitting && compiler.options.mode === "production") {
|
|
167
115
|
compiler.hooks.done.tap(PLUGIN_NAME, () => {
|
|
@@ -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 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;AACH,QAAA,sBAAsBA,qB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C;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;;"}
|
|
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'\n\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { logDiff } from '../logger'\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\nconst debug =\n process.env.TSR_VITE_DEBUG &&\n ['true', 'router-plugin'].includes(process.env.TSR_VITE_DEBUG)\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'\n\nexport const unpluginRouterCodeSplitterFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}, { framework }) => {\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) {\n logDiff(code, compiledVirtualRoute.code)\n console.log('Output:\\n', compiledVirtualRoute.code)\n }\n\n return compiledVirtualRoute\n }\n\n const handleCompilingFile = (code: string, id: string) => {\n if (debug) console.info('Compiling Route: ', id)\n\n const compiledReferenceRoute = compileCodeSplitReferenceRoute({\n code,\n root: ROOT,\n filename: id,\n })\n\n if (debug) {\n logDiff(code, compiledReferenceRoute.code)\n console.log('Output:\\n', compiledReferenceRoute.code + '\\n\\n')\n }\n\n return compiledReferenceRoute\n }\n\n return {\n name: 'router-code-splitter-plugin',\n enforce: 'pre',\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(id) {\n if (!userConfig.autoCodeSplitting) {\n return undefined\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 userConfig = getConfig(options, ROOT)\n },\n\n webpack(compiler) {\n ROOT = process.cwd()\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","compileCodeSplitVirtualRoute","logDiff","compileCodeSplitReferenceRoute","pathToFileURL","fileURLToPath","splitPrefix","config","getConfig"],"mappings":";;;;;;;;AAcA,MAAM,QACJ,QAAQ,IAAI,kBACZ,CAAC,QAAQ,eAAe,EAAE,SAAS,QAAQ,IAAI,cAAc;AAE/D,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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I;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;;"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const chalk = require("chalk");
|
|
4
|
+
const diff = require("diff");
|
|
5
|
+
function logDiff(oldStr, newStr) {
|
|
6
|
+
const differences = diff.diffWords(oldStr, newStr);
|
|
7
|
+
let output = "";
|
|
8
|
+
let unchangedLines = "";
|
|
9
|
+
function processUnchangedLines(lines) {
|
|
10
|
+
const lineArray = lines.split("\n");
|
|
11
|
+
if (lineArray.length > 4) {
|
|
12
|
+
return [
|
|
13
|
+
chalk.dim(lineArray[0]),
|
|
14
|
+
chalk.dim(lineArray[1]),
|
|
15
|
+
"",
|
|
16
|
+
chalk.dim.bold(`... (${lineArray.length - 4} lines) ...`),
|
|
17
|
+
"",
|
|
18
|
+
chalk.dim(lineArray[lineArray.length - 2]),
|
|
19
|
+
chalk.dim(lineArray[lineArray.length - 1])
|
|
20
|
+
].join("\n");
|
|
21
|
+
}
|
|
22
|
+
return chalk.dim(lines);
|
|
23
|
+
}
|
|
24
|
+
differences.forEach((part, index) => {
|
|
25
|
+
const nextPart = differences[index + 1];
|
|
26
|
+
if (part.added) {
|
|
27
|
+
if (unchangedLines) {
|
|
28
|
+
output += processUnchangedLines(unchangedLines);
|
|
29
|
+
unchangedLines = "";
|
|
30
|
+
}
|
|
31
|
+
output += chalk.green.bold(part.value);
|
|
32
|
+
if (nextPart == null ? void 0 : nextPart.removed) output += " ";
|
|
33
|
+
} else if (part.removed) {
|
|
34
|
+
if (unchangedLines) {
|
|
35
|
+
output += processUnchangedLines(unchangedLines);
|
|
36
|
+
unchangedLines = "";
|
|
37
|
+
}
|
|
38
|
+
output += chalk.red.bold(part.value);
|
|
39
|
+
if (nextPart == null ? void 0 : nextPart.added) output += " ";
|
|
40
|
+
} else {
|
|
41
|
+
unchangedLines += part.value;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
if (unchangedLines) {
|
|
45
|
+
output += processUnchangedLines(unchangedLines);
|
|
46
|
+
}
|
|
47
|
+
if (output) {
|
|
48
|
+
console.log("\nDiff:");
|
|
49
|
+
console.log(output + "\n");
|
|
50
|
+
} else {
|
|
51
|
+
console.log("No changes");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.logDiff = logDiff;
|
|
55
|
+
//# sourceMappingURL=logger.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.cjs","sources":["../../src/logger.ts"],"sourcesContent":["import chalk from 'chalk'\nimport { diffWords } from 'diff'\n\nexport function logDiff(oldStr: string, newStr: string) {\n const differences = diffWords(oldStr, newStr)\n\n let output = ''\n let unchangedLines = ''\n\n function processUnchangedLines(lines: string): string {\n const lineArray = lines.split('\\n')\n if (lineArray.length > 4) {\n return [\n chalk.dim(lineArray[0]),\n chalk.dim(lineArray[1]),\n '',\n chalk.dim.bold(`... (${lineArray.length - 4} lines) ...`),\n '',\n chalk.dim(lineArray[lineArray.length - 2]),\n chalk.dim(lineArray[lineArray.length - 1]),\n ].join('\\n')\n }\n return chalk.dim(lines)\n }\n\n differences.forEach((part, index) => {\n const nextPart = differences[index + 1]\n\n if (part.added) {\n if (unchangedLines) {\n output += processUnchangedLines(unchangedLines)\n unchangedLines = ''\n }\n output += chalk.green.bold(part.value)\n if (nextPart?.removed) output += ' '\n } else if (part.removed) {\n if (unchangedLines) {\n output += processUnchangedLines(unchangedLines)\n unchangedLines = ''\n }\n output += chalk.red.bold(part.value)\n if (nextPart?.added) output += ' '\n } else {\n unchangedLines += part.value\n }\n })\n\n // Process any remaining unchanged lines at the end\n if (unchangedLines) {\n output += processUnchangedLines(unchangedLines)\n }\n\n if (output) {\n console.log('\\nDiff:')\n console.log(output + '\\n')\n } else {\n console.log('No changes')\n }\n}\n"],"names":["diffWords"],"mappings":";;;;AAGgB,SAAA,QAAQ,QAAgB,QAAgB;AAChD,QAAA,cAAcA,KAAAA,UAAU,QAAQ,MAAM;AAE5C,MAAI,SAAS;AACb,MAAI,iBAAiB;AAErB,WAAS,sBAAsB,OAAuB;AAC9C,UAAA,YAAY,MAAM,MAAM,IAAI;AAC9B,QAAA,UAAU,SAAS,GAAG;AACjB,aAAA;AAAA,QACL,MAAM,IAAI,UAAU,CAAC,CAAC;AAAA,QACtB,MAAM,IAAI,UAAU,CAAC,CAAC;AAAA,QACtB;AAAA,QACA,MAAM,IAAI,KAAK,QAAQ,UAAU,SAAS,CAAC,aAAa;AAAA,QACxD;AAAA,QACA,MAAM,IAAI,UAAU,UAAU,SAAS,CAAC,CAAC;AAAA,QACzC,MAAM,IAAI,UAAU,UAAU,SAAS,CAAC,CAAC;AAAA,MAAA,EACzC,KAAK,IAAI;AAAA,IAAA;AAEN,WAAA,MAAM,IAAI,KAAK;AAAA,EAAA;AAGZ,cAAA,QAAQ,CAAC,MAAM,UAAU;AAC7B,UAAA,WAAW,YAAY,QAAQ,CAAC;AAEtC,QAAI,KAAK,OAAO;AACd,UAAI,gBAAgB;AAClB,kBAAU,sBAAsB,cAAc;AAC7B,yBAAA;AAAA,MAAA;AAEnB,gBAAU,MAAM,MAAM,KAAK,KAAK,KAAK;AACjC,UAAA,qCAAU,QAAmB,WAAA;AAAA,IAAA,WACxB,KAAK,SAAS;AACvB,UAAI,gBAAgB;AAClB,kBAAU,sBAAsB,cAAc;AAC7B,yBAAA;AAAA,MAAA;AAEnB,gBAAU,MAAM,IAAI,KAAK,KAAK,KAAK;AAC/B,UAAA,qCAAU,MAAiB,WAAA;AAAA,IAAA,OAC1B;AACL,wBAAkB,KAAK;AAAA,IAAA;AAAA,EACzB,CACD;AAGD,MAAI,gBAAgB;AAClB,cAAU,sBAAsB,cAAc;AAAA,EAAA;AAGhD,MAAI,QAAQ;AACV,YAAQ,IAAI,SAAS;AACb,YAAA,IAAI,SAAS,IAAI;AAAA,EAAA,OACpB;AACL,YAAQ,IAAI,YAAY;AAAA,EAAA;AAE5B;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function logDiff(oldStr: string, newStr: string): void;
|
|
@@ -5,18 +5,26 @@ 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
|
-
|
|
8
|
+
process.env.TSR_VITE_DEBUG;
|
|
9
9
|
let generate = _generate["default"];
|
|
10
10
|
if (!generate) {
|
|
11
11
|
generate = _generate;
|
|
12
12
|
}
|
|
13
|
+
function addSplitSearchParamToFilename(filename) {
|
|
14
|
+
const [bareFilename] = filename.split("?");
|
|
15
|
+
return `${bareFilename}?${splitPrefix}`;
|
|
16
|
+
}
|
|
17
|
+
function removeSplitSearchParamFromFilename(filename) {
|
|
18
|
+
const [bareFilename] = filename.split("?");
|
|
19
|
+
return bareFilename;
|
|
20
|
+
}
|
|
13
21
|
function compileCodeSplitReferenceRoute(opts) {
|
|
14
22
|
const ast = parseAst(opts);
|
|
15
23
|
babel.traverse(ast, {
|
|
16
24
|
Program: {
|
|
17
25
|
enter(programPath, programState) {
|
|
18
26
|
const state = programState;
|
|
19
|
-
const splitUrl =
|
|
27
|
+
const splitUrl = addSplitSearchParamToFilename(opts.filename);
|
|
20
28
|
let existingCompImportPath = null;
|
|
21
29
|
let existingLoaderImportPath = null;
|
|
22
30
|
programPath.traverse(
|
|
@@ -149,22 +157,11 @@ function compileCodeSplitReferenceRoute(opts) {
|
|
|
149
157
|
}
|
|
150
158
|
}
|
|
151
159
|
});
|
|
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("");
|
|
158
160
|
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("");
|
|
165
161
|
return generate(ast, {
|
|
166
162
|
sourceMaps: true,
|
|
167
|
-
sourceFileName: opts.filename
|
|
163
|
+
sourceFileName: opts.filename,
|
|
164
|
+
minified: process.env.NODE_ENV === "production"
|
|
168
165
|
});
|
|
169
166
|
}
|
|
170
167
|
const splitNodeTypes = ["component", "loader"];
|
|
@@ -334,7 +331,7 @@ function compileCodeSplitVirtualRoute(opts) {
|
|
|
334
331
|
)
|
|
335
332
|
),
|
|
336
333
|
t.stringLiteral(
|
|
337
|
-
opts.filename
|
|
334
|
+
removeSplitSearchParamFromFilename(opts.filename)
|
|
338
335
|
)
|
|
339
336
|
)
|
|
340
337
|
);
|
|
@@ -345,19 +342,7 @@ function compileCodeSplitVirtualRoute(opts) {
|
|
|
345
342
|
}
|
|
346
343
|
}
|
|
347
344
|
});
|
|
348
|
-
if (debug) console.info("");
|
|
349
|
-
if (debug) console.info("Dead Code Elimination Input 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("");
|
|
354
345
|
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("");
|
|
361
346
|
if (knownExportedIdents.size > 0) {
|
|
362
347
|
const list = Array.from(knownExportedIdents).reduce((str, ident) => {
|
|
363
348
|
str += `
|
|
@@ -376,7 +361,8 @@ These should either have their export statements removed or be imported from ano
|
|
|
376
361
|
}
|
|
377
362
|
return generate(ast, {
|
|
378
363
|
sourceMaps: true,
|
|
379
|
-
sourceFileName: opts.filename
|
|
364
|
+
sourceFileName: opts.filename,
|
|
365
|
+
minified: process.env.NODE_ENV === "production"
|
|
380
366
|
});
|
|
381
367
|
}
|
|
382
368
|
function getImportSpecifierAndPathFromLocalName(programPath, name) {
|