@@ -16,8 +16,9 @@ function getWorkshopAppServerBuildPath() {
1616}
1717
1818export function patchServerBuild ( contents ) {
19+ let patchedContents = contents
1920 const routeModuleName = contents . match (
20- / " r o u t e s \/ \$ " : \s * \{ [ \s \S ] * ?m o d u l e : \s * ( r o u t e \d + ) / ,
21+ / c o n s t r o u t e s = \{ [ \s \S ] * ? " r o u t e s \/ \$ " : \s * \{ [ \s \S ] * ?m o d u l e : \s * ( r o u t e \d + ) / ,
2122 ) ?. [ 1 ]
2223
2324 if ( ! routeModuleName ) {
@@ -46,22 +47,28 @@ export function patchServerBuild(contents) {
4647 if ( ! / \n \s + a c t i o n : / . test ( routeModuleBody ) ) {
4748 const patchedRouteModuleBody = routeModuleBody . replace (
4849 / \n ( \s + ) l o a d e r : \s * ( [ A - Z a - z _ $ ] [ \w $ ] * ) / ,
49- `\n$1action: ${ loaderName } ,\n$1loader: $2` ,
50+ ( _match , indent , loader ) =>
51+ `\n${ indent } action: ${ loaderName } ,\n${ indent } loader: ${ loader } ` ,
5052 )
51- contents = contents . replace ( routeModuleBody , patchedRouteModuleBody )
53+ const routeModuleBodyStart =
54+ routeModuleMatch . index + routeModuleMatch [ 0 ] . indexOf ( routeModuleBody )
55+ patchedContents =
56+ patchedContents . slice ( 0 , routeModuleBodyStart ) +
57+ patchedRouteModuleBody +
58+ patchedContents . slice ( routeModuleBodyStart + routeModuleBody . length )
5259 patchedRouteAction = true
5360 }
5461
5562 let patchedManifest = false
56- contents = contents . replace (
63+ patchedContents = patchedContents . replace (
5764 / " r o u t e s \/ \$ " : \{ ( [ \s \S ] { 0 , 600 } ?) " h a s A c t i o n " : f a l s e / g,
5865 ( match , routeManifestPrefix ) => {
5966 patchedManifest = true
6067 return `"routes/$": {${ routeManifestPrefix } "hasAction": true`
6168 } ,
6269 )
6370
64- return { contents, patchedRouteAction, patchedManifest }
71+ return { contents : patchedContents , patchedRouteAction, patchedManifest }
6572}
6673
6774export async function patchInstalledWorkshopApp ( ) {
0 commit comments