From 20a5629e58ca2f7e57cbdf8b05e8e6c22dfea977 Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 11 Jul 2026 17:19:03 +0800 Subject: [PATCH] fix: preserve fresh config errors --- src/native.ts | 18 +++++------------- tests/fresh/error.config.mjs | 3 +++ tests/fresh/index.test.ts | 10 ++++++++++ 3 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 tests/fresh/error.config.mjs diff --git a/src/native.ts b/src/native.ts index 51cb32f..409df55 100644 --- a/src/native.ts +++ b/src/native.ts @@ -7,18 +7,6 @@ type NativeLoadResult = { export const JS_CONFIG_REGEXP = /\.(?:js|mjs|cjs)$/; -const tryFreshImport = async (configFileURL: string) => { - try { - const { freshImport } = await import( - /* rspackChunkName: 'freshImport' */ - 'fresh-import' - ); - return await freshImport(configFileURL); - } catch { - // - } -}; - export const loadWithNative = async ( configPath: string, fresh: boolean, @@ -33,7 +21,11 @@ export const loadWithNative = async ( }; } - const freshImportResult = await tryFreshImport(configFileURL); + const { freshImport } = await import( + /* rspackChunkName: 'freshImport' */ + 'fresh-import' + ); + const freshImportResult = await freshImport(configFileURL); if (freshImportResult) { return { diff --git a/tests/fresh/error.config.mjs b/tests/fresh/error.config.mjs new file mode 100644 index 0000000..d32dbdd --- /dev/null +++ b/tests/fresh/error.config.mjs @@ -0,0 +1,3 @@ +globalThis.__freshErrorCount = (globalThis.__freshErrorCount ?? 0) + 1; + +throw new Error('test config error'); diff --git a/tests/fresh/index.test.ts b/tests/fresh/index.test.ts index c219e46..acfbd4b 100644 --- a/tests/fresh/index.test.ts +++ b/tests/fresh/index.test.ts @@ -5,6 +5,7 @@ import { loadConfig } from '../../src/index'; const __dirname = import.meta.dirname; const configPath = join(__dirname, 'demo.config.mjs'); const depPath = join(__dirname, 'dep.mjs'); +const errorConfigPath = join(__dirname, 'error.config.mjs'); test('fresh reloads bypass module cache and report relative dependencies', async () => { Reflect.deleteProperty(globalThis, '__freshConfigCount'); @@ -36,3 +37,12 @@ test('fresh reloads bypass module cache and report relative dependencies', async expect(fresh.dependencies).toEqual([depPath]); expect(fresher.dependencies).toEqual([depPath]); }); + +test('fresh config errors are not retried', async () => { + Reflect.deleteProperty(globalThis, '__freshErrorCount'); + + await expect( + loadConfig({ path: errorConfigPath, loader: 'native', fresh: true }), + ).rejects.toThrow('test config error'); + expect(Reflect.get(globalThis, '__freshErrorCount')).toBe(1); +});