From f22fc26f9cd8d9fe8d1200308745c2c296dd1ce5 Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Fri, 18 Apr 2025 15:46:29 +0800 Subject: [PATCH 1/3] fix: should throw error when no entry find with bundle dts --- packages/plugin-dts/src/utils.ts | 10 +++++++++- .../dts/bundle/no-entry/package.json | 6 ++++++ .../dts/bundle/no-entry/rslib.config.ts | 19 +++++++++++++++++++ tests/integration/dts/index.test.ts | 15 +++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/integration/dts/bundle/no-entry/package.json create mode 100644 tests/integration/dts/bundle/no-entry/rslib.config.ts 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/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..8b8c86304 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(err.message).toMatchInlineSnapshot( + `"Can not find a valid entry for dts.bundle option, please check your entry config."`, + ); + } + + restore(); + }); }); describe('dts when build: true', () => { From 86e14903ce8937da76e78cf1b8006cd53baac69b Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Fri, 18 Apr 2025 15:49:15 +0800 Subject: [PATCH 2/3] chore: update --- pnpm-lock.yaml | 2 ++ 1 file changed, 2 insertions(+) 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': From 2eacb3fd490d2e60c1d9198947668ac0f2b7e3d3 Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Fri, 18 Apr 2025 16:39:23 +0800 Subject: [PATCH 3/3] chore: update --- tests/integration/dts/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/dts/index.test.ts b/tests/integration/dts/index.test.ts index 8b8c86304..66977986e 100644 --- a/tests/integration/dts/index.test.ts +++ b/tests/integration/dts/index.test.ts @@ -385,7 +385,7 @@ describe('dts when bundle: true', () => { try { await buildAndGetResults({ fixturePath, type: 'dts' }); } catch (err: any) { - expect(err.message).toMatchInlineSnapshot( + expect(stripAnsi(err.message)).toMatchInlineSnapshot( `"Can not find a valid entry for dts.bundle option, please check your entry config."`, ); }