Skip to content

Commit 4d0524b

Browse files
authored
fix: skip plugin if build command is empty (#471)
* fix: skip plugin if build command is empty * fix: report build status
1 parent fcb06fe commit 4d0524b

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

helpers/doesNotNeedPlugin.js

+9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
// Checks all the cases for which the plugin should do nothing
2+
const { redBright } = require('chalk')
3+
24
const doesSiteUseNextOnNetlify = require('./doesSiteUseNextOnNetlify')
35
const isStaticExportProject = require('./isStaticExportProject')
46

57
const doesNotNeedPlugin = ({ netlifyConfig, packageJson }) => {
68
const { build } = netlifyConfig
79
const { scripts = {} } = packageJson
810

11+
if (!build.command) {
12+
console.log(
13+
redBright`⚠️ Warning: No build command specified in the site's Netlify config, so plugin will not run. This deploy will fail unless you have already exported the site. ⚠️`,
14+
)
15+
return true
16+
}
17+
918
return isStaticExportProject({ build, scripts }) || doesSiteUseNextOnNetlify({ packageJson })
1019
}
1120

index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ module.exports = {
8686
if (doesNotNeedPlugin({ netlifyConfig, packageJson, utils })) {
8787
utils.status.show({
8888
title: 'Essential Next.js Build Plugin did not run',
89-
summary: 'The site either uses static export, or manually runs next-on-netlify',
89+
summary: netlifyConfig.build.command
90+
? 'The site either uses static export, or manually runs next-on-netlify'
91+
: 'The site config does not specify a build command',
9092
})
9193
return
9294
}

test/index.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,20 @@ afterEach(async () => {
7373
})
7474

7575
const DUMMY_PACKAGE_JSON = { name: 'dummy', version: '1.0.0' }
76-
const netlifyConfig = { build: {} }
76+
const netlifyConfig = { build: { command: 'next build' } }
7777

7878
describe('preBuild()', () => {
79+
test('do nothing if the app has no build command', async () => {
80+
await plugin.onPreBuild({
81+
netlifyConfig: { build: { command: '' } },
82+
packageJson: { ...DUMMY_PACKAGE_JSON, scripts: { build: 'next build' } },
83+
utils,
84+
constants: { FUNCTIONS_SRC: 'out_functions' },
85+
})
86+
87+
expect(await pathExists('next.config.js')).toBeFalsy()
88+
})
89+
7990
test('do nothing if the app has static html export in npm script', async () => {
8091
await plugin.onPreBuild({
8192
netlifyConfig: { build: { command: 'npm run build' } },
@@ -205,7 +216,7 @@ describe('onBuild()', () => {
205216
await moveNextDist()
206217
const PUBLISH_DIR = 'publish'
207218
await plugin.onBuild({
208-
netlifyConfig: { build: { publish: path.resolve(PUBLISH_DIR) } },
219+
netlifyConfig: { build: { publish: path.resolve(PUBLISH_DIR), command: 'next build' } },
209220
packageJson: DUMMY_PACKAGE_JSON,
210221
constants: {
211222
PUBLISH_DIR,

0 commit comments

Comments
 (0)