File tree 5 files changed +79
-4
lines changed
5 files changed +79
-4
lines changed Original file line number Diff line number Diff line change 59
59
"standard-version" : " ^9.3.2" ,
60
60
"ts-jest" : " 24.0.2" ,
61
61
"tslint" : " 5.14.0" ,
62
- "typescript" : " ^3.9.10 "
62
+ "typescript" : " ^4.7.4 "
63
63
},
64
64
"dependencies" : {
65
65
"fs-extra" : " ^7.0.1" ,
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ declare namespace Serverless {
11
11
service : {
12
12
provider : {
13
13
name : string
14
+ runtime ?: string
14
15
}
15
16
functions : {
16
17
[ key : string ] : Serverless . Function
@@ -38,6 +39,7 @@ declare namespace Serverless {
38
39
interface Function {
39
40
handler : string
40
41
package : Serverless . Package
42
+ runtime ?: string
41
43
}
42
44
43
45
interface Layer {
Original file line number Diff line number Diff line change @@ -93,14 +93,23 @@ export class TypeScriptPlugin {
93
93
get functions ( ) {
94
94
const { options } = this
95
95
const { service } = this . serverless
96
+ const functions = service . functions || { }
96
97
97
- if ( options . function ) {
98
+ const nodeFunctions = { }
99
+ for ( const [ name , functionObject ] of Object . entries ( functions ) ) {
100
+ const runtime = functions [ name ] . runtime || service . provider . runtime
101
+ if ( runtime . includes ( 'nodejs' ) ) {
102
+ nodeFunctions [ name ] = functionObject
103
+ }
104
+ }
105
+
106
+ if ( options . function && nodeFunctions [ options . function ] ) {
98
107
return {
99
- [ options . function ] : service . functions [ this . options . function ]
108
+ [ options . function ] : nodeFunctions [ options . function ]
100
109
}
101
110
}
102
111
103
- return service . functions
112
+ return nodeFunctions
104
113
}
105
114
106
115
get rootFileNames ( ) {
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import * as path from 'path'
4
4
const functions : { [ key : string ] : Serverless . Function } = {
5
5
hello : {
6
6
handler : 'tests/assets/hello.handler' ,
7
+ runtime : 'nodejs10.1' ,
7
8
package : {
8
9
include : [ ] ,
9
10
exclude : [ ] ,
@@ -12,6 +13,7 @@ const functions: { [key: string]: Serverless.Function } = {
12
13
} ,
13
14
world : {
14
15
handler : 'tests/assets/world.handler' ,
16
+ runtime : 'nodejs10.1' ,
15
17
package : {
16
18
include : [ ] ,
17
19
exclude : [ ] ,
@@ -20,6 +22,7 @@ const functions: { [key: string]: Serverless.Function } = {
20
22
} ,
21
23
js : {
22
24
handler : 'tests/assets/jsfile.create' ,
25
+ runtime : 'nodejs10.1' ,
23
26
package : {
24
27
include : [ ] ,
25
28
exclude : [ ] ,
Original file line number Diff line number Diff line change
1
+ import * as TypeScriptPlugin from '../src/index'
2
+
3
+ describe ( 'TypeScriptPlugin' , ( ) => {
4
+ it ( 'rootFileNames includes only node runtimes' , ( ) => {
5
+ const slsInstance : Serverless . Instance = {
6
+ cli : {
7
+ log : jest . fn ( )
8
+ } ,
9
+ config : {
10
+ servicePath : 'servicePath'
11
+ } ,
12
+ service : {
13
+ provider : {
14
+ name : 'aws' ,
15
+ runtime : 'nodejs99'
16
+ } ,
17
+ functions : {
18
+ func1 : {
19
+ handler : 'java-fn' ,
20
+ runtime : 'python3.9' ,
21
+ package :{
22
+ exclude : [ ] ,
23
+ include : [ ] ,
24
+ patterns : [ ]
25
+ }
26
+ } ,
27
+ func2 : {
28
+ handler : 'node-fn' ,
29
+ runtime : 'nodejs16' ,
30
+ package :{
31
+ exclude : [ ] ,
32
+ include : [ ] ,
33
+ patterns : [ ]
34
+ }
35
+ }
36
+ } ,
37
+ package : {
38
+ exclude : [ ] ,
39
+ include : [ ] ,
40
+ patterns : [ ]
41
+ } ,
42
+ layers : { } ,
43
+ getAllLayers : jest . fn ( ) ,
44
+ getAllFunctions : jest . fn ( )
45
+ } ,
46
+ pluginManager : {
47
+ spawn : jest . fn ( )
48
+ }
49
+ }
50
+
51
+ const plugin = new ( TypeScriptPlugin as any ) ( slsInstance , { } )
52
+
53
+ expect (
54
+ Object . keys ( plugin . functions )
55
+ ) . toEqual (
56
+ [
57
+ 'func2'
58
+ ] ,
59
+ )
60
+ } )
61
+ } )
You can’t perform that action at this time.
0 commit comments