@@ -7,12 +7,12 @@ const { PHASE_PRODUCTION_BUILD } = require('next/constants')
77const { default : loadConfig } = require ( 'next/dist/next-server/server/config' )
88const findUp = require ( 'find-up' )
99const makeDir = require ( 'make-dir' )
10- const pathExists = require ( 'path-exists' )
11- const cpx = require ( 'cpx' )
10+ const { copy } = require ( 'cpx' )
1211
1312const isStaticExportProject = require ( './helpers/isStaticExportProject' )
1413
1514const pWriteFile = util . promisify ( fs . writeFile )
15+ const pCopy = util . promisify ( copy )
1616
1717// * Helpful Plugin Context *
1818// - Between the prebuild and build steps, the project's build command is run
@@ -73,26 +73,15 @@ module.exports = {
7373 console . log ( `** Adding next.config.js with target set to 'serverless' **` )
7474 }
7575 } ,
76- async onBuild ( { constants } ) {
76+ async onBuild ( { constants : { PUBLISH_DIR , FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC } } ) {
7777 console . log ( `** Running Next on Netlify package **` )
7878 nextOnNetlify ( )
7979
8080 // Next-on-netlify puts its files into out_functions and out_publish
8181 // 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 ) ] )
9784 } ,
9885}
86+
87+ const DEFAULT_FUNCTIONS_SRC = 'netlify-automatic-functions'
0 commit comments