11import * as ts from 'typescript'
2- import * as fs from 'fs-extra'
2+ import * as fse from 'fs-extra'
33import * as _ from 'lodash'
44import * as path from 'path'
55
6+ import { ServerlessTSFunction , ServerlessTSInstance } from './serverlessTypes'
7+
68export const makeDefaultTypescriptConfig = ( ) : ts . CompilerOptions => {
79 const defaultTypescriptConfig : ts . CompilerOptions = {
810 preserveConstEnums : true ,
@@ -18,7 +20,7 @@ export const makeDefaultTypescriptConfig = (): ts.CompilerOptions => {
1820 return defaultTypescriptConfig
1921}
2022
21- export const extractFileNames = ( cwd : string , provider : string , functions ?: { [ key : string ] : Serverless . Function } ) : string [ ] => {
23+ export const extractFileNames = ( cwd : string , provider : string , functions ?: { [ key : string ] : ServerlessTSFunction } ) : string [ ] => {
2224 // The Google provider will use the entrypoint not from the definition of the
2325 // handler function, but instead from the package.json:main field, or via a
2426 // index.js file. This check reads the current package.json in the same way
@@ -27,17 +29,17 @@ export const extractFileNames = (cwd: string, provider: string, functions?: { [k
2729 // it instead selects the index.js file.
2830 if ( provider === 'google' ) {
2931 const packageFilePath = path . join ( cwd , 'package.json' )
30- if ( fs . existsSync ( packageFilePath ) ) {
32+ if ( fse . existsSync ( packageFilePath ) ) {
3133
3234 // Load in the package.json file.
33- const packageFile = JSON . parse ( fs . readFileSync ( packageFilePath ) . toString ( ) )
35+ const packageFile = JSON . parse ( fse . readFileSync ( packageFilePath ) . toString ( ) )
3436
3537 // Either grab the package.json:main field, or use the index.ts file.
3638 // (This will be transpiled to index.js).
3739 const main = packageFile . main ? packageFile . main . replace ( / \. j s $ / , '.ts' ) : 'index.ts'
3840
3941 // Check that the file indeed exists.
40- if ( ! fs . existsSync ( path . join ( cwd , main ) ) ) {
42+ if ( ! fse . existsSync ( path . join ( cwd , main ) ) ) {
4143 console . log ( `Cannot locate entrypoint, ${ main } not found` )
4244 throw new Error ( 'Typescript compilation failed' )
4345 }
@@ -55,12 +57,12 @@ export const extractFileNames = (cwd: string, provider: string, functions?: { [k
5557 const fileName = h . substring ( 0 , fnNameLastAppearanceIndex )
5658
5759 // Check if the .ts files exists. If so return that to watch
58- if ( fs . existsSync ( path . join ( cwd , fileName + 'ts' ) ) ) {
60+ if ( fse . existsSync ( path . join ( cwd , fileName + 'ts' ) ) ) {
5961 return fileName + 'ts'
6062 }
6163
6264 // Check if the .js files exists. If so return that to watch
63- if ( fs . existsSync ( path . join ( cwd , fileName + 'js' ) ) ) {
65+ if ( fse . existsSync ( path . join ( cwd , fileName + 'js' ) ) ) {
6466 return fileName + 'js'
6567 }
6668
@@ -112,21 +114,21 @@ export const getSourceFiles = (
112114
113115export const getTypescriptConfig = (
114116 cwd : string ,
115- serverless ?: Partial < Serverless . Instance > ,
117+ serverless ?: Partial < ServerlessTSInstance > ,
116118 logger ?: { log : ( str : string ) => void }
117119) : ts . CompilerOptions => {
118120 let configFilePath = path . join ( cwd , 'tsconfig.json' )
119121
120122 if ( serverless && serverless . service . custom && serverless . service . custom . typeScript && serverless . service . custom . typeScript . tsconfigFilePath ) {
121123 configFilePath = path . join ( cwd , serverless . service . custom . typeScript . tsconfigFilePath )
122- if ( ! fs . existsSync ( configFilePath ) ) {
124+ if ( ! fse . existsSync ( configFilePath ) ) {
123125 throw new Error ( `Custom Typescript Config File not found at "${ configFilePath } "` )
124126 }
125127 }
126128
127- if ( fs . existsSync ( configFilePath ) ) {
129+ if ( fse . existsSync ( configFilePath ) ) {
128130
129- const configFileText = fs . readFileSync ( configFilePath ) . toString ( )
131+ const configFileText = fse . readFileSync ( configFilePath ) . toString ( )
130132 const result = ts . parseConfigFileTextToJson ( configFilePath , configFileText )
131133 if ( result . error ) {
132134 throw new Error ( JSON . stringify ( result . error ) )
0 commit comments