File tree 3 files changed +60
-12
lines changed 3 files changed +60
-12
lines changed Original file line number Diff line number Diff line change @@ -6,7 +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 Zip = require ( 'adm-zip ' ) ;
9
+ const { zipDirectory } = require ( './zipService ' ) ;
10
10
11
11
BbPromise . promisifyAll ( fse ) ;
12
12
@@ -60,15 +60,8 @@ class ServerlessPythonRequirements {
60
60
61
61
packRequirements ( ) {
62
62
return this . installRequirements ( ) . then ( ( ) => {
63
- return new BbPromise ( ( resolve , reject ) => {
64
- if ( this . custom . zipImport ) {
65
- this . serverless . cli . log ( 'Zipping required Python packages...' ) ;
66
- const zip = new Zip ( ) ;
67
- zip . addLocalFolder ( '.requirements' , '' ) ;
68
- zip . writeZip ( '.requirements.zip' ) ;
69
- fse . remove ( '.requirements' , ( err ) => err ?reject ( ) :resolve ( ) ) ;
70
- } else resolve ( ) ;
71
- } ) ;
63
+ if ( this . custom . zipImport )
64
+ return zipDirectory ( '.requirements' , '.requirements.zip' ) ;
72
65
} ) ;
73
66
}
74
67
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " serverless-python-requirements" ,
3
- "version" : " 2.0.0-beta.2 " ,
3
+ "version" : " 2.0.0-beta.3 " ,
4
4
"engines" : {
5
5
"node" : " >=4.0"
6
6
},
29
29
],
30
30
"files" : [
31
31
" index.js" ,
32
+ " zipService.js" ,
32
33
" LICENSE" ,
33
34
" package.json" ,
34
35
" requirements.py" ,
39
40
"scripts" : {},
40
41
"devDependencies" : {},
41
42
"dependencies" : {
43
+ "archiver" : " ^1.3.0" ,
42
44
"bluebird" : " ^3.0.6" ,
43
- "adm-zip" : " 0.4.7" ,
44
45
"fs-extra" : " ^0.26.7" ,
46
+ "glob-all" : " ^3.1.0" ,
45
47
"lodash" : " ^4.13.1"
46
48
}
47
49
}
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+ // ripped from serverless and adapted for simpler use
3
+ // https://github.com/serverless/serverless/blob/b0df37673bd3a1fac11ccbfa3eb48e3626c0acb1/lib/plugins/package/lib/zipService.js
4
+
5
+ const archiver = require ( 'archiver' ) ;
6
+ const BbPromise = require ( 'bluebird' ) ;
7
+ const path = require ( 'path' ) ;
8
+ const fs = require ( 'fs' ) ;
9
+ const glob = require ( 'glob-all' ) ;
10
+
11
+ module . exports = {
12
+ zipDirectory ( dirPath , artifactFilePath ) {
13
+ const patterns = [ '**' ] ;
14
+
15
+ const zip = archiver . create ( 'zip' ) ;
16
+
17
+ const output = fs . createWriteStream ( artifactFilePath ) ;
18
+
19
+ output . on ( 'open' , ( ) => {
20
+ zip . pipe ( output ) ;
21
+
22
+ const files = glob . sync ( patterns , {
23
+ cwd : dirPath ,
24
+ dot : true ,
25
+ silent : true ,
26
+ follow : true ,
27
+ } ) ;
28
+
29
+ files . forEach ( ( filePath ) => {
30
+ const fullPath = path . resolve (
31
+ dirPath ,
32
+ filePath
33
+ ) ;
34
+
35
+ const stats = fs . statSync ( fullPath ) ;
36
+
37
+ if ( ! stats . isDirectory ( fullPath ) ) {
38
+ zip . append ( fs . createReadStream ( fullPath ) , {
39
+ name : filePath ,
40
+ mode : stats . mode ,
41
+ } ) ;
42
+ }
43
+ } ) ;
44
+
45
+ zip . finalize ( ) ;
46
+ } ) ;
47
+
48
+ return new BbPromise ( ( resolve , reject ) => {
49
+ output . on ( 'close' , ( ) => resolve ( artifactFilePath ) ) ;
50
+ zip . on ( 'error' , ( err ) => reject ( err ) ) ;
51
+ } ) ;
52
+ } ,
53
+ } ;
You can’t perform that action at this time.
0 commit comments