From ccebe4efefac629790abec617b075c2c41a9ad78 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 27 Jun 2023 20:25:14 +0200 Subject: [PATCH] fix(vercel, netlify): always check `nativeSWR` future flag --- src/presets/netlify.ts | 21 ++++++++++++++------- src/presets/vercel.ts | 17 +++++++++++------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/presets/netlify.ts b/src/presets/netlify.ts index 5b6dca0250..6fb9ae628a 100644 --- a/src/presets/netlify.ts +++ b/src/presets/netlify.ts @@ -19,9 +19,7 @@ export const netlify = defineNitroPreset({ }, hooks: { "rollup:before": (nitro: Nitro) => { - if (!nitro.options.future.nativeSWR) { - deprecateSWR(nitro); - } + deprecateSWR(nitro); }, async compiled(nitro: Nitro) { await writeHeaders(nitro); @@ -45,7 +43,9 @@ export const netlifyBuilder = defineNitroPreset({ extends: "netlify", entry: "#internal/nitro/entries/netlify-builder", hooks: { - "rollup:before": (nitro: Nitro) => deprecateSWR(nitro), + "rollup:before": (nitro: Nitro) => { + deprecateSWR(nitro); + }, }, }); @@ -67,7 +67,9 @@ export const netlifyEdge = defineNitroPreset({ polyfill: ["#internal/nitro/polyfill/deno-env"], }, hooks: { - "rollup:before": (nitro: Nitro) => deprecateSWR(nitro), + "rollup:before": (nitro: Nitro) => { + deprecateSWR(nitro); + }, async compiled(nitro: Nitro) { // https://docs.netlify.com/edge-functions/create-integration/ const manifest = { @@ -100,7 +102,9 @@ export const netlifyStatic = defineNitroPreset({ preview: "npx serve ./static", }, hooks: { - "rollup:before": (nitro: Nitro) => deprecateSWR(nitro), + "rollup:before": (nitro: Nitro) => { + deprecateSWR(nitro); + }, async compiled(nitro: Nitro) { await writeHeaders(nitro); await writeRedirects(nitro); @@ -203,6 +207,9 @@ async function writeHeaders(nitro: Nitro) { } function deprecateSWR(nitro: Nitro) { + if (nitro.options.future.nativeSWR) { + return; + } let hasLegacyOptions = false; for (const [key, value] of Object.entries(nitro.options.routeRules)) { if ("isr" in value) { @@ -221,7 +228,7 @@ function deprecateSWR(nitro: Nitro) { } if (hasLegacyOptions) { console.warn( - "[nitro] Nitro now uses `isr` option to configure ISR behavior on Netlify. Backwards-compatible support for `static` and `swr` support with Builder Functions will be removed in the future versions." + "[nitro] Nitro now uses `isr` option to configure ISR behavior on Netlify. Backwards-compatible support for `static` and `swr` support with Builder Functions will be removed in the future versions. Set `future.nativeSWR: true` nitro config disable this warning." ); } } diff --git a/src/presets/vercel.ts b/src/presets/vercel.ts index 79fd2145ff..7d47e67995 100644 --- a/src/presets/vercel.ts +++ b/src/presets/vercel.ts @@ -23,9 +23,7 @@ export const vercel = defineNitroPreset({ }, hooks: { "rollup:before": (nitro: Nitro) => { - if (!nitro.options.future.nativeSWR) { - deprecateSWR(nitro); - } + deprecateSWR(nitro); }, async compiled(nitro: Nitro) { const buildConfigPath = resolve(nitro.options.output.dir, "config.json"); @@ -103,7 +101,9 @@ export const vercelEdge = defineNitroPreset({ }, }, hooks: { - "rollup:before": (nitro: Nitro) => deprecateSWR(nitro), + "rollup:before": (nitro: Nitro) => { + deprecateSWR(nitro); + }, async compiled(nitro: Nitro) { const buildConfigPath = resolve(nitro.options.output.dir, "config.json"); const buildConfig = generateBuildConfig(nitro); @@ -136,7 +136,9 @@ export const vercelStatic = defineNitroPreset({ preview: "npx serve ./static", }, hooks: { - "rollup:before": (nitro: Nitro) => deprecateSWR(nitro), + "rollup:before": (nitro: Nitro) => { + deprecateSWR(nitro); + }, async compiled(nitro: Nitro) { const buildConfigPath = resolve(nitro.options.output.dir, "config.json"); const buildConfig = generateBuildConfig(nitro); @@ -261,6 +263,9 @@ function generateEndpoint(url: string) { } function deprecateSWR(nitro: Nitro) { + if (nitro.options.future.nativeSWR) { + return; + } let hasLegacyOptions = false; for (const [key, value] of Object.entries(nitro.options.routeRules)) { if ("isr" in value) { @@ -279,7 +284,7 @@ function deprecateSWR(nitro: Nitro) { } if (hasLegacyOptions) { console.warn( - "[nitro] Nitro now uses `isr` option to configure ISR behavior on Vercel. Backwards-compatible support for `static` and `swr` options within the Vercel Build Options API will be removed in the future versions." + "[nitro] Nitro now uses `isr` option to configure ISR behavior on Vercel. Backwards-compatible support for `static` and `swr` options within the Vercel Build Options API will be removed in the future versions. Set `future.nativeSWR: true` nitro config disable this warning." ); } }