1
- const fs = require ( 'fs' )
2
- const path = require ( 'path' )
3
- const util = require ( 'util' )
4
-
5
- const findUp = require ( 'find-up' )
6
1
const makeDir = require ( 'make-dir' )
7
2
8
3
const { restoreCache, saveCache } = require ( './helpers/cacheBuild' )
9
4
const copyUnstableIncludedDirs = require ( './helpers/copyUnstableIncludedDirs' )
10
5
const doesNotNeedPlugin = require ( './helpers/doesNotNeedPlugin' )
11
6
const getNextConfig = require ( './helpers/getNextConfig' )
12
7
const validateNextUsage = require ( './helpers/validateNextUsage' )
8
+ const verifyBuildTarget = require ( './helpers/verifyBuildTarget' )
13
9
const nextOnNetlify = require ( './src' )
14
10
15
- const pWriteFile = util . promisify ( fs . writeFile )
16
-
17
11
// * Helpful Plugin Context *
18
12
// - Between the prebuild and build steps, the project's build command is run
19
13
// - Between the build and postbuild steps, any functions are bundled
@@ -29,21 +23,13 @@ module.exports = {
29
23
return failBuild ( 'Could not find a package.json for this project' )
30
24
}
31
25
32
- const pluginNotNeeded = await doesNotNeedPlugin ( { netlifyConfig, packageJson, failBuild } )
33
-
34
- if ( ! pluginNotNeeded ) {
35
- const nextConfigPath = await findUp ( 'next.config.js' )
36
- if ( nextConfigPath === undefined ) {
37
- // Create the next config file with target set to serverless by default
38
- const nextConfig = `
39
- module.exports = {
40
- target: 'serverless'
41
- }
42
- `
43
- await pWriteFile ( 'next.config.js' , nextConfig )
44
- }
26
+ if ( doesNotNeedPlugin ( { netlifyConfig, packageJson, failBuild } ) ) {
27
+ return
45
28
}
46
29
30
+ // Populates the correct config if needed
31
+ await verifyBuildTarget ( { netlifyConfig, packageJson, failBuild } )
32
+
47
33
// Because we memoize nextConfig, we need to do this after the write file
48
34
const nextConfig = await getNextConfig ( utils . failBuild )
49
35
@@ -64,7 +50,7 @@ module.exports = {
64
50
} ) {
65
51
const { failBuild } = utils . build
66
52
67
- if ( await doesNotNeedPlugin ( { netlifyConfig, packageJson, failBuild } ) ) {
53
+ if ( doesNotNeedPlugin ( { netlifyConfig, packageJson, failBuild } ) ) {
68
54
return
69
55
}
70
56
@@ -76,7 +62,7 @@ module.exports = {
76
62
} ,
77
63
78
64
async onPostBuild ( { netlifyConfig, packageJson, constants : { FUNCTIONS_DIST } , utils } ) {
79
- if ( await doesNotNeedPlugin ( { netlifyConfig, packageJson, utils } ) ) {
65
+ if ( doesNotNeedPlugin ( { netlifyConfig, packageJson, utils } ) ) {
80
66
return
81
67
}
82
68
0 commit comments