From 63756c937aa94653008db1cd7ad9f30d876fd464 Mon Sep 17 00:00:00 2001 From: Bruno Agutoli Date: Sun, 5 May 2019 17:55:59 +1000 Subject: [PATCH] added support for yarn (package manager) and bugfix for issue #7 --- README.md | 1 + lib/AbstractService.js | 2 +- lib/aws/BucketService.js | 32 ++++---- lib/aws/BucketService.js.map | 2 +- lib/aws/CloudFormationService.js | 10 +-- lib/aws/CloudFormationService.js.map | 2 +- lib/aws/LayersService.js | 16 ++-- lib/aws/LayersService.js.map | 2 +- lib/index.js | 33 ++++---- lib/index.js.map | 2 +- lib/package/Dependencies.js | 113 ++++++++++++++++++--------- lib/package/Dependencies.js.map | 2 +- lib/package/ZipService.js | 8 +- src/index.js | 2 +- src/package/Dependencies.js | 62 +++++++++++---- 15 files changed, 180 insertions(+), 109 deletions(-) diff --git a/README.md b/README.md index e825a06..7fc15b6 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ plugins: ```yaml custom: serverless-layers: + packageManager: yarn, # NEW compileDir: '.serverless', packagePath: 'package.json', compatibleRuntimes: ['nodejs'], diff --git a/lib/AbstractService.js b/lib/AbstractService.js index 614ebee..a0cf657 100644 --- a/lib/AbstractService.js +++ b/lib/AbstractService.js @@ -7,7 +7,7 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl var path = require('path'); var AbstractService = function AbstractService(plugin) { - (0, _classCallCheck2["default"])(this, AbstractService); + (0, _classCallCheck2.default)(this, AbstractService); this.plugin = plugin; this.stackName = plugin.getStackName(); this.bucketName = plugin.getBucketName(); diff --git a/lib/aws/BucketService.js b/lib/aws/BucketService.js index 42e5f4f..de9e82b 100644 --- a/lib/aws/BucketService.js +++ b/lib/aws/BucketService.js @@ -23,23 +23,23 @@ var AbstractService = require('../AbstractService'); var UploadService = /*#__PURE__*/ function (_AbstractService) { - (0, _inherits2["default"])(UploadService, _AbstractService); + (0, _inherits2.default)(UploadService, _AbstractService); function UploadService() { - (0, _classCallCheck2["default"])(this, UploadService); - return (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(UploadService).apply(this, arguments)); + (0, _classCallCheck2.default)(this, UploadService); + return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(UploadService).apply(this, arguments)); } - (0, _createClass2["default"])(UploadService, [{ + (0, _createClass2.default)(UploadService, [{ key: "uploadZipFile", value: function () { - var _uploadZipFile = (0, _asyncToGenerator2["default"])( + var _uploadZipFile = (0, _asyncToGenerator2.default)( /*#__PURE__*/ - _regenerator["default"].mark(function _callee() { + _regenerator.default.mark(function _callee() { var _this = this; var params; - return _regenerator["default"].wrap(function _callee$(_context) { + return _regenerator.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: @@ -53,7 +53,7 @@ function (_AbstractService) { _this.plugin.log('OK...'); return result; - })["catch"](function (e) { + }).catch(function (e) { console.log(e.message); process.exit(1); })); @@ -75,13 +75,13 @@ function (_AbstractService) { }, { key: "uploadPackageJson", value: function () { - var _uploadPackageJson = (0, _asyncToGenerator2["default"])( + var _uploadPackageJson = (0, _asyncToGenerator2.default)( /*#__PURE__*/ - _regenerator["default"].mark(function _callee2() { + _regenerator.default.mark(function _callee2() { var _this2 = this; var params; - return _regenerator["default"].wrap(function _callee2$(_context2) { + return _regenerator.default.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: @@ -95,7 +95,7 @@ function (_AbstractService) { _this2.plugin.log('OK...'); return result; - })["catch"](function (e) { + }).catch(function (e) { console.log(e.message); process.exit(1); })); @@ -117,13 +117,13 @@ function (_AbstractService) { }, { key: "downloadPackageJson", value: function () { - var _downloadPackageJson = (0, _asyncToGenerator2["default"])( + var _downloadPackageJson = (0, _asyncToGenerator2.default)( /*#__PURE__*/ - _regenerator["default"].mark(function _callee3() { + _regenerator.default.mark(function _callee3() { var _this3 = this; var params; - return _regenerator["default"].wrap(function _callee3$(_context3) { + return _regenerator.default.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: @@ -134,7 +134,7 @@ function (_AbstractService) { }; return _context3.abrupt("return", this.provider.request('S3', 'getObject', params).then(function (result) { return JSON.parse(result.Body.toString()); - })["catch"](function () { + }).catch(function () { _this3.plugin.log('package.json does not exists at bucket...'); return null; diff --git a/lib/aws/BucketService.js.map b/lib/aws/BucketService.js.map index 0a3a6ca..c91fc66 100644 --- a/lib/aws/BucketService.js.map +++ b/lib/aws/BucketService.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/aws/BucketService.js"],"names":["fs","require","AbstractService","UploadService","plugin","log","params","Bucket","bucketName","Key","zipFileKeyName","Body","createReadStream","getPathZipFileName","provider","request","then","result","e","console","message","process","exit","packageJsonKeyName","settings","packagePath","JSON","parse","toString","module","exports"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAMA,EAAE,GAAGC,OAAO,CAAC,IAAD,CAAlB;;AACA,IAAMC,eAAe,GAAGD,OAAO,CAAC,oBAAD,CAA/B;;IAEME,a;;;;;;;;;;;;;;;;;;;;;;;AAEF,qBAAKC,MAAL,CAAYC,GAAZ,CAAgB,4BAAhB;AAEMC,gBAAAA,M,GAAS;AACbC,kBAAAA,MAAM,EAAE,KAAKC,UADA;AAEbC,kBAAAA,GAAG,EAAE,KAAKC,cAFG;AAGbC,kBAAAA,IAAI,EAAEX,EAAE,CAACY,gBAAH,CAAoB,KAAKR,MAAL,CAAYS,kBAAZ,EAApB;AAHO,iB;iDAMR,KAAKC,QAAL,CAAcC,OAAd,CAAsB,IAAtB,EAA4B,WAA5B,EAAyCT,MAAzC,EACJU,IADI,CACC,UAACC,MAAD,EAAY;AAChB,kBAAA,KAAI,CAACb,MAAL,CAAYC,GAAZ,CAAgB,OAAhB;;AACA,yBAAOY,MAAP;AACD,iBAJI,WAKE,UAAAC,CAAC,EAAI;AACVC,kBAAAA,OAAO,CAACd,GAAR,CAAYa,CAAC,CAACE,OAAd;AACAC,kBAAAA,OAAO,CAACC,IAAR,CAAa,CAAb;A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,aAAjB","sourcesContent":["const fs = require('fs');\nconst AbstractService = require('../AbstractService');\n\nclass UploadService extends AbstractService {\n async uploadZipFile() {\n this.plugin.log('Uploading layer package...');\n\n const params = {\n Bucket: this.bucketName,\n Key: this.zipFileKeyName,\n Body: fs.createReadStream(this.plugin.getPathZipFileName())\n };\n\n return this.provider.request('S3', 'putObject', params)\n .then((result) => {\n this.plugin.log('OK...');\n return result;\n })\n .catch(e => {\n console.log(e.message);\n process.exit(1);\n });\n }\n\n async uploadPackageJson() {\n this.plugin.log('Uploading remote package.json...');\n\n const params = {\n Bucket: this.bucketName,\n Key: this.packageJsonKeyName,\n Body: fs.createReadStream(this.plugin.settings.packagePath)\n };\n\n return this.provider.request('S3', 'putObject', params)\n .then((result) => {\n this.plugin.log('OK...');\n return result;\n })\n .catch(e => {\n console.log(e.message);\n process.exit(1);\n });\n }\n\n async downloadPackageJson() {\n this.plugin.log('Downloading package.json from bucket...');\n\n const params = {\n Bucket: this.bucketName,\n Key: this.packageJsonKeyName\n };\n\n return this.provider.request('S3', 'getObject', params)\n .then((result) => JSON.parse(result.Body.toString()))\n .catch(() => {\n this.plugin.log('package.json does not exists at bucket...');\n return null;\n });\n }\n}\n\nmodule.exports = UploadService;\n"],"file":"BucketService.js"} \ No newline at end of file +{"version":3,"sources":["../../src/aws/BucketService.js"],"names":["fs","require","AbstractService","UploadService","plugin","log","params","Bucket","bucketName","Key","zipFileKeyName","Body","createReadStream","getPathZipFileName","provider","request","then","result","catch","e","console","message","process","exit","packageJsonKeyName","settings","packagePath","JSON","parse","toString","module","exports"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAMA,EAAE,GAAGC,OAAO,CAAC,IAAD,CAAlB;;AACA,IAAMC,eAAe,GAAGD,OAAO,CAAC,oBAAD,CAA/B;;IAEME,a;;;;;;;;;;;;;;;;;;;;;;;AAEF,qBAAKC,MAAL,CAAYC,GAAZ,CAAgB,4BAAhB;AAEMC,gBAAAA,M,GAAS;AACbC,kBAAAA,M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L,CAAYC,GAAZ,CAAgB,yCAAhB;AAEMC,gBAAAA,M,GAAS;AACbC,kBAAAA,MAAM,EAAE,KAAKC,UADA;AAEbC,kBAAAA,GAAG,EAAE,KAAKe;AAFG,iB;kDAKR,KAAKV,QAAL,CAAcC,OAAd,CAAsB,IAAtB,EAA4B,WAA5B,EAAyCT,MAAzC,EACJU,IADI,CACC,UAACC,MAAD;AAAA,yBAAYU,IAAI,CAACC,KAAL,CAAWX,MAAM,CAACN,IAAP,CAAYkB,QAAZ,EAAX,CAAZ;AAAA,iBADD,EAEJX,KAFI,CAEE,YAAM;AACX,kBAAA,MAAI,CAACd,MAAL,CAAYC,GAAZ,CAAgB,2CAAhB;;AACA,yBAAO,IAAP;AACD,iBALI,C;;;;;;;;;;;;;;;;;;EAjDiBH,e;;AA0D5B4B,MAAM,CAACC,OAAP,GAAiB5B,aAAjB","sourcesContent":["const fs = require('fs');\nconst AbstractService = require('../AbstractService');\n\nclass UploadService extends AbstractService {\n async uploadZipFile() {\n this.plugin.log('Uploading layer package...');\n\n const params = {\n Bucket: this.bucketName,\n Key: this.zipFileKeyName,\n Body: fs.createReadStream(this.plugin.getPathZipFileName())\n };\n\n return this.provider.request('S3', 'putObject', params)\n .then((result) => {\n this.plugin.log('OK...');\n return result;\n })\n .catch(e => {\n console.log(e.message);\n process.exit(1);\n });\n }\n\n async uploadPackageJson() {\n this.plugin.log('Uploading remote package.json...');\n\n const params = {\n Bucket: this.bucketName,\n Key: this.packageJsonKeyName,\n Body: fs.createReadStream(this.plugin.settings.packagePath)\n };\n\n return this.provider.request('S3', 'putObject', params)\n .then((result) => {\n this.plugin.log('OK...');\n return result;\n })\n .catch(e => {\n console.log(e.message);\n process.exit(1);\n });\n }\n\n async downloadPackageJson() {\n this.plugin.log('Downloading package.json from bucket...');\n\n const params = {\n Bucket: this.bucketName,\n Key: this.packageJsonKeyName\n };\n\n return this.provider.request('S3', 'getObject', params)\n .then((result) => JSON.parse(result.Body.toString()))\n .catch(() => {\n this.plugin.log('package.json does not exists at bucket...');\n return null;\n });\n }\n}\n\nmodule.exports = UploadService;\n"],"file":"BucketService.js"} \ No newline at end of file diff --git a/lib/aws/CloudFormationService.js b/lib/aws/CloudFormationService.js index 7dafb69..51f189a 100644 --- a/lib/aws/CloudFormationService.js +++ b/lib/aws/CloudFormationService.js @@ -17,14 +17,14 @@ var AbstractService = require('../AbstractService'); var CloudFormationService = /*#__PURE__*/ function (_AbstractService) { - (0, _inherits2["default"])(CloudFormationService, _AbstractService); + (0, _inherits2.default)(CloudFormationService, _AbstractService); function CloudFormationService() { - (0, _classCallCheck2["default"])(this, CloudFormationService); - return (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(CloudFormationService).apply(this, arguments)); + (0, _classCallCheck2.default)(this, CloudFormationService); + return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(CloudFormationService).apply(this, arguments)); } - (0, _createClass2["default"])(CloudFormationService, [{ + (0, _createClass2.default)(CloudFormationService, [{ key: "getOutputs", value: function getOutputs() { var params = { @@ -33,7 +33,7 @@ function (_AbstractService) { return this.provider.request('CloudFormation', 'describeStacks', params).then(function (_ref) { var Stacks = _ref.Stacks; return Stacks && Stacks[0].Outputs; - })["catch"](function () { + }).catch(function () { return []; }); } diff --git a/lib/aws/CloudFormationService.js.map b/lib/aws/CloudFormationService.js.map index 186066a..bd39c8b 100644 --- a/lib/aws/CloudFormationService.js.map +++ b/lib/aws/CloudFormationService.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/aws/CloudFormationService.js"],"names":["AbstractService","require","CloudFormationService","params","StackName","stackName","provider","request","then","Stacks","Outputs","module","exports"],"mappings":";;;;;;;;;;;;;;AAAA,IAAMA,eAAe,GAAGC,OAAO,CAAC,oBAAD,CAA/B;;IAEMC,qB;;;;;;;;;;;;iCACS;AACX,UAAMC,MAAM,GAAG;AACbC,QAAAA,SAAS,EAAE,KAAKC;AADH,OAAf;AAIA,aAAO,KAAKC,QAAL,CAAcC,OAAd,CAAsB,gBAAtB,EAAwC,gBAAxC,EAA0DJ,MAA1D,EACJK,IADI,CACC;AAAA,YAAGC,MAAH,QAAGA,MAAH;AAAA,eAAgBA,MAAM,IAAIA,MAAM,CAAC,CAAD,CAAN,CAAUC,OAApC;AAAA,OADD,WAEE;AAAA,eAAM,EAAN;AAAA,OAFF,CAAP;AAGD;;;EATiCV,e;;AAYpCW,MAAM,CAACC,OAAP,GAAiBV,qBAAjB","sourcesContent":["const AbstractService = require('../AbstractService');\n\nclass CloudFormationService extends AbstractService {\n getOutputs() {\n const params = {\n StackName: this.stackName\n };\n\n return this.provider.request('CloudFormation', 'describeStacks', params)\n .then(({ Stacks }) => Stacks && Stacks[0].Outputs)\n .catch(() => []);\n }\n}\n\nmodule.exports = CloudFormationService;\n"],"file":"CloudFormationService.js"} \ No newline at end of file +{"version":3,"sources":["../../src/aws/CloudFormationService.js"],"names":["AbstractService","require","CloudFormationService","params","StackName","stackName","provider","request","then","Stacks","Outputs","catch","module","exports"],"mappings":";;;;;;;;;;;;;;AAAA,IAAMA,eAAe,GAAGC,OAAO,CAAC,oBAAD,CAA/B;;IAEMC,qB;;;;;;;;;;;;iCACS;AACX,UAAMC,MAAM,GAAG;AACbC,QAAAA,SAAS,EAAE,KAAKC;AADH,OAAf;AAIA,aAAO,KAAKC,QAAL,CAAcC,OAAd,CAAsB,gBAAtB,EAAwC,gBAAxC,EAA0DJ,MAA1D,EACJK,IADI,CACC;AAAA,YAAGC,MAAH,QAAGA,MAAH;AAAA,eAAgBA,MAAM,IAAIA,MAAM,CAAC,CAAD,CAAN,CAAUC,OAApC;AAAA,OADD,EAEJC,KAFI,CAEE;AAAA,eAAM,EAAN;AAAA,OAFF,CAAP;AAGD;;;EATiCX,e;;AAYpCY,MAAM,CAACC,OAAP,GAAiBX,qBAAjB","sourcesContent":["const AbstractService = require('../AbstractService');\n\nclass CloudFormationService extends AbstractService {\n getOutputs() {\n const params = {\n StackName: this.stackName\n };\n\n return this.provider.request('CloudFormation', 'describeStacks', params)\n .then(({ Stacks }) => Stacks && Stacks[0].Outputs)\n .catch(() => []);\n }\n}\n\nmodule.exports = CloudFormationService;\n"],"file":"CloudFormationService.js"} \ No newline at end of file diff --git a/lib/aws/LayersService.js b/lib/aws/LayersService.js index 251b1ce..266fb42 100644 --- a/lib/aws/LayersService.js +++ b/lib/aws/LayersService.js @@ -21,23 +21,23 @@ var AbstractService = require('../AbstractService'); var LayersService = /*#__PURE__*/ function (_AbstractService) { - (0, _inherits2["default"])(LayersService, _AbstractService); + (0, _inherits2.default)(LayersService, _AbstractService); function LayersService() { - (0, _classCallCheck2["default"])(this, LayersService); - return (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(LayersService).apply(this, arguments)); + (0, _classCallCheck2.default)(this, LayersService); + return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(LayersService).apply(this, arguments)); } - (0, _createClass2["default"])(LayersService, [{ + (0, _createClass2.default)(LayersService, [{ key: "publishVersion", value: function () { - var _publishVersion = (0, _asyncToGenerator2["default"])( + var _publishVersion = (0, _asyncToGenerator2.default)( /*#__PURE__*/ - _regenerator["default"].mark(function _callee() { + _regenerator.default.mark(function _callee() { var _this = this; var params; - return _regenerator["default"].wrap(function _callee$(_context) { + return _regenerator.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: @@ -55,7 +55,7 @@ function (_AbstractService) { _this.plugin.cacheObject.LayerVersionArn = result.LayerVersionArn; return result; - })["catch"](function (e) { + }).catch(function (e) { console.log(e.message); process.exit(1); })); diff --git a/lib/aws/LayersService.js.map b/lib/aws/LayersService.js.map index 7e77796..f26e86b 100644 --- a/lib/aws/LayersService.js.map +++ b/lib/aws/LayersService.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/aws/LayersService.js"],"names":["AbstractService","require","LayersService","params","Content","S3Bucket","bucketName","S3Key","zipFileKeyName","LayerName","stackName","Description","CompatibleRuntimes","plugin","settings","compatibleRuntimes","provider","request","then","result","log","cacheObject","LayerVersionArn","e","console","message","process","exit","module","exports"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAMA,eAAe,GAAGC,OAAO,CAAC,oBAAD,CAA/B;;IAEMC,a;;;;;;;;;;;;;;;;;;;;;;;AAEIC,gBAAAA,M,GAAS;AACbC,kBAAAA,OAAO,EAAE;AACPC,oBAAAA,QAAQ,EAAE,KAAKC,UADR;AAEPC,oBAAAA,KAAK,EAAE,KAAKC;AAFL,mBADI;AAKbC,kBAAAA,SAAS,EAAE,KAAKC,SALH;AAMbC,kBAAAA,WAAW,EAAE,qCANA;AAObC,kBAAAA,kBAAkB,EAAE,KAAKC,MAAL,CAAYC,QAAZ,CAAqBC;AAP5B,iB;iDAUR,KAAKC,QAAL,CAAcC,OAAd,CAAsB,QAAtB,EAAgC,qBAAhC,EAAuDd,MAAvD,EACJe,IADI,CACC,UAACC,MAAD,EAAY;AAChB,kBAAA,KAAI,CAACN,MAAL,CAAYO,GAAZ,CAAgB,gCAAhB;;AACA,kBAAA,KAAI,CAACP,MAAL,CAAYQ,WAAZ,CAAwBC,eAAxB,GAA0CH,MAAM,CAACG,eAAjD;AACA,yBAAOH,MAAP;AACD,iBALI,WAME,UAAAI,CAAC,EAAI;AACVC,kBAAAA,OAAO,CAACJ,GAAR,CAAYG,CAAC,CAACE,OAAd;AACAC,kBAAAA,OAAO,CAACC,IAAR,CAAa,CAAb;AACD,iBATI,C;;;;;;;;;;;;;;;;;;EAZiB3B,e;;AAyB5B4B,MAAM,CAACC,OAAP,GAAiB3B,aAAjB","sourcesContent":["const AbstractService = require('../AbstractService');\n\nclass LayersService extends AbstractService {\n async publishVersion() {\n const params = {\n Content: {\n S3Bucket: this.bucketName,\n S3Key: this.zipFileKeyName\n },\n LayerName: this.stackName,\n Description: 'created by serverless-layers plugin',\n CompatibleRuntimes: this.plugin.settings.compatibleRuntimes\n };\n\n return this.provider.request('Lambda', 'publishLayerVersion', params)\n .then((result) => {\n this.plugin.log('New layer version published...');\n this.plugin.cacheObject.LayerVersionArn = result.LayerVersionArn;\n return result;\n })\n .catch(e => {\n console.log(e.message);\n process.exit(1);\n });\n }\n}\n\nmodule.exports = LayersService;\n"],"file":"LayersService.js"} \ No newline at end of file +{"version":3,"sources":["../../src/aws/LayersService.js"],"names":["AbstractService","require","LayersService","params","Content","S3Bucket","bucketName","S3Key","zipFileKeyName","LayerName","stackName","Description","CompatibleRuntimes","plugin","settings","compatibleRuntimes","provider","request","then","result","log","cacheObject","LayerVersionArn","catch","e","console","message","process","exit","module","exports"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAMA,eAAe,GAAGC,OAAO,CAAC,oBAAD,CAA/B;;IAEMC,a;;;;;;;;;;;;;;;;;;;;;;;AAEIC,gBAAAA,M,GAAS;AACbC,kBAAAA,OAAO,EAAE;AACPC,oBAAAA,QAAQ,EAAE,KAAKC,UADR;AAEPC,oBAAAA,KAAK,EAAE,KAAKC;AAFL,mBADI;AAKbC,kBAAAA,SAAS,EAAE,KAAKC,SALH;AAMbC,kBAAAA,WAAW,EAAE,qCANA;AAObC,kBAAAA,kBAAkB,EAAE,KAAKC,MAAL,CAAYC,QAAZ,CAAqBC;AAP5B,iB;iDAUR,KAAKC,QAAL,CAAcC,OAAd,CAAsB,QAAtB,EAAgC,qBAAhC,EAAuDd,MAAvD,EACJe,IADI,CACC,UAACC,MAAD,EAAY;AAChB,kBAAA,KAAI,CAACN,MAAL,CAAYO,GAAZ,CAAgB,gCAAhB;;AACA,kBAAA,KAAI,CAACP,MAAL,CAAYQ,WAAZ,CAAwBC,eAAxB,GAA0CH,MAAM,CAACG,eAAjD;AACA,yBAAOH,MAAP;AACD,iBALI,EAMJI,KANI,CAME,UAAAC,CAAC,EAAI;AACVC,kBAAAA,OAAO,CAACL,GAAR,CAAYI,CAAC,CAACE,OAAd;AACAC,kBAAAA,OAAO,CAACC,IAAR,CAAa,CAAb;AACD,iBATI,C;;;;;;;;;;;;;;;;;;EAZiB5B,e;;AAyB5B6B,MAAM,CAACC,OAAP,GAAiB5B,aAAjB","sourcesContent":["const AbstractService = require('../AbstractService');\n\nclass LayersService extends AbstractService {\n async publishVersion() {\n const params = {\n Content: {\n S3Bucket: this.bucketName,\n S3Key: this.zipFileKeyName\n },\n LayerName: this.stackName,\n Description: 'created by serverless-layers plugin',\n CompatibleRuntimes: this.plugin.settings.compatibleRuntimes\n };\n\n return this.provider.request('Lambda', 'publishLayerVersion', params)\n .then((result) => {\n this.plugin.log('New layer version published...');\n this.plugin.cacheObject.LayerVersionArn = result.LayerVersionArn;\n return result;\n })\n .catch(e => {\n console.log(e.message);\n process.exit(1);\n });\n }\n}\n\nmodule.exports = LayersService;\n"],"file":"LayersService.js"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index 993da74..1088a9c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -32,7 +32,7 @@ function () { function ServerlessLayers(serverless, options) { var _this = this; - (0, _classCallCheck2["default"])(this, ServerlessLayers); + (0, _classCallCheck2.default)(this, ServerlessLayers); this.cacheObject = {}; this.options = options; this.serverless = serverless; @@ -69,14 +69,14 @@ function () { }; } - (0, _createClass2["default"])(ServerlessLayers, [{ + (0, _createClass2.default)(ServerlessLayers, [{ key: "init", value: function () { - var _init = (0, _asyncToGenerator2["default"])( + var _init = (0, _asyncToGenerator2.default)( /*#__PURE__*/ - _regenerator["default"].mark(function _callee() { + _regenerator.default.mark(function _callee() { var localpackageJson; - return _regenerator["default"].wrap(function _callee$(_context) { + return _regenerator.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: @@ -114,6 +114,7 @@ function () { value: function getSettings() { var inboundSettings = (this.serverless.service.custom || {})['serverless-layers']; var defaultSettings = { + packageManager: 'npm', compileDir: '.serverless', packagePath: 'package.json', compatibleRuntimes: ['nodejs'], @@ -124,11 +125,11 @@ function () { }, { key: "main", value: function () { - var _main = (0, _asyncToGenerator2["default"])( + var _main = (0, _asyncToGenerator2.default)( /*#__PURE__*/ - _regenerator["default"].mark(function _callee2() { + _regenerator.default.mark(function _callee2() { var remotePackage, isDifferent, currentLayerARN, version; - return _regenerator["default"].wrap(function _callee2$(_context2) { + return _regenerator.default.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: @@ -173,7 +174,7 @@ function () { case 18: _context2.next = 20; - return this.zipService["package"](); + return this.zipService.package(); case 20: _context2.next = 22; @@ -239,11 +240,11 @@ function () { }, { key: "getLayerArn", value: function () { - var _getLayerArn = (0, _asyncToGenerator2["default"])( + var _getLayerArn = (0, _asyncToGenerator2.default)( /*#__PURE__*/ - _regenerator["default"].mark(function _callee3() { + _regenerator.default.mark(function _callee3() { var outputs, logicalId; - return _regenerator["default"].wrap(function _callee3$(_context3) { + return _regenerator.default.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: @@ -309,7 +310,7 @@ function () { this.service.resources = this.service.resources || {}; this.service.resources.Outputs = this.service.resources.Outputs || {}; var outputName = this.getOutputLogicalId(); - Object.assign(this.service.resources.Outputs, (0, _defineProperty2["default"])({}, outputName, { + Object.assign(this.service.resources.Outputs, (0, _defineProperty2.default)({}, outputName, { Value: layerArn, Export: { Name: outputName @@ -343,13 +344,13 @@ function () { }, { key: "finalizeDeploy", value: function () { - var _finalizeDeploy = (0, _asyncToGenerator2["default"])( + var _finalizeDeploy = (0, _asyncToGenerator2.default)( /*#__PURE__*/ - _regenerator["default"].mark(function _callee4() { + _regenerator.default.mark(function _callee4() { var _this4 = this; var currentLayerARN; - return _regenerator["default"].wrap(function _callee4$(_context4) { + return _regenerator.default.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: diff --git a/lib/index.js.map b/lib/index.js.map index 09becd1..90ae5a1 100644 --- a/lib/index.js.map +++ b/lib/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/index.js"],"names":["BbPromise","require","path","LayersService","BucketService","CloudFormationService","ZipService","Dependencies","ServerlessLayers","serverless","options","cacheObject","provider","getProvider","service","region","getRegion","log","bind","main","version","getVersion","replace","process","exit","hooks","then","init","finalizeDeploy","settings","getSettings","zipService","dependencies","layersService","bucketService","cloudFormationService","localpackageJson","join","env","PWD","packagePath","localPackage","e","inboundSettings","custom","defaultSettings","compileDir","compatibleRuntimes","layersDeploymentBucket","deploymentBucket","Object","assign","downloadPackageJson","remotePackage","isDifferent","isDiff","getLayerArn","currentLayerARN","relateLayerWithFunctions","install","uploadZipFile","publishVersion","uploadPackageJson","LayerVersionArn","stage","Error","cwd","getStackName","serviceStage","deploymentPrefix","getDeploymentPrefix","getOutputs","outputs","logicalId","getOutputLogicalId","find","x","OutputKey","OutputValue","naming","getLambdaLayerOutputLogicalId","layerArn","functions","keys","forEach","funcName","layers","push","resources","Outputs","outputName","Value","Export","Name","depsA","depsB","depsKeyA","depsKeyB","isSizeEqual","length","hasDifference","dependence","map","msg","cli","module","exports"],"mappings":";;;;;;;;;;;;;;AAAA,IAAMA,SAAS,GAAGC,OAAO,CAAC,UAAD,CAAzB;;AACA,IAAMC,IAAI,GAAGD,OAAO,CAAC,MAAD,CAApB;;AAEA,IAAME,aAAa,GAAGF,OAAO,CAAC,qBAAD,CAA7B;;AACA,IAAMG,aAAa,GAAGH,OAAO,CAAC,qBAAD,CAA7B;;AACA,IAAMI,qBAAqB,GAAGJ,OAAO,CAAC,6BAAD,CAArC;;AACA,IAAMK,UAAU,GAAGL,OAAO,CAAC,sBAAD,CAA1B;;AACA,IAAMM,YAAY,GAAGN,OAAO,CAAC,wBAAD,CAA5B;;IAEMO,gB;;;AACJ,4BAAYC,UAAZ,EAAwBC,OAAxB,EAAiC;AAAA;;AAAA;AAC/B,SAAKC,WAAL,GAAmB,EAAnB;AACA,SAAKD,OAAL,GAAeA,OAAf;AACA,SAAKD,UAAL,GAAkBA,UAAlB;AAEA,SAAKG,QAAL,GAAgBH,UAAU,CAACI,WAAX,CAAuB,KAAvB,CAAhB;AACA,SAAKC,OAAL,GAAeL,UAAU,CAAC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E8C,G,EAAK;AACP,WAAK9F,UAAL,CAAgB+F,GAAhB,CAAoBvF,GAApB,2BAA2CsF,GAA3C;AACD;;;;;AAGHE,MAAM,CAACC,OAAP,GAAiBlG,gBAAjB","sourcesContent":["const BbPromise = require('bluebird');\nconst path = require('path');\n\nconst LayersService = require('./aws/LayersService');\nconst BucketService = require('./aws/BucketService');\nconst CloudFormationService = require('./aws/CloudFormationService');\nconst ZipService = require('./package/ZipService');\nconst Dependencies = require('./package/Dependencies');\n\nclass ServerlessLayers {\n constructor(serverless, options) {\n this.cacheObject = {};\n this.options = options;\n this.serverless = serverless;\n\n this.provider = serverless.getProvider('aws');\n this.service = serverless.service;\n this.options.region = this.provider.getRegion();\n\n // bindings\n this.log = this.log.bind(this);\n this.main = this.main.bind(this);\n\n const version = serverless.getVersion().replace(/\\./g, '');\n\n if (version < 1340) {\n this.log(`Error: Please install serverless >= 1.34.0 (current ${serverless.getVersion()})`)\n process.exit(1);\n }\n\n // hooks\n this.hooks = {\n 'before:package:initialize': () => BbPromise.bind(this)\n .then(() => this.init()),\n 'package:initialize': () => BbPromise.bind(this)\n .then(() => this.main()),\n 'aws:info:displayLayers': () => BbPromise.bind(this)\n .then(() => this.finalizeDeploy())\n };\n }\n\n async init() {\n this.settings = this.getSettings();\n\n this.zipService = new ZipService(this);\n this.dependencies = new Dependencies(this);\n this.layersService = new LayersService(this);\n this.bucketService = new BucketService(this);\n this.cloudFormationService = new CloudFormationService(this);\n\n const localpackageJson = path.join(\n process.env.PWD,\n this.settings.packagePath\n );\n\n try {\n this.localPackage = require(localpackageJson);\n } catch (e) {\n this.log(`Error: Can not find ${localpackageJson}!`);\n process.exit(1);\n }\n }\n\n getSettings() {\n const inboundSettings = (this.serverless.service.custom || {})[\n 'serverless-layers'\n ];\n const defaultSettings = {\n compileDir: '.serverless',\n packagePath: 'package.json',\n compatibleRuntimes: ['nodejs'],\n layersDeploymentBucket: this.service.provider.deploymentBucket\n };\n return Object.assign({}, defaultSettings, inboundSettings);\n }\n\n async main() {\n const remotePackage = await this.bucketService.downloadPackageJson();\n\n let isDifferent = true;\n if (remotePackage) {\n this.log('Comparing package.json dependencies...');\n isDifferent = await this.isDiff(remotePackage.dependencies, this.localPackage.dependencies);\n }\n\n const currentLayerARN = await this.getLayerArn();\n\n if (!isDifferent && currentLayerARN) {\n this.log(`Not has changed! Using same layer arn: ${currentLayerARN}`);\n this.relateLayerWithFunctions(currentLayerARN);\n return;\n }\n\n await this.dependencies.install()\n await this.zipService.package();\n await this.bucketService.uploadZipFile();\n const version = await this.layersService.publishVersion();\n await this.bucketService.uploadPackageJson();\n\n this.relateLayerWithFunctions(version.LayerVersionArn);\n }\n\n getStackName() {\n return `${this.serverless.service.service}-${this.options.stage}`;\n }\n\n getBucketName() {\n if (!this.settings.layersDeploymentBucket) {\n throw new Error(\n 'Please, you should specify \"deploymentBucket\" or \"layersDeploymentBucket\" option for this plugin!\\n'\n );\n }\n return this.settings.layersDeploymentBucket;\n }\n\n getPathZipFileName() {\n return `${path.join(process.cwd(), this.settings.compileDir, this.getStackName())}.zip`;\n }\n\n getBucketLayersPath() {\n const serviceStage = `${this.serverless.service.service}/${this.options.stage}`;\n\n let deploymentPrefix = 'serverless';\n if (this.provider.getDeploymentPrefix) {\n deploymentPrefix = this.provider.getDeploymentPrefix();\n }\n\n return path.join(\n deploymentPrefix,\n serviceStage,\n 'layers'\n );\n }\n\n async getLayerArn() {\n if (this.cacheObject.LayerVersionArn) {\n return this.cacheObject.LayerVersionArn;\n }\n const outputs = await this.cloudFormationService.getOutputs();\n if (!outputs) return null;\n const logicalId = this.getOutputLogicalId();\n return (outputs.find(x => x.OutputKey === logicalId) || {}).OutputValue;\n }\n\n getOutputLogicalId() {\n return this.provider.naming.getLambdaLayerOutputLogicalId(this.getStackName());\n }\n\n relateLayerWithFunctions(layerArn) {\n this.log('Associating layers...');\n\n const { functions } = this.service;\n\n Object.keys(functions).forEach(funcName => {\n functions[funcName].layers = functions[funcName].layers || [];\n functions[funcName].layers.push(layerArn);\n this.log(`function.${funcName} - ${layerArn}`);\n });\n\n this.service.resources = this.service.resources || {};\n this.service.resources.Outputs = this.service.resources.Outputs || {};\n\n const outputName = this.getOutputLogicalId();\n\n Object.assign(this.service.resources.Outputs, {\n [outputName]: {\n Value: layerArn,\n Export: {\n Name: outputName\n }\n }\n });\n }\n\n isDiff(depsA, depsB) {\n const depsKeyA = Object.keys(depsA);\n const depsKeyB = Object.keys(depsB);\n const isSizeEqual = depsKeyA.length === depsKeyB.length;\n\n if (!isSizeEqual) return true;\n\n let hasDifference = false;\n Object.keys(depsA).forEach(dependence => {\n if (depsA[dependence] !== depsB[dependence]) {\n hasDifference = true;\n }\n });\n\n return hasDifference;\n }\n\n getDependenciesList() {\n return Object.keys((this.localPackage.dependencies||[])).map(x => (\n `${x}@${this.localPackage.dependencies[x]}`\n ));\n }\n\n async finalizeDeploy() {\n const currentLayerARN = await this.getLayerArn();\n Object.keys(this.service.functions).forEach(funcName => {\n this.log(`function.${funcName} = layers.${currentLayerARN}`);\n });\n }\n\n log(msg) {\n this.serverless.cli.log(`[LayersPlugin]: ${msg}`);\n }\n}\n\nmodule.exports = ServerlessLayers;\n"],"file":"index.js"} \ No newline at end of file +{"version":3,"sources":["../src/index.js"],"names":["BbPromise","require","path","LayersService","BucketService","CloudFormationService","ZipService","Dependencies","ServerlessLayers","serverless","options","cacheObject","provider","getProvider","service","region","getRegion","log","bind","main","version","getVersion","replace","process","exit","hooks","then","init","finalizeDeploy","settings","getSettings","zipService","dependencies","layersService","bucketService","cloudFormationService","localpackageJson","join","env","PWD","packagePath","localPackage","e","inboundSettings","custom","defaultSettings","packageManager","compileDir","compatibleRuntimes","layersDeploymentBucket","deploymentBucket","Object","assign","downloadPackageJson","remotePackage","isDifferent","isDiff","getLayerArn","currentLayerARN","relateLayerWithFunctions","install","package","uploadZipFile","publishVersion","uploadPackageJson","LayerVersionArn","stage","Error","cwd","getStackName","serviceStage","deploymentPrefix","getDeploymentPrefix","getOutputs","outputs","logicalId","getOutputLogicalId","find","x","OutputKey","OutputValue","naming","getLambdaLayerOutputLogicalId","layerArn","functions","keys","forEach","funcName","layers","push","resources","Outputs","outputName","Value","Export","Name","depsA","depsB","depsKeyA","depsKeyB","isSizeEqual","length","hasDifference","dependence","map","msg","cli","module","exports"],"mappings":";;;;;;;;;;;;;;AAAA,IAAMA,SAAS,GAAGC,OAAO,CAAC,UAAD,CAAzB;;AACA,IAAMC,IAAI,GAAGD,OAAO,CAAC,MAAD,CAApB;;AAEA,IAAME,aAAa,GAAGF,OAAO,CAAC,qBAAD,CAA7B;;AACA,IAAMG,aAAa,GAAGH,OAAO,CAAC,qBAAD,CAA7B;;AACA,IAAMI,qBAAqB,GAAGJ,OAAO,CAAC,6BAAD,CAArC;;AACA,IAAMK,UAAU,GAAGL,OAAO,CAAC,sBAAD,CAA1B;;AACA,IAAMM,YAAY,GAAGN,OAAO,CAAC,wBAAD,CAA5B;;IAEMO,gB;;;AACJ,4BAAYC,UAAZ,EAAwBC,OAAxB,EAAiC;AAAA;;AAAA;AAC/B,SAAKC,WAAL,GAAmB,EAAnB;AACA,SAAKD,OAAL,GAAeA,OAAf;AACA,SAAKD,UAAL,GAAkBA,UAAlB;AAEA,SAAKG,QAAL,GAAgBH,UAAU,CAACI,WAAX,CAAuB,KAAvB,CAAhB;AACA,SAAKC,OAAL,GAAeL,UAAU,CAACK,OAA1B;AACA,SAAKJ,OAAL,CAAaK,MAAb,GAAsB,KAAKH,QAAL,CAAcI,SAAd,EAAtB,CAP+B,CAS/B;;AACA,SAAKC,GAAL,GAAW,KAAKA,GAAL,CAASC,IAAT,CAAc,IAAd,CAAX;AACA,SAAKC,IAAL,GAAY,KAAKA,IAAL,CAAUD,IAAV,CAAe,IAAf,CAAZ;AAEA,QAAME,OAAO,GAAGX,UAAU,CAACY,UAAX,GAAwBC,OAAxB,CAAgC,KAAhC,EAAuC,EAAvC,CAAhB;;AAEA,QAAIF,OAAO,GAAG,IAAd,EAAoB;AAClB,W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GAAGF,QAAQ,CAACG,MAAT,KAAoBF,QAAQ,CAACE,MAAjD;AAEA,UAAI,CAACD,WAAL,EAAkB,OAAO,IAAP;AAElB,UAAIE,aAAa,GAAG,KAApB;AACAnD,MAAAA,MAAM,CAACkC,IAAP,CAAYW,KAAZ,EAAmBV,OAAnB,CAA2B,UAAAiB,UAAU,EAAI;AACvC,YAAIP,KAAK,CAACO,UAAD,CAAL,KAAsBN,KAAK,CAACM,UAAD,CAA/B,EAA6C;AAC3CD,UAAAA,aAAa,GAAG,IAAhB;AACD;AACF,OAJD;AAMA,aAAOA,aAAP;AACD;;;0CAEqB;AAAA;;AACpB,aAAOnD,MAAM,CAACkC,IAAP,CAAa,KAAK5C,YAAL,CAAkBT,YAAlB,IAAgC,EAA7C,EAAkDwE,GAAlD,CAAsD,UAAA1B,CAAC;AAAA,yBACzDA,CADyD,cACpD,MAAI,CAACrC,YAAL,CAAkBT,YAAlB,CAA+B8C,CAA/B,CADoD;AAAA,OAAvD,CAAP;AAGD;;;;;;;;;;;;;;;uBAG+B,KAAKrB,WAAL,E;;;AAAxBC,gBAAAA,e;AACNP,gBAAAA,MAAM,CAACkC,IAAP,CAAY,KAAKvE,OAAL,CAAasE,SAAzB,EAAoCE,OAApC,CAA4C,UAAAC,QAAQ,EAAI;AACtD,kBAAA,MAAI,CAACtE,GAAL,oBAAqBsE,QAArB,uBAA0C7B,eAA1C;AACD,iBAFD;;;;;;;;;;;;;;;;;;wBAKE+C,G,EAAK;AACP,WAAKhG,UAAL,CAAgBiG,GAAhB,CAAoBzF,GAApB,2BAA2CwF,GAA3C;AACD;;;;;AAGHE,MAAM,CAACC,OAAP,GAAiBpG,gBAAjB","sourcesContent":["const BbPromise = require('bluebird');\nconst path = require('path');\n\nconst LayersService = require('./aws/LayersService');\nconst BucketService = require('./aws/BucketService');\nconst CloudFormationService = require('./aws/CloudFormationService');\nconst ZipService = require('./package/ZipService');\nconst Dependencies = require('./package/Dependencies');\n\nclass ServerlessLayers {\n constructor(serverless, options) {\n this.cacheObject = {};\n this.options = options;\n this.serverless = serverless;\n\n this.provider = serverless.getProvider('aws');\n this.service = serverless.service;\n this.options.region = this.provider.getRegion();\n\n // bindings\n this.log = this.log.bind(this);\n this.main = this.main.bind(this);\n\n const version = serverless.getVersion().replace(/\\./g, '');\n\n if (version < 1340) {\n this.log(`Error: Please install serverless >= 1.34.0 (current ${serverless.getVersion()})`)\n process.exit(1);\n }\n\n // hooks\n this.hooks = {\n 'before:package:initialize': () => BbPromise.bind(this)\n .then(() => this.init()),\n 'package:initialize': () => BbPromise.bind(this)\n .then(() => this.main()),\n 'aws:info:displayLayers': () => BbPromise.bind(this)\n .then(() => this.finalizeDeploy())\n };\n }\n\n async init() {\n this.settings = this.getSettings();\n\n this.zipService = new ZipService(this);\n this.dependencies = new Dependencies(this);\n this.layersService = new LayersService(this);\n this.bucketService = new BucketService(this);\n this.cloudFormationService = new CloudFormationService(this);\n\n const localpackageJson = path.join(\n process.env.PWD,\n this.settings.packagePath\n );\n\n try {\n this.localPackage = require(localpackageJson);\n } catch (e) {\n this.log(`Error: Can not find ${localpackageJson}!`);\n process.exit(1);\n }\n }\n\n getSettings() {\n const inboundSettings = (this.serverless.service.custom || {})[\n 'serverless-layers'\n ];\n const defaultSettings = {\n packageManager: 'npm',\n compileDir: '.serverless',\n packagePath: 'package.json',\n compatibleRuntimes: ['nodejs'],\n layersDeploymentBucket: this.service.provider.deploymentBucket\n };\n return Object.assign({}, defaultSettings, inboundSettings);\n }\n\n async main() {\n const remotePackage = await this.bucketService.downloadPackageJson();\n\n let isDifferent = true;\n if (remotePackage) {\n this.log('Comparing package.json dependencies...');\n isDifferent = await this.isDiff(remotePackage.dependencies, this.localPackage.dependencies);\n }\n\n const currentLayerARN = await this.getLayerArn();\n if (!isDifferent && currentLayerARN) {\n this.log(`Not has changed! Using same layer arn: ${currentLayerARN}`);\n this.relateLayerWithFunctions(currentLayerARN);\n return;\n }\n\n await this.dependencies.install()\n await this.zipService.package();\n await this.bucketService.uploadZipFile();\n const version = await this.layersService.publishVersion();\n await this.bucketService.uploadPackageJson();\n\n this.relateLayerWithFunctions(version.LayerVersionArn);\n }\n\n getStackName() {\n return `${this.serverless.service.service}-${this.options.stage}`;\n }\n\n getBucketName() {\n if (!this.settings.layersDeploymentBucket) {\n throw new Error(\n 'Please, you should specify \"deploymentBucket\" or \"layersDeploymentBucket\" option for this plugin!\\n'\n );\n }\n return this.settings.layersDeploymentBucket;\n }\n\n getPathZipFileName() {\n return `${path.join(process.cwd(), this.settings.compileDir, this.getStackName())}.zip`;\n }\n\n getBucketLayersPath() {\n const serviceStage = `${this.serverless.service.service}/${this.options.stage}`;\n\n let deploymentPrefix = 'serverless';\n if (this.provider.getDeploymentPrefix) {\n deploymentPrefix = this.provider.getDeploymentPrefix();\n }\n\n return path.join(\n deploymentPrefix,\n serviceStage,\n 'layers'\n );\n }\n\n async getLayerArn() {\n if (this.cacheObject.LayerVersionArn) {\n return this.cacheObject.LayerVersionArn;\n }\n const outputs = await this.cloudFormationService.getOutputs();\n if (!outputs) return null;\n const logicalId = this.getOutputLogicalId();\n return (outputs.find(x => x.OutputKey === logicalId) || {}).OutputValue;\n }\n\n getOutputLogicalId() {\n return this.provider.naming.getLambdaLayerOutputLogicalId(this.getStackName());\n }\n\n relateLayerWithFunctions(layerArn) {\n this.log('Associating layers...');\n\n const { functions } = this.service;\n\n Object.keys(functions).forEach(funcName => {\n functions[funcName].layers = functions[funcName].layers || [];\n functions[funcName].layers.push(layerArn);\n this.log(`function.${funcName} - ${layerArn}`);\n });\n\n this.service.resources = this.service.resources || {};\n this.service.resources.Outputs = this.service.resources.Outputs || {};\n\n const outputName = this.getOutputLogicalId();\n\n Object.assign(this.service.resources.Outputs, {\n [outputName]: {\n Value: layerArn,\n Export: {\n Name: outputName\n }\n }\n });\n }\n\n isDiff(depsA, depsB) {\n const depsKeyA = Object.keys(depsA);\n const depsKeyB = Object.keys(depsB);\n const isSizeEqual = depsKeyA.length === depsKeyB.length;\n\n if (!isSizeEqual) return true;\n\n let hasDifference = false;\n Object.keys(depsA).forEach(dependence => {\n if (depsA[dependence] !== depsB[dependence]) {\n hasDifference = true;\n }\n });\n\n return hasDifference;\n }\n\n getDependenciesList() {\n return Object.keys((this.localPackage.dependencies||[])).map(x => (\n `${x}@${this.localPackage.dependencies[x]}`\n ));\n }\n\n async finalizeDeploy() {\n const currentLayerARN = await this.getLayerArn();\n Object.keys(this.service.functions).forEach(funcName => {\n this.log(`function.${funcName} = layers.${currentLayerARN}`);\n });\n }\n\n log(msg) {\n this.serverless.cli.log(`[LayersPlugin]: ${msg}`);\n }\n}\n\nmodule.exports = ServerlessLayers;\n"],"file":"index.js"} \ No newline at end of file diff --git a/lib/package/Dependencies.js b/lib/package/Dependencies.js index d2f813b..f0bca41 100644 --- a/lib/package/Dependencies.js +++ b/lib/package/Dependencies.js @@ -16,11 +16,13 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); +var fs = require('fs'); + var path = require('path'); var mkdirp = require('mkdirp'); -var _install = require('npm-install-package'); +var exec = require('child_process').execSync; var copyFile = require('fs-copy-file'); // v6.10.3 support @@ -30,53 +32,92 @@ var AbstractService = require('../AbstractService'); var Dependencies = /*#__PURE__*/ function (_AbstractService) { - (0, _inherits2["default"])(Dependencies, _AbstractService); + (0, _inherits2.default)(Dependencies, _AbstractService); function Dependencies() { - (0, _classCallCheck2["default"])(this, Dependencies); - return (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(Dependencies).apply(this, arguments)); + (0, _classCallCheck2.default)(this, Dependencies); + return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Dependencies).apply(this, arguments)); } - (0, _createClass2["default"])(Dependencies, [{ + (0, _createClass2.default)(Dependencies, [{ + key: "init", + value: function init() { + this.commands = { + npm: 'npm install', + yarn: 'yarn' + }; + this.initialCwd = process.cwd(); + this.nodeJsDir = path.join(process.cwd(), this.plugin.settings.compileDir, 'layers', 'nodejs'); + } + }, { + key: "run", + value: function run(cmd) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; + console.log(exec(cmd, options).toString()); + } + }, { + key: "copyProjectFile", + value: function copyProjectFile(filename) { + var _this = this; + + this.init(); + + if (!fs.existsSync(filename)) { + this.plugin.log("[warning] \"".concat(filename, "\" file does not exists!")); + return true; + } + + return new Promise(function (resolve) { + copyFile(filename, path.join(_this.nodeJsDir, filename), function (copyErr) { + if (copyErr) throw copyErr; + return resolve(); + }); + }); + } + }, { key: "install", value: function () { - var _install2 = (0, _asyncToGenerator2["default"])( + var _install = (0, _asyncToGenerator2.default)( /*#__PURE__*/ - _regenerator["default"].mark(function _callee() { - var _this = this; - - var initialCwd, nodeJsDir; - return _regenerator["default"].wrap(function _callee$(_context) { + _regenerator.default.mark(function _callee() { + return _regenerator.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: + this.init(); this.plugin.log('Dependencies has changed! Re-installing...'); - initialCwd = process.cwd(); - nodeJsDir = path.join(process.cwd(), this.plugin.settings.compileDir, 'layers', 'nodejs'); - _context.next = 5; - return mkdirp.sync(nodeJsDir); - - case 5: - return _context.abrupt("return", new Promise(function (resolve) { - copyFile(_this.plugin.settings.packagePath, path.join(nodeJsDir, 'package.json'), function (copyErr) { - if (copyErr) throw copyErr; // install deps - - process.chdir(nodeJsDir); - var opts = { - saveDev: false, - cache: true, - silent: false - }; - - _install(_this.plugin.getDependenciesList(), opts, function (installErr) { - process.chdir(initialCwd); - if (installErr) throw installErr; - resolve(); - }); - }); - })); + _context.next = 4; + return mkdirp.sync(this.nodeJsDir); + + case 4: + _context.next = 6; + return this.copyProjectFile(this.plugin.settings.packagePath); case 6: + if (!(this.plugin.settings.packageManager === 'npm')) { + _context.next = 9; + break; + } + + _context.next = 9; + return this.copyProjectFile('package-lock.json'); + + case 9: + if (!(this.plugin.settings.packageManager === 'yarn')) { + _context.next = 12; + break; + } + + _context.next = 12; + return this.copyProjectFile('yarn.lock'); + + case 12: + process.chdir(this.nodeJsDir); // packages installation + + this.run(this.commands[this.plugin.settings.packageManager]); + process.chdir(this.initialCwd); + + case 15: case "end": return _context.stop(); } @@ -85,7 +126,7 @@ function (_AbstractService) { })); function install() { - return _install2.apply(this, arguments); + return _install.apply(this, arguments); } return install; diff --git a/lib/package/Dependencies.js.map b/lib/package/Dependencies.js.map index b0a9276..f147098 100644 --- a/lib/package/Dependencies.js.map +++ b/lib/package/Dependencies.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/package/Dependencies.js"],"names":["path","require","mkdirp","install","copyFile","AbstractService","Dependencies","plugin","log","initialCwd","process","cwd","nodeJsDir","join","settings","compileDir","sync","Promise","resolve","packagePath","copyErr","chdir","opts","saveDev","cache","silent","getDependenciesList","installErr","module","exports"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAMA,IAAI,GAAGC,OAAO,CAAC,MAAD,CAApB;;AACA,IAAMC,MAAM,GAAGD,OAAO,CAAC,QAAD,CAAtB;;AACA,IAAME,QAAO,GAAGF,OAAO,CAAC,qBAAD,CAAvB;;AACA,IAAMG,QAAQ,GAAGH,OAAO,CAAC,cAAD,CAAxB,C,CAA0C;;;AAE1C,IAAMI,eAAe,GAAGJ,OAAO,CAAC,oBAAD,CAA/B;;IAEMK,Y;;;;;;;;;;;;;;;;;;;;;;;AAEF,qBAAKC,MAAL,CAAYC,GAAZ,CAAgB,4CAAhB;AAEMC,gBAAAA,U,GAAaC,OAAO,CAACC,GAAR,E;AACbC,gBAAAA,S,GAAYZ,IAAI,CAACa,IAAL,CAAUH,OAAO,CAACC,GAAR,EAAV,EAAyB,KAAKJ,MAAL,CAAYO,QAAZ,CAAqBC,UAA9C,EAA0D,QAA1D,EAAoE,QAApE,C;;uBAEZb,MAAM,CAACc,IAAP,CAAYJ,SAAZ,C;;;iDAEC,IAAIK,OAAJ,CAAY,UAACC,OAAD,EAAa;AAC9Bd,kBAAAA,QAAQ,CAAC,KAAI,CAACG,MAAL,CAAYO,QAAZ,CAAqBK,WAAtB,EAAmCnB,IAAI,CAACa,IAAL,CAAUD,SAAV,EAAqB,cAArB,CAAnC,EAAyE,UAACQ,OAAD,EAAa;AAC5F,wBAAIA,OAAJ,EAAa,MAAMA,OAAN,CAD+E,CAG5F;;AACAV,oBAAAA,OAAO,CAACW,KAAR,CAAcT,SAAd;AAEA,wBAAMU,IAAI,GAAG;AAAEC,sBAAAA,OAAO,EAAE,KAAX;AAAkBC,sBAAAA,KAAK,EAAE,IAAzB;AAA+BC,sBAAAA,MAAM,EAAE;AAAvC,qBAAb;;AAEAtB,oBAAAA,QAAO,CAAC,KAAI,CAACI,MAAL,CAAYmB,mBAAZ,EAAD,EAAoCJ,IAApC,EAA0C,UAACK,UAAD,EAAgB;AAC/DjB,sBAAAA,OAAO,CAACW,KAAR,CAAcZ,UAAd;AACA,0BAAIkB,UAAJ,EAAgB,MAAMA,UAAN;AAChBT,sBAAAA,OAAO;AACR,qBAJM,CAAP;AAKD,mBAbO,CAAR;AAcD,iBAfM,C;;;;;;;;;;;;;;;;;;EATgBb,e;;AA4B3BuB,MAAM,CAACC,OAAP,GAAiBvB,YAAjB","sourcesContent":["const path = require('path');\nconst mkdirp = require('mkdirp');\nconst install = require('npm-install-package');\nconst copyFile = require('fs-copy-file'); // v6.10.3 support\n\nconst AbstractService = require('../AbstractService');\n\nclass Dependencies extends AbstractService {\n async install() {\n this.plugin.log('Dependencies has changed! Re-installing...');\n\n const initialCwd = process.cwd();\n const nodeJsDir = path.join(process.cwd(), this.plugin.settings.compileDir, 'layers', 'nodejs');\n\n await mkdirp.sync(nodeJsDir);\n\n return new Promise((resolve) => {\n copyFile(this.plugin.settings.packagePath, path.join(nodeJsDir, 'package.json'), (copyErr) => {\n if (copyErr) throw copyErr;\n\n // install deps\n process.chdir(nodeJsDir);\n\n const opts = { saveDev: false, cache: true, silent: false };\n\n install(this.plugin.getDependenciesList(), opts, (installErr) => {\n process.chdir(initialCwd);\n if (installErr) throw installErr;\n resolve();\n });\n });\n });\n }\n}\n\nmodule.exports = Dependencies;\n"],"file":"Dependencies.js"} \ No newline at end of file +{"version":3,"sources":["../../src/package/Dependencies.js"],"names":["fs","require","path","mkdirp","exec","execSync","copyFile","AbstractService","Dependencies","commands","npm","yarn","initialCwd","process","cwd","nodeJsDir","join","plugin","settings","compileDir","cmd","options","console","log","toString","filename","init","existsSync","Promise","resolve","copyErr","sync","copyProjectFile","packagePath","packageManager","chdir","run","module","exports"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAMA,EAAE,GAAGC,OAAO,CAAC,IAAD,CAAlB;;AACA,IAAMC,IAAI,GAAGD,OAAO,CAAC,MAAD,CAApB;;AACA,IAAME,MAAM,GAAGF,OAAO,CAAC,QAAD,CAAtB;;AACA,IAAMG,IAAI,GAAGH,OAAO,CAAC,eAAD,CAAP,CAAyBI,QAAtC;;AACA,IAAMC,QAAQ,GAAGL,OAAO,CAAC,cAAD,CAAxB,C,CAA0C;;;AAE1C,IAAMM,eAAe,GAAGN,OAAO,CAAC,oBAAD,CAA/B;;IAGMO,Y;;;;;;;;;;;;2BACG;AACL,WAAKC,QAAL,GAAgB;AACdC,QAAAA,GAAG,EAAE,aADS;AAEdC,QAAAA,IAAI,EAAE;AAFQ,OAAhB;AAIA,WAAKC,UAAL,GAAkBC,OAAO,CAACC,GAAR,EAAlB;AACA,WAAKC,SAAL,GAAiBb,IAAI,CAACc,IAAL,CAAUH,OAAO,CAACC,GAAR,EAAV,EAAyB,KAAKG,MAAL,CAAYC,QAAZ,CAAqBC,UAA9C,EAA0D,QAA1D,EAAoE,QAApE,CAAjB;AACD;;;wBAEGC,G,EAAmB;AAAA,UAAdC,OAAc,uEAAJ,EAAI;AACrBC,MAAAA,OAAO,CAACC,GAAR,CAAYnB,IAAI,CAACgB,GAAD,EAAMC,OAAN,CAAJ,CAAmBG,QAAnB,EAAZ;AACD;;;oCAEeC,Q,EAAU;AA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('mkdirp');\nconst exec = require('child_process').execSync;\nconst copyFile = require('fs-copy-file'); // v6.10.3 support\n\nconst AbstractService = require('../AbstractService');\n\n\nclass Dependencies extends AbstractService {\n init() {\n this.commands = {\n npm: 'npm install',\n yarn: 'yarn'\n };\n this.initialCwd = process.cwd();\n this.nodeJsDir = path.join(process.cwd(), this.plugin.settings.compileDir, 'layers', 'nodejs');\n }\n\n run(cmd, options = []) {\n console.log(exec(cmd, options).toString());\n }\n\n copyProjectFile(filename) {\n this.init();\n\n if (!fs.existsSync(filename)) {\n this.plugin.log(`[warning] \"${filename}\" file does not exists!`);\n return true;\n }\n\n return new Promise((resolve) => {\n copyFile(filename, path.join(this.nodeJsDir, filename), (copyErr) => {\n if (copyErr) throw copyErr;\n return resolve();\n });\n });\n }\n\n async install() {\n this.init();\n this.plugin.log('Dependencies has changed! Re-installing...');\n\n await mkdirp.sync(this.nodeJsDir);\n await this.copyProjectFile(this.plugin.settings.packagePath);\n\n if (this.plugin.settings.packageManager === 'npm') {\n await this.copyProjectFile('package-lock.json');\n }\n\n if (this.plugin.settings.packageManager === 'yarn') {\n await this.copyProjectFile('yarn.lock');\n }\n\n process.chdir(this.nodeJsDir);\n\n // packages installation\n this.run(this.commands[this.plugin.settings.packageManager]);\n\n process.chdir(this.initialCwd);\n }\n}\n\nmodule.exports = Dependencies;\n"],"file":"Dependencies.js"} \ No newline at end of file diff --git a/lib/package/ZipService.js b/lib/package/ZipService.js index 3419dc5..7e290c5 100644 --- a/lib/package/ZipService.js +++ b/lib/package/ZipService.js @@ -25,14 +25,14 @@ var AbstractService = require('../AbstractService'); var ZipService = /*#__PURE__*/ function (_AbstractService) { - (0, _inherits2["default"])(ZipService, _AbstractService); + (0, _inherits2.default)(ZipService, _AbstractService); function ZipService() { - (0, _classCallCheck2["default"])(this, ZipService); - return (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(ZipService).apply(this, arguments)); + (0, _classCallCheck2.default)(this, ZipService); + return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(ZipService).apply(this, arguments)); } - (0, _createClass2["default"])(ZipService, [{ + (0, _createClass2.default)(ZipService, [{ key: "package", value: function _package() { var _this = this; diff --git a/src/index.js b/src/index.js index 91078d9..f4fc256 100644 --- a/src/index.js +++ b/src/index.js @@ -66,6 +66,7 @@ class ServerlessLayers { 'serverless-layers' ]; const defaultSettings = { + packageManager: 'npm', compileDir: '.serverless', packagePath: 'package.json', compatibleRuntimes: ['nodejs'], @@ -84,7 +85,6 @@ class ServerlessLayers { } const currentLayerARN = await this.getLayerArn(); - if (!isDifferent && currentLayerARN) { this.log(`Not has changed! Using same layer arn: ${currentLayerARN}`); this.relateLayerWithFunctions(currentLayerARN); diff --git a/src/package/Dependencies.js b/src/package/Dependencies.js index 99ef4a1..481c315 100644 --- a/src/package/Dependencies.js +++ b/src/package/Dependencies.js @@ -1,35 +1,63 @@ +const fs = require('fs'); const path = require('path'); const mkdirp = require('mkdirp'); -const install = require('npm-install-package'); +const exec = require('child_process').execSync; const copyFile = require('fs-copy-file'); // v6.10.3 support const AbstractService = require('../AbstractService'); + class Dependencies extends AbstractService { - async install() { - this.plugin.log('Dependencies has changed! Re-installing...'); + init() { + this.commands = { + npm: 'npm install', + yarn: 'yarn' + }; + this.initialCwd = process.cwd(); + this.nodeJsDir = path.join(process.cwd(), this.plugin.settings.compileDir, 'layers', 'nodejs'); + } - const initialCwd = process.cwd(); - const nodeJsDir = path.join(process.cwd(), this.plugin.settings.compileDir, 'layers', 'nodejs'); + run(cmd, options = []) { + console.log(exec(cmd, options).toString()); + } - await mkdirp.sync(nodeJsDir); + copyProjectFile(filename) { + this.init(); + + if (!fs.existsSync(filename)) { + this.plugin.log(`[warning] "${filename}" file does not exists!`); + return true; + } return new Promise((resolve) => { - copyFile(this.plugin.settings.packagePath, path.join(nodeJsDir, 'package.json'), (copyErr) => { + copyFile(filename, path.join(this.nodeJsDir, filename), (copyErr) => { if (copyErr) throw copyErr; + return resolve(); + }); + }); + } - // install deps - process.chdir(nodeJsDir); + async install() { + this.init(); + this.plugin.log('Dependencies has changed! Re-installing...'); - const opts = { saveDev: false, cache: true, silent: false }; + await mkdirp.sync(this.nodeJsDir); + await this.copyProjectFile(this.plugin.settings.packagePath); - install(this.plugin.getDependenciesList(), opts, (installErr) => { - process.chdir(initialCwd); - if (installErr) throw installErr; - resolve(); - }); - }); - }); + if (this.plugin.settings.packageManager === 'npm') { + await this.copyProjectFile('package-lock.json'); + } + + if (this.plugin.settings.packageManager === 'yarn') { + await this.copyProjectFile('yarn.lock'); + } + + process.chdir(this.nodeJsDir); + + // packages installation + this.run(this.commands[this.plugin.settings.packageManager]); + + process.chdir(this.initialCwd); } }