Skip to content

Commit 4fdcb21

Browse files
chore: retain patched server files (#1533)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 086a703 commit 4fdcb21

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

packages/runtime/src/helpers/files.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ export const moveStaticPages = async ({
280280
}
281281
}
282282

283+
const PATCH_WARNING = `/* File patched by Netlify */`
284+
283285
/**
284286
* Attempt to patch a source file, preserving a backup
285287
*/
@@ -294,7 +296,13 @@ const patchFile = async ({
294296
console.warn('File was not found')
295297
return false
296298
}
297-
const content = await readFile(file, 'utf8')
299+
let content = await readFile(file, 'utf8')
300+
301+
// If the file has already been patched, patch the backed-up original instead
302+
if (content.includes(PATCH_WARNING) && existsSync(`${file}.orig`)) {
303+
content = await readFile(`${file}.orig`, 'utf8')
304+
}
305+
298306
const newContent = replacements.reduce((acc, [from, to]) => {
299307
if (acc.includes(to)) {
300308
console.log('Already patched. Skipping.')
@@ -307,7 +315,7 @@ const patchFile = async ({
307315
return false
308316
}
309317
await writeFile(`${file}.orig`, content)
310-
await writeFile(file, newContent)
318+
await writeFile(file, `${newContent}\n${PATCH_WARNING}`)
311319
console.log('Done')
312320
return true
313321
}

packages/runtime/src/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
generateCustomHeaders,
1717
} from './helpers/config'
1818
import { updateConfig, writeEdgeFunctions, loadMiddlewareManifest } from './helpers/edge'
19-
import { moveStaticPages, movePublicFiles, patchNextFiles, unpatchNextFiles } from './helpers/files'
19+
import { moveStaticPages, movePublicFiles, patchNextFiles } from './helpers/files'
2020
import { generateFunctions, setupImageFunction, generatePagesResolver } from './helpers/functions'
2121
import { generateRedirects, generateStaticRedirects } from './helpers/redirects'
2222
import { shouldSkip, isNextAuthInstalled, getCustomImageResponseHeaders } from './helpers/utils'
@@ -200,7 +200,6 @@ const plugin: NetlifyPlugin = {
200200

201201
warnForProblematicUserRewrites({ basePath, redirects })
202202
warnForRootRedirects({ appDir })
203-
await unpatchNextFiles(basePath)
204203
},
205204
}
206205
module.exports = plugin

0 commit comments

Comments
 (0)