@@ -54,20 +54,30 @@ function injectRequirements(requirementsPath, packagePath, options) {
54
54
* @param {string } source path to original package
55
55
* @param {string } target path to result package
56
56
* @param {string } module module to keep
57
+ * @param {[string] } include files to keep
57
58
* @return {Promise } the JSZip object written out.
58
59
*/
59
- function moveModuleUp ( source , target , module ) {
60
+ function moveModuleUp ( source , target , module , include ) {
60
61
const targetZip = new JSZip ( ) ;
62
+ let included = new Set ( ) ;
63
+
64
+ if ( ! ! include && include . length > 0 )
65
+ included = new Set ( glob . sync ( include ) ) ;
66
+
67
+ console . log ( "To include:" , included ) ;
61
68
62
69
return fse
63
70
. readFileAsync ( source )
64
71
. then ( buffer => JSZip . loadAsync ( buffer ) )
65
72
. then ( sourceZip =>
66
73
sourceZip . filter (
67
- file =>
68
- file . startsWith ( module + '/' ) ||
74
+ file => {
75
+ // return true;
76
+ return file . startsWith ( module + '/' ) ||
69
77
file . startsWith ( 'serverless_sdk/' ) ||
70
- file . match ( / ^ s _ .* \. p y / ) !== null
78
+ file . match ( / ^ s _ .* \. p y / ) !== null ||
79
+ included . has ( file )
80
+ }
71
81
)
72
82
)
73
83
. map ( srcZipObj =>
@@ -93,13 +103,13 @@ function injectAllRequirements(funcArtifact) {
93
103
}
94
104
95
105
this . serverless . cli . log ( 'Injecting required Python packages to package...' ) ;
96
-
106
+ this . serverless . cli . log ( "SERVERLESS INFO:" , this . servicePath ) ;
97
107
if ( this . serverless . service . package . individually ) {
98
108
return BbPromise . resolve ( this . targetFuncs )
99
109
. filter ( func =>
100
110
( func . runtime || this . serverless . service . provider . runtime ) . match (
101
- / ^ p y t h o n .* /
102
- )
111
+ / ^ p y t h o n .* /
112
+ )
103
113
)
104
114
. map ( func => {
105
115
if ( ! get ( func , 'module' ) ) {
@@ -108,14 +118,17 @@ function injectAllRequirements(funcArtifact) {
108
118
return func ;
109
119
} )
110
120
. map ( func => {
121
+
111
122
if ( func . module !== '.' ) {
112
123
const artifact = func . package ? func . package . artifact : funcArtifact ;
113
124
const newArtifact = path . join (
114
125
'.serverless' ,
115
126
`${ func . module } -${ func . name } .zip`
116
127
) ;
117
128
func . package . artifact = newArtifact ;
118
- return moveModuleUp ( artifact , newArtifact , func . module ) . then (
129
+ const package_include = func . package ? func . package . include : [ ] ;
130
+ this . serverless . cli . log ( "Package Include:" , package_include ) ;
131
+ return moveModuleUp ( artifact , newArtifact , func . module , package_include ) . then (
119
132
( ) => func
120
133
) ;
121
134
} else {
0 commit comments