Skip to content

Commit 70b73d8

Browse files
committed
fix: remove unnecessary patching code
1 parent c867b59 commit 70b73d8

File tree

1 file changed

+1
-51
lines changed

1 file changed

+1
-51
lines changed

packages/runtime/src/helpers/files.ts

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,7 @@ import { cpus } from 'os'
22

33
import type { NetlifyConfig } from '@netlify/build'
44
import { yellowBright } from 'chalk'
5-
import {
6-
existsSync,
7-
readJson,
8-
move,
9-
copy,
10-
writeJson,
11-
readFile,
12-
writeFile,
13-
ensureDir,
14-
readFileSync,
15-
remove,
16-
} from 'fs-extra'
5+
import { existsSync, readJson, move, copy, writeJson, ensureDir, readFileSync, remove } from 'fs-extra'
176
import globby from 'globby'
187
import { PrerenderManifest } from 'next/dist/build'
198
import { outdent } from 'outdent'
@@ -297,45 +286,6 @@ export const moveStaticPages = async ({
297286
}
298287
}
299288

300-
const PATCH_WARNING = `/* File patched by Netlify */`
301-
302-
/**
303-
* Attempt to patch a source file, preserving a backup
304-
*/
305-
const patchFile = async ({
306-
file,
307-
replacements,
308-
}: {
309-
file: string
310-
replacements: Array<[from: string, to: string]>
311-
}): Promise<boolean> => {
312-
if (!existsSync(file)) {
313-
console.warn('File was not found')
314-
return false
315-
}
316-
let content = await readFile(file, 'utf8')
317-
318-
// If the file has already been patched, patch the backed-up original instead
319-
if (content.includes(PATCH_WARNING) && existsSync(`${file}.orig`)) {
320-
content = await readFile(`${file}.orig`, 'utf8')
321-
}
322-
323-
const newContent = replacements.reduce((acc, [from, to]) => {
324-
if (acc.includes(to)) {
325-
console.log('Already patched. Skipping.')
326-
return acc
327-
}
328-
return acc.replace(from, to)
329-
}, content)
330-
if (newContent === content) {
331-
console.warn('File was not changed')
332-
return false
333-
}
334-
await writeFile(`${file}.orig`, content)
335-
await writeFile(file, `${newContent}\n${PATCH_WARNING}`)
336-
console.log('Done')
337-
return true
338-
}
339289
/**
340290
* The file we need has moved around a bit over the past few versions,
341291
* so we iterate through the options until we find it

0 commit comments

Comments
 (0)