Skip to content

Commit 58ab80f

Browse files
committed
feat: hide modified config in temp dir
1 parent dc0a6d7 commit 58ab80f

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/helpers/config.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1+
import { readFileSync } from 'fs'
2+
13
import type { NetlifyConfig } from '@netlify/build'
24
import { copySync, moveSync } from 'fs-extra/esm'
35

4-
import { __dirname, NETLIFY_PUBLISH_DIR } from './constants.js'
6+
import { __dirname, NETLIFY_PUBLISH_DIR, NETLIFY_TEMP_DIR } from './constants.js'
57

68
/**
79
* Modify the user's next.config.js to use standalone mode
810
*/
911
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`)
1116
copySync(`${__dirname}/../templates/next.config.cjs`, 'next.config.js')
1217
}
1318

1419
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+
}
1623
}
1724

1825
/**

src/helpers/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { fileURLToPath } from 'node:url'
33
export const __dirname = fileURLToPath(new URL('.', import.meta.url))
44

55
export const NETLIFY_PUBLISH_DIR = '.netlify/publish'
6+
export const NETLIFY_TEMP_DIR = '.netlify/temp'
67

78
export const FUNCTIONS_INTERNAL_DIR = '.netlify/functions-internal'
89
export const FUNCTIONS_URL = '/.netlify/functions'

0 commit comments

Comments
 (0)