@tanstack/router-generator 1.132.0-alpha.9 → 1.132.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/dist/cjs/config.cjs +6 -2
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/config.d.cts +12 -9
- package/dist/cjs/generator.cjs +264 -316
- package/dist/cjs/generator.cjs.map +1 -1
- package/dist/cjs/generator.d.cts +20 -7
- package/dist/cjs/index.cjs +0 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +4 -4
- package/dist/cjs/plugin/types.d.cts +10 -38
- package/dist/cjs/transform/transform.cjs +108 -40
- package/dist/cjs/transform/transform.cjs.map +1 -1
- package/dist/cjs/transform/transform.d.cts +1 -1
- package/dist/cjs/transform/types.d.cts +4 -18
- package/dist/cjs/types.d.cts +1 -1
- package/dist/cjs/utils.cjs +55 -39
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +5 -5
- package/dist/esm/config.d.ts +12 -9
- package/dist/esm/config.js +6 -2
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/generator.d.ts +20 -7
- package/dist/esm/generator.js +266 -318
- package/dist/esm/generator.js.map +1 -1
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.js +1 -2
- package/dist/esm/plugin/types.d.ts +10 -38
- package/dist/esm/transform/transform.d.ts +1 -1
- package/dist/esm/transform/transform.js +106 -38
- package/dist/esm/transform/transform.js.map +1 -1
- package/dist/esm/transform/types.d.ts +4 -18
- package/dist/esm/types.d.ts +1 -1
- package/dist/esm/utils.d.ts +5 -5
- package/dist/esm/utils.js +55 -39
- package/dist/esm/utils.js.map +1 -1
- package/package.json +5 -5
- package/src/config.ts +7 -1
- package/src/generator.ts +306 -366
- package/src/index.ts +2 -7
- package/src/plugin/types.ts +11 -44
- package/src/transform/transform.ts +118 -53
- package/src/transform/types.ts +5 -18
- package/src/types.ts +1 -1
- package/src/utils.ts +85 -70
- package/dist/cjs/plugin/default-generator-plugin.cjs +0 -94
- package/dist/cjs/plugin/default-generator-plugin.cjs.map +0 -1
- package/dist/cjs/plugin/default-generator-plugin.d.cts +0 -2
- package/dist/cjs/transform/default-transform-plugin.cjs +0 -97
- package/dist/cjs/transform/default-transform-plugin.cjs.map +0 -1
- package/dist/cjs/transform/default-transform-plugin.d.cts +0 -2
- package/dist/esm/plugin/default-generator-plugin.d.ts +0 -2
- package/dist/esm/plugin/default-generator-plugin.js +0 -94
- package/dist/esm/plugin/default-generator-plugin.js.map +0 -1
- package/dist/esm/transform/default-transform-plugin.d.ts +0 -2
- package/dist/esm/transform/default-transform-plugin.js +0 -97
- package/dist/esm/transform/default-transform-plugin.js.map +0 -1
- package/src/plugin/default-generator-plugin.ts +0 -109
- package/src/transform/default-transform-plugin.ts +0 -106
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const defaultTransformPlugin = require("../transform/default-transform-plugin.cjs");
|
|
4
|
-
const utils = require("../utils.cjs");
|
|
5
|
-
const EXPORT_NAME = "Route";
|
|
6
|
-
function defaultGeneratorPlugin() {
|
|
7
|
-
return {
|
|
8
|
-
name: "default",
|
|
9
|
-
transformPlugin: defaultTransformPlugin.defaultTransformPlugin,
|
|
10
|
-
imports: (opts) => {
|
|
11
|
-
const imports = [];
|
|
12
|
-
if (opts.acc.routeNodes.some((n) => n.isVirtual)) {
|
|
13
|
-
imports.push({
|
|
14
|
-
specifiers: [{ imported: "createFileRoute" }],
|
|
15
|
-
source: opts.generator.targetTemplate.fullPkg
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
if (opts.generator.config.verboseFileRoutes === false) {
|
|
19
|
-
const typeImport = {
|
|
20
|
-
specifiers: [],
|
|
21
|
-
source: opts.generator.targetTemplate.fullPkg,
|
|
22
|
-
importKind: "type"
|
|
23
|
-
};
|
|
24
|
-
if (opts.sortedRouteNodes.some(
|
|
25
|
-
(d) => utils.isRouteNodeValidForAugmentation(d) && d._fsRouteType !== "lazy"
|
|
26
|
-
)) {
|
|
27
|
-
typeImport.specifiers.push({ imported: "CreateFileRoute" });
|
|
28
|
-
}
|
|
29
|
-
if (opts.sortedRouteNodes.some(
|
|
30
|
-
(node) => opts.acc.routePiecesByPath[node.routePath]?.lazy && utils.isRouteNodeValidForAugmentation(node)
|
|
31
|
-
)) {
|
|
32
|
-
typeImport.specifiers.push({ imported: "CreateLazyFileRoute" });
|
|
33
|
-
}
|
|
34
|
-
if (typeImport.specifiers.length > 0) {
|
|
35
|
-
typeImport.specifiers.push({ imported: "FileRoutesByPath" });
|
|
36
|
-
imports.push(typeImport);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
const hasMatchingRouteFiles = opts.acc.routeNodes.length > 0;
|
|
40
|
-
if (hasMatchingRouteFiles) {
|
|
41
|
-
if (!opts.rootRouteNode.exports?.includes(EXPORT_NAME)) {
|
|
42
|
-
imports.push({
|
|
43
|
-
specifiers: [{ imported: "createRootRoute" }],
|
|
44
|
-
source: opts.generator.targetTemplate.fullPkg
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return imports;
|
|
49
|
-
},
|
|
50
|
-
moduleAugmentation: ({ generator }) => ({
|
|
51
|
-
module: generator.targetTemplate.fullPkg,
|
|
52
|
-
interfaceName: "FileRoutesByPath"
|
|
53
|
-
}),
|
|
54
|
-
onRouteTreesChanged: ({ routeTrees, generator }) => {
|
|
55
|
-
const routeTree = routeTrees.find(
|
|
56
|
-
(tree) => tree.exportName === EXPORT_NAME
|
|
57
|
-
);
|
|
58
|
-
if (!routeTree) {
|
|
59
|
-
throw new Error(
|
|
60
|
-
'No route tree found with export name "Route". Please ensure your routes are correctly defined.'
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
utils.checkRouteFullPathUniqueness(
|
|
64
|
-
routeTree.sortedRouteNodes.filter(
|
|
65
|
-
(d) => d.children === void 0 && "lazy" !== d._fsRouteType && d.exports?.includes(EXPORT_NAME)
|
|
66
|
-
),
|
|
67
|
-
generator.config
|
|
68
|
-
);
|
|
69
|
-
},
|
|
70
|
-
routeModuleAugmentation: ({ routeNode }) => {
|
|
71
|
-
if (routeNode._fsRouteType === "lazy") {
|
|
72
|
-
return `const createLazyFileRoute: CreateLazyFileRoute<FileRoutesByPath['${routeNode.routePath}']['preLoaderRoute']>`;
|
|
73
|
-
} else {
|
|
74
|
-
return `const createFileRoute: CreateFileRoute<'${routeNode.routePath}',
|
|
75
|
-
FileRoutesByPath['${routeNode.routePath}']['parentRoute'],
|
|
76
|
-
FileRoutesByPath['${routeNode.routePath}']['id'],
|
|
77
|
-
FileRoutesByPath['${routeNode.routePath}']['path'],
|
|
78
|
-
FileRoutesByPath['${routeNode.routePath}']['fullPath']
|
|
79
|
-
>
|
|
80
|
-
`;
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
createRootRouteCode: () => `createRootRoute()`,
|
|
84
|
-
createVirtualRouteCode: ({ node }) => `createFileRoute('${node.routePath}')()`,
|
|
85
|
-
config: ({ sortedRouteNodes }) => {
|
|
86
|
-
const hasMatchingRouteFiles = sortedRouteNodes.length > 0;
|
|
87
|
-
return {
|
|
88
|
-
virtualRootRoute: hasMatchingRouteFiles
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
exports.defaultGeneratorPlugin = defaultGeneratorPlugin;
|
|
94
|
-
//# sourceMappingURL=default-generator-plugin.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"default-generator-plugin.cjs","sources":["../../../src/plugin/default-generator-plugin.ts"],"sourcesContent":["import { defaultTransformPlugin } from '../transform/default-transform-plugin'\nimport {\n checkRouteFullPathUniqueness,\n isRouteNodeValidForAugmentation,\n} from '../utils'\nimport type { ImportDeclaration } from '../types'\nimport type { GeneratorPluginWithTransform } from './types'\n\nconst EXPORT_NAME = 'Route'\nexport function defaultGeneratorPlugin(): GeneratorPluginWithTransform {\n return {\n name: 'default',\n transformPlugin: defaultTransformPlugin,\n imports: (opts) => {\n const imports: Array<ImportDeclaration> = []\n if (opts.acc.routeNodes.some((n) => n.isVirtual)) {\n imports.push({\n specifiers: [{ imported: 'createFileRoute' }],\n source: opts.generator.targetTemplate.fullPkg,\n })\n }\n if (opts.generator.config.verboseFileRoutes === false) {\n const typeImport: ImportDeclaration = {\n specifiers: [],\n source: opts.generator.targetTemplate.fullPkg,\n importKind: 'type',\n }\n if (\n opts.sortedRouteNodes.some(\n (d) =>\n isRouteNodeValidForAugmentation(d) && d._fsRouteType !== 'lazy',\n )\n ) {\n typeImport.specifiers.push({ imported: 'CreateFileRoute' })\n }\n if (\n opts.sortedRouteNodes.some(\n (node) =>\n opts.acc.routePiecesByPath[node.routePath!]?.lazy &&\n isRouteNodeValidForAugmentation(node),\n )\n ) {\n typeImport.specifiers.push({ imported: 'CreateLazyFileRoute' })\n }\n\n if (typeImport.specifiers.length > 0) {\n typeImport.specifiers.push({ imported: 'FileRoutesByPath' })\n imports.push(typeImport)\n }\n }\n const hasMatchingRouteFiles = opts.acc.routeNodes.length > 0\n if (hasMatchingRouteFiles) {\n // needs a virtual root route\n if (!opts.rootRouteNode.exports?.includes(EXPORT_NAME)) {\n imports.push({\n specifiers: [{ imported: 'createRootRoute' }],\n source: opts.generator.targetTemplate.fullPkg,\n })\n }\n }\n return imports\n },\n moduleAugmentation: ({ generator }) => ({\n module: generator.targetTemplate.fullPkg,\n interfaceName: 'FileRoutesByPath',\n }),\n onRouteTreesChanged: ({ routeTrees, generator }) => {\n const routeTree = routeTrees.find(\n (tree) => tree.exportName === EXPORT_NAME,\n )\n if (!routeTree) {\n throw new Error(\n 'No route tree found with export name \"Route\". Please ensure your routes are correctly defined.',\n )\n }\n checkRouteFullPathUniqueness(\n routeTree.sortedRouteNodes.filter(\n (d) =>\n d.children === undefined &&\n 'lazy' !== d._fsRouteType &&\n d.exports?.includes(EXPORT_NAME),\n ),\n generator.config,\n )\n },\n routeModuleAugmentation: ({ routeNode }) => {\n if (routeNode._fsRouteType === 'lazy') {\n return `const createLazyFileRoute: CreateLazyFileRoute<FileRoutesByPath['${routeNode.routePath}']['preLoaderRoute']>`\n } else {\n return `const createFileRoute: CreateFileRoute<'${routeNode.routePath}',\n FileRoutesByPath['${routeNode.routePath}']['parentRoute'],\n FileRoutesByPath['${routeNode.routePath}']['id'],\n FileRoutesByPath['${routeNode.routePath}']['path'],\n FileRoutesByPath['${routeNode.routePath}']['fullPath']\n >\n `\n }\n },\n createRootRouteCode: () => `createRootRoute()`,\n createVirtualRouteCode: ({ node }) =>\n `createFileRoute('${node.routePath}')()`,\n config: ({ sortedRouteNodes }) => {\n const hasMatchingRouteFiles = sortedRouteNodes.length > 0\n return {\n virtualRootRoute: hasMatchingRouteFiles,\n }\n },\n }\n}\n"],"names":["defaultTransformPlugin","isRouteNodeValidForAugmentation","checkRouteFullPathUniqueness"],"mappings":";;;;AAQA,MAAM,cAAc;AACb,SAAS,yBAAuD;AACrE,SAAO;AAAA,IACL,MAAM;AAAA,IACN,iBAAiBA,uBAAAA;AAAAA,IACjB,SAAS,CAAC,SAAS;AACjB,YAAM,UAAoC,CAAA;AAC1C,UAAI,KAAK,IAAI,WAAW,KAAK,CAAC,MAAM,EAAE,SAAS,GAAG;AAChD,gBAAQ,KAAK;AAAA,UACX,YAAY,CAAC,EAAE,UAAU,mBAAmB;AAAA,UAC5C,QAAQ,KAAK,UAAU,eAAe;AAAA,QAAA,CACvC;AAAA,MACH;AACA,UAAI,KAAK,UAAU,OAAO,sBAAsB,OAAO;AACrD,cAAM,aAAgC;AAAA,UACpC,YAAY,CAAA;AAAA,UACZ,QAAQ,KAAK,UAAU,eAAe;AAAA,UACtC,YAAY;AAAA,QAAA;AAEd,YACE,KAAK,iBAAiB;AAAA,UACpB,CAAC,MACCC,MAAAA,gCAAgC,CAAC,KAAK,EAAE,iBAA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QAAQ;AACrC,eAAO,oEAAoE,UAAU,SAAS;AAAA,MAChG,OAAO;AACL,eAAO,2CAA2C,UAAU,SAAS;AAAA,gCAC7C,UAAU,SAAS;AAAA,gCACnB,UAAU,SAAS;AAAA,gCACnB,UAAU,SAAS;AAAA,gCACnB,UAAU,SAAS;AAAA;AAAA;AAAA,MAG7C;AAAA,IACF;AAAA,IACA,qBAAqB,MAAM;AAAA,IAC3B,wBAAwB,CAAC,EAAE,WACzB,oBAAoB,KAAK,SAAS;AAAA,IACpC,QAAQ,CAAC,EAAE,uBAAuB;AAChC,YAAM,wBAAwB,iBAAiB,SAAS;AACxD,aAAO;AAAA,QACL,kBAAkB;AAAA,MAAA;AAAA,IAEtB;AAAA,EAAA;AAEJ;;"}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const recast = require("recast");
|
|
4
|
-
const utils = require("./utils.cjs");
|
|
5
|
-
const b = recast.types.builders;
|
|
6
|
-
const EXPORT_NAME = "Route";
|
|
7
|
-
const defaultTransformPlugin = {
|
|
8
|
-
name: "default-transform",
|
|
9
|
-
exportName: EXPORT_NAME,
|
|
10
|
-
imports: (ctx) => {
|
|
11
|
-
const imports = {};
|
|
12
|
-
const targetModule = `@tanstack/${ctx.target}-router`;
|
|
13
|
-
if (ctx.verboseFileRoutes === false) {
|
|
14
|
-
imports.banned = [
|
|
15
|
-
{
|
|
16
|
-
source: targetModule,
|
|
17
|
-
specifiers: [
|
|
18
|
-
{ imported: "createLazyFileRoute" },
|
|
19
|
-
{ imported: "createFileRoute" }
|
|
20
|
-
]
|
|
21
|
-
}
|
|
22
|
-
];
|
|
23
|
-
} else {
|
|
24
|
-
if (ctx.lazy) {
|
|
25
|
-
imports.required = [
|
|
26
|
-
{
|
|
27
|
-
source: targetModule,
|
|
28
|
-
specifiers: [{ imported: "createLazyFileRoute" }]
|
|
29
|
-
}
|
|
30
|
-
];
|
|
31
|
-
imports.banned = [
|
|
32
|
-
{
|
|
33
|
-
source: targetModule,
|
|
34
|
-
specifiers: [{ imported: "createFileRoute" }]
|
|
35
|
-
}
|
|
36
|
-
];
|
|
37
|
-
} else {
|
|
38
|
-
imports.required = [
|
|
39
|
-
{
|
|
40
|
-
source: targetModule,
|
|
41
|
-
specifiers: [{ imported: "createFileRoute" }]
|
|
42
|
-
}
|
|
43
|
-
];
|
|
44
|
-
imports.banned = [
|
|
45
|
-
{
|
|
46
|
-
source: targetModule,
|
|
47
|
-
specifiers: [{ imported: "createLazyFileRoute" }]
|
|
48
|
-
}
|
|
49
|
-
];
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return imports;
|
|
53
|
-
},
|
|
54
|
-
onExportFound: ({ decl, ctx }) => {
|
|
55
|
-
let appliedChanges = false;
|
|
56
|
-
if (decl.init?.type === "CallExpression") {
|
|
57
|
-
const callExpression = decl.init;
|
|
58
|
-
let identifier;
|
|
59
|
-
if (callExpression.callee.type === "Identifier") {
|
|
60
|
-
identifier = callExpression.callee;
|
|
61
|
-
if (ctx.verboseFileRoutes) {
|
|
62
|
-
callExpression.callee = b.callExpression(identifier, [
|
|
63
|
-
b.stringLiteral(ctx.routeId)
|
|
64
|
-
]);
|
|
65
|
-
appliedChanges = true;
|
|
66
|
-
}
|
|
67
|
-
} else if (callExpression.callee.type === "CallExpression" && callExpression.callee.callee.type === "Identifier") {
|
|
68
|
-
identifier = callExpression.callee.callee;
|
|
69
|
-
if (!ctx.verboseFileRoutes) {
|
|
70
|
-
callExpression.callee = identifier;
|
|
71
|
-
appliedChanges = true;
|
|
72
|
-
} else {
|
|
73
|
-
appliedChanges = utils.ensureStringArgument(
|
|
74
|
-
callExpression.callee,
|
|
75
|
-
ctx.routeId,
|
|
76
|
-
ctx.preferredQuote
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (identifier === void 0) {
|
|
81
|
-
throw new Error(
|
|
82
|
-
`expected identifier to be present in ${ctx.routeId} for export ${EXPORT_NAME}`
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
if (identifier.name === "createFileRoute" && ctx.lazy) {
|
|
86
|
-
identifier.name = "createLazyFileRoute";
|
|
87
|
-
appliedChanges = true;
|
|
88
|
-
} else if (identifier.name === "createLazyFileRoute" && !ctx.lazy) {
|
|
89
|
-
identifier.name = "createFileRoute";
|
|
90
|
-
appliedChanges = true;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return appliedChanges;
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
exports.defaultTransformPlugin = defaultTransformPlugin;
|
|
97
|
-
//# sourceMappingURL=default-transform-plugin.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"default-transform-plugin.cjs","sources":["../../../src/transform/default-transform-plugin.ts"],"sourcesContent":["import { types } from 'recast'\nimport { ensureStringArgument } from './utils'\nimport type { TransformImportsConfig, TransformPlugin } from './types'\n\nconst b = types.builders\n\nconst EXPORT_NAME = 'Route'\nexport const defaultTransformPlugin: TransformPlugin = {\n name: 'default-transform',\n exportName: EXPORT_NAME,\n imports: (ctx) => {\n const imports: TransformImportsConfig = {}\n const targetModule = `@tanstack/${ctx.target}-router`\n if (ctx.verboseFileRoutes === false) {\n imports.banned = [\n {\n source: targetModule,\n specifiers: [\n { imported: 'createLazyFileRoute' },\n { imported: 'createFileRoute' },\n ],\n },\n ]\n } else {\n if (ctx.lazy) {\n imports.required = [\n {\n source: targetModule,\n specifiers: [{ imported: 'createLazyFileRoute' }],\n },\n ]\n imports.banned = [\n {\n source: targetModule,\n specifiers: [{ imported: 'createFileRoute' }],\n },\n ]\n } else {\n imports.required = [\n {\n source: targetModule,\n specifiers: [{ imported: 'createFileRoute' }],\n },\n ]\n imports.banned = [\n {\n source: targetModule,\n specifiers: [{ imported: 'createLazyFileRoute' }],\n },\n ]\n }\n }\n return imports\n },\n onExportFound: ({ decl, ctx }) => {\n let appliedChanges = false\n if (decl.init?.type === 'CallExpression') {\n const callExpression = decl.init\n let identifier: types.namedTypes.Identifier | undefined\n // `const Route = createFileRoute({ ... })`\n if (callExpression.callee.type === 'Identifier') {\n identifier = callExpression.callee\n if (ctx.verboseFileRoutes) {\n // we need to add the string literal via another CallExpression\n callExpression.callee = b.callExpression(identifier, [\n b.stringLiteral(ctx.routeId),\n ])\n appliedChanges = true\n }\n }\n // `const Route = createFileRoute('/path')({ ... })`\n else if (\n callExpression.callee.type === 'CallExpression' &&\n callExpression.callee.callee.type === 'Identifier'\n ) {\n identifier = callExpression.callee.callee\n if (!ctx.verboseFileRoutes) {\n // we need to remove the route id\n callExpression.callee = identifier\n appliedChanges = true\n } else {\n // check if the route id is correct\n appliedChanges = ensureStringArgument(\n callExpression.callee,\n ctx.routeId,\n ctx.preferredQuote,\n )\n }\n }\n if (identifier === undefined) {\n throw new Error(\n `expected identifier to be present in ${ctx.routeId} for export ${EXPORT_NAME}`,\n )\n }\n if (identifier.name === 'createFileRoute' && ctx.lazy) {\n identifier.name = 'createLazyFileRoute'\n appliedChanges = true\n } else if (identifier.name === 'createLazyFileRoute' && !ctx.lazy) {\n identifier.name = 'createFileRoute'\n appliedChanges = true\n }\n }\n\n return appliedChanges\n },\n}\n"],"names":["types","ensureStringArgument"],"mappings":";;;;AAIA,MAAM,IAAIA,OAAAA,MAAM;AAEhB,MAAM,cAAc;AACb,MAAM,yBAA0C;AAAA,EACrD,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,SAAS,CAAC,QAAQ;AAChB,UAAM,UAAkC,CAAA;AACxC,UAAM,eAAe,aAAa,IAAI,MAAM;AAC5C,QAAI,IAAI,sBAAsB,OAAO;AACnC,cAAQ,SAAS;AAAA,QACf;AAAA,UACE,QAAQ;AAAA,UACR,YAAY;AAAA,YACV,EAAE,UAAU,sBAAA;AAAA,YACZ,EAAE,UAAU,kBAAA;AAAA,UAAkB;AAAA,QAChC;AAAA,MACF;AAAA,IAEJ,OAA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,IAAI;AAAA,UACR,wCAAwC,IAAI,OAAO,eAAe,WAAW;AAAA,QAAA;AAAA,MAEjF;AACA,UAAI,WAAW,SAAS,qBAAqB,IAAI,MAAM;AACrD,mBAAW,OAAO;AAClB,yBAAiB;AAAA,MACnB,WAAW,WAAW,SAAS,yBAAyB,CAAC,IAAI,MAAM;AACjE,mBAAW,OAAO;AAClB,yBAAiB;AAAA,MACnB;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;;"}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { defaultTransformPlugin } from "../transform/default-transform-plugin.js";
|
|
2
|
-
import { checkRouteFullPathUniqueness, isRouteNodeValidForAugmentation } from "../utils.js";
|
|
3
|
-
const EXPORT_NAME = "Route";
|
|
4
|
-
function defaultGeneratorPlugin() {
|
|
5
|
-
return {
|
|
6
|
-
name: "default",
|
|
7
|
-
transformPlugin: defaultTransformPlugin,
|
|
8
|
-
imports: (opts) => {
|
|
9
|
-
const imports = [];
|
|
10
|
-
if (opts.acc.routeNodes.some((n) => n.isVirtual)) {
|
|
11
|
-
imports.push({
|
|
12
|
-
specifiers: [{ imported: "createFileRoute" }],
|
|
13
|
-
source: opts.generator.targetTemplate.fullPkg
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
if (opts.generator.config.verboseFileRoutes === false) {
|
|
17
|
-
const typeImport = {
|
|
18
|
-
specifiers: [],
|
|
19
|
-
source: opts.generator.targetTemplate.fullPkg,
|
|
20
|
-
importKind: "type"
|
|
21
|
-
};
|
|
22
|
-
if (opts.sortedRouteNodes.some(
|
|
23
|
-
(d) => isRouteNodeValidForAugmentation(d) && d._fsRouteType !== "lazy"
|
|
24
|
-
)) {
|
|
25
|
-
typeImport.specifiers.push({ imported: "CreateFileRoute" });
|
|
26
|
-
}
|
|
27
|
-
if (opts.sortedRouteNodes.some(
|
|
28
|
-
(node) => opts.acc.routePiecesByPath[node.routePath]?.lazy && isRouteNodeValidForAugmentation(node)
|
|
29
|
-
)) {
|
|
30
|
-
typeImport.specifiers.push({ imported: "CreateLazyFileRoute" });
|
|
31
|
-
}
|
|
32
|
-
if (typeImport.specifiers.length > 0) {
|
|
33
|
-
typeImport.specifiers.push({ imported: "FileRoutesByPath" });
|
|
34
|
-
imports.push(typeImport);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
const hasMatchingRouteFiles = opts.acc.routeNodes.length > 0;
|
|
38
|
-
if (hasMatchingRouteFiles) {
|
|
39
|
-
if (!opts.rootRouteNode.exports?.includes(EXPORT_NAME)) {
|
|
40
|
-
imports.push({
|
|
41
|
-
specifiers: [{ imported: "createRootRoute" }],
|
|
42
|
-
source: opts.generator.targetTemplate.fullPkg
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return imports;
|
|
47
|
-
},
|
|
48
|
-
moduleAugmentation: ({ generator }) => ({
|
|
49
|
-
module: generator.targetTemplate.fullPkg,
|
|
50
|
-
interfaceName: "FileRoutesByPath"
|
|
51
|
-
}),
|
|
52
|
-
onRouteTreesChanged: ({ routeTrees, generator }) => {
|
|
53
|
-
const routeTree = routeTrees.find(
|
|
54
|
-
(tree) => tree.exportName === EXPORT_NAME
|
|
55
|
-
);
|
|
56
|
-
if (!routeTree) {
|
|
57
|
-
throw new Error(
|
|
58
|
-
'No route tree found with export name "Route". Please ensure your routes are correctly defined.'
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
checkRouteFullPathUniqueness(
|
|
62
|
-
routeTree.sortedRouteNodes.filter(
|
|
63
|
-
(d) => d.children === void 0 && "lazy" !== d._fsRouteType && d.exports?.includes(EXPORT_NAME)
|
|
64
|
-
),
|
|
65
|
-
generator.config
|
|
66
|
-
);
|
|
67
|
-
},
|
|
68
|
-
routeModuleAugmentation: ({ routeNode }) => {
|
|
69
|
-
if (routeNode._fsRouteType === "lazy") {
|
|
70
|
-
return `const createLazyFileRoute: CreateLazyFileRoute<FileRoutesByPath['${routeNode.routePath}']['preLoaderRoute']>`;
|
|
71
|
-
} else {
|
|
72
|
-
return `const createFileRoute: CreateFileRoute<'${routeNode.routePath}',
|
|
73
|
-
FileRoutesByPath['${routeNode.routePath}']['parentRoute'],
|
|
74
|
-
FileRoutesByPath['${routeNode.routePath}']['id'],
|
|
75
|
-
FileRoutesByPath['${routeNode.routePath}']['path'],
|
|
76
|
-
FileRoutesByPath['${routeNode.routePath}']['fullPath']
|
|
77
|
-
>
|
|
78
|
-
`;
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
createRootRouteCode: () => `createRootRoute()`,
|
|
82
|
-
createVirtualRouteCode: ({ node }) => `createFileRoute('${node.routePath}')()`,
|
|
83
|
-
config: ({ sortedRouteNodes }) => {
|
|
84
|
-
const hasMatchingRouteFiles = sortedRouteNodes.length > 0;
|
|
85
|
-
return {
|
|
86
|
-
virtualRootRoute: hasMatchingRouteFiles
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
export {
|
|
92
|
-
defaultGeneratorPlugin
|
|
93
|
-
};
|
|
94
|
-
//# sourceMappingURL=default-generator-plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"default-generator-plugin.js","sources":["../../../src/plugin/default-generator-plugin.ts"],"sourcesContent":["import { defaultTransformPlugin } from '../transform/default-transform-plugin'\nimport {\n checkRouteFullPathUniqueness,\n isRouteNodeValidForAugmentation,\n} from '../utils'\nimport type { ImportDeclaration } from '../types'\nimport type { GeneratorPluginWithTransform } from './types'\n\nconst EXPORT_NAME = 'Route'\nexport function defaultGeneratorPlugin(): GeneratorPluginWithTransform {\n return {\n name: 'default',\n transformPlugin: defaultTransformPlugin,\n imports: (opts) => {\n const imports: Array<ImportDeclaration> = []\n if (opts.acc.routeNodes.some((n) => n.isVirtual)) {\n imports.push({\n specifiers: [{ imported: 'createFileRoute' }],\n source: opts.generator.targetTemplate.fullPkg,\n })\n }\n if (opts.generator.config.verboseFileRoutes === false) {\n const typeImport: ImportDeclaration = {\n specifiers: [],\n source: opts.generator.targetTemplate.fullPkg,\n importKind: 'type',\n }\n if (\n opts.sortedRouteNodes.some(\n (d) =>\n isRouteNodeValidForAugmentation(d) && d._fsRouteType !== 'lazy',\n )\n ) {\n typeImport.specifiers.push({ imported: 'CreateFileRoute' })\n }\n if (\n opts.sortedRouteNodes.some(\n (node) =>\n opts.acc.routePiecesByPath[node.routePath!]?.lazy &&\n isRouteNodeValidForAugmentation(node),\n )\n ) {\n typeImport.specifiers.push({ imported: 'CreateLazyFileRoute' })\n }\n\n if (typeImport.specifiers.length > 0) {\n typeImport.specifiers.push({ imported: 'FileRoutesByPath' })\n imports.push(typeImport)\n }\n }\n const hasMatchingRouteFiles = opts.acc.routeNodes.length > 0\n if (hasMatchingRouteFiles) {\n // needs a virtual root route\n if (!opts.rootRouteNode.exports?.includes(EXPORT_NAME)) {\n imports.push({\n specifiers: [{ imported: 'createRootRoute' }],\n source: opts.generator.targetTemplate.fullPkg,\n })\n }\n }\n return imports\n },\n moduleAugmentation: ({ generator }) => ({\n module: generator.targetTemplate.fullPkg,\n interfaceName: 'FileRoutesByPath',\n }),\n onRouteTreesChanged: ({ routeTrees, generator }) => {\n const routeTree = routeTrees.find(\n (tree) => tree.exportName === EXPORT_NAME,\n )\n if (!routeTree) {\n throw new Error(\n 'No route tree found with export name \"Route\". Please ensure your routes are correctly defined.',\n )\n }\n checkRouteFullPathUniqueness(\n routeTree.sortedRouteNodes.filter(\n (d) =>\n d.children === undefined &&\n 'lazy' !== d._fsRouteType &&\n d.exports?.includes(EXPORT_NAME),\n ),\n generator.config,\n )\n },\n routeModuleAugmentation: ({ routeNode }) => {\n if (routeNode._fsRouteType === 'lazy') {\n return `const createLazyFileRoute: CreateLazyFileRoute<FileRoutesByPath['${routeNode.routePath}']['preLoaderRoute']>`\n } else {\n return `const createFileRoute: CreateFileRoute<'${routeNode.routePath}',\n FileRoutesByPath['${routeNode.routePath}']['parentRoute'],\n FileRoutesByPath['${routeNode.routePath}']['id'],\n FileRoutesByPath['${routeNode.routePath}']['path'],\n FileRoutesByPath['${routeNode.routePath}']['fullPath']\n >\n `\n }\n },\n createRootRouteCode: () => `createRootRoute()`,\n createVirtualRouteCode: ({ node }) =>\n `createFileRoute('${node.routePath}')()`,\n config: ({ sortedRouteNodes }) => {\n const hasMatchingRouteFiles = sortedRouteNodes.length > 0\n return {\n virtualRootRoute: hasMatchingRouteFiles,\n }\n },\n }\n}\n"],"names":[],"mappings":";;AAQA,MAAM,cAAc;AACb,SAAS,yBAAuD;AACrE,SAAO;AAAA,IACL,MAAM;AAAA,IACN,iBAAiB;AAAA,IACjB,SAAS,CAAC,SAAS;AACjB,YAAM,UAAoC,CAAA;AAC1C,UAAI,KAAK,IAAI,WAAW,KAAK,CAAC,MAAM,EAAE,SAAS,GAAG;AAChD,gBAAQ,KAAK;AAAA,UACX,YAAY,CAAC,EAAE,UAAU,mBAAmB;AAAA,UAC5C,QAAQ,KAAK,UAAU,eAAe;AAAA,QAAA,CACvC;AAAA,MACH;AACA,UAAI,KAAK,UAAU,OAAO,sBAAsB,OAAO;AACrD,cAAM,aAAgC;AAAA,UACpC,YAAY,CAAA;AAAA,UACZ,QAAQ,KAAK,UAAU,eAAe;AAAA,UACtC,YAAY;AAAA,QAAA;AAEd,YACE,KAAK,iBAAiB;AAAA,UACpB,CAAC,MACC,gCAAgC,CAAC,KAAK,EAAE,iBAAiB;AAAA,QAAA,GAE7D;AACA,qBAAW,WAAW,KAAK,EAAE,UAAU,mBAAmB;AAAA,QAC5D;AACA,YACE,KAAK,iBAAiB;AAAA,UACpB,CAAC,SACC,KAAK,IAAI,kBAAkB,KAAK,SAAU,GAAG,QAC7C,gCAAgC,IAAI;AAAA,QAAA,GAExC;AACA,qBAAW,WAAW,KAAK,EAAE,UAAU,uBAAuB;AAAA,QAChE;AAEA,YAAI,WAAW,WAAW,SAAS,GAAG;AACpC,qBAAW,WAAW,KAAK,EAAE,UAAU,oBAAoB;AAC3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AAwB,iBAAiB,SAAS;AACxD,aAAO;AAAA,QACL,kBAAkB;AAAA,MAAA;AAAA,IAEtB;AAAA,EAAA;AAEJ;"}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { types } from "recast";
|
|
2
|
-
import { ensureStringArgument } from "./utils.js";
|
|
3
|
-
const b = types.builders;
|
|
4
|
-
const EXPORT_NAME = "Route";
|
|
5
|
-
const defaultTransformPlugin = {
|
|
6
|
-
name: "default-transform",
|
|
7
|
-
exportName: EXPORT_NAME,
|
|
8
|
-
imports: (ctx) => {
|
|
9
|
-
const imports = {};
|
|
10
|
-
const targetModule = `@tanstack/${ctx.target}-router`;
|
|
11
|
-
if (ctx.verboseFileRoutes === false) {
|
|
12
|
-
imports.banned = [
|
|
13
|
-
{
|
|
14
|
-
source: targetModule,
|
|
15
|
-
specifiers: [
|
|
16
|
-
{ imported: "createLazyFileRoute" },
|
|
17
|
-
{ imported: "createFileRoute" }
|
|
18
|
-
]
|
|
19
|
-
}
|
|
20
|
-
];
|
|
21
|
-
} else {
|
|
22
|
-
if (ctx.lazy) {
|
|
23
|
-
imports.required = [
|
|
24
|
-
{
|
|
25
|
-
source: targetModule,
|
|
26
|
-
specifiers: [{ imported: "createLazyFileRoute" }]
|
|
27
|
-
}
|
|
28
|
-
];
|
|
29
|
-
imports.banned = [
|
|
30
|
-
{
|
|
31
|
-
source: targetModule,
|
|
32
|
-
specifiers: [{ imported: "createFileRoute" }]
|
|
33
|
-
}
|
|
34
|
-
];
|
|
35
|
-
} else {
|
|
36
|
-
imports.required = [
|
|
37
|
-
{
|
|
38
|
-
source: targetModule,
|
|
39
|
-
specifiers: [{ imported: "createFileRoute" }]
|
|
40
|
-
}
|
|
41
|
-
];
|
|
42
|
-
imports.banned = [
|
|
43
|
-
{
|
|
44
|
-
source: targetModule,
|
|
45
|
-
specifiers: [{ imported: "createLazyFileRoute" }]
|
|
46
|
-
}
|
|
47
|
-
];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return imports;
|
|
51
|
-
},
|
|
52
|
-
onExportFound: ({ decl, ctx }) => {
|
|
53
|
-
let appliedChanges = false;
|
|
54
|
-
if (decl.init?.type === "CallExpression") {
|
|
55
|
-
const callExpression = decl.init;
|
|
56
|
-
let identifier;
|
|
57
|
-
if (callExpression.callee.type === "Identifier") {
|
|
58
|
-
identifier = callExpression.callee;
|
|
59
|
-
if (ctx.verboseFileRoutes) {
|
|
60
|
-
callExpression.callee = b.callExpression(identifier, [
|
|
61
|
-
b.stringLiteral(ctx.routeId)
|
|
62
|
-
]);
|
|
63
|
-
appliedChanges = true;
|
|
64
|
-
}
|
|
65
|
-
} else if (callExpression.callee.type === "CallExpression" && callExpression.callee.callee.type === "Identifier") {
|
|
66
|
-
identifier = callExpression.callee.callee;
|
|
67
|
-
if (!ctx.verboseFileRoutes) {
|
|
68
|
-
callExpression.callee = identifier;
|
|
69
|
-
appliedChanges = true;
|
|
70
|
-
} else {
|
|
71
|
-
appliedChanges = ensureStringArgument(
|
|
72
|
-
callExpression.callee,
|
|
73
|
-
ctx.routeId,
|
|
74
|
-
ctx.preferredQuote
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (identifier === void 0) {
|
|
79
|
-
throw new Error(
|
|
80
|
-
`expected identifier to be present in ${ctx.routeId} for export ${EXPORT_NAME}`
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
if (identifier.name === "createFileRoute" && ctx.lazy) {
|
|
84
|
-
identifier.name = "createLazyFileRoute";
|
|
85
|
-
appliedChanges = true;
|
|
86
|
-
} else if (identifier.name === "createLazyFileRoute" && !ctx.lazy) {
|
|
87
|
-
identifier.name = "createFileRoute";
|
|
88
|
-
appliedChanges = true;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return appliedChanges;
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
export {
|
|
95
|
-
defaultTransformPlugin
|
|
96
|
-
};
|
|
97
|
-
//# sourceMappingURL=default-transform-plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"default-transform-plugin.js","sources":["../../../src/transform/default-transform-plugin.ts"],"sourcesContent":["import { types } from 'recast'\nimport { ensureStringArgument } from './utils'\nimport type { TransformImportsConfig, TransformPlugin } from './types'\n\nconst b = types.builders\n\nconst EXPORT_NAME = 'Route'\nexport const defaultTransformPlugin: TransformPlugin = {\n name: 'default-transform',\n exportName: EXPORT_NAME,\n imports: (ctx) => {\n const imports: TransformImportsConfig = {}\n const targetModule = `@tanstack/${ctx.target}-router`\n if (ctx.verboseFileRoutes === false) {\n imports.banned = [\n {\n source: targetModule,\n specifiers: [\n { imported: 'createLazyFileRoute' },\n { imported: 'createFileRoute' },\n ],\n },\n ]\n } else {\n if (ctx.lazy) {\n imports.required = [\n {\n source: targetModule,\n specifiers: [{ imported: 'createLazyFileRoute' }],\n },\n ]\n imports.banned = [\n {\n source: targetModule,\n specifiers: [{ imported: 'createFileRoute' }],\n },\n ]\n } else {\n imports.required = [\n {\n source: targetModule,\n specifiers: [{ imported: 'createFileRoute' }],\n },\n ]\n imports.banned = [\n {\n source: targetModule,\n specifiers: [{ imported: 'createLazyFileRoute' }],\n },\n ]\n }\n }\n return imports\n },\n onExportFound: ({ decl, ctx }) => {\n let appliedChanges = false\n if (decl.init?.type === 'CallExpression') {\n const callExpression = decl.init\n let identifier: types.namedTypes.Identifier | undefined\n // `const Route = createFileRoute({ ... })`\n if (callExpression.callee.type === 'Identifier') {\n identifier = callExpression.callee\n if (ctx.verboseFileRoutes) {\n // we need to add the string literal via another CallExpression\n callExpression.callee = b.callExpression(identifier, [\n b.stringLiteral(ctx.routeId),\n ])\n appliedChanges = true\n }\n }\n // `const Route = createFileRoute('/path')({ ... })`\n else if (\n callExpression.callee.type === 'CallExpression' &&\n callExpression.callee.callee.type === 'Identifier'\n ) {\n identifier = callExpression.callee.callee\n if (!ctx.verboseFileRoutes) {\n // we need to remove the route id\n callExpression.callee = identifier\n appliedChanges = true\n } else {\n // check if the route id is correct\n appliedChanges = ensureStringArgument(\n callExpression.callee,\n ctx.routeId,\n ctx.preferredQuote,\n )\n }\n }\n if (identifier === undefined) {\n throw new Error(\n `expected identifier to be present in ${ctx.routeId} for export ${EXPORT_NAME}`,\n )\n }\n if (identifier.name === 'createFileRoute' && ctx.lazy) {\n identifier.name = 'createLazyFileRoute'\n appliedChanges = true\n } else if (identifier.name === 'createLazyFileRoute' && !ctx.lazy) {\n identifier.name = 'createFileRoute'\n appliedChanges = true\n }\n }\n\n return appliedChanges\n },\n}\n"],"names":[],"mappings":";;AAIA,MAAM,IAAI,MAAM;AAEhB,MAAM,cAAc;AACb,MAAM,yBAA0C;AAAA,EACrD,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,SAAS,CAAC,QAAQ;AAChB,UAAM,UAAkC,CAAA;AACxC,UAAM,eAAe,aAAa,IAAI,MAAM;AAC5C,QAAI,IAAI,sBAAsB,OAAO;AACnC,cAAQ,SAAS;AAAA,QACf;AAAA,UACE,QAAQ;AAAA,UACR,YAAY;AAAA,YACV,EAAE,UAAU,sBAAA;AAAA,YACZ,EAAE,UAAU,kBAAA;AAAA,UAAkB;AAAA,QAChC;AAAA,MACF;AAAA,IAEJ,OAAO;AACL,UAAI,IAAI,MAAM;AACZ,gBAAQ,WAAW;AAAA,UACjB;AAAA,YACE,QAAQ;AAAA,YACR,YAAY,CAAC,EAAE,UAAU,uBAAuB;AAAA,UAAA;AAAA,QAClD;AAEF,gBAAQ,SAAS;AAAA,UACf;AAAA,YACE,QAAQ;AAAA,YACR,YAAY,CAAC,EAAE,UAAU,mBAAmB;AAAA,UAAA;AAAA,QAC9C;AAAA,MAEJ,OAAO;AACL,gBAAQ,WAAW;AAAA,UACjB;AAAA,YACE,QAAQ;AAAA,YACR,YAAY,CAAC,EAAE,UAAU,mBAAmB;AAAA,UAAA;AAAA,QAC9C;AAEF,gBAAQ,SAAS;AAAA,UACf;AAAA,YACE,QAAQ;AAAA,YACR,YAAY,CAAC,EAAE,UAAU,uBAAuB;AAAA,UAAA;AAAA,QAClD;AAAA,MAEJ;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EACA,eAAe,CAAC,EAAE,MAAM,UAAU;AAChC,QAAI,iBAAiB;AACrB,QAAI,KAAK,MAAM,SAAS,kBAAkB;AACxC,YAAM,iBAAiB,KAAK;AAC5B,UAAI;AAEJ,UAAI,eAAe,OAAO,SAAS,cAAc;AAC/C,qBAAa,eAAe;AAC5B,YAAI,IAAI,mBAAmB;AAEzB,yBAAe,SAAS,EAAE,eAAe,YAAY;AAAA,YACnD,EAAE,cAAc,IAAI,OAAO;AAAA,UAAA,CAC5B;AACD,2BAAiB;AAAA,QACnB;AAAA,MACF,WAGE,eAAe,OAAO,SAAS,oBAC/B,eAAe,OAAO,OAAO,SAAS,cACtC;AACA,qBAAa,eAAe,OAAO;AACnC,YAAI,CAAC,IAAI,mBAAmB;AAE1B,yBAAe,SAAS;AACxB,2BAAiB;AAAA,QACnB,OAAO;AAEL,2BAAiB;AAAA,YACf,eAAe;AAAA,YACf,IAAI;AAAA,YACJ,IAAI;AAAA,UAAA;AAAA,QAER;AAAA,MACF;AACA,UAAI,eAAe,QAAW;AAC5B,cAAM,IAAI;AAAA,UACR,wCAAwC,IAAI,OAAO,eAAe,WAAW;AAAA,QAAA;AAAA,MAEjF;AACA,UAAI,WAAW,SAAS,qBAAqB,IAAI,MAAM;AACrD,mBAAW,OAAO;AAClB,yBAAiB;AAAA,MACnB,WAAW,WAAW,SAAS,yBAAyB,CAAC,IAAI,MAAM;AACjE,mBAAW,OAAO;AAClB,yBAAiB;AAAA,MACnB;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;"}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { defaultTransformPlugin } from '../transform/default-transform-plugin'
|
|
2
|
-
import {
|
|
3
|
-
checkRouteFullPathUniqueness,
|
|
4
|
-
isRouteNodeValidForAugmentation,
|
|
5
|
-
} from '../utils'
|
|
6
|
-
import type { ImportDeclaration } from '../types'
|
|
7
|
-
import type { GeneratorPluginWithTransform } from './types'
|
|
8
|
-
|
|
9
|
-
const EXPORT_NAME = 'Route'
|
|
10
|
-
export function defaultGeneratorPlugin(): GeneratorPluginWithTransform {
|
|
11
|
-
return {
|
|
12
|
-
name: 'default',
|
|
13
|
-
transformPlugin: defaultTransformPlugin,
|
|
14
|
-
imports: (opts) => {
|
|
15
|
-
const imports: Array<ImportDeclaration> = []
|
|
16
|
-
if (opts.acc.routeNodes.some((n) => n.isVirtual)) {
|
|
17
|
-
imports.push({
|
|
18
|
-
specifiers: [{ imported: 'createFileRoute' }],
|
|
19
|
-
source: opts.generator.targetTemplate.fullPkg,
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
if (opts.generator.config.verboseFileRoutes === false) {
|
|
23
|
-
const typeImport: ImportDeclaration = {
|
|
24
|
-
specifiers: [],
|
|
25
|
-
source: opts.generator.targetTemplate.fullPkg,
|
|
26
|
-
importKind: 'type',
|
|
27
|
-
}
|
|
28
|
-
if (
|
|
29
|
-
opts.sortedRouteNodes.some(
|
|
30
|
-
(d) =>
|
|
31
|
-
isRouteNodeValidForAugmentation(d) && d._fsRouteType !== 'lazy',
|
|
32
|
-
)
|
|
33
|
-
) {
|
|
34
|
-
typeImport.specifiers.push({ imported: 'CreateFileRoute' })
|
|
35
|
-
}
|
|
36
|
-
if (
|
|
37
|
-
opts.sortedRouteNodes.some(
|
|
38
|
-
(node) =>
|
|
39
|
-
opts.acc.routePiecesByPath[node.routePath!]?.lazy &&
|
|
40
|
-
isRouteNodeValidForAugmentation(node),
|
|
41
|
-
)
|
|
42
|
-
) {
|
|
43
|
-
typeImport.specifiers.push({ imported: 'CreateLazyFileRoute' })
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (typeImport.specifiers.length > 0) {
|
|
47
|
-
typeImport.specifiers.push({ imported: 'FileRoutesByPath' })
|
|
48
|
-
imports.push(typeImport)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
const hasMatchingRouteFiles = opts.acc.routeNodes.length > 0
|
|
52
|
-
if (hasMatchingRouteFiles) {
|
|
53
|
-
// needs a virtual root route
|
|
54
|
-
if (!opts.rootRouteNode.exports?.includes(EXPORT_NAME)) {
|
|
55
|
-
imports.push({
|
|
56
|
-
specifiers: [{ imported: 'createRootRoute' }],
|
|
57
|
-
source: opts.generator.targetTemplate.fullPkg,
|
|
58
|
-
})
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return imports
|
|
62
|
-
},
|
|
63
|
-
moduleAugmentation: ({ generator }) => ({
|
|
64
|
-
module: generator.targetTemplate.fullPkg,
|
|
65
|
-
interfaceName: 'FileRoutesByPath',
|
|
66
|
-
}),
|
|
67
|
-
onRouteTreesChanged: ({ routeTrees, generator }) => {
|
|
68
|
-
const routeTree = routeTrees.find(
|
|
69
|
-
(tree) => tree.exportName === EXPORT_NAME,
|
|
70
|
-
)
|
|
71
|
-
if (!routeTree) {
|
|
72
|
-
throw new Error(
|
|
73
|
-
'No route tree found with export name "Route". Please ensure your routes are correctly defined.',
|
|
74
|
-
)
|
|
75
|
-
}
|
|
76
|
-
checkRouteFullPathUniqueness(
|
|
77
|
-
routeTree.sortedRouteNodes.filter(
|
|
78
|
-
(d) =>
|
|
79
|
-
d.children === undefined &&
|
|
80
|
-
'lazy' !== d._fsRouteType &&
|
|
81
|
-
d.exports?.includes(EXPORT_NAME),
|
|
82
|
-
),
|
|
83
|
-
generator.config,
|
|
84
|
-
)
|
|
85
|
-
},
|
|
86
|
-
routeModuleAugmentation: ({ routeNode }) => {
|
|
87
|
-
if (routeNode._fsRouteType === 'lazy') {
|
|
88
|
-
return `const createLazyFileRoute: CreateLazyFileRoute<FileRoutesByPath['${routeNode.routePath}']['preLoaderRoute']>`
|
|
89
|
-
} else {
|
|
90
|
-
return `const createFileRoute: CreateFileRoute<'${routeNode.routePath}',
|
|
91
|
-
FileRoutesByPath['${routeNode.routePath}']['parentRoute'],
|
|
92
|
-
FileRoutesByPath['${routeNode.routePath}']['id'],
|
|
93
|
-
FileRoutesByPath['${routeNode.routePath}']['path'],
|
|
94
|
-
FileRoutesByPath['${routeNode.routePath}']['fullPath']
|
|
95
|
-
>
|
|
96
|
-
`
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
createRootRouteCode: () => `createRootRoute()`,
|
|
100
|
-
createVirtualRouteCode: ({ node }) =>
|
|
101
|
-
`createFileRoute('${node.routePath}')()`,
|
|
102
|
-
config: ({ sortedRouteNodes }) => {
|
|
103
|
-
const hasMatchingRouteFiles = sortedRouteNodes.length > 0
|
|
104
|
-
return {
|
|
105
|
-
virtualRootRoute: hasMatchingRouteFiles,
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
}
|
|
109
|
-
}
|