@@ -11,14 +11,14 @@ import { generate, parse } from './babel.js';
1111import { PLUGIN_NAME , SERVER_ONLY_ROUTE_EXPORTS } from './constants.js' ;
1212import { createDevServerMiddleware } from './dev-server.js' ;
1313import {
14- generateWithProps ,
15- removeExports ,
16- transformRoute ,
17- findEntryFile
14+ generateWithProps ,
15+ removeExports ,
16+ transformRoute ,
17+ findEntryFile ,
1818} from './plugin-utils.js' ;
1919import {
20- configRoutesToRouteManifest ,
21- getReactRouterManifestForDev
20+ configRoutesToRouteManifest ,
21+ getReactRouterManifestForDev ,
2222} from './manifest.js' ;
2323import { generateServerBuild } from './server-utils.js' ;
2424import { createModifyBrowserManifestPlugin } from './modify-browser-manifest.js' ;
@@ -39,7 +39,6 @@ export type PluginOptions = {
3939 serverOutput ?: 'module' | 'commonjs' ;
4040} ;
4141
42-
4342export type Route = {
4443 id : string ;
4544 parentId ?: string ;
@@ -62,7 +61,7 @@ export type RouteManifestItem = Omit<Route, 'file' | 'children'> & {
6261} ;
6362
6463export const pluginReactRouter = (
65- options : PluginOptions = { } ,
64+ options : PluginOptions = { }
6665) : RsbuildPlugin => ( {
6766 name : PLUGIN_NAME ,
6867
@@ -90,27 +89,27 @@ export const pluginReactRouter = (
9089 const source = new RawSource (
9190 JSON . stringify ( {
9291 type : 'commonjs' ,
93- } ) ,
92+ } )
9493 ) ;
9594
9695 if ( compilation . getAsset ( packageJsonPath ) ) {
9796 compilation . updateAsset ( packageJsonPath , source ) ;
9897 } else {
9998 compilation . emitAsset ( packageJsonPath , source ) ;
10099 }
101- } ,
100+ }
102101 ) ;
103102 }
104103
105104 // Run typegen on build/dev
106105 api . onBeforeStartDevServer ( async ( ) => {
107106 const { $ } = await import ( 'execa' ) ;
108- $ `npx --yes react-router typegen --watch` ;
107+ $ `npx --yes react-router typegen --watch` ;
109108 } ) ;
110109
111110 api . onBeforeBuild ( async ( ) => {
112111 const { $ } = await import ( 'execa' ) ;
113- $ `npx --yes react-router typegen` ;
112+ $ `npx --yes react-router typegen` ;
114113 } ) ;
115114
116115 const jiti = createJiti ( process . cwd ( ) ) ;
@@ -127,7 +126,7 @@ export const pluginReactRouter = (
127126 } )
128127 . catch ( ( ) => {
129128 console . error (
130- 'No react-router.config.ts found, using default configuration.' ,
129+ 'No react-router.config.ts found, using default configuration.'
131130 ) ;
132131 return { } as Config ;
133132 } ) ;
@@ -139,25 +138,25 @@ export const pluginReactRouter = (
139138 . import < RouteConfigEntry [ ] > ( routesPath , {
140139 default : true ,
141140 } )
142- . catch ( ( error ) => {
141+ . catch ( error => {
143142 console . error ( 'Failed to load routes.ts:' , error ) ;
144143 console . error ( 'No routes.ts found in app directory.' ) ;
145144 return [ ] as RouteConfigEntry [ ] ;
146145 } ) ;
147146
148147 // Remove local JS_EXTENSIONS definition - use the imported one instead
149-
148+
150149 // Remove duplicate findEntryFile implementation
151150 const entryClientPath = findEntryFile (
152- resolve ( appDirectory , 'entry.client' ) ,
151+ resolve ( appDirectory , 'entry.client' )
153152 ) ;
154153 const entryServerPath = findEntryFile (
155- resolve ( appDirectory , 'entry.server' ) ,
154+ resolve ( appDirectory , 'entry.server' )
156155 ) ;
157156
158157 // Check for server app file
159158 const serverAppPath = findEntryFile (
160- resolve ( appDirectory , '../server/index' ) ,
159+ resolve ( appDirectory , '../server/index' )
161160 ) ;
162161 const hasServerApp = existsSync ( serverAppPath ) ;
163162
@@ -176,7 +175,7 @@ export const pluginReactRouter = (
176175
177176 const rootRouteFile = relative (
178177 appDirectory ,
179- resolve ( appDirectory , 'root.tsx' ) ,
178+ resolve ( appDirectory , 'root.tsx' )
180179 ) ;
181180
182181 const routes = {
@@ -241,13 +240,10 @@ export const pluginReactRouter = (
241240 ...Object . values ( routes ) . reduce (
242241 ( acc : Record < string , string > , route ) => {
243242 acc [ route . file . slice ( 0 , route . file . lastIndexOf ( '.' ) ) ] =
244- `${ resolve (
245- appDirectory ,
246- route . file ,
247- ) } ?react-router-route`;
243+ `${ resolve ( appDirectory , route . file ) } ?react-router-route` ;
248244 return acc ;
249245 } ,
250- { } as Record < string , string > ,
246+ { } as Record < string , string >
251247 ) ,
252248 } ,
253249 } ,
@@ -305,8 +301,14 @@ export const pluginReactRouter = (
305301 externalsType : pluginOptions . serverOutput ,
306302 output : {
307303 chunkFormat : pluginOptions . serverOutput ,
308- chunkLoading : pluginOptions . serverOutput === 'module' ? 'import' : 'require' ,
309- workerChunkLoading : pluginOptions . serverOutput === 'module' ? 'import' : 'require' ,
304+ chunkLoading :
305+ pluginOptions . serverOutput === 'module'
306+ ? 'import'
307+ : 'require' ,
308+ workerChunkLoading :
309+ pluginOptions . serverOutput === 'module'
310+ ? 'import'
311+ : 'require' ,
310312 wasmLoading : 'fetch' ,
311313 library : { type : pluginOptions . serverOutput } ,
312314 module : pluginOptions . serverOutput === 'module' ,
@@ -324,10 +326,14 @@ export const pluginReactRouter = (
324326 if ( name === 'web' ) {
325327 return mergeEnvironmentConfig ( config , {
326328 tools : {
327- rspack : ( rspackConfig ) => {
329+ rspack : rspackConfig => {
328330 if ( rspackConfig . plugins ) {
329331 rspackConfig . plugins . push (
330- createModifyBrowserManifestPlugin ( routes , pluginOptions , appDirectory )
332+ createModifyBrowserManifestPlugin (
333+ routes ,
334+ pluginOptions ,
335+ appDirectory
336+ )
331337 ) ;
332338 }
333339 return rspackConfig ;
@@ -336,29 +342,31 @@ export const pluginReactRouter = (
336342 } ) ;
337343 }
338344 return config ;
339- } ,
345+ }
340346 ) ;
341347
342348 api . processAssets (
343349 { stage : 'additional' , targets : [ 'node' ] } ,
344350 ( { sources, compilation } ) => {
345351 const packageJsonPath = 'package.json' ;
346- const source = new sources . RawSource ( `{"type": "${ pluginOptions . serverOutput } "}` ) ;
352+ const source = new sources . RawSource (
353+ `{"type": "${ pluginOptions . serverOutput } "}`
354+ ) ;
347355
348356 if ( compilation . getAsset ( packageJsonPath ) ) {
349357 compilation . updateAsset ( packageJsonPath , source ) ;
350358 } else {
351359 compilation . emitAsset ( packageJsonPath , source ) ;
352360 }
353- } ,
361+ }
354362 ) ;
355363
356364 // Add manifest transformations
357365 api . transform (
358366 {
359367 test : / v i r t u a l \/ r e a c t - r o u t e r \/ ( b r o w s e r | s e r v e r ) - m a n i f e s t / ,
360368 } ,
361- async ( args ) => {
369+ async args => {
362370 // For browser manifest, return a placeholder that will be modified by the plugin
363371 if ( args . environment . name === 'web' ) {
364372 return {
@@ -376,15 +384,15 @@ export const pluginReactRouter = (
376384 return {
377385 code : `export default ${ jsesc ( manifest , { es6 : true } ) } ;` ,
378386 } ;
379- } ,
387+ }
380388 ) ;
381389
382390 // Add route transformation
383391 api . transform (
384392 {
385393 resourceQuery : / \? r e a c t - r o u t e r - r o u t e / ,
386394 } ,
387- async ( args ) => {
395+ async args => {
388396 let code = (
389397 await esbuild . transform ( args . code , {
390398 jsx : 'automatic' ,
@@ -395,7 +403,7 @@ export const pluginReactRouter = (
395403 ) . code ;
396404
397405 const defaultExportMatch = code . match (
398- / \n \s { 0 , } ( [ \w \d _ ] + ) \s a s d e f a u l t , ? / ,
406+ / \n \s { 0 , } ( [ \w \d _ ] + ) \s a s d e f a u l t , ? /
399407 ) ;
400408 if (
401409 defaultExportMatch &&
@@ -419,7 +427,7 @@ export const pluginReactRouter = (
419427 filename : args . resource ,
420428 sourceFileName : args . resourcePath ,
421429 } ) ;
422- } ,
430+ }
423431 ) ;
424432 } ,
425433} ) ;
0 commit comments