File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ import {
1616 generateCustomHeaders ,
1717} from './helpers/config'
1818import { updateConfig , writeEdgeFunctions , loadMiddlewareManifest } from './helpers/edge'
19- import { moveStaticPages , movePublicFiles , patchNextFiles , unpatchNextFiles } from './helpers/files'
19+ import { moveStaticPages , movePublicFiles , patchNextFiles } from './helpers/files'
2020import { generateFunctions , setupImageFunction , generatePagesResolver } from './helpers/functions'
2121import { generateRedirects , generateStaticRedirects } from './helpers/redirects'
2222import { 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}
206205module . exports = plugin
You can’t perform that action at this time.
0 commit comments