Skip to content

Commit 8efbebb

Browse files
authored
Merge pull request #14 from netlify/feat/has-framework
2 parents 3305b79 + 34d0127 commit 8efbebb

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

index.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,27 @@ const fs = require('fs');
22
const { existsSync, readFileSync } = require('fs');
33
const path = require('path');
44
const { appendFile, readdir } = require('fs').promises;
5-
const { listFrameworks } = require('@netlify/framework-info');
5+
const { hasFramework } = require('@netlify/framework-info');
66
const nextOnNetlify = require('next-on-netlify');
77
const { PHASE_PRODUCTION_BUILD } = require('next/constants');
88
const { default: loadConfig } = require('next/dist/next-server/server/config');
99
const makeDir = require('make-dir');
1010
const cpx = require('cpx');
1111
const isStaticExportProject = require('./helpers/isStaticExportProject');
1212

13-
const _isNextProject = async () => {
14-
const frameworks = await listFrameworks();
15-
return !!frameworks.find(({ name }) => name === 'next');
16-
};
17-
1813
// * Helpful Plugin Context *
1914
// - Between the prebuild and build steps, the project's build command is run
2015
// - Between the build and postbuild steps, any functions are bundled
2116

2217
module.exports = {
2318
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+
2523
const { build } = netlifyConfig;
2624
const { failBuild } = utils.build;
2725

28-
if (isNextProject) {
2926
// TO-DO: Post alpha, try to remove this workaround for missing deps in
3027
// the next-on-netlify function template
3128
await utils.run.command('npm install next-on-netlify@latest');
@@ -80,14 +77,8 @@ module.exports = {
8077
await appendFile('next.config.js', nextConfig);
8178
console.log(`** Adding next.config.js with target set to 'serverless' **`);
8279
}
83-
} else {
84-
failBuild(`This application does not use Next.js.`);
85-
}
8680
},
8781
async onBuild({ constants }) {
88-
const isNextProject = await _isNextProject();
89-
90-
if (isNextProject) {
9182
console.log(`** Running Next on Netlify package **`);
9283
nextOnNetlify();
9384

@@ -107,6 +98,5 @@ module.exports = {
10798
// with function names that next-on-netlify can generate
10899
// cpx.copySync('out_functions/**/*', FUNCTIONS_SRC);
109100
cpx.copySync('out_publish/**/*', PUBLISH_DIR);
110-
}
111101
}
112102
}

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
"homepage": "https://github.com/netlify/netlify-plugin-nextjs#readme",
2424
"dependencies": {
25-
"@netlify/framework-info": "^0.1.3",
25+
"@netlify/framework-info": "^0.2.0",
2626
"cpx": "^1.5.0",
2727
"make-dir": "^3.1.0",
2828
"next-on-netlify": "^2.6.0"

0 commit comments

Comments
 (0)