@@ -2,18 +2,7 @@ import { cpus } from 'os'
2
2
3
3
import type { NetlifyConfig } from '@netlify/build'
4
4
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'
17
6
import globby from 'globby'
18
7
import { PrerenderManifest } from 'next/dist/build'
19
8
import { outdent } from 'outdent'
@@ -297,45 +286,6 @@ export const moveStaticPages = async ({
297
286
}
298
287
}
299
288
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
- }
339
289
/**
340
290
* The file we need has moved around a bit over the past few versions,
341
291
* so we iterate through the options until we find it
@@ -386,82 +336,6 @@ export const getDependenciesOfFile = async (file: string) => {
386
336
return dependencies . files . map ( ( dep ) => resolve ( dirname ( file ) , dep ) )
387
337
}
388
338
389
- const baseServerReplacements : Array < [ string , string ] > = [
390
- // force manual revalidate during cache fetches
391
- // for more info https://github.com/netlify/next-runtime/pull/1541
392
- [
393
- `checkIsManualRevalidate(req, this.renderOpts.previewProps)` ,
394
- `checkIsManualRevalidate(process.env._REVALIDATE_SSG ? { headers: { 'x-prerender-revalidate': this.renderOpts.previewProps.previewModeId } } : req, this.renderOpts.previewProps)` ,
395
- ] ,
396
- // In https://github.com/vercel/next.js/pull/47803 checkIsManualRevalidate was renamed to checkIsOnDemandRevalidate
397
- [
398
- `checkIsOnDemandRevalidate(req, this.renderOpts.previewProps)` ,
399
- `checkIsOnDemandRevalidate(process.env._REVALIDATE_SSG ? { headers: { 'x-prerender-revalidate': this.renderOpts.previewProps.previewModeId } } : req, this.renderOpts.previewProps)` ,
400
- ] ,
401
- // format of checkIsOnDemandRevalidate changed in 13.3.4
402
- [
403
- 'checkIsOnDemandRevalidate)(req, this.renderOpts.previewProps)' ,
404
- 'checkIsOnDemandRevalidate)(process.env._REVALIDATE_SSG ? { headers: { "x-prerender-revalidate": this.renderOpts.previewProps.previewModeId } } : req, this.renderOpts.previewProps)' ,
405
- ] ,
406
- // ensure ISR 404 pages send the correct SWR cache headers
407
- [ `private: isPreviewMode || is404Page && cachedData` , `private: isPreviewMode && cachedData` ] ,
408
- ]
409
-
410
- const nextServerReplacements : Array < [ string , string ] > = [
411
- [
412
- `getMiddlewareManifest() {\n if (this.minimalMode) return null;` ,
413
- `getMiddlewareManifest() {\n if (this.minimalMode || (!process.env.NETLIFY_DEV && process.env.NEXT_DISABLE_NETLIFY_EDGE !== 'true' && process.env.NEXT_DISABLE_NETLIFY_EDGE !== '1')) return null;` ,
414
- ] ,
415
- [
416
- `generateCatchAllMiddlewareRoute(devReady) {\n if (this.minimalMode) return []` ,
417
- `generateCatchAllMiddlewareRoute(devReady) {\n if (this.minimalMode || (!process.env.NETLIFY_DEV && process.env.NEXT_DISABLE_NETLIFY_EDGE !== 'true' && process.env.NEXT_DISABLE_NETLIFY_EDGE !== '1')) return [];` ,
418
- ] ,
419
- [
420
- `generateCatchAllMiddlewareRoute() {\n if (this.minimalMode) return undefined;` ,
421
- `generateCatchAllMiddlewareRoute() {\n if (this.minimalMode || (!process.env.NETLIFY_DEV && process.env.NEXT_DISABLE_NETLIFY_EDGE !== 'true' && process.env.NEXT_DISABLE_NETLIFY_EDGE !== '1')) return undefined;` ,
422
- ] ,
423
- [
424
- `getMiddlewareManifest() {\n if (this.minimalMode) {` ,
425
- `getMiddlewareManifest() {\n if (!this.minimalMode && (!process.env.NETLIFY_DEV && process.env.NEXT_DISABLE_NETLIFY_EDGE === 'true' || process.env.NEXT_DISABLE_NETLIFY_EDGE === '1')) {` ,
426
- ] ,
427
- ]
428
-
429
- export const patchNextFiles = async ( root : string ) : Promise < void > => {
430
- const baseServerFile = getServerFile ( root )
431
- console . log ( `Patching ${ baseServerFile } ` )
432
- if ( baseServerFile ) {
433
- await patchFile ( {
434
- file : baseServerFile ,
435
- replacements : baseServerReplacements ,
436
- } )
437
- }
438
-
439
- const nextServerFile = getServerFile ( root , false )
440
- console . log ( `Patching ${ nextServerFile } ` )
441
- if ( nextServerFile ) {
442
- await patchFile ( {
443
- file : nextServerFile ,
444
- replacements : nextServerReplacements ,
445
- } )
446
- }
447
- }
448
-
449
- export const unpatchFile = async ( file : string ) : Promise < void > => {
450
- const origFile = `${ file } .orig`
451
- if ( existsSync ( origFile ) ) {
452
- await move ( origFile , file , { overwrite : true } )
453
- }
454
- }
455
-
456
- export const unpatchNextFiles = async ( root : string ) : Promise < void > => {
457
- const baseServerFile = getServerFile ( root )
458
- await unpatchFile ( baseServerFile )
459
- const nextServerFile = getServerFile ( root , false )
460
- if ( nextServerFile !== baseServerFile ) {
461
- await unpatchFile ( nextServerFile )
462
- }
463
- }
464
-
465
339
export const movePublicFiles = async ( {
466
340
appDir,
467
341
outdir,
0 commit comments