@tanstack/router-plugin 1.58.4 → 1.58.12

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.
@@ -92,9 +92,16 @@ const unpluginRouterGeneratorFactory = (options = {}) => {
92
92
  } else {
93
93
  const routesDirectoryPath = getRoutesDirectoryPath();
94
94
  const chokidar = await import("chokidar");
95
- chokidar.watch(routesDirectoryPath).on("add", async () => {
95
+ chokidar.watch(routesDirectoryPath, { ignoreInitial: true }).on("add", async () => {
96
96
  await run(generate);
97
97
  });
98
+ let generated = false;
99
+ compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
100
+ if (!generated) {
101
+ generated = true;
102
+ return run(generate);
103
+ }
104
+ });
98
105
  }
99
106
  },
100
107
  async webpack(compiler) {
@@ -104,9 +111,16 @@ const unpluginRouterGeneratorFactory = (options = {}) => {
104
111
  } else {
105
112
  const routesDirectoryPath = getRoutesDirectoryPath();
106
113
  const chokidar = await import("chokidar");
107
- chokidar.watch(routesDirectoryPath).on("add", async () => {
114
+ chokidar.watch(routesDirectoryPath, { ignoreInitial: true }).on("add", async () => {
108
115
  await run(generate);
109
116
  });
117
+ let generated = false;
118
+ compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
119
+ if (!generated) {
120
+ generated = true;
121
+ return run(generate);
122
+ }
123
+ });
110
124
  }
111
125
  if (compiler.options.mode === "production") {
112
126
  compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {
@@ -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)\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 // rspack watcher doesn't register newly created files\n if (compiler.options.mode === 'production') {\n await run(generate)\n } else {\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar.watch(routesDirectoryPath).on('add', async () => {\n await run(generate)\n })\n }\n },\n async webpack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n // webpack watcher doesn't register newly created files\n if (compiler.options.mode === 'production') {\n await run(generate)\n } else {\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar.watch(routesDirectoryPath).on('add', async () => {\n await run(generate)\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;AAC3B,MAAI,aAAa;AAEjB,QAAM,yBAAyB,MAAM;AAC5B,WAAAA,qBAAW,WAAW,eAAe,IACxC,WAAW,kBACXC,UAAAA,KAAK,MAAM,WAAW,eAAe;AAAA,EAAA;AAG3C,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf;AAAA,IACF;AAEA,YAAQ,IAAI;AAER,QAAA;AACF,YAAMC,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,aAAaF,UAAAA,KAAK,MAAMG,UAAgB,gBAAA,GAAG;AAChC,mBAAAC,OAAA,UAAU,SAAS,IAAI;AACpC;AAAA,IACF;AAEA,QACE,UAAU,YACV,aAAaC,UAAAA,QAAQ,WAAW,kBAAkB,GAClD;AAEA;AAAA,IACF;AAEA,UAAM,sBAAsB;AACxB,QAAA,SAAS,WAAW,mBAAmB,GAAG;AAC5C,YAAM,SAAS;AAAA,IACjB;AAAA,EAAA;AAGI,QAAA,MAA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A,CACF;AAAA,MACH;AAAA,IACF;AAAA,EAAA;AAEJ;;"}
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)\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;AAC3B,MAAI,aAAa;AAEjB,QAAM,yBAAyB,MAAM;AAC5B,WAAAA,qBAAW,WAAW,eAAe,IACxC,WAAW,kBACXC,UAAAA,KAAK,MAAM,WAAW,eAAe;AAAA,EAAA;AAG3C,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf;AAAA,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AAO,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,UACrB;AAAA,QAAA,CACD;AAAA,MACH;AAAA,IACF;AAAA,IACA,MAAM,QAAQ,UAAU;AACT,mBAAAA,OAAA,UAAU,SAAS,IAAI;AAEhC,UAAA,SAAS,QAAQ,SAAS,cAAc;AAC1C,cAAM,IAAI,QAAQ;AAAA,MAAA,OACb;AAEL,cAAM,sBAAsB;AACtB,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,UACrB;AAAA,QAAA,CACD;AAAA,MACH;AAEI,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,MACH;AAAA,IACF;AAAA,EAAA;AAEJ;;"}
@@ -68,9 +68,16 @@ const unpluginRouterGeneratorFactory = (options = {}) => {
68
68
  } else {
69
69
  const routesDirectoryPath = getRoutesDirectoryPath();
70
70
  const chokidar = await import("chokidar");
71
- chokidar.watch(routesDirectoryPath).on("add", async () => {
71
+ chokidar.watch(routesDirectoryPath, { ignoreInitial: true }).on("add", async () => {
72
72
  await run(generate);
73
73
  });
74
+ let generated = false;
75
+ compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
76
+ if (!generated) {
77
+ generated = true;
78
+ return run(generate);
79
+ }
80
+ });
74
81
  }
75
82
  },
76
83
  async webpack(compiler) {
@@ -80,9 +87,16 @@ const unpluginRouterGeneratorFactory = (options = {}) => {
80
87
  } else {
81
88
  const routesDirectoryPath = getRoutesDirectoryPath();
82
89
  const chokidar = await import("chokidar");
83
- chokidar.watch(routesDirectoryPath).on("add", async () => {
90
+ chokidar.watch(routesDirectoryPath, { ignoreInitial: true }).on("add", async () => {
84
91
  await run(generate);
85
92
  });
93
+ let generated = false;
94
+ compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
95
+ if (!generated) {
96
+ generated = true;
97
+ return run(generate);
98
+ }
99
+ });
86
100
  }
87
101
  if (compiler.options.mode === "production") {
88
102
  compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {
@@ -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)\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 // rspack watcher doesn't register newly created files\n if (compiler.options.mode === 'production') {\n await run(generate)\n } else {\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar.watch(routesDirectoryPath).on('add', async () => {\n await run(generate)\n })\n }\n },\n async webpack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n // webpack watcher doesn't register newly created files\n if (compiler.options.mode === 'production') {\n await run(generate)\n } else {\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar.watch(routesDirectoryPath).on('add', async () => {\n await run(generate)\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,Q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;AAAA,MAAA,OACb;AACL,cAAM,sBAAsB;AACtB,cAAA,WAAW,MAAM,OAAO,UAAU;AACxC,iBAAS,MAAM,mBAAmB,EAAE,GAAG,OAAO,YAAY;AACxD,gBAAM,IAAI,QAAQ;AAAA,QAAA,CACnB;AAAA,MACH;AAAA,IACF;AAAA,IACA,MAAM,QAAQ,UAAU;AACT,mBAAA,UAAU,SAAS,IAAI;AAGhC,UAAA,SAAS,QAAQ,SAAS,cAAc;AAC1C,cAAM,IAAI,QAAQ;AAAA,MAAA,OACb;AACL,cAAM,sBAAsB;AACtB,cAAA,WAAW,MAAM,OAAO,UAAU;AACxC,iBAAS,MAAM,mBAAmB,EAAE,GAAG,OAAO,YAAY;AACxD,gBAAM,IAAI,QAAQ;AAAA,QAAA,CACnB;AAAA,MACH;AAEI,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,MACH;AAAA,IACF;AAAA,EAAA;AAEJ;"}
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)\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;AAC3B,MAAI,aAAa;AAEjB,QAAM,yBAAyB,MAAM;AAC5B,WAAA,WAAW,WAAW,eAAe,IACxC,WAAW,kBACX,KAAK,MAAM,WAAW,eAAe;AAAA,EAAA;AAG3C,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,UAAU,SAAS,IAAI;AACpC;AAAA,IACF;AAEA,QACE,UAAU,YACV,aAAa,QAAQ,WAAW,kBAAkB,GAClD;AAEA;AAAA,IACF;AAEA,UAAM,sBAAsB;AACxB,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;AAA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A,CACD;AAAA,MACH;AAEI,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,MACH;AAAA,IACF;AAAA,EAAA;AAEJ;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/router-plugin",
3
- "version": "1.58.4",
3
+ "version": "1.58.12",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -92,8 +92,8 @@
92
92
  "chokidar": "^3.6.0",
93
93
  "unplugin": "^1.12.2",
94
94
  "zod": "^3.23.8",
95
- "@tanstack/virtual-file-routes": "^1.56.0",
96
- "@tanstack/router-generator": "^1.58.1"
95
+ "@tanstack/router-generator": "^1.58.12",
96
+ "@tanstack/virtual-file-routes": "^1.56.0"
97
97
  },
98
98
  "peerDependencies": {
99
99
  "@rsbuild/core": ">=1.0.2",
@@ -92,28 +92,48 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
92
92
  async rspack(compiler) {
93
93
  userConfig = getConfig(options, ROOT)
94
94
 
95
- // rspack watcher doesn't register newly created files
96
95
  if (compiler.options.mode === 'production') {
97
96
  await run(generate)
98
97
  } else {
98
+ // rspack watcher doesn't register newly created files
99
99
  const routesDirectoryPath = getRoutesDirectoryPath()
100
100
  const chokidar = await import('chokidar')
101
- chokidar.watch(routesDirectoryPath).on('add', async () => {
102
- await run(generate)
101
+ chokidar
102
+ .watch(routesDirectoryPath, { ignoreInitial: true })
103
+ .on('add', async () => {
104
+ await run(generate)
105
+ })
106
+
107
+ let generated = false
108
+ compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
109
+ if (!generated) {
110
+ generated = true
111
+ return run(generate)
112
+ }
103
113
  })
104
114
  }
105
115
  },
106
116
  async webpack(compiler) {
107
117
  userConfig = getConfig(options, ROOT)
108
118
 
109
- // webpack watcher doesn't register newly created files
110
119
  if (compiler.options.mode === 'production') {
111
120
  await run(generate)
112
121
  } else {
122
+ // webpack watcher doesn't register newly created files
113
123
  const routesDirectoryPath = getRoutesDirectoryPath()
114
124
  const chokidar = await import('chokidar')
115
- chokidar.watch(routesDirectoryPath).on('add', async () => {
116
- await run(generate)
125
+ chokidar
126
+ .watch(routesDirectoryPath, { ignoreInitial: true })
127
+ .on('add', async () => {
128
+ await run(generate)
129
+ })
130
+
131
+ let generated = false
132
+ compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
133
+ if (!generated) {
134
+ generated = true
135
+ return run(generate)
136
+ }
117
137
  })
118
138
  }
119
139