Skip to content

Commit

Permalink
fix(schema): handle dev/test buildId in schema (#27274)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed May 20, 2024
1 parent 1ce1a55 commit a1c184a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
3 changes: 1 addition & 2 deletions packages/nuxt/src/core/nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {

// Add app manifest handler and prerender configuration
if (nuxt.options.experimental.appManifest) {
const buildId = nuxt.options.runtimeConfig.app.buildId ||=
(nuxt.options.dev ? 'dev' : nuxt.options.test ? 'test' : nuxt.options.buildId)
const buildId = nuxt.options.runtimeConfig.app.buildId ||= nuxt.options.buildId
const buildTimestamp = Date.now()

const manifestPrefix = joinURL(nuxt.options.app.buildAssetsDir, 'builds')
Expand Down
7 changes: 6 additions & 1 deletion packages/schema/src/config/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
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()
},
},

/**
Expand Down
6 changes: 1 addition & 5 deletions vitest.nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ export default defineVitestConfig({
environmentOptions: {
nuxt: {
overrides: {
buildId: 'override',
experimental: {
appManifest: process.env.TEST_MANIFEST !== 'manifest-off',
},
runtimeConfig: {
app: {
buildId: 'override',
},
},
},
},
},
Expand Down

0 comments on commit a1c184a

Please sign in to comment.