Skip to content

Commit

Permalink
fix: should check lib array non-empty (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
Timeless0911 authored Mar 6, 2025
1 parent a5f75e4 commit ffa3c68
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1571,9 +1571,11 @@ export async function composeCreateRsbuildConfig(
...sharedRsbuildConfig
} = rslibConfig;

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

Expand Down
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions tests/integration/config-check/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { join } from 'node:path';
import stripAnsi from 'strip-ansi';
import { buildAndGetResults } from 'test-helper';
import { expect, test } from 'vitest';

test('should throw error when lib array not exists or empty', async () => {
const fixturePath = join(__dirname, 'lib-array');
try {
await buildAndGetResults({ fixturePath });
} catch (error) {
expect(stripAnsi((error as Error).message)).toMatchInlineSnapshot(
`"Expect "lib" field to be a non-empty array, but got: []."`,
);
}
});
6 changes: 6 additions & 0 deletions tests/integration/config-check/lib-array/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "config-check-lib-array-test",
"version": "1.0.0",
"private": true,
"type": "module"
}
5 changes: 5 additions & 0 deletions tests/integration/config-check/lib-array/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from '@rslib/core';

export default defineConfig({
lib: [],
});

0 comments on commit ffa3c68

Please sign in to comment.