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

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.
@@ -4,15 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
6
 
7
+ var NetlifyAPI = _interopDefault(require('netlify'));
7
8
  var fs = require('fs');
8
9
  var fs__default = _interopDefault(fs);
9
- var path = require('path');
10
- var path__default = _interopDefault(path);
11
- var stripANSI = _interopDefault(require('strip-ansi'));
12
- var jest$1 = require('jest');
13
- var eslint$1 = require('eslint');
14
- var NetlifyAPI = _interopDefault(require('netlify'));
15
- var fetch = _interopDefault(require('node-fetch'));
10
+ var undici = require('undici');
11
+ var path = _interopDefault(require('path'));
16
12
  var zlib = _interopDefault(require('zlib'));
17
13
  var util = require('util');
18
14
 
@@ -149,6 +145,24 @@ var runtime = (function (exports) {
149
145
  var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
150
146
  var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
151
147
 
148
+ function define(obj, key, value) {
149
+ Object.defineProperty(obj, key, {
150
+ value: value,
151
+ enumerable: true,
152
+ configurable: true,
153
+ writable: true
154
+ });
155
+ return obj[key];
156
+ }
157
+ try {
158
+ // IE 8 has a broken Object.defineProperty that only works on DOM objects.
159
+ define({}, "");
160
+ } catch (err) {
161
+ define = function(obj, key, value) {
162
+ return obj[key] = value;
163
+ };
164
+ }
165
+
152
166
  function wrap(innerFn, outerFn, self, tryLocsList) {
153
167
  // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
154
168
  var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
@@ -201,9 +215,9 @@ var runtime = (function (exports) {
201
215
  // This is a polyfill for %IteratorPrototype% for environments that
202
216
  // don't natively support it.
203
217
  var IteratorPrototype = {};
204
- IteratorPrototype[iteratorSymbol] = function () {
218
+ define(IteratorPrototype, iteratorSymbol, function () {
205
219
  return this;
206
- };
220
+ });
207
221
 
208
222
  var getProto = Object.getPrototypeOf;
209
223
  var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
@@ -217,18 +231,22 @@ var runtime = (function (exports) {
217
231
 
218
232
  var Gp = GeneratorFunctionPrototype.prototype =
219
233
  Generator.prototype = Object.create(IteratorPrototype);
220
- GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
221
- GeneratorFunctionPrototype.constructor = GeneratorFunction;
222
- GeneratorFunctionPrototype[toStringTagSymbol] =
223
- GeneratorFunction.displayName = "GeneratorFunction";
234
+ GeneratorFunction.prototype = GeneratorFunctionPrototype;
235
+ define(Gp, "constructor", GeneratorFunctionPrototype);
236
+ define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
237
+ GeneratorFunction.displayName = define(
238
+ GeneratorFunctionPrototype,
239
+ toStringTagSymbol,
240
+ "GeneratorFunction"
241
+ );
224
242
 
225
243
  // Helper for defining the .next, .throw, and .return methods of the
226
244
  // Iterator interface in terms of a single ._invoke method.
227
245
  function defineIteratorMethods(prototype) {
228
246
  ["next", "throw", "return"].forEach(function(method) {
229
- prototype[method] = function(arg) {
247
+ define(prototype, method, function(arg) {
230
248
  return this._invoke(method, arg);
231
- };
249
+ });
232
250
  });
233
251
  }
234
252
 
@@ -247,9 +265,7 @@ var runtime = (function (exports) {
247
265
  Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
248
266
  } else {
249
267
  genFun.__proto__ = GeneratorFunctionPrototype;
250
- if (!(toStringTagSymbol in genFun)) {
251
- genFun[toStringTagSymbol] = "GeneratorFunction";
252
- }
268
+ define(genFun, toStringTagSymbol, "GeneratorFunction");
253
269
  }
254
270
  genFun.prototype = Object.create(Gp);
255
271
  return genFun;
@@ -331,9 +347,9 @@ var runtime = (function (exports) {
331
347
  }
332
348
 
333
349
  defineIteratorMethods(AsyncIterator.prototype);
334
- AsyncIterator.prototype[asyncIteratorSymbol] = function () {
350
+ define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
335
351
  return this;
336
- };
352
+ });
337
353
  exports.AsyncIterator = AsyncIterator;
338
354
 
339
355
  // Note that simple async functions are implemented on top of
@@ -519,20 +535,20 @@ var runtime = (function (exports) {
519
535
  // unified ._invoke helper method.
520
536
  defineIteratorMethods(Gp);
521
537
 
522
- Gp[toStringTagSymbol] = "Generator";
538
+ define(Gp, toStringTagSymbol, "Generator");
523
539
 
524
540
  // A Generator should always return itself as the iterator object when the
525
541
  // @@iterator function is called on it. Some browsers' implementations of the
526
542
  // iterator prototype chain incorrectly implement this, causing the Generator
527
543
  // object to not be returned from this call. This ensures that doesn't happen.
528
544
  // See https://github.com/facebook/regenerator/issues/274 for more details.
529
- Gp[iteratorSymbol] = function() {
545
+ define(Gp, iteratorSymbol, function() {
530
546
  return this;
531
- };
547
+ });
532
548
 
533
- Gp.toString = function() {
549
+ define(Gp, "toString", function() {
534
550
  return "[object Generator]";
535
- };
551
+ });
536
552
 
537
553
  function pushTryEntry(locs) {
538
554
  var entry = { tryLoc: locs[0] };
@@ -851,250 +867,21 @@ try {
851
867
  } catch (accidentalStrictMode) {
852
868
  // This module should not be running in strict mode, so the above
853
869
  // assignment should always work unless something is misconfigured. Just
854
- // in case runtime.js accidentally runs in strict mode, we can escape
870
+ // in case runtime.js accidentally runs in strict mode, in modern engines
871
+ // we can explicitly access globalThis. In older engines we can escape
855
872
  // strict mode using a global Function call. This could conceivably fail
856
873
  // if a Content Security Policy forbids using Function, but in that case
857
874
  // the proper solution is to fix the accidental strict mode problem. If
858
875
  // you've misconfigured your bundler to force strict mode and applied a
859
876
  // CSP to forbid Function, and you're not willing to fix either of those
860
877
  // problems, please detail your unique predicament in a GitHub issue.
861
- Function("r", "regeneratorRuntime = r")(runtime);
862
- }
863
- });
864
-
865
- var jestSuccessFeedback = function jestSuccessFeedback(jsonResults, showSuccessMessage) {
866
- if (!showSuccessMessage) {
867
- // tslint:disable-next-line:no-console
868
- console.log(":+1: Jest tests passed");
878
+ if (typeof globalThis === "object") {
879
+ globalThis.regeneratorRuntime = runtime;
869
880
  } else {
870
- message(":+1: Jest tests passed: " + jsonResults.numPassedTests + "/" + jsonResults.numTotalTests + " (" + jsonResults.numPendingTests + " skipped)");
881
+ Function("r", "regeneratorRuntime = r")(runtime);
871
882
  }
872
- };
873
-
874
- function getUrl(file, line) {
875
- var gitlab = danger.gitlab;
876
-
877
- if (gitlab) {
878
- var headSha = danger.gitlab.mr.diff_refs.head_sha;
879
- var repoSlug = gitlab.metadata.repoSlug;
880
- var baseUrl = "https://gitlab.com/" + repoSlug + "/-/blob";
881
- return baseUrl + "/" + headSha + "/" + file + (line ? "#L" + line : "");
882
- }
883
-
884
- return "#";
885
- }
886
-
887
- var lineOfError = function lineOfError(msg, filePath) {
888
- var filename = path.basename(filePath);
889
- var restOfTrace = msg.split(filename, 2)[1];
890
- return restOfTrace ? parseInt(restOfTrace.split(":")[1], 10) : null;
891
- };
892
-
893
- var sanitizeShortErrorMessage = function sanitizeShortErrorMessage(msg) {
894
- if (msg.includes("does not match stored snapshot")) {
895
- return "Snapshot has changed";
896
- }
897
-
898
- return msg.split(" at", 1)[0].trim().split("\n").splice(2).join("").replace(/\s\s+/g, " ").replace("Received:", ", received:").replace("., received", ", received").split("Difference:")[0];
899
- }; // e.g. https://gitlab.com/carburo/danger/-/blob/802af5c0b057c4439ef465a75009f017423fbf98/simple.test.js#L6
900
-
901
-
902
- var linkToTest = function linkToTest(file, msg, title) {
903
- var line = lineOfError(msg, file);
904
- return "<a href='" + getUrl(file, line) + "'>" + title + "</a>";
905
- };
906
-
907
- var assertionFailString = function assertionFailString(file, status) {
908
- return "\n <li>\n " + linkToTest(file, status.failureMessages && status.failureMessages[0], status.title) + "\n <br/>\n " + sanitizeShortErrorMessage(status.failureMessages && stripANSI(status.failureMessages[0])) + "\n \n <details>\n <summary>Full message</summary>\n <pre><code>\n " + (status.failureMessages && stripANSI(status.failureMessages.join("\n"))) + "\n </code></pre>\n </details>\n </li>\n <br/>\n ";
909
- };
910
-
911
- var fileToFailString = function fileToFailString( // tslint:disable-next-line:no-shadowed-variable
912
- path, failedAssertions) {
913
- return "\n <b>:black_joker: FAIL</b> in " + path + "\n \n " + failedAssertions.map(function (a) {
914
- return assertionFailString(path, a);
915
- }).join("\n\n") + "\n ";
916
- };
917
-
918
- var presentErrors = function presentErrors(jsonResults) {
919
- var failing = jsonResults.testResults.filter(function (tr) {
920
- return tr.status === "failed";
921
- });
922
- failing.forEach(function (results) {
923
- var relativeFilePath = path.relative(process.cwd(), results.name);
924
- var failedAssertions = results.assertionResults.filter(function (r) {
925
- return r.status === "failed";
926
- });
927
- var failMessage = fileToFailString(relativeFilePath, failedAssertions);
928
- fail(failMessage);
929
- });
930
- };
931
-
932
- function jest(_x) {
933
- return _jest.apply(this, arguments);
934
- }
935
-
936
- function _jest() {
937
- _jest = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(config) {
938
- var _config, _config$testResultsJs, testResultsJsonPath, _config$showSuccessMe, showSuccessMessage, _config$runJest, runJest, jsonFileContents, jsonResults;
939
-
940
- return runtime_1.wrap(function _callee$(_context) {
941
- while (1) {
942
- switch (_context.prev = _context.next) {
943
- case 0:
944
- if (config === void 0) {
945
- config = {};
946
- }
947
-
948
- _config = config, _config$testResultsJs = _config.testResultsJsonPath, testResultsJsonPath = _config$testResultsJs === void 0 ? "test-results.json" : _config$testResultsJs, _config$showSuccessMe = _config.showSuccessMessage, showSuccessMessage = _config$showSuccessMe === void 0 ? true : _config$showSuccessMe, _config$runJest = _config.runJest, runJest = _config$runJest === void 0 ? true : _config$runJest;
949
-
950
- if (!runJest) {
951
- _context.next = 11;
952
- break;
953
- }
954
-
955
- _context.prev = 3;
956
- _context.next = 6;
957
- return jest$1.run(["--outputFile", "test-results.json", "--json"]);
958
-
959
- case 6:
960
- _context.next = 11;
961
- break;
962
-
963
- case 8:
964
- _context.prev = 8;
965
- _context.t0 = _context["catch"](3);
966
- console.error(_context.t0);
967
-
968
- case 11:
969
- _context.prev = 11;
970
- jsonFileContents = fs.readFileSync(testResultsJsonPath, "utf8");
971
- jsonResults = JSON.parse(jsonFileContents);
972
-
973
- if (!jsonResults.success) {
974
- _context.next = 17;
975
- break;
976
- }
977
-
978
- jestSuccessFeedback(jsonResults, showSuccessMessage);
979
- return _context.abrupt("return");
980
-
981
- case 17:
982
- presentErrors(jsonResults);
983
- _context.next = 24;
984
- break;
985
-
986
- case 20:
987
- _context.prev = 20;
988
- _context.t1 = _context["catch"](11);
989
- // tslint:disable-next-line:no-console
990
- console.error(_context.t1);
991
- fail("[danger-plugin-jest] Could not read test results. Danger cannot pass or fail the build.");
992
-
993
- case 24:
994
- case "end":
995
- return _context.stop();
996
- }
997
- }
998
- }, _callee, null, [[3, 8], [11, 20]]);
999
- }));
1000
- return _jest.apply(this, arguments);
1001
- }
1002
-
1003
- function getFileContents(path) {
1004
- if (danger.gitlab) {
1005
- return danger.gitlab.utils.fileContents(path);
1006
- } else if (danger.github) {
1007
- return danger.github.utils.fileContents(path);
1008
- }
1009
-
1010
- return fs.readFileSync(path, "utf8");
1011
- }
1012
-
1013
- function lintFile(_x, _x2, _x3) {
1014
- return _lintFile.apply(this, arguments);
1015
- }
1016
- /**
1017
- * Eslint your code with Danger
1018
- */
1019
-
1020
-
1021
- function _lintFile() {
1022
- _lintFile = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(linter, _config, path) {
1023
- var contents, report;
1024
- return runtime_1.wrap(function _callee$(_context) {
1025
- while (1) {
1026
- switch (_context.prev = _context.next) {
1027
- case 0:
1028
- _context.next = 2;
1029
- return getFileContents(path);
1030
-
1031
- case 2:
1032
- contents = _context.sent;
1033
- report = linter.executeOnText(contents, path);
1034
-
1035
- if (report.results.length) {
1036
- report.results[0].messages.map(function (msg) {
1037
- if (msg.fatal) {
1038
- fail("Fatal error linting " + path + " with eslint.");
1039
- return undefined;
1040
- }
1041
-
1042
- if (msg.severity === 1 || msg.severity === 2) {
1043
- var fn = {
1044
- 1: warn,
1045
- 2: fail
1046
- }[msg.severity];
1047
- fn(path + " line " + msg.line + " \u2013 " + msg.message + " (" + msg.ruleId + ")");
1048
- }
1049
-
1050
- return undefined;
1051
- });
1052
- }
1053
-
1054
- case 5:
1055
- case "end":
1056
- return _context.stop();
1057
- }
1058
- }
1059
- }, _callee);
1060
- }));
1061
- return _lintFile.apply(this, arguments);
1062
- }
1063
-
1064
- function eslint(_x4, _x5) {
1065
- return _eslint.apply(this, arguments);
1066
- }
1067
-
1068
- function _eslint() {
1069
- _eslint = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(config, extensions) {
1070
- var allFiles, cli, filesToLint;
1071
- return runtime_1.wrap(function _callee2$(_context2) {
1072
- while (1) {
1073
- switch (_context2.prev = _context2.next) {
1074
- case 0:
1075
- allFiles = danger.git.created_files.concat(danger.git.modified_files);
1076
- cli = new eslint$1.CLIEngine({
1077
- baseConfig: config
1078
- }); // let eslint filter down to non-ignored, matching the extensions expected
1079
-
1080
- filesToLint = allFiles.filter(function (f) {
1081
- return !cli.isPathIgnored(f) && (extensions == null ? void 0 : extensions.some(function (ext) {
1082
- return f.endsWith(ext);
1083
- }));
1084
- });
1085
- return _context2.abrupt("return", Promise.all(filesToLint.map(function (f) {
1086
- return lintFile(cli, config, f);
1087
- })));
1088
-
1089
- case 4:
1090
- case "end":
1091
- return _context2.stop();
1092
- }
1093
- }
1094
- }, _callee2);
1095
- }));
1096
- return _eslint.apply(this, arguments);
1097
883
  }
884
+ });
1098
885
 
1099
886
  function deploySite(_ref) {
1100
887
  var siteId = _ref.siteId,
@@ -1214,11 +1001,11 @@ function generateMDTable(headers, body) {
1214
1001
  function getDefaultGetBundlesFn(bundlePrefix) {
1215
1002
  return function defaultGetBundlesFn(bundlesDir) {
1216
1003
  return fs.readdirSync(bundlesDir).map(function (name) {
1217
- return path__default.join(bundlesDir, name);
1004
+ return path.join(bundlesDir, name);
1218
1005
  }).filter(function (dirName) {
1219
1006
  return fs.lstatSync(dirName).isDirectory();
1220
1007
  }).map(function (dirName) {
1221
- return path__default.join(dirName, path__default.basename(dirName).replace(bundlePrefix, "") + ".bundle.js");
1008
+ return path.join(dirName, path.basename(dirName).replace(bundlePrefix, "") + ".bundle.js");
1222
1009
  });
1223
1010
  };
1224
1011
  }
@@ -1251,7 +1038,7 @@ function bundleSizeResults(_ref) {
1251
1038
  var jsFile = fs.readFileSync(filePath);
1252
1039
  var fileSizes = [jsFile].concat(gzip ? [zlib.gzipSync(jsFile)] : [], brotli ? [zlib.brotliCompressSync(jsFile)] : []);
1253
1040
  return {
1254
- filename: renameFn(path__default.basename(filePath)),
1041
+ filename: renameFn(path.basename(filePath)),
1255
1042
  sizes: fileSizes.map(function (file) {
1256
1043
  return file.length;
1257
1044
  })
@@ -1291,7 +1078,7 @@ function bundleSize(_x) {
1291
1078
 
1292
1079
  function _bundleSize() {
1293
1080
  _bundleSize = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(options) {
1294
- var results, reportPath, _options$baseBundleJo, baseBundleJob, baseResults, projectId, authToken, targetBranch, baseBundlesUrl, baseBundles, diffHeaders, _baseResults, bundles, brotli, gzip, headers, body;
1081
+ var results, reportPath, _options$baseBundleJo, baseBundleJob, baseResults, projectId, authToken, targetBranch, baseBundlesUrl, baseResultsResponse, baseBundles, diffHeaders, _baseResults, bundles, brotli, gzip, headers, body;
1295
1082
 
1296
1083
  return runtime_1.wrap(function _callee$(_context) {
1297
1084
  while (1) {
@@ -1301,7 +1088,7 @@ function _bundleSize() {
1301
1088
  reportPath = options.reportPath, _options$baseBundleJo = options.baseBundleJob, baseBundleJob = _options$baseBundleJo === void 0 ? "publish" : _options$baseBundleJo;
1302
1089
 
1303
1090
  if (!reportPath) {
1304
- _context.next = 10;
1091
+ _context.next = 14;
1305
1092
  break;
1306
1093
  }
1307
1094
 
@@ -1310,26 +1097,39 @@ function _bundleSize() {
1310
1097
  targetBranch = process.env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME || "master";
1311
1098
  baseBundlesUrl = "https://gitlab.com/api/v4/projects/" + projectId + "/jobs/artifacts/" + targetBranch + "/raw/" + reportPath + "?job=" + baseBundleJob;
1312
1099
  _context.next = 9;
1313
- return fetch(baseBundlesUrl, {
1100
+ return undici.fetch(baseBundlesUrl, {
1314
1101
  headers: {
1315
1102
  "PRIVATE-TOKEN": authToken
1316
1103
  }
1317
- }).then(function (response) {
1318
- return response.json();
1319
1104
  });
1320
1105
 
1321
1106
  case 9:
1107
+ baseResultsResponse = _context.sent;
1108
+
1109
+ if (!baseResultsResponse.ok) {
1110
+ _context.next = 14;
1111
+ break;
1112
+ }
1113
+
1114
+ _context.next = 13;
1115
+ return baseResultsResponse.json();
1116
+
1117
+ case 13:
1322
1118
  baseResults = _context.sent;
1323
1119
 
1324
- case 10:
1120
+ case 14:
1325
1121
  baseBundles = new Map();
1326
1122
  diffHeaders = [];
1327
1123
 
1328
1124
  if (baseResults) {
1329
1125
  _baseResults = baseResults, bundles = _baseResults.bundles, brotli = _baseResults.brotli, gzip = _baseResults.gzip;
1330
- bundles.forEach(function (bundle) {
1331
- baseBundles.set(bundle.filename, bundle.sizes);
1332
- });
1126
+
1127
+ if (bundles) {
1128
+ bundles.forEach(function (bundle) {
1129
+ baseBundles.set(bundle.filename, bundle.sizes);
1130
+ });
1131
+ }
1132
+
1333
1133
  diffHeaders = ["Filesize diff"].concat(gzip ? ["Gzip diff"] : [], brotli ? ["Brotli diff"] : []);
1334
1134
  }
1335
1135
 
@@ -1358,7 +1158,7 @@ function _bundleSize() {
1358
1158
  });
1359
1159
  markdown(["## Bundle size", generateMDTable(headers, body)].join("\n\n"));
1360
1160
 
1361
- case 16:
1161
+ case 20:
1362
1162
  case "end":
1363
1163
  return _context.stop();
1364
1164
  }
@@ -1415,8 +1215,6 @@ function _lighthouse() {
1415
1215
 
1416
1216
  exports.bundleSize = bundleSize;
1417
1217
  exports.bundleSizeResults = bundleSizeResults;
1418
- exports.eslint = eslint;
1419
- exports.jest = jest;
1420
1218
  exports.lighthouse = lighthouse;
1421
1219
  exports.netlify = pluginNetlify;
1422
1220
  //# sourceMappingURL=danger-plugins.cjs.development.js.map