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
18 changes: 5 additions & 13 deletions src/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -33,7 +21,11 @@ export const loadWithNative = async (
};
}

const freshImportResult = await tryFreshImport(configFileURL);
const { freshImport } = await import(
/* rspackChunkName: 'freshImport' */
'fresh-import'
);
Comment thread
chenjiahan marked this conversation as resolved.
const freshImportResult = await freshImport(configFileURL);

if (freshImportResult) {
return {
Expand Down
3 changes: 3 additions & 0 deletions tests/fresh/error.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
globalThis.__freshErrorCount = (globalThis.__freshErrorCount ?? 0) + 1;

throw new Error('test config error');
10 changes: 10 additions & 0 deletions tests/fresh/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
});