@tanstack/router-plugin 1.39.4 → 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 +7 -6
- package/dist/cjs/code-splitter.cjs.map +1 -1
- package/dist/cjs/code-splitter.d.cts +1 -19
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/index.d.cts +2 -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 +9 -3
- package/dist/cjs/vite.cjs.map +1 -1
- package/dist/cjs/vite.d.cts +1 -0
- package/dist/esm/code-splitter.d.ts +1 -19
- package/dist/esm/code-splitter.js +7 -6
- package/dist/esm/code-splitter.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +4 -4
- 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 +1 -0
- package/dist/esm/vite.js +11 -5
- package/dist/esm/vite.js.map +1 -1
- package/package.json +1 -1
- package/src/code-splitter.ts +18 -14
- package/src/index.ts +2 -2
- package/src/router-generator.ts +3 -7
- package/src/vite.ts +10 -4
|
@@ -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;
|
|
@@ -139,6 +139,9 @@ const unpluginFactory = (options = {}, { framework }) => {
|
|
|
139
139
|
return await handleSplittingFile(code, id);
|
|
140
140
|
} else if (fileIsInRoutesDirectory(id, userConfig.routesDirectory) && (code.includes("createRoute(") || code.includes("createFileRoute("))) {
|
|
141
141
|
for (const externalPlugin of bannedBeforeExternalPlugins) {
|
|
142
|
+
if (!externalPlugin.frameworks.includes(framework)) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
142
145
|
if (code.includes(externalPlugin.identifier)) {
|
|
143
146
|
throw new FoundPluginInBeforeCode(externalPlugin, framework);
|
|
144
147
|
}
|
|
@@ -155,7 +158,5 @@ const unpluginFactory = (options = {}, { framework }) => {
|
|
|
155
158
|
}
|
|
156
159
|
};
|
|
157
160
|
};
|
|
158
|
-
|
|
159
|
-
exports.unpluginFactory = unpluginFactory;
|
|
160
|
-
exports.unpluginRouterCodeSplitter = unpluginRouterCodeSplitter;
|
|
161
|
+
exports.unpluginRouterCodeSplitterFactory = unpluginRouterCodeSplitterFactory;
|
|
161
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","split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B;AAC1C,eAAA;AAAA,MACT;AAEA,UAAI,OAAO,WAAWC,UAAc,cAAA,GAAG,GAAG;AACxC,eAAO,OAAO,QAAQA,UAAc,cAAA,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,MAAMC,uBAAc,EAAE;AACxB,UAAA,aAAa,OAAO,GAAG;AAC3B,WAAKC,SAAc,cAAA,GAAG,EAAE,QAAQ,OAAO,GAAG;AAEtC,UAAA,GAAG,SAASF,UAAAA,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,eAAeG,UAAQ;AAC3B,eAAOA,SAAO;AACD,qBAAA,MAAMC,OAAAA,UAAU,SAAS,IAAI;AAAA,MAC5C;AAAA,IACF;AAAA,EAAA;AAEJ;;"}
|
|
@@ -1,22 +1,4 @@
|
|
|
1
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/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const codeSplitter = require("./code-splitter.cjs");
|
|
4
4
|
const routerGenerator = require("./router-generator.cjs");
|
|
5
5
|
const config = require("./config.cjs");
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
6
|
+
exports.unpluginRouterCodeSplitterFactory = codeSplitter.unpluginRouterCodeSplitterFactory;
|
|
7
|
+
exports.unpluginRouterGeneratorFactory = routerGenerator.unpluginRouterGeneratorFactory;
|
|
8
8
|
exports.configSchema = config.configSchema;
|
|
9
9
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { unpluginRouterCodeSplitterFactory } from './code-splitter.cjs';
|
|
2
|
+
export { unpluginRouterGeneratorFactory } from './router-generator.cjs';
|
|
3
3
|
export { configSchema } from './config.cjs';
|
|
4
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,YAAY,MAAM;AACxB,MAAM,UAAU,CAAC,SAAkB;AAC1B,SAAA;AACT;AAEO,MAAM,iCAET,CAAC,UAAU,OAAO;AAChB,MAAA,OAAe,QAAQ;AAC3B,MAAI,aAAa;AAEjB,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf;AAAA,IACF;AAEA,YAAQ,IAAI;AAER,QAAA;AACF,YAAMA,gBAAAA,UAAU,UAAU;AAAA,aACnB,KAAK;AACZ,cAAQ,MAAM,GAAG;AACjB,cAAQ,KAAK;AAAA,IAAA,UACb;AACA,cAAQ,KAAK;AAAA,IACf;AAAA,EAAA;AAGI,QAAA,aAAa,OACjB,MACA,UACG;AACG,UAAA,WAAWC,oBAAU,IAAI;AAE/B,QAAI,aAAaC,UAAAA,KAAK,MAAMC,UAAgB,gBAAA,GAAG;AAChC,mBAAA,MAAMC,OAAAA,UAAU,SAAS,IAAI;AAC1C;AAAA,IACF;AAEA,QACE,UAAU,YACV,aAAaC,UAAAA,QAAQ,WAAW,kBAAkB,GAClD;AAEA;AAAA,IACF;AAEM,UAAA,sBAAsBC,UAAAA,WAAW,WAAW,eAAe,IAC7D,WAAW,kBACXJ,eAAK,MAAM,WAAW,eAAe;AAErC,QAAA,SAAS,WAAW,mBAAmB,GAAG;AAC5C,YAAM,SAAS;AAAA,IACjB;AAAA,EAAA;AAGI,QAAA,MAAyD,OAAO,OAAO;AACvE,QAAA,WAAW,yBAAyB,MAAM;AAC5C,YAAM,GAAG;AAAA,IACX;AAAA,EAAA;AAGK,SAAA;AAAA,IACL,MAAM;AAAA,IACN,MAAM,YAAY,IAAI,EAAE,SAAS;AAC/B,YAAM,IAAI,YAAY;AACd,cAAA,WAAW,IAAI,KAAK;AAAA,MAAA,CAC3B;AAAA,IACH;AAAA,IACA,MAAM;AAAA,MACJ,MAAM,eAAeK,UAAQ;AAC3B,eAAOA,SAAO;AACD,qBAAA,MAAMH,OAAAA,UAAU,SAAS,IAAI;AAE1C,cAAM,IAAI,QAAQ;AAAA,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,10 +1,15 @@
|
|
|
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");
|
|
4
5
|
const config = require("./config.cjs");
|
|
5
6
|
const routerGenerator = require("./router-generator.cjs");
|
|
6
|
-
const TanStackRouterGeneratorVite =
|
|
7
|
-
|
|
7
|
+
const TanStackRouterGeneratorVite = unplugin.createVitePlugin(
|
|
8
|
+
routerGenerator.unpluginRouterGeneratorFactory
|
|
9
|
+
);
|
|
10
|
+
const TanStackRouterCodeSplitterVite = unplugin.createVitePlugin(
|
|
11
|
+
codeSplitter.unpluginRouterCodeSplitterFactory
|
|
12
|
+
);
|
|
8
13
|
function TanStackRouterVite(inlineConfig) {
|
|
9
14
|
return [
|
|
10
15
|
TanStackRouterGeneratorVite(inlineConfig),
|
|
@@ -15,4 +20,5 @@ exports.configSchema = config.configSchema;
|
|
|
15
20
|
exports.TanStackRouterCodeSplitterVite = TanStackRouterCodeSplitterVite;
|
|
16
21
|
exports.TanStackRouterGeneratorVite = TanStackRouterGeneratorVite;
|
|
17
22
|
exports.TanStackRouterVite = TanStackRouterVite;
|
|
23
|
+
exports.default = TanStackRouterVite;
|
|
18
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
|
@@ -38,5 +38,6 @@ declare const TanStackRouterCodeSplitterVite: (options?: Partial<{
|
|
|
38
38
|
routeFileIgnorePattern?: string | undefined;
|
|
39
39
|
}> | undefined) => VitePlugin<any> | VitePlugin<any>[];
|
|
40
40
|
declare function TanStackRouterVite(inlineConfig?: Partial<Config>): Array<VitePlugin>;
|
|
41
|
+
export default TanStackRouterVite;
|
|
41
42
|
export { configSchema, TanStackRouterGeneratorVite, TanStackRouterCodeSplitterVite, TanStackRouterVite, };
|
|
42
43
|
export type { Config };
|
|
@@ -1,22 +1,4 @@
|
|
|
1
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;
|
|
@@ -137,6 +137,9 @@ const unpluginFactory = (options = {}, { framework }) => {
|
|
|
137
137
|
return await handleSplittingFile(code, id);
|
|
138
138
|
} else if (fileIsInRoutesDirectory(id, userConfig.routesDirectory) && (code.includes("createRoute(") || code.includes("createFileRoute("))) {
|
|
139
139
|
for (const externalPlugin of bannedBeforeExternalPlugins) {
|
|
140
|
+
if (!externalPlugin.frameworks.includes(framework)) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
140
143
|
if (code.includes(externalPlugin.identifier)) {
|
|
141
144
|
throw new FoundPluginInBeforeCode(externalPlugin, framework);
|
|
142
145
|
}
|
|
@@ -153,9 +156,7 @@ const unpluginFactory = (options = {}, { framework }) => {
|
|
|
153
156
|
}
|
|
154
157
|
};
|
|
155
158
|
};
|
|
156
|
-
const unpluginRouterCodeSplitter = /* @__PURE__ */ createUnplugin(unpluginFactory);
|
|
157
159
|
export {
|
|
158
|
-
|
|
159
|
-
unpluginRouterCodeSplitter
|
|
160
|
+
unpluginRouterCodeSplitterFactory
|
|
160
161
|
};
|
|
161
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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AAW,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/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { unpluginRouterCodeSplitterFactory } from './code-splitter.js';
|
|
2
|
+
export { unpluginRouterGeneratorFactory } from './router-generator.js';
|
|
3
3
|
export { configSchema } from './config.js';
|
|
4
4
|
export type { Config } from './config.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { unpluginRouterCodeSplitterFactory } from "./code-splitter.js";
|
|
2
|
+
import { unpluginRouterGeneratorFactory } from "./router-generator.js";
|
|
3
3
|
import { configSchema } from "./config.js";
|
|
4
4
|
export {
|
|
5
5
|
configSchema,
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
unpluginRouterCodeSplitterFactory,
|
|
7
|
+
unpluginRouterGeneratorFactory
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -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) {\n ROOT = config.root\n userConfig = await getConfig(options, ROOT)\n\n await run(generate)\n },\n },\n }\n}\n"],"names":[],"mappings":";;;;AAQA,IAAI,OAAO;AACX,MAAM,YAAY,MAAM;AACxB,MAAM,UAAU,CAAC,SAAkB;AAC1B,SAAA;AACT;AAEO,MAAM,iCAET,CAAC,UAAU,OAAO;AAChB,MAAA,OAAe,QAAQ;AAC3B,MAAI,aAAa;AAEjB,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf;AAAA,IACF;AAEA,YAAQ,IAAI;AAER,QAAA;AACF,YAAM,UAAU,UAAU;AAAA,aACnB,KAAK;AACZ,cAAQ,MAAM,GAAG;AACjB,cAAQ,KAAK;AAAA,IAAA,UACb;AACA,cAAQ,KAAK;AAAA,IACf;AAAA,EAAA;AAGI,QAAA,aAAa,OACjB,MACA,UACG;AACG,UAAA,WAAW,UAAU,IAAI;AAE/B,QAAI,aAAa,KAAK,MAAM,gBAAgB,GAAG;AAChC,mBAAA,MAAM,UAAU,SAAS,IAAI;AAC1C;AAAA,IACF;AAEA,QACE,UAAU,YACV,aAAa,QAAQ,WAAW,kBAAkB,GAClD;AAEA;AAAA,IACF;AAEM,UAAA,sBAAsB,WAAW,WAAW,eAAe,IAC7D,WAAW,kBACX,KAAK,MAAM,WAAW,eAAe;AAErC,QAAA,SAAS,WAAW,mBAAmB,GAAG;AAC5C,YAAM,SAAS;AAAA,IACjB;AAAA,EAAA;AAGI,QAAA,MAAyD,OAAO,OAAO;AACvE,QAAA,WAAW,yBAAyB,MAAM;AAC5C,YAAM,GAAG;AAAA,IACX;AAAA,EAAA;AAGK,SAAA;AAAA,IACL,MAAM;AAAA,IACN,MAAM,YAAY,IAAI,EAAE,SAAS;AAC/B,YAAM,IAAI,YAAY;AACd,cAAA,WAAW,IAAI,KAAK;AAAA,MAAA,CAC3B;AAAA,IACH;AAAA,IACA,MAAM;AAAA,MACJ,MAAM,eAAe,QAAQ;AAC3B,eAAO,OAAO;AACD,qBAAA,MAAM,UAAU,SAAS,IAAI;AAE1C,cAAM,IAAI,QAAQ;AAAA,MACpB;AAAA,IACF;AAAA,EAAA;AAEJ;"}
|
package/dist/esm/vite.d.ts
CHANGED
|
@@ -38,5 +38,6 @@ declare const TanStackRouterCodeSplitterVite: (options?: Partial<{
|
|
|
38
38
|
routeFileIgnorePattern?: string | undefined;
|
|
39
39
|
}> | undefined) => VitePlugin<any> | VitePlugin<any>[];
|
|
40
40
|
declare function TanStackRouterVite(inlineConfig?: Partial<Config>): Array<VitePlugin>;
|
|
41
|
+
export default TanStackRouterVite;
|
|
41
42
|
export { configSchema, TanStackRouterGeneratorVite, TanStackRouterCodeSplitterVite, TanStackRouterVite, };
|
|
42
43
|
export type { Config };
|
package/dist/esm/vite.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createVitePlugin } from "unplugin";
|
|
2
|
+
import { unpluginRouterCodeSplitterFactory } from "./code-splitter.js";
|
|
2
3
|
import { configSchema } from "./config.js";
|
|
3
|
-
import {
|
|
4
|
-
const TanStackRouterGeneratorVite =
|
|
5
|
-
|
|
4
|
+
import { unpluginRouterGeneratorFactory } from "./router-generator.js";
|
|
5
|
+
const TanStackRouterGeneratorVite = createVitePlugin(
|
|
6
|
+
unpluginRouterGeneratorFactory
|
|
7
|
+
);
|
|
8
|
+
const TanStackRouterCodeSplitterVite = createVitePlugin(
|
|
9
|
+
unpluginRouterCodeSplitterFactory
|
|
10
|
+
);
|
|
6
11
|
function TanStackRouterVite(inlineConfig) {
|
|
7
12
|
return [
|
|
8
13
|
TanStackRouterGeneratorVite(inlineConfig),
|
|
@@ -13,6 +18,7 @@ export {
|
|
|
13
18
|
TanStackRouterCodeSplitterVite,
|
|
14
19
|
TanStackRouterGeneratorVite,
|
|
15
20
|
TanStackRouterVite,
|
|
16
|
-
configSchema
|
|
21
|
+
configSchema,
|
|
22
|
+
TanStackRouterVite as default
|
|
17
23
|
};
|
|
18
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,6 +1,5 @@
|
|
|
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'
|
|
@@ -8,7 +7,7 @@ import { getConfig } from './config'
|
|
|
8
7
|
import { splitPrefix } from './constants'
|
|
9
8
|
|
|
10
9
|
import type { Config } from './config'
|
|
11
|
-
import type { UnpluginFactory } from 'unplugin'
|
|
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,10 +49,9 @@ plugins: [
|
|
|
45
49
|
}
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
export const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
) => {
|
|
52
|
+
export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
53
|
+
Partial<Config> | undefined
|
|
54
|
+
> = (options = {}, { framework }) => {
|
|
52
55
|
const debug = Boolean(process.env.TSR_VITE_DEBUG)
|
|
53
56
|
|
|
54
57
|
let ROOT: string = process.cwd()
|
|
@@ -143,6 +146,10 @@ export const unpluginFactory: UnpluginFactory<Partial<Config> | undefined> = (
|
|
|
143
146
|
(code.includes('createRoute(') || code.includes('createFileRoute('))
|
|
144
147
|
) {
|
|
145
148
|
for (const externalPlugin of bannedBeforeExternalPlugins) {
|
|
149
|
+
if (!externalPlugin.frameworks.includes(framework)) {
|
|
150
|
+
continue
|
|
151
|
+
}
|
|
152
|
+
|
|
146
153
|
if (code.includes(externalPlugin.identifier)) {
|
|
147
154
|
throw new FoundPluginInBeforeCode(externalPlugin, framework)
|
|
148
155
|
}
|
|
@@ -161,6 +168,3 @@ export const unpluginFactory: UnpluginFactory<Partial<Config> | undefined> = (
|
|
|
161
168
|
},
|
|
162
169
|
}
|
|
163
170
|
}
|
|
164
|
-
|
|
165
|
-
export const unpluginRouterCodeSplitter =
|
|
166
|
-
/* #__PURE__ */ createUnplugin(unpluginFactory)
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { unpluginRouterCodeSplitterFactory } from './code-splitter'
|
|
2
|
+
export { unpluginRouterGeneratorFactory } from './router-generator'
|
|
3
3
|
export { configSchema } from './config'
|
|
4
4
|
export type { Config } from './config'
|
package/src/router-generator.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
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'
|
|
@@ -13,9 +12,9 @@ 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
19
|
let userConfig = options as Config
|
|
21
20
|
|
|
@@ -87,6 +86,3 @@ const unpluginFactory: UnpluginFactory<Partial<Config> | undefined> = (
|
|
|
87
86
|
},
|
|
88
87
|
}
|
|
89
88
|
}
|
|
90
|
-
|
|
91
|
-
export const unpluginRouterGenerator =
|
|
92
|
-
/* #__PURE__ */ createUnplugin(unpluginFactory)
|
package/src/vite.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createVitePlugin } from 'unplugin'
|
|
2
|
+
import { unpluginRouterCodeSplitterFactory } from './code-splitter'
|
|
2
3
|
import { configSchema } from './config'
|
|
3
|
-
import {
|
|
4
|
+
import { unpluginRouterGeneratorFactory } from './router-generator'
|
|
4
5
|
|
|
5
6
|
import type { Config } from './config'
|
|
6
7
|
import type { VitePlugin } from 'unplugin'
|
|
7
8
|
|
|
8
|
-
const TanStackRouterGeneratorVite =
|
|
9
|
-
|
|
9
|
+
const TanStackRouterGeneratorVite = createVitePlugin(
|
|
10
|
+
unpluginRouterGeneratorFactory,
|
|
11
|
+
)
|
|
12
|
+
const TanStackRouterCodeSplitterVite = createVitePlugin(
|
|
13
|
+
unpluginRouterCodeSplitterFactory,
|
|
14
|
+
)
|
|
10
15
|
|
|
11
16
|
function TanStackRouterVite(inlineConfig?: Partial<Config>): Array<VitePlugin> {
|
|
12
17
|
return [
|
|
@@ -15,6 +20,7 @@ function TanStackRouterVite(inlineConfig?: Partial<Config>): Array<VitePlugin> {
|
|
|
15
20
|
]
|
|
16
21
|
}
|
|
17
22
|
|
|
23
|
+
export default TanStackRouterVite
|
|
18
24
|
export {
|
|
19
25
|
configSchema,
|
|
20
26
|
TanStackRouterGeneratorVite,
|