From d8c190365ab88d0fb95927b637a69cddb184c877 Mon Sep 17 00:00:00 2001 From: Aaron Klinker Date: Thu, 20 Jul 2023 09:06:28 -0500 Subject: [PATCH] fix: Don't crash when generating types in dev mode --- src/core/build.ts | 8 ++++++-- src/index.ts | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/core/build.ts b/src/core/build.ts index 4c7f6055f..464a97d3f 100644 --- a/src/core/build.ts +++ b/src/core/build.ts @@ -39,7 +39,7 @@ export async function buildInternal( const entrypoints = await findEntrypoints(config); const groups = groupEntrypoints(entrypoints); - const { output } = await rebuild(config, groups); + const { output } = await rebuild(config, groups, undefined, true); // Post-build config.logger.success( @@ -70,7 +70,11 @@ export async function rebuild( ): Promise<{ output: BuildOutput; manifest: Manifest.WebExtensionManifest }> { // Update types directory with new files and types const allEntrypoints = await findEntrypoints(config); - await generateTypesDir(allEntrypoints, config); + await generateTypesDir(allEntrypoints, config).catch((err) => { + config.logger.warn('Failed to update .wxt directory:', err); + // Throw the error if doing a regular build, don't for dev mode. + if (config.command === 'build') throw err; + }); // Build and merge the outputs const newOutput = await buildEntrypoints(entrypointGroups, config); diff --git a/src/index.ts b/src/index.ts index 33d44de32..d486a8abf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,8 +59,9 @@ export async function createServer( await fileChangedMutex.runExclusive(async () => { const fileChanges = changeQueue.splice(0, changeQueue.length); - const changes = detectDevChanges(fileChanges, server.currentOutput); + if (fileChanges.length === 0) return; + const changes = detectDevChanges(fileChanges, server.currentOutput); if (changes.type === 'no-change') return; // Log the entrypoints that were effected