@tanstack/router-plugin 1.166.10 → 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,32 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
1
|
+
//#region src/core/code-splitter/path-ids.ts
|
|
3
2
|
function createIdentifier(strings) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
safeString = safeString.replace(/=/g, "--equals--");
|
|
16
|
-
safeString = safeString.replace(/&/g, "--ampersand--");
|
|
17
|
-
safeString = safeString.replace(/\s/g, "_");
|
|
18
|
-
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;
|
|
19
14
|
}
|
|
20
15
|
function decodeIdentifier(identifier) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
combinedString = combinedString.replace(/_/g, " ");
|
|
33
|
-
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("---");
|
|
34
27
|
}
|
|
28
|
+
//#endregion
|
|
35
29
|
exports.createIdentifier = createIdentifier;
|
|
36
30
|
exports.decodeIdentifier = decodeIdentifier;
|
|
37
|
-
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=path-ids.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path-ids.cjs","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.cjs","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
|
-
|
|
2
|
-
|
|
3
|
-
const reactRefreshRouteComponents = require("./react-refresh-route-components.cjs");
|
|
1
|
+
const require_react_refresh_route_components = require("./react-refresh-route-components.cjs");
|
|
2
|
+
//#region src/core/code-splitter/plugins/framework-plugins.ts
|
|
4
3
|
function getReferenceRouteCompilerPlugins(opts) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
default:
|
|
13
|
-
return void 0;
|
|
14
|
-
}
|
|
4
|
+
switch (opts.targetFramework) {
|
|
5
|
+
case "react":
|
|
6
|
+
if (opts.addHmr) return [require_react_refresh_route_components.createReactRefreshRouteComponentsPlugin()];
|
|
7
|
+
return;
|
|
8
|
+
default: return;
|
|
9
|
+
}
|
|
15
10
|
}
|
|
11
|
+
//#endregion
|
|
16
12
|
exports.getReferenceRouteCompilerPlugins = getReferenceRouteCompilerPlugins;
|
|
17
|
-
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=framework-plugins.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"framework-plugins.cjs","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.cjs","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,uCAAA,yCAAyC,CAAC;AAEpD;EAEF,QACE"}
|
|
@@ -1,69 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: () => e[k]
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
n.default = e;
|
|
19
|
-
return Object.freeze(n);
|
|
20
|
-
}
|
|
21
|
-
const t__namespace = /* @__PURE__ */ _interopNamespaceDefault(t);
|
|
22
|
-
const REACT_REFRESH_ROUTE_COMPONENT_IDENTS = /* @__PURE__ */ new Set([
|
|
23
|
-
"component",
|
|
24
|
-
"pendingComponent",
|
|
25
|
-
"errorComponent",
|
|
26
|
-
"notFoundComponent"
|
|
1
|
+
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_utils = require("../../utils.cjs");
|
|
3
|
+
let _babel_types = require("@babel/types");
|
|
4
|
+
_babel_types = require_runtime.__toESM(_babel_types);
|
|
5
|
+
//#region src/core/code-splitter/plugins/react-refresh-route-components.ts
|
|
6
|
+
var REACT_REFRESH_ROUTE_COMPONENT_IDENTS = new Set([
|
|
7
|
+
"component",
|
|
8
|
+
"pendingComponent",
|
|
9
|
+
"errorComponent",
|
|
10
|
+
"notFoundComponent"
|
|
27
11
|
]);
|
|
28
12
|
function createReactRefreshRouteComponentsPlugin() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
ctx.programPath,
|
|
48
|
-
`TSR${prop.key.name[0].toUpperCase()}${prop.key.name.slice(1)}`
|
|
49
|
-
);
|
|
50
|
-
hoistedDeclarations.push(
|
|
51
|
-
t__namespace.variableDeclaration("const", [
|
|
52
|
-
t__namespace.variableDeclarator(
|
|
53
|
-
hoistedIdentifier,
|
|
54
|
-
t__namespace.cloneNode(prop.value, true)
|
|
55
|
-
)
|
|
56
|
-
])
|
|
57
|
-
);
|
|
58
|
-
prop.value = t__namespace.cloneNode(hoistedIdentifier);
|
|
59
|
-
});
|
|
60
|
-
if (hoistedDeclarations.length === 0) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
ctx.insertionPath.insertBefore(hoistedDeclarations);
|
|
64
|
-
return { modified: true };
|
|
65
|
-
}
|
|
66
|
-
};
|
|
13
|
+
return {
|
|
14
|
+
name: "react-refresh-route-components",
|
|
15
|
+
onUnsplittableRoute(ctx) {
|
|
16
|
+
if (!ctx.opts.addHmr) return;
|
|
17
|
+
const hoistedDeclarations = [];
|
|
18
|
+
ctx.routeOptions.properties.forEach((prop) => {
|
|
19
|
+
if (!_babel_types.isObjectProperty(prop) || !_babel_types.isIdentifier(prop.key)) return;
|
|
20
|
+
if (!REACT_REFRESH_ROUTE_COMPONENT_IDENTS.has(prop.key.name)) return;
|
|
21
|
+
if (!_babel_types.isArrowFunctionExpression(prop.value) && !_babel_types.isFunctionExpression(prop.value)) return;
|
|
22
|
+
const hoistedIdentifier = require_utils.getUniqueProgramIdentifier(ctx.programPath, `TSR${prop.key.name[0].toUpperCase()}${prop.key.name.slice(1)}`);
|
|
23
|
+
hoistedDeclarations.push(_babel_types.variableDeclaration("const", [_babel_types.variableDeclarator(hoistedIdentifier, _babel_types.cloneNode(prop.value, true))]));
|
|
24
|
+
prop.value = _babel_types.cloneNode(hoistedIdentifier);
|
|
25
|
+
});
|
|
26
|
+
if (hoistedDeclarations.length === 0) return;
|
|
27
|
+
ctx.insertionPath.insertBefore(hoistedDeclarations);
|
|
28
|
+
return { modified: true };
|
|
29
|
+
}
|
|
30
|
+
};
|
|
67
31
|
}
|
|
32
|
+
//#endregion
|
|
68
33
|
exports.createReactRefreshRouteComponentsPlugin = createReactRefreshRouteComponentsPlugin;
|
|
69
|
-
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=react-refresh-route-components.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-refresh-route-components.cjs","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.cjs","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,aAAE,iBAAiB,KAAK,IAAI,CAAC,aAAE,aAAa,KAAK,IAAI,CACxD;AAGF,QAAI,CAAC,qCAAqC,IAAI,KAAK,IAAI,KAAK,CAC1D;AAGF,QACE,CAAC,aAAE,0BAA0B,KAAK,MAAM,IACxC,CAAC,aAAE,qBAAqB,KAAK,MAAM,CAEnC;IAGF,MAAM,oBAAoB,cAAA,2BACxB,IAAI,aACJ,MAAM,KAAK,IAAI,KAAK,GAAI,aAAa,GAAG,KAAK,IAAI,KAAK,MAAM,EAAE,GAC/D;AAED,wBAAoB,KAClB,aAAE,oBAAoB,SAAS,CAC7B,aAAE,mBACA,mBACA,aAAE,UAAU,KAAK,OAAO,KAAK,CAC9B,CACF,CAAC,CACH;AAED,SAAK,QAAQ,aAAE,UAAU,kBAAkB;KAC3C;AAEF,OAAI,oBAAoB,WAAW,EACjC;AAGF,OAAI,cAAc,aAAa,oBAAoB;AACnD,UAAO,EAAE,UAAU,MAAM;;EAE5B"}
|
package/dist/cjs/core/config.cjs
CHANGED
|
@@ -1,53 +1,43 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
{
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
).superRefine((val, ctx) => {
|
|
19
|
-
const flattened = val.flat();
|
|
20
|
-
const unique = [...new Set(flattened)];
|
|
21
|
-
if (unique.length !== flattened.length) {
|
|
22
|
-
ctx.addIssue({
|
|
23
|
-
code: "custom",
|
|
24
|
-
message: ` Split groupings must be unique and not repeated. i.e. i.e. [['component'], ['pendingComponent'], ['errorComponent', 'notFoundComponent']].
|
|
25
|
-
You input was: ${JSON.stringify(val)}.`
|
|
26
|
-
});
|
|
27
|
-
}
|
|
1
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let zod = require("zod");
|
|
3
|
+
let _tanstack_router_generator = require("@tanstack/router-generator");
|
|
4
|
+
//#region src/core/config.ts
|
|
5
|
+
var splitGroupingsSchema = zod.z.array(zod.z.array(zod.z.union([
|
|
6
|
+
zod.z.literal("loader"),
|
|
7
|
+
zod.z.literal("component"),
|
|
8
|
+
zod.z.literal("pendingComponent"),
|
|
9
|
+
zod.z.literal("errorComponent"),
|
|
10
|
+
zod.z.literal("notFoundComponent")
|
|
11
|
+
])), { message: " Must be an Array of Arrays containing the split groupings. i.e. [['component'], ['pendingComponent'], ['errorComponent', 'notFoundComponent']]" }).superRefine((val, ctx) => {
|
|
12
|
+
const flattened = val.flat();
|
|
13
|
+
if ([...new Set(flattened)].length !== flattened.length) ctx.addIssue({
|
|
14
|
+
code: "custom",
|
|
15
|
+
message: ` Split groupings must be unique and not repeated. i.e. i.e. [['component'], ['pendingComponent'], ['errorComponent', 'notFoundComponent']].\n You input was: ${JSON.stringify(val)}.`
|
|
16
|
+
});
|
|
28
17
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
18
|
+
var codeSplittingOptionsSchema = zod.z.object({
|
|
19
|
+
splitBehavior: zod.z.function().optional(),
|
|
20
|
+
defaultBehavior: splitGroupingsSchema.optional(),
|
|
21
|
+
deleteNodes: zod.z.array(zod.z.string()).optional(),
|
|
22
|
+
addHmr: zod.z.boolean().optional().default(true)
|
|
34
23
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
vite: zod.z.object({
|
|
42
|
-
environmentName: zod.z.string().optional()
|
|
43
|
-
}).optional()
|
|
44
|
-
}).optional()
|
|
24
|
+
var configSchema = _tanstack_router_generator.configSchema.extend({
|
|
25
|
+
enableRouteGeneration: zod.z.boolean().optional(),
|
|
26
|
+
codeSplittingOptions: zod.z.custom((v) => {
|
|
27
|
+
return codeSplittingOptionsSchema.parse(v);
|
|
28
|
+
}).optional(),
|
|
29
|
+
plugin: zod.z.object({ vite: zod.z.object({ environmentName: zod.z.string().optional() }).optional() }).optional()
|
|
45
30
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
31
|
+
var getConfig = (inlineConfig, root) => {
|
|
32
|
+
const config = (0, _tanstack_router_generator.getConfig)(inlineConfig, root);
|
|
33
|
+
return configSchema.parse({
|
|
34
|
+
...inlineConfig,
|
|
35
|
+
...config
|
|
36
|
+
});
|
|
49
37
|
};
|
|
38
|
+
//#endregion
|
|
50
39
|
exports.configSchema = configSchema;
|
|
51
40
|
exports.getConfig = getConfig;
|
|
52
41
|
exports.splitGroupingsSchema = splitGroupingsSchema;
|
|
53
|
-
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=config.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.cjs","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.cjs","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,IAAA,EACjC,MACC,IAAA,EAAE,MACA,IAAA,EAAE,MAAM;CACN,IAAA,EAAE,QAAQ,SAAS;CACnB,IAAA,EAAE,QAAQ,YAAY;CACtB,IAAA,EAAE,QAAQ,mBAAmB;CAC7B,IAAA,EAAE,QAAQ,iBAAiB;CAC3B,IAAA,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,IAAA,EAAE,OAAO;CAC1C,eAAe,IAAA,EAAE,UAAU,CAAC,UAAU;CACtC,iBAAiB,qBAAqB,UAAU;CAChD,aAAa,IAAA,EAAE,MAAM,IAAA,EAAE,QAAQ,CAAC,CAAC,UAAU;CAC3C,QAAQ,IAAA,EAAE,SAAS,CAAC,UAAU,CAAC,QAAQ,KAAK;CAC7C,CAAC;AAOF,IAAa,eAAe,2BAAA,aAAsB,OAAO;CACvD,uBAAuB,IAAA,EAAE,SAAS,CAAC,UAAU;CAC7C,sBAAsB,IAAA,EACnB,QAA8B,MAAM;AACnC,SAAO,2BAA2B,MAAM,EAAE;GAC1C,CACD,UAAU;CACb,QAAQ,IAAA,EACL,OAAO,EACN,MAAM,IAAA,EACH,OAAO,EACN,iBAAiB,IAAA,EAAE,QAAQ,CAAC,UAAU,EACvC,CAAC,CACD,UAAU,EACd,CAAC,CACD,UAAU;CACd,CAAC;AAEF,IAAa,aAAa,cAA+B,SAAiB;CACxE,MAAM,UAAA,GAAA,2BAAA,WAA4B,cAAc,KAAK;AAErD,QAAO,aAAa,MAAM;EAAE,GAAG;EAAc,GAAG;EAAQ,CAAC"}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"notFoundComponent"
|
|
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"
|
|
11
10
|
];
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
var defaultCodeSplitGroupings = [
|
|
12
|
+
["component"],
|
|
13
|
+
["errorComponent"],
|
|
14
|
+
["notFoundComponent"]
|
|
16
15
|
];
|
|
16
|
+
//#endregion
|
|
17
17
|
exports.defaultCodeSplitGroupings = defaultCodeSplitGroupings;
|
|
18
18
|
exports.splitRouteIdentNodes = splitRouteIdentNodes;
|
|
19
19
|
exports.tsrShared = tsrShared;
|
|
20
20
|
exports.tsrSplit = tsrSplit;
|
|
21
|
-
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=constants.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.cjs","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.cjs","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,117 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
`import { ${routeType} } from '${routerImportPath}'`
|
|
80
|
-
)();
|
|
81
|
-
ast.program.body.unshift(autoImportStatement);
|
|
82
|
-
const result = routerUtils.generateFromAst(ast, {
|
|
83
|
-
sourceMaps: true,
|
|
84
|
-
filename: normalizedId,
|
|
85
|
-
sourceFileName: normalizedId
|
|
86
|
-
});
|
|
87
|
-
if (utils.debug) {
|
|
88
|
-
routerUtils.logDiff(code, result.code);
|
|
89
|
-
console.log("Output:\n", result.code + "\n\n");
|
|
90
|
-
}
|
|
91
|
-
return result;
|
|
92
|
-
}
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
vite: {
|
|
97
|
-
configResolved(config2) {
|
|
98
|
-
ROOT = config2.root;
|
|
99
|
-
initUserConfig();
|
|
100
|
-
},
|
|
101
|
-
// this check may only happen after config is resolved, so we use applyToEnvironment (apply is too early)
|
|
102
|
-
applyToEnvironment() {
|
|
103
|
-
return userConfig.verboseFileRoutes === false;
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
rspack() {
|
|
107
|
-
ROOT = process.cwd();
|
|
108
|
-
initUserConfig();
|
|
109
|
-
},
|
|
110
|
-
webpack() {
|
|
111
|
-
ROOT = process.cwd();
|
|
112
|
-
initUserConfig();
|
|
113
|
-
}
|
|
114
|
-
};
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_config = require("./config.cjs");
|
|
3
|
+
const require_utils = require("./utils.cjs");
|
|
4
|
+
let _tanstack_router_utils = require("@tanstack/router-utils");
|
|
5
|
+
let _babel_core = require("@babel/core");
|
|
6
|
+
_babel_core = require_runtime.__toESM(_babel_core);
|
|
7
|
+
let _babel_template = require("@babel/template");
|
|
8
|
+
_babel_template = require_runtime.__toESM(_babel_template);
|
|
9
|
+
//#region src/core/route-autoimport-plugin.ts
|
|
10
|
+
/**
|
|
11
|
+
* This plugin adds imports for createFileRoute and createLazyFileRoute to the file route.
|
|
12
|
+
*/
|
|
13
|
+
var unpluginRouteAutoImportFactory = (options = {}) => {
|
|
14
|
+
let ROOT = process.cwd();
|
|
15
|
+
let userConfig;
|
|
16
|
+
function initUserConfig() {
|
|
17
|
+
if (typeof options === "function") userConfig = options();
|
|
18
|
+
else userConfig = require_config.getConfig(options, ROOT);
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
name: "tanstack-router:autoimport",
|
|
22
|
+
enforce: "pre",
|
|
23
|
+
transform: {
|
|
24
|
+
filter: {
|
|
25
|
+
id: /\.(m|c)?(j|t)sx?$/,
|
|
26
|
+
code: /createFileRoute\(|createLazyFileRoute\(/
|
|
27
|
+
},
|
|
28
|
+
handler(code, id) {
|
|
29
|
+
const normalizedId = require_utils.normalizePath(id);
|
|
30
|
+
if (!globalThis.TSR_ROUTES_BY_ID_MAP?.has(normalizedId)) return null;
|
|
31
|
+
let routeType;
|
|
32
|
+
if (code.includes("createFileRoute(")) routeType = "createFileRoute";
|
|
33
|
+
else if (code.includes("createLazyFileRoute(")) routeType = "createLazyFileRoute";
|
|
34
|
+
else return null;
|
|
35
|
+
const routerImportPath = `@tanstack/${userConfig.target}-router`;
|
|
36
|
+
const ast = (0, _tanstack_router_utils.parseAst)({ code });
|
|
37
|
+
let isCreateRouteFunctionImported = false;
|
|
38
|
+
_babel_core.traverse(ast, { Program: { enter(programPath) {
|
|
39
|
+
programPath.traverse({ ImportDeclaration(path) {
|
|
40
|
+
if (path.node.specifiers.map((specifier) => specifier.local.name).includes(routeType) && path.node.source.value === routerImportPath) isCreateRouteFunctionImported = true;
|
|
41
|
+
} });
|
|
42
|
+
} } });
|
|
43
|
+
if (!isCreateRouteFunctionImported) {
|
|
44
|
+
if (require_utils.debug) console.info("Adding autoimports to route ", normalizedId);
|
|
45
|
+
const autoImportStatement = _babel_template.statement(`import { ${routeType} } from '${routerImportPath}'`)();
|
|
46
|
+
ast.program.body.unshift(autoImportStatement);
|
|
47
|
+
const result = (0, _tanstack_router_utils.generateFromAst)(ast, {
|
|
48
|
+
sourceMaps: true,
|
|
49
|
+
filename: normalizedId,
|
|
50
|
+
sourceFileName: normalizedId
|
|
51
|
+
});
|
|
52
|
+
if (require_utils.debug) {
|
|
53
|
+
(0, _tanstack_router_utils.logDiff)(code, result.code);
|
|
54
|
+
console.log("Output:\n", result.code + "\n\n");
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
vite: {
|
|
62
|
+
configResolved(config) {
|
|
63
|
+
ROOT = config.root;
|
|
64
|
+
initUserConfig();
|
|
65
|
+
},
|
|
66
|
+
applyToEnvironment() {
|
|
67
|
+
return userConfig.verboseFileRoutes === false;
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
rspack() {
|
|
71
|
+
ROOT = process.cwd();
|
|
72
|
+
initUserConfig();
|
|
73
|
+
},
|
|
74
|
+
webpack() {
|
|
75
|
+
ROOT = process.cwd();
|
|
76
|
+
initUserConfig();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
115
79
|
};
|
|
80
|
+
//#endregion
|
|
116
81
|
exports.unpluginRouteAutoImportFactory = unpluginRouteAutoImportFactory;
|
|
117
|
-
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=route-autoimport-plugin.cjs.map
|