@@ -86,7 +86,7 @@ function moveModuleUp(source, target, module) {
86
86
* Inject requirements into packaged application.
87
87
* @return {Promise } the combined promise for requirements injection.
88
88
*/
89
- function injectAllRequirements ( funcArtifact ) {
89
+ async function injectAllRequirements ( funcArtifact ) {
90
90
if ( this . options . layer ) {
91
91
// The requirements will be placed in a Layer, so just resolve
92
92
return BbPromise . resolve ( ) ;
@@ -101,61 +101,56 @@ function injectAllRequirements(funcArtifact) {
101
101
this . serverless . cli . log ( 'Injecting required Python packages to package...' ) ;
102
102
}
103
103
104
- let returnPromise ;
105
- if ( this . serverless . service . package . individually ) {
106
- returnPromise = BbPromise . resolve ( this . targetFuncs )
107
- . filter ( ( func ) =>
108
- ( func . runtime || this . serverless . service . provider . runtime ) . match (
109
- / ^ p y t h o n .* /
104
+ try {
105
+ if ( this . serverless . service . package . individually ) {
106
+ await BbPromise . resolve ( this . targetFuncs )
107
+ . filter ( ( func ) =>
108
+ ( func . runtime || this . serverless . service . provider . runtime ) . match (
109
+ / ^ p y t h o n .* /
110
+ )
110
111
)
111
- )
112
- . map ( ( func ) => {
113
- if ( ! get ( func , 'module' ) ) {
114
- set ( func , [ 'module' ] , '.' ) ;
115
- }
116
- return func ;
117
- } )
118
- . map ( ( func ) => {
119
- if ( func . module !== '.' ) {
120
- const artifact = func . package ? func . package . artifact : funcArtifact ;
121
- const newArtifact = path . join (
122
- '.serverless' ,
123
- `${ func . module } -${ func . name } .zip`
124
- ) ;
125
- func . package . artifact = newArtifact ;
126
- return moveModuleUp ( artifact , newArtifact , func . module ) . then (
127
- ( ) => func
128
- ) ;
129
- } else {
112
+ . map ( ( func ) => {
113
+ if ( ! get ( func , 'module' ) ) {
114
+ set ( func , [ 'module' ] , '.' ) ;
115
+ }
130
116
return func ;
131
- }
132
- } )
133
- . map ( ( func ) => {
134
- return this . options . zip
135
- ? func
136
- : injectRequirements (
137
- path . join ( '.serverless' , func . module , 'requirements' ) ,
138
- func . package . artifact ,
139
- this . options
117
+ } )
118
+ . map ( ( func ) => {
119
+ if ( func . module !== '.' ) {
120
+ const artifact = func . package
121
+ ? func . package . artifact
122
+ : funcArtifact ;
123
+ const newArtifact = path . join (
124
+ '.serverless' ,
125
+ ` ${ func . module } - ${ func . name } .zip`
140
126
) ;
141
- } ) ;
142
- } else if ( ! this . options . zip ) {
143
- returnPromise = injectRequirements (
144
- path . join ( '.serverless' , 'requirements' ) ,
145
- this . serverless . service . package . artifact || funcArtifact ,
146
- this . options
147
- ) ;
127
+ func . package . artifact = newArtifact ;
128
+ return moveModuleUp ( artifact , newArtifact , func . module ) . then (
129
+ ( ) => func
130
+ ) ;
131
+ } else {
132
+ return func ;
133
+ }
134
+ } )
135
+ . map ( ( func ) => {
136
+ return this . options . zip
137
+ ? func
138
+ : injectRequirements (
139
+ path . join ( '.serverless' , func . module , 'requirements' ) ,
140
+ func . package . artifact ,
141
+ this . options
142
+ ) ;
143
+ } ) ;
144
+ } else if ( ! this . options . zip ) {
145
+ await injectRequirements (
146
+ path . join ( '.serverless' , 'requirements' ) ,
147
+ this . serverless . service . package . artifact || funcArtifact ,
148
+ this . options
149
+ ) ;
150
+ }
151
+ } finally {
152
+ injectProgress && injectProgress . remove ( ) ;
148
153
}
149
-
150
- return (
151
- returnPromise &&
152
- returnPromise
153
- . then ( ( ) => injectProgress && injectProgress . remove ( ) )
154
- . catch ( ( e ) => {
155
- injectProgress && injectProgress . remove ( ) ;
156
- throw e ;
157
- } )
158
- ) ;
159
154
}
160
155
161
156
module . exports = { injectAllRequirements } ;
0 commit comments