@@ -449,9 +449,10 @@ function printDiagnostics(context, diagnostics) {
449449 } ) ;
450450}
451451
452- function getOptionsOverrides ( _a ) {
452+ function getOptionsOverrides ( _a , tsConfigJson ) {
453453 var useTsconfigDeclarationDir = _a . useTsconfigDeclarationDir ;
454- return __assign ( { module : typescript . ModuleKind . ES2015 , noEmitHelpers : true , importHelpers : true , noResolve : false , outDir : process . cwd ( ) } , ( useTsconfigDeclarationDir ? { } : { declarationDir : process . cwd ( ) } ) ) ;
454+ var declaration = lodash . get ( tsConfigJson , "compilerOptions.declaration" , false ) ;
455+ return __assign ( { module : typescript . ModuleKind . ES2015 , noEmitHelpers : true , importHelpers : true , noResolve : false , outDir : process . cwd ( ) } , ( ! declaration || useTsconfigDeclarationDir ? { } : { declarationDir : process . cwd ( ) } ) ) ;
455456}
456457
457458function parseTsConfig ( tsconfig , context , pluginOptions ) {
@@ -464,7 +465,7 @@ function parseTsConfig(tsconfig, context, pluginOptions) {
464465 printDiagnostics ( context , convertDiagnostic ( "config" , [ result . error ] ) ) ;
465466 throw new Error ( "failed to parse " + fileName ) ;
466467 }
467- return typescript . parseJsonConfigFileContent ( result . config , typescript . sys , path . dirname ( fileName ) , getOptionsOverrides ( pluginOptions ) , fileName ) ;
468+ return typescript . parseJsonConfigFileContent ( result . config , typescript . sys , path . dirname ( fileName ) , getOptionsOverrides ( pluginOptions , result . config ) , fileName ) ;
468469}
469470
470471// The injected id for helpers.
@@ -512,6 +513,7 @@ function typescript$1(options) {
512513 abortOnError : true ,
513514 rollupCommonJSResolveHack : false ,
514515 tsconfig : "tsconfig.json" ,
516+ useTsconfigDeclarationDir : false ,
515517 } ) ;
516518 return {
517519 options : function ( config ) {
@@ -629,14 +631,17 @@ function typescript$1(options) {
629631 var baseDeclarationDir = parsedConfig . options . outDir ;
630632 lodash . each ( declarations , function ( _a ) {
631633 var name = _a . name , text = _a . text , writeByteOrderMark = _a . writeByteOrderMark ;
634+ var writeToPath ;
632635 // If for some reason no 'dest' property exists or if 'useTsconfigDeclarationDir' is given in the plugin options,
633636 // use the path provided by Typescript's LanguageService.
634- if ( dest == null || pluginOptions . useTsconfigDeclarationDir )
635- return typescript . sys . writeFile ( name , text , writeByteOrderMark ) ;
636- // Otherwise, take the directory name from the path and make sure it is absolute.
637- var destDirname = path . dirname ( dest ) ;
638- var destDirectory = path . isAbsolute ( dest ) ? destDirname : path . join ( process . cwd ( ) , destDirname ) ;
639- var writeToPath = path . join ( destDirectory , path . relative ( baseDeclarationDir , name ) ) ;
637+ if ( ! dest || pluginOptions . useTsconfigDeclarationDir )
638+ writeToPath = name ;
639+ else {
640+ // Otherwise, take the directory name from the path and make sure it is absolute.
641+ var destDirname = path . dirname ( dest ) ;
642+ var destDirectory = path . isAbsolute ( dest ) ? destDirname : path . join ( process . cwd ( ) , destDirname ) ;
643+ writeToPath = path . join ( destDirectory , path . relative ( baseDeclarationDir , name ) ) ;
644+ }
640645 // Write the declaration file to disk.
641646 typescript . sys . writeFile ( writeToPath , text , writeByteOrderMark ) ;
642647 } ) ;
0 commit comments