mirror of
https://github.com/egoist/tsup.git
synced 2025-12-08 20:35:58 +00:00
fix: respect paths in tsconfig.json in dts build
This commit is contained in:
parent
77bb2b4a65
commit
15ce73713b
@ -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 || [])],
|
||||
},
|
||||
|
||||
@ -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 };
|
||||
"
|
||||
`)
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user