Skip to content

Improve framework detection #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,27 @@ const fs = require('fs');
const { existsSync, readFileSync } = require('fs');
const path = require('path');
const { appendFile, readdir } = require('fs').promises;
const { listFrameworks } = require('@netlify/framework-info');
const { hasFramework } = require('@netlify/framework-info');
const nextOnNetlify = require('next-on-netlify');
const { PHASE_PRODUCTION_BUILD } = require('next/constants');
const { default: loadConfig } = require('next/dist/next-server/server/config');
const makeDir = require('make-dir');
const cpx = require('cpx');
const isStaticExportProject = require('./helpers/isStaticExportProject');

const _isNextProject = async () => {
const frameworks = await listFrameworks();
return !!frameworks.find(({ name }) => name === 'next');
};

// * Helpful Plugin Context *
// - Between the prebuild and build steps, the project's build command is run
// - Between the build and postbuild steps, any functions are bundled

module.exports = {
async onPreBuild({ constants, netlifyConfig, utils }) {
const isNextProject = await _isNextProject();
if (!(await hasFramework('next'))) {
return failBuild(`This application does not use Next.js.`);
}

const { build } = netlifyConfig;
const { failBuild } = utils.build;

if (isNextProject) {
// TO-DO: Post alpha, try to remove this workaround for missing deps in
// the next-on-netlify function template
await utils.run.command('npm install next-on-netlify@latest');
Expand Down Expand Up @@ -80,14 +77,8 @@ module.exports = {
await appendFile('next.config.js', nextConfig);
console.log(`** Adding next.config.js with target set to 'serverless' **`);
}
} else {
failBuild(`This application does not use Next.js.`);
}
},
async onBuild({ constants }) {
const isNextProject = await _isNextProject();

if (isNextProject) {
console.log(`** Running Next on Netlify package **`);
nextOnNetlify();

Expand All @@ -107,6 +98,5 @@ module.exports = {
// with function names that next-on-netlify can generate
// cpx.copySync('out_functions/**/*', FUNCTIONS_SRC);
cpx.copySync('out_publish/**/*', PUBLISH_DIR);
}
}
}
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"homepage": "https://github.com/netlify/netlify-plugin-nextjs#readme",
"dependencies": {
"@netlify/framework-info": "^0.1.3",
"@netlify/framework-info": "^0.2.0",
"cpx": "^1.5.0",
"make-dir": "^3.1.0",
"next-on-netlify": "^2.6.0"
Expand Down