@tanstack/router-plugin 1.86.0 → 1.87.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/core/router-generator-plugin.cjs +6 -2
- package/dist/cjs/core/router-generator-plugin.cjs.map +1 -1
- package/dist/esm/core/router-generator-plugin.js +6 -2
- package/dist/esm/core/router-generator-plugin.js.map +1 -1
- package/package.json +6 -6
- package/src/core/router-generator-plugin.ts +6 -2
|
@@ -88,7 +88,9 @@ const unpluginRouterGeneratorFactory = (options = {}) => {
|
|
|
88
88
|
async rspack(compiler) {
|
|
89
89
|
userConfig = config.getConfig(options, ROOT);
|
|
90
90
|
if (compiler.options.mode === "production") {
|
|
91
|
-
|
|
91
|
+
compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
|
|
92
|
+
await run(generate);
|
|
93
|
+
});
|
|
92
94
|
} else {
|
|
93
95
|
const routesDirectoryPath = getRoutesDirectoryPath();
|
|
94
96
|
const chokidar = await import("chokidar");
|
|
@@ -107,7 +109,9 @@ const unpluginRouterGeneratorFactory = (options = {}) => {
|
|
|
107
109
|
async webpack(compiler) {
|
|
108
110
|
userConfig = config.getConfig(options, ROOT);
|
|
109
111
|
if (compiler.options.mode === "production") {
|
|
110
|
-
|
|
112
|
+
compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
|
|
113
|
+
await run(generate);
|
|
114
|
+
});
|
|
111
115
|
} else {
|
|
112
116
|
const routesDirectoryPath = getRoutesDirectoryPath();
|
|
113
117
|
const chokidar = await import("chokidar");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-generator-plugin.cjs","sources":["../../../src/core/router-generator-plugin.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 getRoutesDirectoryPath = () => {\n return isAbsolute(userConfig.routesDirectory)\n ? userConfig.routesDirectory\n : join(ROOT, userConfig.routesDirectory)\n }\n\n const generate = async () => {\n if (checkLock()) {\n return\n }\n\n setLock(true)\n\n try {\n await generator(userConfig, process.cwd())\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 = 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 = getRoutesDirectoryPath()\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 = getConfig(options, ROOT)\n\n await run(generate)\n },\n },\n async rspack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n if (compiler.options.mode === 'production') {\n await run(generate)\n } else {\n // rspack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', async () => {\n await run(generate)\n })\n\n let generated = false\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (!generated) {\n generated = true\n return run(generate)\n }\n })\n }\n },\n async webpack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n if (compiler.options.mode === 'production') {\n await run(generate)\n } else {\n // webpack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', async () => {\n await run(generate)\n })\n\n let generated = false\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (!generated) {\n generated = true\n return run(generate)\n }\n })\n }\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {\n console.info('✅ ' + PLUGIN_NAME + ': route-tree generation done')\n setTimeout(() => {\n process.exit(0)\n })\n })\n }\n },\n }\n}\n"],"names":["isAbsolute","join","generator","normalize","CONFIG_FILE_NAME","getConfig","resolve","config"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,IAAI,OAAO;AACX,MAAM,YAAY,MAAM;AACxB,MAAM,UAAU,CAAC,SAAkB;AAC1B,SAAA;AACT;AAEA,MAAM,cAAc;AAEb,MAAM,iCAET,CAAC,UAAU,OAAO;AAChB,MAAA,OAAe,QAAQ,IAAI;AAC/B,MAAI,aAAa;AAEjB,QAAM,yBAAyB,MAAM;AAC5B,WAAAA,UAAA,WAAW,WAAW,eAAe,IACxC,WAAW,kBACXC,eAAK,MAAM,WAAW,eAAe;AAAA,EAC3C;AAEA,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf;AAAA,IAAA;AAGF,YAAQ,IAAI;AAER,QAAA;AACF,YAAMC,0BAAU,YAAY,QAAQ,IAAA,CAAK;AAAA,aAClC,KAAK;AACZ,cAAQ,MAAM,GAAG;AACjB,cAAQ,KAAK;AAAA,IAAA,UACb;AACA,cAAQ,KAAK;AAAA,IAAA;AAAA,EAEjB;AAEM,QAAA,aAAa,OACjB,MACA,UACG;AACG,UAAA,WAAWC,oBAAU,IAAI;AAE/B,QAAI,aAAaF,UAAAA,KAAK,MAAMG,UAAgB,gBAAA,GAAG;AAChC,mBAAAC,OAAAA,UAAU,SAAS,IAAI;AACpC;AAAA,IAAA;AAGF,QACE,UAAU,YACV,aAAaC,UAAAA,QAAQ,WAAW,kBAAkB,GAClD;AAEA;AAAA,IAAA;AAGF,UAAM,sBAAsB,uBAAuB;AAC/C,QAAA,SAAS,WAAW,mBAAmB,GAAG;AAC5C,YAAM,SAAS;AAAA,IAAA;AAAA,EAEnB;AAEM,QAAA,MAAyD,OAAO,OAAO;AACvE,QAAA,WAAW,yBAAyB,MAAM;AAC5C,YAAM,GAAG;AAAA,IAAA;AAAA,EAEb;AAEO,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,eAAeC,UAAQ;AAC3B,eAAOA,SAAO;AACD,qBAAAF,OAAAA,UAAU,SAAS,IAAI;AAEpC,cAAM,IAAI,QAAQ;AAAA,MAAA;AAAA,IAEtB;AAAA,IACA,MAAM,OAAO,UAAU;AACR,mBAAAA,OAAAA,UAAU,SAAS,IAAI;AAEhC,UAAA,SAAS,QAAQ,SAAS,cAAc;AAC1C,
|
|
1
|
+
{"version":3,"file":"router-generator-plugin.cjs","sources":["../../../src/core/router-generator-plugin.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 getRoutesDirectoryPath = () => {\n return isAbsolute(userConfig.routesDirectory)\n ? userConfig.routesDirectory\n : join(ROOT, userConfig.routesDirectory)\n }\n\n const generate = async () => {\n if (checkLock()) {\n return\n }\n\n setLock(true)\n\n try {\n await generator(userConfig, process.cwd())\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 = 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 = getRoutesDirectoryPath()\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 = getConfig(options, ROOT)\n\n await run(generate)\n },\n },\n async rspack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {\n await run(generate)\n })\n } else {\n // rspack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', async () => {\n await run(generate)\n })\n\n let generated = false\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (!generated) {\n generated = true\n return run(generate)\n }\n })\n }\n },\n async webpack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {\n await run(generate)\n })\n } else {\n // webpack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', async () => {\n await run(generate)\n })\n\n let generated = false\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (!generated) {\n generated = true\n return run(generate)\n }\n })\n }\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {\n console.info('✅ ' + PLUGIN_NAME + ': route-tree generation done')\n setTimeout(() => {\n process.exit(0)\n })\n })\n }\n },\n }\n}\n"],"names":["isAbsolute","join","generator","normalize","CONFIG_FILE_NAME","getConfig","resolve","config"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,IAAI,OAAO;AACX,MAAM,YAAY,MAAM;AACxB,MAAM,UAAU,CAAC,SAAkB;AAC1B,SAAA;AACT;AAEA,MAAM,cAAc;AAEb,MAAM,iCAET,CAAC,UAAU,OAAO;AAChB,MAAA,OAAe,QAAQ,IAAI;AAC/B,MAAI,aAAa;AAEjB,QAAM,yBAAyB,MAAM;AAC5B,WAAAA,UAAA,WAAW,WAAW,eAAe,IACxC,WAAW,kBACXC,eAAK,MAAM,WAAW,eAAe;AAAA,EAC3C;AAEA,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf;AAAA,IAAA;AAGF,YAAQ,IAAI;AAER,QAAA;AACF,YAAMC,0BAAU,YAAY,QAAQ,IAAA,CAAK;AAAA,aAClC,KAAK;AACZ,cAAQ,MAAM,GAAG;AACjB,cAAQ,KAAK;AAAA,IAAA,UACb;AACA,cAAQ,KAAK;AAAA,IAAA;AAAA,EAEjB;AAEM,QAAA,aAAa,OACjB,MACA,UACG;AACG,UAAA,WAAWC,oBAAU,IAAI;AAE/B,QAAI,aAAaF,UAAAA,KAAK,MAAMG,UAAgB,g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;AAAA,MAAA;AAAA,IAEL;AAAA,IACA,MAAM,QAAQ,UAAU;AACT,mBAAAA,OAAAA,UAAU,SAAS,IAAI;AAEhC,UAAA,SAAS,QAAQ,SAAS,cAAc;AAC1C,iBAAS,MAAM,UAAU,WAAW,aAAa,YAAY;AAC3D,gBAAM,IAAI,QAAQ;AAAA,QAAA,CACnB;AAAA,MAAA,OACI;AAEL,cAAM,sBAAsB,uBAAuB;AAC7C,cAAA,WAAW,MAAM,OAAO,UAAU;AAErC,iBAAA,MAAM,qBAAqB,EAAE,eAAe,MAAM,EAClD,GAAG,OAAO,YAAY;AACrB,gBAAM,IAAI,QAAQ;AAAA,QAAA,CACnB;AAEH,YAAI,YAAY;AAChB,iBAAS,MAAM,SAAS,WAAW,aAAa,YAAY;AAC1D,cAAI,CAAC,WAAW;AACF,wBAAA;AACZ,mBAAO,IAAI,QAAQ;AAAA,UAAA;AAAA,QACrB,CACD;AAAA,MAAA;AAGC,UAAA,SAAS,QAAQ,SAAS,cAAc;AAC1C,iBAAS,MAAM,KAAK,IAAI,aAAa,CAAC,UAAU;AACtC,kBAAA,KAAK,OAAO,cAAc,8BAA8B;AAChE,qBAAW,MAAM;AACf,oBAAQ,KAAK,CAAC;AAAA,UAAA,CACf;AAAA,QAAA,CACF;AAAA,MAAA;AAAA,IACH;AAAA,EAEJ;AACF;;"}
|
|
@@ -64,7 +64,9 @@ const unpluginRouterGeneratorFactory = (options = {}) => {
|
|
|
64
64
|
async rspack(compiler) {
|
|
65
65
|
userConfig = getConfig(options, ROOT);
|
|
66
66
|
if (compiler.options.mode === "production") {
|
|
67
|
-
|
|
67
|
+
compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
|
|
68
|
+
await run(generate);
|
|
69
|
+
});
|
|
68
70
|
} else {
|
|
69
71
|
const routesDirectoryPath = getRoutesDirectoryPath();
|
|
70
72
|
const chokidar = await import("chokidar");
|
|
@@ -83,7 +85,9 @@ const unpluginRouterGeneratorFactory = (options = {}) => {
|
|
|
83
85
|
async webpack(compiler) {
|
|
84
86
|
userConfig = getConfig(options, ROOT);
|
|
85
87
|
if (compiler.options.mode === "production") {
|
|
86
|
-
|
|
88
|
+
compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
|
|
89
|
+
await run(generate);
|
|
90
|
+
});
|
|
87
91
|
} else {
|
|
88
92
|
const routesDirectoryPath = getRoutesDirectoryPath();
|
|
89
93
|
const chokidar = await import("chokidar");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-generator-plugin.js","sources":["../../../src/core/router-generator-plugin.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 getRoutesDirectoryPath = () => {\n return isAbsolute(userConfig.routesDirectory)\n ? userConfig.routesDirectory\n : join(ROOT, userConfig.routesDirectory)\n }\n\n const generate = async () => {\n if (checkLock()) {\n return\n }\n\n setLock(true)\n\n try {\n await generator(userConfig, process.cwd())\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 = 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 = getRoutesDirectoryPath()\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 = getConfig(options, ROOT)\n\n await run(generate)\n },\n },\n async rspack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n if (compiler.options.mode === 'production') {\n await run(generate)\n } else {\n // rspack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', async () => {\n await run(generate)\n })\n\n let generated = false\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (!generated) {\n generated = true\n return run(generate)\n }\n })\n }\n },\n async webpack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n if (compiler.options.mode === 'production') {\n await run(generate)\n } else {\n // webpack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', async () => {\n await run(generate)\n })\n\n let generated = false\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (!generated) {\n generated = true\n return run(generate)\n }\n })\n }\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {\n console.info('✅ ' + PLUGIN_NAME + ': route-tree generation done')\n setTimeout(() => {\n process.exit(0)\n })\n })\n }\n },\n }\n}\n"],"names":[],"mappings":";;;;AAQA,IAAI,OAAO;AACX,MAAM,YAAY,MAAM;AACxB,MAAM,UAAU,CAAC,SAAkB;AAC1B,SAAA;AACT;AAEA,MAAM,cAAc;AAEb,MAAM,iCAET,CAAC,UAAU,OAAO;AAChB,MAAA,OAAe,QAAQ,IAAI;AAC/B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c;AAC1C,
|
|
1
|
+
{"version":3,"file":"router-generator-plugin.js","sources":["../../../src/core/router-generator-plugin.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 getRoutesDirectoryPath = () => {\n return isAbsolute(userConfig.routesDirectory)\n ? userConfig.routesDirectory\n : join(ROOT, userConfig.routesDirectory)\n }\n\n const generate = async () => {\n if (checkLock()) {\n return\n }\n\n setLock(true)\n\n try {\n await generator(userConfig, process.cwd())\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 = 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 = getRoutesDirectoryPath()\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 = getConfig(options, ROOT)\n\n await run(generate)\n },\n },\n async rspack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {\n await run(generate)\n })\n } else {\n // rspack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', async () => {\n await run(generate)\n })\n\n let generated = false\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (!generated) {\n generated = true\n return run(generate)\n }\n })\n }\n },\n async webpack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {\n await run(generate)\n })\n } else {\n // webpack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', async () => {\n await run(generate)\n })\n\n let generated = false\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (!generated) {\n generated = true\n return run(generate)\n }\n })\n }\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {\n console.info('✅ ' + PLUGIN_NAME + ': route-tree generation done')\n setTimeout(() => {\n process.exit(0)\n })\n })\n }\n },\n }\n}\n"],"names":[],"mappings":";;;;AAQA,IAAI,OAAO;AACX,MAAM,YAAY,MAAM;AACxB,MAAM,UAAU,CAAC,SAAkB;AAC1B,SAAA;AACT;AAEA,MAAM,cAAc;AAEb,MAAM,iCAET,CAAC,UAAU,OAAO;AAChB,MAAA,OAAe,QAAQ,IAAI;AAC/B,MAAI,aAAa;AAEjB,QAAM,yBAAyB,MAAM;AAC5B,WAAA,WAAW,WAAW,eAAe,IACxC,WAAW,kBACX,KAAK,MAAM,WAAW,eAAe;AAAA,EAC3C;AAEA,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf;AAAA,IAAA;AAGF,YAAQ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ing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -87,13 +87,13 @@
|
|
|
87
87
|
},
|
|
88
88
|
"dependencies": {
|
|
89
89
|
"@babel/core": "^7.26.0",
|
|
90
|
-
"@babel/generator": "^7.26.
|
|
91
|
-
"@babel/parser": "^7.26.
|
|
90
|
+
"@babel/generator": "^7.26.3",
|
|
91
|
+
"@babel/parser": "^7.26.3",
|
|
92
92
|
"@babel/plugin-syntax-jsx": "^7.25.9",
|
|
93
93
|
"@babel/plugin-syntax-typescript": "^7.25.9",
|
|
94
94
|
"@babel/template": "^7.25.9",
|
|
95
|
-
"@babel/traverse": "^7.
|
|
96
|
-
"@babel/types": "^7.26.
|
|
95
|
+
"@babel/traverse": "^7.26.4",
|
|
96
|
+
"@babel/types": "^7.26.3",
|
|
97
97
|
"@types/babel__core": "^7.20.5",
|
|
98
98
|
"@types/babel__generator": "^7.6.8",
|
|
99
99
|
"@types/babel__template": "^7.4.4",
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"chokidar": "^3.6.0",
|
|
103
103
|
"unplugin": "^1.16.0",
|
|
104
104
|
"zod": "^3.23.8",
|
|
105
|
-
"@tanstack/router-generator": "^1.
|
|
105
|
+
"@tanstack/router-generator": "^1.87.3",
|
|
106
106
|
"@tanstack/virtual-file-routes": "^1.81.9"
|
|
107
107
|
},
|
|
108
108
|
"peerDependencies": {
|
|
@@ -93,7 +93,9 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
|
|
|
93
93
|
userConfig = getConfig(options, ROOT)
|
|
94
94
|
|
|
95
95
|
if (compiler.options.mode === 'production') {
|
|
96
|
-
|
|
96
|
+
compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
|
|
97
|
+
await run(generate)
|
|
98
|
+
})
|
|
97
99
|
} else {
|
|
98
100
|
// rspack watcher doesn't register newly created files
|
|
99
101
|
const routesDirectoryPath = getRoutesDirectoryPath()
|
|
@@ -117,7 +119,9 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
|
|
|
117
119
|
userConfig = getConfig(options, ROOT)
|
|
118
120
|
|
|
119
121
|
if (compiler.options.mode === 'production') {
|
|
120
|
-
|
|
122
|
+
compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
|
|
123
|
+
await run(generate)
|
|
124
|
+
})
|
|
121
125
|
} else {
|
|
122
126
|
// webpack watcher doesn't register newly created files
|
|
123
127
|
const routesDirectoryPath = getRoutesDirectoryPath()
|