@tanstack/router-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/code-splitter.cjs +11 -6
- package/dist/cjs/code-splitter.cjs.map +1 -1
- package/dist/cjs/code-splitter.d.cts +2 -20
- package/dist/cjs/config.cjs +1 -0
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/config.d.cts +3 -4
- package/dist/cjs/index.cjs +4 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +4 -2
- package/dist/cjs/router-generator.cjs +2 -4
- package/dist/cjs/router-generator.cjs.map +1 -1
- package/dist/cjs/router-generator.d.cts +4 -18
- package/dist/cjs/vite.cjs +11 -3
- package/dist/cjs/vite.cjs.map +1 -1
- package/dist/cjs/vite.d.cts +7 -5
- package/dist/esm/code-splitter.d.ts +2 -20
- package/dist/esm/code-splitter.js +11 -6
- package/dist/esm/code-splitter.js.map +1 -1
- package/dist/esm/config.d.ts +3 -4
- package/dist/esm/config.js +1 -0
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/index.d.ts +4 -2
- package/dist/esm/index.js +6 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/router-generator.d.ts +4 -18
- package/dist/esm/router-generator.js +2 -4
- package/dist/esm/router-generator.js.map +1 -1
- package/dist/esm/vite.d.ts +7 -5
- package/dist/esm/vite.js +13 -5
- package/dist/esm/vite.js.map +1 -1
- package/package.json +1 -1
- package/src/code-splitter.ts +23 -14
- package/src/config.ts +3 -3
- package/src/index.ts +4 -2
- package/src/router-generator.ts +5 -9
- package/src/vite.ts +20 -9
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const node_path = require("node:path");
|
|
4
4
|
const node_url = require("node:url");
|
|
5
|
-
const unplugin = require("unplugin");
|
|
6
5
|
const ast = require("./ast.cjs");
|
|
7
6
|
const compilers = require("./compilers.cjs");
|
|
8
7
|
const config = require("./config.cjs");
|
|
@@ -18,7 +17,8 @@ const bannedBeforeExternalPlugins = [
|
|
|
18
17
|
{
|
|
19
18
|
identifier: "@react-refresh",
|
|
20
19
|
pkg: "@vitejs/plugin-react",
|
|
21
|
-
usage: "viteReact()"
|
|
20
|
+
usage: "viteReact()",
|
|
21
|
+
frameworks: ["vite"]
|
|
22
22
|
}
|
|
23
23
|
];
|
|
24
24
|
class FoundPluginInBeforeCode extends Error {
|
|
@@ -32,7 +32,7 @@ plugins: [
|
|
|
32
32
|
`);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
const
|
|
35
|
+
const unpluginRouterCodeSplitterFactory = (options = {}, { framework }) => {
|
|
36
36
|
const debug = Boolean(process.env.TSR_VITE_DEBUG);
|
|
37
37
|
let ROOT = process.cwd();
|
|
38
38
|
let userConfig = options;
|
|
@@ -128,6 +128,10 @@ const unpluginFactory = (options = {}, { framework }) => {
|
|
|
128
128
|
return null;
|
|
129
129
|
},
|
|
130
130
|
async transform(code, id) {
|
|
131
|
+
var _a;
|
|
132
|
+
if (!((_a = userConfig.experimental) == null ? void 0 : _a.enableCodeSplitting)) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
131
135
|
const url = node_url.pathToFileURL(id);
|
|
132
136
|
url.searchParams.delete("v");
|
|
133
137
|
id = node_url.fileURLToPath(url).replace(/\\/g, "/");
|
|
@@ -135,6 +139,9 @@ const unpluginFactory = (options = {}, { framework }) => {
|
|
|
135
139
|
return await handleSplittingFile(code, id);
|
|
136
140
|
} else if (fileIsInRoutesDirectory(id, userConfig.routesDirectory) && (code.includes("createRoute(") || code.includes("createFileRoute("))) {
|
|
137
141
|
for (const externalPlugin of bannedBeforeExternalPlugins) {
|
|
142
|
+
if (!externalPlugin.frameworks.includes(framework)) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
138
145
|
if (code.includes(externalPlugin.identifier)) {
|
|
139
146
|
throw new FoundPluginInBeforeCode(externalPlugin, framework);
|
|
140
147
|
}
|
|
@@ -151,7 +158,5 @@ const unpluginFactory = (options = {}, { framework }) => {
|
|
|
151
158
|
}
|
|
152
159
|
};
|
|
153
160
|
};
|
|
154
|
-
|
|
155
|
-
exports.unpluginFactory = unpluginFactory;
|
|
156
|
-
exports.unpluginRouterCodeSplitter = unpluginRouterCodeSplitter;
|
|
161
|
+
exports.unpluginRouterCodeSplitterFactory = unpluginRouterCodeSplitterFactory;
|
|
157
162
|
//# sourceMappingURL=code-splitter.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-splitter.cjs","sources":["../../src/code-splitter.ts"],"sourcesContent":["import { isAbsolute, join } from 'node:path'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\
|
|
1
|
+
{"version":3,"file":"code-splitter.cjs","sources":["../../src/code-splitter.ts"],"sourcesContent":["import { isAbsolute, join } from 'node:path'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\n\nimport { compileAst } from './ast'\nimport { compileFile, splitFile } from './compilers'\nimport { getConfig } from './config'\nimport { splitPrefix } from './constants'\n\nimport type { Config } from './config'\nimport type { UnpluginContextMeta, UnpluginFactory } from 'unplugin'\n\nfunction capitalizeFirst(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1)\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\ntype BannedBeforeExternalPlugin = {\n identifier: string\n pkg: string\n usage: string\n frameworks: Array<UnpluginContextMeta['framework']>\n}\n\nconst bannedBeforeExternalPlugins: Array<BannedBeforeExternalPlugin> = [\n {\n identifier: '@react-refresh',\n pkg: '@vitejs/plugin-react',\n usage: 'viteReact()',\n frameworks: ['vite'],\n },\n]\n\nclass FoundPluginInBeforeCode extends Error {\n constructor(externalPlugin: BannedBeforeExternalPlugin, framework: string) {\n super(`We detected that the '${externalPlugin.pkg}' was passed before '@tanstack/router-plugin'. Please make sure that '@tanstack/router-plugin' is passed before '${externalPlugin.pkg}' and try again: \ne.g.\nplugins: [\n TanStackRouter${capitalizeFirst(framework)}(), // Place this before ${externalPlugin.usage}\n ${externalPlugin.usage},\n]\n`)\n }\n}\n\nexport const unpluginRouterCodeSplitterFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}, { framework }) => {\n const debug = Boolean(process.env.TSR_VITE_DEBUG)\n\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n const handleSplittingFile = async (code: string, id: string) => {\n const compiledAst = compileAst({\n root: ROOT,\n })\n\n if (debug) console.info('Splitting route: ', id)\n\n const compiled = await splitFile({\n code,\n compileAst: compiledAst,\n filename: id,\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 }\n\n const handleCompilingFile = async (code: string, id: string) => {\n const compiledAst = compileAst({\n root: ROOT,\n })\n\n if (debug) console.info('Handling createRoute: ', id)\n\n const compiled = await compileFile({\n code,\n compileAst: compiledAst,\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 {\n name: 'router-code-splitter-plugin',\n enforce: 'pre',\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) {\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 if (id.includes(splitPrefix)) {\n return await handleSplittingFile(code, id)\n } else if (\n fileIsInRoutesDirectory(id, userConfig.routesDirectory) &&\n (code.includes('createRoute(') || code.includes('createFileRoute('))\n ) {\n for (const externalPlugin of bannedBeforeExternalPlugins) {\n if (!externalPlugin.frameworks.includes(framework)) {\n continue\n }\n\n if (code.includes(externalPlugin.identifier)) {\n throw new FoundPluginInBeforeCode(externalPlugin, framework)\n }\n }\n\n return await handleCompilingFile(code, id)\n }\n\n return null\n },\n vite: {\n async configResolved(config) {\n ROOT = config.root\n userConfig = await getConfig(options, ROOT)\n },\n },\n }\n}\n"],"names":["isAbsolute","join","compileAst","splitFile","compileFile","splitPrefix","pathToFileURL","fileURLToPath","config","getConfig"],"mappings":";;;;;;;;AAWA,SAAS,gBAAgB,KAAqB;AACrC,SAAA,IAAI,OAAO,CAAC,EAAE,gBAAgB,IAAI,MAAM,CAAC;AAClD;AAEA,SAAS,wBAAwB,UAAkB,iBAAyB;AACpE,QAAA,sBAAsBA,qBAAW,eAAe,IAClD,kBACAC,UAAK,KAAA,QAAQ,OAAO,eAAe;AAEhC,SAAA,SAAS,WAAW,mBAAmB;AAChD;AASA,MAAM,8BAAiE;AAAA,EACrE;AAAA,IACE,YAAY;AAAA,IACZ,KAAK;AAAA,IACL,OAAO;AAAA,IACP,YAAY,CAAC,MAAM;AAAA,EACrB;AACF;AAEA,MAAM,gCAAgC,MAAM;AAAA,EAC1C,YAAY,gBAA4C,WAAmB;AACzE,UAAM,yBAAyB,eAAe,GAAG,oHAAoH,eAAe,GAAG;AAAA;AAAA;AAAA,kBAGzK,gBAAgB,SAAS,CAAC,4BAA4B,eAAe,KAAK;AAAA,IACxF,eAAe,KAAK;AAAA;AAAA,CAEvB;AAAA,EACC;AACF;AAEO,MAAM,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AK,SAAS,eAAe,UAAU,GAAG;AACtC,kBAAA,IAAI,wBAAwB,gBAAgB,SAAS;AAAA,UAC7D;AAAA,QACF;AAEO,eAAA,MAAM,oBAAoB,MAAM,EAAE;AAAA,MAC3C;AAEO,aAAA;AAAA,IACT;AAAA,IACA,MAAM;AAAA,MACJ,MAAM,eAAeG,UAAQ;AAC3B,eAAOA,SAAO;AACD,qBAAA,MAAMC,OAAAA,UAAU,SAAS,IAAI;AAAA,MAC5C;AAAA,IACF;AAAA,EAAA;AAEJ;;"}
|
|
@@ -1,22 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Config } from './config.cjs';
|
|
2
2
|
import { UnpluginFactory } from 'unplugin';
|
|
3
3
|
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const unpluginRouterCodeSplitter: import('unplugin').UnpluginInstance<Partial<{
|
|
6
|
-
routeFileIgnorePrefix: string;
|
|
7
|
-
routesDirectory: string;
|
|
8
|
-
generatedRouteTree: string;
|
|
9
|
-
quoteStyle: "single" | "double";
|
|
10
|
-
semicolons: boolean;
|
|
11
|
-
disableTypes: boolean;
|
|
12
|
-
addExtensions: boolean;
|
|
13
|
-
disableLogging: boolean;
|
|
14
|
-
routeTreeFileHeader: string[];
|
|
15
|
-
routeTreeFileFooter: string[];
|
|
16
|
-
enableRouteGeneration?: boolean | undefined;
|
|
17
|
-
experimental?: {
|
|
18
|
-
enableCodeSplitting?: boolean | undefined;
|
|
19
|
-
} | undefined;
|
|
20
|
-
routeFilePrefix?: string | undefined;
|
|
21
|
-
routeFileIgnorePattern?: string | undefined;
|
|
22
|
-
}> | undefined, boolean>;
|
|
4
|
+
export declare const unpluginRouterCodeSplitterFactory: UnpluginFactory<Partial<Config> | undefined>;
|
package/dist/cjs/config.cjs
CHANGED
|
@@ -12,5 +12,6 @@ const getConfig = async (inlineConfig, root) => {
|
|
|
12
12
|
const config = await routerGenerator.getConfig(inlineConfig, root);
|
|
13
13
|
return configSchema.parse({ ...config, ...inlineConfig });
|
|
14
14
|
};
|
|
15
|
+
exports.configSchema = configSchema;
|
|
15
16
|
exports.getConfig = getConfig;
|
|
16
17
|
//# sourceMappingURL=config.cjs.map
|
package/dist/cjs/config.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.cjs","sources":["../../src/config.ts"],"sourcesContent":["import { z } from 'zod'\nimport {\n configSchema as generatorConfigSchema,\n getConfig as getGeneratorConfig,\n} from '@tanstack/router-generator'\n\
|
|
1
|
+
{"version":3,"file":"config.cjs","sources":["../../src/config.ts"],"sourcesContent":["import { z } from 'zod'\nimport {\n configSchema as generatorConfigSchema,\n getConfig as getGeneratorConfig,\n} from '@tanstack/router-generator'\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 const getConfig = async (\n inlineConfig: Partial<Config>,\n root: string,\n) => {\n const config = await getGeneratorConfig(inlineConfig, root)\n\n return configSchema.parse({ ...config, ...inlineConfig })\n}\n\nexport type Config = z.infer<typeof configSchema>\n"],"names":["generatorConfigSchema","z","getGeneratorConfig"],"mappings":";;;;AAMa,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;AAEY,MAAA,YAAY,OACvB,cACA,SACG;AACH,QAAM,SAAS,MAAMC,gBAAAA,UAAmB,cAAc,IAAI;AAE1D,SAAO,aAAa,MAAM,EAAE,GAAG,QAAQ,GAAG,cAAc;AAC1D;;;"}
|
package/dist/cjs/config.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
declare const configSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
3
|
+
export declare const configSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
4
4
|
routeFilePrefix: z.ZodOptional<z.ZodString>;
|
|
5
5
|
routeFileIgnorePrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
6
6
|
routeFileIgnorePattern: z.ZodOptional<z.ZodString>;
|
|
@@ -57,7 +57,7 @@ declare const configSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
|
57
57
|
routeTreeFileHeader?: string[] | undefined;
|
|
58
58
|
routeTreeFileFooter?: string[] | undefined;
|
|
59
59
|
}>;
|
|
60
|
-
export declare const getConfig: (inlineConfig: Partial<
|
|
60
|
+
export declare const getConfig: (inlineConfig: Partial<Config>, root: string) => Promise<{
|
|
61
61
|
routeFileIgnorePrefix: string;
|
|
62
62
|
routesDirectory: string;
|
|
63
63
|
generatedRouteTree: string;
|
|
@@ -75,5 +75,4 @@ export declare const getConfig: (inlineConfig: Partial<PluginOptions>, root: str
|
|
|
75
75
|
routeFilePrefix?: string | undefined;
|
|
76
76
|
routeFileIgnorePattern?: string | undefined;
|
|
77
77
|
}>;
|
|
78
|
-
export type
|
|
79
|
-
export {};
|
|
78
|
+
export type Config = z.infer<typeof configSchema>;
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const codeSplitter = require("./code-splitter.cjs");
|
|
4
4
|
const routerGenerator = require("./router-generator.cjs");
|
|
5
|
-
|
|
6
|
-
exports.
|
|
5
|
+
const config = require("./config.cjs");
|
|
6
|
+
exports.unpluginRouterCodeSplitterFactory = codeSplitter.unpluginRouterCodeSplitterFactory;
|
|
7
|
+
exports.unpluginRouterGeneratorFactory = routerGenerator.unpluginRouterGeneratorFactory;
|
|
8
|
+
exports.configSchema = config.configSchema;
|
|
7
9
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { unpluginRouterCodeSplitterFactory } from './code-splitter.cjs';
|
|
2
|
+
export { unpluginRouterGeneratorFactory } from './router-generator.cjs';
|
|
3
|
+
export { configSchema } from './config.cjs';
|
|
4
|
+
export type { Config } from './config.cjs';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const node_path = require("node:path");
|
|
4
|
-
const unplugin = require("unplugin");
|
|
5
4
|
const routerGenerator = require("@tanstack/router-generator");
|
|
6
5
|
const config = require("./config.cjs");
|
|
7
6
|
const constants = require("./constants.cjs");
|
|
@@ -10,7 +9,7 @@ const checkLock = () => lock;
|
|
|
10
9
|
const setLock = (bool) => {
|
|
11
10
|
lock = bool;
|
|
12
11
|
};
|
|
13
|
-
const
|
|
12
|
+
const unpluginRouterGeneratorFactory = (options = {}) => {
|
|
14
13
|
let ROOT = process.cwd();
|
|
15
14
|
let userConfig = options;
|
|
16
15
|
const generate = async () => {
|
|
@@ -62,6 +61,5 @@ const unpluginFactory = (options = {}) => {
|
|
|
62
61
|
}
|
|
63
62
|
};
|
|
64
63
|
};
|
|
65
|
-
|
|
66
|
-
exports.unpluginRouterGenerator = unpluginRouterGenerator;
|
|
64
|
+
exports.unpluginRouterGeneratorFactory = unpluginRouterGeneratorFactory;
|
|
67
65
|
//# sourceMappingURL=router-generator.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-generator.cjs","sources":["../../src/router-generator.ts"],"sourcesContent":["import { isAbsolute, join, normalize, resolve } from 'node:path'\nimport {
|
|
1
|
+
{"version":3,"file":"router-generator.cjs","sources":["../../src/router-generator.ts"],"sourcesContent":["import { isAbsolute, join, normalize, resolve } from 'node:path'\nimport { generator } from '@tanstack/router-generator'\n\nimport { getConfig } from './config'\nimport { CONFIG_FILE_NAME } from './constants'\nimport type { Config } from './config'\nimport type { UnpluginFactory } from 'unplugin'\n\nlet lock = false\nconst checkLock = () => lock\nconst setLock = (bool: boolean) => {\n lock = bool\n}\n\nexport const unpluginRouterGeneratorFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}) => {\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n const generate = async () => {\n if (checkLock()) {\n return\n }\n\n setLock(true)\n\n try {\n await generator(userConfig)\n } catch (err) {\n console.error(err)\n console.info()\n } finally {\n setLock(false)\n }\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(options, 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 const run: (cb: () => Promise<void> | void) => Promise<void> = async (cb) => {\n if (userConfig.enableRouteGeneration ?? true) {\n await cb()\n }\n }\n\n return {\n name: 'router-generator-plugin',\n async watchChange(id, { event }) {\n await run(async () => {\n await handleFile(id, event)\n })\n },\n vite: {\n async configResolved(config) {\n ROOT = config.root\n userConfig = await getConfig(options, ROOT)\n\n await run(generate)\n },\n },\n }\n}\n"],"names":["generator","normalize","join","CONFIG_FILE_NAME","getConfig","resolve","isAbsolute","config"],"mappings":";;;;;;AAQA,IAAI,OAAO;AACX,MAAM,YAA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,MACpB;AAAA,IACF;AAAA,EAAA;AAEJ;;"}
|
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
quoteStyle: "single" | "double";
|
|
6
|
-
semicolons: boolean;
|
|
7
|
-
disableTypes: boolean;
|
|
8
|
-
addExtensions: boolean;
|
|
9
|
-
disableLogging: boolean;
|
|
10
|
-
routeTreeFileHeader: string[];
|
|
11
|
-
routeTreeFileFooter: string[];
|
|
12
|
-
enableRouteGeneration?: boolean | undefined;
|
|
13
|
-
experimental?: {
|
|
14
|
-
enableCodeSplitting?: boolean | undefined;
|
|
15
|
-
} | undefined;
|
|
16
|
-
routeFilePrefix?: string | undefined;
|
|
17
|
-
routeFileIgnorePattern?: string | undefined;
|
|
18
|
-
}> | undefined, boolean>;
|
|
1
|
+
import { Config } from './config.cjs';
|
|
2
|
+
import { UnpluginFactory } from 'unplugin';
|
|
3
|
+
|
|
4
|
+
export declare const unpluginRouterGeneratorFactory: UnpluginFactory<Partial<Config> | undefined>;
|
package/dist/cjs/vite.cjs
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const unplugin = require("unplugin");
|
|
3
4
|
const codeSplitter = require("./code-splitter.cjs");
|
|
5
|
+
const config = require("./config.cjs");
|
|
4
6
|
const routerGenerator = require("./router-generator.cjs");
|
|
5
|
-
const TanStackRouterGeneratorVite =
|
|
6
|
-
|
|
7
|
+
const TanStackRouterGeneratorVite = unplugin.createVitePlugin(
|
|
8
|
+
routerGenerator.unpluginRouterGeneratorFactory
|
|
9
|
+
);
|
|
10
|
+
const TanStackRouterCodeSplitterVite = unplugin.createVitePlugin(
|
|
11
|
+
codeSplitter.unpluginRouterCodeSplitterFactory
|
|
12
|
+
);
|
|
7
13
|
function TanStackRouterVite(inlineConfig) {
|
|
8
14
|
return [
|
|
9
15
|
TanStackRouterGeneratorVite(inlineConfig),
|
|
10
16
|
TanStackRouterCodeSplitterVite(inlineConfig)
|
|
11
17
|
];
|
|
12
18
|
}
|
|
19
|
+
exports.configSchema = config.configSchema;
|
|
13
20
|
exports.TanStackRouterCodeSplitterVite = TanStackRouterCodeSplitterVite;
|
|
14
21
|
exports.TanStackRouterGeneratorVite = TanStackRouterGeneratorVite;
|
|
15
22
|
exports.TanStackRouterVite = TanStackRouterVite;
|
|
23
|
+
exports.default = TanStackRouterVite;
|
|
16
24
|
//# sourceMappingURL=vite.cjs.map
|
package/dist/cjs/vite.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.cjs","sources":["../../src/vite.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"vite.cjs","sources":["../../src/vite.ts"],"sourcesContent":["import { createVitePlugin } from 'unplugin'\nimport { unpluginRouterCodeSplitterFactory } from './code-splitter'\nimport { configSchema } from './config'\nimport { unpluginRouterGeneratorFactory } from './router-generator'\n\nimport type { Config } from './config'\nimport type { VitePlugin } from 'unplugin'\n\nconst TanStackRouterGeneratorVite = createVitePlugin(\n unpluginRouterGeneratorFactory,\n)\nconst TanStackRouterCodeSplitterVite = createVitePlugin(\n unpluginRouterCodeSplitterFactory,\n)\n\nfunction TanStackRouterVite(inlineConfig?: Partial<Config>): Array<VitePlugin> {\n return [\n TanStackRouterGeneratorVite(inlineConfig) as VitePlugin,\n TanStackRouterCodeSplitterVite(inlineConfig) as VitePlugin,\n ]\n}\n\nexport default TanStackRouterVite\nexport {\n configSchema,\n TanStackRouterGeneratorVite,\n TanStackRouterCodeSplitterVite,\n TanStackRouterVite,\n}\nexport type { Config }\n"],"names":["createVitePlugin","unpluginRouterGeneratorFactory","unpluginRouterCodeSplitterFactory"],"mappings":";;;;;;AAQA,MAAM,8BAA8BA,SAAA;AAAA,EAClCC,gBAAA;AACF;AACA,MAAM,iCAAiCD,SAAA;AAAA,EACrCE,aAAA;AACF;AAEA,SAAS,mBAAmB,cAAmD;AACtE,SAAA;AAAA,IACL,4BAA4B,YAAY;AAAA,IACxC,+BAA+B,YAAY;AAAA,EAAA;AAE/C;;;;;;"}
|
package/dist/cjs/vite.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { configSchema, Config } from './config.cjs';
|
|
2
2
|
import { VitePlugin } from 'unplugin';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
declare const TanStackRouterGeneratorVite: (options?: Partial<{
|
|
5
5
|
routeFileIgnorePrefix: string;
|
|
6
6
|
routesDirectory: string;
|
|
7
7
|
generatedRouteTree: string;
|
|
@@ -19,7 +19,7 @@ export declare const TanStackRouterGeneratorVite: (options?: Partial<{
|
|
|
19
19
|
routeFilePrefix?: string | undefined;
|
|
20
20
|
routeFileIgnorePattern?: string | undefined;
|
|
21
21
|
}> | undefined) => VitePlugin<any> | VitePlugin<any>[];
|
|
22
|
-
|
|
22
|
+
declare const TanStackRouterCodeSplitterVite: (options?: Partial<{
|
|
23
23
|
routeFileIgnorePrefix: string;
|
|
24
24
|
routesDirectory: string;
|
|
25
25
|
generatedRouteTree: string;
|
|
@@ -37,5 +37,7 @@ export declare const TanStackRouterCodeSplitterVite: (options?: Partial<{
|
|
|
37
37
|
routeFilePrefix?: string | undefined;
|
|
38
38
|
routeFileIgnorePattern?: string | undefined;
|
|
39
39
|
}> | undefined) => VitePlugin<any> | VitePlugin<any>[];
|
|
40
|
-
|
|
41
|
-
export
|
|
40
|
+
declare function TanStackRouterVite(inlineConfig?: Partial<Config>): Array<VitePlugin>;
|
|
41
|
+
export default TanStackRouterVite;
|
|
42
|
+
export { configSchema, TanStackRouterGeneratorVite, TanStackRouterCodeSplitterVite, TanStackRouterVite, };
|
|
43
|
+
export type { Config };
|
|
@@ -1,22 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Config } from './config.js';
|
|
2
2
|
import { UnpluginFactory } from 'unplugin';
|
|
3
3
|
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const unpluginRouterCodeSplitter: import('unplugin').UnpluginInstance<Partial<{
|
|
6
|
-
routeFileIgnorePrefix: string;
|
|
7
|
-
routesDirectory: string;
|
|
8
|
-
generatedRouteTree: string;
|
|
9
|
-
quoteStyle: "single" | "double";
|
|
10
|
-
semicolons: boolean;
|
|
11
|
-
disableTypes: boolean;
|
|
12
|
-
addExtensions: boolean;
|
|
13
|
-
disableLogging: boolean;
|
|
14
|
-
routeTreeFileHeader: string[];
|
|
15
|
-
routeTreeFileFooter: string[];
|
|
16
|
-
enableRouteGeneration?: boolean | undefined;
|
|
17
|
-
experimental?: {
|
|
18
|
-
enableCodeSplitting?: boolean | undefined;
|
|
19
|
-
} | undefined;
|
|
20
|
-
routeFilePrefix?: string | undefined;
|
|
21
|
-
routeFileIgnorePattern?: string | undefined;
|
|
22
|
-
}> | undefined, boolean>;
|
|
4
|
+
export declare const unpluginRouterCodeSplitterFactory: UnpluginFactory<Partial<Config> | undefined>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isAbsolute, join } from "node:path";
|
|
2
2
|
import { pathToFileURL, fileURLToPath } from "node:url";
|
|
3
|
-
import { createUnplugin } from "unplugin";
|
|
4
3
|
import { compileAst } from "./ast.js";
|
|
5
4
|
import { splitFile, compileFile } from "./compilers.js";
|
|
6
5
|
import { getConfig } from "./config.js";
|
|
@@ -16,7 +15,8 @@ const bannedBeforeExternalPlugins = [
|
|
|
16
15
|
{
|
|
17
16
|
identifier: "@react-refresh",
|
|
18
17
|
pkg: "@vitejs/plugin-react",
|
|
19
|
-
usage: "viteReact()"
|
|
18
|
+
usage: "viteReact()",
|
|
19
|
+
frameworks: ["vite"]
|
|
20
20
|
}
|
|
21
21
|
];
|
|
22
22
|
class FoundPluginInBeforeCode extends Error {
|
|
@@ -30,7 +30,7 @@ plugins: [
|
|
|
30
30
|
`);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
const
|
|
33
|
+
const unpluginRouterCodeSplitterFactory = (options = {}, { framework }) => {
|
|
34
34
|
const debug = Boolean(process.env.TSR_VITE_DEBUG);
|
|
35
35
|
let ROOT = process.cwd();
|
|
36
36
|
let userConfig = options;
|
|
@@ -126,6 +126,10 @@ const unpluginFactory = (options = {}, { framework }) => {
|
|
|
126
126
|
return null;
|
|
127
127
|
},
|
|
128
128
|
async transform(code, id) {
|
|
129
|
+
var _a;
|
|
130
|
+
if (!((_a = userConfig.experimental) == null ? void 0 : _a.enableCodeSplitting)) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
129
133
|
const url = pathToFileURL(id);
|
|
130
134
|
url.searchParams.delete("v");
|
|
131
135
|
id = fileURLToPath(url).replace(/\\/g, "/");
|
|
@@ -133,6 +137,9 @@ const unpluginFactory = (options = {}, { framework }) => {
|
|
|
133
137
|
return await handleSplittingFile(code, id);
|
|
134
138
|
} else if (fileIsInRoutesDirectory(id, userConfig.routesDirectory) && (code.includes("createRoute(") || code.includes("createFileRoute("))) {
|
|
135
139
|
for (const externalPlugin of bannedBeforeExternalPlugins) {
|
|
140
|
+
if (!externalPlugin.frameworks.includes(framework)) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
136
143
|
if (code.includes(externalPlugin.identifier)) {
|
|
137
144
|
throw new FoundPluginInBeforeCode(externalPlugin, framework);
|
|
138
145
|
}
|
|
@@ -149,9 +156,7 @@ const unpluginFactory = (options = {}, { framework }) => {
|
|
|
149
156
|
}
|
|
150
157
|
};
|
|
151
158
|
};
|
|
152
|
-
const unpluginRouterCodeSplitter = /* @__PURE__ */ createUnplugin(unpluginFactory);
|
|
153
159
|
export {
|
|
154
|
-
|
|
155
|
-
unpluginRouterCodeSplitter
|
|
160
|
+
unpluginRouterCodeSplitterFactory
|
|
156
161
|
};
|
|
157
162
|
//# sourceMappingURL=code-splitter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-splitter.js","sources":["../../src/code-splitter.ts"],"sourcesContent":["import { isAbsolute, join } from 'node:path'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\
|
|
1
|
+
{"version":3,"file":"code-splitter.js","sources":["../../src/code-splitter.ts"],"sourcesContent":["import { isAbsolute, join } from 'node:path'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\n\nimport { compileAst } from './ast'\nimport { compileFile, splitFile } from './compilers'\nimport { getConfig } from './config'\nimport { splitPrefix } from './constants'\n\nimport type { Config } from './config'\nimport type { UnpluginContextMeta, UnpluginFactory } from 'unplugin'\n\nfunction capitalizeFirst(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1)\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\ntype BannedBeforeExternalPlugin = {\n identifier: string\n pkg: string\n usage: string\n frameworks: Array<UnpluginContextMeta['framework']>\n}\n\nconst bannedBeforeExternalPlugins: Array<BannedBeforeExternalPlugin> = [\n {\n identifier: '@react-refresh',\n pkg: '@vitejs/plugin-react',\n usage: 'viteReact()',\n frameworks: ['vite'],\n },\n]\n\nclass FoundPluginInBeforeCode extends Error {\n constructor(externalPlugin: BannedBeforeExternalPlugin, framework: string) {\n super(`We detected that the '${externalPlugin.pkg}' was passed before '@tanstack/router-plugin'. Please make sure that '@tanstack/router-plugin' is passed before '${externalPlugin.pkg}' and try again: \ne.g.\nplugins: [\n TanStackRouter${capitalizeFirst(framework)}(), // Place this before ${externalPlugin.usage}\n ${externalPlugin.usage},\n]\n`)\n }\n}\n\nexport const unpluginRouterCodeSplitterFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}, { framework }) => {\n const debug = Boolean(process.env.TSR_VITE_DEBUG)\n\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n const handleSplittingFile = async (code: string, id: string) => {\n const compiledAst = compileAst({\n root: ROOT,\n })\n\n if (debug) console.info('Splitting route: ', id)\n\n const compiled = await splitFile({\n code,\n compileAst: compiledAst,\n filename: id,\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 }\n\n const handleCompilingFile = async (code: string, id: string) => {\n const compiledAst = compileAst({\n root: ROOT,\n })\n\n if (debug) console.info('Handling createRoute: ', id)\n\n const compiled = await compileFile({\n code,\n compileAst: compiledAst,\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 {\n name: 'router-code-splitter-plugin',\n enforce: 'pre',\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) {\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 if (id.includes(splitPrefix)) {\n return await handleSplittingFile(code, id)\n } else if (\n fileIsInRoutesDirectory(id, userConfig.routesDirectory) &&\n (code.includes('createRoute(') || code.includes('createFileRoute('))\n ) {\n for (const externalPlugin of bannedBeforeExternalPlugins) {\n if (!externalPlugin.frameworks.includes(framework)) {\n continue\n }\n\n if (code.includes(externalPlugin.identifier)) {\n throw new FoundPluginInBeforeCode(externalPlugin, framework)\n }\n }\n\n return await handleCompilingFile(code, id)\n }\n\n return null\n },\n vite: {\n async configResolved(config) {\n ROOT = config.root\n userConfig = await getConfig(options, ROOT)\n },\n },\n }\n}\n"],"names":[],"mappings":";;;;;;AAWA,SAAS,gBAAgB,KAAqB;AACrC,SAAA,IAAI,OAAO,CAAC,EAAE,gBAAgB,IAAI,MAAM,CAAC;AAClD;AAEA,SAAS,wBAAwB,UAAkB,iBAAyB;AACpE,QAAA,sBAAsB,WAAW,eAAe,IAClD,kBACA,KAAK,QAAQ,OAAO,eAAe;AAEhC,SAAA,SAAS,WAAW,mBAAmB;AAChD;AASA,MAAM,8BAAiE;AAAA,EACrE;AAAA,IACE,YAAY;AAAA,IACZ,KAAK;AAAA,IACL,OAAO;AAAA,IACP,YAAY,CAAC,MAAM;AAAA,EACrB;AACF;AAEA,MAAM,gCAAgC,MAAM;AAAA,EAC1C,YAAY,gBAA4C,WAAmB;AACzE,UAAM,yBAAyB,eAAe,GAAG,oHAAoH,eAAe,GAAG;AAAA;AAAA;AAAA,kBAGzK,gBAAgB,SAAS,CAAC,4BAA4B,eAAe,KAAK;AAAA,IACxF,eAAe,KAAK;AAAA;AAAA,CAEvB;AAAA,EACC;AACF;AAEO,MAAM,oCAET,CAAC,UAAU,IAAI,EAAE,gBAAgB;AACnC,QAAM,QAAQ,QAAQ,QAAQ,IAAI,cAAc;AAE5C,MAAA,OAAe,QAAQ;AAC3B,MAAI,aAAa;AAEX,QAAA,sBAAsB,OAAO,MAAc,OAAe;AAC9D,UAAM,cAAc,WAAW;AAAA,MAC7B,MAAM;AAAA,IAAA,CACP;AAEG,QAAA;AAAe,cAAA,KAAK,qBAAqB,EAAE;AAEzC,UAAA,WAAW,MAAM,UAAU;AAAA,MAC/B;AAAA,MACA,YAAY;AAAA,MACZ,UAAU;AAAA,IAAA,CACX;AAEG,QAAA;AAAO,cAAQ,KAAK,EAAE;AACtB,QAAA;AAAO,cAAQ,KAAK,cAAc;AAClC,QAAA;AAAO,cAAQ,KA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QAAQ;;AACZ,UAAA,GAAC,gBAAW,iBAAX,mBAAyB,sBAAqB;AAC1C,eAAA;AAAA,MACT;AAEA,UAAI,OAAO,WAAW,cAAc,GAAG,GAAG;AACxC,eAAO,OAAO,QAAQ,cAAc,KAAK,EAAE;AAAA,MAC7C;AACO,aAAA;AAAA,IACT;AAAA,IACA,MAAM,UAAU,MAAM,IAAI;;AACpB,UAAA,GAAC,gBAAW,iBAAX,mBAAyB,sBAAqB;AAC1C,eAAA;AAAA,MACT;AAEM,YAAA,MAAM,cAAc,EAAE;AACxB,UAAA,aAAa,OAAO,GAAG;AAC3B,WAAK,cAAc,GAAG,EAAE,QAAQ,OAAO,GAAG;AAEtC,UAAA,GAAG,SAAS,WAAW,GAAG;AACrB,eAAA,MAAM,oBAAoB,MAAM,EAAE;AAAA,MAEzC,WAAA,wBAAwB,IAAI,WAAW,eAAe,MACrD,KAAK,SAAS,cAAc,KAAK,KAAK,SAAS,kBAAkB,IAClE;AACA,mBAAW,kBAAkB,6BAA6B;AACxD,cAAI,CAAC,eAAe,WAAW,SAAS,SAAS,GAAG;AAClD;AAAA,UACF;AAEA,cAAI,KAAK,SAAS,eAAe,UAAU,GAAG;AACtC,kBAAA,IAAI,wBAAwB,gBAAgB,SAAS;AAAA,UAC7D;AAAA,QACF;AAEO,eAAA,MAAM,oBAAoB,MAAM,EAAE;AAAA,MAC3C;AAEO,aAAA;AAAA,IACT;AAAA,IACA,MAAM;AAAA,MACJ,MAAM,eAAe,QAAQ;AAC3B,eAAO,OAAO;AACD,qBAAA,MAAM,UAAU,SAAS,IAAI;AAAA,MAC5C;AAAA,IACF;AAAA,EAAA;AAEJ;"}
|
package/dist/esm/config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
declare const configSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
3
|
+
export declare const configSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
4
4
|
routeFilePrefix: z.ZodOptional<z.ZodString>;
|
|
5
5
|
routeFileIgnorePrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
6
6
|
routeFileIgnorePattern: z.ZodOptional<z.ZodString>;
|
|
@@ -57,7 +57,7 @@ declare const configSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
|
57
57
|
routeTreeFileHeader?: string[] | undefined;
|
|
58
58
|
routeTreeFileFooter?: string[] | undefined;
|
|
59
59
|
}>;
|
|
60
|
-
export declare const getConfig: (inlineConfig: Partial<
|
|
60
|
+
export declare const getConfig: (inlineConfig: Partial<Config>, root: string) => Promise<{
|
|
61
61
|
routeFileIgnorePrefix: string;
|
|
62
62
|
routesDirectory: string;
|
|
63
63
|
generatedRouteTree: string;
|
|
@@ -75,5 +75,4 @@ export declare const getConfig: (inlineConfig: Partial<PluginOptions>, root: str
|
|
|
75
75
|
routeFilePrefix?: string | undefined;
|
|
76
76
|
routeFileIgnorePattern?: string | undefined;
|
|
77
77
|
}>;
|
|
78
|
-
export type
|
|
79
|
-
export {};
|
|
78
|
+
export type Config = z.infer<typeof configSchema>;
|
package/dist/esm/config.js
CHANGED
package/dist/esm/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sources":["../../src/config.ts"],"sourcesContent":["import { z } from 'zod'\nimport {\n configSchema as generatorConfigSchema,\n getConfig as getGeneratorConfig,\n} from '@tanstack/router-generator'\n\
|
|
1
|
+
{"version":3,"file":"config.js","sources":["../../src/config.ts"],"sourcesContent":["import { z } from 'zod'\nimport {\n configSchema as generatorConfigSchema,\n getConfig as getGeneratorConfig,\n} from '@tanstack/router-generator'\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 const getConfig = async (\n inlineConfig: Partial<Config>,\n root: string,\n) => {\n const config = await getGeneratorConfig(inlineConfig, root)\n\n return configSchema.parse({ ...config, ...inlineConfig })\n}\n\nexport type Config = z.infer<typeof configSchema>\n"],"names":["generatorConfigSchema","getGeneratorConfig"],"mappings":";;AAMa,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;AAEY,MAAA,YAAY,OACvB,cACA,SACG;AACH,QAAM,SAAS,MAAMC,YAAmB,cAAc,IAAI;AAE1D,SAAO,aAAa,MAAM,EAAE,GAAG,QAAQ,GAAG,cAAc;AAC1D;"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { unpluginRouterCodeSplitterFactory } from './code-splitter.js';
|
|
2
|
+
export { unpluginRouterGeneratorFactory } from './router-generator.js';
|
|
3
|
+
export { configSchema } from './config.js';
|
|
4
|
+
export type { Config } from './config.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { unpluginRouterCodeSplitterFactory } from "./code-splitter.js";
|
|
2
|
+
import { unpluginRouterGeneratorFactory } from "./router-generator.js";
|
|
3
|
+
import { configSchema } from "./config.js";
|
|
3
4
|
export {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
configSchema,
|
|
6
|
+
unpluginRouterCodeSplitterFactory,
|
|
7
|
+
unpluginRouterGeneratorFactory
|
|
6
8
|
};
|
|
7
9
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
quoteStyle: "single" | "double";
|
|
6
|
-
semicolons: boolean;
|
|
7
|
-
disableTypes: boolean;
|
|
8
|
-
addExtensions: boolean;
|
|
9
|
-
disableLogging: boolean;
|
|
10
|
-
routeTreeFileHeader: string[];
|
|
11
|
-
routeTreeFileFooter: string[];
|
|
12
|
-
enableRouteGeneration?: boolean | undefined;
|
|
13
|
-
experimental?: {
|
|
14
|
-
enableCodeSplitting?: boolean | undefined;
|
|
15
|
-
} | undefined;
|
|
16
|
-
routeFilePrefix?: string | undefined;
|
|
17
|
-
routeFileIgnorePattern?: string | undefined;
|
|
18
|
-
}> | undefined, boolean>;
|
|
1
|
+
import { Config } from './config.js';
|
|
2
|
+
import { UnpluginFactory } from 'unplugin';
|
|
3
|
+
|
|
4
|
+
export declare const unpluginRouterGeneratorFactory: UnpluginFactory<Partial<Config> | undefined>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { normalize, join, resolve, isAbsolute } from "node:path";
|
|
2
|
-
import { createUnplugin } from "unplugin";
|
|
3
2
|
import { generator } from "@tanstack/router-generator";
|
|
4
3
|
import { getConfig } from "./config.js";
|
|
5
4
|
import { CONFIG_FILE_NAME } from "./constants.js";
|
|
@@ -8,7 +7,7 @@ const checkLock = () => lock;
|
|
|
8
7
|
const setLock = (bool) => {
|
|
9
8
|
lock = bool;
|
|
10
9
|
};
|
|
11
|
-
const
|
|
10
|
+
const unpluginRouterGeneratorFactory = (options = {}) => {
|
|
12
11
|
let ROOT = process.cwd();
|
|
13
12
|
let userConfig = options;
|
|
14
13
|
const generate = async () => {
|
|
@@ -60,8 +59,7 @@ const unpluginFactory = (options = {}) => {
|
|
|
60
59
|
}
|
|
61
60
|
};
|
|
62
61
|
};
|
|
63
|
-
const unpluginRouterGenerator = /* @__PURE__ */ createUnplugin(unpluginFactory);
|
|
64
62
|
export {
|
|
65
|
-
|
|
63
|
+
unpluginRouterGeneratorFactory
|
|
66
64
|
};
|
|
67
65
|
//# sourceMappingURL=router-generator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-generator.js","sources":["../../src/router-generator.ts"],"sourcesContent":["import { isAbsolute, join, normalize, resolve } from 'node:path'\nimport {
|
|
1
|
+
{"version":3,"file":"router-generator.js","sources":["../../src/router-generator.ts"],"sourcesContent":["import { isAbsolute, join, normalize, resolve } from 'node:path'\nimport { generator } from '@tanstack/router-generator'\n\nimport { getConfig } from './config'\nimport { CONFIG_FILE_NAME } from './constants'\nimport type { Config } from './config'\nimport type { UnpluginFactory } from 'unplugin'\n\nlet lock = false\nconst checkLock = () => lock\nconst setLock = (bool: boolean) => {\n lock = bool\n}\n\nexport const unpluginRouterGeneratorFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}) => {\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n const generate = async () => {\n if (checkLock()) {\n return\n }\n\n setLock(true)\n\n try {\n await generator(userConfig)\n } catch (err) {\n console.error(err)\n console.info()\n } finally {\n setLock(false)\n }\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(options, 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 const run: (cb: () => Promise<void> | void) => Promise<void> = async (cb) => {\n if (userConfig.enableRouteGeneration ?? true) {\n await cb()\n }\n }\n\n return {\n name: 'router-generator-plugin',\n async watchChange(id, { event }) {\n await run(async () => {\n await handleFile(id, event)\n })\n },\n vite: {\n async configResolved(config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AM,UAAU,SAAS,IAAI;AAE1C,cAAM,IAAI,QAAQ;AAAA,MACpB;AAAA,IACF;AAAA,EAAA;AAEJ;"}
|
package/dist/esm/vite.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { configSchema, Config } from './config.js';
|
|
2
2
|
import { VitePlugin } from 'unplugin';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
declare const TanStackRouterGeneratorVite: (options?: Partial<{
|
|
5
5
|
routeFileIgnorePrefix: string;
|
|
6
6
|
routesDirectory: string;
|
|
7
7
|
generatedRouteTree: string;
|
|
@@ -19,7 +19,7 @@ export declare const TanStackRouterGeneratorVite: (options?: Partial<{
|
|
|
19
19
|
routeFilePrefix?: string | undefined;
|
|
20
20
|
routeFileIgnorePattern?: string | undefined;
|
|
21
21
|
}> | undefined) => VitePlugin<any> | VitePlugin<any>[];
|
|
22
|
-
|
|
22
|
+
declare const TanStackRouterCodeSplitterVite: (options?: Partial<{
|
|
23
23
|
routeFileIgnorePrefix: string;
|
|
24
24
|
routesDirectory: string;
|
|
25
25
|
generatedRouteTree: string;
|
|
@@ -37,5 +37,7 @@ export declare const TanStackRouterCodeSplitterVite: (options?: Partial<{
|
|
|
37
37
|
routeFilePrefix?: string | undefined;
|
|
38
38
|
routeFileIgnorePattern?: string | undefined;
|
|
39
39
|
}> | undefined) => VitePlugin<any> | VitePlugin<any>[];
|
|
40
|
-
|
|
41
|
-
export
|
|
40
|
+
declare function TanStackRouterVite(inlineConfig?: Partial<Config>): Array<VitePlugin>;
|
|
41
|
+
export default TanStackRouterVite;
|
|
42
|
+
export { configSchema, TanStackRouterGeneratorVite, TanStackRouterCodeSplitterVite, TanStackRouterVite, };
|
|
43
|
+
export type { Config };
|
package/dist/esm/vite.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { createVitePlugin } from "unplugin";
|
|
2
|
+
import { unpluginRouterCodeSplitterFactory } from "./code-splitter.js";
|
|
3
|
+
import { configSchema } from "./config.js";
|
|
4
|
+
import { unpluginRouterGeneratorFactory } from "./router-generator.js";
|
|
5
|
+
const TanStackRouterGeneratorVite = createVitePlugin(
|
|
6
|
+
unpluginRouterGeneratorFactory
|
|
7
|
+
);
|
|
8
|
+
const TanStackRouterCodeSplitterVite = createVitePlugin(
|
|
9
|
+
unpluginRouterCodeSplitterFactory
|
|
10
|
+
);
|
|
5
11
|
function TanStackRouterVite(inlineConfig) {
|
|
6
12
|
return [
|
|
7
13
|
TanStackRouterGeneratorVite(inlineConfig),
|
|
@@ -11,6 +17,8 @@ function TanStackRouterVite(inlineConfig) {
|
|
|
11
17
|
export {
|
|
12
18
|
TanStackRouterCodeSplitterVite,
|
|
13
19
|
TanStackRouterGeneratorVite,
|
|
14
|
-
TanStackRouterVite
|
|
20
|
+
TanStackRouterVite,
|
|
21
|
+
configSchema,
|
|
22
|
+
TanStackRouterVite as default
|
|
15
23
|
};
|
|
16
24
|
//# sourceMappingURL=vite.js.map
|
package/dist/esm/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","sources":["../../src/vite.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"vite.js","sources":["../../src/vite.ts"],"sourcesContent":["import { createVitePlugin } from 'unplugin'\nimport { unpluginRouterCodeSplitterFactory } from './code-splitter'\nimport { configSchema } from './config'\nimport { unpluginRouterGeneratorFactory } from './router-generator'\n\nimport type { Config } from './config'\nimport type { VitePlugin } from 'unplugin'\n\nconst TanStackRouterGeneratorVite = createVitePlugin(\n unpluginRouterGeneratorFactory,\n)\nconst TanStackRouterCodeSplitterVite = createVitePlugin(\n unpluginRouterCodeSplitterFactory,\n)\n\nfunction TanStackRouterVite(inlineConfig?: Partial<Config>): Array<VitePlugin> {\n return [\n TanStackRouterGeneratorVite(inlineConfig) as VitePlugin,\n TanStackRouterCodeSplitterVite(inlineConfig) as VitePlugin,\n ]\n}\n\nexport default TanStackRouterVite\nexport {\n configSchema,\n TanStackRouterGeneratorVite,\n TanStackRouterCodeSplitterVite,\n TanStackRouterVite,\n}\nexport type { Config }\n"],"names":[],"mappings":";;;;AAQA,MAAM,8BAA8B;AAAA,EAClC;AACF;AACA,MAAM,iCAAiC;AAAA,EACrC;AACF;AAEA,SAAS,mBAAmB,cAAmD;AACtE,SAAA;AAAA,IACL,4BAA4B,YAAY;AAAA,IACxC,+BAA+B,YAAY;AAAA,EAAA;AAE/C;"}
|
package/package.json
CHANGED
package/src/code-splitter.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { isAbsolute, join } from 'node:path'
|
|
2
2
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
3
|
-
import { createUnplugin } from 'unplugin'
|
|
4
3
|
|
|
5
4
|
import { compileAst } from './ast'
|
|
6
5
|
import { compileFile, splitFile } from './compilers'
|
|
7
6
|
import { getConfig } from './config'
|
|
8
7
|
import { splitPrefix } from './constants'
|
|
9
8
|
|
|
10
|
-
import type {
|
|
11
|
-
import type { UnpluginFactory } from 'unplugin'
|
|
9
|
+
import type { Config } from './config'
|
|
10
|
+
import type { UnpluginContextMeta, UnpluginFactory } from 'unplugin'
|
|
12
11
|
|
|
13
12
|
function capitalizeFirst(str: string): string {
|
|
14
13
|
return str.charAt(0).toUpperCase() + str.slice(1)
|
|
@@ -22,19 +21,24 @@ function fileIsInRoutesDirectory(filePath: string, routesDirectory: string) {
|
|
|
22
21
|
return filePath.startsWith(routesDirectoryPath)
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
type BannedBeforeExternalPlugin = {
|
|
25
|
+
identifier: string
|
|
26
|
+
pkg: string
|
|
27
|
+
usage: string
|
|
28
|
+
frameworks: Array<UnpluginContextMeta['framework']>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const bannedBeforeExternalPlugins: Array<BannedBeforeExternalPlugin> = [
|
|
26
32
|
{
|
|
27
33
|
identifier: '@react-refresh',
|
|
28
34
|
pkg: '@vitejs/plugin-react',
|
|
29
35
|
usage: 'viteReact()',
|
|
36
|
+
frameworks: ['vite'],
|
|
30
37
|
},
|
|
31
38
|
]
|
|
32
39
|
|
|
33
40
|
class FoundPluginInBeforeCode extends Error {
|
|
34
|
-
constructor(
|
|
35
|
-
externalPlugin: (typeof bannedBeforeExternalPlugins)[number],
|
|
36
|
-
framework: string,
|
|
37
|
-
) {
|
|
41
|
+
constructor(externalPlugin: BannedBeforeExternalPlugin, framework: string) {
|
|
38
42
|
super(`We detected that the '${externalPlugin.pkg}' was passed before '@tanstack/router-plugin'. Please make sure that '@tanstack/router-plugin' is passed before '${externalPlugin.pkg}' and try again:
|
|
39
43
|
e.g.
|
|
40
44
|
plugins: [
|
|
@@ -45,13 +49,13 @@ plugins: [
|
|
|
45
49
|
}
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
export const
|
|
49
|
-
Partial<
|
|
52
|
+
export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
53
|
+
Partial<Config> | undefined
|
|
50
54
|
> = (options = {}, { framework }) => {
|
|
51
55
|
const debug = Boolean(process.env.TSR_VITE_DEBUG)
|
|
52
56
|
|
|
53
57
|
let ROOT: string = process.cwd()
|
|
54
|
-
let userConfig = options as
|
|
58
|
+
let userConfig = options as Config
|
|
55
59
|
|
|
56
60
|
const handleSplittingFile = async (code: string, id: string) => {
|
|
57
61
|
const compiledAst = compileAst({
|
|
@@ -127,6 +131,10 @@ export const unpluginFactory: UnpluginFactory<
|
|
|
127
131
|
return null
|
|
128
132
|
},
|
|
129
133
|
async transform(code, id) {
|
|
134
|
+
if (!userConfig.experimental?.enableCodeSplitting) {
|
|
135
|
+
return null
|
|
136
|
+
}
|
|
137
|
+
|
|
130
138
|
const url = pathToFileURL(id)
|
|
131
139
|
url.searchParams.delete('v')
|
|
132
140
|
id = fileURLToPath(url).replace(/\\/g, '/')
|
|
@@ -138,6 +146,10 @@ export const unpluginFactory: UnpluginFactory<
|
|
|
138
146
|
(code.includes('createRoute(') || code.includes('createFileRoute('))
|
|
139
147
|
) {
|
|
140
148
|
for (const externalPlugin of bannedBeforeExternalPlugins) {
|
|
149
|
+
if (!externalPlugin.frameworks.includes(framework)) {
|
|
150
|
+
continue
|
|
151
|
+
}
|
|
152
|
+
|
|
141
153
|
if (code.includes(externalPlugin.identifier)) {
|
|
142
154
|
throw new FoundPluginInBeforeCode(externalPlugin, framework)
|
|
143
155
|
}
|
|
@@ -156,6 +168,3 @@ export const unpluginFactory: UnpluginFactory<
|
|
|
156
168
|
},
|
|
157
169
|
}
|
|
158
170
|
}
|
|
159
|
-
|
|
160
|
-
export const unpluginRouterCodeSplitter =
|
|
161
|
-
/* #__PURE__ */ createUnplugin(unpluginFactory)
|
package/src/config.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
getConfig as getGeneratorConfig,
|
|
5
5
|
} from '@tanstack/router-generator'
|
|
6
6
|
|
|
7
|
-
const configSchema = generatorConfigSchema.extend({
|
|
7
|
+
export const configSchema = generatorConfigSchema.extend({
|
|
8
8
|
enableRouteGeneration: z.boolean().optional(),
|
|
9
9
|
experimental: z
|
|
10
10
|
.object({
|
|
@@ -14,7 +14,7 @@ const configSchema = generatorConfigSchema.extend({
|
|
|
14
14
|
})
|
|
15
15
|
|
|
16
16
|
export const getConfig = async (
|
|
17
|
-
inlineConfig: Partial<
|
|
17
|
+
inlineConfig: Partial<Config>,
|
|
18
18
|
root: string,
|
|
19
19
|
) => {
|
|
20
20
|
const config = await getGeneratorConfig(inlineConfig, root)
|
|
@@ -22,4 +22,4 @@ export const getConfig = async (
|
|
|
22
22
|
return configSchema.parse({ ...config, ...inlineConfig })
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export type
|
|
25
|
+
export type Config = z.infer<typeof configSchema>
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { unpluginRouterCodeSplitterFactory } from './code-splitter'
|
|
2
|
+
export { unpluginRouterGeneratorFactory } from './router-generator'
|
|
3
|
+
export { configSchema } from './config'
|
|
4
|
+
export type { Config } from './config'
|
package/src/router-generator.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { isAbsolute, join, normalize, resolve } from 'node:path'
|
|
2
|
-
import { createUnplugin } from 'unplugin'
|
|
3
2
|
import { generator } from '@tanstack/router-generator'
|
|
4
3
|
|
|
5
4
|
import { getConfig } from './config'
|
|
6
5
|
import { CONFIG_FILE_NAME } from './constants'
|
|
7
|
-
import type {
|
|
6
|
+
import type { Config } from './config'
|
|
8
7
|
import type { UnpluginFactory } from 'unplugin'
|
|
9
8
|
|
|
10
9
|
let lock = false
|
|
@@ -13,11 +12,11 @@ const setLock = (bool: boolean) => {
|
|
|
13
12
|
lock = bool
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
) => {
|
|
15
|
+
export const unpluginRouterGeneratorFactory: UnpluginFactory<
|
|
16
|
+
Partial<Config> | undefined
|
|
17
|
+
> = (options = {}) => {
|
|
19
18
|
let ROOT: string = process.cwd()
|
|
20
|
-
let userConfig = options as
|
|
19
|
+
let userConfig = options as Config
|
|
21
20
|
|
|
22
21
|
const generate = async () => {
|
|
23
22
|
if (checkLock()) {
|
|
@@ -87,6 +86,3 @@ const unpluginFactory: UnpluginFactory<Partial<PluginOptions> | undefined> = (
|
|
|
87
86
|
},
|
|
88
87
|
}
|
|
89
88
|
}
|
|
90
|
-
|
|
91
|
-
export const unpluginRouterGenerator =
|
|
92
|
-
/* #__PURE__ */ createUnplugin(unpluginFactory)
|
package/src/vite.ts
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { createVitePlugin } from 'unplugin'
|
|
2
|
+
import { unpluginRouterCodeSplitterFactory } from './code-splitter'
|
|
3
|
+
import { configSchema } from './config'
|
|
4
|
+
import { unpluginRouterGeneratorFactory } from './router-generator'
|
|
3
5
|
|
|
4
|
-
import type {
|
|
6
|
+
import type { Config } from './config'
|
|
5
7
|
import type { VitePlugin } from 'unplugin'
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
const TanStackRouterGeneratorVite = createVitePlugin(
|
|
10
|
+
unpluginRouterGeneratorFactory,
|
|
11
|
+
)
|
|
12
|
+
const TanStackRouterCodeSplitterVite = createVitePlugin(
|
|
13
|
+
unpluginRouterCodeSplitterFactory,
|
|
14
|
+
)
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
inlineConfig?: Partial<PluginOptions>,
|
|
12
|
-
): Array<VitePlugin> {
|
|
16
|
+
function TanStackRouterVite(inlineConfig?: Partial<Config>): Array<VitePlugin> {
|
|
13
17
|
return [
|
|
14
18
|
TanStackRouterGeneratorVite(inlineConfig) as VitePlugin,
|
|
15
19
|
TanStackRouterCodeSplitterVite(inlineConfig) as VitePlugin,
|
|
16
20
|
]
|
|
17
21
|
}
|
|
18
22
|
|
|
19
|
-
export
|
|
23
|
+
export default TanStackRouterVite
|
|
24
|
+
export {
|
|
25
|
+
configSchema,
|
|
26
|
+
TanStackRouterGeneratorVite,
|
|
27
|
+
TanStackRouterCodeSplitterVite,
|
|
28
|
+
TanStackRouterVite,
|
|
29
|
+
}
|
|
30
|
+
export type { Config }
|