Skip to content

Commit

Permalink
fix: absolute entry when bundle DTS (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
Timeless0911 authored Aug 21, 2024
1 parent 4e20196 commit e9d2133
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
6 changes: 6 additions & 0 deletions e2e/cases/dts/bundle/absolute-entry/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "dts-bundle-absolute-entry-test",
"version": "1.0.0",
"private": true,
"type": "module"
}
20 changes: 20 additions & 0 deletions e2e/cases/dts/bundle/absolute-entry/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { join } from 'node:path';
import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper';
import { defineConfig } from '@rslib/core';

export default defineConfig({
lib: [
generateBundleEsmConfig({
dts: {
bundle: true,
},
}),
generateBundleCjsConfig(),
],
source: {
entry: {
index: join(__dirname, '../__fixtures__/src/index.ts'),
},
tsconfigPath: '../__fixtures__/tsconfig.json',
},
});
9 changes: 9 additions & 0 deletions e2e/cases/dts/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,13 @@ describe('dts when bundle: true', () => {
`"<ROOT>/e2e/cases/dts/bundle/bundle-name/dist/esm/bundleName.d.ts"`,
);
});

test('entry is an absolute path', async () => {
const fixturePath = join(__dirname, 'bundle', 'absolute-entry');
const { entryFiles } = await buildAndGetResults(fixturePath, 'dts');

expect(entryFiles.esm).toMatchInlineSnapshot(
`"<ROOT>/e2e/cases/dts/bundle/absolute-entry/dist/esm/index.d.ts"`,
);
});
});
6 changes: 4 additions & 2 deletions packages/plugin-dts/src/dts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'node:fs';
import { basename, dirname, join, relative } from 'node:path';
import { basename, dirname, isAbsolute, join, relative } from 'node:path';
import { logger } from '@rsbuild/core';
import color from 'picocolors';
import ts from 'typescript';
Expand Down Expand Up @@ -141,7 +141,9 @@ export async function generateDts(data: DtsGenOptions): Promise<void> {
let entry = '';

if (bundle === true && entryPath) {
const entrySourcePath = join(cwd, entryPath);
const entrySourcePath = isAbsolute(entryPath)
? entryPath
: join(cwd, entryPath);
const relativePath = relative(rootDir, dirname(entrySourcePath));
entry = join(
declarationDir!,
Expand Down

0 comments on commit e9d2133

Please sign in to comment.