Skip to content

Commit 56fef5f

Browse files
authored
feat: fail build when netlify forms detected without workaround (#2539)
* feat: fail build when netlify forms detected without workaround * test: update forms tests * feat: check env var before verifying netlify forms
1 parent f02ef88 commit 56fef5f

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/build/verification.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ export async function verifyNetlifyFormsWorkaround(ctx: PluginContext) {
113113

114114
export function verifyNetlifyForms(ctx: PluginContext, html: string) {
115115
if (
116-
!verifications.has('netlifyForms') &&
116+
process.env.NETLIFY_NEXT_VERIFY_FORMS !== '0' &&
117+
process.env.NETLIFY_NEXT_VERIFY_FORMS?.toUpperCase() !== 'FALSE' &&
117118
!verifications.has('netlifyFormsWorkaround') &&
118119
formDetectionRegex.test(html)
119120
) {
120-
console.warn(
121+
ctx.failBuild(
121122
'@netlify/plugin-nextjs@5 requires migration steps to support Netlify Forms. Refer to https://ntl.fyi/next-runtime-forms-migration for migration example.',
122123
)
123-
verifications.add('netlifyForms')
124124
}
125125
}

tests/integration/netlify-forms.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ beforeEach<FixtureTestContext>(async (ctx) => {
1919
await startMockBlobStore(ctx)
2020
})
2121

22-
it<FixtureTestContext>('should warn when netlify forms are used', async (ctx) => {
22+
it<FixtureTestContext>('should fail build when netlify forms are used', async (ctx) => {
2323
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
2424

2525
await createFixture('netlify-forms', ctx)
2626

27-
const runPluginPromise = await runPlugin(ctx)
27+
const runPluginPromise = runPlugin(ctx)
2828

29-
expect(warn).toBeCalledWith(
29+
await expect(runPluginPromise).rejects.toThrow(
3030
'@netlify/plugin-nextjs@5 requires migration steps to support Netlify Forms. Refer to https://ntl.fyi/next-runtime-forms-migration for migration example.',
3131
)
3232
})
3333

34-
it<FixtureTestContext>('should not warn when netlify forms are used with workaround', async (ctx) => {
34+
it<FixtureTestContext>('should not fail build when netlify forms are used with workaround', async (ctx) => {
3535
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
3636

3737
await createFixture('netlify-forms-workaround', ctx)
3838

39-
const runPluginPromise = await runPlugin(ctx)
39+
const runPluginPromise = runPlugin(ctx)
4040

41-
expect(warn).not.toBeCalled()
41+
await expect(runPluginPromise).resolves
4242
})

0 commit comments

Comments
 (0)