@@ -60,8 +60,10 @@ export class TypeScriptPlugin {
60
60
await this . copyExtras ( )
61
61
await this . copyDependencies ( )
62
62
if ( this . isWatching ) {
63
- emitedFiles . forEach ( filename => {
64
- const module = require . resolve ( path . resolve ( this . originalServicePath , filename ) )
63
+ emitedFiles . forEach ( ( filename ) => {
64
+ const module = require . resolve (
65
+ path . resolve ( this . originalServicePath , filename )
66
+ )
65
67
delete require . cache [ module ]
66
68
} )
67
69
}
@@ -71,7 +73,7 @@ export class TypeScriptPlugin {
71
73
this . watchFunction ( )
72
74
this . serverless . cli . log ( 'Waiting for changes...' )
73
75
}
74
- }
76
+ } ,
75
77
}
76
78
}
77
79
@@ -81,7 +83,7 @@ export class TypeScriptPlugin {
81
83
82
84
if ( options . function ) {
83
85
return {
84
- [ options . function ] : service . functions [ this . options . function ]
86
+ [ options . function ] : service . functions [ this . options . function ] ,
85
87
}
86
88
}
87
89
@@ -103,11 +105,14 @@ export class TypeScriptPlugin {
103
105
fn . package = fn . package || {
104
106
exclude : [ ] ,
105
107
include : [ ] ,
106
- patterns : [ ]
108
+ patterns : [ ] ,
107
109
}
108
110
109
111
// Add plugin to excluded packages or an empty array if exclude is undefined
110
- fn . package . exclude = _ . uniq ( [ ...fn . package . exclude || [ ] , 'node_modules/serverless-plugin-typescript' ] )
112
+ fn . package . exclude = _ . uniq ( [
113
+ ...( fn . package . exclude || [ ] ) ,
114
+ 'node_modules/serverless-plugin-typescript' ,
115
+ ] )
111
116
}
112
117
}
113
118
@@ -132,7 +137,11 @@ export class TypeScriptPlugin {
132
137
this . serverless . cli . log ( `Watching typescript files...` )
133
138
134
139
this . isWatching = true
135
- watchFiles ( this . rootFileNames , this . originalServicePath , this . compileTs . bind ( this ) )
140
+ watchFiles (
141
+ this . rootFileNames ,
142
+ this . originalServicePath ,
143
+ this . compileTs . bind ( this )
144
+ )
136
145
}
137
146
138
147
async compileTs ( ) : Promise < string [ ] > {
@@ -143,14 +152,19 @@ export class TypeScriptPlugin {
143
152
// Save original service path and functions
144
153
this . originalServicePath = this . serverless . config . servicePath
145
154
// Fake service path so that serverless will know what to zip
146
- this . serverless . config . servicePath = path . join ( this . originalServicePath , BUILD_FOLDER )
155
+ this . serverless . config . servicePath = path . join (
156
+ this . originalServicePath ,
157
+ BUILD_FOLDER
158
+ )
147
159
}
148
160
let tsConfigFileLocation : string | undefined
149
161
if (
150
- this . serverless . service . custom !== undefined
151
- && this . serverless . service . custom . serverlessPluginTypescript !== undefined
162
+ this . serverless . service . custom !== undefined &&
163
+ this . serverless . service . custom . serverlessPluginTypescript !== undefined
152
164
) {
153
- tsConfigFileLocation = this . serverless . service . custom . serverlessPluginTypescript . tsConfigFileLocation
165
+ tsConfigFileLocation =
166
+ this . serverless . service . custom . serverlessPluginTypescript
167
+ . tsConfigFileLocation
154
168
}
155
169
const tsconfig = typescript . getTypescriptConfig (
156
170
this . originalServicePath ,
@@ -169,7 +183,10 @@ export class TypeScriptPlugin {
169
183
async copyExtras ( ) {
170
184
const { service } = this . serverless
171
185
172
- const patterns = [ ...( service . package . include || [ ] ) , ...( service . package . patterns || [ ] ) ]
186
+ const patterns = [
187
+ ...( service . package . include || [ ] ) ,
188
+ ...( service . package . patterns || [ ] ) ,
189
+ ]
173
190
// include any "extras" from the "include" section
174
191
if ( patterns . length > 0 ) {
175
192
const files = await globby ( patterns )
@@ -183,7 +200,10 @@ export class TypeScriptPlugin {
183
200
}
184
201
185
202
if ( ! fs . existsSync ( destFileName ) ) {
186
- fs . copySync ( path . resolve ( filename ) , path . resolve ( path . join ( BUILD_FOLDER , filename ) ) )
203
+ fs . copySync (
204
+ path . resolve ( filename ) ,
205
+ path . resolve ( path . join ( BUILD_FOLDER , filename ) )
206
+ )
187
207
}
188
208
}
189
209
}
@@ -196,12 +216,14 @@ export class TypeScriptPlugin {
196
216
*/
197
217
async copyDependencies ( isPackaging = false ) {
198
218
const outPkgPath = path . resolve ( path . join ( BUILD_FOLDER , 'package.json' ) )
199
- const outModulesPath = path . resolve ( path . join ( BUILD_FOLDER , 'node_modules' ) )
219
+ const outModulesPath = path . resolve (
220
+ path . join ( BUILD_FOLDER , 'node_modules' )
221
+ )
200
222
201
223
// copy development dependencies during packaging
202
224
if ( isPackaging ) {
203
225
if ( fs . existsSync ( outModulesPath ) ) {
204
- fs . unlinkSync ( outModulesPath )
226
+ fs . removeSync ( outModulesPath )
205
227
}
206
228
207
229
fs . copySync (
@@ -210,7 +232,11 @@ export class TypeScriptPlugin {
210
232
)
211
233
} else {
212
234
if ( ! fs . existsSync ( outModulesPath ) ) {
213
- await this . linkOrCopy ( path . resolve ( 'node_modules' ) , outModulesPath , 'junction' )
235
+ await this . linkOrCopy (
236
+ path . resolve ( 'node_modules' ) ,
237
+ outModulesPath ,
238
+ 'junction'
239
+ )
214
240
}
215
241
}
216
242
@@ -244,7 +270,7 @@ export class TypeScriptPlugin {
244
270
245
271
if ( service . package . individually ) {
246
272
const functionNames = service . getAllFunctions ( )
247
- functionNames . forEach ( name => {
273
+ functionNames . forEach ( ( name ) => {
248
274
service . functions [ name ] . package . artifact = path . join (
249
275
this . originalServicePath ,
250
276
SERVERLESS_FOLDER ,
@@ -273,14 +299,17 @@ export class TypeScriptPlugin {
273
299
* Attempt to symlink a given path or directory and copy if it fails with an
274
300
* `EPERM` error.
275
301
*/
276
- private async linkOrCopy ( srcPath : string , dstPath : string , type ?: fs . FsSymlinkType ) : Promise < void > {
277
- return fs . symlink ( srcPath , dstPath , type )
278
- . catch ( error => {
279
- if ( error . code === 'EPERM' && error . errno === - 4048 ) {
280
- return fs . copy ( srcPath , dstPath )
281
- }
282
- throw error
283
- } )
302
+ private async linkOrCopy (
303
+ srcPath : string ,
304
+ dstPath : string ,
305
+ type ?: fs . FsSymlinkType
306
+ ) : Promise < void > {
307
+ return fs . symlink ( srcPath , dstPath , type ) . catch ( ( error ) => {
308
+ if ( error . code === 'EPERM' && error . errno === - 4048 ) {
309
+ return fs . copy ( srcPath , dstPath )
310
+ }
311
+ throw error
312
+ } )
284
313
}
285
314
}
286
315
0 commit comments