From 34d0127d3230ac86d9b286cc6c393de1dafb07e7 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Thu, 29 Oct 2020 13:31:14 +0100 Subject: [PATCH] Improve framework detection --- index.js | 20 +++++--------------- package-lock.json | 6 +++--- package.json | 2 +- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index c90d37e252..1deb182a18 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ 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'); @@ -10,22 +10,19 @@ 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'); @@ -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(); @@ -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); - } } } diff --git a/package-lock.json b/package-lock.json index 6fcafa834c..abeff4fb06 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1218,9 +1218,9 @@ } }, "@netlify/framework-info": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/@netlify/framework-info/-/framework-info-0.1.3.tgz", - "integrity": "sha512-+dIXlgXpbYTwUHniNQPWu78bnlqC98eYE+TmWRDoFmELAHGISqbE1viRdQTxixU4B27HSy7mDqEk/RSV/irfRg==", + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@netlify/framework-info/-/framework-info-0.2.0.tgz", + "integrity": "sha512-q4G4+FODron6wSwwEDyDB2g80PFBwAQzV3AUZ825E2v+2ONaAe0JIfqnUAV62d7lhg42lf4WreTacbpKpuPeqg==", "requires": { "filter-obj": "^2.0.1", "is-plain-obj": "^2.1.0", diff --git a/package.json b/package.json index f2f10d0efa..d058d01849 100644 --- a/package.json +++ b/package.json @@ -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"