File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change
1
+ import { readFileSync } from 'fs'
2
+
1
3
import type { NetlifyConfig } from '@netlify/build'
2
4
import { copySync , moveSync } from 'fs-extra/esm'
3
5
4
- import { __dirname , NETLIFY_PUBLISH_DIR } from './constants.js'
6
+ import { __dirname , NETLIFY_PUBLISH_DIR , NETLIFY_TEMP_DIR } from './constants.js'
5
7
6
8
/**
7
9
* Modify the user's next.config.js to use standalone mode
8
10
*/
9
11
export const modifyNextConfig = ( ) => {
10
- moveSync ( 'next.config.js' , 'next.config.js.orig' )
12
+ // revert any previous changes
13
+ revertNextConfig ( )
14
+
15
+ moveSync ( 'next.config.js' , `${ NETLIFY_TEMP_DIR } /next.config.js` )
11
16
copySync ( `${ __dirname } /../templates/next.config.cjs` , 'next.config.js' )
12
17
}
13
18
14
19
export const revertNextConfig = ( ) => {
15
- moveSync ( 'next.config.js.orig' , 'next.config.js' , { overwrite : true } )
20
+ if ( readFileSync ( 'next.config.js' ) . includes ( 'Netlify generated code' ) ) {
21
+ moveSync ( `${ NETLIFY_TEMP_DIR } /next.config.js` , 'next.config.js' , { overwrite : true } )
22
+ }
16
23
}
17
24
18
25
/**
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { fileURLToPath } from 'node:url'
3
3
export const __dirname = fileURLToPath ( new URL ( '.' , import . meta. url ) )
4
4
5
5
export const NETLIFY_PUBLISH_DIR = '.netlify/publish'
6
+ export const NETLIFY_TEMP_DIR = '.netlify/temp'
6
7
7
8
export const FUNCTIONS_INTERNAL_DIR = '.netlify/functions-internal'
8
9
export const FUNCTIONS_URL = '/.netlify/functions'
You can’t perform that action at this time.
0 commit comments