Skip to content

Commit 2a068d8

Browse files
committed
fix: validate entry type
1 parent 860dba6 commit 2a068d8

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

packages/core/src/config.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ const composeEntryConfig = async (
890890
root: string,
891891
cssModulesAuto: CssLoaderOptionsAuto,
892892
): Promise<{ entryConfig: EnvironmentConfig; lcp: string | null }> => {
893-
let entries = rawEntry;
893+
let entries: RsbuildConfigEntry = rawEntry;
894894

895895
if (!entries) {
896896
// In bundle mode, return directly to let Rsbuild apply default entry to './src/index.ts'
@@ -904,6 +904,15 @@ const composeEntryConfig = async (
904904
};
905905
}
906906

907+
// Type check to ensure entries is of the expected type
908+
if (typeof entries !== 'object') {
909+
throw new Error(
910+
`The ${color.cyan('source.entry')} configuration should be an object, but received ${typeof entries}: ${color.cyan(
911+
entries,
912+
)}. Please check your configuration and ensure it is correctly configured.`,
913+
);
914+
}
915+
907916
if (bundle !== false) {
908917
const entryErrorReasons: string[] = [];
909918
traverseEntryQuery(entries, (entry) => {

tests/integration/entry/index.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,17 @@ test('validate entry and throw errors', async () => {
154154
expect(stripAnsi(errMsg)).toMatchInlineSnapshot(
155155
`"Error: Can't resolve the entry "./src/main.ts" at the location <ROOT>/tests/integration/entry/validate/src/main.ts. Please ensure that the file exists."`,
156156
);
157+
158+
try {
159+
await buildAndGetResults({
160+
fixturePath,
161+
configPath: 'bundlelessWithString.config.ts',
162+
});
163+
} catch (e) {
164+
errMsg = (e as Error).message;
165+
}
166+
167+
expect(stripAnsi(errMsg)).toMatchInlineSnapshot(
168+
`"The source.entry configuration should be an object, but received string: ./src/**. Please check your configuration and ensure it is correctly configured."`,
169+
);
157170
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { defineConfig } from '@rslib/core';
2+
import { generateBundleEsmConfig } from 'test-helper';
3+
4+
export default defineConfig({
5+
lib: [
6+
generateBundleEsmConfig({
7+
bundle: false,
8+
source: {
9+
// @ts-expect-error test error config
10+
entry: './src/**',
11+
},
12+
}),
13+
],
14+
});

0 commit comments

Comments
 (0)