@@ -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 (
@@ -142,15 +161,22 @@ export class TypeScriptPlugin {
142
161
// Link or copy node_modules and package.json to .build so Serverless can
143
162
// exlcude devDeps during packaging
144
163
if ( ! fs . existsSync ( outModulesPath ) ) {
145
- await this . linkOrCopy ( path . resolve ( 'node_modules' ) , outModulesPath , 'junction' )
164
+ await this . linkOrCopy (
165
+ path . resolve ( 'node_modules' ) ,
166
+ outModulesPath ,
167
+ 'junction'
168
+ )
146
169
}
147
170
148
171
if ( ! fs . existsSync ( outPkgPath ) ) {
149
172
await this . linkOrCopy ( path . resolve ( 'package.json' ) , outPkgPath , 'file' )
150
173
}
151
174
152
175
// include any "extras" from the "include" section
153
- if ( this . serverless . service . package . include && this . serverless . service . package . include . length > 0 ) {
176
+ if (
177
+ this . serverless . service . package . include &&
178
+ this . serverless . service . package . include . length > 0
179
+ ) {
154
180
const files = await globby ( this . serverless . service . package . include )
155
181
156
182
for ( const filename of files ) {
@@ -162,7 +188,10 @@ export class TypeScriptPlugin {
162
188
}
163
189
164
190
if ( ! fs . existsSync ( destFileName ) ) {
165
- fs . copySync ( path . resolve ( filename ) , path . resolve ( path . join ( buildFolder , filename ) ) )
191
+ fs . copySync (
192
+ path . resolve ( filename ) ,
193
+ path . resolve ( path . join ( buildFolder , filename ) )
194
+ )
166
195
}
167
196
}
168
197
}
@@ -177,7 +206,7 @@ export class TypeScriptPlugin {
177
206
if ( this . options . function ) {
178
207
const fn = this . serverless . service . functions [ this . options . function ]
179
208
const basename = path . basename ( fn . package . artifact )
180
- fn . package . artifact = path . join (
209
+ fn . package . artifact = path . join (
181
210
this . originalServicePath ,
182
211
serverlessFolder ,
183
212
path . basename ( fn . package . artifact )
@@ -191,7 +220,9 @@ export class TypeScriptPlugin {
191
220
this . serverless . service . functions [ name ] . package . artifact = path . join (
192
221
this . originalServicePath ,
193
222
serverlessFolder ,
194
- path . basename ( this . serverless . service . functions [ name ] . package . artifact )
223
+ path . basename (
224
+ this . serverless . service . functions [ name ] . package . artifact
225
+ )
195
226
)
196
227
} )
197
228
return
@@ -233,13 +264,12 @@ export class TypeScriptPlugin {
233
264
dstPath : string ,
234
265
type ?: 'dir' | 'junction' | 'file'
235
266
) : Promise < void > {
236
- return fs . symlink ( srcPath , dstPath , type )
237
- . catch ( error => {
238
- if ( error . code === 'EPERM' && error . errno === - 4048 ) {
239
- return fs . copy ( srcPath , dstPath )
240
- }
241
- throw error
242
- } )
267
+ return fs . symlink ( srcPath , dstPath , type ) . catch ( error => {
268
+ if ( error . code === 'EPERM' && error . errno === - 4048 ) {
269
+ return fs . copy ( srcPath , dstPath )
270
+ }
271
+ throw error
272
+ } )
243
273
}
244
274
}
245
275
0 commit comments