diff --git a/packages/plugin-dts/src/utils.ts b/packages/plugin-dts/src/utils.ts index c4e6ab626..ea7eecf86 100644 --- a/packages/plugin-dts/src/utils.ts +++ b/packages/plugin-dts/src/utils.ts @@ -421,12 +421,20 @@ export function processSourceEntry( entryConfig && Object.values(entryConfig).every((val) => typeof val === 'string') ) { - return Object.entries(entryConfig as Record).map( + const entries = Object.entries(entryConfig as Record).map( ([name, path]) => ({ name, path, }), ); + + if (entries.length === 0) { + throw new Error( + `Can not find a valid entry for ${color.cyan('dts.bundle')} option, please check your entry config.`, + ); + } + + return entries; } throw new Error( diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index de6e15e89..89c46c9e8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -686,6 +686,8 @@ importers: tests/integration/dts/bundle/multiple-entries: {} + tests/integration/dts/bundle/no-entry: {} + tests/integration/dts/bundle/rootdir: devDependencies: '@types/chromecast-caf-sender': diff --git a/tests/integration/dts/bundle/no-entry/package.json b/tests/integration/dts/bundle/no-entry/package.json new file mode 100644 index 000000000..31d5e1e24 --- /dev/null +++ b/tests/integration/dts/bundle/no-entry/package.json @@ -0,0 +1,6 @@ +{ + "name": "dts-bundle-no-entry-test", + "version": "1.0.0", + "private": true, + "type": "module" +} diff --git a/tests/integration/dts/bundle/no-entry/rslib.config.ts b/tests/integration/dts/bundle/no-entry/rslib.config.ts new file mode 100644 index 000000000..6d4975d6c --- /dev/null +++ b/tests/integration/dts/bundle/no-entry/rslib.config.ts @@ -0,0 +1,19 @@ +import { defineConfig } from '@rslib/core'; +import { generateBundleEsmConfig } from 'test-helper'; + +export default defineConfig({ + lib: [ + generateBundleEsmConfig({ + bundle: false, + dts: { + bundle: true, + }, + }), + ], + source: { + entry: { + index: '../__fixtures__/src', + }, + tsconfigPath: '../__fixtures__/tsconfig.json', + }, +}); diff --git a/tests/integration/dts/index.test.ts b/tests/integration/dts/index.test.ts index 0b5632639..66977986e 100644 --- a/tests/integration/dts/index.test.ts +++ b/tests/integration/dts/index.test.ts @@ -377,6 +377,21 @@ describe('dts when bundle: true', () => { expect([indexEsm, indexCjs, sumEsm, sumCjs]).toMatchSnapshot(); }); + + test('can not find a valid entry', async () => { + const fixturePath = join(__dirname, 'bundle', 'no-entry'); + const { restore } = proxyConsole(); + + try { + await buildAndGetResults({ fixturePath, type: 'dts' }); + } catch (err: any) { + expect(stripAnsi(err.message)).toMatchInlineSnapshot( + `"Can not find a valid entry for dts.bundle option, please check your entry config."`, + ); + } + + restore(); + }); }); describe('dts when build: true', () => {