Skip to content

Commit f1acff2

Browse files
committed
Fix Module Include
Fixes a bug where individual "include" files/directories are ignored for a package.
1 parent b652947 commit f1acff2

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

lib/inject.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,30 @@ function injectRequirements(requirementsPath, packagePath, options) {
5454
* @param {string} source path to original package
5555
* @param {string} target path to result package
5656
* @param {string} module module to keep
57+
* @param {[string]} include files to keep
5758
* @return {Promise} the JSZip object written out.
5859
*/
59-
function moveModuleUp(source, target, module) {
60+
function moveModuleUp(source, target, module, include) {
6061
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);
6168

6269
return fse
6370
.readFileAsync(source)
6471
.then(buffer => JSZip.loadAsync(buffer))
6572
.then(sourceZip =>
6673
sourceZip.filter(
67-
file =>
68-
file.startsWith(module + '/') ||
74+
file => {
75+
// return true;
76+
return file.startsWith(module + '/') ||
6977
file.startsWith('serverless_sdk/') ||
70-
file.match(/^s_.*\.py/) !== null
78+
file.match(/^s_.*\.py/) !== null ||
79+
included.has(file)
80+
}
7181
)
7282
)
7383
.map(srcZipObj =>
@@ -93,13 +103,13 @@ function injectAllRequirements(funcArtifact) {
93103
}
94104

95105
this.serverless.cli.log('Injecting required Python packages to package...');
96-
106+
this.serverless.cli.log("SERVERLESS INFO:", this.servicePath);
97107
if (this.serverless.service.package.individually) {
98108
return BbPromise.resolve(this.targetFuncs)
99109
.filter(func =>
100110
(func.runtime || this.serverless.service.provider.runtime).match(
101-
/^python.*/
102-
)
111+
/^python.*/
112+
)
103113
)
104114
.map(func => {
105115
if (!get(func, 'module')) {
@@ -108,14 +118,17 @@ function injectAllRequirements(funcArtifact) {
108118
return func;
109119
})
110120
.map(func => {
121+
111122
if (func.module !== '.') {
112123
const artifact = func.package ? func.package.artifact : funcArtifact;
113124
const newArtifact = path.join(
114125
'.serverless',
115126
`${func.module}-${func.name}.zip`
116127
);
117128
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(
119132
() => func
120133
);
121134
} else {

0 commit comments

Comments
 (0)