Skip to content

Commit ffa3c68

Browse files
authored
fix: should check lib array non-empty (#820)
1 parent a5f75e4 commit ffa3c68

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

packages/core/src/config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,9 +1571,11 @@ export async function composeCreateRsbuildConfig(
15711571
...sharedRsbuildConfig
15721572
} = rslibConfig;
15731573

1574-
if (!libConfigsArray) {
1574+
if (!Array.isArray(libConfigsArray) || libConfigsArray.length === 0) {
15751575
throw new Error(
1576-
`Expect lib field to be an array, but got ${libConfigsArray}.`,
1576+
`Expect "lib" field to be a non-empty array, but got: ${color.cyan(
1577+
JSON.stringify(libConfigsArray),
1578+
)}.`,
15771579
);
15781580
}
15791581

pnpm-lock.yaml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { join } from 'node:path';
2+
import stripAnsi from 'strip-ansi';
3+
import { buildAndGetResults } from 'test-helper';
4+
import { expect, test } from 'vitest';
5+
6+
test('should throw error when lib array not exists or empty', async () => {
7+
const fixturePath = join(__dirname, 'lib-array');
8+
try {
9+
await buildAndGetResults({ fixturePath });
10+
} catch (error) {
11+
expect(stripAnsi((error as Error).message)).toMatchInlineSnapshot(
12+
`"Expect "lib" field to be a non-empty array, but got: []."`,
13+
);
14+
}
15+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "config-check-lib-array-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { defineConfig } from '@rslib/core';
2+
3+
export default defineConfig({
4+
lib: [],
5+
});

0 commit comments

Comments
 (0)