fix: respect paths in tsconfig.json in dts build

This commit is contained in:
EGOIST 2021-03-17 13:23:48 +08:00
parent 77bb2b4a65
commit 15ce73713b
2 changed files with 38 additions and 3 deletions

View File

@ -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 || [])],
},

View File

@ -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 };
"
`)
})