Skip to content

Commit c5813db

Browse files
authored
perf(dev): avoid removing manifest immediately after creation (#686)
1 parent c83ace1 commit c5813db

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

packages/nuxi/src/utils/dev.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { joinURL } from 'ufo'
1919
import { clearBuildDir } from '../utils/fs'
2020
import { loadKit } from '../utils/kit'
2121
import { logger } from '../utils/logger'
22-
import { loadNuxtManifest, writeNuxtManifest } from '../utils/nuxt'
22+
import { loadNuxtManifest, resolveNuxtManifest, writeNuxtManifest } from '../utils/nuxt'
2323

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

217217
// Write manifest and also check if we need cache invalidation
218218
if (!reload) {
219-
const previousManifest = await loadNuxtManifest(
220-
this._currentNuxt.options.buildDir,
221-
)
222-
const newManifest = await writeNuxtManifest(this._currentNuxt)
219+
const previousManifest = await loadNuxtManifest(this._currentNuxt.options.buildDir)
220+
const newManifest = resolveNuxtManifest(this._currentNuxt)
221+
222+
// we deliberately do not block initialising Nuxt on creation of the manifest
223+
const promise = writeNuxtManifest(this._currentNuxt, newManifest)
224+
this._currentNuxt.hooks.hookOnce('ready', async () => {
225+
await promise
226+
})
227+
223228
if (
224229
previousManifest
225230
&& newManifest
@@ -284,7 +289,6 @@ class NuxtDevServer extends EventEmitter {
284289
}
285290

286291
await Promise.all([
287-
288292
kit.writeTypes(this._currentNuxt).catch(console.error),
289293
kit.buildNuxt(this._currentNuxt),
290294
])

packages/nuxi/src/utils/fs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function clearDir(path: string, exclude?: string[]) {
3232
}
3333

3434
export function clearBuildDir(path: string) {
35-
return clearDir(path, ['cache', 'analyze'])
35+
return clearDir(path, ['cache', 'analyze', 'nuxt.json'])
3636
}
3737

3838
export async function rmRecursive(paths: string[]) {

packages/nuxi/src/utils/nuxt.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function nuxtVersionToGitIdentifier(version: string) {
4242
return `v${version}`
4343
}
4444

45-
function resolveNuxtManifest(nuxt: Nuxt): NuxtProjectManifest {
45+
export function resolveNuxtManifest(nuxt: Nuxt): NuxtProjectManifest {
4646
const manifest: NuxtProjectManifest = {
4747
_hash: null,
4848
project: {
@@ -56,19 +56,14 @@ function resolveNuxtManifest(nuxt: Nuxt): NuxtProjectManifest {
5656
return manifest
5757
}
5858

59-
export async function writeNuxtManifest(
60-
nuxt: Nuxt,
61-
): Promise<NuxtProjectManifest> {
62-
const manifest = resolveNuxtManifest(nuxt)
59+
export async function writeNuxtManifest(nuxt: Nuxt, manifest = resolveNuxtManifest(nuxt)): Promise<NuxtProjectManifest> {
6360
const manifestPath = resolve(nuxt.options.buildDir, 'nuxt.json')
6461
await fsp.mkdir(dirname(manifestPath), { recursive: true })
6562
await fsp.writeFile(manifestPath, JSON.stringify(manifest, null, 2), 'utf-8')
6663
return manifest
6764
}
6865

69-
export async function loadNuxtManifest(
70-
buildDir: string,
71-
): Promise<NuxtProjectManifest | null> {
66+
export async function loadNuxtManifest(buildDir: string): Promise<NuxtProjectManifest | null> {
7267
const manifestPath = resolve(buildDir, 'nuxt.json')
7368
const manifest: NuxtProjectManifest | null = await fsp
7469
.readFile(manifestPath, 'utf-8')

0 commit comments

Comments
 (0)