@@ -7,12 +7,12 @@ const { PHASE_PRODUCTION_BUILD } = require('next/constants')
7
7
const { default : loadConfig } = require ( 'next/dist/next-server/server/config' )
8
8
const findUp = require ( 'find-up' )
9
9
const makeDir = require ( 'make-dir' )
10
- const pathExists = require ( 'path-exists' )
11
- const cpx = require ( 'cpx' )
10
+ const { copy } = require ( 'cpx' )
12
11
13
12
const isStaticExportProject = require ( './helpers/isStaticExportProject' )
14
13
15
14
const pWriteFile = util . promisify ( fs . writeFile )
15
+ const pCopy = util . promisify ( copy )
16
16
17
17
// * Helpful Plugin Context *
18
18
// - Between the prebuild and build steps, the project's build command is run
@@ -73,26 +73,15 @@ module.exports = {
73
73
console . log ( `** Adding next.config.js with target set to 'serverless' **` )
74
74
}
75
75
} ,
76
- async onBuild ( { constants } ) {
76
+ async onBuild ( { constants : { PUBLISH_DIR , FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC } } ) {
77
77
console . log ( `** Running Next on Netlify package **` )
78
78
nextOnNetlify ( )
79
79
80
80
// Next-on-netlify puts its files into out_functions and out_publish
81
81
// Copy files from next-on-netlify's output to the right functions/publish dirs
82
-
83
- // TO-DO: use FUNCTIONS_DIST when internal bug is fixed
84
- const { PUBLISH_DIR } = constants
85
- // if (!(await pathExists(FUNCTIONS_DIST))) {
86
- // await makeDir(FUNCTIONS_DIST)
87
- // }
88
- const hasPublishDir = await pathExists ( PUBLISH_DIR )
89
- if ( ! hasPublishDir ) {
90
- await makeDir ( PUBLISH_DIR )
91
- }
92
-
93
- // TO-DO: make sure FUNCTIONS_DIST doesnt have a custom function name conflict
94
- // with function names that next-on-netlify can generate
95
- // cpx.copySync('out_functions/**/*', FUNCTIONS_SRC);
96
- cpx . copySync ( 'out_publish/**/*' , PUBLISH_DIR )
82
+ await makeDir ( PUBLISH_DIR )
83
+ await Promise . all ( [ pCopy ( 'out_functions/**' , FUNCTIONS_SRC ) , pCopy ( 'out_publish/**' , PUBLISH_DIR ) ] )
97
84
} ,
98
85
}
86
+
87
+ const DEFAULT_FUNCTIONS_SRC = 'netlify-automatic-functions'
0 commit comments