@@ -2,30 +2,27 @@ const fs = require('fs');
2
2
const { existsSync, readFileSync } = require ( 'fs' ) ;
3
3
const path = require ( 'path' ) ;
4
4
const { appendFile, readdir } = require ( 'fs' ) . promises ;
5
- const { listFrameworks } = require ( '@netlify/framework-info' ) ;
5
+ const { hasFramework } = require ( '@netlify/framework-info' ) ;
6
6
const nextOnNetlify = require ( 'next-on-netlify' ) ;
7
7
const { PHASE_PRODUCTION_BUILD } = require ( 'next/constants' ) ;
8
8
const { default : loadConfig } = require ( 'next/dist/next-server/server/config' ) ;
9
9
const makeDir = require ( 'make-dir' ) ;
10
10
const cpx = require ( 'cpx' ) ;
11
11
const isStaticExportProject = require ( './helpers/isStaticExportProject' ) ;
12
12
13
- const _isNextProject = async ( ) => {
14
- const frameworks = await listFrameworks ( ) ;
15
- return ! ! frameworks . find ( ( { name } ) => name === 'next' ) ;
16
- } ;
17
-
18
13
// * Helpful Plugin Context *
19
14
// - Between the prebuild and build steps, the project's build command is run
20
15
// - Between the build and postbuild steps, any functions are bundled
21
16
22
17
module . exports = {
23
18
async onPreBuild ( { constants, netlifyConfig, utils } ) {
24
- const isNextProject = await _isNextProject ( ) ;
19
+ if ( ! ( await hasFramework ( 'next' ) ) ) {
20
+ return failBuild ( `This application does not use Next.js.` ) ;
21
+ }
22
+
25
23
const { build } = netlifyConfig ;
26
24
const { failBuild } = utils . build ;
27
25
28
- if ( isNextProject ) {
29
26
// TO-DO: Post alpha, try to remove this workaround for missing deps in
30
27
// the next-on-netlify function template
31
28
await utils . run . command ( 'npm install next-on-netlify@latest' ) ;
@@ -80,14 +77,8 @@ module.exports = {
80
77
await appendFile ( 'next.config.js' , nextConfig ) ;
81
78
console . log ( `** Adding next.config.js with target set to 'serverless' **` ) ;
82
79
}
83
- } else {
84
- failBuild ( `This application does not use Next.js.` ) ;
85
- }
86
80
} ,
87
81
async onBuild ( { constants } ) {
88
- const isNextProject = await _isNextProject ( ) ;
89
-
90
- if ( isNextProject ) {
91
82
console . log ( `** Running Next on Netlify package **` ) ;
92
83
nextOnNetlify ( ) ;
93
84
@@ -107,6 +98,5 @@ module.exports = {
107
98
// with function names that next-on-netlify can generate
108
99
// cpx.copySync('out_functions/**/*', FUNCTIONS_SRC);
109
100
cpx . copySync ( 'out_publish/**/*' , PUBLISH_DIR ) ;
110
- }
111
101
}
112
102
}
0 commit comments