fix(schema): handle dev/test `buildId` in schema (#27274)

This commit is contained in:
Daniel Roe 2024-05-19 19:53:20 -05:00 committed by GitHub
parent 1ce1a55a87
commit a1c184a288
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 8 deletions

View File

@ -218,8 +218,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
// Add app manifest handler and prerender configuration // Add app manifest handler and prerender configuration
if (nuxt.options.experimental.appManifest) { if (nuxt.options.experimental.appManifest) {
const buildId = nuxt.options.runtimeConfig.app.buildId ||= const buildId = nuxt.options.runtimeConfig.app.buildId ||= nuxt.options.buildId
(nuxt.options.dev ? 'dev' : nuxt.options.test ? 'test' : nuxt.options.buildId)
const buildTimestamp = Date.now() const buildTimestamp = Date.now()
const manifestPrefix = joinURL(nuxt.options.app.buildAssetsDir, 'builds') const manifestPrefix = joinURL(nuxt.options.app.buildAssetsDir, 'builds')

View File

@ -165,7 +165,12 @@ export default defineUntypedSchema({
* A unique identifier matching the build. This may contain the hash of the current state of the project. * A unique identifier matching the build. This may contain the hash of the current state of the project.
*/ */
buildId: { buildId: {
$resolve: (val: string) => val ?? randomUUID(), $resolve: async (val: string | undefined, get): Promise<string> => {
if (typeof val === 'string') { return val }
const [isDev, isTest] = await Promise.all([get('dev') as Promise<boolean>, get('test') as Promise<boolean>])
return isDev ? 'dev' : isTest ? 'test' : randomUUID()
},
}, },
/** /**

View File

@ -13,14 +13,10 @@ export default defineVitestConfig({
environmentOptions: { environmentOptions: {
nuxt: { nuxt: {
overrides: { overrides: {
buildId: 'override',
experimental: { experimental: {
appManifest: process.env.TEST_MANIFEST !== 'manifest-off', appManifest: process.env.TEST_MANIFEST !== 'manifest-off',
}, },
runtimeConfig: {
app: {
buildId: 'override',
},
},
}, },
}, },
}, },