Skip to content

Commit bc160c6

Browse files
authored
fix: should throw error when no entry find with bundle dts (#934)
1 parent 6e9f930 commit bc160c6

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

packages/plugin-dts/src/utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,20 @@ export function processSourceEntry(
416416
entryConfig &&
417417
Object.values(entryConfig).every((val) => typeof val === 'string')
418418
) {
419-
return Object.entries(entryConfig as Record<string, string>).map(
419+
const entries = Object.entries(entryConfig as Record<string, string>).map(
420420
([name, path]) => ({
421421
name,
422422
path,
423423
}),
424424
);
425+
426+
if (entries.length === 0) {
427+
throw new Error(
428+
`Can not find a valid entry for ${color.cyan('dts.bundle')} option, please check your entry config.`,
429+
);
430+
}
431+
432+
return entries;
425433
}
426434

427435
throw new Error(

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: 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
@@ -381,6 +381,21 @@ describe('dts when bundle: true', () => {
381381

382382
expect([indexEsm, indexCjs, sumEsm, sumCjs]).toMatchSnapshot();
383383
});
384+
385+
test('can not find a valid entry', async () => {
386+
const fixturePath = join(__dirname, 'bundle', 'no-entry');
387+
const { restore } = proxyConsole();
388+
389+
try {
390+
await buildAndGetResults({ fixturePath, type: 'dts' });
391+
} catch (err: any) {
392+
expect(stripAnsi(err.message)).toMatchInlineSnapshot(
393+
`"Can not find a valid entry for dts.bundle option, please check your entry config."`,
394+
);
395+
}
396+
397+
restore();
398+
});
384399
});
385400

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

0 commit comments

Comments
 (0)