@tanstack/router-plugin 1.39.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/cjs/ast.cjs +51 -0
- package/dist/cjs/ast.cjs.map +1 -0
- package/dist/cjs/ast.d.cts +22 -0
- package/dist/cjs/code-splitter.cjs +157 -0
- package/dist/cjs/code-splitter.cjs.map +1 -0
- package/dist/cjs/code-splitter.d.cts +22 -0
- package/dist/cjs/compilers.cjs +327 -0
- package/dist/cjs/compilers.cjs.map +1 -0
- package/dist/cjs/compilers.d.cts +18 -0
- package/dist/cjs/config.cjs +16 -0
- package/dist/cjs/config.cjs.map +1 -0
- package/dist/cjs/config.d.cts +79 -0
- package/dist/cjs/constants.cjs +7 -0
- package/dist/cjs/constants.cjs.map +1 -0
- package/dist/cjs/constants.d.cts +2 -0
- package/dist/cjs/eliminateUnreferencedIdentifiers.cjs +149 -0
- package/dist/cjs/eliminateUnreferencedIdentifiers.cjs.map +1 -0
- package/dist/cjs/eliminateUnreferencedIdentifiers.d.cts +9 -0
- package/dist/cjs/index.cjs +7 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +2 -0
- package/dist/cjs/router-generator.cjs +67 -0
- package/dist/cjs/router-generator.cjs.map +1 -0
- package/dist/cjs/router-generator.d.cts +18 -0
- package/dist/cjs/vite.cjs +16 -0
- package/dist/cjs/vite.cjs.map +1 -0
- package/dist/cjs/vite.d.cts +41 -0
- package/dist/esm/ast.d.ts +22 -0
- package/dist/esm/ast.js +34 -0
- package/dist/esm/ast.js.map +1 -0
- package/dist/esm/code-splitter.d.ts +22 -0
- package/dist/esm/code-splitter.js +157 -0
- package/dist/esm/code-splitter.js.map +1 -0
- package/dist/esm/compilers.d.ts +18 -0
- package/dist/esm/compilers.js +309 -0
- package/dist/esm/compilers.js.map +1 -0
- package/dist/esm/config.d.ts +79 -0
- package/dist/esm/config.js +16 -0
- package/dist/esm/config.js.map +1 -0
- package/dist/esm/constants.d.ts +2 -0
- package/dist/esm/constants.js +7 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/eliminateUnreferencedIdentifiers.d.ts +9 -0
- package/dist/esm/eliminateUnreferencedIdentifiers.js +132 -0
- package/dist/esm/eliminateUnreferencedIdentifiers.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/router-generator.d.ts +18 -0
- package/dist/esm/router-generator.js +67 -0
- package/dist/esm/router-generator.js.map +1 -0
- package/dist/esm/vite.d.ts +41 -0
- package/dist/esm/vite.js +16 -0
- package/dist/esm/vite.js.map +1 -0
- package/package.json +88 -0
- package/src/ast.ts +49 -0
- package/src/code-splitter.ts +162 -0
- package/src/compilers.ts +414 -0
- package/src/config.ts +25 -0
- package/src/constants.ts +2 -0
- package/src/eliminateUnreferencedIdentifiers.ts +211 -0
- package/src/index.ts +2 -0
- package/src/router-generator.ts +92 -0
- package/src/vite.ts +19 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compilers.cjs","sources":["../../src/compilers.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport * as template from '@babel/template'\nimport { splitPrefix } from './constants'\nimport { eliminateUnreferencedIdentifiers } from './eliminateUnreferencedIdentifiers'\nimport type * as babel from '@babel/core'\nimport type { CompileAstFn } from './ast'\n\ntype SplitModulesById = Record<\n string,\n { id: string; node: t.FunctionExpression }\n>\n\ninterface State {\n filename: string\n opts: {\n minify: boolean\n root: string\n }\n imported: Record<string, boolean>\n refs: Set<any>\n serverIndex: number\n splitIndex: number\n splitModulesById: SplitModulesById\n}\n\nexport async function compileFile(opts: {\n code: string\n compileAst: CompileAstFn\n filename: string\n}) {\n return await opts.compileAst({\n code: opts.code,\n filename: opts.filename,\n getBabelConfig: () => ({\n plugins: [\n [\n {\n visitor: {\n Program: {\n enter(programPath: babel.NodePath<t.Program>, state: State) {\n const splitUrl = `${splitPrefix}:${opts.filename}?${splitPrefix}`\n\n programPath.traverse(\n {\n CallExpression: (path) => {\n if (path.node.callee.type === 'Identifier') {\n if (\n path.node.callee.name === 'createRoute' ||\n path.node.callee.name === 'createFileRoute'\n ) {\n if (\n path.parentPath.node.type === 'CallExpression'\n ) {\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n let found = false\n\n const hasImportedOrDefinedIdentifier = (\n name: string,\n ) => {\n return programPath.scope.hasBinding(name)\n }\n\n if (t.isObjectExpression(options)) {\n options.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n if (t.isIdentifier(prop.key)) {\n if (prop.key.name === 'component') {\n const value = prop.value\n\n if (t.isIdentifier(value)) {\n removeIdentifierLiteral(path, value)\n }\n\n // Prepend the import statement to the program along with the importer function\n // Check to see if lazyRouteComponent is already imported before attempting\n // to import it again\n\n if (\n !hasImportedOrDefinedIdentifier(\n 'lazyRouteComponent',\n )\n ) {\n programPath.unshiftContainer('body', [\n template.smart(\n `import { lazyRouteComponent } from '@tanstack/react-router'`,\n )() as t.Statement,\n ])\n }\n\n if (\n !hasImportedOrDefinedIdentifier(\n '$$splitComponentImporter',\n )\n ) {\n programPath.unshiftContainer('body', [\n template.smart(\n `const $$splitComponentImporter = () => import('${splitUrl}')`,\n )() as t.Statement,\n ])\n }\n\n prop.value = template.expression(\n `lazyRouteComponent($$splitComponentImporter, 'component')`,\n )() as any\n\n programPath.pushContainer('body', [\n template.smart(\n `function DummyComponent() { return null }`,\n )() as t.Statement,\n ])\n\n found = true\n } else if (prop.key.name === 'loader') {\n const value = prop.value\n\n if (t.isIdentifier(value)) {\n removeIdentifierLiteral(path, value)\n }\n\n // Prepend the import statement to the program along with the importer function\n\n if (\n !hasImportedOrDefinedIdentifier(\n 'lazyFn',\n )\n ) {\n programPath.unshiftContainer('body', [\n template.smart(\n `import { lazyFn } from '@tanstack/react-router'`,\n )() as t.Statement,\n ])\n }\n\n if (\n !hasImportedOrDefinedIdentifier(\n '$$splitLoaderImporter',\n )\n ) {\n programPath.unshiftContainer('body', [\n template.smart(\n `const $$splitLoaderImporter = () => import('${splitUrl}')`,\n )() as t.Statement,\n ])\n }\n\n prop.value = template.expression(\n `lazyFn($$splitLoaderImporter, 'loader')`,\n )() as any\n\n found = true\n }\n }\n }\n\n programPath.scope.crawl()\n })\n }\n\n if (found as boolean) {\n programPath.pushContainer('body', [\n template.smart(\n `function TSR_Dummy_Component() {}`,\n )() as t.Statement,\n ])\n }\n }\n }\n }\n },\n },\n state,\n )\n\n eliminateUnreferencedIdentifiers(programPath)\n },\n },\n },\n },\n {\n root: process.cwd(),\n minify: process.env.NODE_ENV === 'production',\n },\n ],\n ].filter(Boolean),\n }),\n })\n}\n\n// Reusable function to get literal value or resolve variable to literal\nfunction resolveIdentifier(path: any, node: any) {\n if (t.isIdentifier(node)) {\n const binding = path.scope.getBinding(node.name)\n if (\n binding\n // && binding.kind === 'const'\n ) {\n const declarator = binding.path.node\n if (t.isObjectExpression(declarator.init)) {\n return declarator.init\n } else if (t.isFunctionDeclaration(declarator.init)) {\n return declarator.init\n }\n }\n return undefined\n }\n\n return node\n}\n\nfunction removeIdentifierLiteral(path: any, node: any) {\n if (t.isIdentifier(node)) {\n const binding = path.scope.getBinding(node.name)\n if (binding) {\n binding.path.remove()\n }\n }\n}\n\nconst splitNodeTypes = ['component', 'loader'] as const\ntype SplitNodeType = (typeof splitNodeTypes)[number]\n\nexport async function splitFile(opts: {\n code: string\n compileAst: CompileAstFn\n filename: string\n}) {\n return await opts.compileAst({\n code: opts.code,\n filename: opts.filename,\n getBabelConfig: () => ({\n plugins: [\n [\n {\n visitor: {\n Program: {\n enter(programPath: babel.NodePath<t.Program>, state: State) {\n const splitNodesByType: Record<\n SplitNodeType,\n t.Node | undefined\n > = {\n component: undefined,\n loader: undefined,\n }\n\n // Find the node\n programPath.traverse(\n {\n CallExpression: (path) => {\n if (path.node.callee.type === 'Identifier') {\n if (\n path.node.callee.name === 'createRoute' ||\n path.node.callee.name === 'createFileRoute'\n ) {\n if (\n path.parentPath.node.type === 'CallExpression'\n ) {\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n if (t.isObjectExpression(options)) {\n options.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n splitNodeTypes.forEach((type) => {\n if (t.isIdentifier(prop.key)) {\n if (prop.key.name === type) {\n splitNodesByType[type] = prop.value\n }\n }\n })\n }\n })\n\n // Remove all of the options\n options.properties = []\n }\n }\n }\n }\n },\n },\n state,\n )\n\n splitNodeTypes.forEach((splitType) => {\n let splitNode = splitNodesByType[splitType]\n\n if (!splitNode) {\n return\n }\n\n while (t.isIdentifier(splitNode)) {\n const binding = programPath.scope.getBinding(\n splitNode.name,\n )\n splitNode = binding?.path.node\n }\n\n // Add the node to the program\n if (splitNode) {\n if (t.isFunctionDeclaration(splitNode)) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitType),\n t.functionExpression(\n splitNode.id || null, // Anonymize the function expression\n splitNode.params,\n splitNode.body,\n splitNode.generator,\n splitNode.async,\n ),\n ),\n ]),\n )\n } else if (\n t.isFunctionExpression(splitNode) ||\n t.isArrowFunctionExpression(splitNode)\n ) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitType),\n splitNode as any,\n ),\n ]),\n )\n } else if (t.isImportSpecifier(splitNode)) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitType),\n splitNode.local,\n ),\n ]),\n )\n } else {\n console.info(splitNode)\n throw new Error(\n `Unexpected splitNode type ☝️: ${splitNode.type}`,\n )\n }\n }\n\n // If the splitNode exists at the top of the program\n // then we need to remove that copy\n programPath.node.body = programPath.node.body.filter(\n (node) => {\n return node !== splitNode\n },\n )\n\n // Export the node\n programPath.pushContainer('body', [\n t.exportNamedDeclaration(null, [\n t.exportSpecifier(\n t.identifier(splitType),\n t.identifier(splitType),\n ),\n ]),\n ])\n })\n\n // convert exports to imports from the original file\n programPath.traverse({\n ExportNamedDeclaration(path) {\n // e.g. export const x = 1 or export { x }\n // becomes\n // import { x } from '${opts.id}'\n\n if (path.node.declaration) {\n if (t.isVariableDeclaration(path.node.declaration)) {\n path.replaceWith(\n t.importDeclaration(\n path.node.declaration.declarations.map((decl) =>\n t.importSpecifier(\n t.identifier((decl.id as any).name),\n t.identifier((decl.id as any).name),\n ),\n ),\n t.stringLiteral(\n opts.filename.split(\n `?${splitPrefix}`,\n )[0] as string,\n ),\n ),\n )\n }\n }\n },\n })\n\n eliminateUnreferencedIdentifiers(programPath)\n },\n },\n },\n },\n {\n root: process.cwd(),\n minify: process.env.NODE_ENV === 'production',\n },\n ],\n ].filter(Boolean),\n }),\n })\n}\n"],"names":["splitPrefix","t","template","eliminateUnreferencedIdentifiers"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyBA,eAAsB,YAAY,MAI/B;AACM,SAAA,MAAM,KAAK,WAAW;AAAA,IAC3B,MAAM,KAAK;AAAA,IACX,UAAU,KAAK;AAAA,IACf,gBAAgB,OAAO;AAAA,MACrB,SAAS;AAAA,QACP;AAAA,UACE;AAAA,YACE,SAAS;AAAA,cACP,SAAS;AAAA,gBACP,MAAM,aAAwC,OAAc;AAC1D,wBAAM,WAAW,GAAGA,UAAAA,WAAW,IAAI,KAAK,QAAQ,IAAIA,UAAW,WAAA;AAEnD,8BAAA;AAAA,oBACV;AAAA,sBACE,gBAAgB,CAAC,SAAS;AACxB,4BAAI,KAAK,KAAK,OAAO,SAAS,cAAc;AAExC,8BAAA,KAAK,KAAK,OAAO,SAAS,iBAC1B,KAAK,KAAK,OAAO,SAAS,mBAC1B;AACA,gCACE,KAAK,WAAW,KAAK,SAAS,kBAC9B;AACA,oCAAM,UAAU;AAAA,gCACd;AAAA,gCACA,KAAK,WAAW,KAAK,UAAU,CAAC;AAAA,8BAAA;A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SAAS;AAAA,sBAClB;AAAA,oBAAA;AAIF,gCAAY,cAAc,QAAQ;AAAA,sBAChCA,aAAE,uBAAuB,MAAM;AAAA,wBAC7BA,aAAE;AAAA,0BACAA,aAAE,WAAW,SAAS;AAAA,0BACtBA,aAAE,WAAW,SAAS;AAAA,wBACxB;AAAA,sBAAA,CACD;AAAA,oBAAA,CACF;AAAA,kBAAA,CACF;AAGD,8BAAY,SAAS;AAAA,oBACnB,uBAAuB,MAAM;AAKvB,0BAAA,KAAK,KAAK,aAAa;AACzB,4BAAIA,aAAE,sBAAsB,KAAK,KAAK,WAAW,GAAG;AAC7C,+BAAA;AAAA,4BACHA,aAAE;AAAA,8BACA,KAAK,KAAK,YAAY,aAAa;AAAA,gCAAI,CAAC,SACtCA,aAAE;AAAA,kCACAA,aAAE,WAAY,KAAK,GAAW,IAAI;AAAA,kCAClCA,aAAE,WAAY,KAAK,GAAW,IAAI;AAAA,gCACpC;AAAA,8BACF;AAAA,8BACAA,aAAE;AAAA,gCACA,KAAK,SAAS;AAAA,kCACZ,IAAID,UAAAA,WAAW;AAAA,kCACf,CAAC;AAAA,8BACL;AAAA,4BACF;AAAA,0BAAA;AAAA,wBAEJ;AAAA,sBACF;AAAA,oBACF;AAAA,kBAAA,CACD;AAEDG,mDAAA,iCAAiC,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,18 @@
|
|
|
1
|
+
import { CompileAstFn } from './ast.cjs';
|
|
2
|
+
|
|
3
|
+
export declare function compileFile(opts: {
|
|
4
|
+
code: string;
|
|
5
|
+
compileAst: CompileAstFn;
|
|
6
|
+
filename: string;
|
|
7
|
+
}): Promise<{
|
|
8
|
+
code: string;
|
|
9
|
+
map: any;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function splitFile(opts: {
|
|
12
|
+
code: string;
|
|
13
|
+
compileAst: CompileAstFn;
|
|
14
|
+
filename: string;
|
|
15
|
+
}): Promise<{
|
|
16
|
+
code: string;
|
|
17
|
+
map: any;
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const zod = require("zod");
|
|
4
|
+
const routerGenerator = require("@tanstack/router-generator");
|
|
5
|
+
const configSchema = routerGenerator.configSchema.extend({
|
|
6
|
+
enableRouteGeneration: zod.z.boolean().optional(),
|
|
7
|
+
experimental: zod.z.object({
|
|
8
|
+
enableCodeSplitting: zod.z.boolean().optional()
|
|
9
|
+
}).optional()
|
|
10
|
+
});
|
|
11
|
+
const getConfig = async (inlineConfig, root) => {
|
|
12
|
+
const config = await routerGenerator.getConfig(inlineConfig, root);
|
|
13
|
+
return configSchema.parse({ ...config, ...inlineConfig });
|
|
14
|
+
};
|
|
15
|
+
exports.getConfig = getConfig;
|
|
16
|
+
//# sourceMappingURL=config.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.cjs","sources":["../../src/config.ts"],"sourcesContent":["import { z } from 'zod'\nimport {\n configSchema as generatorConfigSchema,\n getConfig as getGeneratorConfig,\n} from '@tanstack/router-generator'\n\nconst configSchema = generatorConfigSchema.extend({\n enableRouteGeneration: z.boolean().optional(),\n experimental: z\n .object({\n enableCodeSplitting: z.boolean().optional(),\n })\n .optional(),\n})\n\nexport const getConfig = async (\n inlineConfig: Partial<PluginOptions>,\n root: string,\n) => {\n const config = await getGeneratorConfig(inlineConfig, root)\n\n return configSchema.parse({ ...config, ...inlineConfig })\n}\n\nexport type PluginOptions = z.infer<typeof configSchema>\n"],"names":["generatorConfigSchema","z","getGeneratorConfig"],"mappings":";;;;AAMA,MAAM,eAAeA,6BAAsB,OAAO;AAAA,EAChD,uBAAuBC,IAAA,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC5C,cAAcA,MACX,OAAO;AAAA,IACN,qBAAqBA,IAAA,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC3C,CAAA,EACA,SAAS;AACd,CAAC;AAEY,MAAA,YAAY,OACvB,cACA,SACG;AACH,QAAM,SAAS,MAAMC,gBAAAA,UAAmB,cAAc,IAAI;AAE1D,SAAO,aAAa,MAAM,EAAE,GAAG,QAAQ,GAAG,cAAc;AAC1D;;"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const configSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
4
|
+
routeFilePrefix: z.ZodOptional<z.ZodString>;
|
|
5
|
+
routeFileIgnorePrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
6
|
+
routeFileIgnorePattern: z.ZodOptional<z.ZodString>;
|
|
7
|
+
routesDirectory: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
8
|
+
generatedRouteTree: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
9
|
+
quoteStyle: z.ZodDefault<z.ZodOptional<z.ZodEnum<["single", "double"]>>>;
|
|
10
|
+
semicolons: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
11
|
+
disableTypes: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
12
|
+
addExtensions: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
13
|
+
disableLogging: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
14
|
+
routeTreeFileHeader: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
15
|
+
routeTreeFileFooter: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
16
|
+
}, {
|
|
17
|
+
enableRouteGeneration: z.ZodOptional<z.ZodBoolean>;
|
|
18
|
+
experimental: z.ZodOptional<z.ZodObject<{
|
|
19
|
+
enableCodeSplitting: z.ZodOptional<z.ZodBoolean>;
|
|
20
|
+
}, "strip", z.ZodTypeAny, {
|
|
21
|
+
enableCodeSplitting?: boolean | undefined;
|
|
22
|
+
}, {
|
|
23
|
+
enableCodeSplitting?: boolean | undefined;
|
|
24
|
+
}>>;
|
|
25
|
+
}>, "strip", z.ZodTypeAny, {
|
|
26
|
+
routeFileIgnorePrefix: string;
|
|
27
|
+
routesDirectory: string;
|
|
28
|
+
generatedRouteTree: string;
|
|
29
|
+
quoteStyle: "single" | "double";
|
|
30
|
+
semicolons: boolean;
|
|
31
|
+
disableTypes: boolean;
|
|
32
|
+
addExtensions: boolean;
|
|
33
|
+
disableLogging: boolean;
|
|
34
|
+
routeTreeFileHeader: string[];
|
|
35
|
+
routeTreeFileFooter: string[];
|
|
36
|
+
enableRouteGeneration?: boolean | undefined;
|
|
37
|
+
experimental?: {
|
|
38
|
+
enableCodeSplitting?: boolean | undefined;
|
|
39
|
+
} | undefined;
|
|
40
|
+
routeFilePrefix?: string | undefined;
|
|
41
|
+
routeFileIgnorePattern?: string | undefined;
|
|
42
|
+
}, {
|
|
43
|
+
enableRouteGeneration?: boolean | undefined;
|
|
44
|
+
experimental?: {
|
|
45
|
+
enableCodeSplitting?: boolean | undefined;
|
|
46
|
+
} | undefined;
|
|
47
|
+
routeFilePrefix?: string | undefined;
|
|
48
|
+
routeFileIgnorePrefix?: string | undefined;
|
|
49
|
+
routeFileIgnorePattern?: string | undefined;
|
|
50
|
+
routesDirectory?: string | undefined;
|
|
51
|
+
generatedRouteTree?: string | undefined;
|
|
52
|
+
quoteStyle?: "single" | "double" | undefined;
|
|
53
|
+
semicolons?: boolean | undefined;
|
|
54
|
+
disableTypes?: boolean | undefined;
|
|
55
|
+
addExtensions?: boolean | undefined;
|
|
56
|
+
disableLogging?: boolean | undefined;
|
|
57
|
+
routeTreeFileHeader?: string[] | undefined;
|
|
58
|
+
routeTreeFileFooter?: string[] | undefined;
|
|
59
|
+
}>;
|
|
60
|
+
export declare const getConfig: (inlineConfig: Partial<PluginOptions>, root: string) => Promise<{
|
|
61
|
+
routeFileIgnorePrefix: string;
|
|
62
|
+
routesDirectory: string;
|
|
63
|
+
generatedRouteTree: string;
|
|
64
|
+
quoteStyle: "single" | "double";
|
|
65
|
+
semicolons: boolean;
|
|
66
|
+
disableTypes: boolean;
|
|
67
|
+
addExtensions: boolean;
|
|
68
|
+
disableLogging: boolean;
|
|
69
|
+
routeTreeFileHeader: string[];
|
|
70
|
+
routeTreeFileFooter: string[];
|
|
71
|
+
enableRouteGeneration?: boolean | undefined;
|
|
72
|
+
experimental?: {
|
|
73
|
+
enableCodeSplitting?: boolean | undefined;
|
|
74
|
+
} | undefined;
|
|
75
|
+
routeFilePrefix?: string | undefined;
|
|
76
|
+
routeFileIgnorePattern?: string | undefined;
|
|
77
|
+
}>;
|
|
78
|
+
export type PluginOptions = z.infer<typeof configSchema>;
|
|
79
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const CONFIG_FILE_NAME = "tsr.config.json";
|
|
4
|
+
const splitPrefix = "tsr-split";
|
|
5
|
+
exports.CONFIG_FILE_NAME = CONFIG_FILE_NAME;
|
|
6
|
+
exports.splitPrefix = splitPrefix;
|
|
7
|
+
//# sourceMappingURL=constants.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.cjs","sources":["../../src/constants.ts"],"sourcesContent":["export const CONFIG_FILE_NAME = 'tsr.config.json'\nexport const splitPrefix = 'tsr-split'\n"],"names":[],"mappings":";;AAAO,MAAM,mBAAmB;AACzB,MAAM,cAAc;;;"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const t = require("@babel/types");
|
|
4
|
+
function _interopNamespaceDefault(e) {
|
|
5
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
6
|
+
if (e) {
|
|
7
|
+
for (const k in e) {
|
|
8
|
+
if (k !== "default") {
|
|
9
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
10
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: () => e[k]
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
n.default = e;
|
|
18
|
+
return Object.freeze(n);
|
|
19
|
+
}
|
|
20
|
+
const t__namespace = /* @__PURE__ */ _interopNamespaceDefault(t);
|
|
21
|
+
const eliminateUnreferencedIdentifiers = (programPath, refs) => {
|
|
22
|
+
let referencesRemovedInThisPass;
|
|
23
|
+
const shouldBeRemoved = (ident) => {
|
|
24
|
+
if (isIdentifierReferenced(ident))
|
|
25
|
+
return false;
|
|
26
|
+
return true;
|
|
27
|
+
};
|
|
28
|
+
const sweepFunction = (path) => {
|
|
29
|
+
const identifier = getIdentifier(path);
|
|
30
|
+
if ((identifier == null ? void 0 : identifier.node) && shouldBeRemoved(identifier)) {
|
|
31
|
+
++referencesRemovedInThisPass;
|
|
32
|
+
if (t__namespace.isAssignmentExpression(path.parentPath.node) || t__namespace.isVariableDeclarator(path.parentPath.node)) {
|
|
33
|
+
path.parentPath.remove();
|
|
34
|
+
} else {
|
|
35
|
+
path.remove();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const sweepImport = (path) => {
|
|
40
|
+
const local = path.get("local");
|
|
41
|
+
if (shouldBeRemoved(local)) {
|
|
42
|
+
++referencesRemovedInThisPass;
|
|
43
|
+
path.remove();
|
|
44
|
+
if (path.parent.specifiers.length === 0) {
|
|
45
|
+
path.parentPath.remove();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const handleObjectPattern = (pattern) => {
|
|
50
|
+
const properties = pattern.get("properties");
|
|
51
|
+
properties.forEach((property) => {
|
|
52
|
+
if (property.node.type === "ObjectProperty") {
|
|
53
|
+
const value = property.get("value");
|
|
54
|
+
if (t__namespace.isIdentifier(value)) {
|
|
55
|
+
if (shouldBeRemoved(value)) {
|
|
56
|
+
property.remove();
|
|
57
|
+
}
|
|
58
|
+
} else if (t__namespace.isObjectPattern(value)) {
|
|
59
|
+
handleObjectPattern(value);
|
|
60
|
+
}
|
|
61
|
+
} else if (t__namespace.isRestElement(property.node)) {
|
|
62
|
+
const argument = property.get("argument");
|
|
63
|
+
if (t__namespace.isIdentifier(argument) && shouldBeRemoved(argument)) {
|
|
64
|
+
property.remove();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
do {
|
|
70
|
+
referencesRemovedInThisPass = 0;
|
|
71
|
+
programPath.scope.crawl();
|
|
72
|
+
programPath.traverse({
|
|
73
|
+
VariableDeclarator(path) {
|
|
74
|
+
if (path.node.id.type === "Identifier") {
|
|
75
|
+
const local = path.get("id");
|
|
76
|
+
if (shouldBeRemoved(local)) {
|
|
77
|
+
++referencesRemovedInThisPass;
|
|
78
|
+
path.remove();
|
|
79
|
+
}
|
|
80
|
+
} else if (path.node.id.type === "ObjectPattern") {
|
|
81
|
+
handleObjectPattern(
|
|
82
|
+
path.get("id")
|
|
83
|
+
);
|
|
84
|
+
} else if (path.node.id.type === "ArrayPattern") {
|
|
85
|
+
const pattern = path.get("id");
|
|
86
|
+
let hasRemoved = false;
|
|
87
|
+
pattern.get("elements").forEach((element, index) => {
|
|
88
|
+
let identifierPath;
|
|
89
|
+
if (t__namespace.isIdentifier(element.node)) {
|
|
90
|
+
identifierPath = element;
|
|
91
|
+
} else if (t__namespace.isRestElement(element.node)) {
|
|
92
|
+
identifierPath = element.get(
|
|
93
|
+
"argument"
|
|
94
|
+
);
|
|
95
|
+
} else {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (shouldBeRemoved(identifierPath)) {
|
|
99
|
+
hasRemoved = true;
|
|
100
|
+
pattern.node.elements[index] = null;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
if (hasRemoved && pattern.node.elements.every((element) => element === null)) {
|
|
104
|
+
path.remove();
|
|
105
|
+
++referencesRemovedInThisPass;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
FunctionDeclaration: sweepFunction,
|
|
110
|
+
FunctionExpression: sweepFunction,
|
|
111
|
+
ArrowFunctionExpression: sweepFunction,
|
|
112
|
+
ImportSpecifier: sweepImport,
|
|
113
|
+
ImportDefaultSpecifier: sweepImport,
|
|
114
|
+
ImportNamespaceSpecifier: sweepImport
|
|
115
|
+
});
|
|
116
|
+
} while (referencesRemovedInThisPass);
|
|
117
|
+
};
|
|
118
|
+
function getIdentifier(path) {
|
|
119
|
+
const parentPath = path.parentPath;
|
|
120
|
+
if (parentPath.type === "VariableDeclarator") {
|
|
121
|
+
const variablePath = parentPath;
|
|
122
|
+
const name = variablePath.get("id");
|
|
123
|
+
return name.node.type === "Identifier" ? name : null;
|
|
124
|
+
}
|
|
125
|
+
if (parentPath.type === "AssignmentExpression") {
|
|
126
|
+
const variablePath = parentPath;
|
|
127
|
+
const name = variablePath.get("left");
|
|
128
|
+
return name.node.type === "Identifier" ? name : null;
|
|
129
|
+
}
|
|
130
|
+
if (path.node.type === "ArrowFunctionExpression") {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
if (path.node.type === "FunctionExpression") {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
return path.node.id && path.node.id.type === "Identifier" ? path.get("id") : null;
|
|
137
|
+
}
|
|
138
|
+
function isIdentifierReferenced(ident) {
|
|
139
|
+
const binding = ident.scope.getBinding(ident.node.name);
|
|
140
|
+
if (binding == null ? void 0 : binding.referenced) {
|
|
141
|
+
if (binding.path.type === "FunctionDeclaration") {
|
|
142
|
+
return !binding.constantViolations.concat(binding.referencePaths).every((ref) => ref.findParent((parent) => parent === binding.path));
|
|
143
|
+
}
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
exports.eliminateUnreferencedIdentifiers = eliminateUnreferencedIdentifiers;
|
|
149
|
+
//# sourceMappingURL=eliminateUnreferencedIdentifiers.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eliminateUnreferencedIdentifiers.cjs","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/**\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 const handleObjectPattern = (pattern: NodePath<BabelTypes.ObjectPattern>) => {\n const properties = pattern.get('properties')\n properties.forEach((property) => {\n if (property.node.type === 'ObjectProperty') {\n const value = property.get('value') as any\n if (t.isIdentifier(value)) {\n if (shouldBeRemoved(value as any)) {\n property.remove()\n }\n } else if (t.isObjectPattern(value)) {\n handleObjectPattern(value as any)\n }\n } else if (t.isRestElement(property.node)) {\n const argument = property.get('argument')\n if (\n t.isIdentifier(argument as any) &&\n shouldBeRemoved(argument as NodePath<BabelTypes.Identifier>)\n ) {\n property.remove()\n }\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 handleObjectPattern(\n path.get('id') as NodePath<BabelTypes.ObjectPattern>,\n )\n } else if (path.node.id.type === 'ArrayPattern') {\n const pattern = path.get('id') as NodePath<BabelTypes.ArrayPattern>\n\n let hasRemoved = false as boolean\n\n pattern.get('elements').forEach((element, index) => {\n // if (!element) return // Skip holes in the pattern\n\n let identifierPath: NodePath<BabelTypes.Identifier>\n\n if (t.isIdentifier(element.node)) {\n identifierPath = element as NodePath<BabelTypes.Identifier>\n } else if (t.isRestElement(element.node)) {\n identifierPath = element.get(\n 'argument',\n ) as NodePath<BabelTypes.Identifier>\n } else {\n // For now, ignore other types like AssignmentPattern\n return\n }\n\n if (shouldBeRemoved(identifierPath)) {\n hasRemoved = true\n pattern.node.elements[index] = null // Remove the element by setting it to null\n }\n })\n\n // If any elements were removed and no elements are left, remove the entire declaration\n if (\n hasRemoved &&\n pattern.node.elements.every((element) => element === null)\n ) {\n path.remove()\n ++referencesRemovedInThisPass\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 if (path.node.type === 'FunctionExpression') {\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":["t"],"mappings":";;;;;;;;;;;;;;;;;;;;AAYa,MAAA,m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AAI;AAClC,WAAO,KAAK,KAAK,SAAS,eACrB,OACD;AAAA,EACN;AAEI,MAAA,WAAW,SAAS,wBAAwB;AAC9C,UAAM,eAAe;AACf,UAAA,OAAO,aAAa,IAAI,MAAM;AACpC,WAAO,KAAK,KAAK,SAAS,eACrB,OACD;AAAA,EACN;AAEI,MAAA,KAAK,KAAK,SAAS,2BAA2B;AACzC,WAAA;AAAA,EACT;AAEI,MAAA,KAAK,KAAK,SAAS,sBAAsB;AACpC,WAAA;AAAA,EACT;AAGO,SAAA,KAAK,KAAK,MAAM,KAAK,KAAK,GAAG,SAAS,eACxC,KAAK,IAAI,IAAI,IACd;AACN;AAEA,SAAS,uBACP,OACS;AACT,QAAM,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;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { types as BabelTypes } from '@babel/core';
|
|
2
|
+
import { NodePath } from '@babel/traverse';
|
|
3
|
+
|
|
4
|
+
type IdentifierPath = NodePath<BabelTypes.Identifier>;
|
|
5
|
+
/**
|
|
6
|
+
* @param refs - If provided, only these identifiers will be considered for removal.
|
|
7
|
+
*/
|
|
8
|
+
export declare const eliminateUnreferencedIdentifiers: (programPath: NodePath<BabelTypes.Program>, refs?: Set<IdentifierPath>) => void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const codeSplitter = require("./code-splitter.cjs");
|
|
4
|
+
const routerGenerator = require("./router-generator.cjs");
|
|
5
|
+
exports.unpluginRouterCodeSplitter = codeSplitter.unpluginRouterCodeSplitter;
|
|
6
|
+
exports.unpluginRouterGenerator = routerGenerator.unpluginRouterGenerator;
|
|
7
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const node_path = require("node:path");
|
|
4
|
+
const unplugin = require("unplugin");
|
|
5
|
+
const routerGenerator = require("@tanstack/router-generator");
|
|
6
|
+
const config = require("./config.cjs");
|
|
7
|
+
const constants = require("./constants.cjs");
|
|
8
|
+
let lock = false;
|
|
9
|
+
const checkLock = () => lock;
|
|
10
|
+
const setLock = (bool) => {
|
|
11
|
+
lock = bool;
|
|
12
|
+
};
|
|
13
|
+
const unpluginFactory = (options = {}) => {
|
|
14
|
+
let ROOT = process.cwd();
|
|
15
|
+
let userConfig = options;
|
|
16
|
+
const generate = async () => {
|
|
17
|
+
if (checkLock()) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
setLock(true);
|
|
21
|
+
try {
|
|
22
|
+
await routerGenerator.generator(userConfig);
|
|
23
|
+
} catch (err) {
|
|
24
|
+
console.error(err);
|
|
25
|
+
console.info();
|
|
26
|
+
} finally {
|
|
27
|
+
setLock(false);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const handleFile = async (file, event) => {
|
|
31
|
+
const filePath = node_path.normalize(file);
|
|
32
|
+
if (filePath === node_path.join(ROOT, constants.CONFIG_FILE_NAME)) {
|
|
33
|
+
userConfig = await config.getConfig(options, ROOT);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (event === "update" && filePath === node_path.resolve(userConfig.generatedRouteTree)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const routesDirectoryPath = node_path.isAbsolute(userConfig.routesDirectory) ? userConfig.routesDirectory : node_path.join(ROOT, userConfig.routesDirectory);
|
|
40
|
+
if (filePath.startsWith(routesDirectoryPath)) {
|
|
41
|
+
await generate();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const run = async (cb) => {
|
|
45
|
+
if (userConfig.enableRouteGeneration ?? true) {
|
|
46
|
+
await cb();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
name: "router-generator-plugin",
|
|
51
|
+
async watchChange(id, { event }) {
|
|
52
|
+
await run(async () => {
|
|
53
|
+
await handleFile(id, event);
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
vite: {
|
|
57
|
+
async configResolved(config$1) {
|
|
58
|
+
ROOT = config$1.root;
|
|
59
|
+
userConfig = await config.getConfig(options, ROOT);
|
|
60
|
+
await run(generate);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
const unpluginRouterGenerator = /* @__PURE__ */ unplugin.createUnplugin(unpluginFactory);
|
|
66
|
+
exports.unpluginRouterGenerator = unpluginRouterGenerator;
|
|
67
|
+
//# sourceMappingURL=router-generator.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-generator.cjs","sources":["../../src/router-generator.ts"],"sourcesContent":["import { isAbsolute, join, normalize, resolve } from 'node:path'\nimport { createUnplugin } from 'unplugin'\nimport { generator } from '@tanstack/router-generator'\n\nimport { getConfig } from './config'\nimport { CONFIG_FILE_NAME } from './constants'\nimport type { PluginOptions } from './config'\nimport type { UnpluginFactory } from 'unplugin'\n\nlet lock = false\nconst checkLock = () => lock\nconst setLock = (bool: boolean) => {\n lock = bool\n}\n\nconst unpluginFactory: UnpluginFactory<Partial<PluginOptions>> = (\n options = {},\n) => {\n let ROOT: string = process.cwd()\n let userConfig = options as PluginOptions\n\n const generate = async () => {\n if (checkLock()) {\n return\n }\n\n setLock(true)\n\n try {\n await generator(userConfig)\n } catch (err) {\n console.error(err)\n console.info()\n } finally {\n setLock(false)\n }\n }\n\n const handleFile = async (\n file: string,\n event: 'create' | 'update' | 'delete',\n ) => {\n const filePath = normalize(file)\n\n if (filePath === join(ROOT, CONFIG_FILE_NAME)) {\n userConfig = await getConfig(options, ROOT)\n return\n }\n\n if (\n event === 'update' &&\n filePath === resolve(userConfig.generatedRouteTree)\n ) {\n // skip generating routes if the generated route tree is updated\n return\n }\n\n const routesDirectoryPath = isAbsolute(userConfig.routesDirectory)\n ? userConfig.routesDirectory\n : join(ROOT, userConfig.routesDirectory)\n\n if (filePath.startsWith(routesDirectoryPath)) {\n await generate()\n }\n }\n\n const run: (cb: () => Promise<void> | void) => Promise<void> = async (cb) => {\n if (userConfig.enableRouteGeneration ?? true) {\n await cb()\n }\n }\n\n return {\n name: 'router-generator-plugin',\n async watchChange(id, { event }) {\n await run(async () => {\n await handleFile(id, event)\n })\n },\n vite: {\n async configResolved(config) {\n ROOT = config.root\n userConfig = await getConfig(options, ROOT)\n\n await run(generate)\n },\n },\n }\n}\n\nexport const unpluginRouterGenerator =\n /* #__PURE__ */ createUnplugin(unpluginFactory)\n"],"names":["generator","normalize","join","CONFIG_FILE_NAME","getConfig","resolve","isAbsolute","config"],"mappings":";;;;;;;AASA,IAAI,OAAO;AACX,MAAM,YAAY,MAAM;AACxB,MAAM,UAAU,CAAC,SAAkB;AAC1B,SAAA;AACT;AAEA,MAAM,kBAA2D,CAC/D,UAAU,OACP;AACC,MAAA,OAAe,QAAQ;AAC3B,MAAI,aAAa;AAEjB,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf;AAAA,IACF;AAEA,YAAQ,IAAI;AAER,QAAA;AACF,YAAMA,gBAAAA,UAAU,UAAU;AAAA,aACnB,KAAK;AACZ,cAAQ,MAAM,GAAG;AACjB,cAAQ,KAAK;AAAA,IAAA,UACb;AACA,cAAQ,KAAK;AAAA,IACf;AAAA,EAAA;AAGI,QAAA,aAAa,OACjB,MACA,UACG;AACG,UAAA,WAAWC,oBAAU,IAAI;AAE/B,QAAI,aAAaC,UAAAA,KAAK,MAAMC,UAAgB,gBAAA,GAAG;AAChC,mBAAA,MAAMC,OAAAA,UAAU,SAAS,IAAI;AAC1C;AAAA,IACF;AAEA,QACE,UAAU,YACV,aAAaC,UAAAA,QAAQ,WAAW,kBAAkB,GAClD;AAEA;AAAA,IACF;AAEM,UAAA,sBAAsBC,UAAAA,WAAW,WAAW,eAAe,IAC7D,WAAW,kBACXJ,eAAK,MAAM,WAAW,eAAe;AAErC,QAAA,SAAS,WAAW,mBAAmB,GAAG;AAC5C,YAAM,SAAS;AAAA,IACjB;AAAA,EAAA;AAGI,QAAA,MAAyD,OAAO,OAAO;AACvE,QAAA,WAAW,yBAAyB,MAAM;AAC5C,YAAM,GAAG;AAAA,IACX;AAAA,EAAA;AAGK,SAAA;AAAA,IACL,MAAM;AAAA,IACN,MAAM,YAAY,IAAI,EAAE,SAAS;AAC/B,YAAM,IAAI,YAAY;AACd,cAAA,WAAW,IAAI,KAAK;AAAA,MAAA,CAC3B;AAAA,IACH;AAAA,IACA,MAAM;AAAA,MACJ,MAAM,eAAeK,UAAQ;AAC3B,eAAOA,SAAO;AACD,qBAAA,MAAMH,OAAAA,UAAU,SAAS,IAAI;AAE1C,cAAM,IAAI,QAAQ;AAAA,MACpB;AAAA,IACF;AAAA,EAAA;AAEJ;AAEa,MAAA,kEACoB,eAAe;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const unpluginRouterGenerator: import('unplugin').UnpluginInstance<Partial<{
|
|
2
|
+
routeFileIgnorePrefix: string;
|
|
3
|
+
routesDirectory: string;
|
|
4
|
+
generatedRouteTree: string;
|
|
5
|
+
quoteStyle: "single" | "double";
|
|
6
|
+
semicolons: boolean;
|
|
7
|
+
disableTypes: boolean;
|
|
8
|
+
addExtensions: boolean;
|
|
9
|
+
disableLogging: boolean;
|
|
10
|
+
routeTreeFileHeader: string[];
|
|
11
|
+
routeTreeFileFooter: string[];
|
|
12
|
+
enableRouteGeneration?: boolean | undefined;
|
|
13
|
+
experimental?: {
|
|
14
|
+
enableCodeSplitting?: boolean | undefined;
|
|
15
|
+
} | undefined;
|
|
16
|
+
routeFilePrefix?: string | undefined;
|
|
17
|
+
routeFileIgnorePattern?: string | undefined;
|
|
18
|
+
}>, boolean>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const codeSplitter = require("./code-splitter.cjs");
|
|
4
|
+
const routerGenerator = require("./router-generator.cjs");
|
|
5
|
+
const TanStackRouterGeneratorVite = routerGenerator.unpluginRouterGenerator.vite;
|
|
6
|
+
const TanStackRouterCodeSplitterVite = codeSplitter.unpluginRouterCodeSplitter.vite;
|
|
7
|
+
function TanStackRouterVite(inlineConfig) {
|
|
8
|
+
return [
|
|
9
|
+
TanStackRouterGeneratorVite(inlineConfig),
|
|
10
|
+
TanStackRouterCodeSplitterVite(inlineConfig)
|
|
11
|
+
];
|
|
12
|
+
}
|
|
13
|
+
exports.TanStackRouterCodeSplitterVite = TanStackRouterCodeSplitterVite;
|
|
14
|
+
exports.TanStackRouterGeneratorVite = TanStackRouterGeneratorVite;
|
|
15
|
+
exports.TanStackRouterVite = TanStackRouterVite;
|
|
16
|
+
//# sourceMappingURL=vite.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.cjs","sources":["../../src/vite.ts"],"sourcesContent":["import { unpluginRouterCodeSplitter } from './code-splitter'\nimport { unpluginRouterGenerator } from './router-generator'\n\nimport type { PluginOptions } from './config'\nimport type { VitePlugin } from 'unplugin'\n\nexport const TanStackRouterGeneratorVite = unpluginRouterGenerator.vite\nexport const TanStackRouterCodeSplitterVite = unpluginRouterCodeSplitter.vite\n\nexport function TanStackRouterVite(\n inlineConfig: Partial<PluginOptions>,\n): Array<VitePlugin> {\n return [\n TanStackRouterGeneratorVite(inlineConfig) as VitePlugin,\n TanStackRouterCodeSplitterVite(inlineConfig) as VitePlugin,\n ]\n}\n\nexport type Config = PluginOptions\n"],"names":["unpluginRouterGenerator","unpluginRouterCodeSplitter"],"mappings":";;;;AAMO,MAAM,8BAA8BA,gBAAwB,wBAAA;AAC5D,MAAM,iCAAiCC,aAA2B,2BAAA;AAElE,SAAS,mBACd,cACmB;AACZ,SAAA;AAAA,IACL,4BAA4B,YAAY;AAAA,IACxC,+BAA+B,YAAY;AAAA,EAAA;AAE/C;;;;"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { PluginOptions } from './config.cjs';
|
|
2
|
+
import { VitePlugin } from 'unplugin';
|
|
3
|
+
|
|
4
|
+
export declare const TanStackRouterGeneratorVite: (options: Partial<{
|
|
5
|
+
routeFileIgnorePrefix: string;
|
|
6
|
+
routesDirectory: string;
|
|
7
|
+
generatedRouteTree: string;
|
|
8
|
+
quoteStyle: "single" | "double";
|
|
9
|
+
semicolons: boolean;
|
|
10
|
+
disableTypes: boolean;
|
|
11
|
+
addExtensions: boolean;
|
|
12
|
+
disableLogging: boolean;
|
|
13
|
+
routeTreeFileHeader: string[];
|
|
14
|
+
routeTreeFileFooter: string[];
|
|
15
|
+
enableRouteGeneration?: boolean | undefined;
|
|
16
|
+
experimental?: {
|
|
17
|
+
enableCodeSplitting?: boolean | undefined;
|
|
18
|
+
} | undefined;
|
|
19
|
+
routeFilePrefix?: string | undefined;
|
|
20
|
+
routeFileIgnorePattern?: string | undefined;
|
|
21
|
+
}>) => VitePlugin<any> | VitePlugin<any>[];
|
|
22
|
+
export declare const TanStackRouterCodeSplitterVite: (options: Partial<{
|
|
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
|
+
routeTreeFileHeader: string[];
|
|
32
|
+
routeTreeFileFooter: string[];
|
|
33
|
+
enableRouteGeneration?: boolean | undefined;
|
|
34
|
+
experimental?: {
|
|
35
|
+
enableCodeSplitting?: boolean | undefined;
|
|
36
|
+
} | undefined;
|
|
37
|
+
routeFilePrefix?: string | undefined;
|
|
38
|
+
routeFileIgnorePattern?: string | undefined;
|
|
39
|
+
}>) => VitePlugin<any> | VitePlugin<any>[];
|
|
40
|
+
export declare function TanStackRouterVite(inlineConfig: Partial<PluginOptions>): Array<VitePlugin>;
|
|
41
|
+
export type Config = PluginOptions;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type CompileAstFn = (compileOpts: {
|
|
2
|
+
code: string;
|
|
3
|
+
filename: string;
|
|
4
|
+
getBabelConfig: () => {
|
|
5
|
+
plugins: Array<any>;
|
|
6
|
+
};
|
|
7
|
+
}) => Promise<{
|
|
8
|
+
code: string;
|
|
9
|
+
map: any;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function compileAst(makeOpts: {
|
|
12
|
+
root: string;
|
|
13
|
+
}): (opts: {
|
|
14
|
+
code: string;
|
|
15
|
+
filename: string;
|
|
16
|
+
getBabelConfig: () => {
|
|
17
|
+
plugins: Array<any>;
|
|
18
|
+
};
|
|
19
|
+
}) => Promise<{
|
|
20
|
+
code: string;
|
|
21
|
+
map: any;
|
|
22
|
+
}>;
|
package/dist/esm/ast.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as babel from "@babel/core";
|
|
2
|
+
function compileAst(makeOpts) {
|
|
3
|
+
return async (opts) => {
|
|
4
|
+
const res = babel.transformSync(opts.code, {
|
|
5
|
+
plugins: [
|
|
6
|
+
["@babel/plugin-syntax-jsx", {}],
|
|
7
|
+
[
|
|
8
|
+
"@babel/plugin-syntax-typescript",
|
|
9
|
+
{
|
|
10
|
+
isTSX: true
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
...opts.getBabelConfig().plugins
|
|
14
|
+
],
|
|
15
|
+
root: makeOpts.root,
|
|
16
|
+
filename: opts.filename,
|
|
17
|
+
sourceMaps: true
|
|
18
|
+
});
|
|
19
|
+
if (res == null ? void 0 : res.code) {
|
|
20
|
+
return {
|
|
21
|
+
code: res.code,
|
|
22
|
+
map: res.map
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
code: opts.code,
|
|
27
|
+
map: null
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
compileAst
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=ast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.js","sources":["../../src/ast.ts"],"sourcesContent":["import * as babel from '@babel/core'\n\nexport type CompileAstFn = (compileOpts: {\n code: string\n filename: string\n getBabelConfig: () => { plugins: Array<any> }\n}) => Promise<{\n code: string\n map: any\n}>\n\nexport function compileAst(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 = babel.transformSync(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"],"names":[],"mappings":";AAWO,SAAS,WAAW,UAA4B;AACrD,SAAO,OAAO,SAOR;AACJ,UAAM,MAAM,MAAM,cAAc,KAAK,MAAM;AAAA,MACzC,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;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PluginOptions } from './config.js';
|
|
2
|
+
import { UnpluginFactory } from 'unplugin';
|
|
3
|
+
|
|
4
|
+
export declare const unpluginFactory: UnpluginFactory<Partial<PluginOptions>>;
|
|
5
|
+
export declare const unpluginRouterCodeSplitter: import('unplugin').UnpluginInstance<Partial<{
|
|
6
|
+
routeFileIgnorePrefix: string;
|
|
7
|
+
routesDirectory: string;
|
|
8
|
+
generatedRouteTree: string;
|
|
9
|
+
quoteStyle: "single" | "double";
|
|
10
|
+
semicolons: boolean;
|
|
11
|
+
disableTypes: boolean;
|
|
12
|
+
addExtensions: boolean;
|
|
13
|
+
disableLogging: boolean;
|
|
14
|
+
routeTreeFileHeader: string[];
|
|
15
|
+
routeTreeFileFooter: string[];
|
|
16
|
+
enableRouteGeneration?: boolean | undefined;
|
|
17
|
+
experimental?: {
|
|
18
|
+
enableCodeSplitting?: boolean | undefined;
|
|
19
|
+
} | undefined;
|
|
20
|
+
routeFilePrefix?: string | undefined;
|
|
21
|
+
routeFileIgnorePattern?: string | undefined;
|
|
22
|
+
}>, boolean>;
|