@tanstack/router-plugin 1.39.4 → 1.39.9
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 +10 -6
- package/dist/cjs/code-splitter.cjs.map +1 -1
- package/dist/cjs/code-splitter.d.cts +1 -19
- package/dist/cjs/composed.cjs +16 -0
- package/dist/cjs/composed.cjs.map +1 -0
- package/dist/cjs/composed.d.cts +4 -0
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/index.d.cts +2 -2
- package/dist/cjs/router-generator.cjs +10 -4
- package/dist/cjs/router-generator.cjs.map +1 -1
- package/dist/cjs/router-generator.d.cts +4 -18
- package/dist/cjs/rspack.cjs +20 -0
- package/dist/cjs/rspack.cjs.map +1 -0
- package/dist/cjs/rspack.d.cts +107 -0
- package/dist/cjs/vite.cjs +11 -9
- package/dist/cjs/vite.cjs.map +1 -1
- package/dist/cjs/vite.d.cts +48 -4
- package/dist/esm/code-splitter.d.ts +1 -19
- package/dist/esm/code-splitter.js +10 -6
- package/dist/esm/code-splitter.js.map +1 -1
- package/dist/esm/composed.d.ts +4 -0
- package/dist/esm/composed.js +16 -0
- package/dist/esm/composed.js.map +1 -0
- 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 +10 -4
- package/dist/esm/router-generator.js.map +1 -1
- package/dist/esm/rspack.d.ts +107 -0
- package/dist/esm/rspack.js +20 -0
- package/dist/esm/rspack.js.map +1 -0
- package/dist/esm/vite.d.ts +48 -4
- package/dist/esm/vite.js +13 -11
- package/dist/esm/vite.js.map +1 -1
- package/package.json +16 -2
- package/src/code-splitter.ts +27 -14
- package/src/composed.ts +30 -0
- package/src/index.ts +2 -2
- package/src/router-generator.ts +15 -8
- package/src/rspack.ts +74 -0
- package/src/vite.ts +40 -11
|
@@ -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
|
}
|
|
@@ -152,10 +155,11 @@ const unpluginFactory = (options = {}, { framework }) => {
|
|
|
152
155
|
ROOT = config$1.root;
|
|
153
156
|
userConfig = await config.getConfig(options, ROOT);
|
|
154
157
|
}
|
|
158
|
+
},
|
|
159
|
+
async rspack(compiler) {
|
|
160
|
+
userConfig = await config.getConfig(options, ROOT);
|
|
155
161
|
}
|
|
156
162
|
};
|
|
157
163
|
};
|
|
158
|
-
|
|
159
|
-
exports.unpluginFactory = unpluginFactory;
|
|
160
|
-
exports.unpluginRouterCodeSplitter = unpluginRouterCodeSplitter;
|
|
164
|
+
exports.unpluginRouterCodeSplitterFactory = unpluginRouterCodeSplitterFactory;
|
|
161
165
|
//# 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\nconst PLUGIN_NAME = 'unplugin:router-code-splitter'\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\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\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\n vite: {\n async configResolved(config) {\n ROOT = config.root\n userConfig = await getConfig(options, ROOT)\n },\n },\n\n async rspack(compiler) {\n userConfig = await getConfig(options, ROOT)\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,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AAe,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,IAEA,MAAM;AAAA,MACJ,MAAM,eAAeG,UAAQ;AAC3B,eAAOA,SAAO;AACD,qBAAA,MAAMC,OAAAA,UAAU,SAAS,IAAI;AAAA,MAC5C;AAAA,IACF;AAAA,IAEA,MAAM,OAAO,UAAU;AACR,mBAAA,MAAMA,OAAAA,UAAU,SAAS,IAAI;AAAA,IAC5C;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>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const routerGenerator = require("./router-generator.cjs");
|
|
4
|
+
const codeSplitter = require("./code-splitter.cjs");
|
|
5
|
+
const unpluginRouterComposedFactory = (options = {}, meta) => {
|
|
6
|
+
const routerGenerator$1 = routerGenerator.unpluginRouterGeneratorFactory(options);
|
|
7
|
+
const routerGeneratorOptions = Array.isArray(routerGenerator$1) ? routerGenerator$1 : [routerGenerator$1];
|
|
8
|
+
const routerCodeSplitter = codeSplitter.unpluginRouterCodeSplitterFactory(options, meta);
|
|
9
|
+
let routerCodeSplitterOptions = Array.isArray(routerCodeSplitter) ? routerCodeSplitter : [routerCodeSplitter];
|
|
10
|
+
if (meta.framework === "rspack") {
|
|
11
|
+
routerCodeSplitterOptions = [];
|
|
12
|
+
}
|
|
13
|
+
return [...routerGeneratorOptions, ...routerCodeSplitterOptions];
|
|
14
|
+
};
|
|
15
|
+
exports.unpluginRouterComposedFactory = unpluginRouterComposedFactory;
|
|
16
|
+
//# sourceMappingURL=composed.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composed.cjs","sources":["../../src/composed.ts"],"sourcesContent":["import { unpluginRouterGeneratorFactory } from './router-generator'\nimport { unpluginRouterCodeSplitterFactory } from './code-splitter'\n\nimport type { Config } from './config'\nimport type { UnpluginFactory } from 'unplugin'\n\nexport const unpluginRouterComposedFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}, meta) => {\n const routerGenerator = unpluginRouterGeneratorFactory(options, meta)\n\n const routerGeneratorOptions = Array.isArray(routerGenerator)\n ? routerGenerator\n : [routerGenerator]\n\n const routerCodeSplitter = unpluginRouterCodeSplitterFactory(options, meta)\n let routerCodeSplitterOptions = Array.isArray(routerCodeSplitter)\n ? routerCodeSplitter\n : [routerCodeSplitter]\n\n // Rspack doesn't support the `resolveId` and `transform` hooks provided by unplugin\n // so we need to disable the code splitter for it\n // If you're using Rspack, and know how to implement the code splitting, please let us know\n // We'd love to support it, but we're not sure how to do it yet\n if (meta.framework === 'rspack') {\n routerCodeSplitterOptions = []\n }\n\n return [...routerGeneratorOptions, ...routerCodeSplitterOptions]\n}\n"],"names":["routerGenerator","unpluginRouterGeneratorFactory","unpluginRouterCodeSplitterFactory"],"mappings":";;;;AAMO,MAAM,gCAET,CAAC,UAAU,IAAI,SAAS;AACpB,QAAAA,oBAAkBC,+CAA+B,OAAa;AAEpE,QAAM,yBAAyB,MAAM,QAAQD,iBAAe,IACxDA,oBACA,CAACA,iBAAe;AAEd,QAAA,qBAAqBE,aAAAA,kCAAkC,SAAS,IAAI;AAC1E,MAAI,4BAA4B,MAAM,QAAQ,kBAAkB,IAC5D,qBACA,CAAC,kBAAkB;AAMnB,MAAA,KAAK,cAAc,UAAU;AAC/B,gCAA4B,CAAA;AAAA,EAC9B;AAEA,SAAO,CAAC,GAAG,wBAAwB,GAAG,yBAAyB;AACjE;;"}
|
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,8 @@ const checkLock = () => lock;
|
|
|
10
9
|
const setLock = (bool) => {
|
|
11
10
|
lock = bool;
|
|
12
11
|
};
|
|
13
|
-
const
|
|
12
|
+
const PLUGIN_NAME = "unplugin:router-generator";
|
|
13
|
+
const unpluginRouterGeneratorFactory = (options = {}) => {
|
|
14
14
|
let ROOT = process.cwd();
|
|
15
15
|
let userConfig = options;
|
|
16
16
|
const generate = async () => {
|
|
@@ -59,9 +59,15 @@ const unpluginFactory = (options = {}) => {
|
|
|
59
59
|
userConfig = await config.getConfig(options, ROOT);
|
|
60
60
|
await run(generate);
|
|
61
61
|
}
|
|
62
|
+
},
|
|
63
|
+
async rspack(compiler) {
|
|
64
|
+
userConfig = await config.getConfig(options, ROOT);
|
|
65
|
+
await run(generate);
|
|
66
|
+
compiler.hooks.watchRun.tap(PLUGIN_NAME, async () => {
|
|
67
|
+
await run(generate);
|
|
68
|
+
});
|
|
62
69
|
}
|
|
63
70
|
};
|
|
64
71
|
};
|
|
65
|
-
|
|
66
|
-
exports.unpluginRouterGenerator = unpluginRouterGenerator;
|
|
72
|
+
exports.unpluginRouterGeneratorFactory = unpluginRouterGeneratorFactory;
|
|
67
73
|
//# 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 { UnpluginFactory } from 'unplugin'\nimport type { Config } from './config'\n\nlet lock = false\nconst checkLock = () => lock\nconst setLock = (bool: boolean) => {\n lock = bool\n}\n\nconst PLUGIN_NAME = 'unplugin:router-generator'\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 async rspack(compiler) {\n userConfig = await getConfig(options, ROOT)\n\n await run(generate)\n\n compiler.hooks.watchRun.tap(PLUGIN_NAME, async () => {\n await run(generate)\n })\n },\n }\n}\n"],"names":["generator","normalize","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K,UAAQ;AAC3B,eAAOA,SAAO;AACD,qBAAA,MAAMH,OAAAA,UAAU,SAAS,IAAI;AAE1C,cAAM,IAAI,QAAQ;AAAA,MACpB;AAAA,IACF;AAAA,IACA,MAAM,OAAO,UAAU;AACR,mBAAA,MAAMA,OAAAA,UAAU,SAAS,IAAI;AAE1C,YAAM,IAAI,QAAQ;AAElB,eAAS,MAAM,SAAS,IAAI,aAAa,YAAY;AACnD,cAAM,IAAI,QAAQ;AAAA,MAAA,CACnB;AAAA,IACH;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 { UnpluginFactory } from 'unplugin';
|
|
2
|
+
import { Config } from './config.cjs';
|
|
3
|
+
|
|
4
|
+
export declare const unpluginRouterGeneratorFactory: UnpluginFactory<Partial<Config> | undefined>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const unplugin = require("unplugin");
|
|
4
|
+
const codeSplitter = require("./code-splitter.cjs");
|
|
5
|
+
const config = require("./config.cjs");
|
|
6
|
+
const routerGenerator = require("./router-generator.cjs");
|
|
7
|
+
const composed = require("./composed.cjs");
|
|
8
|
+
const TanStackRouterGeneratorRspack = /* @__PURE__ */ unplugin.createRspackPlugin(
|
|
9
|
+
routerGenerator.unpluginRouterGeneratorFactory
|
|
10
|
+
);
|
|
11
|
+
const unstable_TanStackRouterCodeSplitterRspack = /* @__PURE__ */ unplugin.createRspackPlugin(codeSplitter.unpluginRouterCodeSplitterFactory);
|
|
12
|
+
const TanStackRouterRspack = /* @__PURE__ */ unplugin.createRspackPlugin(
|
|
13
|
+
composed.unpluginRouterComposedFactory
|
|
14
|
+
);
|
|
15
|
+
exports.configSchema = config.configSchema;
|
|
16
|
+
exports.TanStackRouterGeneratorRspack = TanStackRouterGeneratorRspack;
|
|
17
|
+
exports.TanStackRouterRspack = TanStackRouterRspack;
|
|
18
|
+
exports.default = TanStackRouterRspack;
|
|
19
|
+
exports.unstable_TanStackRouterCodeSplitterRspack = unstable_TanStackRouterCodeSplitterRspack;
|
|
20
|
+
//# sourceMappingURL=rspack.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rspack.cjs","sources":["../../src/rspack.ts"],"sourcesContent":["import { createRspackPlugin } from 'unplugin'\nimport { unpluginRouterCodeSplitterFactory } from './code-splitter'\nimport { configSchema } from './config'\nimport { unpluginRouterGeneratorFactory } from './router-generator'\nimport { unpluginRouterComposedFactory } from './composed'\nimport type { Config } from './config'\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * // ...\n * tools: {\n * rspack: {\n * plugins: [TanStackRouterGeneratorRspack()],\n * },\n * },\n * })\n * ```\n */\nconst TanStackRouterGeneratorRspack = /* #__PURE__ */ createRspackPlugin(\n unpluginRouterGeneratorFactory,\n)\n\n/**\n * @experimental Do not use this plugin yet\n *\n * Unplugin's Rspack integration doesn't support the `resolveId` and `transform` hooks.\n * The code-splitter won't work with Rspack and will probably break your dev and build.\n *\n * If you're familiar with Rspack and know how to overcome our `resolveId` and `transform`\n * limitations, please let us know.\n * We'd love to support it, but we're not sure how to do it yet 😅.\n *\n * @example\n * ```ts\n * export default defineConfig({\n * // ...\n * tools: {\n * rspack: {\n * plugins: [unstable_TanStackRouterCodeSplitterRspack()],\n * },\n * },\n * })\n * ```\n */\nconst unstable_TanStackRouterCodeSplitterRspack =\n /* #__PURE__ */ createRspackPlugin(unpluginRouterCodeSplitterFactory)\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * // ...\n * tools: {\n * rspack: {\n * plugins: [TanStackRouterRspack()],\n * },\n * },\n * })\n * ```\n */\nconst TanStackRouterRspack = /* #__PURE__ */ createRspackPlugin(\n unpluginRouterComposedFactory,\n)\n\nexport default TanStackRouterRspack\nexport {\n configSchema,\n TanStackRouterRspack,\n TanStackRouterGeneratorRspack,\n unstable_TanStackRouterCodeSplitterRspack,\n}\nexport type { Config }\n"],"names":["createRspackPlugin","unpluginRouterGeneratorFactory","unpluginRouterCodeSplitterFactory","unpluginRouterComposedFactory"],"mappings":";;;;;;;AAoBA,MAAM,gCAAgDA,yBAAA;AAAA,EACpDC,gBAAA;AACF;AAwBM,MAAA,wFAC+BC,8CAAiC;AAetE,MAAM,uBAAuCF,yBAAA;AAAA,EAC3CG,SAAA;AACF;;;;;;"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { configSchema, Config } from './config.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* export default defineConfig({
|
|
7
|
+
* // ...
|
|
8
|
+
* tools: {
|
|
9
|
+
* rspack: {
|
|
10
|
+
* plugins: [TanStackRouterGeneratorRspack()],
|
|
11
|
+
* },
|
|
12
|
+
* },
|
|
13
|
+
* })
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare const TanStackRouterGeneratorRspack: (options?: Partial<{
|
|
17
|
+
routeFileIgnorePrefix: string;
|
|
18
|
+
routesDirectory: string;
|
|
19
|
+
generatedRouteTree: string;
|
|
20
|
+
quoteStyle: "single" | "double";
|
|
21
|
+
semicolons: boolean;
|
|
22
|
+
disableTypes: boolean;
|
|
23
|
+
addExtensions: boolean;
|
|
24
|
+
disableLogging: boolean;
|
|
25
|
+
routeTreeFileHeader: string[];
|
|
26
|
+
routeTreeFileFooter: string[];
|
|
27
|
+
enableRouteGeneration?: boolean | undefined;
|
|
28
|
+
experimental?: {
|
|
29
|
+
enableCodeSplitting?: boolean | undefined;
|
|
30
|
+
} | undefined;
|
|
31
|
+
routeFilePrefix?: string | undefined;
|
|
32
|
+
routeFileIgnorePattern?: string | undefined;
|
|
33
|
+
}> | undefined) => _rspack_core_dist_config_zod.RspackPluginInstance;
|
|
34
|
+
/**
|
|
35
|
+
* @experimental Do not use this plugin yet
|
|
36
|
+
*
|
|
37
|
+
* Unplugin's Rspack integration doesn't support the `resolveId` and `transform` hooks.
|
|
38
|
+
* The code-splitter won't work with Rspack and will probably break your dev and build.
|
|
39
|
+
*
|
|
40
|
+
* If you're familiar with Rspack and know how to overcome our `resolveId` and `transform`
|
|
41
|
+
* limitations, please let us know.
|
|
42
|
+
* We'd love to support it, but we're not sure how to do it yet 😅.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* export default defineConfig({
|
|
47
|
+
* // ...
|
|
48
|
+
* tools: {
|
|
49
|
+
* rspack: {
|
|
50
|
+
* plugins: [unstable_TanStackRouterCodeSplitterRspack()],
|
|
51
|
+
* },
|
|
52
|
+
* },
|
|
53
|
+
* })
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
declare const unstable_TanStackRouterCodeSplitterRspack: (options?: Partial<{
|
|
57
|
+
routeFileIgnorePrefix: string;
|
|
58
|
+
routesDirectory: string;
|
|
59
|
+
generatedRouteTree: string;
|
|
60
|
+
quoteStyle: "single" | "double";
|
|
61
|
+
semicolons: boolean;
|
|
62
|
+
disableTypes: boolean;
|
|
63
|
+
addExtensions: boolean;
|
|
64
|
+
disableLogging: boolean;
|
|
65
|
+
routeTreeFileHeader: string[];
|
|
66
|
+
routeTreeFileFooter: string[];
|
|
67
|
+
enableRouteGeneration?: boolean | undefined;
|
|
68
|
+
experimental?: {
|
|
69
|
+
enableCodeSplitting?: boolean | undefined;
|
|
70
|
+
} | undefined;
|
|
71
|
+
routeFilePrefix?: string | undefined;
|
|
72
|
+
routeFileIgnorePattern?: string | undefined;
|
|
73
|
+
}> | undefined) => _rspack_core_dist_config_zod.RspackPluginInstance;
|
|
74
|
+
/**
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* export default defineConfig({
|
|
78
|
+
* // ...
|
|
79
|
+
* tools: {
|
|
80
|
+
* rspack: {
|
|
81
|
+
* plugins: [TanStackRouterRspack()],
|
|
82
|
+
* },
|
|
83
|
+
* },
|
|
84
|
+
* })
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
declare const TanStackRouterRspack: (options?: Partial<{
|
|
88
|
+
routeFileIgnorePrefix: string;
|
|
89
|
+
routesDirectory: string;
|
|
90
|
+
generatedRouteTree: string;
|
|
91
|
+
quoteStyle: "single" | "double";
|
|
92
|
+
semicolons: boolean;
|
|
93
|
+
disableTypes: boolean;
|
|
94
|
+
addExtensions: boolean;
|
|
95
|
+
disableLogging: boolean;
|
|
96
|
+
routeTreeFileHeader: string[];
|
|
97
|
+
routeTreeFileFooter: string[];
|
|
98
|
+
enableRouteGeneration?: boolean | undefined;
|
|
99
|
+
experimental?: {
|
|
100
|
+
enableCodeSplitting?: boolean | undefined;
|
|
101
|
+
} | undefined;
|
|
102
|
+
routeFilePrefix?: string | undefined;
|
|
103
|
+
routeFileIgnorePattern?: string | undefined;
|
|
104
|
+
}> | undefined) => _rspack_core_dist_config_zod.RspackPluginInstance;
|
|
105
|
+
export default TanStackRouterRspack;
|
|
106
|
+
export { configSchema, TanStackRouterRspack, TanStackRouterGeneratorRspack, unstable_TanStackRouterCodeSplitterRspack, };
|
|
107
|
+
export type { Config };
|
package/dist/cjs/vite.cjs
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
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
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
const composed = require("./composed.cjs");
|
|
8
|
+
const TanStackRouterGeneratorVite = unplugin.createVitePlugin(
|
|
9
|
+
routerGenerator.unpluginRouterGeneratorFactory
|
|
10
|
+
);
|
|
11
|
+
const TanStackRouterCodeSplitterVite = unplugin.createVitePlugin(
|
|
12
|
+
codeSplitter.unpluginRouterCodeSplitterFactory
|
|
13
|
+
);
|
|
14
|
+
const TanStackRouterVite = unplugin.createVitePlugin(composed.unpluginRouterComposedFactory);
|
|
14
15
|
exports.configSchema = config.configSchema;
|
|
15
16
|
exports.TanStackRouterCodeSplitterVite = TanStackRouterCodeSplitterVite;
|
|
16
17
|
exports.TanStackRouterGeneratorVite = TanStackRouterGeneratorVite;
|
|
17
18
|
exports.TanStackRouterVite = TanStackRouterVite;
|
|
19
|
+
exports.default = TanStackRouterVite;
|
|
18
20
|
//# 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'\nimport { unpluginRouterComposedFactory } from './composed'\n\nimport type { Config } from './config'\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [TanStackRouterGeneratorVite()],\n * // ...\n * })\n * ```\n */\nconst TanStackRouterGeneratorVite = createVitePlugin(\n unpluginRouterGeneratorFactory,\n)\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [TanStackRouterCodeSplitterVite()],\n * // ...\n * })\n * ```\n */\nconst TanStackRouterCodeSplitterVite = createVitePlugin(\n unpluginRouterCodeSplitterFactory,\n)\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [TanStackRouterVite()],\n * // ...\n * })\n * ```\n */\nconst TanStackRouterVite = createVitePlugin(unpluginRouterComposedFactory)\n\nexport default TanStackRouterVite\nexport {\n configSchema,\n TanStackRouterGeneratorVite,\n TanStackRouterCodeSplitterVite,\n TanStackRouterVite,\n}\nexport type { Config }\n"],"names":["createVitePlugin","unpluginRouterGeneratorFactory","unpluginRouterCodeSplitterFactory","unpluginRouterComposedFactory"],"mappings":";;;;;;;AAiBA,MAAM,8BAA8BA,SAAA;AAAA,EAClCC,gBAAA;AACF;AAWA,MAAM,iCAAiCD,SAAA;AAAA,EACrCE,aAAA;AACF;AAWM,MAAA,qBAAqBF,0BAAiBG,SAA6B,6BAAA;;;;;;"}
|
package/dist/cjs/vite.d.cts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { configSchema, Config } from './config.cjs';
|
|
2
|
-
import { VitePlugin } from 'unplugin';
|
|
3
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* export default defineConfig({
|
|
7
|
+
* plugins: [TanStackRouterGeneratorVite()],
|
|
8
|
+
* // ...
|
|
9
|
+
* })
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
4
12
|
declare const TanStackRouterGeneratorVite: (options?: Partial<{
|
|
5
13
|
routeFileIgnorePrefix: string;
|
|
6
14
|
routesDirectory: string;
|
|
@@ -18,7 +26,16 @@ declare const TanStackRouterGeneratorVite: (options?: Partial<{
|
|
|
18
26
|
} | undefined;
|
|
19
27
|
routeFilePrefix?: string | undefined;
|
|
20
28
|
routeFileIgnorePattern?: string | undefined;
|
|
21
|
-
}> | undefined) =>
|
|
29
|
+
}> | undefined) => import('vite').Plugin<any> | import('vite').Plugin<any>[];
|
|
30
|
+
/**
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* export default defineConfig({
|
|
34
|
+
* plugins: [TanStackRouterCodeSplitterVite()],
|
|
35
|
+
* // ...
|
|
36
|
+
* })
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
22
39
|
declare const TanStackRouterCodeSplitterVite: (options?: Partial<{
|
|
23
40
|
routeFileIgnorePrefix: string;
|
|
24
41
|
routesDirectory: string;
|
|
@@ -36,7 +53,34 @@ declare const TanStackRouterCodeSplitterVite: (options?: Partial<{
|
|
|
36
53
|
} | undefined;
|
|
37
54
|
routeFilePrefix?: string | undefined;
|
|
38
55
|
routeFileIgnorePattern?: string | undefined;
|
|
39
|
-
}> | undefined) =>
|
|
40
|
-
|
|
56
|
+
}> | undefined) => import('vite').Plugin<any> | import('vite').Plugin<any>[];
|
|
57
|
+
/**
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* export default defineConfig({
|
|
61
|
+
* plugins: [TanStackRouterVite()],
|
|
62
|
+
* // ...
|
|
63
|
+
* })
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare const TanStackRouterVite: (options?: Partial<{
|
|
67
|
+
routeFileIgnorePrefix: string;
|
|
68
|
+
routesDirectory: string;
|
|
69
|
+
generatedRouteTree: string;
|
|
70
|
+
quoteStyle: "single" | "double";
|
|
71
|
+
semicolons: boolean;
|
|
72
|
+
disableTypes: boolean;
|
|
73
|
+
addExtensions: boolean;
|
|
74
|
+
disableLogging: boolean;
|
|
75
|
+
routeTreeFileHeader: string[];
|
|
76
|
+
routeTreeFileFooter: string[];
|
|
77
|
+
enableRouteGeneration?: boolean | undefined;
|
|
78
|
+
experimental?: {
|
|
79
|
+
enableCodeSplitting?: boolean | undefined;
|
|
80
|
+
} | undefined;
|
|
81
|
+
routeFilePrefix?: string | undefined;
|
|
82
|
+
routeFileIgnorePattern?: string | undefined;
|
|
83
|
+
}> | undefined) => import('vite').Plugin<any> | import('vite').Plugin<any>[];
|
|
84
|
+
export default TanStackRouterVite;
|
|
41
85
|
export { configSchema, TanStackRouterGeneratorVite, TanStackRouterCodeSplitterVite, TanStackRouterVite, };
|
|
42
86
|
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
|
}
|
|
@@ -150,12 +153,13 @@ const unpluginFactory = (options = {}, { framework }) => {
|
|
|
150
153
|
ROOT = config.root;
|
|
151
154
|
userConfig = await getConfig(options, ROOT);
|
|
152
155
|
}
|
|
156
|
+
},
|
|
157
|
+
async rspack(compiler) {
|
|
158
|
+
userConfig = await getConfig(options, ROOT);
|
|
153
159
|
}
|
|
154
160
|
};
|
|
155
161
|
};
|
|
156
|
-
const unpluginRouterCodeSplitter = /* @__PURE__ */ createUnplugin(unpluginFactory);
|
|
157
162
|
export {
|
|
158
|
-
|
|
159
|
-
unpluginRouterCodeSplitter
|
|
163
|
+
unpluginRouterCodeSplitterFactory
|
|
160
164
|
};
|
|
161
165
|
//# 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\nconst PLUGIN_NAME = 'unplugin:router-code-splitter'\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\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\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\n vite: {\n async configResolved(config) {\n ROOT = config.root\n userConfig = await getConfig(options, ROOT)\n },\n },\n\n async rspack(compiler) {\n userConfig = await getConfig(options, ROOT)\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;AAIO,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,MAA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