serverless-plugin-include-dependencies
Advanced tools
Comparing version 5.0.0 to 5.1.0
@@ -16,3 +16,3 @@ 'use strict'; | ||
module.exports = function(filename, serverless, cache) { | ||
module.exports = function(filename, serverless, checkedFiles, cache) { | ||
const servicePath = serverless.config.servicePath; | ||
@@ -23,2 +23,3 @@ const modulePaths = new Set(); | ||
const localFilesToProcess = [filename]; | ||
if (!checkedFiles) checkedFiles = new Set(); | ||
@@ -43,3 +44,3 @@ function handle(name, basedir, optionalDependencies, peerDependenciesMeta) { | ||
} | ||
} else { | ||
@@ -75,3 +76,3 @@ // TODO: should we warn here? | ||
if (filePaths.has(currentLocalFile)) { | ||
if (filePaths.has(currentLocalFile) || checkedFiles.has(currentLocalFile)) { | ||
continue; | ||
@@ -81,2 +82,3 @@ } | ||
filePaths.add(currentLocalFile); | ||
checkedFiles.add(currentLocalFile); | ||
@@ -130,3 +132,3 @@ precinct.paperwork(currentLocalFile, { includeCore: false }).forEach(dependency => { | ||
return Array.from(filePaths); | ||
return Array.from(filePaths).map(file => file.replace(/\\/, '/')); | ||
}; |
@@ -7,2 +7,3 @@ 'use strict'; | ||
const micromatch = require('micromatch'); | ||
const glob = require('glob'); | ||
@@ -36,2 +37,3 @@ const getDependencyList = require('./get-dependency-list'); | ||
this.cache = new Set(); | ||
this.checkedFiles = new Set(); | ||
@@ -58,2 +60,19 @@ const service = this.serverless.service; | ||
} | ||
const files = [...new Set(this.getPatterns().filter(pattern => !pattern.startsWith('!') && !pattern.includes('node_modules')) | ||
.map(modulePath => glob.sync(modulePath, { | ||
nodir: true, | ||
ignore: path.join(modulePath, 'node_modules', '**'), | ||
absolute: true | ||
}) | ||
).flat().map(file => file.replaceAll('\\', '/')))]; | ||
files.forEach(fileName => { | ||
if (!this.checkedFiles.has(fileName)) { | ||
const dependencies = this.getDependencies(fileName, service.package.patterns); | ||
service.package.patterns = union(service.package.patterns, dependencies); | ||
} | ||
}); | ||
this.checkedFiles.clear(); | ||
} | ||
@@ -75,2 +94,7 @@ | ||
getPatterns() { | ||
const service = this.serverless.service; | ||
return (service.package && service.package.patterns) || []; | ||
} | ||
getPluginOptions() { | ||
@@ -85,3 +109,3 @@ const service = this.serverless.service; | ||
functionObject.package = functionObject.package || {}; | ||
const fileName = this.getHandlerFilename(functionObject.handler); | ||
@@ -111,3 +135,3 @@ const dependencies = this.getDependencies(fileName, service.package.patterns); | ||
const servicePath = this.serverless.config.servicePath; | ||
const dependencies = this.getDependencyList(fileName); | ||
const dependencies = this.getDependencyList(fileName) || []; | ||
const relativeDependencies = dependencies.map(p => path.relative(servicePath, p)); | ||
@@ -130,7 +154,7 @@ | ||
if (options && options.enableCaching) { | ||
return getDependencyList(fileName, this.serverless, this.cache); | ||
return getDependencyList(fileName, this.serverless, this.checkedFiles, this.cache); | ||
} | ||
} | ||
return getDependencyList(fileName, this.serverless); | ||
return getDependencyList(fileName, this.serverless, this.checkedFiles); | ||
} | ||
}; |
{ | ||
"name": "serverless-plugin-include-dependencies", | ||
"version": "5.0.0", | ||
"version": "5.1.0", | ||
"engines": { | ||
@@ -5,0 +5,0 @@ "node": ">=4.0" |
@@ -5,2 +5,6 @@ # serverless-plugin-include-dependencies | ||
5.1.0 introduces support for detecting dependencies of files included via package.patterns | ||
This is useful if you are dynamically importing a directory. | ||
As of 5.0.0 this plugin uses the `package.patterns` property. `always` is no longer supported as it should be possible with just package.patterns | ||
@@ -61,3 +65,3 @@ | ||
``` | ||
But be warned: Smaller individual functions can still mean a larger overall deployment. (10 functions that are 3 MB each is more net data tranfer and storage than 1 function that is 6 MB) | ||
But be warned: Smaller individual functions can still mean a larger overall deployment. (10 functions that are 3 MB each is more net data transfer and storage than 1 function that is 6 MB) | ||
@@ -64,0 +68,0 @@ ## Dependency caching (Experimental) |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
13480
220
93
1