1- import { mergeObjects , resolve , tryGetPackageInfo , tryGetPkgPath } from './utils'
1+ import { ensureAbsolute , mergeObjects , resolve , tryGetPackageInfo , tryGetPkgPath } from './utils'
22
3- import type { ExtractorLogLevel , IExtractorInvokeOptions } from '@microsoft/api-extractor'
3+ import type { ExtractorLogLevel , IConfigFile , IExtractorInvokeOptions } from '@microsoft/api-extractor'
44import type { BundleConfig } from './types'
55
66export interface BundleDtsOptions {
77 root : string ,
88 configPath ?: string ,
9+ tsconfigPath ?: string ,
910 compilerOptions : Record < string , any > ,
1011 outDir : string ,
1112 entryPath : string ,
@@ -27,6 +28,7 @@ const dtsRE = /\.d\.(m|c)?tsx?$/
2728export async function bundleDtsFiles ( {
2829 root,
2930 configPath,
31+ tsconfigPath,
3032 compilerOptions,
3133 outDir,
3234 entryPath,
@@ -38,7 +40,8 @@ export async function bundleDtsFiles({
3840} : BundleDtsOptions ) {
3941 const { Extractor, ExtractorConfig } = await import ( '@microsoft/api-extractor' )
4042
41- const configObjectFullPath = resolve ( root , 'api-extractor.json' )
43+ configPath = configPath ? ensureAbsolute ( configPath , root ) : ''
44+ const configObjectFullPath = configPath || resolve ( root , 'api-extractor.json' )
4245
4346 if ( ! dtsRE . test ( fileName ) ) {
4447 fileName += '.d.ts'
@@ -49,12 +52,12 @@ export async function bundleDtsFiles({
4952 compilerOptions = { ...compilerOptions , module : 'ESNext' }
5053 }
5154
52- const configObject = mergeObjects ( {
55+ const configObject : IConfigFile = {
5356 bundledPackages,
5457 projectFolder : root ,
5558 mainEntryPointFilePath : entryPath ,
5659 compiler : {
57- tsconfigFilePath : configPath ,
60+ tsconfigFilePath : tsconfigPath ,
5861 overrideTsconfig : {
5962 $schema : 'http://json.schemastore.org/tsconfig' ,
6063 compilerOptions,
@@ -86,7 +89,15 @@ export async function bundleDtsFiles({
8689 } ,
8790 } ,
8891 } ,
89- } , extractorConfig )
92+ }
93+
94+ if ( configPath ) {
95+ mergeObjects ( configObject , ExtractorConfig . loadFile ( configPath ) )
96+ }
97+
98+ if ( Object . keys ( extractorConfig ) . length ) {
99+ mergeObjects ( configObject , extractorConfig )
100+ }
90101
91102 const config = ExtractorConfig . prepare ( {
92103 configObject,
0 commit comments