@front10/danger-plugins 2.0.0-alpha.1 → 2.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,5 @@
1
- import NetlifyAPI from 'netlify';
2
1
  import fs__default, { existsSync, readFileSync, readdirSync, lstatSync, readFile as readFile$1 } from 'fs';
3
- import { fetch } from 'undici';
2
+ import fetch from 'node-fetch';
4
3
  import path from 'path';
5
4
  import zlib from 'zlib';
6
5
  import { promisify } from 'util';
@@ -41,81 +40,6 @@ function _asyncToGenerator(fn) {
41
40
  };
42
41
  }
43
42
 
44
- function _extends() {
45
- _extends = Object.assign || function (target) {
46
- for (var i = 1; i < arguments.length; i++) {
47
- var source = arguments[i];
48
-
49
- for (var key in source) {
50
- if (Object.prototype.hasOwnProperty.call(source, key)) {
51
- target[key] = source[key];
52
- }
53
- }
54
- }
55
-
56
- return target;
57
- };
58
-
59
- return _extends.apply(this, arguments);
60
- }
61
-
62
- function _objectWithoutPropertiesLoose(source, excluded) {
63
- if (source == null) return {};
64
- var target = {};
65
- var sourceKeys = Object.keys(source);
66
- var key, i;
67
-
68
- for (i = 0; i < sourceKeys.length; i++) {
69
- key = sourceKeys[i];
70
- if (excluded.indexOf(key) >= 0) continue;
71
- target[key] = source[key];
72
- }
73
-
74
- return target;
75
- }
76
-
77
- function _unsupportedIterableToArray(o, minLen) {
78
- if (!o) return;
79
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
80
- var n = Object.prototype.toString.call(o).slice(8, -1);
81
- if (n === "Object" && o.constructor) n = o.constructor.name;
82
- if (n === "Map" || n === "Set") return Array.from(o);
83
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
84
- }
85
-
86
- function _arrayLikeToArray(arr, len) {
87
- if (len == null || len > arr.length) len = arr.length;
88
-
89
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
90
-
91
- return arr2;
92
- }
93
-
94
- function _createForOfIteratorHelperLoose(o, allowArrayLike) {
95
- var it;
96
-
97
- if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
98
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
99
- if (it) o = it;
100
- var i = 0;
101
- return function () {
102
- if (i >= o.length) return {
103
- done: true
104
- };
105
- return {
106
- done: false,
107
- value: o[i++]
108
- };
109
- };
110
- }
111
-
112
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
113
- }
114
-
115
- it = o[Symbol.iterator]();
116
- return it.next.bind(it);
117
- }
118
-
119
43
  function createCommonjsModule(fn, module) {
120
44
  return module = { exports: {} }, fn(module, module.exports), module.exports;
121
45
  }
@@ -138,24 +62,6 @@ var runtime = (function (exports) {
138
62
  var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
139
63
  var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
140
64
 
141
- function define(obj, key, value) {
142
- Object.defineProperty(obj, key, {
143
- value: value,
144
- enumerable: true,
145
- configurable: true,
146
- writable: true
147
- });
148
- return obj[key];
149
- }
150
- try {
151
- // IE 8 has a broken Object.defineProperty that only works on DOM objects.
152
- define({}, "");
153
- } catch (err) {
154
- define = function(obj, key, value) {
155
- return obj[key] = value;
156
- };
157
- }
158
-
159
65
  function wrap(innerFn, outerFn, self, tryLocsList) {
160
66
  // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
161
67
  var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
@@ -208,9 +114,9 @@ var runtime = (function (exports) {
208
114
  // This is a polyfill for %IteratorPrototype% for environments that
209
115
  // don't natively support it.
210
116
  var IteratorPrototype = {};
211
- define(IteratorPrototype, iteratorSymbol, function () {
117
+ IteratorPrototype[iteratorSymbol] = function () {
212
118
  return this;
213
- });
119
+ };
214
120
 
215
121
  var getProto = Object.getPrototypeOf;
216
122
  var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
@@ -224,22 +130,18 @@ var runtime = (function (exports) {
224
130
 
225
131
  var Gp = GeneratorFunctionPrototype.prototype =
226
132
  Generator.prototype = Object.create(IteratorPrototype);
227
- GeneratorFunction.prototype = GeneratorFunctionPrototype;
228
- define(Gp, "constructor", GeneratorFunctionPrototype);
229
- define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
230
- GeneratorFunction.displayName = define(
231
- GeneratorFunctionPrototype,
232
- toStringTagSymbol,
233
- "GeneratorFunction"
234
- );
133
+ GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
134
+ GeneratorFunctionPrototype.constructor = GeneratorFunction;
135
+ GeneratorFunctionPrototype[toStringTagSymbol] =
136
+ GeneratorFunction.displayName = "GeneratorFunction";
235
137
 
236
138
  // Helper for defining the .next, .throw, and .return methods of the
237
139
  // Iterator interface in terms of a single ._invoke method.
238
140
  function defineIteratorMethods(prototype) {
239
141
  ["next", "throw", "return"].forEach(function(method) {
240
- define(prototype, method, function(arg) {
142
+ prototype[method] = function(arg) {
241
143
  return this._invoke(method, arg);
242
- });
144
+ };
243
145
  });
244
146
  }
245
147
 
@@ -258,7 +160,9 @@ var runtime = (function (exports) {
258
160
  Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
259
161
  } else {
260
162
  genFun.__proto__ = GeneratorFunctionPrototype;
261
- define(genFun, toStringTagSymbol, "GeneratorFunction");
163
+ if (!(toStringTagSymbol in genFun)) {
164
+ genFun[toStringTagSymbol] = "GeneratorFunction";
165
+ }
262
166
  }
263
167
  genFun.prototype = Object.create(Gp);
264
168
  return genFun;
@@ -340,9 +244,9 @@ var runtime = (function (exports) {
340
244
  }
341
245
 
342
246
  defineIteratorMethods(AsyncIterator.prototype);
343
- define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
247
+ AsyncIterator.prototype[asyncIteratorSymbol] = function () {
344
248
  return this;
345
- });
249
+ };
346
250
  exports.AsyncIterator = AsyncIterator;
347
251
 
348
252
  // Note that simple async functions are implemented on top of
@@ -528,20 +432,20 @@ var runtime = (function (exports) {
528
432
  // unified ._invoke helper method.
529
433
  defineIteratorMethods(Gp);
530
434
 
531
- define(Gp, toStringTagSymbol, "Generator");
435
+ Gp[toStringTagSymbol] = "Generator";
532
436
 
533
437
  // A Generator should always return itself as the iterator object when the
534
438
  // @@iterator function is called on it. Some browsers' implementations of the
535
439
  // iterator prototype chain incorrectly implement this, causing the Generator
536
440
  // object to not be returned from this call. This ensures that doesn't happen.
537
441
  // See https://github.com/facebook/regenerator/issues/274 for more details.
538
- define(Gp, iteratorSymbol, function() {
442
+ Gp[iteratorSymbol] = function() {
539
443
  return this;
540
- });
444
+ };
541
445
 
542
- define(Gp, "toString", function() {
446
+ Gp.toString = function() {
543
447
  return "[object Generator]";
544
- });
448
+ };
545
449
 
546
450
  function pushTryEntry(locs) {
547
451
  var entry = { tryLoc: locs[0] };
@@ -860,49 +764,24 @@ try {
860
764
  } catch (accidentalStrictMode) {
861
765
  // This module should not be running in strict mode, so the above
862
766
  // assignment should always work unless something is misconfigured. Just
863
- // in case runtime.js accidentally runs in strict mode, in modern engines
864
- // we can explicitly access globalThis. In older engines we can escape
767
+ // in case runtime.js accidentally runs in strict mode, we can escape
865
768
  // strict mode using a global Function call. This could conceivably fail
866
769
  // if a Content Security Policy forbids using Function, but in that case
867
770
  // the proper solution is to fix the accidental strict mode problem. If
868
771
  // you've misconfigured your bundler to force strict mode and applied a
869
772
  // CSP to forbid Function, and you're not willing to fix either of those
870
773
  // problems, please detail your unique predicament in a GitHub issue.
871
- if (typeof globalThis === "object") {
872
- globalThis.regeneratorRuntime = runtime;
873
- } else {
874
- Function("r", "regeneratorRuntime = r")(runtime);
875
- }
774
+ Function("r", "regeneratorRuntime = r")(runtime);
876
775
  }
877
776
  });
878
777
 
879
- function deploySite(_ref) {
880
- var siteId = _ref.siteId,
881
- buildDir = _ref.buildDir,
882
- customClient = _ref.client,
883
- configRest = _objectWithoutPropertiesLoose(_ref, ["siteId", "buildDir", "client"]);
884
-
885
- var client = customClient;
886
-
887
- if (!client) {
888
- var authToken = process.env.NETLIFY_AUTH_TOKEN;
889
- client = new NetlifyAPI(authToken);
890
- }
891
-
892
- return client.deploy(siteId, buildDir, _extends({
893
- statusCb: function statusCb(statusObj) {
894
- console.log(statusObj.msg);
895
- }
896
- }, configRest));
778
+ function deployment(_x) {
779
+ return _deployment.apply(this, arguments);
897
780
  }
898
- function deploy(_x) {
899
- return _deploy.apply(this, arguments);
900
- }
901
-
902
- function _deploy() {
903
- _deploy = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(configs) {
904
- var authToken, client, message, deployResults, _iterator, _step, config, result, lastCommit;
905
781
 
782
+ function _deployment() {
783
+ _deployment = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(configs) {
784
+ var authToken, lastCommit;
906
785
  return runtime_1.wrap(function _callee$(_context) {
907
786
  while (1) {
908
787
  switch (_context.prev = _context.next) {
@@ -913,66 +792,29 @@ function _deploy() {
913
792
  fail("Couldn't get deploy information. You need to set up an authentication \n token in your environment variables. \n See: https://gitlab.com/help/ci/variables/README#variables");
914
793
  }
915
794
 
916
- _context.prev = 2;
917
- client = new NetlifyAPI(authToken);
918
-
919
- if (danger.gitlab) {
920
- message = danger.gitlab.mr.title;
921
- }
922
-
923
- deployResults = [];
924
- _iterator = _createForOfIteratorHelperLoose(configs);
925
-
926
- case 7:
927
- if ((_step = _iterator()).done) {
928
- _context.next = 15;
929
- break;
795
+ try {
796
+ lastCommit = danger.git.commits[0];
797
+ markdown(["## Deploy preview", "The deploy preview is ready!", "Built with commit " + lastCommit.sha].concat(configs.map(function (result) {
798
+ return result.label + ": " + result.deploy_url;
799
+ })).join("\n\n"));
800
+ } catch (e) {
801
+ console.error(e);
802
+ fail("Couldn't get deploy information.");
930
803
  }
931
804
 
932
- config = _step.value;
933
- _context.next = 11;
934
- return deploySite(_extends({
935
- client: client,
936
- message: message,
937
- draft: true
938
- }, config));
939
-
940
- case 11:
941
- result = _context.sent;
942
- deployResults.push(result);
943
-
944
- case 13:
945
- _context.next = 7;
946
- break;
947
-
948
- case 15:
949
- lastCommit = danger.git.commits[0];
950
- markdown(["## Deploy preview", "Deploy preview for *front10-ui* ready!", "Built with commit " + lastCommit.sha].concat(deployResults.map(function (result, index) {
951
- return configs[index].label + ": " + result.deploy.deploy_ssl_url;
952
- })).join("\n\n"));
953
- _context.next = 23;
954
- break;
955
-
956
- case 19:
957
- _context.prev = 19;
958
- _context.t0 = _context["catch"](2);
959
- console.error(_context.t0);
960
- fail("Couldn't get deploy information.");
961
-
962
- case 23:
805
+ case 3:
963
806
  case "end":
964
807
  return _context.stop();
965
808
  }
966
809
  }
967
- }, _callee, null, [[2, 19]]);
810
+ }, _callee);
968
811
  }));
969
- return _deploy.apply(this, arguments);
812
+ return _deployment.apply(this, arguments);
970
813
  }
971
814
 
972
815
  var pluginNetlify = {
973
816
  __proto__: null,
974
- deploySite: deploySite,
975
- deploy: deploy
817
+ deployment: deployment
976
818
  };
977
819
 
978
820
  /**
@@ -991,7 +833,7 @@ function generateMDTable(headers, body) {
991
833
  return tableHeaders.join("\n") + "\n" + tableBody.join("\n");
992
834
  }
993
835
 
994
- function getDefaultGetBundlesFn(bundlePrefix) {
836
+ function getWidgetsGetBundlesFn(bundlePrefix) {
995
837
  return function defaultGetBundlesFn(bundlesDir) {
996
838
  return readdirSync(bundlesDir).map(function (name) {
997
839
  return path.join(bundlesDir, name);
@@ -1003,23 +845,44 @@ function getDefaultGetBundlesFn(bundlePrefix) {
1003
845
  };
1004
846
  }
1005
847
 
1006
- function defaultRenameFn(filename) {
848
+ function defaultGetBundlesFn(bundlesDir) {
849
+ return readdirSync(bundlesDir).filter(function (file) {
850
+ return file.endsWith(".js");
851
+ }).map(function (file) {
852
+ return path.join(bundlesDir, file);
853
+ });
854
+ }
855
+
856
+ function widgetsRenameFn(filename) {
1007
857
  return filename.split(".bundle.js")[0].replace(/--/g, "-").split("-").map(function (e) {
1008
858
  return e[0].toUpperCase() + e.slice(1);
1009
859
  }).join(" ").replace("Mobile", "(mobile)");
1010
860
  }
1011
861
 
862
+ function defaultRenameFn(filename) {
863
+ return filename.replace(".min.js", "").replace(".js", "");
864
+ }
865
+
1012
866
  function bundleSizeResults(_ref) {
1013
867
  var _ref$formats = _ref.formats,
1014
868
  formats = _ref$formats === void 0 ? ["gzip"] : _ref$formats,
1015
869
  bundlesDir = _ref.bundlesDir,
1016
870
  _ref$renameFn = _ref.renameFn,
1017
871
  renameFn = _ref$renameFn === void 0 ? defaultRenameFn : _ref$renameFn,
1018
- getBundlesFn = _ref.getBundlesFn,
872
+ _ref$getBundlesFn = _ref.getBundlesFn,
873
+ getBundlesFn = _ref$getBundlesFn === void 0 ? defaultGetBundlesFn : _ref$getBundlesFn,
1019
874
  _ref$bundlePrefix = _ref.bundlePrefix,
1020
875
  bundlePrefix = _ref$bundlePrefix === void 0 ? "cmp-mc-" : _ref$bundlePrefix,
1021
- reportPath = _ref.reportPath;
1022
- var getBundles = getBundlesFn != null ? getBundlesFn : getDefaultGetBundlesFn(bundlePrefix);
876
+ reportPath = _ref.reportPath,
877
+ preset = _ref.preset;
878
+ var getBundles = getBundlesFn;
879
+ var rename = renameFn;
880
+
881
+ if (preset === "widgets") {
882
+ getBundles = getWidgetsGetBundlesFn(bundlePrefix);
883
+ rename = widgetsRenameFn;
884
+ }
885
+
1023
886
  var files = getBundles(bundlesDir).filter(existsSync);
1024
887
  var formatFilter = new Set(formats);
1025
888
  var gzip = formatFilter.has("gzip");
@@ -1031,7 +894,7 @@ function bundleSizeResults(_ref) {
1031
894
  var jsFile = readFileSync(filePath);
1032
895
  var fileSizes = [jsFile].concat(gzip ? [zlib.gzipSync(jsFile)] : [], brotli ? [zlib.brotliCompressSync(jsFile)] : []);
1033
896
  return {
1034
- filename: renameFn(path.basename(filePath)),
897
+ filename: rename(path.basename(filePath)),
1035
898
  sizes: fileSizes.map(function (file) {
1036
899
  return file.length;
1037
900
  })
@@ -1071,7 +934,7 @@ function bundleSize(_x) {
1071
934
 
1072
935
  function _bundleSize() {
1073
936
  _bundleSize = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(options) {
1074
- var results, reportPath, _options$baseBundleJo, baseBundleJob, baseResults, projectId, authToken, targetBranch, baseBundlesUrl, baseResultsResponse, baseBundles, diffHeaders, _baseResults, bundles, brotli, gzip, headers, body;
937
+ var results, reportPath, _options$baseBundleJo, baseBundleJob, baseResults, projectId, authToken, targetBranch, baseBundlesUrl, baseBundles, diffHeaders, _baseResults, bundles, brotli, gzip, headers, body;
1075
938
 
1076
939
  return runtime_1.wrap(function _callee$(_context) {
1077
940
  while (1) {
@@ -1081,36 +944,27 @@ function _bundleSize() {
1081
944
  reportPath = options.reportPath, _options$baseBundleJo = options.baseBundleJob, baseBundleJob = _options$baseBundleJo === void 0 ? "publish" : _options$baseBundleJo;
1082
945
 
1083
946
  if (!reportPath) {
1084
- _context.next = 14;
947
+ _context.next = 10;
1085
948
  break;
1086
949
  }
1087
950
 
1088
951
  projectId = process.env.CI_MERGE_REQUEST_PROJECT_ID;
1089
952
  authToken = process.env.DANGER_GITLAB_API_TOKEN;
1090
- targetBranch = process.env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME || "master";
953
+ targetBranch = process.env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME || "main";
1091
954
  baseBundlesUrl = "https://gitlab.com/api/v4/projects/" + projectId + "/jobs/artifacts/" + targetBranch + "/raw/" + reportPath + "?job=" + baseBundleJob;
1092
955
  _context.next = 9;
1093
956
  return fetch(baseBundlesUrl, {
1094
957
  headers: {
1095
958
  "PRIVATE-TOKEN": authToken
1096
959
  }
960
+ }).then(function (response) {
961
+ return response.json();
1097
962
  });
1098
963
 
1099
964
  case 9:
1100
- baseResultsResponse = _context.sent;
1101
-
1102
- if (!baseResultsResponse.ok) {
1103
- _context.next = 14;
1104
- break;
1105
- }
1106
-
1107
- _context.next = 13;
1108
- return baseResultsResponse.json();
1109
-
1110
- case 13:
1111
965
  baseResults = _context.sent;
1112
966
 
1113
- case 14:
967
+ case 10:
1114
968
  baseBundles = new Map();
1115
969
  diffHeaders = [];
1116
970
 
@@ -1151,7 +1005,7 @@ function _bundleSize() {
1151
1005
  });
1152
1006
  markdown(["## Bundle size", generateMDTable(headers, body)].join("\n\n"));
1153
1007
 
1154
- case 20:
1008
+ case 16:
1155
1009
  case "end":
1156
1010
  return _context.stop();
1157
1011
  }