Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions packages/nuxi/src/utils/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { joinURL } from 'ufo'
import { clearBuildDir } from '../utils/fs'
import { loadKit } from '../utils/kit'
import { logger } from '../utils/logger'
import { loadNuxtManifest, writeNuxtManifest } from '../utils/nuxt'
import { loadNuxtManifest, resolveNuxtManifest, writeNuxtManifest } from '../utils/nuxt'

export type NuxtDevIPCMessage =
| { type: 'nuxt:internal:dev:ready', port: number }
Expand Down Expand Up @@ -216,10 +216,15 @@ class NuxtDevServer extends EventEmitter {

// Write manifest and also check if we need cache invalidation
if (!reload) {
const previousManifest = await loadNuxtManifest(
this._currentNuxt.options.buildDir,
)
const newManifest = await writeNuxtManifest(this._currentNuxt)
const previousManifest = await loadNuxtManifest(this._currentNuxt.options.buildDir)
const newManifest = resolveNuxtManifest(this._currentNuxt)

// we deliberately do not block initialising Nuxt on creation of the manifest
const promise = writeNuxtManifest(this._currentNuxt, newManifest)
this._currentNuxt.hooks.hookOnce('ready', async () => {
await promise
})

if (
previousManifest
&& newManifest
Expand Down Expand Up @@ -284,7 +289,6 @@ class NuxtDevServer extends EventEmitter {
}

await Promise.all([

kit.writeTypes(this._currentNuxt).catch(console.error),
kit.buildNuxt(this._currentNuxt),
])
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxi/src/utils/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function clearDir(path: string, exclude?: string[]) {
}

export function clearBuildDir(path: string) {
return clearDir(path, ['cache', 'analyze'])
return clearDir(path, ['cache', 'analyze', 'nuxt.json'])
}

export async function rmRecursive(paths: string[]) {
Expand Down
11 changes: 3 additions & 8 deletions packages/nuxi/src/utils/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function nuxtVersionToGitIdentifier(version: string) {
return `v${version}`
}

function resolveNuxtManifest(nuxt: Nuxt): NuxtProjectManifest {
export function resolveNuxtManifest(nuxt: Nuxt): NuxtProjectManifest {
const manifest: NuxtProjectManifest = {
_hash: null,
project: {
Expand All @@ -56,19 +56,14 @@ function resolveNuxtManifest(nuxt: Nuxt): NuxtProjectManifest {
return manifest
}

export async function writeNuxtManifest(
nuxt: Nuxt,
): Promise<NuxtProjectManifest> {
const manifest = resolveNuxtManifest(nuxt)
export async function writeNuxtManifest(nuxt: Nuxt, manifest = resolveNuxtManifest(nuxt)): Promise<NuxtProjectManifest> {
const manifestPath = resolve(nuxt.options.buildDir, 'nuxt.json')
await fsp.mkdir(dirname(manifestPath), { recursive: true })
await fsp.writeFile(manifestPath, JSON.stringify(manifest, null, 2), 'utf-8')
return manifest
}

export async function loadNuxtManifest(
buildDir: string,
): Promise<NuxtProjectManifest | null> {
export async function loadNuxtManifest(buildDir: string): Promise<NuxtProjectManifest | null> {
const manifestPath = resolve(buildDir, 'nuxt.json')
const manifest: NuxtProjectManifest | null = await fsp
.readFile(manifestPath, 'utf-8')
Expand Down
Loading