Skip to content

Commit cd98c23

Browse files
Fix workshop app patch target
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
1 parent 43a935c commit cd98c23

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

epicshop/patch-workshop-app.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ function getWorkshopAppServerBuildPath() {
1616
}
1717

1818
export function patchServerBuild(contents) {
19+
let patchedContents = contents
1920
const routeModuleName = contents.match(
20-
/"routes\/\$":\s*\{[\s\S]*?module:\s*(route\d+)/,
21+
/const routes = \{[\s\S]*?"routes\/\$":\s*\{[\s\S]*?module:\s*(route\d+)/,
2122
)?.[1]
2223

2324
if (!routeModuleName) {
@@ -46,22 +47,28 @@ export function patchServerBuild(contents) {
4647
if (!/\n\s+action:/.test(routeModuleBody)) {
4748
const patchedRouteModuleBody = routeModuleBody.replace(
4849
/\n(\s+)loader:\s*([A-Za-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
/"routes\/\$": \{([\s\S]{0,600}?)"hasAction": false/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

6774
export async function patchInstalledWorkshopApp() {

0 commit comments

Comments
 (0)