diff --git a/src/rollup.ts b/src/rollup.ts index 4c4dea7..27d0d29 100644 --- a/src/rollup.ts +++ b/src/rollup.ts @@ -5,7 +5,7 @@ import dtsPlugin from 'rollup-plugin-dts' import hashbangPlugin from 'rollup-plugin-hashbang' import jsonPlugin from '@rollup/plugin-json' import { handleError } from './errors' -import { getDeps, removeFiles } from './utils' +import { getDeps, removeFiles, loadTsConfig } from './utils' import { TsResolveOptions, tsResolvePlugin } from './rollup/ts-resolve' type RollupConfig = { @@ -44,6 +44,8 @@ const getRollupConfig = async ( }, } + const tsconfig = await loadTsConfig(process.cwd()) + return { inputConfig: { input: dtsOptions.entry, @@ -62,7 +64,9 @@ const getRollupConfig = async ( tsResolveOptions && tsResolvePlugin(tsResolveOptions), hashbangPlugin(), jsonPlugin(), - dtsPlugin(), + dtsPlugin({ + compilerOptions: tsconfig.data?.compilerOptions, + }), ].filter(Boolean), external: [...deps, ...(options.external || [])], }, diff --git a/test/index.test.ts b/test/index.test.ts index e65e753..dae5f1a 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -580,7 +580,7 @@ test('onSuccess', async () => { }) test('support baseUrl and paths in tsconfig.json', async () => { - await run(getTestName(), { + const { getFileContent } = await run(getTestName(), { 'input.ts': `export * from '@/foo'`, 'foo.ts': `export const foo = 'foo'`, 'tsconfig.json': `{ @@ -590,4 +590,35 @@ test('support baseUrl and paths in tsconfig.json', async () => { } }`, }) + expect(await getFileContent('dist/input.js')).toMatchInlineSnapshot(` + "\\"use strict\\";Object.defineProperty(exports, \\"__esModule\\", {value: true});// foo.ts + var foo = \\"foo\\"; + + + exports.foo = foo; + " + `) +}) + +test('support baseUrl and paths in tsconfig.json in --dts build', async () => { + const { getFileContent } = await run( + getTestName(), + { + 'input.ts': `export * from '@/foo'`, + 'src/foo.ts': `export const foo = 'foo'`, + 'tsconfig.json': `{ + "compilerOptions": { + "baseUrl":".", + "paths":{"@/*": ["./src/*"]} + } + }`, + }, + { flags: ['--dts'] } + ) + expect(await getFileContent('dist/input.d.ts')).toMatchInlineSnapshot(` + "declare const foo = \\"foo\\"; + + export { foo }; + " + `) })