Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

serverless-build-plugin

Package Overview
Dependencies
Maintainers
2
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serverless-build-plugin - npm Package Compare versions

Comparing version 2.3.0 to 2.4.0-alpha.0

75

__tests__/ModuleBundler.test.js

@@ -44,12 +44,19 @@ "use strict";

describe('ModuleBundler', function () {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 31000;
var servicePath = path.resolve(__dirname, '../../test/1.0');
jasmine.DEFAULT_TIMEOUT_INTERVAL = 31000;
var artifact = Archiver('zip', { store: true });
var logger = new Logger_1.Logger({ silent: true });
var moduleBundler = new ModuleBundler_1.ModuleBundler({
servicePath: servicePath,
logger: new Logger_1.Logger(),
logger: logger,
archive: artifact,
});
var dependencies = require(servicePath + "/package.json").dependencies;
beforeAll(function () { return __awaiter(_this, void 0, void 0, function () {
var findModule = function (module) {
return moduleBundler.modules.find(function (_a) {
var name = _a.name;
return name === module;
});
};
it('can bundle all dependencies', function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {

@@ -60,2 +67,8 @@ switch (_a.label) {

_a.sent();
Object.keys(dependencies).forEach(function (dep) {
expect(moduleBundler.modules.some(function (_a) {
var name = _a.name;
return name === dep;
})).toBeTruthy();
});
return [2 /*return*/];

@@ -65,14 +78,48 @@ }

}); });
Object.keys(dependencies).forEach(function (dep) {
it("Has bundled dependency " + dep, function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
expect(moduleBundler.modules.some(function (_a) {
var name = _a.name;
return name === dep;
})).toBeTruthy();
return [2 /*return*/];
});
}); });
});
it('can include specific dependencies', function () { return __awaiter(_this, void 0, void 0, function () {
var includePackage;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
includePackage = 'lutils';
return [4 /*yield*/, moduleBundler.bundle({ include: [includePackage] })];
case 1:
_a.sent();
expect(findModule(includePackage)).toBeTruthy();
expect(moduleBundler.modules).toHaveLength(1);
return [2 /*return*/];
}
});
}); });
it('can exclude specific dependencies', function () { return __awaiter(_this, void 0, void 0, function () {
var excludePackage;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
excludePackage = 'bluebird';
return [4 /*yield*/, moduleBundler.bundle({ exclude: [excludePackage] })];
case 1:
_a.sent();
expect(findModule(excludePackage)).toBeFalsy();
expect(findModule('lutils')).toBeTruthy();
return [2 /*return*/];
}
});
}); });
it('can deep exclude specific dependencies', function () { return __awaiter(_this, void 0, void 0, function () {
var excludePackage;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
excludePackage = 'babel-runtime';
return [4 /*yield*/, moduleBundler.bundle({ exclude: [excludePackage], deepExclude: [excludePackage] })];
case 1:
_a.sent();
expect(findModule(excludePackage)).toBeFalsy();
expect(findModule('lutils')).toBeTruthy();
return [2 /*return*/];
}
});
}); });
});
//# sourceMappingURL=ModuleBundler.test.js.map
## 2.3.0 - Aug 08 2017
Features:
- [x] Now supports `webpack.config.ts` and any TypeScript build file by default
- Uses the services local `ts-node` to execute
## 2.2.0 - Aug 07 2017
- [x] Fixed regression with `node@8` in regards to async/await and Promise.all
- Thanks @brendo
## 2.1.0 - Jul 13 2017

@@ -3,0 +12,0 @@

102

FileBuild.js

@@ -99,5 +99,4 @@ "use strict";

switch (_a.label) {
case 0: return [4 /*yield*/, this.tryBuildFiles()];
case 1:
builderFilePath = _a.sent();
case 0:
builderFilePath = this.tryBuildFiles();
if (!builderFilePath) {

@@ -115,9 +114,9 @@ throw new Error('Unrecognized build file path');

}
if (!lutils_1.isFunction(result)) return [3 /*break*/, 3];
if (!lutils_1.isFunction(result)) return [3 /*break*/, 2];
return [4 /*yield*/, Bluebird.try(function () { return result(fnConfig, _this, { entryRelPath: entryRelPath, entryPoint: entryPoint, buildFilename: buildFilename }); })];
case 1:
result = _a.sent();
_a.label = 2;
case 2:
result = _a.sent();
_a.label = 3;
case 3:
if (!lutils_1.isObject(result)) return [3 /*break*/, 6];
if (!lutils_1.isObject(result)) return [3 /*break*/, 4];
webpackConfig = lutils_1.clone(result);

@@ -131,27 +130,14 @@ lutils_1.merge(webpackConfig, {

return [4 /*yield*/, this.webpackBuilder.build(webpackConfig)];
case 4:
case 3:
externals = _a.sent();
externals && externals.forEach(function (ext) { return _this.externals.add(ext); });
return [4 /*yield*/, Bluebird.each([
buildFilename, buildFilename + ".map",
], function (relPath) { return __awaiter(_this, void 0, void 0, function () {
var filePath;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
filePath = path.resolve(this.buildTmpDir, relPath);
return [4 /*yield*/, fs_extra_1.existsSync(filePath)];
case 1:
if (!(_a.sent())) {
return [2 /*return*/];
}
archive.file(filePath, { name: relPath });
return [2 /*return*/];
}
});
}); })];
case 5:
_a.sent();
return [3 /*break*/, 7];
case 6:
[buildFilename, buildFilename + ".map"].forEach(function (relPath) {
var filePath = path.resolve(_this.buildTmpDir, relPath);
if (!fs_extra_1.existsSync(filePath)) {
return;
}
archive.file(filePath, { name: relPath });
});
return [3 /*break*/, 5];
case 4:
if (lutils_1.isString(result) || result instanceof Buffer) {

@@ -175,4 +161,4 @@ //

}
_a.label = 7;
case 7: return [2 /*return*/, this];
_a.label = 5;
case 5: return [2 /*return*/, this];
}

@@ -186,37 +172,19 @@ });

FileBuild.prototype.tryBuildFiles = function () {
return __awaiter(this, void 0, void 0, function () {
var _a, _b, fileName, e_1_1, e_1, _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
_d.trys.push([0, 5, 6, 7]);
_a = __values(this.tryFiles), _b = _a.next();
_d.label = 1;
case 1:
if (!!_b.done) return [3 /*break*/, 4];
fileName = _b.value;
return [4 /*yield*/, fs_extra_1.existsSync(fileName)];
case 2:
if (_d.sent()) {
return [2 /*return*/, fileName];
}
_d.label = 3;
case 3:
_b = _a.next();
return [3 /*break*/, 1];
case 4: return [3 /*break*/, 7];
case 5:
e_1_1 = _d.sent();
e_1 = { error: e_1_1 };
return [3 /*break*/, 7];
case 6:
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_1) throw e_1.error; }
return [7 /*endfinally*/];
case 7: return [2 /*return*/, null];
try {
for (var _a = __values(this.tryFiles), _b = _a.next(); !_b.done; _b = _a.next()) {
var fileName = _b.value;
if (fs_extra_1.existsSync(fileName)) {
return fileName;
}
});
});
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_1) throw e_1.error; }
}
return null;
var e_1, _c;
};

@@ -223,0 +191,0 @@ return FileBuild;

module.exports = {
"verbose": false,
"collectCoverageFrom": [
"src/**/*",
"!**/__tests__/**"
],
"coverageReporters": ['text', 'text-summary'],
"coverageThreshold": {
"global": { lines: 30 }
},
"moduleFileExtensions": ["ts", "tsx", "js"],
"transform": { ".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js" },
"testRegex": "(\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [ "ts", "tsx", "js" ],
"testPathIgnorePatterns": [
"dist",
"/node_modules/"
]
],
"verbose": false,
}

@@ -9,5 +9,5 @@ export declare class Walker {

file(fn: any): this;
end(): Promise<void>;
end(): Promise<any[]>;
private capture;
}
export declare function findSymlinks(dirPath: any, maxDepth?: number): Promise<Map<any, any>>;

@@ -103,6 +103,3 @@ "use strict";

_a.sent();
return [4 /*yield*/, Promise.all(this.pending)];
case 2:
_a.sent();
return [2 /*return*/];
return [2 /*return*/, Promise.all(this.pending)];
}

@@ -109,0 +106,0 @@ });

@@ -96,15 +96,10 @@ "use strict";

var _this = this;
var links, _a, transforms, readModule;
return __generator(this, function (_b) {
switch (_b.label) {
var links, transforms, readModule;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Walker_1.findSymlinks(path_1.join(this.servicePath, 'node_modules'))];
case 1:
links = _b.sent();
_a = this;
return [4 /*yield*/, this.resolveDependencies(this.servicePath, { include: include, exclude: exclude, deepExclude: deepExclude, links: links })];
case 2:
_a.modules = _b.sent();
return [4 /*yield*/, this.resolveTransforms()];
case 3:
transforms = _b.sent();
links = _a.sent();
this.modules = this.resolveDependencies(this.servicePath, { include: include, exclude: exclude, deepExclude: deepExclude, links: links });
transforms = this.resolveTransforms();
readModule = function (_a) {

@@ -114,3 +109,3 @@ var packagePath = _a.packagePath, packageDir = _a.packageDir, relativePath = _a.relativePath, packageJson = _a.packageJson;

var _this = this;
var filter, onFile, walker;
var filter, onFile;
return __generator(this, function (_a) {

@@ -129,2 +124,6 @@ switch (_a.label) {

}
// If there are no deep exclusions, then there is no more filtering.
if (!deepExclude.length) {
return true;
}
// This pulls ['node_modules', 'pack'] out of

@@ -168,12 +167,9 @@ // .../node_modules/package/node_modules/pack

}); };
walker = new Walker_1.Walker(packagePath)
.filter(filter)
.file(onFile);
return [4 /*yield*/, walker.end()];
return [4 /*yield*/, new Walker_1.Walker(packagePath)
.filter(filter)
.file(onFile)
.end()];
case 1:
_a.sent();
return [4 /*yield*/, this.logger.module(({ filePath: relativePath, realPath: packagePath, packageJson: packageJson }))];
case 2:
_a.sent();
return [2 /*return*/];
return [2 /*return*/, this.logger.module(({ filePath: relativePath, realPath: packagePath, packageJson: packageJson }))];
}

@@ -184,4 +180,4 @@ });

return [4 /*yield*/, Bluebird.map(this.modules, readModule)];
case 4:
_b.sent();
case 2:
_a.sent();
return [2 /*return*/, this];

@@ -193,16 +189,11 @@ }

ModuleBundler.prototype.resolveTransforms = function () {
return __awaiter(this, void 0, void 0, function () {
var transforms, uglifyConfig;
return __generator(this, function (_a) {
transforms = [];
uglifyConfig = this.uglify;
if (uglifyConfig) {
if (uglifyConfig === true) {
uglifyConfig = null;
}
transforms.push(new Uglify_1.UglifyTransform(uglifyConfig, this));
}
return [2 /*return*/, transforms];
});
});
var transforms = [];
var uglifyConfig = this.uglify;
if (uglifyConfig) {
if (uglifyConfig === true) {
uglifyConfig = null;
}
transforms.push(new Uglify_1.UglifyTransform(uglifyConfig, this));
}
return transforms;
};

@@ -240,87 +231,57 @@ ModuleBundler.prototype.resolveSymlinkPath = function (filePath, links) {

var _b = _a === void 0 ? {} : _a, _c = _b.include, include = _c === void 0 ? [] : _c, _d = _b.exclude, exclude = _d === void 0 ? [] : _d, _e = _b.deepExclude, deepExclude = _e === void 0 ? [] : _e, _f = _b.links, links = _f === void 0 ? new Map() : _f;
return __awaiter(this, void 0, void 0, function () {
var _this = this;
var resolvedDeps, cache, separator, recurse;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
resolvedDeps = [];
cache = new Set();
separator = path_1.sep + "node_modules" + path_1.sep;
recurse = function (packageDir, _include, _exclude) {
if (_include === void 0) { _include = []; }
if (_exclude === void 0) { _exclude = []; }
return __awaiter(_this, void 0, void 0, function () {
var _this = this;
var packageJson, name, dependencies, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
packageJson = require(path_1.join(packageDir, './package.json'));
name = packageJson.name, dependencies = packageJson.dependencies;
result = {
name: name,
packageDir: packageDir,
packagePath: packageDir,
};
if (!dependencies) {
return [2 /*return*/, result];
}
return [4 /*yield*/, Bluebird.map(Object.keys(dependencies), function (packageName) { return __awaiter(_this, void 0, void 0, function () {
var resolvedDir, childPackageJsonPath, childPackageJson, nextPackagePath, link, relativePath, childResult;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
/**
* Skips on exclude matches, if set
* Skips on include mis-matches, if set
*/
if (_exclude.length && _exclude.indexOf(packageName) > -1) {
return [2 /*return*/];
}
if (_include.length && _include.indexOf(packageName) < 0) {
return [2 /*return*/];
}
resolvedDir = resolvePackage(packageName, { cwd: packageDir });
childPackageJsonPath = path_1.join(resolvedDir, './package.json');
return [4 /*yield*/, fs_extra_1.existsSync(childPackageJsonPath)];
case 1:
if (_a.sent()) {
childPackageJson = require(childPackageJsonPath); // eslint-disable-line
}
if (!resolvedDir) {
return [2 /*return*/];
}
nextPackagePath = resolvedDir;
link = links.get(resolvedDir);
if (link) {
resolvedDir = link;
}
relativePath = path_1.join('node_modules', resolvedDir.split(separator).slice(1).join(separator));
if (cache.has(relativePath)) {
return [2 /*return*/];
}
cache.add(relativePath);
return [4 /*yield*/, recurse(nextPackagePath, undefined, deepExclude)];
case 2:
childResult = _a.sent();
resolvedDeps.push(__assign({}, childResult, { packageDir: packageDir, relativePath: relativePath, packageJson: childPackageJson }));
return [2 /*return*/];
}
});
}); })];
case 1:
_a.sent();
return [2 /*return*/, result];
}
});
});
};
return [4 /*yield*/, recurse(initialPackageDir, include, exclude)];
case 1:
_a.sent();
return [2 /*return*/, resolvedDeps];
var resolvedDeps = [];
var cache = new Set();
var separator = path_1.sep + "node_modules" + path_1.sep;
/**
* Resolves packages to their package root directory &
* also resolves dependant packages recursively.
* - Will also ignore the input package in the results
*/
var recurse = function (packageDir, _include, _exclude) {
if (_include === void 0) { _include = []; }
if (_exclude === void 0) { _exclude = []; }
var packageJson = require(path_1.join(packageDir, './package.json')); // eslint-disable-line
var name = packageJson.name, dependencies = packageJson.dependencies;
var result = {
name: name,
packageDir: packageDir,
packagePath: packageDir,
};
if (!dependencies) {
return result;
}
Object.keys(dependencies).map(function (packageName) {
// Skips on exclude matches, if set
if (_exclude.length && _exclude.indexOf(packageName) > -1) {
return;
}
// Skips on include mis-matches, if set
if (_include.length && _include.indexOf(packageName) < 0) {
return;
}
var nextPackagePath = resolvePackage(packageName, { cwd: packageDir });
if (!nextPackagePath) {
return;
}
var link = links.get(nextPackagePath);
if (link) {
nextPackagePath = link;
}
var relativePath = path_1.join('node_modules', nextPackagePath.split(separator).slice(1).join(separator));
if (cache.has(relativePath)) {
return;
}
cache.add(relativePath);
var childPackageJsonPath = path_1.join(nextPackagePath, './package.json');
var childPackageJson;
if (fs_extra_1.existsSync(childPackageJsonPath)) {
childPackageJson = require(childPackageJsonPath); // eslint-disable-line
}
var childResult = recurse(nextPackagePath, undefined, deepExclude);
resolvedDeps.push(__assign({}, childResult, { packageDir: packageDir, relativePath: relativePath, packageJson: childPackageJson }));
});
});
return result;
};
recurse(initialPackageDir, include, exclude);
return resolvedDeps;
};

@@ -327,0 +288,0 @@ return ModuleBundler;

{
"name": "serverless-build-plugin",
"version": "2.3.0",
"version": "2.4.0-alpha.0",
"description": "A Node.js focused build optimizer plugin for serverless",

@@ -14,8 +14,8 @@ "main": "./index.js",

"test": "jest src",
"test:coverage": "jest src --coverage",
"test:dist": "jest -c '{}' dist",
"test:prepare": "cd test/1.0 && yarn",
"release": "cd dist && npm publish",
"release": "cd dist && yarn publish",
"lint": "tslint 'src/**/*.ts'",
"preversion": "yarn build && yarn test:dist",
"coverage": "jest src --coverage"
"preversion": "yarn build && yarn test:dist"
},

@@ -22,0 +22,0 @@ "dependencies": {

@@ -20,2 +20,4 @@ import { IPluginConfig } from './config';

build: () => Promise<void>;
buildFunction(fnName: any, fnConfig: any): Promise<any>;
passThroughFunction(fnName: any, fnConfig: any): Promise<any>;
/**

@@ -26,3 +28,3 @@ * Builds a function into an streaming zip artifact

*/
buildFunction(fnName: any, fnConfig: any): Promise<any>;
buildNodejsFunction(fnName: any, fnConfig: any): Promise<any>;
/**

@@ -29,0 +31,0 @@ * Writes the `artifact` and attaches it to serverless

@@ -171,4 +171,5 @@ "use strict";

});
var oldPluginFn = packagePlugin.packageFunction;
packagePlugin.packageFunction = function (fnName) { return __awaiter(_this, void 0, void 0, function () {
var fnConfig, artifactPath, packageFilePath;
var fnConfig, artifactPath, ext, packageFilePath;
return __generator(this, function (_a) {

@@ -179,6 +180,8 @@ switch (_a.label) {

artifactPath = fnConfig.artifact || (fnConfig.package && fnConfig.package.artifact);
// If we haven't built the artifact ourself, delegate back to the vanilla packagePlugin implementation
if (!artifactPath) {
throw new Error("Artifact path not found for function " + fnName);
return [2 /*return*/, oldPluginFn.call(packagePlugin, fnName)];
}
packageFilePath = path.join(this.tmpDir, "./" + fnName + ".zip");
ext = artifactPath.indexOf('.jar') > -1 ? 'jar' : 'zip';
packageFilePath = path.join(this.tmpDir, "./" + fnName + "." + ext);
return [4 /*yield*/, fs_extra_1.copy(artifactPath, packageFilePath)];

@@ -208,5 +211,5 @@ case 1:

this.serverless.service.package.individually = true;
// In sls 1.11 and lower this will skip 'archiving' (no effect in 1.12+)
this.serverless.service.package.artifact = true;
if (semver.lt(version, '1.12.0')) {
// In sls 1.11 and lower this will skip 'archiving'
this.serverless.service.package.artifact = true;
this.logger.message(c.red('DEPRECATION'), 'Upgrade to >= serverless@1.12. Build plugin is dropping support in the next major version');

@@ -277,2 +280,31 @@ }

}
ServerlessBuildPlugin.prototype.buildFunction = function (fnName, fnConfig) {
return __awaiter(this, void 0, void 0, function () {
var runtime;
return __generator(this, function (_a) {
runtime = fnConfig.runtime || this.serverless.service.provider.runtime;
this.logger.message('FUNCTION', c.reset.bold(fnName));
this.logger.log('');
if (runtime.indexOf('nodejs') > -1) {
return [2 /*return*/, this.buildNodejsFunction(fnName, fnConfig)];
}
if (runtime.indexOf('java') > -1) {
return [2 /*return*/, this.passThroughFunction(fnName, fnConfig)];
}
throw new this.serverless.classes.Error('[serverless-build-plugin]: Unsupported runtime. Only supports nodejs and java.');
});
});
};
ServerlessBuildPlugin.prototype.passThroughFunction = function (fnName, fnConfig) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
this.logger.log(c.reset.bold("No build step for " + fnName + " as it uses the " + fnConfig.runtime + " runtime"));
this.logger.log('');
this.logger.log('');
// Nothing needs to be done here, as we expect java artifacts to be compiled
// outside of serverless and specified as `package.artifact`
return [2 /*return*/, fnConfig];
});
});
};
/**

@@ -283,3 +315,3 @@ * Builds a function into an streaming zip artifact

*/
ServerlessBuildPlugin.prototype.buildFunction = function (fnName, fnConfig) {
ServerlessBuildPlugin.prototype.buildNodejsFunction = function (fnName, fnConfig) {
return __awaiter(this, void 0, void 0, function () {

@@ -292,4 +324,2 @@ var moduleIncludes, method, artifact, sourceBundler, result;

artifact = Archiver('zip', this.config.zip);
this.logger.message('FUNCTION', c.reset.bold(fnName));
this.logger.log('');
if (!(method === 'bundle')) return [3 /*break*/, 2];

@@ -296,0 +326,0 @@ sourceBundler = new SourceBundler_1.SourceBundler({

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc