Skip to content

Commit

Permalink
fix(dts): correct tsconfig path not found error message (#740)
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework authored Feb 7, 2025
1 parent 5dafcdc commit e7ed714
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/plugin-dts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type ChildProcess, fork } from 'node:child_process';
import { dirname, extname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { type RsbuildConfig, type RsbuildPlugin, logger } from '@rsbuild/core';
import color from 'picocolors';
import ts from 'typescript';
import { loadTsconfig, processSourceEntry } from './utils';

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

if (!tsconfigPath) {
logger.error(`tsconfig.json not found in ${cwd}`);
logger.error(
`Failed to resolve tsconfig file ${color.cyan(`"${config.source.tsconfigPath}"`)} from ${color.cyan(cwd)}. Please ensure that the file exists.`,
);
throw new Error();
}

Expand Down
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tests/integration/dts/bundle-false/tsconfig-path/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "dts-true-bundle-false-tsconfig-path-test",
"version": "1.0.0",
"private": true,
"type": "module"
}
19 changes: 19 additions & 0 deletions tests/integration/dts/bundle-false/tsconfig-path/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { defineConfig } from '@rslib/core';
import { generateBundleEsmConfig } from 'test-helper';

export default defineConfig({
lib: [
generateBundleEsmConfig({
bundle: false,
dts: {
bundle: false,
},
}),
],
source: {
entry: {
index: '../__fixtures__/src/index.ts',
},
tsconfigPath: '../path_not_exist/tsconfig.json',
},
});
17 changes: 17 additions & 0 deletions tests/integration/dts/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { existsSync } from 'node:fs';
import { join } from 'node:path';
import stripAnsi from 'strip-ansi';
import {
buildAndGetResults,
createTempFiles,
globContentJSON,
proxyConsole,
} from 'test-helper';
import { describe, expect, test } from 'vitest';

Expand Down Expand Up @@ -145,6 +147,21 @@ describe('dts when bundle: false', () => {
]
`);
});

test('should emit error when tsconfig not found', async () => {
const fixturePath = join(__dirname, 'bundle-false', 'tsconfig-path');
await createTempFiles(fixturePath, false);

const { logs, restore } = proxyConsole();
try {
await buildAndGetResults({ fixturePath, type: 'dts' });
} catch (err: any) {
expect(logs.map((log) => stripAnsi(log)).join('')).toMatchInlineSnapshot(
`"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."`,
);
}
restore();
});
});

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

0 comments on commit e7ed714

Please sign in to comment.