Skip to content

Commit feb4672

Browse files
committed
fix: replace _generate property usage
1 parent cb88068 commit feb4672

5 files changed

Lines changed: 34 additions & 32 deletions

File tree

specs/utils/nuxt.ts

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -62,37 +62,38 @@ export async function loadFixture(testContext: VitestContext) {
6262
const buildDir = resolve(ctx.options.rootDir, '.nuxt', testKey)
6363
const outputDir = resolve(ctx.options.rootDir, '.output', testKey)
6464

65-
ctx.options.nuxtConfig = defu(ctx.options.nuxtConfig, {
66-
buildDir,
67-
modules: [
68-
(_, nuxt) => {
69-
/**
70-
* Register nitro plugin for IPC communication to update runtime config
71-
*/
72-
nuxt.options.nitro.plugins ||= []
73-
nuxt.options.nitro.plugins.push(fileURLToPath(new URL('./nitro-plugin', import.meta.url)))
74-
/**
75-
* The `overrides` option is only used for testing, it is used to option overrides to the project layer in a fixture.
76-
*/
77-
if (nuxt.options?.i18n?.overrides) {
78-
const project = nuxt.options._layers[0]
79-
const { overrides, ...mergedOptions } = nuxt.options.i18n
80-
delete nuxt.options.i18n.overrides
81-
project.config.i18n = defu(overrides, project.config.i18n)
82-
Object.assign(nuxt.options.i18n, defu(overrides, mergedOptions))
65+
ctx.options.nuxtConfig = defu(
66+
ctx.options.nuxtConfig,
67+
{
68+
buildDir,
69+
modules: [
70+
(_, nuxt) => {
71+
/**
72+
* Register nitro plugin for IPC communication to update runtime config
73+
*/
74+
nuxt.options.nitro.plugins ||= []
75+
nuxt.options.nitro.plugins.push(fileURLToPath(new URL('./nitro-plugin', import.meta.url)))
76+
/**
77+
* The `overrides` option is only used for testing, it is used to option overrides to the project layer in a fixture.
78+
*/
79+
if (nuxt.options?.i18n?.overrides) {
80+
const project = nuxt.options._layers[0]
81+
const { overrides, ...mergedOptions } = nuxt.options.i18n
82+
delete nuxt.options.i18n.overrides
83+
project.config.i18n = defu(overrides, project.config.i18n)
84+
Object.assign(nuxt.options.i18n, defu(overrides, mergedOptions))
85+
}
86+
}
87+
],
88+
_generate: ctx.options.prerender,
89+
nitro: {
90+
output: {
91+
dir: outputDir
8392
}
8493
}
85-
],
86-
// NOTE: the following code is added for prerender
87-
_generate: ctx.options.prerender,
88-
nitro: {
89-
...(ctx.options.prerender ? { static: true } : {}),
90-
output: {
91-
dir: outputDir,
92-
...(ctx.options.prerender ? { publicDir: resolve(outputDir, 'public') } : {})
93-
}
94-
}
95-
})
94+
},
95+
ctx.options.prerender ? { nitro: { static: true, output: { publicDir: resolve(outputDir, 'public') } } } : {}
96+
)
9697
}
9798

9899
ctx.nuxt = await kit.loadNuxt({

src/bundler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function getDefineConfig({ options, fullStatic }: I18nNuxtContext, server
7171

7272
const common = {
7373
__IS_SSR__: String(nuxt.options.ssr),
74-
__IS_SSG__: String(nuxt.options._generate),
74+
__IS_SSG__: String(!!nuxt.options.nitro.static),
7575
__PARALLEL_PLUGIN__: String(options.parallelPlugin),
7676
__DYNAMIC_PARAMS_KEY__: JSON.stringify(DYNAMIC_PARAMS_KEY),
7777
__DEFAULT_COOKIE_KEY__: JSON.stringify(DEFAULT_COOKIE_KEY),

src/module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default defineNuxtModule<NuxtI18nOptions>({
2525
configKey: 'i18n',
2626
compatibility: {
2727
nuxt: '>=3.0.0-rc.11',
28+
// @ts-ignore property removed in Nuxt 4
2829
bridge: false
2930
}
3031
},

src/pages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export async function setupPages({ localeCodes, options, normalizedLocales }: I1
7070

7171
// keep root when using prefixed routing without prerendering
7272
const indexPage = pages.find(x => x.path === '/')
73-
if (!nuxt.options._generate && options.strategy === 'prefix' && indexPage != null) {
73+
if (!nuxt.options.nitro.static && options.strategy === 'prefix' && indexPage != null) {
7474
localizedPages.unshift(indexPage as NarrowedNuxtPage)
7575
}
7676

src/prepare/strategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { I18nNuxtContext } from '../context'
22
import type { Nuxt } from '@nuxt/schema'
33

44
export function prepareStrategy({ options, localeCodes }: I18nNuxtContext, nuxt: Nuxt) {
5-
if (options.strategy === 'prefix' && nuxt.options._generate) {
5+
if (options.strategy === 'prefix' && nuxt.options.nitro.static) {
66
const localizedEntryPages = localeCodes.map(x => '/' + x)
77
nuxt.hook('nitro:config', config => {
88
config.prerender ??= {}

0 commit comments

Comments
 (0)