Skip to content

Commit 84dc6f5

Browse files
committed
fix: skip plugin if build command is empty
1 parent 4edbc73 commit 84dc6f5

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

helpers/doesNotNeedPlugin.js

Lines changed: 9 additions & 0 deletions
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

test/index.js

Lines changed: 13 additions & 2 deletions
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)