Skip to content

Commit e9d2133

Browse files
authored
fix: absolute entry when bundle DTS (#120)
1 parent 4e20196 commit e9d2133

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "dts-bundle-absolute-entry-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { join } from 'node:path';
2+
import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper';
3+
import { defineConfig } from '@rslib/core';
4+
5+
export default defineConfig({
6+
lib: [
7+
generateBundleEsmConfig({
8+
dts: {
9+
bundle: true,
10+
},
11+
}),
12+
generateBundleCjsConfig(),
13+
],
14+
source: {
15+
entry: {
16+
index: join(__dirname, '../__fixtures__/src/index.ts'),
17+
},
18+
tsconfigPath: '../__fixtures__/tsconfig.json',
19+
},
20+
});

e2e/cases/dts/index.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,13 @@ describe('dts when bundle: true', () => {
115115
`"<ROOT>/e2e/cases/dts/bundle/bundle-name/dist/esm/bundleName.d.ts"`,
116116
);
117117
});
118+
119+
test('entry is an absolute path', async () => {
120+
const fixturePath = join(__dirname, 'bundle', 'absolute-entry');
121+
const { entryFiles } = await buildAndGetResults(fixturePath, 'dts');
122+
123+
expect(entryFiles.esm).toMatchInlineSnapshot(
124+
`"<ROOT>/e2e/cases/dts/bundle/absolute-entry/dist/esm/index.d.ts"`,
125+
);
126+
});
118127
});

packages/plugin-dts/src/dts.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'node:fs';
2-
import { basename, dirname, join, relative } from 'node:path';
2+
import { basename, dirname, isAbsolute, join, relative } from 'node:path';
33
import { logger } from '@rsbuild/core';
44
import color from 'picocolors';
55
import ts from 'typescript';
@@ -141,7 +141,9 @@ export async function generateDts(data: DtsGenOptions): Promise<void> {
141141
let entry = '';
142142

143143
if (bundle === true && entryPath) {
144-
const entrySourcePath = join(cwd, entryPath);
144+
const entrySourcePath = isAbsolute(entryPath)
145+
? entryPath
146+
: join(cwd, entryPath);
145147
const relativePath = relative(rootDir, dirname(entrySourcePath));
146148
entry = join(
147149
declarationDir!,

0 commit comments

Comments
 (0)