@@ -4,7 +4,11 @@ import * as fs from 'fs-extra'
4
4
import * as _ from 'lodash'
5
5
import * as globby from 'globby'
6
6
7
- import { ServerlessOptions , ServerlessInstance , ServerlessFunction } from './types'
7
+ import {
8
+ ServerlessOptions ,
9
+ ServerlessInstance ,
10
+ ServerlessFunction
11
+ } from './types'
8
12
import * as typescript from './typescript'
9
13
10
14
import { watchFiles } from './watchFiles'
@@ -14,7 +18,6 @@ const serverlessFolder = '.serverless'
14
18
const buildFolder = '.build'
15
19
16
20
export class TypeScriptPlugin {
17
-
18
21
private originalServicePath : string
19
22
private isWatching : boolean
20
23
@@ -47,7 +50,9 @@ export class TypeScriptPlugin {
47
50
const emitedFiles = await this . compileTs ( )
48
51
if ( this . isWatching ) {
49
52
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
+ )
51
56
delete require . cache [ module ]
52
57
} )
53
58
}
@@ -63,12 +68,20 @@ export class TypeScriptPlugin {
63
68
64
69
get functions ( ) {
65
70
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
+ }
67
76
: this . serverless . service . functions
68
77
}
69
78
70
79
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
+ )
72
85
}
73
86
74
87
prepare ( ) {
@@ -78,10 +91,13 @@ export class TypeScriptPlugin {
78
91
const fn = functions [ fnName ]
79
92
fn . package = fn . package || {
80
93
exclude : [ ] ,
81
- include : [ ] ,
94
+ include : [ ]
82
95
}
83
96
// 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
+ ] )
85
101
}
86
102
}
87
103
@@ -119,7 +135,10 @@ export class TypeScriptPlugin {
119
135
// Save original service path and functions
120
136
this . originalServicePath = this . serverless . config . servicePath
121
137
// 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
+ )
123
142
}
124
143
125
144
const tsconfig = typescript . getTypescriptConfig (
@@ -138,16 +157,25 @@ export class TypeScriptPlugin {
138
157
async copyExtras ( ) {
139
158
// include node_modules into build
140
159
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
+ )
142
164
}
143
165
144
166
// include package.json into build so Serverless can exlcude devDeps during packaging
145
167
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
+ )
147
172
}
148
173
149
174
// 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
+ ) {
151
179
const files = await globby ( this . serverless . service . package . include )
152
180
153
181
for ( const filename of files ) {
@@ -159,7 +187,10 @@ export class TypeScriptPlugin {
159
187
}
160
188
161
189
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
+ )
163
194
}
164
195
}
165
196
}
@@ -174,7 +205,7 @@ export class TypeScriptPlugin {
174
205
if ( this . options . function ) {
175
206
const fn = this . serverless . service . functions [ this . options . function ]
176
207
const basename = path . basename ( fn . package . artifact )
177
- fn . package . artifact = path . join (
208
+ fn . package . artifact = path . join (
178
209
this . originalServicePath ,
179
210
serverlessFolder ,
180
211
path . basename ( fn . package . artifact )
@@ -188,7 +219,9 @@ export class TypeScriptPlugin {
188
219
this . serverless . service . functions [ name ] . package . artifact = path . join (
189
220
this . originalServicePath ,
190
221
serverlessFolder ,
191
- path . basename ( this . serverless . service . functions [ name ] . package . artifact )
222
+ path . basename (
223
+ this . serverless . service . functions [ name ] . package . artifact
224
+ )
192
225
)
193
226
} )
194
227
return
@@ -199,6 +232,18 @@ export class TypeScriptPlugin {
199
232
serverlessFolder ,
200
233
path . basename ( this . serverless . service . package . artifact )
201
234
)
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
+ } )
202
247
}
203
248
204
249
async cleanup ( ) : Promise < void > {
@@ -208,7 +253,6 @@ export class TypeScriptPlugin {
208
253
// Remove temp build folder
209
254
fs . removeSync ( path . join ( this . originalServicePath , buildFolder ) )
210
255
}
211
-
212
256
}
213
257
214
258
module . exports = TypeScriptPlugin
0 commit comments