@@ -2,6 +2,7 @@ import * as ts from 'typescript'
2
2
import * as fs from 'fs-extra'
3
3
import * as _ from 'lodash'
4
4
import * as path from 'path'
5
+ import { log } from '@serverless/utils/log'
5
6
6
7
export function makeDefaultTypescriptConfig ( ) {
7
8
const defaultTypescriptConfig : ts . CompilerOptions = {
@@ -38,8 +39,7 @@ export function extractFileNames(cwd: string, provider: string, functions?: { [k
38
39
39
40
// Check that the file indeed exists.
40
41
if ( ! fs . existsSync ( path . join ( cwd , main ) ) ) {
41
- console . log ( `Cannot locate entrypoint, ${ main } not found` )
42
- throw new Error ( 'Typescript compilation failed' )
42
+ throw new Error ( `Typescript compilation failed: Cannot locate entrypoint, ${ main } not found` )
43
43
}
44
44
45
45
return [ main ]
@@ -65,8 +65,7 @@ export function extractFileNames(cwd: string, provider: string, functions?: { [k
65
65
}
66
66
67
67
// Can't find the files. Watch will have an exception anyway. So throw one with error.
68
- console . log ( `Cannot locate handler - ${ fileName } not found` )
69
- throw new Error ( 'Typescript compilation failed. Please ensure handlers exists with ext .ts or .js' )
68
+ throw new Error ( `Typescript compilation failed. Please ensure handlers exists with ext .ts or .js.\nCannot locate handler: ${ fileName } not found.` )
70
69
} )
71
70
}
72
71
@@ -80,15 +79,15 @@ export async function run(fileNames: string[], options: ts.CompilerOptions): Pro
80
79
81
80
allDiagnostics . forEach ( diagnostic => {
82
81
if ( ! diagnostic . file ) {
83
- console . log ( diagnostic )
82
+ log . verbose ( JSON . stringify ( diagnostic ) )
84
83
}
85
84
const { line, character} = diagnostic . file . getLineAndCharacterOfPosition ( diagnostic . start )
86
85
const message = ts . flattenDiagnosticMessageText ( diagnostic . messageText , '\n' )
87
- console . log ( `${ diagnostic . file . fileName } (${ line + 1 } ,${ character + 1 } ): ${ message } ` )
86
+ log . verbose ( `${ diagnostic . file . fileName } (${ line + 1 } ,${ character + 1 } ): ${ message } ` )
88
87
} )
89
88
90
89
if ( emitResult . emitSkipped ) {
91
- throw new Error ( 'Typescript compilation failed' )
90
+ throw new Error ( 'TypeScript compilation failed' )
92
91
}
93
92
94
93
return emitResult . emittedFiles . filter ( filename => filename . endsWith ( '.js' ) )
@@ -113,7 +112,7 @@ export function getSourceFiles(
113
112
export function getTypescriptConfig (
114
113
cwd : string ,
115
114
tsConfigFileLocation : string = 'tsconfig.json' ,
116
- logger ?: { log : ( str : string ) => void }
115
+ shouldLog ?: boolean
117
116
) : ts . CompilerOptions {
118
117
const configFilePath = path . join ( cwd , tsConfigFileLocation )
119
118
@@ -133,13 +132,13 @@ export function getTypescriptConfig(
133
132
throw new Error ( JSON . stringify ( configParseResult . errors ) )
134
133
}
135
134
136
- if ( logger ) {
137
- logger . log ( `Using local tsconfig.json - ${ tsConfigFileLocation } ` )
135
+ if ( shouldLog ) {
136
+ log . verbose ( `Using local tsconfig.json - ${ tsConfigFileLocation } ` )
138
137
}
139
138
140
139
// disallow overrriding rootDir
141
- if ( configParseResult . options . rootDir && path . resolve ( configParseResult . options . rootDir ) !== path . resolve ( cwd ) && logger ) {
142
- logger . log ( 'Warning : "rootDir" from local tsconfig.json is overriden ')
140
+ if ( configParseResult . options . rootDir && path . resolve ( configParseResult . options . rootDir ) !== path . resolve ( cwd ) && log ) {
141
+ log . warning ( 'Typescript : "rootDir" from local tsconfig.json is overridden ')
143
142
}
144
143
configParseResult . options . rootDir = cwd
145
144
0 commit comments