Skip to content

Commit

Permalink
fix: latest next version bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Patryk Mostowski authored and Patryk Mostowski committed Feb 19, 2024
1 parent 26612dc commit f153ed0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/plugin/checkNextVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' */
Expand Down
3 changes: 2 additions & 1 deletion src/plugin/withTranslateRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const withTranslateRoutes = (userNextConfig: NextConfigWithNTR): NextConf
}

const hasOldRouterContextPath = checkNextVersion('<13.5.0')
const isLatestNextVersion = checkNextVersion('=latest')

return {
...nextConfig,
Expand All @@ -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 }))
Expand Down

0 comments on commit f153ed0

Please sign in to comment.