@tanstack/router-plugin 1.166.9 → 1.166.11
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/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/cjs/core/code-splitter/compilers.cjs +866 -1324
- package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/framework-options.cjs +39 -41
- package/dist/cjs/core/code-splitter/framework-options.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/path-ids.cjs +26 -31
- package/dist/cjs/core/code-splitter/path-ids.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/plugins/framework-plugins.cjs +11 -14
- package/dist/cjs/core/code-splitter/plugins/framework-plugins.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/plugins/react-refresh-route-components.cjs +31 -65
- package/dist/cjs/core/code-splitter/plugins/react-refresh-route-components.cjs.map +1 -1
- package/dist/cjs/core/config.cjs +36 -46
- package/dist/cjs/core/config.cjs.map +1 -1
- package/dist/cjs/core/constants.cjs +16 -15
- package/dist/cjs/core/constants.cjs.map +1 -1
- package/dist/cjs/core/route-autoimport-plugin.cjs +81 -115
- package/dist/cjs/core/route-autoimport-plugin.cjs.map +1 -1
- package/dist/cjs/core/route-hmr-statement.cjs +34 -56
- package/dist/cjs/core/route-hmr-statement.cjs.map +1 -1
- package/dist/cjs/core/router-code-splitter-plugin.cjs +236 -306
- package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-composed-plugin.cjs +28 -34
- package/dist/cjs/core/router-composed-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-generator-plugin.cjs +101 -133
- package/dist/cjs/core/router-generator-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-hmr-plugin.cjs +81 -81
- package/dist/cjs/core/router-hmr-plugin.cjs.map +1 -1
- package/dist/cjs/core/utils.cjs +23 -30
- package/dist/cjs/core/utils.cjs.map +1 -1
- package/dist/cjs/esbuild.cjs +47 -18
- package/dist/cjs/esbuild.cjs.map +1 -1
- package/dist/cjs/index.cjs +11 -13
- package/dist/cjs/rspack.cjs +58 -19
- package/dist/cjs/rspack.cjs.map +1 -1
- package/dist/cjs/vite.cjs +52 -20
- package/dist/cjs/vite.cjs.map +1 -1
- package/dist/cjs/webpack.cjs +46 -19
- package/dist/cjs/webpack.cjs.map +1 -1
- package/dist/esm/core/code-splitter/compilers.js +859 -1307
- package/dist/esm/core/code-splitter/compilers.js.map +1 -1
- package/dist/esm/core/code-splitter/framework-options.js +40 -42
- package/dist/esm/core/code-splitter/framework-options.js.map +1 -1
- package/dist/esm/core/code-splitter/path-ids.js +27 -33
- package/dist/esm/core/code-splitter/path-ids.js.map +1 -1
- package/dist/esm/core/code-splitter/plugins/framework-plugins.js +11 -14
- package/dist/esm/core/code-splitter/plugins/framework-plugins.js.map +1 -1
- package/dist/esm/core/code-splitter/plugins/react-refresh-route-components.js +29 -48
- package/dist/esm/core/code-splitter/plugins/react-refresh-route-components.js.map +1 -1
- package/dist/esm/core/config.js +35 -48
- package/dist/esm/core/config.js.map +1 -1
- package/dist/esm/core/constants.js +17 -19
- package/dist/esm/core/constants.js.map +1 -1
- package/dist/esm/core/route-autoimport-plugin.js +78 -98
- package/dist/esm/core/route-autoimport-plugin.js.map +1 -1
- package/dist/esm/core/route-hmr-statement.js +32 -39
- package/dist/esm/core/route-hmr-statement.js.map +1 -1
- package/dist/esm/core/router-code-splitter-plugin.js +234 -305
- package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
- package/dist/esm/core/router-composed-plugin.js +25 -32
- package/dist/esm/core/router-composed-plugin.js.map +1 -1
- package/dist/esm/core/router-generator-plugin.js +100 -111
- package/dist/esm/core/router-generator-plugin.js.map +1 -1
- package/dist/esm/core/router-hmr-plugin.js +79 -80
- package/dist/esm/core/router-hmr-plugin.js.map +1 -1
- package/dist/esm/core/utils.js +21 -15
- package/dist/esm/core/utils.js.map +1 -1
- package/dist/esm/esbuild.js +37 -18
- package/dist/esm/esbuild.js.map +1 -1
- package/dist/esm/index.js +2 -11
- package/dist/esm/rspack.js +49 -20
- package/dist/esm/rspack.js.map +1 -1
- package/dist/esm/vite.js +42 -21
- package/dist/esm/vite.js.map +1 -1
- package/dist/esm/webpack.js +37 -20
- package/dist/esm/webpack.js.map +1 -1
- package/package.json +6 -6
- package/src/core/code-splitter/compilers.ts +1 -1
- package/src/core/route-autoimport-plugin.ts +1 -1
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/esm/index.js.map +0 -1
|
@@ -1,37 +1,31 @@
|
|
|
1
|
+
//#region src/core/code-splitter/path-ids.ts
|
|
1
2
|
function createIdentifier(strings) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
safeString = safeString.replace(/=/g, "--equals--");
|
|
14
|
-
safeString = safeString.replace(/&/g, "--ampersand--");
|
|
15
|
-
safeString = safeString.replace(/\s/g, "_");
|
|
16
|
-
return safeString;
|
|
3
|
+
if (strings.length === 0) throw new Error("Cannot create an identifier from an empty array");
|
|
4
|
+
let safeString = [...strings].sort().join("---").replace(/\//g, "--slash--");
|
|
5
|
+
safeString = safeString.replace(/\\/g, "--backslash--");
|
|
6
|
+
safeString = safeString.replace(/\?/g, "--question--");
|
|
7
|
+
safeString = safeString.replace(/%/g, "--percent--");
|
|
8
|
+
safeString = safeString.replace(/#/g, "--hash--");
|
|
9
|
+
safeString = safeString.replace(/\+/g, "--plus--");
|
|
10
|
+
safeString = safeString.replace(/=/g, "--equals--");
|
|
11
|
+
safeString = safeString.replace(/&/g, "--ampersand--");
|
|
12
|
+
safeString = safeString.replace(/\s/g, "_");
|
|
13
|
+
return safeString;
|
|
17
14
|
}
|
|
18
15
|
function decodeIdentifier(identifier) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
combinedString = combinedString.replace(/_/g, " ");
|
|
31
|
-
return combinedString.split("---");
|
|
16
|
+
if (!identifier) return [];
|
|
17
|
+
let combinedString = identifier.replace(/--slash--/g, "/");
|
|
18
|
+
combinedString = combinedString.replace(/--backslash--/g, "\\");
|
|
19
|
+
combinedString = combinedString.replace(/--question--/g, "?");
|
|
20
|
+
combinedString = combinedString.replace(/--percent--/g, "%");
|
|
21
|
+
combinedString = combinedString.replace(/--hash--/g, "#");
|
|
22
|
+
combinedString = combinedString.replace(/--plus--/g, "+");
|
|
23
|
+
combinedString = combinedString.replace(/--equals--/g, "=");
|
|
24
|
+
combinedString = combinedString.replace(/--ampersand--/g, "&");
|
|
25
|
+
combinedString = combinedString.replace(/_/g, " ");
|
|
26
|
+
return combinedString.split("---");
|
|
32
27
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
//# sourceMappingURL=path-ids.js.map
|
|
28
|
+
//#endregion
|
|
29
|
+
export { createIdentifier, decodeIdentifier };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=path-ids.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path-ids.js","sources":["../../../../src/core/code-splitter/path-ids.ts"],"sourcesContent":["export function createIdentifier(strings: Array<string>): string {\n if (strings.length === 0) {\n throw new Error('Cannot create an identifier from an empty array')\n }\n\n const sortedStrings = [...strings].sort()\n const combinedString = sortedStrings.join('---') // Delimiter\n\n // Replace unsafe characters\n let safeString = combinedString.replace(/\\//g, '--slash--')\n safeString = safeString.replace(/\\\\/g, '--backslash--')\n safeString = safeString.replace(/\\?/g, '--question--')\n safeString = safeString.replace(/%/g, '--percent--')\n safeString = safeString.replace(/#/g, '--hash--')\n safeString = safeString.replace(/\\+/g, '--plus--')\n safeString = safeString.replace(/=/g, '--equals--')\n safeString = safeString.replace(/&/g, '--ampersand--')\n safeString = safeString.replace(/\\s/g, '_') // Replace spaces with underscores\n\n return safeString\n}\n\nexport function decodeIdentifier(identifier: string): Array<string> {\n if (!identifier) {\n return []\n }\n\n let combinedString = identifier.replace(/--slash--/g, '/')\n combinedString = combinedString.replace(/--backslash--/g, '\\\\')\n combinedString = combinedString.replace(/--question--/g, '?')\n combinedString = combinedString.replace(/--percent--/g, '%')\n combinedString = combinedString.replace(/--hash--/g, '#')\n combinedString = combinedString.replace(/--plus--/g, '+')\n combinedString = combinedString.replace(/--equals--/g, '=')\n combinedString = combinedString.replace(/--ampersand--/g, '&')\n combinedString = combinedString.replace(/_/g, ' ') // Restore spaces\n\n return combinedString.split('---')\n}\n"],"
|
|
1
|
+
{"version":3,"file":"path-ids.js","names":[],"sources":["../../../../src/core/code-splitter/path-ids.ts"],"sourcesContent":["export function createIdentifier(strings: Array<string>): string {\n if (strings.length === 0) {\n throw new Error('Cannot create an identifier from an empty array')\n }\n\n const sortedStrings = [...strings].sort()\n const combinedString = sortedStrings.join('---') // Delimiter\n\n // Replace unsafe characters\n let safeString = combinedString.replace(/\\//g, '--slash--')\n safeString = safeString.replace(/\\\\/g, '--backslash--')\n safeString = safeString.replace(/\\?/g, '--question--')\n safeString = safeString.replace(/%/g, '--percent--')\n safeString = safeString.replace(/#/g, '--hash--')\n safeString = safeString.replace(/\\+/g, '--plus--')\n safeString = safeString.replace(/=/g, '--equals--')\n safeString = safeString.replace(/&/g, '--ampersand--')\n safeString = safeString.replace(/\\s/g, '_') // Replace spaces with underscores\n\n return safeString\n}\n\nexport function decodeIdentifier(identifier: string): Array<string> {\n if (!identifier) {\n return []\n }\n\n let combinedString = identifier.replace(/--slash--/g, '/')\n combinedString = combinedString.replace(/--backslash--/g, '\\\\')\n combinedString = combinedString.replace(/--question--/g, '?')\n combinedString = combinedString.replace(/--percent--/g, '%')\n combinedString = combinedString.replace(/--hash--/g, '#')\n combinedString = combinedString.replace(/--plus--/g, '+')\n combinedString = combinedString.replace(/--equals--/g, '=')\n combinedString = combinedString.replace(/--ampersand--/g, '&')\n combinedString = combinedString.replace(/_/g, ' ') // Restore spaces\n\n return combinedString.split('---')\n}\n"],"mappings":";AAAA,SAAgB,iBAAiB,SAAgC;AAC/D,KAAI,QAAQ,WAAW,EACrB,OAAM,IAAI,MAAM,kDAAkD;CAOpE,IAAI,aAJkB,CAAC,GAAG,QAAQ,CAAC,MAAM,CACJ,KAAK,MAAM,CAGhB,QAAQ,OAAO,YAAY;AAC3D,cAAa,WAAW,QAAQ,OAAO,gBAAgB;AACvD,cAAa,WAAW,QAAQ,OAAO,eAAe;AACtD,cAAa,WAAW,QAAQ,MAAM,cAAc;AACpD,cAAa,WAAW,QAAQ,MAAM,WAAW;AACjD,cAAa,WAAW,QAAQ,OAAO,WAAW;AAClD,cAAa,WAAW,QAAQ,MAAM,aAAa;AACnD,cAAa,WAAW,QAAQ,MAAM,gBAAgB;AACtD,cAAa,WAAW,QAAQ,OAAO,IAAI;AAE3C,QAAO;;AAGT,SAAgB,iBAAiB,YAAmC;AAClE,KAAI,CAAC,WACH,QAAO,EAAE;CAGX,IAAI,iBAAiB,WAAW,QAAQ,cAAc,IAAI;AAC1D,kBAAiB,eAAe,QAAQ,kBAAkB,KAAK;AAC/D,kBAAiB,eAAe,QAAQ,iBAAiB,IAAI;AAC7D,kBAAiB,eAAe,QAAQ,gBAAgB,IAAI;AAC5D,kBAAiB,eAAe,QAAQ,aAAa,IAAI;AACzD,kBAAiB,eAAe,QAAQ,aAAa,IAAI;AACzD,kBAAiB,eAAe,QAAQ,eAAe,IAAI;AAC3D,kBAAiB,eAAe,QAAQ,kBAAkB,IAAI;AAC9D,kBAAiB,eAAe,QAAQ,MAAM,IAAI;AAElD,QAAO,eAAe,MAAM,MAAM"}
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { createReactRefreshRouteComponentsPlugin } from "./react-refresh-route-components.js";
|
|
2
|
+
//#region src/core/code-splitter/plugins/framework-plugins.ts
|
|
2
3
|
function getReferenceRouteCompilerPlugins(opts) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
default:
|
|
11
|
-
return void 0;
|
|
12
|
-
}
|
|
4
|
+
switch (opts.targetFramework) {
|
|
5
|
+
case "react":
|
|
6
|
+
if (opts.addHmr) return [createReactRefreshRouteComponentsPlugin()];
|
|
7
|
+
return;
|
|
8
|
+
default: return;
|
|
9
|
+
}
|
|
13
10
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=framework-plugins.js.map
|
|
11
|
+
//#endregion
|
|
12
|
+
export { getReferenceRouteCompilerPlugins };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=framework-plugins.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"framework-plugins.js","sources":["../../../../../src/core/code-splitter/plugins/framework-plugins.ts"],"sourcesContent":["import { createReactRefreshRouteComponentsPlugin } from './react-refresh-route-components'\nimport type { ReferenceRouteCompilerPlugin } from '../plugins'\nimport type { Config } from '../../config'\n\nexport function getReferenceRouteCompilerPlugins(opts: {\n targetFramework: Config['target']\n addHmr?: boolean\n}): Array<ReferenceRouteCompilerPlugin> | undefined {\n switch (opts.targetFramework) {\n case 'react': {\n if (opts.addHmr) {\n return [createReactRefreshRouteComponentsPlugin()]\n }\n return undefined\n }\n default:\n return undefined\n }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"framework-plugins.js","names":[],"sources":["../../../../../src/core/code-splitter/plugins/framework-plugins.ts"],"sourcesContent":["import { createReactRefreshRouteComponentsPlugin } from './react-refresh-route-components'\nimport type { ReferenceRouteCompilerPlugin } from '../plugins'\nimport type { Config } from '../../config'\n\nexport function getReferenceRouteCompilerPlugins(opts: {\n targetFramework: Config['target']\n addHmr?: boolean\n}): Array<ReferenceRouteCompilerPlugin> | undefined {\n switch (opts.targetFramework) {\n case 'react': {\n if (opts.addHmr) {\n return [createReactRefreshRouteComponentsPlugin()]\n }\n return undefined\n }\n default:\n return undefined\n }\n}\n"],"mappings":";;AAIA,SAAgB,iCAAiC,MAGG;AAClD,SAAQ,KAAK,iBAAb;EACE,KAAK;AACH,OAAI,KAAK,OACP,QAAO,CAAC,yCAAyC,CAAC;AAEpD;EAEF,QACE"}
|
|
@@ -1,52 +1,33 @@
|
|
|
1
|
-
import * as t from "@babel/types";
|
|
2
1
|
import { getUniqueProgramIdentifier } from "../../utils.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import * as t from "@babel/types";
|
|
3
|
+
//#region src/core/code-splitter/plugins/react-refresh-route-components.ts
|
|
4
|
+
var REACT_REFRESH_ROUTE_COMPONENT_IDENTS = new Set([
|
|
5
|
+
"component",
|
|
6
|
+
"pendingComponent",
|
|
7
|
+
"errorComponent",
|
|
8
|
+
"notFoundComponent"
|
|
8
9
|
]);
|
|
9
10
|
function createReactRefreshRouteComponentsPlugin() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
ctx.programPath,
|
|
29
|
-
`TSR${prop.key.name[0].toUpperCase()}${prop.key.name.slice(1)}`
|
|
30
|
-
);
|
|
31
|
-
hoistedDeclarations.push(
|
|
32
|
-
t.variableDeclaration("const", [
|
|
33
|
-
t.variableDeclarator(
|
|
34
|
-
hoistedIdentifier,
|
|
35
|
-
t.cloneNode(prop.value, true)
|
|
36
|
-
)
|
|
37
|
-
])
|
|
38
|
-
);
|
|
39
|
-
prop.value = t.cloneNode(hoistedIdentifier);
|
|
40
|
-
});
|
|
41
|
-
if (hoistedDeclarations.length === 0) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
ctx.insertionPath.insertBefore(hoistedDeclarations);
|
|
45
|
-
return { modified: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
11
|
+
return {
|
|
12
|
+
name: "react-refresh-route-components",
|
|
13
|
+
onUnsplittableRoute(ctx) {
|
|
14
|
+
if (!ctx.opts.addHmr) return;
|
|
15
|
+
const hoistedDeclarations = [];
|
|
16
|
+
ctx.routeOptions.properties.forEach((prop) => {
|
|
17
|
+
if (!t.isObjectProperty(prop) || !t.isIdentifier(prop.key)) return;
|
|
18
|
+
if (!REACT_REFRESH_ROUTE_COMPONENT_IDENTS.has(prop.key.name)) return;
|
|
19
|
+
if (!t.isArrowFunctionExpression(prop.value) && !t.isFunctionExpression(prop.value)) return;
|
|
20
|
+
const hoistedIdentifier = getUniqueProgramIdentifier(ctx.programPath, `TSR${prop.key.name[0].toUpperCase()}${prop.key.name.slice(1)}`);
|
|
21
|
+
hoistedDeclarations.push(t.variableDeclaration("const", [t.variableDeclarator(hoistedIdentifier, t.cloneNode(prop.value, true))]));
|
|
22
|
+
prop.value = t.cloneNode(hoistedIdentifier);
|
|
23
|
+
});
|
|
24
|
+
if (hoistedDeclarations.length === 0) return;
|
|
25
|
+
ctx.insertionPath.insertBefore(hoistedDeclarations);
|
|
26
|
+
return { modified: true };
|
|
27
|
+
}
|
|
28
|
+
};
|
|
48
29
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
//# sourceMappingURL=react-refresh-route-components.js.map
|
|
30
|
+
//#endregion
|
|
31
|
+
export { createReactRefreshRouteComponentsPlugin };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=react-refresh-route-components.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-refresh-route-components.js","sources":["../../../../../src/core/code-splitter/plugins/react-refresh-route-components.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport { getUniqueProgramIdentifier } from '../../utils'\nimport type { ReferenceRouteCompilerPlugin } from '../plugins'\n\nconst REACT_REFRESH_ROUTE_COMPONENT_IDENTS = new Set([\n 'component',\n 'pendingComponent',\n 'errorComponent',\n 'notFoundComponent',\n])\n\nexport function createReactRefreshRouteComponentsPlugin(): ReferenceRouteCompilerPlugin {\n return {\n name: 'react-refresh-route-components',\n onUnsplittableRoute(ctx) {\n if (!ctx.opts.addHmr) {\n return\n }\n\n const hoistedDeclarations: Array<t.VariableDeclaration> = []\n\n ctx.routeOptions.properties.forEach((prop) => {\n if (!t.isObjectProperty(prop) || !t.isIdentifier(prop.key)) {\n return\n }\n\n if (!REACT_REFRESH_ROUTE_COMPONENT_IDENTS.has(prop.key.name)) {\n return\n }\n\n if (\n !t.isArrowFunctionExpression(prop.value) &&\n !t.isFunctionExpression(prop.value)\n ) {\n return\n }\n\n const hoistedIdentifier = getUniqueProgramIdentifier(\n ctx.programPath,\n `TSR${prop.key.name[0]!.toUpperCase()}${prop.key.name.slice(1)}`,\n )\n\n hoistedDeclarations.push(\n t.variableDeclaration('const', [\n t.variableDeclarator(\n hoistedIdentifier,\n t.cloneNode(prop.value, true),\n ),\n ]),\n )\n\n prop.value = t.cloneNode(hoistedIdentifier)\n })\n\n if (hoistedDeclarations.length === 0) {\n return\n }\n\n ctx.insertionPath.insertBefore(hoistedDeclarations)\n return { modified: true }\n },\n }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"react-refresh-route-components.js","names":[],"sources":["../../../../../src/core/code-splitter/plugins/react-refresh-route-components.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport { getUniqueProgramIdentifier } from '../../utils'\nimport type { ReferenceRouteCompilerPlugin } from '../plugins'\n\nconst REACT_REFRESH_ROUTE_COMPONENT_IDENTS = new Set([\n 'component',\n 'pendingComponent',\n 'errorComponent',\n 'notFoundComponent',\n])\n\nexport function createReactRefreshRouteComponentsPlugin(): ReferenceRouteCompilerPlugin {\n return {\n name: 'react-refresh-route-components',\n onUnsplittableRoute(ctx) {\n if (!ctx.opts.addHmr) {\n return\n }\n\n const hoistedDeclarations: Array<t.VariableDeclaration> = []\n\n ctx.routeOptions.properties.forEach((prop) => {\n if (!t.isObjectProperty(prop) || !t.isIdentifier(prop.key)) {\n return\n }\n\n if (!REACT_REFRESH_ROUTE_COMPONENT_IDENTS.has(prop.key.name)) {\n return\n }\n\n if (\n !t.isArrowFunctionExpression(prop.value) &&\n !t.isFunctionExpression(prop.value)\n ) {\n return\n }\n\n const hoistedIdentifier = getUniqueProgramIdentifier(\n ctx.programPath,\n `TSR${prop.key.name[0]!.toUpperCase()}${prop.key.name.slice(1)}`,\n )\n\n hoistedDeclarations.push(\n t.variableDeclaration('const', [\n t.variableDeclarator(\n hoistedIdentifier,\n t.cloneNode(prop.value, true),\n ),\n ]),\n )\n\n prop.value = t.cloneNode(hoistedIdentifier)\n })\n\n if (hoistedDeclarations.length === 0) {\n return\n }\n\n ctx.insertionPath.insertBefore(hoistedDeclarations)\n return { modified: true }\n },\n }\n}\n"],"mappings":";;;AAIA,IAAM,uCAAuC,IAAI,IAAI;CACnD;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAgB,0CAAwE;AACtF,QAAO;EACL,MAAM;EACN,oBAAoB,KAAK;AACvB,OAAI,CAAC,IAAI,KAAK,OACZ;GAGF,MAAM,sBAAoD,EAAE;AAE5D,OAAI,aAAa,WAAW,SAAS,SAAS;AAC5C,QAAI,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC,EAAE,aAAa,KAAK,IAAI,CACxD;AAGF,QAAI,CAAC,qCAAqC,IAAI,KAAK,IAAI,KAAK,CAC1D;AAGF,QACE,CAAC,EAAE,0BAA0B,KAAK,MAAM,IACxC,CAAC,EAAE,qBAAqB,KAAK,MAAM,CAEnC;IAGF,MAAM,oBAAoB,2BACxB,IAAI,aACJ,MAAM,KAAK,IAAI,KAAK,GAAI,aAAa,GAAG,KAAK,IAAI,KAAK,MAAM,EAAE,GAC/D;AAED,wBAAoB,KAClB,EAAE,oBAAoB,SAAS,CAC7B,EAAE,mBACA,mBACA,EAAE,UAAU,KAAK,OAAO,KAAK,CAC9B,CACF,CAAC,CACH;AAED,SAAK,QAAQ,EAAE,UAAU,kBAAkB;KAC3C;AAEF,OAAI,oBAAoB,WAAW,EACjC;AAGF,OAAI,cAAc,aAAa,oBAAoB;AACnD,UAAO,EAAE,UAAU,MAAM;;EAE5B"}
|
package/dist/esm/core/config.js
CHANGED
|
@@ -1,53 +1,40 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
).superRefine((val, ctx) => {
|
|
17
|
-
const flattened = val.flat();
|
|
18
|
-
const unique = [...new Set(flattened)];
|
|
19
|
-
if (unique.length !== flattened.length) {
|
|
20
|
-
ctx.addIssue({
|
|
21
|
-
code: "custom",
|
|
22
|
-
message: ` Split groupings must be unique and not repeated. i.e. i.e. [['component'], ['pendingComponent'], ['errorComponent', 'notFoundComponent']].
|
|
23
|
-
You input was: ${JSON.stringify(val)}.`
|
|
24
|
-
});
|
|
25
|
-
}
|
|
2
|
+
import { configSchema, getConfig } from "@tanstack/router-generator";
|
|
3
|
+
//#region src/core/config.ts
|
|
4
|
+
var splitGroupingsSchema = z.array(z.array(z.union([
|
|
5
|
+
z.literal("loader"),
|
|
6
|
+
z.literal("component"),
|
|
7
|
+
z.literal("pendingComponent"),
|
|
8
|
+
z.literal("errorComponent"),
|
|
9
|
+
z.literal("notFoundComponent")
|
|
10
|
+
])), { message: " Must be an Array of Arrays containing the split groupings. i.e. [['component'], ['pendingComponent'], ['errorComponent', 'notFoundComponent']]" }).superRefine((val, ctx) => {
|
|
11
|
+
const flattened = val.flat();
|
|
12
|
+
if ([...new Set(flattened)].length !== flattened.length) ctx.addIssue({
|
|
13
|
+
code: "custom",
|
|
14
|
+
message: ` Split groupings must be unique and not repeated. i.e. i.e. [['component'], ['pendingComponent'], ['errorComponent', 'notFoundComponent']].\n You input was: ${JSON.stringify(val)}.`
|
|
15
|
+
});
|
|
26
16
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
17
|
+
var codeSplittingOptionsSchema = z.object({
|
|
18
|
+
splitBehavior: z.function().optional(),
|
|
19
|
+
defaultBehavior: splitGroupingsSchema.optional(),
|
|
20
|
+
deleteNodes: z.array(z.string()).optional(),
|
|
21
|
+
addHmr: z.boolean().optional().default(true)
|
|
32
22
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
vite: z.object({
|
|
40
|
-
environmentName: z.string().optional()
|
|
41
|
-
}).optional()
|
|
42
|
-
}).optional()
|
|
23
|
+
var configSchema$1 = configSchema.extend({
|
|
24
|
+
enableRouteGeneration: z.boolean().optional(),
|
|
25
|
+
codeSplittingOptions: z.custom((v) => {
|
|
26
|
+
return codeSplittingOptionsSchema.parse(v);
|
|
27
|
+
}).optional(),
|
|
28
|
+
plugin: z.object({ vite: z.object({ environmentName: z.string().optional() }).optional() }).optional()
|
|
43
29
|
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
30
|
+
var getConfig$1 = (inlineConfig, root) => {
|
|
31
|
+
const config = getConfig(inlineConfig, root);
|
|
32
|
+
return configSchema$1.parse({
|
|
33
|
+
...inlineConfig,
|
|
34
|
+
...config
|
|
35
|
+
});
|
|
47
36
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
53
|
-
//# sourceMappingURL=config.js.map
|
|
37
|
+
//#endregion
|
|
38
|
+
export { configSchema$1 as configSchema, getConfig$1 as getConfig, splitGroupingsSchema };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sources":["../../../src/core/config.ts"],"sourcesContent":["import { z } from 'zod'\nimport {\n configSchema as generatorConfigSchema,\n getConfig as getGeneratorConfig,\n} from '@tanstack/router-generator'\nimport type {\n CreateFileRoute,\n RegisteredRouter,\n RouteIds,\n} from '@tanstack/router-core'\nimport type { CodeSplitGroupings } from './constants'\n\nexport const splitGroupingsSchema = z\n .array(\n z.array(\n z.union([\n z.literal('loader'),\n z.literal('component'),\n z.literal('pendingComponent'),\n z.literal('errorComponent'),\n z.literal('notFoundComponent'),\n ]),\n ),\n {\n message:\n \" Must be an Array of Arrays containing the split groupings. i.e. [['component'], ['pendingComponent'], ['errorComponent', 'notFoundComponent']]\",\n },\n )\n .superRefine((val, ctx) => {\n const flattened = val.flat()\n const unique = [...new Set(flattened)]\n\n // Elements must be unique,\n // ie. this shouldn't be allows [['component'], ['component', 'loader']]\n if (unique.length !== flattened.length) {\n ctx.addIssue({\n code: 'custom',\n message:\n \" Split groupings must be unique and not repeated. i.e. i.e. [['component'], ['pendingComponent'], ['errorComponent', 'notFoundComponent']].\" +\n `\\n You input was: ${JSON.stringify(val)}.`,\n })\n }\n })\n\nexport type CodeSplittingOptions = {\n /**\n * Use this function to programmatically control the code splitting behavior\n * based on the `routeId` for each route.\n *\n * If you just need to change the default behavior, you can use the `defaultBehavior` option.\n * @param params\n */\n splitBehavior?: (params: {\n routeId: RouteIds<RegisteredRouter['routeTree']>\n }) => CodeSplitGroupings | undefined | void\n\n /**\n * The default/global configuration to control your code splitting behavior per route.\n * @default [['component'],['pendingComponent'],['errorComponent'],['notFoundComponent']]\n */\n defaultBehavior?: CodeSplitGroupings\n\n /**\n * The nodes that shall be deleted from the route.\n * @default undefined\n */\n deleteNodes?: Array<DeletableNodes>\n\n /**\n * @default true\n */\n addHmr?: boolean\n}\n\nconst codeSplittingOptionsSchema = z.object({\n splitBehavior: z.function().optional(),\n defaultBehavior: splitGroupingsSchema.optional(),\n deleteNodes: z.array(z.string()).optional(),\n addHmr: z.boolean().optional().default(true),\n})\n\ntype FileRouteKeys = keyof (Parameters<\n CreateFileRoute<any, any, any, any, any>\n>[0] & {})\nexport type DeletableNodes = FileRouteKeys | (string & {})\n\nexport const configSchema = generatorConfigSchema.extend({\n enableRouteGeneration: z.boolean().optional(),\n codeSplittingOptions: z\n .custom<CodeSplittingOptions>((v) => {\n return codeSplittingOptionsSchema.parse(v)\n })\n .optional(),\n plugin: z\n .object({\n vite: z\n .object({\n environmentName: z.string().optional(),\n })\n .optional(),\n })\n .optional(),\n})\n\nexport const getConfig = (inlineConfig: Partial<Config>, root: string) => {\n const config = getGeneratorConfig(inlineConfig, root)\n\n return configSchema.parse({ ...inlineConfig, ...config })\n}\n\nexport type Config = z.infer<typeof configSchema>\nexport type ConfigInput = z.input<typeof configSchema>\nexport type ConfigOutput = z.output<typeof configSchema>\n"],"
|
|
1
|
+
{"version":3,"file":"config.js","names":[],"sources":["../../../src/core/config.ts"],"sourcesContent":["import { z } from 'zod'\nimport {\n configSchema as generatorConfigSchema,\n getConfig as getGeneratorConfig,\n} from '@tanstack/router-generator'\nimport type {\n CreateFileRoute,\n RegisteredRouter,\n RouteIds,\n} from '@tanstack/router-core'\nimport type { CodeSplitGroupings } from './constants'\n\nexport const splitGroupingsSchema = z\n .array(\n z.array(\n z.union([\n z.literal('loader'),\n z.literal('component'),\n z.literal('pendingComponent'),\n z.literal('errorComponent'),\n z.literal('notFoundComponent'),\n ]),\n ),\n {\n message:\n \" Must be an Array of Arrays containing the split groupings. i.e. [['component'], ['pendingComponent'], ['errorComponent', 'notFoundComponent']]\",\n },\n )\n .superRefine((val, ctx) => {\n const flattened = val.flat()\n const unique = [...new Set(flattened)]\n\n // Elements must be unique,\n // ie. this shouldn't be allows [['component'], ['component', 'loader']]\n if (unique.length !== flattened.length) {\n ctx.addIssue({\n code: 'custom',\n message:\n \" Split groupings must be unique and not repeated. i.e. i.e. [['component'], ['pendingComponent'], ['errorComponent', 'notFoundComponent']].\" +\n `\\n You input was: ${JSON.stringify(val)}.`,\n })\n }\n })\n\nexport type CodeSplittingOptions = {\n /**\n * Use this function to programmatically control the code splitting behavior\n * based on the `routeId` for each route.\n *\n * If you just need to change the default behavior, you can use the `defaultBehavior` option.\n * @param params\n */\n splitBehavior?: (params: {\n routeId: RouteIds<RegisteredRouter['routeTree']>\n }) => CodeSplitGroupings | undefined | void\n\n /**\n * The default/global configuration to control your code splitting behavior per route.\n * @default [['component'],['pendingComponent'],['errorComponent'],['notFoundComponent']]\n */\n defaultBehavior?: CodeSplitGroupings\n\n /**\n * The nodes that shall be deleted from the route.\n * @default undefined\n */\n deleteNodes?: Array<DeletableNodes>\n\n /**\n * @default true\n */\n addHmr?: boolean\n}\n\nconst codeSplittingOptionsSchema = z.object({\n splitBehavior: z.function().optional(),\n defaultBehavior: splitGroupingsSchema.optional(),\n deleteNodes: z.array(z.string()).optional(),\n addHmr: z.boolean().optional().default(true),\n})\n\ntype FileRouteKeys = keyof (Parameters<\n CreateFileRoute<any, any, any, any, any>\n>[0] & {})\nexport type DeletableNodes = FileRouteKeys | (string & {})\n\nexport const configSchema = generatorConfigSchema.extend({\n enableRouteGeneration: z.boolean().optional(),\n codeSplittingOptions: z\n .custom<CodeSplittingOptions>((v) => {\n return codeSplittingOptionsSchema.parse(v)\n })\n .optional(),\n plugin: z\n .object({\n vite: z\n .object({\n environmentName: z.string().optional(),\n })\n .optional(),\n })\n .optional(),\n})\n\nexport const getConfig = (inlineConfig: Partial<Config>, root: string) => {\n const config = getGeneratorConfig(inlineConfig, root)\n\n return configSchema.parse({ ...inlineConfig, ...config })\n}\n\nexport type Config = z.infer<typeof configSchema>\nexport type ConfigInput = z.input<typeof configSchema>\nexport type ConfigOutput = z.output<typeof configSchema>\n"],"mappings":";;;AAYA,IAAa,uBAAuB,EACjC,MACC,EAAE,MACA,EAAE,MAAM;CACN,EAAE,QAAQ,SAAS;CACnB,EAAE,QAAQ,YAAY;CACtB,EAAE,QAAQ,mBAAmB;CAC7B,EAAE,QAAQ,iBAAiB;CAC3B,EAAE,QAAQ,oBAAoB;CAC/B,CAAC,CACH,EACD,EACE,SACE,oJACH,CACF,CACA,aAAa,KAAK,QAAQ;CACzB,MAAM,YAAY,IAAI,MAAM;AAK5B,KAJe,CAAC,GAAG,IAAI,IAAI,UAAU,CAAC,CAI3B,WAAW,UAAU,OAC9B,KAAI,SAAS;EACX,MAAM;EACN,SACE,kKACsB,KAAK,UAAU,IAAI,CAAC;EAC7C,CAAC;EAEJ;AAgCJ,IAAM,6BAA6B,EAAE,OAAO;CAC1C,eAAe,EAAE,UAAU,CAAC,UAAU;CACtC,iBAAiB,qBAAqB,UAAU;CAChD,aAAa,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;CAC3C,QAAQ,EAAE,SAAS,CAAC,UAAU,CAAC,QAAQ,KAAK;CAC7C,CAAC;AAOF,IAAa,iBAAe,aAAsB,OAAO;CACvD,uBAAuB,EAAE,SAAS,CAAC,UAAU;CAC7C,sBAAsB,EACnB,QAA8B,MAAM;AACnC,SAAO,2BAA2B,MAAM,EAAE;GAC1C,CACD,UAAU;CACb,QAAQ,EACL,OAAO,EACN,MAAM,EACH,OAAO,EACN,iBAAiB,EAAE,QAAQ,CAAC,UAAU,EACvC,CAAC,CACD,UAAU,EACd,CAAC,CACD,UAAU;CACd,CAAC;AAEF,IAAa,eAAa,cAA+B,SAAiB;CACxE,MAAM,SAAS,UAAmB,cAAc,KAAK;AAErD,QAAO,eAAa,MAAM;EAAE,GAAG;EAAc,GAAG;EAAQ,CAAC"}
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
//#region src/core/constants.ts
|
|
2
|
+
var tsrSplit = "tsr-split";
|
|
3
|
+
var tsrShared = "tsr-shared";
|
|
4
|
+
var splitRouteIdentNodes = [
|
|
5
|
+
"loader",
|
|
6
|
+
"component",
|
|
7
|
+
"pendingComponent",
|
|
8
|
+
"errorComponent",
|
|
9
|
+
"notFoundComponent"
|
|
9
10
|
];
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
var defaultCodeSplitGroupings = [
|
|
12
|
+
["component"],
|
|
13
|
+
["errorComponent"],
|
|
14
|
+
["notFoundComponent"]
|
|
14
15
|
];
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
tsrSplit
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=constants.js.map
|
|
16
|
+
//#endregion
|
|
17
|
+
export { defaultCodeSplitGroupings, splitRouteIdentNodes, tsrShared, tsrSplit };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../../../src/core/constants.ts"],"sourcesContent":["export const tsrSplit = 'tsr-split'\nexport const tsrShared = 'tsr-shared'\n\nexport const splitRouteIdentNodes = [\n 'loader',\n 'component',\n 'pendingComponent',\n 'errorComponent',\n 'notFoundComponent',\n] as const\nexport type SplitRouteIdentNodes = (typeof splitRouteIdentNodes)[number]\nexport type CodeSplitGroupings = Array<Array<SplitRouteIdentNodes>>\n\nexport const defaultCodeSplitGroupings: CodeSplitGroupings = [\n ['component'],\n ['errorComponent'],\n ['notFoundComponent'],\n]\n"],"
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["../../../src/core/constants.ts"],"sourcesContent":["export const tsrSplit = 'tsr-split'\nexport const tsrShared = 'tsr-shared'\n\nexport const splitRouteIdentNodes = [\n 'loader',\n 'component',\n 'pendingComponent',\n 'errorComponent',\n 'notFoundComponent',\n] as const\nexport type SplitRouteIdentNodes = (typeof splitRouteIdentNodes)[number]\nexport type CodeSplitGroupings = Array<Array<SplitRouteIdentNodes>>\n\nexport const defaultCodeSplitGroupings: CodeSplitGroupings = [\n ['component'],\n ['errorComponent'],\n ['notFoundComponent'],\n]\n"],"mappings":";AAAA,IAAa,WAAW;AACxB,IAAa,YAAY;AAEzB,IAAa,uBAAuB;CAClC;CACA;CACA;CACA;CACA;CACD;AAID,IAAa,4BAAgD;CAC3D,CAAC,YAAY;CACb,CAAC,iBAAiB;CAClB,CAAC,oBAAoB;CACtB"}
|
|
@@ -1,100 +1,80 @@
|
|
|
1
|
-
import { parseAst, generateFromAst, logDiff } from "@tanstack/router-utils";
|
|
2
|
-
import babel from "@babel/core";
|
|
3
|
-
import * as template from "@babel/template";
|
|
4
1
|
import { getConfig } from "./config.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
ROOT = config.root;
|
|
80
|
-
initUserConfig();
|
|
81
|
-
},
|
|
82
|
-
// this check may only happen after config is resolved, so we use applyToEnvironment (apply is too early)
|
|
83
|
-
applyToEnvironment() {
|
|
84
|
-
return userConfig.verboseFileRoutes === false;
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
rspack() {
|
|
88
|
-
ROOT = process.cwd();
|
|
89
|
-
initUserConfig();
|
|
90
|
-
},
|
|
91
|
-
webpack() {
|
|
92
|
-
ROOT = process.cwd();
|
|
93
|
-
initUserConfig();
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
export {
|
|
98
|
-
unpluginRouteAutoImportFactory
|
|
2
|
+
import { debug, normalizePath } from "./utils.js";
|
|
3
|
+
import { generateFromAst, logDiff, parseAst } from "@tanstack/router-utils";
|
|
4
|
+
import * as babel from "@babel/core";
|
|
5
|
+
import * as template from "@babel/template";
|
|
6
|
+
//#region src/core/route-autoimport-plugin.ts
|
|
7
|
+
/**
|
|
8
|
+
* This plugin adds imports for createFileRoute and createLazyFileRoute to the file route.
|
|
9
|
+
*/
|
|
10
|
+
var unpluginRouteAutoImportFactory = (options = {}) => {
|
|
11
|
+
let ROOT = process.cwd();
|
|
12
|
+
let userConfig;
|
|
13
|
+
function initUserConfig() {
|
|
14
|
+
if (typeof options === "function") userConfig = options();
|
|
15
|
+
else userConfig = getConfig(options, ROOT);
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
name: "tanstack-router:autoimport",
|
|
19
|
+
enforce: "pre",
|
|
20
|
+
transform: {
|
|
21
|
+
filter: {
|
|
22
|
+
id: /\.(m|c)?(j|t)sx?$/,
|
|
23
|
+
code: /createFileRoute\(|createLazyFileRoute\(/
|
|
24
|
+
},
|
|
25
|
+
handler(code, id) {
|
|
26
|
+
const normalizedId = normalizePath(id);
|
|
27
|
+
if (!globalThis.TSR_ROUTES_BY_ID_MAP?.has(normalizedId)) return null;
|
|
28
|
+
let routeType;
|
|
29
|
+
if (code.includes("createFileRoute(")) routeType = "createFileRoute";
|
|
30
|
+
else if (code.includes("createLazyFileRoute(")) routeType = "createLazyFileRoute";
|
|
31
|
+
else return null;
|
|
32
|
+
const routerImportPath = `@tanstack/${userConfig.target}-router`;
|
|
33
|
+
const ast = parseAst({ code });
|
|
34
|
+
let isCreateRouteFunctionImported = false;
|
|
35
|
+
babel.traverse(ast, { Program: { enter(programPath) {
|
|
36
|
+
programPath.traverse({ ImportDeclaration(path) {
|
|
37
|
+
if (path.node.specifiers.map((specifier) => specifier.local.name).includes(routeType) && path.node.source.value === routerImportPath) isCreateRouteFunctionImported = true;
|
|
38
|
+
} });
|
|
39
|
+
} } });
|
|
40
|
+
if (!isCreateRouteFunctionImported) {
|
|
41
|
+
if (debug) console.info("Adding autoimports to route ", normalizedId);
|
|
42
|
+
const autoImportStatement = template.statement(`import { ${routeType} } from '${routerImportPath}'`)();
|
|
43
|
+
ast.program.body.unshift(autoImportStatement);
|
|
44
|
+
const result = generateFromAst(ast, {
|
|
45
|
+
sourceMaps: true,
|
|
46
|
+
filename: normalizedId,
|
|
47
|
+
sourceFileName: normalizedId
|
|
48
|
+
});
|
|
49
|
+
if (debug) {
|
|
50
|
+
logDiff(code, result.code);
|
|
51
|
+
console.log("Output:\n", result.code + "\n\n");
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
vite: {
|
|
59
|
+
configResolved(config) {
|
|
60
|
+
ROOT = config.root;
|
|
61
|
+
initUserConfig();
|
|
62
|
+
},
|
|
63
|
+
applyToEnvironment() {
|
|
64
|
+
return userConfig.verboseFileRoutes === false;
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
rspack() {
|
|
68
|
+
ROOT = process.cwd();
|
|
69
|
+
initUserConfig();
|
|
70
|
+
},
|
|
71
|
+
webpack() {
|
|
72
|
+
ROOT = process.cwd();
|
|
73
|
+
initUserConfig();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
99
76
|
};
|
|
100
|
-
//#
|
|
77
|
+
//#endregion
|
|
78
|
+
export { unpluginRouteAutoImportFactory };
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=route-autoimport-plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-autoimport-plugin.js","sources":["../../../src/core/route-autoimport-plugin.ts"],"sourcesContent":["import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'\nimport babel from '@babel/core'\nimport * as template from '@babel/template'\nimport { getConfig } from './config'\nimport { debug, normalizePath } from './utils'\nimport type { Config } from './config'\nimport type { UnpluginFactory } from 'unplugin'\n\n/**\n * This plugin adds imports for createFileRoute and createLazyFileRoute to the file route.\n */\nexport const unpluginRouteAutoImportFactory: UnpluginFactory<\n Partial<Config | (() => Config)> | undefined\n> = (options = {}) => {\n let ROOT: string = process.cwd()\n let userConfig: Config\n\n function initUserConfig() {\n if (typeof options === 'function') {\n userConfig = options()\n } else {\n userConfig = getConfig(options, ROOT)\n }\n }\n return {\n name: 'tanstack-router:autoimport',\n enforce: 'pre',\n\n transform: {\n filter: {\n // this is necessary for webpack / rspack to avoid matching .html files\n id: /\\.(m|c)?(j|t)sx?$/,\n code: /createFileRoute\\(|createLazyFileRoute\\(/,\n },\n handler(code, id) {\n const normalizedId = normalizePath(id)\n if (!globalThis.TSR_ROUTES_BY_ID_MAP?.has(normalizedId)) {\n return null\n }\n let routeType: 'createFileRoute' | 'createLazyFileRoute'\n if (code.includes('createFileRoute(')) {\n routeType = 'createFileRoute'\n } else if (code.includes('createLazyFileRoute(')) {\n routeType = 'createLazyFileRoute'\n } else {\n return null\n }\n\n const routerImportPath = `@tanstack/${userConfig.target}-router`\n\n const ast = parseAst({ code })\n\n let isCreateRouteFunctionImported = false as boolean\n\n babel.traverse(ast, {\n Program: {\n enter(programPath) {\n programPath.traverse({\n ImportDeclaration(path) {\n const importedSpecifiers = path.node.specifiers.map(\n (specifier) => specifier.local.name,\n )\n if (\n importedSpecifiers.includes(routeType) &&\n path.node.source.value === routerImportPath\n ) {\n isCreateRouteFunctionImported = true\n }\n },\n })\n },\n },\n })\n\n if (!isCreateRouteFunctionImported) {\n if (debug) console.info('Adding autoimports to route ', normalizedId)\n\n const autoImportStatement = template.statement(\n `import { ${routeType} } from '${routerImportPath}'`,\n )()\n ast.program.body.unshift(autoImportStatement)\n\n const result = generateFromAst(ast, {\n sourceMaps: true,\n filename: normalizedId,\n sourceFileName: normalizedId,\n })\n if (debug) {\n logDiff(code, result.code)\n console.log('Output:\\n', result.code + '\\n\\n')\n }\n return result\n }\n\n return null\n },\n },\n\n vite: {\n configResolved(config) {\n ROOT = config.root\n initUserConfig()\n },\n // this check may only happen after config is resolved, so we use applyToEnvironment (apply is too early)\n applyToEnvironment() {\n return userConfig.verboseFileRoutes === false\n },\n },\n\n rspack() {\n ROOT = process.cwd()\n initUserConfig()\n },\n\n webpack() {\n ROOT = process.cwd()\n initUserConfig()\n },\n }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"route-autoimport-plugin.js","names":[],"sources":["../../../src/core/route-autoimport-plugin.ts"],"sourcesContent":["import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'\nimport * as babel from '@babel/core'\nimport * as template from '@babel/template'\nimport { getConfig } from './config'\nimport { debug, normalizePath } from './utils'\nimport type { Config } from './config'\nimport type { UnpluginFactory } from 'unplugin'\n\n/**\n * This plugin adds imports for createFileRoute and createLazyFileRoute to the file route.\n */\nexport const unpluginRouteAutoImportFactory: UnpluginFactory<\n Partial<Config | (() => Config)> | undefined\n> = (options = {}) => {\n let ROOT: string = process.cwd()\n let userConfig: Config\n\n function initUserConfig() {\n if (typeof options === 'function') {\n userConfig = options()\n } else {\n userConfig = getConfig(options, ROOT)\n }\n }\n return {\n name: 'tanstack-router:autoimport',\n enforce: 'pre',\n\n transform: {\n filter: {\n // this is necessary for webpack / rspack to avoid matching .html files\n id: /\\.(m|c)?(j|t)sx?$/,\n code: /createFileRoute\\(|createLazyFileRoute\\(/,\n },\n handler(code, id) {\n const normalizedId = normalizePath(id)\n if (!globalThis.TSR_ROUTES_BY_ID_MAP?.has(normalizedId)) {\n return null\n }\n let routeType: 'createFileRoute' | 'createLazyFileRoute'\n if (code.includes('createFileRoute(')) {\n routeType = 'createFileRoute'\n } else if (code.includes('createLazyFileRoute(')) {\n routeType = 'createLazyFileRoute'\n } else {\n return null\n }\n\n const routerImportPath = `@tanstack/${userConfig.target}-router`\n\n const ast = parseAst({ code })\n\n let isCreateRouteFunctionImported = false as boolean\n\n babel.traverse(ast, {\n Program: {\n enter(programPath) {\n programPath.traverse({\n ImportDeclaration(path) {\n const importedSpecifiers = path.node.specifiers.map(\n (specifier) => specifier.local.name,\n )\n if (\n importedSpecifiers.includes(routeType) &&\n path.node.source.value === routerImportPath\n ) {\n isCreateRouteFunctionImported = true\n }\n },\n })\n },\n },\n })\n\n if (!isCreateRouteFunctionImported) {\n if (debug) console.info('Adding autoimports to route ', normalizedId)\n\n const autoImportStatement = template.statement(\n `import { ${routeType} } from '${routerImportPath}'`,\n )()\n ast.program.body.unshift(autoImportStatement)\n\n const result = generateFromAst(ast, {\n sourceMaps: true,\n filename: normalizedId,\n sourceFileName: normalizedId,\n })\n if (debug) {\n logDiff(code, result.code)\n console.log('Output:\\n', result.code + '\\n\\n')\n }\n return result\n }\n\n return null\n },\n },\n\n vite: {\n configResolved(config) {\n ROOT = config.root\n initUserConfig()\n },\n // this check may only happen after config is resolved, so we use applyToEnvironment (apply is too early)\n applyToEnvironment() {\n return userConfig.verboseFileRoutes === false\n },\n },\n\n rspack() {\n ROOT = process.cwd()\n initUserConfig()\n },\n\n webpack() {\n ROOT = process.cwd()\n initUserConfig()\n },\n }\n}\n"],"mappings":";;;;;;;;;AAWA,IAAa,kCAER,UAAU,EAAE,KAAK;CACpB,IAAI,OAAe,QAAQ,KAAK;CAChC,IAAI;CAEJ,SAAS,iBAAiB;AACxB,MAAI,OAAO,YAAY,WACrB,cAAa,SAAS;MAEtB,cAAa,UAAU,SAAS,KAAK;;AAGzC,QAAO;EACL,MAAM;EACN,SAAS;EAET,WAAW;GACT,QAAQ;IAEN,IAAI;IACJ,MAAM;IACP;GACD,QAAQ,MAAM,IAAI;IAChB,MAAM,eAAe,cAAc,GAAG;AACtC,QAAI,CAAC,WAAW,sBAAsB,IAAI,aAAa,CACrD,QAAO;IAET,IAAI;AACJ,QAAI,KAAK,SAAS,mBAAmB,CACnC,aAAY;aACH,KAAK,SAAS,uBAAuB,CAC9C,aAAY;QAEZ,QAAO;IAGT,MAAM,mBAAmB,aAAa,WAAW,OAAO;IAExD,MAAM,MAAM,SAAS,EAAE,MAAM,CAAC;IAE9B,IAAI,gCAAgC;AAEpC,UAAM,SAAS,KAAK,EAClB,SAAS,EACP,MAAM,aAAa;AACjB,iBAAY,SAAS,EACnB,kBAAkB,MAAM;AAItB,UAH2B,KAAK,KAAK,WAAW,KAC7C,cAAc,UAAU,MAAM,KAChC,CAEoB,SAAS,UAAU,IACtC,KAAK,KAAK,OAAO,UAAU,iBAE3B,iCAAgC;QAGrC,CAAC;OAEL,EACF,CAAC;AAEF,QAAI,CAAC,+BAA+B;AAClC,SAAI,MAAO,SAAQ,KAAK,gCAAgC,aAAa;KAErE,MAAM,sBAAsB,SAAS,UACnC,YAAY,UAAU,WAAW,iBAAiB,GACnD,EAAE;AACH,SAAI,QAAQ,KAAK,QAAQ,oBAAoB;KAE7C,MAAM,SAAS,gBAAgB,KAAK;MAClC,YAAY;MACZ,UAAU;MACV,gBAAgB;MACjB,CAAC;AACF,SAAI,OAAO;AACT,cAAQ,MAAM,OAAO,KAAK;AAC1B,cAAQ,IAAI,aAAa,OAAO,OAAO,OAAO;;AAEhD,YAAO;;AAGT,WAAO;;GAEV;EAED,MAAM;GACJ,eAAe,QAAQ;AACrB,WAAO,OAAO;AACd,oBAAgB;;GAGlB,qBAAqB;AACnB,WAAO,WAAW,sBAAsB;;GAE3C;EAED,SAAS;AACP,UAAO,QAAQ,KAAK;AACpB,mBAAgB;;EAGlB,UAAU;AACR,UAAO,QAAQ,KAAK;AACpB,mBAAgB;;EAEnB"}
|