11"use strict" ;
2- var fs = require ( "fs" ) ;
2+ var __assign = ( this && this . __assign ) || Object . assign || function ( t ) {
3+ for ( var s , i = 1 , n = arguments . length ; i < n ; i ++ ) {
4+ s = arguments [ i ] ;
5+ for ( var p in s ) if ( Object . prototype . hasOwnProperty . call ( s , p ) )
6+ t [ p ] = s [ p ] ;
7+ }
8+ return t ;
9+ } ;
310var path = require ( "path" ) ;
411var _project = require ( "./project" ) ;
512var utils = require ( "./utils" ) ;
@@ -34,8 +41,7 @@ function getTypeScript(typescript) {
3441 throw new Error ( "TypeScript not installed" ) ;
3542 }
3643}
37- function getCompilerOptions ( settings , projectPath , configFileName ) {
38- var typescript = getTypeScript ( settings . typescript ) ;
44+ function checkAndNormalizeSettings ( settings ) {
3945 if ( settings . sourceRoot !== undefined ) {
4046 console . warn ( 'gulp-typescript: sourceRoot isn\'t supported any more. Use sourceRoot option of gulp-sourcemaps instead.' ) ;
4147 }
@@ -45,72 +51,74 @@ function getCompilerOptions(settings, projectPath, configFileName) {
4551 if ( settings . sortOutput !== undefined ) {
4652 utils . deprecate ( "sortOutput is deprecated" , "your project might work without it" , "The non-standard option sortOutput has been removed as of gulp-typescript 3.0.\nYour project will probably compile without this option.\nOtherwise, if you're using gulp-concat, you should remove gulp-concat and use the outFile option instead." ) ;
4753 }
48- // Copy settings and remove several options
49- var newSettings = { } ;
50- for ( var _i = 0 , _a = Object . keys ( settings ) ; _i < _a . length ; _i ++ ) {
51- var option = _a [ _i ] ;
52- if ( option === 'declarationFiles' ) {
53- newSettings . declaration = settings . declarationFiles ;
54- continue ;
55- }
56- if ( option === 'noExternalResolve' ||
57- option === 'sortOutput' ||
58- option === 'typescript' ||
59- option === 'sourceMap' ||
60- option === 'inlineSourceMap' ||
61- option === 'sourceRoot' ||
62- option === 'inlineSources' )
63- continue ;
64- newSettings [ option ] = settings [ option ] ;
54+ if ( settings . declarationFiles ) {
55+ settings . declaration = settings . declarationFiles ;
56+ delete settings . declarationFiles ;
6557 }
66- var result = typescript . convertCompilerOptionsFromJson ( newSettings , projectPath , configFileName ) ;
58+ delete settings . noExternalResolve ;
59+ delete settings . sortOutput ;
60+ delete settings . typescript ;
61+ delete settings . sourceMap ;
62+ delete settings . inlineSourceMap ;
63+ delete settings . sourceRoot ;
64+ delete settings . inlineSources ;
65+ }
66+ function normalizeCompilerOptions ( options ) {
67+ options . sourceMap = true ;
68+ options . suppressOutputPathCheck = true ;
69+ }
70+ function reportErrors ( errors , typescript ) {
6771 var reporter = _reporter . defaultReporter ( ) ;
68- for ( var _b = 0 , _c = result . errors ; _b < _c . length ; _b ++ ) {
69- var error = _c [ _b ] ;
72+ for ( var _i = 0 , errors_1 = errors ; _i < errors_1 . length ; _i ++ ) {
73+ var error = errors_1 [ _i ] ;
7074 reporter . error ( utils . getError ( error , typescript ) , typescript ) ;
7175 }
72- result . options . sourceMap = true ;
73- result . options . suppressOutputPathCheck = true ;
74- return result . options ;
7576}
7677( function ( compile ) {
7778 compile . reporter = _reporter ;
7879 function createProject ( fileNameOrSettings , settings ) {
7980 var tsConfigFileName = undefined ;
8081 var tsConfigContent = undefined ;
8182 var projectDirectory = process . cwd ( ) ;
83+ var typescript ;
84+ var compilerOptions ;
85+ var fileName ;
86+ settings = __assign ( { } , settings ) ; // Shallow copy the settings.
8287 if ( fileNameOrSettings !== undefined ) {
8388 if ( typeof fileNameOrSettings === 'string' ) {
89+ fileName = fileNameOrSettings ;
90+ }
91+ else {
92+ settings = fileNameOrSettings || { } ;
93+ }
94+ typescript = getTypeScript ( settings . typescript ) ;
95+ checkAndNormalizeSettings ( settings ) ;
96+ var settingsResult = typescript . convertCompilerOptionsFromJson ( settings , projectDirectory ) ;
97+ if ( settingsResult . errors ) {
98+ reportErrors ( settingsResult . errors , typescript ) ;
99+ }
100+ compilerOptions = settingsResult . options ;
101+ if ( fileName ) {
84102 tsConfigFileName = path . resolve ( process . cwd ( ) , fileNameOrSettings ) ;
85103 projectDirectory = path . dirname ( tsConfigFileName ) ;
86- // Load file and strip BOM, since JSON.parse fails to parse if there's a BOM present
87- var tsConfigText = fs . readFileSync ( tsConfigFileName ) . toString ( ) ;
88- var typescript = getTypeScript ( settings && settings . typescript ) ;
89- var tsConfig = typescript . parseConfigFileTextToJson ( tsConfigFileName , tsConfigText ) ;
90- tsConfigContent = tsConfig . config || { } ;
104+ var tsConfig = typescript . readConfigFile ( tsConfigFileName , typescript . sys . readFile ) ;
91105 if ( tsConfig . error ) {
92106 console . log ( tsConfig . error . messageText ) ;
93107 }
94- var newSettings = { } ;
95- if ( tsConfigContent . compilerOptions ) {
96- for ( var _i = 0 , _a = Object . keys ( tsConfigContent . compilerOptions ) ; _i < _a . length ; _i ++ ) {
97- var key = _a [ _i ] ;
98- newSettings [ key ] = tsConfigContent . compilerOptions [ key ] ;
99- }
100- }
101- if ( settings ) {
102- for ( var _b = 0 , _c = Object . keys ( settings ) ; _b < _c . length ; _b ++ ) {
103- var key = _c [ _b ] ;
104- newSettings [ key ] = settings [ key ] ;
105- }
108+ var parsed = tsConfig . config &&
109+ typescript . parseJsonConfigFileContent ( tsConfig . config , typescript . sys , path . resolve ( projectDirectory ) , settings , path . basename ( tsConfigFileName ) ) ;
110+ tsConfigContent = {
111+ compilerOptions : parsed . options ,
112+ files : parsed . fileNames ,
113+ } ;
114+ if ( parsed . errors ) {
115+ reportErrors ( parsed . errors , typescript ) ;
106116 }
107- settings = newSettings ;
108- }
109- else {
110- settings = fileNameOrSettings ;
117+ compilerOptions = parsed . options ;
111118 }
112119 }
113- var project = _project . setupProject ( projectDirectory , tsConfigContent , getCompilerOptions ( settings , projectDirectory , tsConfigFileName ) , getTypeScript ( settings . typescript ) ) ;
120+ normalizeCompilerOptions ( compilerOptions ) ;
121+ var project = _project . setupProject ( projectDirectory , tsConfigContent , compilerOptions , typescript ) ;
114122 return project ;
115123 }
116124 compile . createProject = createProject ;
0 commit comments