Skip to content

Commit db1c309

Browse files
committed
fixes #67 do not fail build for unused export script
1 parent 45658af commit db1c309

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ test/sample/netlify-automatic-functions
77
test/sample/my-publish-dir
88
test/sample/.next
99
test/sample/.netlify
10+
next.config.js
1011

1112
# Logs
1213
logs

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ node_modules
2020
__mocks__
2121
test/fixtures
2222
test/sample
23+
next.config.js

helpers/isStaticExportProject.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44

55
const isStaticExportProject = ({ build, scripts }) => {
66
const NEXT_EXPORT_COMMAND = 'next export'
7-
const isSetInNetlifyConfig = build && build.command && build.command.includes(NEXT_EXPORT_COMMAND)
7+
8+
if (!build || !build.command) return
9+
10+
const isSetInNetlifyConfig = build.command.includes(NEXT_EXPORT_COMMAND)
11+
812
const isSetInNpmScript = Object.keys(scripts).find((script) => {
9-
return scripts[script].includes(NEXT_EXPORT_COMMAND)
13+
const scriptValue = scripts[script]
14+
return build.command.includes(script) && scriptValue.includes(NEXT_EXPORT_COMMAND)
1015
})
1116
return isSetInNetlifyConfig || isSetInNpmScript
1217
}

index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ module.exports = {
2929
const { name, scripts = {}, dependencies = {} } = packageJson
3030

3131
if (isStaticExportProject({ build, scripts })) {
32-
return failBuild(`** Static HTML export next.js projects do not require this plugin **`)
32+
return failBuild(
33+
`Static HTML export Next.js projects do not require this plugin. Check your project's build command for 'next export'.`,
34+
)
3335
}
3436

3537
const hasNextOnNetlifyInstalled = dependencies['next-on-netlify'] !== undefined

test/index.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,25 @@ describe('preBuild()', () => {
6363
test('fail build if the app has static html export in npm script', async () => {
6464
await expect(
6565
plugin.onPreBuild({
66-
netlifyConfig: {},
66+
netlifyConfig: { build: { command: 'npm run build' } },
6767
packageJson: { ...DUMMY_PACKAGE_JSON, scripts: { build: 'next export' } },
6868
utils,
6969
constants: { FUNCTIONS_SRC: 'out_functions' },
7070
}),
71-
).rejects.toThrow('** Static HTML export next.js projects do not require this plugin **')
71+
).rejects.toThrow(
72+
`Static HTML export Next.js projects do not require this plugin. Check your project's build command for 'next export'.`,
73+
)
74+
})
75+
76+
test('do not fail build if the app has next export in an unused script', async () => {
77+
await expect(
78+
plugin.onPreBuild({
79+
netlifyConfig: {},
80+
packageJson: { ...DUMMY_PACKAGE_JSON, scripts: { export: 'next export' } },
81+
utils,
82+
constants: {},
83+
}),
84+
).resolves
7285
})
7386

7487
test('fail build if the app has static html export in toml/ntl config', async () => {
@@ -79,7 +92,9 @@ describe('preBuild()', () => {
7992
utils,
8093
constants: { FUNCTIONS_SRC: 'out_functions' },
8194
}),
82-
).rejects.toThrow('** Static HTML export next.js projects do not require this plugin **')
95+
).rejects.toThrow(
96+
`Static HTML export Next.js projects do not require this plugin. Check your project's build command for 'next export'.`,
97+
)
8398
})
8499

85100
test('fail build if app has next-on-netlify installed', async () => {

0 commit comments

Comments
 (0)