@@ -6,6 +6,7 @@ const _ = require('lodash');
6
6
const path = require ( 'path' ) ;
7
7
const fse = require ( 'fs-extra' ) ;
8
8
const child_process = require ( 'child_process' ) ;
9
+ const { EasyZip} = require ( 'easy-zip' ) ;
9
10
10
11
BbPromise . promisifyAll ( fse ) ;
11
12
@@ -18,7 +19,7 @@ class ServerlessPythonRequirements {
18
19
path . join ( this . serverless . config . servicePath , 'requirements.py' ) ) ;
19
20
} ;
20
21
21
- packRequirements ( ) {
22
+ installRequirements ( ) {
22
23
if ( ! fse . existsSync ( path . join ( this . serverless . config . servicePath , 'requirements.txt' ) ) ) {
23
24
return BbPromise . resolve ( ) ;
24
25
}
@@ -52,8 +53,32 @@ class ServerlessPythonRequirements {
52
53
} ) ;
53
54
} ;
54
55
56
+ packRequirements ( ) {
57
+ return this . installRequirements ( ) . then ( ( ) => {
58
+ return new BbPromise ( ( resolve , reject ) => {
59
+ if ( this . serverless . service . custom && this . serverless . service . custom . zipImport ) {
60
+ const zip = new EasyZip ( ) ;
61
+ zip . zipFolder ( '.requirements' , ( err ) => {
62
+ if ( err ) {
63
+ reject ( ) ;
64
+ return ;
65
+ }
66
+ zip . writeToFile ( '.requirements.zip' ) ;
67
+ fse . remove ( '.requirements' , ( err ) => err ?reject ( ) :resolve ( ) ) ;
68
+ } , { rootFolder : '.' } ) ;
69
+ } else {
70
+ resolve ( ) ;
71
+ }
72
+ } ) ;
73
+ } ) ;
74
+ }
75
+
55
76
cleanup ( ) {
56
- const artifacts = [ 'requirements.py' , '.requirements' ] ;
77
+ const artifacts = [ 'requirements.py' ] ;
78
+ if ( this . serverless . service . custom && this . serverless . service . custom . zipImport )
79
+ artifacts . push ( '.requirements.zip' )
80
+ else
81
+ artifacts . push ( '.requirements' )
57
82
58
83
return BbPromise . all ( _ . map ( artifacts , ( artifact ) =>
59
84
fse . removeAsync ( path . join ( this . serverless . config . servicePath , artifact ) ) ) ) ; ;
0 commit comments