Skip to content

Commit f22fc26

Browse files
committed
fix: should throw error when no entry find with bundle dts
1 parent 424d744 commit f22fc26

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

packages/plugin-dts/src/utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,20 @@ export function processSourceEntry(
421421
entryConfig &&
422422
Object.values(entryConfig).every((val) => typeof val === 'string')
423423
) {
424-
return Object.entries(entryConfig as Record<string, string>).map(
424+
const entries = Object.entries(entryConfig as Record<string, string>).map(
425425
([name, path]) => ({
426426
name,
427427
path,
428428
}),
429429
);
430+
431+
if (entries.length === 0) {
432+
throw new Error(
433+
`Can not find a valid entry for ${color.cyan('dts.bundle')} option, please check your entry config.`,
434+
);
435+
}
436+
437+
return entries;
430438
}
431439

432440
throw new Error(
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "dts-bundle-no-entry-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
dts: {
9+
bundle: true,
10+
},
11+
}),
12+
],
13+
source: {
14+
entry: {
15+
index: '../__fixtures__/src',
16+
},
17+
tsconfigPath: '../__fixtures__/tsconfig.json',
18+
},
19+
});

tests/integration/dts/index.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,21 @@ describe('dts when bundle: true', () => {
377377

378378
expect([indexEsm, indexCjs, sumEsm, sumCjs]).toMatchSnapshot();
379379
});
380+
381+
test('can not find a valid entry', async () => {
382+
const fixturePath = join(__dirname, 'bundle', 'no-entry');
383+
const { restore } = proxyConsole();
384+
385+
try {
386+
await buildAndGetResults({ fixturePath, type: 'dts' });
387+
} catch (err: any) {
388+
expect(err.message).toMatchInlineSnapshot(
389+
`"Can not find a valid entry for dts.bundle option, please check your entry config."`,
390+
);
391+
}
392+
393+
restore();
394+
});
380395
});
381396

382397
describe('dts when build: true', () => {

0 commit comments

Comments
 (0)