@tanstack/router-plugin 1.115.3 → 1.116.1
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 +37 -38
- package/dist/cjs/core/router-generator-plugin.cjs.map +1 -1
- package/dist/esm/core/router-generator-plugin.js +37 -38
- package/dist/esm/core/router-generator-plugin.js.map +1 -1
- package/package.json +3 -3
- package/src/core/router-generator-plugin.ts +47 -39
|
@@ -84,55 +84,54 @@ const unpluginRouterGeneratorFactory = (options = {}) => {
|
|
|
84
84
|
await run(generate);
|
|
85
85
|
}
|
|
86
86
|
},
|
|
87
|
-
|
|
87
|
+
rspack(compiler) {
|
|
88
88
|
userConfig = config.getConfig(options, ROOT);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
let handle = null;
|
|
90
|
+
compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
|
|
91
|
+
await run(generate);
|
|
92
|
+
});
|
|
93
|
+
compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
|
|
94
|
+
if (handle) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
94
97
|
const routesDirectoryPath = getRoutesDirectoryPath();
|
|
95
98
|
const chokidar = await import("chokidar");
|
|
96
|
-
chokidar.watch(routesDirectoryPath, { ignoreInitial: true }).on("add", async () => {
|
|
99
|
+
handle = chokidar.watch(routesDirectoryPath, { ignoreInitial: true }).on("add", async () => {
|
|
97
100
|
await run(generate);
|
|
98
101
|
});
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
102
|
+
await run(generate);
|
|
103
|
+
});
|
|
104
|
+
compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {
|
|
105
|
+
if (handle) {
|
|
106
|
+
await handle.close();
|
|
107
|
+
}
|
|
108
|
+
});
|
|
107
109
|
},
|
|
108
|
-
|
|
110
|
+
webpack(compiler) {
|
|
109
111
|
userConfig = config.getConfig(options, ROOT);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
let handle = null;
|
|
113
|
+
compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
|
|
114
|
+
await run(generate);
|
|
115
|
+
});
|
|
116
|
+
compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
|
|
117
|
+
if (handle) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
115
120
|
const routesDirectoryPath = getRoutesDirectoryPath();
|
|
116
121
|
const chokidar = await import("chokidar");
|
|
117
|
-
chokidar.watch(routesDirectoryPath, { ignoreInitial: true }).on("add", async () => {
|
|
122
|
+
handle = chokidar.watch(routesDirectoryPath, { ignoreInitial: true }).on("add", async () => {
|
|
118
123
|
await run(generate);
|
|
119
124
|
});
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
console.info("✅ " + PLUGIN_NAME + ": route-tree generation done");
|
|
131
|
-
setTimeout(() => {
|
|
132
|
-
process.exit(0);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
}
|
|
125
|
+
await run(generate);
|
|
126
|
+
});
|
|
127
|
+
compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {
|
|
128
|
+
if (handle) {
|
|
129
|
+
await handle.close();
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
compiler.hooks.done.tap(PLUGIN_NAME, () => {
|
|
133
|
+
console.info("✅ " + PLUGIN_NAME + ": route-tree generation done");
|
|
134
|
+
});
|
|
136
135
|
}
|
|
137
136
|
};
|
|
138
137
|
};
|
|
@@ -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, resolveConfigPath } from '@tanstack/router-generator'\n\nimport { getConfig } from './config'\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 === resolveConfigPath({ configDirectory: ROOT })) {\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
|
|
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, resolveConfigPath } from '@tanstack/router-generator'\n\nimport { getConfig } from './config'\nimport type { FSWatcher } from 'chokidar'\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 === resolveConfigPath({ configDirectory: ROOT })) {\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 rspack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n let handle: FSWatcher | null = null\n\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {\n await run(generate)\n })\n\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (handle) {\n return\n }\n\n // rspack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n handle = chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', async () => {\n await run(generate)\n })\n\n await run(generate)\n })\n\n compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {\n if (handle) {\n await handle.close()\n }\n })\n },\n webpack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n let handle: FSWatcher | null = null\n\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {\n await run(generate)\n })\n\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (handle) {\n return\n }\n\n // webpack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n handle = chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', async () => {\n await run(generate)\n })\n\n await run(generate)\n })\n\n compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {\n if (handle) {\n await handle.close()\n }\n })\n\n compiler.hooks.done.tap(PLUGIN_NAME, () => {\n console.info('✅ ' + PLUGIN_NAME + ': route-tree generation done')\n })\n },\n }\n}\n"],"names":["isAbsolute","join","generator","normalize","resolveConfigPath","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;AA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63
|
+
rspack(compiler) {
|
|
64
64
|
userConfig = getConfig(options, ROOT);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
let handle = null;
|
|
66
|
+
compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
|
|
67
|
+
await run(generate);
|
|
68
|
+
});
|
|
69
|
+
compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
|
|
70
|
+
if (handle) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
70
73
|
const routesDirectoryPath = getRoutesDirectoryPath();
|
|
71
74
|
const chokidar = await import("chokidar");
|
|
72
|
-
chokidar.watch(routesDirectoryPath, { ignoreInitial: true }).on("add", async () => {
|
|
75
|
+
handle = chokidar.watch(routesDirectoryPath, { ignoreInitial: true }).on("add", async () => {
|
|
73
76
|
await run(generate);
|
|
74
77
|
});
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
78
|
+
await run(generate);
|
|
79
|
+
});
|
|
80
|
+
compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {
|
|
81
|
+
if (handle) {
|
|
82
|
+
await handle.close();
|
|
83
|
+
}
|
|
84
|
+
});
|
|
83
85
|
},
|
|
84
|
-
|
|
86
|
+
webpack(compiler) {
|
|
85
87
|
userConfig = getConfig(options, ROOT);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
let handle = null;
|
|
89
|
+
compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
|
|
90
|
+
await run(generate);
|
|
91
|
+
});
|
|
92
|
+
compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
|
|
93
|
+
if (handle) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
91
96
|
const routesDirectoryPath = getRoutesDirectoryPath();
|
|
92
97
|
const chokidar = await import("chokidar");
|
|
93
|
-
chokidar.watch(routesDirectoryPath, { ignoreInitial: true }).on("add", async () => {
|
|
98
|
+
handle = chokidar.watch(routesDirectoryPath, { ignoreInitial: true }).on("add", async () => {
|
|
94
99
|
await run(generate);
|
|
95
100
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
console.info("✅ " + PLUGIN_NAME + ": route-tree generation done");
|
|
107
|
-
setTimeout(() => {
|
|
108
|
-
process.exit(0);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
}
|
|
101
|
+
await run(generate);
|
|
102
|
+
});
|
|
103
|
+
compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {
|
|
104
|
+
if (handle) {
|
|
105
|
+
await handle.close();
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
compiler.hooks.done.tap(PLUGIN_NAME, () => {
|
|
109
|
+
console.info("✅ " + PLUGIN_NAME + ": route-tree generation done");
|
|
110
|
+
});
|
|
112
111
|
}
|
|
113
112
|
};
|
|
114
113
|
};
|
|
@@ -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, resolveConfigPath } from '@tanstack/router-generator'\n\nimport { getConfig } from './config'\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 === resolveConfigPath({ configDirectory: ROOT })) {\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
|
|
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, resolveConfigPath } from '@tanstack/router-generator'\n\nimport { getConfig } from './config'\nimport type { FSWatcher } from 'chokidar'\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 === resolveConfigPath({ configDirectory: ROOT })) {\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 rspack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n let handle: FSWatcher | null = null\n\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {\n await run(generate)\n })\n\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (handle) {\n return\n }\n\n // rspack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n handle = chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', async () => {\n await run(generate)\n })\n\n await run(generate)\n })\n\n compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {\n if (handle) {\n await handle.close()\n }\n })\n },\n webpack(compiler) {\n userConfig = getConfig(options, ROOT)\n\n let handle: FSWatcher | null = null\n\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {\n await run(generate)\n })\n\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (handle) {\n return\n }\n\n // webpack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n handle = chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', async () => {\n await run(generate)\n })\n\n await run(generate)\n })\n\n compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {\n if (handle) {\n await handle.close()\n }\n })\n\n compiler.hooks.done.tap(PLUGIN_NAME, () => {\n console.info('✅ ' + PLUGIN_NAME + ': route-tree generation done')\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,IAAI;AAER,QAAA;AACF,YAAM,UAAU,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,WAAW,UAAU,IAAI;AAE/B,QAAI,aAAa,kBAAkB,EAAE,iBAAiB,KAAM,CAAA,GAAG;AAChD,mBAAA,UAAU,SAAS,IAAI;AACpC;AAAA,IAAA;AAGF,QACE,UAAU,YACV,aAAa,QAAQ,WAAW,kBAAkB,GAClD;AAEA;AAAA,IAAA;AAGF,UAAM,sBAAsB,uBAAuB;AAC/C,QAAA,SAAS,WAAW,mBAAmB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M,SAAS,WAAW,aAAa,YAAY;AAC1D,YAAI,QAAQ;AACV;AAAA,QAAA;AAIF,cAAM,sBAAsB,uBAAuB;AAC7C,cAAA,WAAW,MAAM,OAAO,UAAU;AAC/B,iBAAA,SACN,MAAM,qBAAqB,EAAE,eAAe,MAAM,EAClD,GAAG,OAAO,YAAY;AACrB,gBAAM,IAAI,QAAQ;AAAA,QAAA,CACnB;AAEH,cAAM,IAAI,QAAQ;AAAA,MAAA,CACnB;AAED,eAAS,MAAM,WAAW,IAAI,aAAa,YAAY;AACrD,YAAI,QAAQ;AACV,gBAAM,OAAO,MAAM;AAAA,QAAA;AAAA,MACrB,CACD;AAED,eAAS,MAAM,KAAK,IAAI,aAAa,MAAM;AACjC,gBAAA,KAAK,OAAO,cAAc,8BAA8B;AAAA,MAAA,CACjE;AAAA,IAAA;AAAA,EAEL;AACF;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/router-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.116.1",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"unplugin": "^2.1.2",
|
|
102
102
|
"zod": "^3.24.2",
|
|
103
103
|
"@tanstack/router-core": "^1.115.3",
|
|
104
|
-
"@tanstack/router-generator": "^1.
|
|
104
|
+
"@tanstack/router-generator": "^1.116.0",
|
|
105
105
|
"@tanstack/router-utils": "^1.115.0",
|
|
106
106
|
"@tanstack/virtual-file-routes": "^1.115.0"
|
|
107
107
|
},
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
"vite": ">=5.0.0 || >=6.0.0",
|
|
111
111
|
"vite-plugin-solid": "^2.11.2",
|
|
112
112
|
"webpack": ">=5.92.0",
|
|
113
|
-
"@tanstack/react-router": "^1.
|
|
113
|
+
"@tanstack/react-router": "^1.116.0"
|
|
114
114
|
},
|
|
115
115
|
"peerDependenciesMeta": {
|
|
116
116
|
"@rsbuild/core": {
|
|
@@ -2,6 +2,7 @@ import { isAbsolute, join, normalize, resolve } from 'node:path'
|
|
|
2
2
|
import { generator, resolveConfigPath } from '@tanstack/router-generator'
|
|
3
3
|
|
|
4
4
|
import { getConfig } from './config'
|
|
5
|
+
import type { FSWatcher } from 'chokidar'
|
|
5
6
|
import type { UnpluginFactory } from 'unplugin'
|
|
6
7
|
import type { Config } from './config'
|
|
7
8
|
|
|
@@ -88,66 +89,73 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
|
|
|
88
89
|
await run(generate)
|
|
89
90
|
},
|
|
90
91
|
},
|
|
91
|
-
|
|
92
|
+
rspack(compiler) {
|
|
92
93
|
userConfig = getConfig(options, ROOT)
|
|
93
94
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
95
|
+
let handle: FSWatcher | null = null
|
|
96
|
+
|
|
97
|
+
compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
|
|
98
|
+
await run(generate)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
|
|
102
|
+
if (handle) {
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
|
|
99
106
|
// rspack watcher doesn't register newly created files
|
|
100
107
|
const routesDirectoryPath = getRoutesDirectoryPath()
|
|
101
108
|
const chokidar = await import('chokidar')
|
|
102
|
-
chokidar
|
|
109
|
+
handle = chokidar
|
|
103
110
|
.watch(routesDirectoryPath, { ignoreInitial: true })
|
|
104
111
|
.on('add', async () => {
|
|
105
112
|
await run(generate)
|
|
106
113
|
})
|
|
107
114
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
}
|
|
115
|
+
await run(generate)
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {
|
|
119
|
+
if (handle) {
|
|
120
|
+
await handle.close()
|
|
121
|
+
}
|
|
122
|
+
})
|
|
116
123
|
},
|
|
117
|
-
|
|
124
|
+
webpack(compiler) {
|
|
118
125
|
userConfig = getConfig(options, ROOT)
|
|
119
126
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
127
|
+
let handle: FSWatcher | null = null
|
|
128
|
+
|
|
129
|
+
compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
|
|
130
|
+
await run(generate)
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
|
|
134
|
+
if (handle) {
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
|
|
125
138
|
// webpack watcher doesn't register newly created files
|
|
126
139
|
const routesDirectoryPath = getRoutesDirectoryPath()
|
|
127
140
|
const chokidar = await import('chokidar')
|
|
128
|
-
chokidar
|
|
141
|
+
handle = chokidar
|
|
129
142
|
.watch(routesDirectoryPath, { ignoreInitial: true })
|
|
130
143
|
.on('add', async () => {
|
|
131
144
|
await run(generate)
|
|
132
145
|
})
|
|
133
146
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
setTimeout(() => {
|
|
147
|
-
process.exit(0)
|
|
148
|
-
})
|
|
149
|
-
})
|
|
150
|
-
}
|
|
147
|
+
await run(generate)
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {
|
|
151
|
+
if (handle) {
|
|
152
|
+
await handle.close()
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
compiler.hooks.done.tap(PLUGIN_NAME, () => {
|
|
157
|
+
console.info('✅ ' + PLUGIN_NAME + ': route-tree generation done')
|
|
158
|
+
})
|
|
151
159
|
},
|
|
152
160
|
}
|
|
153
161
|
}
|