8000 fix(nuxt): do not prompt to update `compatibilityDate` (#31725) · nuxt/nuxt@b3334d0 · GitHub
[go: up one dir, main page]

8000 Skip to content

Commit b3334d0

Browse files
committed
fix(nuxt): do not prompt to update compatibilityDate (#31725)
1 parent 1e992a3 commit b3334d0

File tree

10 files changed

+13
-76
lines changed

10 files changed

+13
-76
lines changed

packages/nuxt/src/core/nuxt.ts

Lines changed: 4 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import { readPackageJSON } from 'pkg-types'
1313
import { hash } from 'ohash'
1414
import consola from 'consola'
1515
import onChange from 'on-change'
16-
import { colorize } from 'consola/utils'
17-
import { updateConfig } from 'c12/update'
16+
import { colors } from 'consola/utils'
1817
import { formatDate, resolveCompatibilityDatesFromEnv } from 'compatx'
1918
import type { DateString } from 'compatx'
2019
import escapeRE from 'escape-string-regexp'
@@ -167,67 +166,12 @@ async function initNuxt (nuxt: Nuxt) {
167166
nuxt.options.compatibilityDate = resolveCompatibilityDatesFromEnv(nuxt.options.compatibilityDate)
168167

169168
if (!nuxt.options.compatibilityDate.default) {
170-
const todaysDate = formatDate(new Date())
171169
nuxt.options.compatibilityDate.default = fallbackCompatibilityDate
172170

173-
const shouldShowPrompt = nuxt.options.dev && hasTTY && !isCI
174-
if (!shouldShowPrompt) {
175-
logger.info(`Using \`${fallbackCompatibilityDate}\` as fallback compatibility date.`)
171+
if (nuxt.options.dev && hasTTY && !isCI && !nuxt.options.test && !warnedAboutCompatDate) {
172+
warnedAboutCompatDate = true
173+
consola.warn(`We recommend adding \`compatibilityDate: '${formatDate('latest')}'\` to your \`nuxt.config\` file.\nUsing \`${fallbackCompatibilityDate}\` as fallback. More info at: ${colors.underline('https://nitro.build/deploy#compatibility-date')}`)
176174
}
177-
178-
async function promptAndUpdate () {
179-
const result = await consola.prompt(`Do you want to update your ${colorize('cyan', 'nuxt.config')} to set ${colorize('cyan', `compatibilityDate: '${todaysDate}'`)}?`, {
180-
type: 'confirm',
181-
default: true,
182-
})
183-
if (result !== true) {
184-
logger.info(`Using \`${fallbackCompatibilityDate}\` as fallback compatibility date.`)
185-
return
186-
}
187-
188-
try {
189-
const res = await updateConfig({
190-
configFile: 'nuxt.config',
191-
cwd: nuxt.options.rootDir,
192-
async onCreate ({ configFile }) {
193-
const shallCreate = await consola.prompt(`Do you want to create ${colorize('cyan', relative(nuxt.options.rootDir, configFile))}?`, {
194-
type: 'confirm',
195-
default: true,
196-
})
197-
if (shallCreate !== true) {
198-
return false
199-
}
200-
return _getDefaultNuxtConfig()
201-
},
202-
onUpdate (config) {
203-
config.compatibilityDate = todaysDate
204-
},
205-
})
206-
207-
if (res?.configFile) {
208-
nuxt.options.compatibilityDate = resolveCompatibilityDatesFromEnv(todaysDate)
209-
consola.success(`Compatibility date set to \`${todaysDate}\` in \`${relative(nuxt.options.rootDir, res.configFile)}\``)
210-
return
211-
}
212-
} catch (err) {
213-
const message = err instanceof Error ? err.message : err
214-
215-
consola.error(`Failed to update config: ${message}`)
216-
}
217-
218-
logger.info(`Using \`${fallbackCompatibilityDate}\` as fallback compatibility date.`)
219-
}
220-
221-
nuxt.hooks.hookOnce('nitro:init', (nitro) => {
222-
if (warnedAboutCompatDate) { return }
223-
224-
nitro.hooks.hookOnce('compiled', () => {
225-
warnedAboutCompatDate = true
226-
// Print warning
227-
logger.info(`Nuxt now supports pinning the behavior of provider and deployment presets with a compatibility date. We recommend you specify a \`compatibilityDate\` in your \`nuxt.config\` file, or set an environment variable, such as \`COMPATIBILITY_DATE=${todaysDate}\`.`)
228-
if (shouldShowPrompt) { promptAndUpdate() }
229-
})
230-
})
231175
}
232176

233177
// Restart Nuxt when layer directories are added or removed
@@ -1001,10 +945,3 @@ function createPortalProperties (sourceValue: any, options: NuxtOptions, paths:
1001945
})
1002946
}
1003947
}
1004-
1005-
const _getDefaultNuxtConfig = () => /* js */
1006-
`// https://nuxt.com/docs/api/configuration/nuxt-config
1007-
export default defineNuxtConfig({
1008-
devtools: { enabled: true }
1009-
})
1010-
`

playground/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export default defineNuxtConfig({
22
devtools: { enabled: true },
3-
compatibilityDate: '2024-06-28',
3+
compatibilityDate: 'latest',
44
})

test/fixtures/basic-types/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export default defineNuxtConfig({
9090
typedPages: true,
9191
appManifest: true,
9292
},
93-
compatibilityDate: '2024-06-28',
93+
compatibilityDate: 'latest',
9494
telemetry: false, // for testing telemetry types - it is auto-disabled in tests
9595
hooks: {
9696
'schema:extend' (schemas) {

test/fixtures/basic/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export default defineNuxtConfig({
178178
headNext: true,
179179
inlineRouteRules: true,
180180
},
181-
compatibilityDate: '2024-06-28',
181+
compatibilityDate: 'latest',
182182
nitro: {
183183
publicAssets: [
184184
{

test/fixtures/hmr/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ export default defineNuxtConfig({
66
renderJsonPayloads: process.env.TEST_PAYLOAD !== 'js',
77
inlineRouteRules: true,
88
},
9-
compatibilityDate: '2024-06-28',
9+
compatibilityDate: 'latest',
1010
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default defineNuxtConfig({
22
future: { compatibilityVersion: process.env.TEST_V4 === 'true' ? 4 : 3 },
33
experimental: { appManifest: true },
4-
compatibilityDate: '2024-06-28',
4+
compatibilityDate: 'latest',
55
})

test/fixtures/minimal/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default defineNuxtConfig({
2828
experimental: {
2929
externalVue: !testWithInlineVue,
3030
},
31-
compatibilityDate: '2024-06-28',
31+
compatibilityDate: 'latest',
3232
nitro: {
3333
output: { dir: fileURLToPath(new URL(testWithInlineVue ? './.output-inline' : './.output', import.meta.url)) },
3434
},

test/fixtures/runtime-compiler/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export default defineNuxtConfig({
88
experimental: {
99
externalVue: false,
1010
},
11-
compatibilityDate: '2024-06-28',
11+
compatibilityDate: 'latest',
1212
})

test/fixtures/spa-loader/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export default defineNuxtConfig({
88
experimental: {
99
spaLoadingTemplateLocation: 'within',
1010
},
11-
compatibilityDate: '2024-06-28',
11+
compatibilityDate: 'latest',
1212
})

test/fixtures/suspense/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default defineNuxtConfig({
99
experimental: {
1010
externalVue: !testWithInlineVue,
1111
},
12-
compatibilityDate: '2024-06-28',
12+
compatibilityDate: 'latest',
1313
nitro: {
1414
output: { dir: fileURLToPath(new URL(testWithInlineVue ? './.output-inline' : './.output', import.meta.url)) },
1515
},

0 commit comments

Comments
 (0)
0