Skip to content

Commit f33db74

Browse files
committed
fix(dts): correct tsconfig path not found error message
1 parent befb09a commit f33db74

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

packages/plugin-dts/src/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { type ChildProcess, fork } from 'node:child_process';
22
import { dirname, extname, join } from 'node:path';
33
import { fileURLToPath } from 'node:url';
44
import { type RsbuildConfig, type RsbuildPlugin, logger } from '@rsbuild/core';
5+
import color from 'picocolors';
56
import ts from 'typescript';
67
import { loadTsconfig, processSourceEntry } from './utils';
78

@@ -88,7 +89,9 @@ export const pluginDts = (options: PluginDtsOptions = {}): RsbuildPlugin => ({
8889
);
8990

9091
if (!tsconfigPath) {
91-
logger.error(`tsconfig.json not found in ${cwd}`);
92+
logger.error(
93+
`Failed to resolve tsconfig file ${color.cyan(`"${config.source.tsconfigPath}"`)} from ${color.cyan(cwd)}. Please ensure that the file exists.`,
94+
);
9295
throw new Error();
9396
}
9497

pnpm-lock.yaml

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "dts-true-bundle-false-tsconfig-path-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}
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: false,
10+
},
11+
}),
12+
],
13+
source: {
14+
entry: {
15+
index: '../__fixtures__/src/index.ts',
16+
},
17+
tsconfigPath: '../path_not_exist/tsconfig.json',
18+
},
19+
});

tests/integration/dts/index.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { existsSync } from 'node:fs';
22
import { join } from 'node:path';
3+
import stripAnsi from 'strip-ansi';
34
import {
45
buildAndGetResults,
56
createTempFiles,
67
globContentJSON,
8+
proxyConsole,
79
} from 'test-helper';
810
import { describe, expect, test } from 'vitest';
911

@@ -145,6 +147,21 @@ describe('dts when bundle: false', () => {
145147
]
146148
`);
147149
});
150+
151+
test('should emit error when tsconfig not found', async () => {
152+
const fixturePath = join(__dirname, 'bundle-false', 'tsconfig-path');
153+
await createTempFiles(fixturePath, false);
154+
155+
const { logs, restore } = proxyConsole();
156+
try {
157+
await buildAndGetResults({ fixturePath, type: 'dts' });
158+
} catch (err: any) {
159+
expect(logs.map((log) => stripAnsi(log)).join('')).toMatchInlineSnapshot(
160+
`"error Failed to resolve tsconfig file "../path_not_exist/tsconfig.json" from <ROOT>/tests/integration/dts/bundle-false/tsconfig-path. Please ensure that the file exists."`,
161+
);
162+
}
163+
restore();
164+
});
148165
});
149166

150167
describe('dts when bundle: true', () => {

0 commit comments

Comments
 (0)