Skip to content

Commit c21847a

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

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

helpers/doesNotNeedPlugin.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ const doesNotNeedPlugin = ({ netlifyConfig, packageJson }) => {
66
const { build } = netlifyConfig
77
const { scripts = {} } = packageJson
88

9+
if (!build.command) {
10+
console.log("No build command specified in the site's Netlify config. Skipping plugin")
11+
return true
12+
}
13+
914
return isStaticExportProject({ build, scripts }) || doesSiteUseNextOnNetlify({ packageJson })
1015
}
1116

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)