@tanstack/router-plugin 1.120.4-alpha.4 → 1.120.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/core/code-splitter/compilers.cjs +21 -39
- package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/compilers.d.cts +0 -3
- package/dist/cjs/core/code-splitter/framework-options.cjs +8 -4
- package/dist/cjs/core/code-splitter/framework-options.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/framework-options.d.cts +2 -0
- package/dist/cjs/core/config.d.cts +40 -31
- package/dist/cjs/core/router-code-splitter-plugin.cjs +20 -11
- package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-composed-plugin.cjs +5 -19
- package/dist/cjs/core/router-composed-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-generator-plugin.cjs +2 -8
- package/dist/cjs/core/router-generator-plugin.cjs.map +1 -1
- package/dist/cjs/esbuild.d.cts +27 -21
- package/dist/cjs/rspack.d.cts +27 -21
- package/dist/cjs/vite.cjs +0 -2
- package/dist/cjs/vite.cjs.map +1 -1
- package/dist/cjs/vite.d.cts +26 -52
- package/dist/cjs/webpack.d.cts +27 -21
- package/dist/esm/core/code-splitter/compilers.d.ts +0 -3
- package/dist/esm/core/code-splitter/compilers.js +21 -39
- package/dist/esm/core/code-splitter/compilers.js.map +1 -1
- package/dist/esm/core/code-splitter/framework-options.d.ts +2 -0
- package/dist/esm/core/code-splitter/framework-options.js +8 -4
- package/dist/esm/core/code-splitter/framework-options.js.map +1 -1
- package/dist/esm/core/config.d.ts +40 -31
- package/dist/esm/core/router-code-splitter-plugin.js +14 -5
- package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
- package/dist/esm/core/router-composed-plugin.js +5 -19
- package/dist/esm/core/router-composed-plugin.js.map +1 -1
- package/dist/esm/core/router-generator-plugin.js +2 -8
- package/dist/esm/core/router-generator-plugin.js.map +1 -1
- package/dist/esm/esbuild.d.ts +27 -21
- package/dist/esm/rspack.d.ts +27 -21
- package/dist/esm/vite.d.ts +26 -52
- package/dist/esm/vite.js +1 -3
- package/dist/esm/vite.js.map +1 -1
- package/dist/esm/webpack.d.ts +27 -21
- package/package.json +6 -6
- package/src/core/code-splitter/compilers.ts +27 -54
- package/src/core/code-splitter/framework-options.ts +6 -0
- package/src/core/router-code-splitter-plugin.ts +23 -3
- package/src/core/router-composed-plugin.ts +10 -20
- package/src/core/router-generator-plugin.ts +1 -12
- package/src/vite.ts +0 -3
- package/dist/cjs/core/route-autoimport-plugin.cjs +0 -98
- package/dist/cjs/core/route-autoimport-plugin.cjs.map +0 -1
- package/dist/cjs/core/route-autoimport-plugin.d.cts +0 -6
- package/dist/cjs/core/route-hmr-statement.cjs +0 -33
- package/dist/cjs/core/route-hmr-statement.cjs.map +0 -1
- package/dist/cjs/core/route-hmr-statement.d.cts +0 -1
- package/dist/cjs/core/router-hmr-plugin.cjs +0 -51
- package/dist/cjs/core/router-hmr-plugin.cjs.map +0 -1
- package/dist/cjs/core/router-hmr-plugin.d.cts +0 -8
- package/dist/cjs/core/utils.cjs +0 -12
- package/dist/cjs/core/utils.cjs.map +0 -1
- package/dist/cjs/core/utils.d.cts +0 -2
- package/dist/esm/core/route-autoimport-plugin.d.ts +0 -6
- package/dist/esm/core/route-autoimport-plugin.js +0 -81
- package/dist/esm/core/route-autoimport-plugin.js.map +0 -1
- package/dist/esm/core/route-hmr-statement.d.ts +0 -1
- package/dist/esm/core/route-hmr-statement.js +0 -16
- package/dist/esm/core/route-hmr-statement.js.map +0 -1
- package/dist/esm/core/router-hmr-plugin.d.ts +0 -8
- package/dist/esm/core/router-hmr-plugin.js +0 -51
- package/dist/esm/core/router-hmr-plugin.js.map +0 -1
- package/dist/esm/core/utils.d.ts +0 -2
- package/dist/esm/core/utils.js +0 -12
- package/dist/esm/core/utils.js.map +0 -1
- package/src/core/route-autoimport-plugin.ts +0 -102
- package/src/core/route-hmr-statement.ts +0 -13
- package/src/core/router-hmr-plugin.ts +0 -65
- package/src/core/utils.ts +0 -18
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* https://github.com/TanStack/router/pull/3355
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { isAbsolute, join, normalize } from 'node:path'
|
|
6
7
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
7
8
|
import { logDiff } from '@tanstack/router-utils'
|
|
8
9
|
import { getConfig, splitGroupingsSchema } from './config'
|
|
@@ -17,7 +18,6 @@ import {
|
|
|
17
18
|
tsrSplit,
|
|
18
19
|
} from './constants'
|
|
19
20
|
import { decodeIdentifier } from './code-splitter/path-ids'
|
|
20
|
-
import { debug, fileIsInRoutesDirectory } from './utils'
|
|
21
21
|
import type { CodeSplitGroupings, SplitRouteIdentNodes } from './constants'
|
|
22
22
|
|
|
23
23
|
import type { Config } from './config'
|
|
@@ -27,10 +27,27 @@ import type {
|
|
|
27
27
|
TransformResult as UnpluginTransformResult,
|
|
28
28
|
} from 'unplugin'
|
|
29
29
|
|
|
30
|
+
const debug =
|
|
31
|
+
process.env.TSR_VITE_DEBUG &&
|
|
32
|
+
['true', 'router-plugin'].includes(process.env.TSR_VITE_DEBUG)
|
|
33
|
+
|
|
30
34
|
function capitalizeFirst(str: string): string {
|
|
31
35
|
return str.charAt(0).toUpperCase() + str.slice(1)
|
|
32
36
|
}
|
|
33
37
|
|
|
38
|
+
function fileIsInRoutesDirectory(
|
|
39
|
+
filePath: string,
|
|
40
|
+
routesDirectory: string,
|
|
41
|
+
): boolean {
|
|
42
|
+
const routesDirectoryPath = isAbsolute(routesDirectory)
|
|
43
|
+
? routesDirectory
|
|
44
|
+
: join(process.cwd(), routesDirectory)
|
|
45
|
+
|
|
46
|
+
const path = normalize(filePath)
|
|
47
|
+
|
|
48
|
+
return path.startsWith(routesDirectoryPath)
|
|
49
|
+
}
|
|
50
|
+
|
|
34
51
|
type BannedBeforeExternalPlugin = {
|
|
35
52
|
identifier: string
|
|
36
53
|
pkg: string
|
|
@@ -87,6 +104,8 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
87
104
|
|
|
88
105
|
const fromCode = detectCodeSplitGroupingsFromRoute({
|
|
89
106
|
code,
|
|
107
|
+
root: ROOT,
|
|
108
|
+
filename: id,
|
|
90
109
|
})
|
|
91
110
|
|
|
92
111
|
if (fromCode.groupings) {
|
|
@@ -120,11 +139,11 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
120
139
|
|
|
121
140
|
const compiledReferenceRoute = compileCodeSplitReferenceRoute({
|
|
122
141
|
code,
|
|
142
|
+
root: ROOT,
|
|
143
|
+
filename: id,
|
|
123
144
|
runtimeEnv: isProduction ? 'prod' : 'dev',
|
|
124
145
|
codeSplitGroupings: splitGroupings,
|
|
125
146
|
targetFramework: userConfig.target,
|
|
126
|
-
filename: id,
|
|
127
|
-
id,
|
|
128
147
|
})
|
|
129
148
|
|
|
130
149
|
if (debug) {
|
|
@@ -159,6 +178,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
159
178
|
|
|
160
179
|
const result = compileCodeSplitVirtualRoute({
|
|
161
180
|
code,
|
|
181
|
+
root: ROOT,
|
|
162
182
|
filename: id,
|
|
163
183
|
splitTargets: grouping,
|
|
164
184
|
})
|
|
@@ -1,32 +1,22 @@
|
|
|
1
1
|
import { unpluginRouterGeneratorFactory } from './router-generator-plugin'
|
|
2
2
|
import { unpluginRouterCodeSplitterFactory } from './router-code-splitter-plugin'
|
|
3
|
-
|
|
4
|
-
import { unpluginRouteAutoimportFactory } from './route-autoimport-plugin'
|
|
3
|
+
|
|
5
4
|
import type { Config } from './config'
|
|
6
5
|
import type { UnpluginFactory } from 'unplugin'
|
|
7
6
|
|
|
8
7
|
export const unpluginRouterComposedFactory: UnpluginFactory<
|
|
9
8
|
Partial<Config> | undefined
|
|
10
9
|
> = (options = {}, meta) => {
|
|
11
|
-
const
|
|
12
|
-
const plugin = pluginFactory(options, meta)
|
|
13
|
-
if (!Array.isArray(plugin)) {
|
|
14
|
-
return [plugin]
|
|
15
|
-
}
|
|
16
|
-
return plugin
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const routerGenerator = getPlugin(unpluginRouterGeneratorFactory)
|
|
20
|
-
const routerCodeSplitter = getPlugin(unpluginRouterCodeSplitterFactory)
|
|
21
|
-
const routeAutoImport = getPlugin(unpluginRouteAutoimportFactory)
|
|
10
|
+
const routerGenerator = unpluginRouterGeneratorFactory(options, meta)
|
|
22
11
|
|
|
23
|
-
const
|
|
12
|
+
const routerGeneratorOptions = Array.isArray(routerGenerator)
|
|
13
|
+
? routerGenerator
|
|
14
|
+
: [routerGenerator]
|
|
24
15
|
|
|
25
|
-
const
|
|
16
|
+
const routerCodeSplitter = unpluginRouterCodeSplitterFactory(options, meta)
|
|
17
|
+
const routerCodeSplitterOptions = Array.isArray(routerCodeSplitter)
|
|
18
|
+
? routerCodeSplitter
|
|
19
|
+
: [routerCodeSplitter]
|
|
26
20
|
|
|
27
|
-
|
|
28
|
-
const routerHmr = getPlugin(unpluginRouterHmrFactory)
|
|
29
|
-
result.push(...routerHmr)
|
|
30
|
-
}
|
|
31
|
-
return result
|
|
21
|
+
return [...routerGeneratorOptions, ...routerCodeSplitterOptions]
|
|
32
22
|
}
|
|
@@ -82,23 +82,12 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
|
|
|
82
82
|
})
|
|
83
83
|
},
|
|
84
84
|
vite: {
|
|
85
|
-
configResolved(config) {
|
|
85
|
+
async configResolved(config) {
|
|
86
86
|
ROOT = config.root
|
|
87
87
|
userConfig = getConfig(options, ROOT)
|
|
88
88
|
|
|
89
|
-
// if (config.command === 'serve') {
|
|
90
|
-
// await run(generate)
|
|
91
|
-
// }
|
|
92
|
-
},
|
|
93
|
-
async buildStart() {
|
|
94
|
-
if (this.environment.name === 'server') {
|
|
95
|
-
// When building in environment mode, we only need to generate routes
|
|
96
|
-
// for the client environment
|
|
97
|
-
return
|
|
98
|
-
}
|
|
99
89
|
await run(generate)
|
|
100
90
|
},
|
|
101
|
-
sharedDuringBuild: true,
|
|
102
91
|
},
|
|
103
92
|
rspack(compiler) {
|
|
104
93
|
userConfig = getConfig(options, ROOT)
|
package/src/vite.ts
CHANGED
|
@@ -43,7 +43,6 @@ const TanStackRouterCodeSplitterVite = createVitePlugin(
|
|
|
43
43
|
* ```
|
|
44
44
|
*/
|
|
45
45
|
const TanStackRouterVite = createVitePlugin(unpluginRouterComposedFactory)
|
|
46
|
-
const tanstackRouter = TanStackRouterVite
|
|
47
46
|
|
|
48
47
|
export default TanStackRouterVite
|
|
49
48
|
export {
|
|
@@ -51,7 +50,5 @@ export {
|
|
|
51
50
|
TanStackRouterGeneratorVite,
|
|
52
51
|
TanStackRouterCodeSplitterVite,
|
|
53
52
|
TanStackRouterVite,
|
|
54
|
-
tanstackRouter,
|
|
55
53
|
}
|
|
56
|
-
|
|
57
54
|
export type { Config }
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const routerUtils = require("@tanstack/router-utils");
|
|
4
|
-
const babel = require("@babel/core");
|
|
5
|
-
const template = require("@babel/template");
|
|
6
|
-
const config = require("./config.cjs");
|
|
7
|
-
const utils = require("./utils.cjs");
|
|
8
|
-
function _interopNamespaceDefault(e) {
|
|
9
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
|
-
if (e) {
|
|
11
|
-
for (const k in e) {
|
|
12
|
-
if (k !== "default") {
|
|
13
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: () => e[k]
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
n.default = e;
|
|
22
|
-
return Object.freeze(n);
|
|
23
|
-
}
|
|
24
|
-
const template__namespace = /* @__PURE__ */ _interopNamespaceDefault(template);
|
|
25
|
-
const unpluginRouteAutoimportFactory = (options = {}) => {
|
|
26
|
-
let ROOT = process.cwd();
|
|
27
|
-
let userConfig = options;
|
|
28
|
-
return {
|
|
29
|
-
name: "router-autoimport-plugin",
|
|
30
|
-
enforce: "pre",
|
|
31
|
-
transform(code, id) {
|
|
32
|
-
let routeType;
|
|
33
|
-
if (code.includes("export const Route = createFileRoute(")) {
|
|
34
|
-
routeType = "createFileRoute";
|
|
35
|
-
} else if (code.includes("export const Route = createLazyFileRoute(")) {
|
|
36
|
-
routeType = "createLazyFileRoute";
|
|
37
|
-
} else {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
const routerImportPath = `@tanstack/${userConfig.target}-router`;
|
|
41
|
-
const ast = routerUtils.parseAst({ code });
|
|
42
|
-
let isCreateRouteFunctionImported = false;
|
|
43
|
-
babel.traverse(ast, {
|
|
44
|
-
Program: {
|
|
45
|
-
enter(programPath) {
|
|
46
|
-
programPath.traverse({
|
|
47
|
-
ImportDeclaration(path) {
|
|
48
|
-
const importedSpecifiers = path.node.specifiers.map(
|
|
49
|
-
(specifier) => specifier.local.name
|
|
50
|
-
);
|
|
51
|
-
if (importedSpecifiers.includes(routeType) && path.node.source.value === routerImportPath) {
|
|
52
|
-
isCreateRouteFunctionImported = true;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
if (!isCreateRouteFunctionImported) {
|
|
60
|
-
if (utils.debug) console.info("Adding autoimports to route ", id);
|
|
61
|
-
const autoImportStatement = template__namespace.statement(
|
|
62
|
-
`import { ${routeType} } from '${routerImportPath}'`
|
|
63
|
-
)();
|
|
64
|
-
ast.program.body.unshift(autoImportStatement);
|
|
65
|
-
const result = routerUtils.generateFromAst(ast, {
|
|
66
|
-
sourceMaps: true,
|
|
67
|
-
filename: id,
|
|
68
|
-
sourceFileName: id
|
|
69
|
-
});
|
|
70
|
-
if (utils.debug) {
|
|
71
|
-
routerUtils.logDiff(code, result.code);
|
|
72
|
-
console.log("Output:\n", result.code + "\n\n");
|
|
73
|
-
}
|
|
74
|
-
return result;
|
|
75
|
-
}
|
|
76
|
-
return null;
|
|
77
|
-
},
|
|
78
|
-
transformInclude(id) {
|
|
79
|
-
return utils.fileIsInRoutesDirectory(id, userConfig.routesDirectory);
|
|
80
|
-
},
|
|
81
|
-
vite: {
|
|
82
|
-
configResolved(config$1) {
|
|
83
|
-
ROOT = config$1.root;
|
|
84
|
-
userConfig = config.getConfig(options, ROOT);
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
rspack() {
|
|
88
|
-
ROOT = process.cwd();
|
|
89
|
-
userConfig = config.getConfig(options, ROOT);
|
|
90
|
-
},
|
|
91
|
-
webpack() {
|
|
92
|
-
ROOT = process.cwd();
|
|
93
|
-
userConfig = config.getConfig(options, ROOT);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
exports.unpluginRouteAutoimportFactory = unpluginRouteAutoimportFactory;
|
|
98
|
-
//# sourceMappingURL=route-autoimport-plugin.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"route-autoimport-plugin.cjs","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, fileIsInRoutesDirectory } 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> | undefined\n> = (options = {}) => {\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n return {\n name: 'router-autoimport-plugin',\n enforce: 'pre',\n\n transform(code, id) {\n let routeType: 'createFileRoute' | 'createLazyFileRoute'\n if (code.includes('export const Route = createFileRoute(')) {\n routeType = 'createFileRoute'\n } else if (code.includes('export const Route = 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 ', id)\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: id,\n sourceFileName: id,\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 transformInclude(id) {\n return fileIsInRoutesDirectory(id, userConfig.routesDirectory)\n },\n\n vite: {\n configResolved(config) {\n ROOT = config.root\n userConfig = getConfig(options, ROOT)\n },\n },\n\n rspack() {\n ROOT = process.cwd()\n userConfig = getConfig(options, ROOT)\n },\n\n webpack() {\n ROOT = process.cwd()\n userConfig = getConfig(options, ROOT)\n },\n }\n}\n"],"names":["parseAst","debug","template","generateFromAst","logDiff","fileIsInRoutesDirectory","config","getConfig"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAWO,MAAM,iCAET,CAAC,UAAU,OAAO;AAChB,MAAA,OAAe,QAAQ,IAAI;AAC/B,MAAI,aAAa;AAEV,SAAA;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,UAAU,MAAM,IAAI;AACd,UAAA;AACA,UAAA,KAAK,SAAS,uCAAuC,GAAG;AAC9C,oBAAA;AAAA,MACH,WAAA,KAAK,SAAS,2CAA2C,GAAG;AACzD,oBAAA;AAAA,MAAA,OACP;AACE,eAAA;AAAA,MAAA;AAGH,YAAA,mBAAmB,aAAa,WAAW,MAAM;AAEvD,YAAM,MAAMA,YAAAA,SAAS,EAAE,MAAM;AAE7B,UAAI,gCAAgC;AAEpC,YAAM,SAAS,KAAK;AAAA,QAClB,SAAS;AAAA,UACP,MAAM,aAAa;AACjB,wBAAY,SAAS;AAAA,cACnB,kBAAkB,MAAM;AAChB,sBAAA,qBAAqB,KAAK,KAAK,WAAW;AAAA,kBAC9C,CAAC,cAAc,UAAU,MAAM;AAAA,gBACjC;AAEE,oBAAA,mBAAmB,SAAS,SAAS,KACrC,KAAK,KAAK,OAAO,UAAU,kBAC3B;AACgC,kDAAA;AAAA,gBAAA;AAAA,cAClC;AAAA,YACF,CACD;AAAA,UAAA;AAAA,QACH;AAAA,MACF,CACD;AAED,UAAI,CAAC,+BAA+B;AAClC,YAAIC,MAAO,MAAA,SAAQ,KAAK,gCAAgC,EAAE;AAE1D,cAAM,sBAAsBC,oBAAS;AAAA,UACnC,YAAY,SAAS,YAAY,gBAAgB;AAAA,QAAA,EACjD;AACE,YAAA,QAAQ,KAAK,QAAQ,mBAAmB;AAEtC,cAAA,SAASC,4BAAgB,KAAK;AAAA,UAClC,YAAY;AAAA,UACZ,UAAU;AAAA,UACV,gBAAgB;AAAA,QAAA,CACjB;AACD,YAAIF,aAAO;AACDG,8BAAA,MAAM,OAAO,IAAI;AACzB,kBAAQ,IAAI,aAAa,OAAO,OAAO,MAAM;AAAA,QAAA;AAExC,eAAA;AAAA,MAAA;AAGF,aAAA;AAAA,IACT;AAAA,IAEA,iBAAiB,IAAI;AACZ,aAAAC,8BAAwB,IAAI,WAAW,eAAe;AAAA,IAC/D;AAAA,IAEA,MAAM;AAAA,MACJ,eAAeC,UAAQ;AACrB,eAAOA,SAAO;AACD,qBAAAC,OAAAA,UAAU,SAAS,IAAI;AAAA,MAAA;AAAA,IAExC;AAAA,IAEA,SAAS;AACP,aAAO,QAAQ,IAAI;AACN,mBAAAA,OAAAA,UAAU,SAAS,IAAI;AAAA,IACtC;AAAA,IAEA,UAAU;AACR,aAAO,QAAQ,IAAI;AACN,mBAAAA,OAAAA,UAAU,SAAS,IAAI;AAAA,IAAA;AAAA,EAExC;AACF;;"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Config } from './config.cjs';
|
|
2
|
-
import { UnpluginFactory } from 'unplugin';
|
|
3
|
-
/**
|
|
4
|
-
* This plugin adds imports for createFileRoute and createLazyFileRoute to the file route.
|
|
5
|
-
*/
|
|
6
|
-
export declare const unpluginRouteAutoimportFactory: UnpluginFactory<Partial<Config> | undefined>;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const template = require("@babel/template");
|
|
4
|
-
function _interopNamespaceDefault(e) {
|
|
5
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
6
|
-
if (e) {
|
|
7
|
-
for (const k in e) {
|
|
8
|
-
if (k !== "default") {
|
|
9
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
10
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: () => e[k]
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
n.default = e;
|
|
18
|
-
return Object.freeze(n);
|
|
19
|
-
}
|
|
20
|
-
const template__namespace = /* @__PURE__ */ _interopNamespaceDefault(template);
|
|
21
|
-
const routeHmrStatement = template__namespace.statement(
|
|
22
|
-
`
|
|
23
|
-
if (import.meta.hot) {
|
|
24
|
-
import.meta.hot.accept((newModule) => {
|
|
25
|
-
if (newModule.Route && typeof newModule.Route.clone === 'function') {
|
|
26
|
-
newModule.Route.clone(Route)
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
`
|
|
31
|
-
)();
|
|
32
|
-
exports.routeHmrStatement = routeHmrStatement;
|
|
33
|
-
//# sourceMappingURL=route-hmr-statement.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"route-hmr-statement.cjs","sources":["../../../src/core/route-hmr-statement.ts"],"sourcesContent":["import * as template from '@babel/template'\n\nexport const routeHmrStatement = template.statement(\n `\nif (import.meta.hot) {\n import.meta.hot.accept((newModule) => {\n if (newModule.Route && typeof newModule.Route.clone === 'function') {\n newModule.Route.clone(Route)\n }\n })\n}\n`,\n)()\n"],"names":["template"],"mappings":";;;;;;;;;;;;;;;;;;;;AAEO,MAAM,oBAAoBA,oBAAS;AAAA,EACxC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASF,EAAE;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const routeHmrStatement: import('@babel/types').Statement;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const routerUtils = require("@tanstack/router-utils");
|
|
4
|
-
const config = require("./config.cjs");
|
|
5
|
-
const routeHmrStatement = require("./route-hmr-statement.cjs");
|
|
6
|
-
const utils = require("./utils.cjs");
|
|
7
|
-
const unpluginRouterHmrFactory = (options = {}) => {
|
|
8
|
-
let ROOT = process.cwd();
|
|
9
|
-
let userConfig = options;
|
|
10
|
-
return {
|
|
11
|
-
name: "router-hmr-plugin",
|
|
12
|
-
enforce: "pre",
|
|
13
|
-
transform(code, id) {
|
|
14
|
-
if (!code.includes("export const Route = createFileRoute(")) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
if (utils.debug) console.info("Adding HMR handling to route ", id);
|
|
18
|
-
const ast = routerUtils.parseAst({ code });
|
|
19
|
-
ast.program.body.push(routeHmrStatement.routeHmrStatement);
|
|
20
|
-
const result = routerUtils.generateFromAst(ast, {
|
|
21
|
-
sourceMaps: true,
|
|
22
|
-
filename: id,
|
|
23
|
-
sourceFileName: id
|
|
24
|
-
});
|
|
25
|
-
if (utils.debug) {
|
|
26
|
-
routerUtils.logDiff(code, result.code);
|
|
27
|
-
console.log("Output:\n", result.code + "\n\n");
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
},
|
|
31
|
-
transformInclude(id) {
|
|
32
|
-
return utils.fileIsInRoutesDirectory(id, userConfig.routesDirectory);
|
|
33
|
-
},
|
|
34
|
-
vite: {
|
|
35
|
-
configResolved(config$1) {
|
|
36
|
-
ROOT = config$1.root;
|
|
37
|
-
userConfig = config.getConfig(options, ROOT);
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
rspack() {
|
|
41
|
-
ROOT = process.cwd();
|
|
42
|
-
userConfig = config.getConfig(options, ROOT);
|
|
43
|
-
},
|
|
44
|
-
webpack() {
|
|
45
|
-
ROOT = process.cwd();
|
|
46
|
-
userConfig = config.getConfig(options, ROOT);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
exports.unpluginRouterHmrFactory = unpluginRouterHmrFactory;
|
|
51
|
-
//# sourceMappingURL=router-hmr-plugin.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router-hmr-plugin.cjs","sources":["../../../src/core/router-hmr-plugin.ts"],"sourcesContent":["import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'\nimport { getConfig } from './config'\nimport { routeHmrStatement } from './route-hmr-statement'\nimport { debug, fileIsInRoutesDirectory } from './utils'\nimport type { Config } from './config'\nimport type { UnpluginFactory } from 'unplugin'\n\n/**\n * This plugin adds HMR support for file routes.\n * It is only added to the composed plugin in dev when autoCodeSplitting is disabled, since the code splitting plugin\n * handles HMR for code-split routes itself.\n */\nexport const unpluginRouterHmrFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}) => {\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n return {\n name: 'router-hmr-plugin',\n enforce: 'pre',\n\n transform(code, id) {\n if (!code.includes('export const Route = createFileRoute(')) {\n return null\n }\n\n if (debug) console.info('Adding HMR handling to route ', id)\n\n const ast = parseAst({ code })\n ast.program.body.push(routeHmrStatement)\n const result = generateFromAst(ast, {\n sourceMaps: true,\n filename: id,\n sourceFileName: id,\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 transformInclude(id) {\n return fileIsInRoutesDirectory(id, userConfig.routesDirectory)\n },\n\n vite: {\n configResolved(config) {\n ROOT = config.root\n userConfig = getConfig(options, ROOT)\n },\n },\n\n rspack() {\n ROOT = process.cwd()\n userConfig = getConfig(options, ROOT)\n },\n\n webpack() {\n ROOT = process.cwd()\n userConfig = getConfig(options, ROOT)\n },\n }\n}\n"],"names":["debug","parseAst","routeHmrStatement","generateFromAst","logDiff","fileIsInRoutesDirectory","config","getConfig"],"mappings":";;;;;;AAYO,MAAM,2BAET,CAAC,UAAU,OAAO;AAChB,MAAA,OAAe,QAAQ,IAAI;AAC/B,MAAI,aAAa;AAEV,SAAA;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,UAAU,MAAM,IAAI;AAClB,UAAI,CAAC,KAAK,SAAS,uCAAuC,GAAG;AACpD,eAAA;AAAA,MAAA;AAGT,UAAIA,MAAO,MAAA,SAAQ,KAAK,iCAAiC,EAAE;AAE3D,YAAM,MAAMC,YAAAA,SAAS,EAAE,MAAM;AACzB,UAAA,QAAQ,KAAK,KAAKC,kBAAAA,iBAAiB;AACjC,YAAA,SAASC,4BAAgB,KAAK;AAAA,QAClC,YAAY;AAAA,QACZ,UAAU;AAAA,QACV,gBAAgB;AAAA,MAAA,CACjB;AACD,UAAIH,aAAO;AACDI,4BAAA,MAAM,OAAO,IAAI;AACzB,gBAAQ,IAAI,aAAa,OAAO,OAAO,MAAM;AAAA,MAAA;AAExC,aAAA;AAAA,IACT;AAAA,IAEA,iBAAiB,IAAI;AACZ,aAAAC,8BAAwB,IAAI,WAAW,eAAe;AAAA,IAC/D;AAAA,IAEA,MAAM;AAAA,MACJ,eAAeC,UAAQ;AACrB,eAAOA,SAAO;AACD,qBAAAC,OAAAA,UAAU,SAAS,IAAI;AAAA,MAAA;AAAA,IAExC;AAAA,IAEA,SAAS;AACP,aAAO,QAAQ,IAAI;AACN,mBAAAA,OAAAA,UAAU,SAAS,IAAI;AAAA,IACtC;AAAA,IAEA,UAAU;AACR,aAAO,QAAQ,IAAI;AACN,mBAAAA,OAAAA,UAAU,SAAS,IAAI;AAAA,IAAA;AAAA,EAExC;AACF;;"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Config } from './config.cjs';
|
|
2
|
-
import { UnpluginFactory } from 'unplugin';
|
|
3
|
-
/**
|
|
4
|
-
* This plugin adds HMR support for file routes.
|
|
5
|
-
* It is only added to the composed plugin in dev when autoCodeSplitting is disabled, since the code splitting plugin
|
|
6
|
-
* handles HMR for code-split routes itself.
|
|
7
|
-
*/
|
|
8
|
-
export declare const unpluginRouterHmrFactory: UnpluginFactory<Partial<Config> | undefined>;
|
package/dist/cjs/core/utils.cjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const node_path = require("node:path");
|
|
4
|
-
const debug = process.env.TSR_VITE_DEBUG && ["true", "router-plugin"].includes(process.env.TSR_VITE_DEBUG);
|
|
5
|
-
function fileIsInRoutesDirectory(filePath, routesDirectory) {
|
|
6
|
-
const routesDirectoryPath = node_path.isAbsolute(routesDirectory) ? routesDirectory : node_path.join(process.cwd(), routesDirectory);
|
|
7
|
-
const path = node_path.normalize(filePath);
|
|
8
|
-
return path.startsWith(routesDirectoryPath);
|
|
9
|
-
}
|
|
10
|
-
exports.debug = debug;
|
|
11
|
-
exports.fileIsInRoutesDirectory = fileIsInRoutesDirectory;
|
|
12
|
-
//# sourceMappingURL=utils.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sources":["../../../src/core/utils.ts"],"sourcesContent":["import { isAbsolute, join, normalize } from 'node:path'\n\nexport const debug =\n process.env.TSR_VITE_DEBUG &&\n ['true', 'router-plugin'].includes(process.env.TSR_VITE_DEBUG)\n\nexport function fileIsInRoutesDirectory(\n filePath: string,\n routesDirectory: string,\n): boolean {\n const routesDirectoryPath = isAbsolute(routesDirectory)\n ? routesDirectory\n : join(process.cwd(), routesDirectory)\n\n const path = normalize(filePath)\n\n return path.startsWith(routesDirectoryPath)\n}\n"],"names":["isAbsolute","join","normalize"],"mappings":";;;AAEa,MAAA,QACX,QAAQ,IAAI,kBACZ,CAAC,QAAQ,eAAe,EAAE,SAAS,QAAQ,IAAI,cAAc;AAE/C,SAAA,wBACd,UACA,iBACS;AACH,QAAA,sBAAsBA,qBAAW,eAAe,IAClD,kBACAC,UAAAA,KAAK,QAAQ,IAAI,GAAG,eAAe;AAEjC,QAAA,OAAOC,oBAAU,QAAQ;AAExB,SAAA,KAAK,WAAW,mBAAmB;AAC5C;;;"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Config } from './config.js';
|
|
2
|
-
import { UnpluginFactory } from 'unplugin';
|
|
3
|
-
/**
|
|
4
|
-
* This plugin adds imports for createFileRoute and createLazyFileRoute to the file route.
|
|
5
|
-
*/
|
|
6
|
-
export declare const unpluginRouteAutoimportFactory: UnpluginFactory<Partial<Config> | undefined>;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { parseAst, generateFromAst, logDiff } from "@tanstack/router-utils";
|
|
2
|
-
import babel from "@babel/core";
|
|
3
|
-
import * as template from "@babel/template";
|
|
4
|
-
import { getConfig } from "./config.js";
|
|
5
|
-
import { fileIsInRoutesDirectory, debug } from "./utils.js";
|
|
6
|
-
const unpluginRouteAutoimportFactory = (options = {}) => {
|
|
7
|
-
let ROOT = process.cwd();
|
|
8
|
-
let userConfig = options;
|
|
9
|
-
return {
|
|
10
|
-
name: "router-autoimport-plugin",
|
|
11
|
-
enforce: "pre",
|
|
12
|
-
transform(code, id) {
|
|
13
|
-
let routeType;
|
|
14
|
-
if (code.includes("export const Route = createFileRoute(")) {
|
|
15
|
-
routeType = "createFileRoute";
|
|
16
|
-
} else if (code.includes("export const Route = createLazyFileRoute(")) {
|
|
17
|
-
routeType = "createLazyFileRoute";
|
|
18
|
-
} else {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
const routerImportPath = `@tanstack/${userConfig.target}-router`;
|
|
22
|
-
const ast = parseAst({ code });
|
|
23
|
-
let isCreateRouteFunctionImported = false;
|
|
24
|
-
babel.traverse(ast, {
|
|
25
|
-
Program: {
|
|
26
|
-
enter(programPath) {
|
|
27
|
-
programPath.traverse({
|
|
28
|
-
ImportDeclaration(path) {
|
|
29
|
-
const importedSpecifiers = path.node.specifiers.map(
|
|
30
|
-
(specifier) => specifier.local.name
|
|
31
|
-
);
|
|
32
|
-
if (importedSpecifiers.includes(routeType) && path.node.source.value === routerImportPath) {
|
|
33
|
-
isCreateRouteFunctionImported = true;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
if (!isCreateRouteFunctionImported) {
|
|
41
|
-
if (debug) console.info("Adding autoimports to route ", id);
|
|
42
|
-
const autoImportStatement = template.statement(
|
|
43
|
-
`import { ${routeType} } from '${routerImportPath}'`
|
|
44
|
-
)();
|
|
45
|
-
ast.program.body.unshift(autoImportStatement);
|
|
46
|
-
const result = generateFromAst(ast, {
|
|
47
|
-
sourceMaps: true,
|
|
48
|
-
filename: id,
|
|
49
|
-
sourceFileName: id
|
|
50
|
-
});
|
|
51
|
-
if (debug) {
|
|
52
|
-
logDiff(code, result.code);
|
|
53
|
-
console.log("Output:\n", result.code + "\n\n");
|
|
54
|
-
}
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
},
|
|
59
|
-
transformInclude(id) {
|
|
60
|
-
return fileIsInRoutesDirectory(id, userConfig.routesDirectory);
|
|
61
|
-
},
|
|
62
|
-
vite: {
|
|
63
|
-
configResolved(config) {
|
|
64
|
-
ROOT = config.root;
|
|
65
|
-
userConfig = getConfig(options, ROOT);
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
rspack() {
|
|
69
|
-
ROOT = process.cwd();
|
|
70
|
-
userConfig = getConfig(options, ROOT);
|
|
71
|
-
},
|
|
72
|
-
webpack() {
|
|
73
|
-
ROOT = process.cwd();
|
|
74
|
-
userConfig = getConfig(options, ROOT);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
|
-
export {
|
|
79
|
-
unpluginRouteAutoimportFactory
|
|
80
|
-
};
|
|
81
|
-
//# sourceMappingURL=route-autoimport-plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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, fileIsInRoutesDirectory } 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> | undefined\n> = (options = {}) => {\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n return {\n name: 'router-autoimport-plugin',\n enforce: 'pre',\n\n transform(code, id) {\n let routeType: 'createFileRoute' | 'createLazyFileRoute'\n if (code.includes('export const Route = createFileRoute(')) {\n routeType = 'createFileRoute'\n } else if (code.includes('export const Route = 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 ', id)\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: id,\n sourceFileName: id,\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 transformInclude(id) {\n return fileIsInRoutesDirectory(id, userConfig.routesDirectory)\n },\n\n vite: {\n configResolved(config) {\n ROOT = config.root\n userConfig = getConfig(options, ROOT)\n },\n },\n\n rspack() {\n ROOT = process.cwd()\n userConfig = getConfig(options, ROOT)\n },\n\n webpack() {\n ROOT = process.cwd()\n userConfig = getConfig(options, ROOT)\n },\n }\n}\n"],"names":[],"mappings":";;;;;AAWO,MAAM,iCAET,CAAC,UAAU,OAAO;AAChB,MAAA,OAAe,QAAQ,IAAI;AAC/B,MAAI,aAAa;AAEV,SAAA;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,UAAU,MAAM,IAAI;AACd,UAAA;AACA,UAAA,KAAK,SAAS,uCAAuC,GAAG;AAC9C,oBAAA;AAAA,MACH,WAAA,KAAK,SAAS,2CAA2C,GAAG;AACzD,oBAAA;AAAA,MAAA,OACP;AACE,eAAA;AAAA,MAAA;AAGH,YAAA,mBAAmB,aAAa,WAAW,MAAM;AAEvD,YAAM,MAAM,SAAS,EAAE,MAAM;AAE7B,UAAI,gCAAgC;AAEpC,YAAM,SAAS,KAAK;AAAA,QAClB,SAAS;AAAA,UACP,MAAM,aAAa;AACjB,wBAAY,SAAS;AAAA,cACnB,kBAAkB,MAAM;AAChB,sBAAA,qBAAqB,KAAK,KAAK,WAAW;AAAA,kBAC9C,CAAC,cAAc,UAAU,MAAM;AAAA,gBACjC;AAEE,oBAAA,mBAAmB,SAAS,SAAS,KACrC,KAAK,KAAK,OAAO,UAAU,kBAC3B;AACgC,kDAAA;AAAA,gBAAA;AAAA,cAClC;AAAA,YACF,CACD;AAAA,UAAA;AAAA,QACH;AAAA,MACF,CACD;AAED,UAAI,CAAC,+BAA+B;AAClC,YAAI,MAAO,SAAQ,KAAK,gCAAgC,EAAE;AAE1D,cAAM,sBAAsB,SAAS;AAAA,UACnC,YAAY,SAAS,YAAY,gBAAgB;AAAA,QAAA,EACjD;AACE,YAAA,QAAQ,KAAK,QAAQ,mBAAmB;AAEtC,cAAA,SAAS,gBAAgB,KAAK;AAAA,UAClC,YAAY;AAAA,UACZ,UAAU;AAAA,UACV,gBAAgB;AAAA,QAAA,CACjB;AACD,YAAI,OAAO;AACD,kBAAA,MAAM,OAAO,IAAI;AACzB,kBAAQ,IAAI,aAAa,OAAO,OAAO,MAAM;AAAA,QAAA;AAExC,eAAA;AAAA,MAAA;AAGF,aAAA;AAAA,IACT;AAAA,IAEA,iBAAiB,IAAI;AACZ,aAAA,wBAAwB,IAAI,WAAW,eAAe;AAAA,IAC/D;AAAA,IAEA,MAAM;AAAA,MACJ,eAAe,QAAQ;AACrB,eAAO,OAAO;AACD,qBAAA,UAAU,SAAS,IAAI;AAAA,MAAA;AAAA,IAExC;AAAA,IAEA,SAAS;AACP,aAAO,QAAQ,IAAI;AACN,mBAAA,UAAU,SAAS,IAAI;AAAA,IACtC;AAAA,IAEA,UAAU;AACR,aAAO,QAAQ,IAAI;AACN,mBAAA,UAAU,SAAS,IAAI;AAAA,IAAA;AAAA,EAExC;AACF;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const routeHmrStatement: import('@babel/types').Statement;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as template from "@babel/template";
|
|
2
|
-
const routeHmrStatement = template.statement(
|
|
3
|
-
`
|
|
4
|
-
if (import.meta.hot) {
|
|
5
|
-
import.meta.hot.accept((newModule) => {
|
|
6
|
-
if (newModule.Route && typeof newModule.Route.clone === 'function') {
|
|
7
|
-
newModule.Route.clone(Route)
|
|
8
|
-
}
|
|
9
|
-
})
|
|
10
|
-
}
|
|
11
|
-
`
|
|
12
|
-
)();
|
|
13
|
-
export {
|
|
14
|
-
routeHmrStatement
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=route-hmr-statement.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"route-hmr-statement.js","sources":["../../../src/core/route-hmr-statement.ts"],"sourcesContent":["import * as template from '@babel/template'\n\nexport const routeHmrStatement = template.statement(\n `\nif (import.meta.hot) {\n import.meta.hot.accept((newModule) => {\n if (newModule.Route && typeof newModule.Route.clone === 'function') {\n newModule.Route.clone(Route)\n }\n })\n}\n`,\n)()\n"],"names":[],"mappings":";AAEO,MAAM,oBAAoB,SAAS;AAAA,EACxC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASF,EAAE;"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Config } from './config.js';
|
|
2
|
-
import { UnpluginFactory } from 'unplugin';
|
|
3
|
-
/**
|
|
4
|
-
* This plugin adds HMR support for file routes.
|
|
5
|
-
* It is only added to the composed plugin in dev when autoCodeSplitting is disabled, since the code splitting plugin
|
|
6
|
-
* handles HMR for code-split routes itself.
|
|
7
|
-
*/
|
|
8
|
-
export declare const unpluginRouterHmrFactory: UnpluginFactory<Partial<Config> | undefined>;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { parseAst, generateFromAst, logDiff } from "@tanstack/router-utils";
|
|
2
|
-
import { getConfig } from "./config.js";
|
|
3
|
-
import { routeHmrStatement } from "./route-hmr-statement.js";
|
|
4
|
-
import { fileIsInRoutesDirectory, debug } from "./utils.js";
|
|
5
|
-
const unpluginRouterHmrFactory = (options = {}) => {
|
|
6
|
-
let ROOT = process.cwd();
|
|
7
|
-
let userConfig = options;
|
|
8
|
-
return {
|
|
9
|
-
name: "router-hmr-plugin",
|
|
10
|
-
enforce: "pre",
|
|
11
|
-
transform(code, id) {
|
|
12
|
-
if (!code.includes("export const Route = createFileRoute(")) {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
if (debug) console.info("Adding HMR handling to route ", id);
|
|
16
|
-
const ast = parseAst({ code });
|
|
17
|
-
ast.program.body.push(routeHmrStatement);
|
|
18
|
-
const result = generateFromAst(ast, {
|
|
19
|
-
sourceMaps: true,
|
|
20
|
-
filename: id,
|
|
21
|
-
sourceFileName: id
|
|
22
|
-
});
|
|
23
|
-
if (debug) {
|
|
24
|
-
logDiff(code, result.code);
|
|
25
|
-
console.log("Output:\n", result.code + "\n\n");
|
|
26
|
-
}
|
|
27
|
-
return result;
|
|
28
|
-
},
|
|
29
|
-
transformInclude(id) {
|
|
30
|
-
return fileIsInRoutesDirectory(id, userConfig.routesDirectory);
|
|
31
|
-
},
|
|
32
|
-
vite: {
|
|
33
|
-
configResolved(config) {
|
|
34
|
-
ROOT = config.root;
|
|
35
|
-
userConfig = getConfig(options, ROOT);
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
rspack() {
|
|
39
|
-
ROOT = process.cwd();
|
|
40
|
-
userConfig = getConfig(options, ROOT);
|
|
41
|
-
},
|
|
42
|
-
webpack() {
|
|
43
|
-
ROOT = process.cwd();
|
|
44
|
-
userConfig = getConfig(options, ROOT);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
export {
|
|
49
|
-
unpluginRouterHmrFactory
|
|
50
|
-
};
|
|
51
|
-
//# sourceMappingURL=router-hmr-plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router-hmr-plugin.js","sources":["../../../src/core/router-hmr-plugin.ts"],"sourcesContent":["import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'\nimport { getConfig } from './config'\nimport { routeHmrStatement } from './route-hmr-statement'\nimport { debug, fileIsInRoutesDirectory } from './utils'\nimport type { Config } from './config'\nimport type { UnpluginFactory } from 'unplugin'\n\n/**\n * This plugin adds HMR support for file routes.\n * It is only added to the composed plugin in dev when autoCodeSplitting is disabled, since the code splitting plugin\n * handles HMR for code-split routes itself.\n */\nexport const unpluginRouterHmrFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}) => {\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n return {\n name: 'router-hmr-plugin',\n enforce: 'pre',\n\n transform(code, id) {\n if (!code.includes('export const Route = createFileRoute(')) {\n return null\n }\n\n if (debug) console.info('Adding HMR handling to route ', id)\n\n const ast = parseAst({ code })\n ast.program.body.push(routeHmrStatement)\n const result = generateFromAst(ast, {\n sourceMaps: true,\n filename: id,\n sourceFileName: id,\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 transformInclude(id) {\n return fileIsInRoutesDirectory(id, userConfig.routesDirectory)\n },\n\n vite: {\n configResolved(config) {\n ROOT = config.root\n userConfig = getConfig(options, ROOT)\n },\n },\n\n rspack() {\n ROOT = process.cwd()\n userConfig = getConfig(options, ROOT)\n },\n\n webpack() {\n ROOT = process.cwd()\n userConfig = getConfig(options, ROOT)\n },\n }\n}\n"],"names":[],"mappings":";;;;AAYO,MAAM,2BAET,CAAC,UAAU,OAAO;AAChB,MAAA,OAAe,QAAQ,IAAI;AAC/B,MAAI,aAAa;AAEV,SAAA;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,UAAU,MAAM,IAAI;AAClB,UAAI,CAAC,KAAK,SAAS,uCAAuC,GAAG;AACpD,eAAA;AAAA,MAAA;AAGT,UAAI,MAAO,SAAQ,KAAK,iCAAiC,EAAE;AAE3D,YAAM,MAAM,SAAS,EAAE,MAAM;AACzB,UAAA,QAAQ,KAAK,KAAK,iBAAiB;AACjC,YAAA,SAAS,gBAAgB,KAAK;AAAA,QAClC,YAAY;AAAA,QACZ,UAAU;AAAA,QACV,gBAAgB;AAAA,MAAA,CACjB;AACD,UAAI,OAAO;AACD,gBAAA,MAAM,OAAO,IAAI;AACzB,gBAAQ,IAAI,aAAa,OAAO,OAAO,MAAM;AAAA,MAAA;AAExC,aAAA;AAAA,IACT;AAAA,IAEA,iBAAiB,IAAI;AACZ,aAAA,wBAAwB,IAAI,WAAW,eAAe;AAAA,IAC/D;AAAA,IAEA,MAAM;AAAA,MACJ,eAAe,QAAQ;AACrB,eAAO,OAAO;AACD,qBAAA,UAAU,SAAS,IAAI;AAAA,MAAA;AAAA,IAExC;AAAA,IAEA,SAAS;AACP,aAAO,QAAQ,IAAI;AACN,mBAAA,UAAU,SAAS,IAAI;AAAA,IACtC;AAAA,IAEA,UAAU;AACR,aAAO,QAAQ,IAAI;AACN,mBAAA,UAAU,SAAS,IAAI;AAAA,IAAA;AAAA,EAExC;AACF;"}
|
package/dist/esm/core/utils.d.ts
DELETED
package/dist/esm/core/utils.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { isAbsolute, join, normalize } from "node:path";
|
|
2
|
-
const debug = process.env.TSR_VITE_DEBUG && ["true", "router-plugin"].includes(process.env.TSR_VITE_DEBUG);
|
|
3
|
-
function fileIsInRoutesDirectory(filePath, routesDirectory) {
|
|
4
|
-
const routesDirectoryPath = isAbsolute(routesDirectory) ? routesDirectory : join(process.cwd(), routesDirectory);
|
|
5
|
-
const path = normalize(filePath);
|
|
6
|
-
return path.startsWith(routesDirectoryPath);
|
|
7
|
-
}
|
|
8
|
-
export {
|
|
9
|
-
debug,
|
|
10
|
-
fileIsInRoutesDirectory
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/core/utils.ts"],"sourcesContent":["import { isAbsolute, join, normalize } from 'node:path'\n\nexport const debug =\n process.env.TSR_VITE_DEBUG &&\n ['true', 'router-plugin'].includes(process.env.TSR_VITE_DEBUG)\n\nexport function fileIsInRoutesDirectory(\n filePath: string,\n routesDirectory: string,\n): boolean {\n const routesDirectoryPath = isAbsolute(routesDirectory)\n ? routesDirectory\n : join(process.cwd(), routesDirectory)\n\n const path = normalize(filePath)\n\n return path.startsWith(routesDirectoryPath)\n}\n"],"names":[],"mappings":";AAEa,MAAA,QACX,QAAQ,IAAI,kBACZ,CAAC,QAAQ,eAAe,EAAE,SAAS,QAAQ,IAAI,cAAc;AAE/C,SAAA,wBACd,UACA,iBACS;AACH,QAAA,sBAAsB,WAAW,eAAe,IAClD,kBACA,KAAK,QAAQ,IAAI,GAAG,eAAe;AAEjC,QAAA,OAAO,UAAU,QAAQ;AAExB,SAAA,KAAK,WAAW,mBAAmB;AAC5C;"}
|