@@ -4,7 +4,11 @@ import * as fs from 'fs-extra'
44import * as _ from 'lodash'
55import * as globby from 'globby'
66
7- import { ServerlessOptions , ServerlessInstance , ServerlessFunction } from './types'
7+ import {
8+ ServerlessOptions ,
9+ ServerlessInstance ,
10+ ServerlessFunction
11+ } from './types'
812import * as typescript from './typescript'
913
1014import { watchFiles } from './watchFiles'
@@ -14,7 +18,6 @@ const serverlessFolder = '.serverless'
1418const buildFolder = '.build'
1519
1620export class TypeScriptPlugin {
17-
1821 private originalServicePath : string
1922 private isWatching : boolean
2023
@@ -47,7 +50,9 @@ export class TypeScriptPlugin {
4750 const emitedFiles = await this . compileTs ( )
4851 if ( this . isWatching ) {
4952 emitedFiles . forEach ( filename => {
50- const module = require . resolve ( path . resolve ( this . originalServicePath , filename ) )
53+ const module = require . resolve (
54+ path . resolve ( this . originalServicePath , filename )
55+ )
5156 delete require . cache [ module ]
5257 } )
5358 }
@@ -63,12 +68,20 @@ export class TypeScriptPlugin {
6368
6469 get functions ( ) {
6570 return this . options . function
66- ? { [ this . options . function ] : this . serverless . service . functions [ this . options . function ] }
71+ ? {
72+ [ this . options . function ] : this . serverless . service . functions [
73+ this . options . function
74+ ]
75+ }
6776 : this . serverless . service . functions
6877 }
6978
7079 get rootFileNames ( ) {
71- return typescript . extractFileNames ( this . originalServicePath , this . serverless . service . provider . name , this . functions )
80+ return typescript . extractFileNames (
81+ this . originalServicePath ,
82+ this . serverless . service . provider . name ,
83+ this . functions
84+ )
7285 }
7386
7487 prepare ( ) {
@@ -78,10 +91,13 @@ export class TypeScriptPlugin {
7891 const fn = functions [ fnName ]
7992 fn . package = fn . package || {
8093 exclude : [ ] ,
81- include : [ ] ,
94+ include : [ ]
8295 }
8396 // Add plugin to excluded packages or an empty array if exclude is undefined
84- fn . package . exclude = _ . uniq ( [ ...fn . package . exclude || [ ] , 'node_modules/serverless-plugin-typescript' ] )
97+ fn . package . exclude = _ . uniq ( [
98+ ...( fn . package . exclude || [ ] ) ,
99+ 'node_modules/serverless-plugin-typescript'
100+ ] )
85101 }
86102 }
87103
@@ -119,7 +135,10 @@ export class TypeScriptPlugin {
119135 // Save original service path and functions
120136 this . originalServicePath = this . serverless . config . servicePath
121137 // Fake service path so that serverless will know what to zip
122- this . serverless . config . servicePath = path . join ( this . originalServicePath , buildFolder )
138+ this . serverless . config . servicePath = path . join (
139+ this . originalServicePath ,
140+ buildFolder
141+ )
123142 }
124143
125144 const tsconfig = typescript . getTypescriptConfig (
@@ -138,16 +157,25 @@ export class TypeScriptPlugin {
138157 async copyExtras ( ) {
139158 // include node_modules into build
140159 if ( ! fs . existsSync ( path . resolve ( path . join ( buildFolder , 'node_modules' ) ) ) ) {
141- fs . symlinkSync ( path . resolve ( 'node_modules' ) , path . resolve ( path . join ( buildFolder , 'node_modules' ) ) )
160+ fs . symlinkSync (
161+ path . resolve ( 'node_modules' ) ,
162+ path . resolve ( path . join ( buildFolder , 'node_modules' ) )
163+ )
142164 }
143165
144166 // include package.json into build so Serverless can exlcude devDeps during packaging
145167 if ( ! fs . existsSync ( path . resolve ( path . join ( buildFolder , 'package.json' ) ) ) ) {
146- fs . symlinkSync ( path . resolve ( 'package.json' ) , path . resolve ( path . join ( buildFolder , 'package.json' ) ) )
168+ fs . symlinkSync (
169+ path . resolve ( 'package.json' ) ,
170+ path . resolve ( path . join ( buildFolder , 'package.json' ) )
171+ )
147172 }
148173
149174 // include any "extras" from the "include" section
150- if ( this . serverless . service . package . include && this . serverless . service . package . include . length > 0 ) {
175+ if (
176+ this . serverless . service . package . include &&
177+ this . serverless . service . package . include . length > 0
178+ ) {
151179 const files = await globby ( this . serverless . service . package . include )
152180
153181 for ( const filename of files ) {
@@ -159,7 +187,10 @@ export class TypeScriptPlugin {
159187 }
160188
161189 if ( ! fs . existsSync ( destFileName ) ) {
162- fs . copySync ( path . resolve ( filename ) , path . resolve ( path . join ( buildFolder , filename ) ) )
190+ fs . copySync (
191+ path . resolve ( filename ) ,
192+ path . resolve ( path . join ( buildFolder , filename ) )
193+ )
163194 }
164195 }
165196 }
@@ -174,7 +205,7 @@ export class TypeScriptPlugin {
174205 if ( this . options . function ) {
175206 const fn = this . serverless . service . functions [ this . options . function ]
176207 const basename = path . basename ( fn . package . artifact )
177- fn . package . artifact = path . join (
208+ fn . package . artifact = path . join (
178209 this . originalServicePath ,
179210 serverlessFolder ,
180211 path . basename ( fn . package . artifact )
@@ -188,7 +219,9 @@ export class TypeScriptPlugin {
188219 this . serverless . service . functions [ name ] . package . artifact = path . join (
189220 this . originalServicePath ,
190221 serverlessFolder ,
191- path . basename ( this . serverless . service . functions [ name ] . package . artifact )
222+ path . basename (
223+ this . serverless . service . functions [ name ] . package . artifact
224+ )
192225 )
193226 } )
194227 return
@@ -199,6 +232,18 @@ export class TypeScriptPlugin {
199232 serverlessFolder ,
200233 path . basename ( this . serverless . service . package . artifact )
201234 )
235+
236+ this . serverless . service . getAllFunctions ( ) . forEach ( name => {
237+ if ( this . serverless . service . functions [ name ] . package . artifact ) {
238+ this . serverless . service . functions [ name ] . package . artifact = path . join (
239+ this . originalServicePath ,
240+ serverlessFolder ,
241+ path . basename (
242+ this . serverless . service . functions [ name ] . package . artifact
243+ )
244+ )
245+ }
246+ } )
202247 }
203248
204249 async cleanup ( ) : Promise < void > {
@@ -208,7 +253,6 @@ export class TypeScriptPlugin {
208253 // Remove temp build folder
209254 fs . removeSync ( path . join ( this . originalServicePath , buildFolder ) )
210255 }
211-
212256}
213257
214258module . exports = TypeScriptPlugin
0 commit comments