From c6d5b79be1d3da709731e803462f19a9f5ebf3a6 Mon Sep 17 00:00:00 2001 From: Rob Stanford Date: Tue, 9 Jul 2024 17:52:06 +0100 Subject: [PATCH 1/3] feat: fail build when netlify forms detected without workaround --- src/build/verification.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/build/verification.ts b/src/build/verification.ts index a4089349d5..e08acd3895 100644 --- a/src/build/verification.ts +++ b/src/build/verification.ts @@ -112,14 +112,9 @@ export async function verifyNetlifyFormsWorkaround(ctx: PluginContext) { } export function verifyNetlifyForms(ctx: PluginContext, html: string) { - if ( - !verifications.has('netlifyForms') && - !verifications.has('netlifyFormsWorkaround') && - formDetectionRegex.test(html) - ) { - console.warn( + if (!verifications.has('netlifyFormsWorkaround') && formDetectionRegex.test(html)) { + ctx.failBuild( '@netlify/plugin-nextjs@5 requires migration steps to support Netlify Forms. Refer to https://ntl.fyi/next-runtime-forms-migration for migration example.', ) - verifications.add('netlifyForms') } } From 8e0a3f03d21056f0e23a15070dd81b7fb9a3d34f Mon Sep 17 00:00:00 2001 From: Rob Stanford Date: Tue, 9 Jul 2024 17:52:13 +0100 Subject: [PATCH 2/3] test: update forms tests --- tests/integration/netlify-forms.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/integration/netlify-forms.test.ts b/tests/integration/netlify-forms.test.ts index 728c377d74..0087d5d9ca 100644 --- a/tests/integration/netlify-forms.test.ts +++ b/tests/integration/netlify-forms.test.ts @@ -19,24 +19,24 @@ beforeEach(async (ctx) => { await startMockBlobStore(ctx) }) -it('should warn when netlify forms are used', async (ctx) => { +it('should fail build when netlify forms are used', async (ctx) => { const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}) await createFixture('netlify-forms', ctx) - const runPluginPromise = await runPlugin(ctx) + const runPluginPromise = runPlugin(ctx) - expect(warn).toBeCalledWith( + await expect(runPluginPromise).rejects.toThrow( '@netlify/plugin-nextjs@5 requires migration steps to support Netlify Forms. Refer to https://ntl.fyi/next-runtime-forms-migration for migration example.', ) }) -it('should not warn when netlify forms are used with workaround', async (ctx) => { +it('should not fail build when netlify forms are used with workaround', async (ctx) => { const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}) await createFixture('netlify-forms-workaround', ctx) - const runPluginPromise = await runPlugin(ctx) + const runPluginPromise = runPlugin(ctx) - expect(warn).not.toBeCalled() + await expect(runPluginPromise).resolves }) From b30752b93f20c5943c8e2b86dc1860b557e4dea6 Mon Sep 17 00:00:00 2001 From: Rob Stanford Date: Tue, 9 Jul 2024 19:46:27 +0100 Subject: [PATCH 3/3] feat: check env var before verifying netlify forms --- src/build/verification.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/build/verification.ts b/src/build/verification.ts index e08acd3895..a35bd85bda 100644 --- a/src/build/verification.ts +++ b/src/build/verification.ts @@ -112,7 +112,12 @@ export async function verifyNetlifyFormsWorkaround(ctx: PluginContext) { } export function verifyNetlifyForms(ctx: PluginContext, html: string) { - if (!verifications.has('netlifyFormsWorkaround') && formDetectionRegex.test(html)) { + if ( + process.env.NETLIFY_NEXT_VERIFY_FORMS !== '0' && + process.env.NETLIFY_NEXT_VERIFY_FORMS?.toUpperCase() !== 'FALSE' && + !verifications.has('netlifyFormsWorkaround') && + formDetectionRegex.test(html) + ) { ctx.failBuild( '@netlify/plugin-nextjs@5 requires migration steps to support Netlify Forms. Refer to https://ntl.fyi/next-runtime-forms-migration for migration example.', )