@tanstack/router-vite-plugin 1.39.3 → 1.39.5
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/index.cjs +7 -199
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -64
- package/dist/esm/index.d.ts +2 -64
- package/dist/esm/index.js +1 -202
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -18
- package/src/index.ts +2 -225
- package/dist/cjs/compilers.cjs +0 -359
- package/dist/cjs/compilers.cjs.map +0 -1
- package/dist/cjs/compilers.d.cts +0 -38
- package/dist/cjs/constants.cjs +0 -5
- package/dist/cjs/constants.cjs.map +0 -1
- package/dist/cjs/constants.d.cts +0 -1
- package/dist/cjs/eliminateUnreferencedIdentifiers.cjs +0 -149
- package/dist/cjs/eliminateUnreferencedIdentifiers.cjs.map +0 -1
- package/dist/cjs/eliminateUnreferencedIdentifiers.d.cts +0 -9
- package/dist/esm/compilers.d.ts +0 -38
- package/dist/esm/compilers.js +0 -340
- package/dist/esm/compilers.js.map +0 -1
- package/dist/esm/constants.d.ts +0 -1
- package/dist/esm/constants.js +0 -5
- package/dist/esm/constants.js.map +0 -1
- package/dist/esm/eliminateUnreferencedIdentifiers.d.ts +0 -9
- package/dist/esm/eliminateUnreferencedIdentifiers.js +0 -132
- package/dist/esm/eliminateUnreferencedIdentifiers.js.map +0 -1
- package/src/compilers.ts +0 -462
- package/src/constants.ts +0 -1
- package/src/eliminateUnreferencedIdentifiers.ts +0 -211
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,203 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
enableRouteGeneration: zod.z.boolean().optional(),
|
|
11
|
-
experimental: zod.z.object({
|
|
12
|
-
enableCodeSplitting: zod.z.boolean().optional()
|
|
13
|
-
}).optional()
|
|
3
|
+
const vite = require("@tanstack/router-plugin/vite");
|
|
4
|
+
Object.keys(vite).forEach((k) => {
|
|
5
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k))
|
|
6
|
+
Object.defineProperty(exports, k, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: () => vite[k]
|
|
9
|
+
});
|
|
14
10
|
});
|
|
15
|
-
const CONFIG_FILE_NAME = "tsr.config.json";
|
|
16
|
-
const debug = Boolean(process.env.TSR_VITE_DEBUG);
|
|
17
|
-
const getConfig = async (inlineConfig, root) => {
|
|
18
|
-
const config = await routerGenerator.getConfig(inlineConfig, root);
|
|
19
|
-
return configSchema.parse({ ...config, ...inlineConfig });
|
|
20
|
-
};
|
|
21
|
-
function TanStackRouterVite(inlineConfig = {}) {
|
|
22
|
-
return [
|
|
23
|
-
TanStackRouterViteGenerator(inlineConfig),
|
|
24
|
-
TanStackRouterViteCodeSplitter(inlineConfig)
|
|
25
|
-
];
|
|
26
|
-
}
|
|
27
|
-
let lock = false;
|
|
28
|
-
function TanStackRouterViteGenerator(inlineConfig = {}) {
|
|
29
|
-
let ROOT = process.cwd();
|
|
30
|
-
let userConfig;
|
|
31
|
-
const generate = async () => {
|
|
32
|
-
if (lock) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
lock = true;
|
|
36
|
-
try {
|
|
37
|
-
await routerGenerator.generator(userConfig);
|
|
38
|
-
} catch (err) {
|
|
39
|
-
console.error(err);
|
|
40
|
-
console.info();
|
|
41
|
-
}
|
|
42
|
-
lock = false;
|
|
43
|
-
};
|
|
44
|
-
const handleFile = async (file, event) => {
|
|
45
|
-
const filePath = path.normalize(file);
|
|
46
|
-
if (filePath === path.join(ROOT, CONFIG_FILE_NAME)) {
|
|
47
|
-
userConfig = await getConfig(inlineConfig, ROOT);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
if (event === "update" && filePath === path.resolve(userConfig.generatedRouteTree)) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const routesDirectoryPath = path.isAbsolute(userConfig.routesDirectory) ? userConfig.routesDirectory : path.join(ROOT, userConfig.routesDirectory);
|
|
54
|
-
if (filePath.startsWith(routesDirectoryPath)) {
|
|
55
|
-
await generate();
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
return {
|
|
59
|
-
name: "vite-plugin-tanstack-router-generator",
|
|
60
|
-
configResolved: async (config) => {
|
|
61
|
-
ROOT = process.cwd();
|
|
62
|
-
userConfig = await getConfig(inlineConfig, ROOT);
|
|
63
|
-
if (userConfig.enableRouteGeneration ?? true) {
|
|
64
|
-
await generate();
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
watchChange: async (file, context) => {
|
|
68
|
-
if (userConfig.enableRouteGeneration ?? true) {
|
|
69
|
-
if (["create", "update", "delete"].includes(context.event)) {
|
|
70
|
-
await handleFile(file, context.event);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
function fileIsInRoutesDirectory(filePath, routesDirectory) {
|
|
77
|
-
const routesDirectoryPath = path.isAbsolute(routesDirectory) ? routesDirectory : path.join(process.cwd(), routesDirectory);
|
|
78
|
-
return filePath.startsWith(routesDirectoryPath);
|
|
79
|
-
}
|
|
80
|
-
function TanStackRouterViteCodeSplitter(inlineConfig = {}) {
|
|
81
|
-
let ROOT = process.cwd();
|
|
82
|
-
let userConfig;
|
|
83
|
-
return {
|
|
84
|
-
name: "vite-plugin-tanstack-router-code-splitter",
|
|
85
|
-
enforce: "pre",
|
|
86
|
-
configResolved: async (config) => {
|
|
87
|
-
ROOT = config.root;
|
|
88
|
-
userConfig = await getConfig(inlineConfig, ROOT);
|
|
89
|
-
},
|
|
90
|
-
resolveId(source) {
|
|
91
|
-
var _a;
|
|
92
|
-
if (!((_a = userConfig.experimental) == null ? void 0 : _a.enableCodeSplitting)) {
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
if (source.startsWith(constants.splitPrefix + ":")) {
|
|
96
|
-
return source.replace(constants.splitPrefix + ":", "");
|
|
97
|
-
}
|
|
98
|
-
return null;
|
|
99
|
-
},
|
|
100
|
-
async transform(code, id, transformOptions) {
|
|
101
|
-
var _a;
|
|
102
|
-
if (!((_a = userConfig.experimental) == null ? void 0 : _a.enableCodeSplitting)) {
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
const url$1 = url.pathToFileURL(id);
|
|
106
|
-
url$1.searchParams.delete("v");
|
|
107
|
-
id = url.fileURLToPath(url$1).replace(/\\/g, "/");
|
|
108
|
-
const compile = compilers.makeCompile({
|
|
109
|
-
root: ROOT
|
|
110
|
-
});
|
|
111
|
-
if (id.includes(constants.splitPrefix)) {
|
|
112
|
-
if (debug)
|
|
113
|
-
console.info("Splitting route: ", id);
|
|
114
|
-
const compiled = await compilers.splitFile({
|
|
115
|
-
code,
|
|
116
|
-
compile,
|
|
117
|
-
filename: id
|
|
118
|
-
// ref,
|
|
119
|
-
});
|
|
120
|
-
if (debug)
|
|
121
|
-
console.info("");
|
|
122
|
-
if (debug)
|
|
123
|
-
console.info("Split Output");
|
|
124
|
-
if (debug)
|
|
125
|
-
console.info("");
|
|
126
|
-
if (debug)
|
|
127
|
-
console.info(compiled.code);
|
|
128
|
-
if (debug)
|
|
129
|
-
console.info("");
|
|
130
|
-
if (debug)
|
|
131
|
-
console.info("");
|
|
132
|
-
if (debug)
|
|
133
|
-
console.info("");
|
|
134
|
-
if (debug)
|
|
135
|
-
console.info("");
|
|
136
|
-
if (debug)
|
|
137
|
-
console.info("");
|
|
138
|
-
if (debug)
|
|
139
|
-
console.info("");
|
|
140
|
-
if (debug)
|
|
141
|
-
console.info("");
|
|
142
|
-
if (debug)
|
|
143
|
-
console.info("");
|
|
144
|
-
return compiled;
|
|
145
|
-
} else if (fileIsInRoutesDirectory(id, userConfig.routesDirectory) && (code.includes("createRoute(") || code.includes("createFileRoute("))) {
|
|
146
|
-
if (code.includes("@react-refresh")) {
|
|
147
|
-
throw new Error(
|
|
148
|
-
`We detected that the '@vitejs/plugin-react' was passed before '@tanstack/router-vite-plugin'. Please make sure that '@tanstack/router-vite-plugin' is passed before '@vitejs/plugin-react' and try again:
|
|
149
|
-
e.g.
|
|
150
|
-
|
|
151
|
-
plugins: [
|
|
152
|
-
TanStackRouterVite(), // Place this before viteReact()
|
|
153
|
-
viteReact(),
|
|
154
|
-
]
|
|
155
|
-
`
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
if (debug)
|
|
159
|
-
console.info("Handling createRoute: ", id);
|
|
160
|
-
const compiled = await compilers.compileFile({
|
|
161
|
-
code,
|
|
162
|
-
compile,
|
|
163
|
-
filename: id
|
|
164
|
-
});
|
|
165
|
-
if (debug)
|
|
166
|
-
console.info("");
|
|
167
|
-
if (debug)
|
|
168
|
-
console.info("Compiled Output");
|
|
169
|
-
if (debug)
|
|
170
|
-
console.info("");
|
|
171
|
-
if (debug)
|
|
172
|
-
console.info(compiled.code);
|
|
173
|
-
if (debug)
|
|
174
|
-
console.info("");
|
|
175
|
-
if (debug)
|
|
176
|
-
console.info("");
|
|
177
|
-
if (debug)
|
|
178
|
-
console.info("");
|
|
179
|
-
if (debug)
|
|
180
|
-
console.info("");
|
|
181
|
-
if (debug)
|
|
182
|
-
console.info("");
|
|
183
|
-
if (debug)
|
|
184
|
-
console.info("");
|
|
185
|
-
if (debug)
|
|
186
|
-
console.info("");
|
|
187
|
-
if (debug)
|
|
188
|
-
console.info("");
|
|
189
|
-
if (debug)
|
|
190
|
-
console.info("");
|
|
191
|
-
if (debug)
|
|
192
|
-
console.info("");
|
|
193
|
-
return compiled;
|
|
194
|
-
}
|
|
195
|
-
return null;
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
exports.TanStackRouterVite = TanStackRouterVite;
|
|
200
|
-
exports.TanStackRouterViteCodeSplitter = TanStackRouterViteCodeSplitter;
|
|
201
|
-
exports.TanStackRouterViteGenerator = TanStackRouterViteGenerator;
|
|
202
|
-
exports.configSchema = configSchema;
|
|
203
11
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/index.ts"],"sourcesContent":["import { isAbsolute, join, normalize, resolve } from 'path'\nimport { fileURLToPath, pathToFileURL } from 'url'\nimport { z } from 'zod'\nimport {\n generator,\n configSchema as generatorConfigSchema,\n getConfig as getGeneratorConfig,\n} from '@tanstack/router-generator'\nimport { compileFile, makeCompile, splitFile } from './compilers'\nimport { splitPrefix } from './constants'\nimport type { Plugin } from 'vite'\n\nexport const configSchema = generatorConfigSchema.extend({\n enableRouteGeneration: z.boolean().optional(),\n experimental: z\n .object({\n enableCodeSplitting: z.boolean().optional(),\n })\n .optional(),\n})\n\nexport type Config = z.infer<typeof configSchema>\n\nconst CONFIG_FILE_NAME = 'tsr.config.json'\nconst debug = Boolean(process.env.TSR_VITE_DEBUG)\n\nconst getConfig = async (inlineConfig: Partial<Config>, root: string) => {\n const config = await getGeneratorConfig(inlineConfig, root)\n\n return configSchema.parse({ ...config, ...inlineConfig })\n}\n\nexport function TanStackRouterVite(\n inlineConfig: Partial<Config> = {},\n): Array<Plugin> {\n return [\n TanStackRouterViteGenerator(inlineConfig),\n TanStackRouterViteCodeSplitter(inlineConfig),\n ]\n}\n\nlet lock = false\n\nexport function TanStackRouterViteGenerator(\n inlineConfig: Partial<Config> = {},\n): Plugin {\n let ROOT: string = process.cwd()\n let userConfig: Config\n\n const generate = async () => {\n if (lock) {\n return\n }\n lock = true\n try {\n await generator(userConfig)\n } catch (err) {\n console.error(err)\n console.info()\n }\n lock = false\n }\n\n const handleFile = async (\n file: string,\n event: 'create' | 'update' | 'delete',\n ) => {\n const filePath = normalize(file)\n\n if (filePath === join(ROOT, CONFIG_FILE_NAME)) {\n userConfig = await getConfig(inlineConfig, ROOT)\n return\n }\n\n if (\n event === 'update' &&\n filePath === resolve(userConfig.generatedRouteTree)\n ) {\n // skip generating routes if the generated route tree is updated\n return\n }\n\n const routesDirectoryPath = isAbsolute(userConfig.routesDirectory)\n ? userConfig.routesDirectory\n : join(ROOT, userConfig.routesDirectory)\n\n if (filePath.startsWith(routesDirectoryPath)) {\n await generate()\n }\n }\n\n return {\n name: 'vite-plugin-tanstack-router-generator',\n configResolved: async (config) => {\n ROOT = process.cwd()\n userConfig = await getConfig(inlineConfig, ROOT)\n if (userConfig.enableRouteGeneration ?? true) {\n await generate()\n }\n },\n watchChange: async (file, context) => {\n if (userConfig.enableRouteGeneration ?? true) {\n if (['create', 'update', 'delete'].includes(context.event)) {\n await handleFile(file, context.event)\n }\n }\n },\n }\n}\n\nfunction fileIsInRoutesDirectory(filePath: string, routesDirectory: string) {\n const routesDirectoryPath = isAbsolute(routesDirectory)\n ? routesDirectory\n : join(process.cwd(), routesDirectory)\n\n return filePath.startsWith(routesDirectoryPath)\n}\n\nexport function TanStackRouterViteCodeSplitter(\n inlineConfig: Partial<Config> = {},\n): Plugin {\n let ROOT: string = process.cwd()\n let userConfig: Config\n\n return {\n name: 'vite-plugin-tanstack-router-code-splitter',\n enforce: 'pre',\n configResolved: async (config) => {\n ROOT = config.root\n userConfig = await getConfig(inlineConfig, ROOT)\n },\n resolveId(source) {\n if (!userConfig.experimental?.enableCodeSplitting) {\n return null\n }\n\n if (source.startsWith(splitPrefix + ':')) {\n return source.replace(splitPrefix + ':', '')\n }\n return null\n },\n async transform(code, id, transformOptions) {\n if (!userConfig.experimental?.enableCodeSplitting) {\n return null\n }\n\n const url = pathToFileURL(id)\n url.searchParams.delete('v')\n id = fileURLToPath(url).replace(/\\\\/g, '/')\n\n const compile = makeCompile({\n root: ROOT,\n })\n\n if (id.includes(splitPrefix)) {\n if (debug) console.info('Splitting route: ', id)\n // const ref = new URLSearchParams(id.split('?')[1]).get('ref') || ''\n\n const compiled = await splitFile({\n code,\n compile,\n filename: id,\n // ref,\n })\n\n if (debug) console.info('')\n if (debug) console.info('Split Output')\n if (debug) console.info('')\n if (debug) console.info(compiled.code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n return compiled\n } else if (\n fileIsInRoutesDirectory(id, userConfig.routesDirectory) &&\n (code.includes('createRoute(') || code.includes('createFileRoute('))\n ) {\n if (code.includes('@react-refresh')) {\n throw new Error(\n `We detected that the '@vitejs/plugin-react' was passed before '@tanstack/router-vite-plugin'. Please make sure that '@tanstack/router-vite-plugin' is passed before '@vitejs/plugin-react' and try again: \ne.g.\n\nplugins: [\n TanStackRouterVite(), // Place this before viteReact()\n viteReact(),\n]\n`,\n )\n }\n\n if (debug) console.info('Handling createRoute: ', id)\n const compiled = await compileFile({\n code,\n compile,\n filename: id,\n })\n\n if (debug) console.info('')\n if (debug) console.info('Compiled Output')\n if (debug) console.info('')\n if (debug) console.info(compiled.code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n return compiled\n }\n\n return null\n },\n }\n}\n"],"names":["generatorConfigSchema","z","getGeneratorConfig","generator","normalize","join","resolve","isAbsolute","splitPrefix","url","pathToFileURL","fileURLToPath","makeCompile","splitFile","compileFile"],"mappings":";;;;;;;;AAYa,MAAA,eAAeA,6BAAsB,OAAO;AAAA,EACvD,uBAAuBC,IAAA,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC5C,cAAcA,MACX,OAAO;AAAA,IACN,qBAAqBA,IAAA,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC3C,CAAA,EACA,SAAS;AACd,CAAC;AAID,MAAM,mBAAmB;AACzB,MAAM,QAAQ,QAA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,EAAE;AACtB,YAAA;AAAO,kBAAQ,KAAK,EAAE;AACtB,YAAA;AAAO,kBAAQ,KAAK,EAAE;AACtB,YAAA;AAAO,kBAAQ,KAAK,EAAE;AACtB,YAAA;AAAO,kBAAQ,KAAK,EAAE;AACtB,YAAA;AAAO,kBAAQ,KAAK,EAAE;AACtB,YAAA;AAAO,kBAAQ,KAAK,EAAE;AAEnB,eAAA;AAAA,MACT;AAEO,aAAA;AAAA,IACT;AAAA,EAAA;AAEJ;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,64 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare const configSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
5
|
-
routeFilePrefix: z.ZodOptional<z.ZodString>;
|
|
6
|
-
routeFileIgnorePrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
7
|
-
routeFileIgnorePattern: z.ZodOptional<z.ZodString>;
|
|
8
|
-
routesDirectory: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
9
|
-
generatedRouteTree: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
10
|
-
quoteStyle: z.ZodDefault<z.ZodOptional<z.ZodEnum<["single", "double"]>>>;
|
|
11
|
-
semicolons: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
12
|
-
disableTypes: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
13
|
-
addExtensions: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
14
|
-
disableLogging: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
15
|
-
routeTreeFileHeader: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
16
|
-
routeTreeFileFooter: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
17
|
-
}, {
|
|
18
|
-
enableRouteGeneration: z.ZodOptional<z.ZodBoolean>;
|
|
19
|
-
experimental: z.ZodOptional<z.ZodObject<{
|
|
20
|
-
enableCodeSplitting: z.ZodOptional<z.ZodBoolean>;
|
|
21
|
-
}, "strip", z.ZodTypeAny, {
|
|
22
|
-
enableCodeSplitting?: boolean | undefined;
|
|
23
|
-
}, {
|
|
24
|
-
enableCodeSplitting?: boolean | undefined;
|
|
25
|
-
}>>;
|
|
26
|
-
}>, "strip", z.ZodTypeAny, {
|
|
27
|
-
routeFileIgnorePrefix: string;
|
|
28
|
-
routesDirectory: string;
|
|
29
|
-
generatedRouteTree: string;
|
|
30
|
-
quoteStyle: "single" | "double";
|
|
31
|
-
semicolons: boolean;
|
|
32
|
-
disableTypes: boolean;
|
|
33
|
-
addExtensions: boolean;
|
|
34
|
-
disableLogging: boolean;
|
|
35
|
-
routeTreeFileHeader: string[];
|
|
36
|
-
routeTreeFileFooter: string[];
|
|
37
|
-
enableRouteGeneration?: boolean | undefined;
|
|
38
|
-
experimental?: {
|
|
39
|
-
enableCodeSplitting?: boolean | undefined;
|
|
40
|
-
} | undefined;
|
|
41
|
-
routeFilePrefix?: string | undefined;
|
|
42
|
-
routeFileIgnorePattern?: string | undefined;
|
|
43
|
-
}, {
|
|
44
|
-
enableRouteGeneration?: boolean | undefined;
|
|
45
|
-
experimental?: {
|
|
46
|
-
enableCodeSplitting?: boolean | undefined;
|
|
47
|
-
} | undefined;
|
|
48
|
-
routeFilePrefix?: string | undefined;
|
|
49
|
-
routeFileIgnorePrefix?: string | undefined;
|
|
50
|
-
routeFileIgnorePattern?: string | undefined;
|
|
51
|
-
routesDirectory?: string | undefined;
|
|
52
|
-
generatedRouteTree?: string | undefined;
|
|
53
|
-
quoteStyle?: "single" | "double" | undefined;
|
|
54
|
-
semicolons?: boolean | undefined;
|
|
55
|
-
disableTypes?: boolean | undefined;
|
|
56
|
-
addExtensions?: boolean | undefined;
|
|
57
|
-
disableLogging?: boolean | undefined;
|
|
58
|
-
routeTreeFileHeader?: string[] | undefined;
|
|
59
|
-
routeTreeFileFooter?: string[] | undefined;
|
|
60
|
-
}>;
|
|
61
|
-
export type Config = z.infer<typeof configSchema>;
|
|
62
|
-
export declare function TanStackRouterVite(inlineConfig?: Partial<Config>): Array<Plugin>;
|
|
63
|
-
export declare function TanStackRouterViteGenerator(inlineConfig?: Partial<Config>): Plugin;
|
|
64
|
-
export declare function TanStackRouterViteCodeSplitter(inlineConfig?: Partial<Config>): Plugin;
|
|
1
|
+
export * from '@tanstack/router-plugin/vite';
|
|
2
|
+
export type * from '@tanstack/router-plugin/vite';
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,64 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare const configSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
5
|
-
routeFilePrefix: z.ZodOptional<z.ZodString>;
|
|
6
|
-
routeFileIgnorePrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
7
|
-
routeFileIgnorePattern: z.ZodOptional<z.ZodString>;
|
|
8
|
-
routesDirectory: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
9
|
-
generatedRouteTree: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
10
|
-
quoteStyle: z.ZodDefault<z.ZodOptional<z.ZodEnum<["single", "double"]>>>;
|
|
11
|
-
semicolons: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
12
|
-
disableTypes: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
13
|
-
addExtensions: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
14
|
-
disableLogging: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
15
|
-
routeTreeFileHeader: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
16
|
-
routeTreeFileFooter: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
17
|
-
}, {
|
|
18
|
-
enableRouteGeneration: z.ZodOptional<z.ZodBoolean>;
|
|
19
|
-
experimental: z.ZodOptional<z.ZodObject<{
|
|
20
|
-
enableCodeSplitting: z.ZodOptional<z.ZodBoolean>;
|
|
21
|
-
}, "strip", z.ZodTypeAny, {
|
|
22
|
-
enableCodeSplitting?: boolean | undefined;
|
|
23
|
-
}, {
|
|
24
|
-
enableCodeSplitting?: boolean | undefined;
|
|
25
|
-
}>>;
|
|
26
|
-
}>, "strip", z.ZodTypeAny, {
|
|
27
|
-
routeFileIgnorePrefix: string;
|
|
28
|
-
routesDirectory: string;
|
|
29
|
-
generatedRouteTree: string;
|
|
30
|
-
quoteStyle: "single" | "double";
|
|
31
|
-
semicolons: boolean;
|
|
32
|
-
disableTypes: boolean;
|
|
33
|
-
addExtensions: boolean;
|
|
34
|
-
disableLogging: boolean;
|
|
35
|
-
routeTreeFileHeader: string[];
|
|
36
|
-
routeTreeFileFooter: string[];
|
|
37
|
-
enableRouteGeneration?: boolean | undefined;
|
|
38
|
-
experimental?: {
|
|
39
|
-
enableCodeSplitting?: boolean | undefined;
|
|
40
|
-
} | undefined;
|
|
41
|
-
routeFilePrefix?: string | undefined;
|
|
42
|
-
routeFileIgnorePattern?: string | undefined;
|
|
43
|
-
}, {
|
|
44
|
-
enableRouteGeneration?: boolean | undefined;
|
|
45
|
-
experimental?: {
|
|
46
|
-
enableCodeSplitting?: boolean | undefined;
|
|
47
|
-
} | undefined;
|
|
48
|
-
routeFilePrefix?: string | undefined;
|
|
49
|
-
routeFileIgnorePrefix?: string | undefined;
|
|
50
|
-
routeFileIgnorePattern?: string | undefined;
|
|
51
|
-
routesDirectory?: string | undefined;
|
|
52
|
-
generatedRouteTree?: string | undefined;
|
|
53
|
-
quoteStyle?: "single" | "double" | undefined;
|
|
54
|
-
semicolons?: boolean | undefined;
|
|
55
|
-
disableTypes?: boolean | undefined;
|
|
56
|
-
addExtensions?: boolean | undefined;
|
|
57
|
-
disableLogging?: boolean | undefined;
|
|
58
|
-
routeTreeFileHeader?: string[] | undefined;
|
|
59
|
-
routeTreeFileFooter?: string[] | undefined;
|
|
60
|
-
}>;
|
|
61
|
-
export type Config = z.infer<typeof configSchema>;
|
|
62
|
-
export declare function TanStackRouterVite(inlineConfig?: Partial<Config>): Array<Plugin>;
|
|
63
|
-
export declare function TanStackRouterViteGenerator(inlineConfig?: Partial<Config>): Plugin;
|
|
64
|
-
export declare function TanStackRouterViteCodeSplitter(inlineConfig?: Partial<Config>): Plugin;
|
|
1
|
+
export * from '@tanstack/router-plugin/vite';
|
|
2
|
+
export type * from '@tanstack/router-plugin/vite';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,203 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { pathToFileURL, fileURLToPath } from "url";
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
import { configSchema as configSchema$1, getConfig as getConfig$1, generator } from "@tanstack/router-generator";
|
|
5
|
-
import { splitFile, compileFile, makeCompile } from "./compilers.js";
|
|
6
|
-
import { splitPrefix } from "./constants.js";
|
|
7
|
-
const configSchema = configSchema$1.extend({
|
|
8
|
-
enableRouteGeneration: z.boolean().optional(),
|
|
9
|
-
experimental: z.object({
|
|
10
|
-
enableCodeSplitting: z.boolean().optional()
|
|
11
|
-
}).optional()
|
|
12
|
-
});
|
|
13
|
-
const CONFIG_FILE_NAME = "tsr.config.json";
|
|
14
|
-
const debug = Boolean(process.env.TSR_VITE_DEBUG);
|
|
15
|
-
const getConfig = async (inlineConfig, root) => {
|
|
16
|
-
const config = await getConfig$1(inlineConfig, root);
|
|
17
|
-
return configSchema.parse({ ...config, ...inlineConfig });
|
|
18
|
-
};
|
|
19
|
-
function TanStackRouterVite(inlineConfig = {}) {
|
|
20
|
-
return [
|
|
21
|
-
TanStackRouterViteGenerator(inlineConfig),
|
|
22
|
-
TanStackRouterViteCodeSplitter(inlineConfig)
|
|
23
|
-
];
|
|
24
|
-
}
|
|
25
|
-
let lock = false;
|
|
26
|
-
function TanStackRouterViteGenerator(inlineConfig = {}) {
|
|
27
|
-
let ROOT = process.cwd();
|
|
28
|
-
let userConfig;
|
|
29
|
-
const generate = async () => {
|
|
30
|
-
if (lock) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
lock = true;
|
|
34
|
-
try {
|
|
35
|
-
await generator(userConfig);
|
|
36
|
-
} catch (err) {
|
|
37
|
-
console.error(err);
|
|
38
|
-
console.info();
|
|
39
|
-
}
|
|
40
|
-
lock = false;
|
|
41
|
-
};
|
|
42
|
-
const handleFile = async (file, event) => {
|
|
43
|
-
const filePath = normalize(file);
|
|
44
|
-
if (filePath === join(ROOT, CONFIG_FILE_NAME)) {
|
|
45
|
-
userConfig = await getConfig(inlineConfig, ROOT);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
if (event === "update" && filePath === resolve(userConfig.generatedRouteTree)) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const routesDirectoryPath = isAbsolute(userConfig.routesDirectory) ? userConfig.routesDirectory : join(ROOT, userConfig.routesDirectory);
|
|
52
|
-
if (filePath.startsWith(routesDirectoryPath)) {
|
|
53
|
-
await generate();
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
return {
|
|
57
|
-
name: "vite-plugin-tanstack-router-generator",
|
|
58
|
-
configResolved: async (config) => {
|
|
59
|
-
ROOT = process.cwd();
|
|
60
|
-
userConfig = await getConfig(inlineConfig, ROOT);
|
|
61
|
-
if (userConfig.enableRouteGeneration ?? true) {
|
|
62
|
-
await generate();
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
watchChange: async (file, context) => {
|
|
66
|
-
if (userConfig.enableRouteGeneration ?? true) {
|
|
67
|
-
if (["create", "update", "delete"].includes(context.event)) {
|
|
68
|
-
await handleFile(file, context.event);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
function fileIsInRoutesDirectory(filePath, routesDirectory) {
|
|
75
|
-
const routesDirectoryPath = isAbsolute(routesDirectory) ? routesDirectory : join(process.cwd(), routesDirectory);
|
|
76
|
-
return filePath.startsWith(routesDirectoryPath);
|
|
77
|
-
}
|
|
78
|
-
function TanStackRouterViteCodeSplitter(inlineConfig = {}) {
|
|
79
|
-
let ROOT = process.cwd();
|
|
80
|
-
let userConfig;
|
|
81
|
-
return {
|
|
82
|
-
name: "vite-plugin-tanstack-router-code-splitter",
|
|
83
|
-
enforce: "pre",
|
|
84
|
-
configResolved: async (config) => {
|
|
85
|
-
ROOT = config.root;
|
|
86
|
-
userConfig = await getConfig(inlineConfig, ROOT);
|
|
87
|
-
},
|
|
88
|
-
resolveId(source) {
|
|
89
|
-
var _a;
|
|
90
|
-
if (!((_a = userConfig.experimental) == null ? void 0 : _a.enableCodeSplitting)) {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
if (source.startsWith(splitPrefix + ":")) {
|
|
94
|
-
return source.replace(splitPrefix + ":", "");
|
|
95
|
-
}
|
|
96
|
-
return null;
|
|
97
|
-
},
|
|
98
|
-
async transform(code, id, transformOptions) {
|
|
99
|
-
var _a;
|
|
100
|
-
if (!((_a = userConfig.experimental) == null ? void 0 : _a.enableCodeSplitting)) {
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
const url = pathToFileURL(id);
|
|
104
|
-
url.searchParams.delete("v");
|
|
105
|
-
id = fileURLToPath(url).replace(/\\/g, "/");
|
|
106
|
-
const compile = makeCompile({
|
|
107
|
-
root: ROOT
|
|
108
|
-
});
|
|
109
|
-
if (id.includes(splitPrefix)) {
|
|
110
|
-
if (debug)
|
|
111
|
-
console.info("Splitting route: ", id);
|
|
112
|
-
const compiled = await splitFile({
|
|
113
|
-
code,
|
|
114
|
-
compile,
|
|
115
|
-
filename: id
|
|
116
|
-
// ref,
|
|
117
|
-
});
|
|
118
|
-
if (debug)
|
|
119
|
-
console.info("");
|
|
120
|
-
if (debug)
|
|
121
|
-
console.info("Split Output");
|
|
122
|
-
if (debug)
|
|
123
|
-
console.info("");
|
|
124
|
-
if (debug)
|
|
125
|
-
console.info(compiled.code);
|
|
126
|
-
if (debug)
|
|
127
|
-
console.info("");
|
|
128
|
-
if (debug)
|
|
129
|
-
console.info("");
|
|
130
|
-
if (debug)
|
|
131
|
-
console.info("");
|
|
132
|
-
if (debug)
|
|
133
|
-
console.info("");
|
|
134
|
-
if (debug)
|
|
135
|
-
console.info("");
|
|
136
|
-
if (debug)
|
|
137
|
-
console.info("");
|
|
138
|
-
if (debug)
|
|
139
|
-
console.info("");
|
|
140
|
-
if (debug)
|
|
141
|
-
console.info("");
|
|
142
|
-
return compiled;
|
|
143
|
-
} else if (fileIsInRoutesDirectory(id, userConfig.routesDirectory) && (code.includes("createRoute(") || code.includes("createFileRoute("))) {
|
|
144
|
-
if (code.includes("@react-refresh")) {
|
|
145
|
-
throw new Error(
|
|
146
|
-
`We detected that the '@vitejs/plugin-react' was passed before '@tanstack/router-vite-plugin'. Please make sure that '@tanstack/router-vite-plugin' is passed before '@vitejs/plugin-react' and try again:
|
|
147
|
-
e.g.
|
|
148
|
-
|
|
149
|
-
plugins: [
|
|
150
|
-
TanStackRouterVite(), // Place this before viteReact()
|
|
151
|
-
viteReact(),
|
|
152
|
-
]
|
|
153
|
-
`
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
if (debug)
|
|
157
|
-
console.info("Handling createRoute: ", id);
|
|
158
|
-
const compiled = await compileFile({
|
|
159
|
-
code,
|
|
160
|
-
compile,
|
|
161
|
-
filename: id
|
|
162
|
-
});
|
|
163
|
-
if (debug)
|
|
164
|
-
console.info("");
|
|
165
|
-
if (debug)
|
|
166
|
-
console.info("Compiled Output");
|
|
167
|
-
if (debug)
|
|
168
|
-
console.info("");
|
|
169
|
-
if (debug)
|
|
170
|
-
console.info(compiled.code);
|
|
171
|
-
if (debug)
|
|
172
|
-
console.info("");
|
|
173
|
-
if (debug)
|
|
174
|
-
console.info("");
|
|
175
|
-
if (debug)
|
|
176
|
-
console.info("");
|
|
177
|
-
if (debug)
|
|
178
|
-
console.info("");
|
|
179
|
-
if (debug)
|
|
180
|
-
console.info("");
|
|
181
|
-
if (debug)
|
|
182
|
-
console.info("");
|
|
183
|
-
if (debug)
|
|
184
|
-
console.info("");
|
|
185
|
-
if (debug)
|
|
186
|
-
console.info("");
|
|
187
|
-
if (debug)
|
|
188
|
-
console.info("");
|
|
189
|
-
if (debug)
|
|
190
|
-
console.info("");
|
|
191
|
-
return compiled;
|
|
192
|
-
}
|
|
193
|
-
return null;
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
export {
|
|
198
|
-
TanStackRouterVite,
|
|
199
|
-
TanStackRouterViteCodeSplitter,
|
|
200
|
-
TanStackRouterViteGenerator,
|
|
201
|
-
configSchema
|
|
202
|
-
};
|
|
1
|
+
export * from "@tanstack/router-plugin/vite";
|
|
203
2
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { isAbsolute, join, normalize, resolve } from 'path'\nimport { fileURLToPath, pathToFileURL } from 'url'\nimport { z } from 'zod'\nimport {\n generator,\n configSchema as generatorConfigSchema,\n getConfig as getGeneratorConfig,\n} from '@tanstack/router-generator'\nimport { compileFile, makeCompile, splitFile } from './compilers'\nimport { splitPrefix } from './constants'\nimport type { Plugin } from 'vite'\n\nexport const configSchema = generatorConfigSchema.extend({\n enableRouteGeneration: z.boolean().optional(),\n experimental: z\n .object({\n enableCodeSplitting: z.boolean().optional(),\n })\n .optional(),\n})\n\nexport type Config = z.infer<typeof configSchema>\n\nconst CONFIG_FILE_NAME = 'tsr.config.json'\nconst debug = Boolean(process.env.TSR_VITE_DEBUG)\n\nconst getConfig = async (inlineConfig: Partial<Config>, root: string) => {\n const config = await getGeneratorConfig(inlineConfig, root)\n\n return configSchema.parse({ ...config, ...inlineConfig })\n}\n\nexport function TanStackRouterVite(\n inlineConfig: Partial<Config> = {},\n): Array<Plugin> {\n return [\n TanStackRouterViteGenerator(inlineConfig),\n TanStackRouterViteCodeSplitter(inlineConfig),\n ]\n}\n\nlet lock = false\n\nexport function TanStackRouterViteGenerator(\n inlineConfig: Partial<Config> = {},\n): Plugin {\n let ROOT: string = process.cwd()\n let userConfig: Config\n\n const generate = async () => {\n if (lock) {\n return\n }\n lock = true\n try {\n await generator(userConfig)\n } catch (err) {\n console.error(err)\n console.info()\n }\n lock = false\n }\n\n const handleFile = async (\n file: string,\n event: 'create' | 'update' | 'delete',\n ) => {\n const filePath = normalize(file)\n\n if (filePath === join(ROOT, CONFIG_FILE_NAME)) {\n userConfig = await getConfig(inlineConfig, ROOT)\n return\n }\n\n if (\n event === 'update' &&\n filePath === resolve(userConfig.generatedRouteTree)\n ) {\n // skip generating routes if the generated route tree is updated\n return\n }\n\n const routesDirectoryPath = isAbsolute(userConfig.routesDirectory)\n ? userConfig.routesDirectory\n : join(ROOT, userConfig.routesDirectory)\n\n if (filePath.startsWith(routesDirectoryPath)) {\n await generate()\n }\n }\n\n return {\n name: 'vite-plugin-tanstack-router-generator',\n configResolved: async (config) => {\n ROOT = process.cwd()\n userConfig = await getConfig(inlineConfig, ROOT)\n if (userConfig.enableRouteGeneration ?? true) {\n await generate()\n }\n },\n watchChange: async (file, context) => {\n if (userConfig.enableRouteGeneration ?? true) {\n if (['create', 'update', 'delete'].includes(context.event)) {\n await handleFile(file, context.event)\n }\n }\n },\n }\n}\n\nfunction fileIsInRoutesDirectory(filePath: string, routesDirectory: string) {\n const routesDirectoryPath = isAbsolute(routesDirectory)\n ? routesDirectory\n : join(process.cwd(), routesDirectory)\n\n return filePath.startsWith(routesDirectoryPath)\n}\n\nexport function TanStackRouterViteCodeSplitter(\n inlineConfig: Partial<Config> = {},\n): Plugin {\n let ROOT: string = process.cwd()\n let userConfig: Config\n\n return {\n name: 'vite-plugin-tanstack-router-code-splitter',\n enforce: 'pre',\n configResolved: async (config) => {\n ROOT = config.root\n userConfig = await getConfig(inlineConfig, ROOT)\n },\n resolveId(source) {\n if (!userConfig.experimental?.enableCodeSplitting) {\n return null\n }\n\n if (source.startsWith(splitPrefix + ':')) {\n return source.replace(splitPrefix + ':', '')\n }\n return null\n },\n async transform(code, id, transformOptions) {\n if (!userConfig.experimental?.enableCodeSplitting) {\n return null\n }\n\n const url = pathToFileURL(id)\n url.searchParams.delete('v')\n id = fileURLToPath(url).replace(/\\\\/g, '/')\n\n const compile = makeCompile({\n root: ROOT,\n })\n\n if (id.includes(splitPrefix)) {\n if (debug) console.info('Splitting route: ', id)\n // const ref = new URLSearchParams(id.split('?')[1]).get('ref') || ''\n\n const compiled = await splitFile({\n code,\n compile,\n filename: id,\n // ref,\n })\n\n if (debug) console.info('')\n if (debug) console.info('Split Output')\n if (debug) console.info('')\n if (debug) console.info(compiled.code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n return compiled\n } else if (\n fileIsInRoutesDirectory(id, userConfig.routesDirectory) &&\n (code.includes('createRoute(') || code.includes('createFileRoute('))\n ) {\n if (code.includes('@react-refresh')) {\n throw new Error(\n `We detected that the '@vitejs/plugin-react' was passed before '@tanstack/router-vite-plugin'. Please make sure that '@tanstack/router-vite-plugin' is passed before '@vitejs/plugin-react' and try again: \ne.g.\n\nplugins: [\n TanStackRouterVite(), // Place this before viteReact()\n viteReact(),\n]\n`,\n )\n }\n\n if (debug) console.info('Handling createRoute: ', id)\n const compiled = await compileFile({\n code,\n compile,\n filename: id,\n })\n\n if (debug) console.info('')\n if (debug) console.info('Compiled Output')\n if (debug) console.info('')\n if (debug) console.info(compiled.code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n return compiled\n }\n\n return null\n },\n }\n}\n"],"names":["generatorConfigSchema","getGeneratorConfig"],"mappings":";;;;;;AAYa,MAAA,eAAeA,eAAsB,OAAO;AAAA,EACvD,uBAAuB,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC5C,cAAc,EACX,OAAO;AAAA,IACN,qBAAqB,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC3C,CAAA,EACA,SAAS;AACd,CAAC;AAID,MAAM,mBAAmB;AACzB,MAAM,QAAQ,QAAQ,QAAQ,IAAI,cAAc;AAEhD,MAAM,YAAY,OAAO,cAA+B,SAAiB;AACvE,QAAM,SAAS,MAAMC,YAAmB,cAAc,IAAI;AAE1D,SAAO,aAAa,MAAM,EAAE,GAAG,QAAQ,GAAG,cAAc;AAC1D;AAEgB,SAAA,mBACd,eAAgC,IACjB;AACR,SAAA;AAAA,IACL,4BAA4B,YAAY;AAAA,IACxC,+BAA+B,YAAY;AAAA,EAAA;AAE/C;AAEA,IAAI,OAAO;AAEK,SAAA,4BACd,eAAgC,IACxB;AACJ,MAAA,OAAe,QAAQ;AACvB,MAAA;AAEJ,QAAM,WAAW,YAAY;AAC3B,QAAI,MAAM;AACR;AAAA,IACF;AACO,WAAA;AACH,QAAA;AACF,YAAM,UAAU,UAAU;AAAA,aACnB,KAAK;AACZ,cAAQ,MAAM,GAAG;AACjB,cAAQ,KAAK;AAAA,IACf;AACO,WAAA;AAAA,EAAA;AAGH,QAAA,aAAa,OACjB,MACA,UACG;AACG,UAAA,WAAW,UAAU,IAAI;AAE/B,QAAI,aAAa,KAAK,MAAM,gBAAgB,GAAG;AAChC,mBAAA,MAAM,UAAU,cAAc,IAAI;AAC/C;AAAA,IACF;AAEA,QACE,UAAU,YACV,aAAa,QAAQ,WAAW,kBAAkB,GAClD;AAEA;AAAA,IACF;AAEM,UAAA,sBAAsB,WAAW,WAAW,eAAe,IAC7D,WAAW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AACtB,YAAA;AAAO,kBAAQ,KAAK,iBAAiB;AACrC,YAAA;AAAO,kBAAQ,KAAK,EAAE;AACtB,YAAA;AAAe,kBAAA,KAAK,SAAS,IAAI;AACjC,YAAA;AAAO,kBAAQ,KAAK,EAAE;AACtB,YAAA;AAAO,kBAAQ,KAAK,EAAE;AACtB,YAAA;AAAO,kBAAQ,KAAK,EAAE;AACtB,YAAA;AAAO,kBAAQ,KAAK,EAAE;AACtB,YAAA;AAAO,kBAAQ,KAAK,EAAE;AACtB,YAAA;AAAO,kBAAQ,KAAK,EAAE;AACtB,YAAA;AAAO,kBAAQ,KAAK,EAAE;AACtB,YAAA;AAAO,kBAAQ,KAAK,EAAE;AACtB,YAAA;AAAO,kBAAQ,KAAK,EAAE;AACtB,YAAA;AAAO,kBAAQ,KAAK,EAAE;AAEnB,eAAA;AAAA,MACT;AAEO,aAAA;AAAA,IACT;AAAA,EAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/router-vite-plugin",
|
|
3
|
-
"version": "1.39.
|
|
3
|
+
"version": "1.39.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,23 +49,7 @@
|
|
|
49
49
|
"src/**"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@
|
|
53
|
-
"@babel/generator": "^7.23.6",
|
|
54
|
-
"@babel/plugin-syntax-jsx": "^7.24.1",
|
|
55
|
-
"@babel/plugin-syntax-typescript": "^7.24.1",
|
|
56
|
-
"@babel/plugin-transform-react-jsx": "^7.23.4",
|
|
57
|
-
"@babel/plugin-transform-typescript": "^7.24.1",
|
|
58
|
-
"@babel/template": "^7.24.0",
|
|
59
|
-
"@babel/traverse": "^7.24.1",
|
|
60
|
-
"@babel/types": "^7.24.0",
|
|
61
|
-
"@types/babel__core": "^7.20.5",
|
|
62
|
-
"@types/babel__generator": "^7.6.8",
|
|
63
|
-
"@types/babel__template": "^7.4.4",
|
|
64
|
-
"@types/babel__traverse": "^7.20.5",
|
|
65
|
-
"@vitejs/plugin-react": "^4.2.1",
|
|
66
|
-
"zod": "^3.22.4",
|
|
67
|
-
"@tanstack/router-generator": "1.37.0",
|
|
68
|
-
"@tanstack/router-plugin": "^1.39.3"
|
|
52
|
+
"@tanstack/router-plugin": "^1.39.5"
|
|
69
53
|
},
|
|
70
54
|
"scripts": {}
|
|
71
55
|
}
|