Skip to content

Commit 502c168

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

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-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

+16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
buildAndGetResults,
55
createTempFiles,
66
globContentJSON,
7+
proxyConsole,
78
} from 'test-helper';
89
import { describe, expect, test } from 'vitest';
910

@@ -145,6 +146,21 @@ describe('dts when bundle: false', () => {
145146
]
146147
`);
147148
});
149+
150+
test('should emit error when tsconfig not found', async () => {
151+
const fixturePath = join(__dirname, 'bundle-false', 'tsconfig-path');
152+
await createTempFiles(fixturePath, false);
153+
154+
const { logs, restore } = proxyConsole();
155+
try {
156+
await buildAndGetResults({ fixturePath, type: 'dts' });
157+
} catch (err: any) {
158+
expect(logs.join('')).toMatchInlineSnapshot(
159+
`"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."`,
160+
);
161+
}
162+
restore();
163+
});
148164
});
149165

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

0 commit comments

Comments
 (0)