@@ -92,8 +92,9 @@ export interface IExtractorConfigPrepareOptions {
9292interface IExtractorConfigParameters {
9393 projectFolder : string ;
9494 packageJson : INodePackageJson | undefined ;
95- packageJsonFullPath : string | undefined ;
95+ packageFolder : string | undefined ;
9696 mainEntryPointFile : string ;
97+ tsconfigFilePath : string ;
9798 overrideTsconfig : { } | undefined ;
9899 skipLibCheck : boolean ;
99100 apiReportEnabled : boolean ;
@@ -142,14 +143,17 @@ export class ExtractorConfig {
142143 public readonly packageJson : INodePackageJson | undefined ;
143144
144145 /**
145- * The absolute path of the file that package.json was loaded from , or undefined if API Extractor was invoked without
146- * a package.json file.
146+ * The absolute path of the folder containing the package.json file for the working package , or undefined
147+ * if API Extractor was invoked without a package.json file.
147148 */
148- public readonly packageJsonFullPath : string | undefined ;
149+ public readonly packageFolder : string | undefined ;
149150
150151 /** {@inheritDoc IConfigFile.mainEntryPointFile } */
151152 public readonly mainEntryPointFile : string ;
152153
154+ /** {@inheritDoc IConfigCompiler.tsconfigFilePath } */
155+ public readonly tsconfigFilePath : string ;
156+
153157 /** {@inheritDoc IConfigCompiler.overrideTsconfig } */
154158 public readonly overrideTsconfig : { } | undefined ;
155159
@@ -192,8 +196,9 @@ export class ExtractorConfig {
192196 private constructor ( parameters : IExtractorConfigParameters ) {
193197 this . projectFolder = parameters . projectFolder ;
194198 this . packageJson = parameters . packageJson ;
195- this . packageJsonFullPath = parameters . packageJsonFullPath ;
199+ this . packageFolder = parameters . packageFolder ;
196200 this . mainEntryPointFile = parameters . mainEntryPointFile ;
201+ this . tsconfigFilePath = parameters . tsconfigFilePath ;
197202 this . overrideTsconfig = parameters . overrideTsconfig ;
198203 this . skipLibCheck = parameters . skipLibCheck ;
199204 this . apiReportEnabled = parameters . apiReportEnabled ;
@@ -270,8 +275,8 @@ export class ExtractorConfig {
270275 do {
271276 // Check if this file was already processed.
272277 if ( visitedPaths . has ( currentConfigFilePath ) ) {
273- throw new Error ( `The API Extractor config files contain a cycle. " ${ currentConfigFilePath } " `
274- + ` is included twice. Please check the "extends" values in config files. ` ) ;
278+ throw new Error ( `The API Extractor "extends" setting contains a cycle.`
279+ + ` This file is included twice: " ${ currentConfigFilePath } " ` ) ;
275280 }
276281 visitedPaths . add ( currentConfigFilePath ) ;
277282
@@ -342,6 +347,13 @@ export class ExtractorConfig {
342347 'mainEntryPointFile' , configFile . mainEntryPointFile , currentConfigFolderPath ) ;
343348 }
344349
350+ if ( configFile . compiler ) {
351+ if ( configFile . compiler . tsconfigFilePath ) {
352+ configFile . compiler . tsconfigFilePath = ExtractorConfig . _resolveConfigFileRelativePath (
353+ 'tsconfigFilePath' , configFile . compiler . tsconfigFilePath , currentConfigFolderPath ) ;
354+ }
355+ }
356+
345357 if ( configFile . apiReport ) {
346358 if ( configFile . apiReport . reportFolder ) {
347359 configFile . apiReport . reportFolder = ExtractorConfig . _resolveConfigFileRelativePath (
@@ -412,27 +424,31 @@ export class ExtractorConfig {
412424
413425 if ( options . configObjectFullPath ) {
414426 if ( ! path . isAbsolute ( options . configObjectFullPath ) ) {
415- throw new Error ( 'configObjectFullPath must be an absolute path' ) ;
427+ throw new Error ( 'The " configObjectFullPath" setting must be an absolute path' ) ;
416428 }
417429 }
418430
419431 ExtractorConfig . jsonSchema . validateObject ( configObject , filenameForErrors ) ;
420432
421- let packageJson : INodePackageJson | undefined = undefined ;
422433 const packageJsonFullPath : string | undefined = options . packageJsonFullPath ;
434+ let packageFolder : string | undefined = undefined ;
435+ let packageJson : INodePackageJson | undefined = undefined ;
436+
423437 if ( packageJsonFullPath ) {
424438 if ( ! / .j s o n $ / i. test ( packageJsonFullPath ) ) {
425439 // Catch common mistakes e.g. where someone passes a folder path instead of a file path
426- throw new Error ( 'The packageJsonFullPath does not have a .json file extension' ) ;
440+ throw new Error ( 'The " packageJsonFullPath" setting does not have a .json file extension' ) ;
427441 }
428442 if ( ! path . isAbsolute ( packageJsonFullPath ) ) {
429- throw new Error ( 'packageJsonFullPath must be an absolute path' ) ;
443+ throw new Error ( 'The " packageJsonFullPath" setting must be an absolute path' ) ;
430444 }
431445
432446 if ( ! options . packageJson ) {
433447 const packageJsonLookup : PackageJsonLookup = new PackageJsonLookup ( ) ;
434448 packageJson = packageJsonLookup . loadNodePackageJson ( packageJsonFullPath ) ;
435449 }
450+
451+ packageFolder = path . dirname ( packageJsonFullPath ) ;
436452 }
437453
438454 try {
@@ -444,14 +460,16 @@ export class ExtractorConfig {
444460
445461 if ( ! configObject . projectFolder ) {
446462 // A merged configuration should have this
447- throw new Error ( 'The "projectFolder" field is missing' ) ;
463+ throw new Error ( 'The "projectFolder" setting is missing' ) ;
448464 }
449465
450466 let projectFolder : string ;
451467 if ( configObject . projectFolder . trim ( ) === '<lookup>' ) {
452468 if ( ! options . configObjectFullPath ) {
453- throw new Error ( 'The "<lookup>" token cannot be expanded because configObjectFullPath was not specified' ) ;
469+ throw new Error ( 'The "projectFolder" setting uses the "<lookup>" token, but it cannot be expanded because'
470+ + ' the "configObjectFullPath" setting was not specified' ) ;
454471 }
472+
455473 // "The default value for `projectFolder` is the token `<lookup>`, which means the folder is determined
456474 // by traversing parent folders, starting from the folder containing api-extractor.json, and stopping
457475 // at the first folder that contains a tsconfig.json file. If a tsconfig.json file cannot be found in
@@ -466,7 +484,7 @@ export class ExtractorConfig {
466484 }
467485 const parentFolder : string = path . dirname ( currentFolder ) ;
468486 if ( parentFolder === '' || parentFolder === currentFolder ) {
469- throw new Error ( 'The projectFolder was set to "<lookup>", but a tsconfig.json file cannot be'
487+ throw new Error ( 'The " projectFolder" setting uses the "<lookup>" token , but a tsconfig.json file cannot be'
470488 + ' found in this folder or any parent folder.' ) ;
471489 }
472490 currentFolder = parentFolder ;
@@ -475,7 +493,7 @@ export class ExtractorConfig {
475493 ExtractorConfig . _rejectAnyTokensInPath ( configObject . projectFolder , 'projectFolder' ) ;
476494
477495 if ( ! FileSystem . exists ( configObject . projectFolder ) ) {
478- throw new Error ( 'The specified projectFolder does not exist: ' + configObject . projectFolder ) ;
496+ throw new Error ( 'The specified " projectFolder" path does not exist: ' + configObject . projectFolder ) ;
479497 }
480498
481499 projectFolder = configObject . projectFolder ;
@@ -494,17 +512,29 @@ export class ExtractorConfig {
494512
495513 if ( ! configObject . mainEntryPointFile ) {
496514 // A merged configuration should have this
497- throw new Error ( 'mainEntryPointFile is missing' ) ;
515+ throw new Error ( 'The " mainEntryPointFile" setting is missing' ) ;
498516 }
499517 const mainEntryPointFile : string = ExtractorConfig . _resolvePathWithTokens ( 'mainEntryPointFile' ,
500518 configObject . mainEntryPointFile , tokenContext ) ;
501519
502520 if ( ! ExtractorConfig . hasDtsFileExtension ( mainEntryPointFile ) ) {
503- throw new Error ( 'The mainEntryPointFile is not a declaration file: ' + mainEntryPointFile ) ;
521+ throw new Error ( 'The " mainEntryPointFile" value is not a declaration file: ' + mainEntryPointFile ) ;
504522 }
505523
506524 if ( ! FileSystem . exists ( mainEntryPointFile ) ) {
507- throw new Error ( 'The mainEntryPointFile does not exist: ' + mainEntryPointFile ) ;
525+ throw new Error ( 'The "mainEntryPointFile" path does not exist: ' + mainEntryPointFile ) ;
526+ }
527+
528+ const tsconfigFilePath : string = ExtractorConfig . _resolvePathWithTokens ( 'tsconfigFilePath' ,
529+ configObject . compiler . tsconfigFilePath , tokenContext ) ;
530+
531+ if ( configObject . compiler . overrideTsconfig === undefined ) {
532+ if ( ! tsconfigFilePath ) {
533+ throw new Error ( 'Either the "tsconfigFilePath" or "overrideTsconfig" setting must be specified' ) ;
534+ }
535+ if ( ! FileSystem . exists ( tsconfigFilePath ) ) {
536+ throw new Error ( 'The file referenced by "tsconfigFilePath" does not exist: ' + tsconfigFilePath ) ;
537+ }
508538 }
509539
510540 let apiReportEnabled : boolean = false ;
@@ -518,11 +548,11 @@ export class ExtractorConfig {
518548
519549 if ( ! reportFilename ) {
520550 // A merged configuration should have this
521- throw new Error ( 'reportFilename is missing' ) ;
551+ throw new Error ( 'The " reportFilename" setting is missing' ) ;
522552 }
523553 if ( reportFilename . indexOf ( '/' ) >= 0 || reportFilename . indexOf ( '\\' ) >= 0 ) {
524554 // A merged configuration should have this
525- throw new Error ( `The reportFilename contains invalid characters: "${ reportFilename } "` ) ;
555+ throw new Error ( `The " reportFilename" setting contains invalid characters: "${ reportFilename } "` ) ;
526556 }
527557
528558 const reportFolder : string = ExtractorConfig . _resolvePathWithTokens ( 'reportFolder' ,
@@ -552,11 +582,11 @@ export class ExtractorConfig {
552582
553583 if ( tsdocMetadataFilePath . trim ( ) === '<lookup>' ) {
554584 if ( ! packageJson ) {
555- throw new Error ( 'The "<lookup>" token cannot be used with compiler.projectFolder because'
556- + 'the "packageJson" option was not provided' ) ;
585+ throw new Error ( 'The "<lookup>" token cannot be used with the "tsdocMetadataFilePath" setting because'
586+ + ' the "packageJson" option was not provided' ) ;
557587 }
558588 if ( ! packageJsonFullPath ) {
559- throw new Error ( 'The "<lookup>" token cannot be used with compiler.projectFolder because'
589+ throw new Error ( 'The "<lookup>" token cannot be used with "tsdocMetadataFilePath" because'
560590 + 'the "packageJsonFullPath" option was not provided' ) ;
561591 }
562592 tsdocMetadataFilePath = PackageMetadataManager . resolveTsdocMetadataPath (
@@ -569,7 +599,8 @@ export class ExtractorConfig {
569599 }
570600
571601 if ( ! tsdocMetadataFilePath ) {
572- throw new Error ( 'The tsdocMetadata.enabled was specified, but tsdocMetadataFilePath is not specified' ) ;
602+ throw new Error ( 'The "tsdocMetadata.enabled" setting is enabled,'
603+ + ' but "tsdocMetadataFilePath" is not specified' ) ;
573604 }
574605 }
575606 }
@@ -592,8 +623,9 @@ export class ExtractorConfig {
592623 return new ExtractorConfig ( {
593624 projectFolder : projectFolder ,
594625 packageJson,
595- packageJsonFullPath ,
626+ packageFolder ,
596627 mainEntryPointFile,
628+ tsconfigFilePath,
597629 overrideTsconfig : configObject . compiler . overrideTsconfig ,
598630 skipLibCheck : ! ! configObject . compiler . skipLibCheck ,
599631 apiReportEnabled,
@@ -641,12 +673,12 @@ export class ExtractorConfig {
641673
642674 if ( value . indexOf ( projectFolderToken ) >= 0 ) {
643675 // If after all replacements, "<projectFolder>" appears somewhere in the string, report an error
644- throw new Error ( `The ${ fieldName } value incorrectly uses the "<projectFolder>" token.`
676+ throw new Error ( `The " ${ fieldName } " value incorrectly uses the "<projectFolder>" token.`
645677 + ` It must appear at the start of the string.` ) ;
646678 }
647679
648680 if ( value . indexOf ( '<lookup>' ) >= 0 ) {
649- throw new Error ( `The ${ fieldName } value incorrectly uses the "<lookup>" token` ) ;
681+ throw new Error ( `The " ${ fieldName } " value incorrectly uses the "<lookup>" token` ) ;
650682 }
651683 ExtractorConfig . _rejectAnyTokensInPath ( value , fieldName ) ;
652684 }
@@ -673,8 +705,8 @@ export class ExtractorConfig {
673705 const tokenRegExp : RegExp = / ( \< [ ^ < ] * ?\> ) / ;
674706 const match : RegExpExecArray | null = tokenRegExp . exec ( value ) ;
675707 if ( match ) {
676- throw new Error ( `The ${ fieldName } value contains an unrecognized token "${ match [ 1 ] } "` ) ;
708+ throw new Error ( `The " ${ fieldName } " value contains an unrecognized token "${ match [ 1 ] } "` ) ;
677709 }
678- throw new Error ( `The ${ fieldName } value contains extra token characters ("<" or ">"): ${ value } ` ) ;
710+ throw new Error ( `The " ${ fieldName } " value contains extra token characters ("<" or ">"): ${ value } ` ) ;
679711 }
680712}
0 commit comments