From f153ed0e8b0cd4f1e5782b5ce7ea17bf8b932ce0 Mon Sep 17 00:00:00 2001 From: Patryk Mostowski Date: Mon, 19 Feb 2024 18:07:58 +0100 Subject: [PATCH] fix: latest next version bug --- src/plugin/checkNextVersion.ts | 2 +- src/plugin/withTranslateRoutes.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/plugin/checkNextVersion.ts b/src/plugin/checkNextVersion.ts index e53efdf..ba4cc02 100644 --- a/src/plugin/checkNextVersion.ts +++ b/src/plugin/checkNextVersion.ts @@ -8,7 +8,7 @@ const parseVersion = (version?: string) => ?.map(Number) type TMinorPatch = `.${number}` -type TVersion = `${number}` | `${number}${TMinorPatch}` | `${number}${TMinorPatch}${TMinorPatch}` +type TVersion = `${number}` | `${number}${TMinorPatch}` | `${number}${TMinorPatch}${TMinorPatch}` | 'latest' export const checkNextVersion = ( /** Ex: '>=13.3.1', '!=12.2.4' */ diff --git a/src/plugin/withTranslateRoutes.ts b/src/plugin/withTranslateRoutes.ts index f581047..1f0e535 100644 --- a/src/plugin/withTranslateRoutes.ts +++ b/src/plugin/withTranslateRoutes.ts @@ -56,6 +56,7 @@ export const withTranslateRoutes = (userNextConfig: NextConfigWithNTR): NextConf } const hasOldRouterContextPath = checkNextVersion('<13.5.0') + const isLatestNextVersion = checkNextVersion('=latest') return { ...nextConfig, @@ -75,7 +76,7 @@ export const withTranslateRoutes = (userNextConfig: NextConfigWithNTR): NextConf if (!config.plugins) { config.plugins = [] } - const ROUTER_CONTEXT_PATH = hasOldRouterContextPath + const ROUTER_CONTEXT_PATH = (hasOldRouterContextPath && !isLatestNextVersion) ? "'next/dist/shared/lib/router-context'" : "'next/dist/shared/lib/router-context.shared-runtime'" config.plugins.push(new DefinePlugin({ ROUTER_CONTEXT_PATH }))