diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index c513b23f2..294a68da1 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -1344,7 +1344,11 @@ const composeEntryConfig = async ( }); if (resolvedEntryFiles.length === 0) { - throw new Error(`Cannot find ${resolvedEntryFiles}`); + const error = new Error( + `No entry files matching ${entryFiles.map((file) => color.cyan(file)).join(', ')}. Please ensure the entry pattern in ${color.cyan('source.entry')} is correct and points to valid source files.`, + ); + error.stack = ''; + throw error; } const outBase = await resolveOutBase(resolvedEntryFiles); diff --git a/tests/integration/entry/index.test.ts b/tests/integration/entry/index.test.ts index 32b1cedf0..1c0718404 100644 --- a/tests/integration/entry/index.test.ts +++ b/tests/integration/entry/index.test.ts @@ -182,7 +182,7 @@ test('validate entry and throw errors', async () => { try { await buildAndGetResults({ fixturePath, - configPath: 'nonExistingFile.config.ts', + configPath: 'bundleNonExistingFile.config.ts', }); } catch (e) { errMsg = (e as AggregateError).errors.join('\n\n'); @@ -192,6 +192,19 @@ test('validate entry and throw errors', async () => { `"Error: Can't resolve the entry "./src/main.ts" at the location /tests/integration/entry/validate/src/main.ts. Please ensure that the file exists."`, ); + try { + await buildAndGetResults({ + fixturePath, + configPath: 'bundlelessNonExistingFile.config.ts', + }); + } catch (e) { + errMsg = (e as Error).message; + } + + expect(stripAnsi(errMsg)).toMatchInlineSnapshot( + `"No entry files matching ./src/non-existing-file.ts, ./non-existing-folder/**/*. Please ensure the entry pattern in source.entry is correct and points to valid source files."`, + ); + try { await buildAndGetResults({ fixturePath, diff --git a/tests/integration/entry/validate/nonExistingFile.config.ts b/tests/integration/entry/validate/bundleNonExistingFile.config.ts similarity index 100% rename from tests/integration/entry/validate/nonExistingFile.config.ts rename to tests/integration/entry/validate/bundleNonExistingFile.config.ts diff --git a/tests/integration/entry/validate/bundlelessNonExistingFile.config.ts b/tests/integration/entry/validate/bundlelessNonExistingFile.config.ts new file mode 100644 index 000000000..51aa2283e --- /dev/null +++ b/tests/integration/entry/validate/bundlelessNonExistingFile.config.ts @@ -0,0 +1,15 @@ +import { defineConfig } from '@rslib/core'; +import { generateBundleEsmConfig } from 'test-helper'; + +export default defineConfig({ + lib: [ + generateBundleEsmConfig({ + bundle: false, + source: { + entry: { + index: ['./src/non-existing-file.ts', './non-existing-folder/**/*'], + }, + }, + }), + ], +});