@front10/danger-plugins 0.11.0-rc.4 → 1.0.0
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.
- package/dist/danger-plugins.cjs.development.js +26 -296
- package/dist/danger-plugins.cjs.development.js.map +1 -1
- package/dist/danger-plugins.cjs.production.min.js +1 -1
- package/dist/danger-plugins.cjs.production.min.js.map +1 -1
- package/dist/danger-plugins.esm.js +27 -294
- package/dist/danger-plugins.esm.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/plugin-netlify.d.ts +0 -1
- package/package.json +1 -4
- package/src/index.ts +0 -2
- package/src/plugin-bundle-size.ts +5 -3
- package/src/plugin-netlify.ts +0 -46
- package/CHANGELOG.md +0 -13
- package/dist/plugin-eslint.d.ts +0 -5
- package/dist/plugin-jest.d.ts +0 -7
- package/src/plugin-eslint.ts +0 -53
- package/src/plugin-jest.ts +0 -202
|
@@ -4,16 +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 child_process = require('child_process');
|
|
16
10
|
var fetch = _interopDefault(require('node-fetch'));
|
|
11
|
+
var path = _interopDefault(require('path'));
|
|
17
12
|
var zlib = _interopDefault(require('zlib'));
|
|
18
13
|
var util = require('util');
|
|
19
14
|
|
|
@@ -863,240 +858,6 @@ try {
|
|
|
863
858
|
}
|
|
864
859
|
});
|
|
865
860
|
|
|
866
|
-
var jestSuccessFeedback = function jestSuccessFeedback(jsonResults, showSuccessMessage) {
|
|
867
|
-
if (!showSuccessMessage) {
|
|
868
|
-
// tslint:disable-next-line:no-console
|
|
869
|
-
console.log(":+1: Jest tests passed");
|
|
870
|
-
} else {
|
|
871
|
-
message(":+1: Jest tests passed: " + jsonResults.numPassedTests + "/" + jsonResults.numTotalTests + " (" + jsonResults.numPendingTests + " skipped)");
|
|
872
|
-
}
|
|
873
|
-
};
|
|
874
|
-
|
|
875
|
-
function getUrl(file, line) {
|
|
876
|
-
var gitlab = danger.gitlab;
|
|
877
|
-
|
|
878
|
-
if (gitlab) {
|
|
879
|
-
var headSha = danger.gitlab.mr.diff_refs.head_sha;
|
|
880
|
-
var repoSlug = gitlab.metadata.repoSlug;
|
|
881
|
-
var baseUrl = "https://gitlab.com/" + repoSlug + "/-/blob";
|
|
882
|
-
return baseUrl + "/" + headSha + "/" + file + (line ? "#L" + line : "");
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
return "#";
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
var lineOfError = function lineOfError(msg, filePath) {
|
|
889
|
-
var filename = path.basename(filePath);
|
|
890
|
-
var restOfTrace = msg.split(filename, 2)[1];
|
|
891
|
-
return restOfTrace ? parseInt(restOfTrace.split(":")[1], 10) : null;
|
|
892
|
-
};
|
|
893
|
-
|
|
894
|
-
var sanitizeShortErrorMessage = function sanitizeShortErrorMessage(msg) {
|
|
895
|
-
if (msg.includes("does not match stored snapshot")) {
|
|
896
|
-
return "Snapshot has changed";
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
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];
|
|
900
|
-
}; // e.g. https://gitlab.com/carburo/danger/-/blob/802af5c0b057c4439ef465a75009f017423fbf98/simple.test.js#L6
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
var linkToTest = function linkToTest(file, msg, title) {
|
|
904
|
-
var line = lineOfError(msg, file);
|
|
905
|
-
return "<a href='" + getUrl(file, line) + "'>" + title + "</a>";
|
|
906
|
-
};
|
|
907
|
-
|
|
908
|
-
var assertionFailString = function assertionFailString(file, status) {
|
|
909
|
-
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 ";
|
|
910
|
-
};
|
|
911
|
-
|
|
912
|
-
var fileToFailString = function fileToFailString( // tslint:disable-next-line:no-shadowed-variable
|
|
913
|
-
path, failedAssertions) {
|
|
914
|
-
return "\n <b>:black_joker: FAIL</b> in " + path + "\n \n " + failedAssertions.map(function (a) {
|
|
915
|
-
return assertionFailString(path, a);
|
|
916
|
-
}).join("\n\n") + "\n ";
|
|
917
|
-
};
|
|
918
|
-
|
|
919
|
-
var presentErrors = function presentErrors(jsonResults) {
|
|
920
|
-
var failing = jsonResults.testResults.filter(function (tr) {
|
|
921
|
-
return tr.status === "failed";
|
|
922
|
-
});
|
|
923
|
-
failing.forEach(function (results) {
|
|
924
|
-
var relativeFilePath = path.relative(process.cwd(), results.name);
|
|
925
|
-
var failedAssertions = results.assertionResults.filter(function (r) {
|
|
926
|
-
return r.status === "failed";
|
|
927
|
-
});
|
|
928
|
-
var failMessage = fileToFailString(relativeFilePath, failedAssertions);
|
|
929
|
-
fail(failMessage);
|
|
930
|
-
});
|
|
931
|
-
};
|
|
932
|
-
|
|
933
|
-
function jest(_x) {
|
|
934
|
-
return _jest.apply(this, arguments);
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
function _jest() {
|
|
938
|
-
_jest = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(config) {
|
|
939
|
-
var _config, _config$testResultsJs, testResultsJsonPath, _config$showSuccessMe, showSuccessMessage, _config$runJest, runJest, jsonFileContents, jsonResults;
|
|
940
|
-
|
|
941
|
-
return runtime_1.wrap(function _callee$(_context) {
|
|
942
|
-
while (1) {
|
|
943
|
-
switch (_context.prev = _context.next) {
|
|
944
|
-
case 0:
|
|
945
|
-
if (config === void 0) {
|
|
946
|
-
config = {};
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
_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;
|
|
950
|
-
|
|
951
|
-
if (!runJest) {
|
|
952
|
-
_context.next = 11;
|
|
953
|
-
break;
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
_context.prev = 3;
|
|
957
|
-
_context.next = 6;
|
|
958
|
-
return jest$1.run(["--outputFile", "test-results.json", "--json"]);
|
|
959
|
-
|
|
960
|
-
case 6:
|
|
961
|
-
_context.next = 11;
|
|
962
|
-
break;
|
|
963
|
-
|
|
964
|
-
case 8:
|
|
965
|
-
_context.prev = 8;
|
|
966
|
-
_context.t0 = _context["catch"](3);
|
|
967
|
-
console.error(_context.t0);
|
|
968
|
-
|
|
969
|
-
case 11:
|
|
970
|
-
_context.prev = 11;
|
|
971
|
-
jsonFileContents = fs.readFileSync(testResultsJsonPath, "utf8");
|
|
972
|
-
jsonResults = JSON.parse(jsonFileContents);
|
|
973
|
-
|
|
974
|
-
if (!jsonResults.success) {
|
|
975
|
-
_context.next = 17;
|
|
976
|
-
break;
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
jestSuccessFeedback(jsonResults, showSuccessMessage);
|
|
980
|
-
return _context.abrupt("return");
|
|
981
|
-
|
|
982
|
-
case 17:
|
|
983
|
-
presentErrors(jsonResults);
|
|
984
|
-
_context.next = 24;
|
|
985
|
-
break;
|
|
986
|
-
|
|
987
|
-
case 20:
|
|
988
|
-
_context.prev = 20;
|
|
989
|
-
_context.t1 = _context["catch"](11);
|
|
990
|
-
// tslint:disable-next-line:no-console
|
|
991
|
-
console.error(_context.t1);
|
|
992
|
-
fail("[danger-plugin-jest] Could not read test results. Danger cannot pass or fail the build.");
|
|
993
|
-
|
|
994
|
-
case 24:
|
|
995
|
-
case "end":
|
|
996
|
-
return _context.stop();
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
}, _callee, null, [[3, 8], [11, 20]]);
|
|
1000
|
-
}));
|
|
1001
|
-
return _jest.apply(this, arguments);
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
function getFileContents(path) {
|
|
1005
|
-
if (danger.gitlab) {
|
|
1006
|
-
return danger.gitlab.utils.fileContents(path);
|
|
1007
|
-
} else if (danger.github) {
|
|
1008
|
-
return danger.github.utils.fileContents(path);
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
return fs.readFileSync(path, "utf8");
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
function lintFile(_x, _x2, _x3) {
|
|
1015
|
-
return _lintFile.apply(this, arguments);
|
|
1016
|
-
}
|
|
1017
|
-
/**
|
|
1018
|
-
* Eslint your code with Danger
|
|
1019
|
-
*/
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
function _lintFile() {
|
|
1023
|
-
_lintFile = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(linter, _config, path) {
|
|
1024
|
-
var contents, report;
|
|
1025
|
-
return runtime_1.wrap(function _callee$(_context) {
|
|
1026
|
-
while (1) {
|
|
1027
|
-
switch (_context.prev = _context.next) {
|
|
1028
|
-
case 0:
|
|
1029
|
-
_context.next = 2;
|
|
1030
|
-
return getFileContents(path);
|
|
1031
|
-
|
|
1032
|
-
case 2:
|
|
1033
|
-
contents = _context.sent;
|
|
1034
|
-
report = linter.executeOnText(contents, path);
|
|
1035
|
-
|
|
1036
|
-
if (report.results.length) {
|
|
1037
|
-
report.results[0].messages.map(function (msg) {
|
|
1038
|
-
if (msg.fatal) {
|
|
1039
|
-
fail("Fatal error linting " + path + " with eslint.");
|
|
1040
|
-
return undefined;
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
if (msg.severity === 1 || msg.severity === 2) {
|
|
1044
|
-
var fn = {
|
|
1045
|
-
1: warn,
|
|
1046
|
-
2: fail
|
|
1047
|
-
}[msg.severity];
|
|
1048
|
-
fn(path + " line " + msg.line + " \u2013 " + msg.message + " (" + msg.ruleId + ")");
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
return undefined;
|
|
1052
|
-
});
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
case 5:
|
|
1056
|
-
case "end":
|
|
1057
|
-
return _context.stop();
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
}, _callee);
|
|
1061
|
-
}));
|
|
1062
|
-
return _lintFile.apply(this, arguments);
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
function eslint(_x4, _x5) {
|
|
1066
|
-
return _eslint.apply(this, arguments);
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
function _eslint() {
|
|
1070
|
-
_eslint = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(config, extensions) {
|
|
1071
|
-
var allFiles, cli, filesToLint;
|
|
1072
|
-
return runtime_1.wrap(function _callee2$(_context2) {
|
|
1073
|
-
while (1) {
|
|
1074
|
-
switch (_context2.prev = _context2.next) {
|
|
1075
|
-
case 0:
|
|
1076
|
-
allFiles = danger.git.created_files.concat(danger.git.modified_files);
|
|
1077
|
-
cli = new eslint$1.CLIEngine({
|
|
1078
|
-
baseConfig: config
|
|
1079
|
-
}); // let eslint filter down to non-ignored, matching the extensions expected
|
|
1080
|
-
|
|
1081
|
-
filesToLint = allFiles.filter(function (f) {
|
|
1082
|
-
return !cli.isPathIgnored(f) && (extensions == null ? void 0 : extensions.some(function (ext) {
|
|
1083
|
-
return f.endsWith(ext);
|
|
1084
|
-
}));
|
|
1085
|
-
});
|
|
1086
|
-
return _context2.abrupt("return", Promise.all(filesToLint.map(function (f) {
|
|
1087
|
-
return lintFile(cli, config, f);
|
|
1088
|
-
})));
|
|
1089
|
-
|
|
1090
|
-
case 4:
|
|
1091
|
-
case "end":
|
|
1092
|
-
return _context2.stop();
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
}, _callee2);
|
|
1096
|
-
}));
|
|
1097
|
-
return _eslint.apply(this, arguments);
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
861
|
function deploySite(_ref) {
|
|
1101
862
|
var siteId = _ref.siteId,
|
|
1102
863
|
buildDir = _ref.buildDir,
|
|
@@ -1122,7 +883,7 @@ function deploy(_x) {
|
|
|
1122
883
|
|
|
1123
884
|
function _deploy() {
|
|
1124
885
|
_deploy = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(configs) {
|
|
1125
|
-
var authToken, client, message, deployResults,
|
|
886
|
+
var authToken, client, message, deployResults, _iterator, _step, config, result, lastCommit;
|
|
1126
887
|
|
|
1127
888
|
return runtime_1.wrap(function _callee$(_context) {
|
|
1128
889
|
while (1) {
|
|
@@ -1142,87 +903,54 @@ function _deploy() {
|
|
|
1142
903
|
}
|
|
1143
904
|
|
|
1144
905
|
deployResults = [];
|
|
1145
|
-
urlsToCheck = [];
|
|
1146
906
|
_iterator = _createForOfIteratorHelperLoose(configs);
|
|
1147
907
|
|
|
1148
|
-
case
|
|
908
|
+
case 7:
|
|
1149
909
|
if ((_step = _iterator()).done) {
|
|
1150
|
-
_context.next =
|
|
910
|
+
_context.next = 15;
|
|
1151
911
|
break;
|
|
1152
912
|
}
|
|
1153
913
|
|
|
1154
914
|
config = _step.value;
|
|
1155
|
-
_context.next =
|
|
915
|
+
_context.next = 11;
|
|
1156
916
|
return deploySite(_extends({
|
|
1157
917
|
client: client,
|
|
1158
918
|
message: message,
|
|
1159
919
|
draft: true
|
|
1160
920
|
}, config));
|
|
1161
921
|
|
|
1162
|
-
case
|
|
922
|
+
case 11:
|
|
1163
923
|
result = _context.sent;
|
|
1164
924
|
deployResults.push(result);
|
|
1165
925
|
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
|
-
case 15:
|
|
1171
|
-
_context.next = 8;
|
|
926
|
+
case 13:
|
|
927
|
+
_context.next = 7;
|
|
1172
928
|
break;
|
|
1173
929
|
|
|
1174
|
-
case
|
|
1175
|
-
lighthouseResults = runLighthouse(urlsToCheck);
|
|
930
|
+
case 15:
|
|
1176
931
|
lastCommit = danger.git.commits[0];
|
|
1177
932
|
markdown(["## Deploy preview", "Deploy preview for *front10-ui* ready!", "Built with commit " + lastCommit.sha].concat(deployResults.map(function (result, index) {
|
|
1178
933
|
return configs[index].label + ": " + result.deploy.deploy_ssl_url;
|
|
1179
|
-
})
|
|
1180
|
-
_context.next =
|
|
934
|
+
})).join("\n\n"));
|
|
935
|
+
_context.next = 23;
|
|
1181
936
|
break;
|
|
1182
937
|
|
|
1183
|
-
case
|
|
1184
|
-
_context.prev =
|
|
938
|
+
case 19:
|
|
939
|
+
_context.prev = 19;
|
|
1185
940
|
_context.t0 = _context["catch"](2);
|
|
1186
941
|
console.error(_context.t0);
|
|
1187
942
|
fail("Couldn't get deploy information.");
|
|
1188
943
|
|
|
1189
|
-
case
|
|
944
|
+
case 23:
|
|
1190
945
|
case "end":
|
|
1191
946
|
return _context.stop();
|
|
1192
947
|
}
|
|
1193
948
|
}
|
|
1194
|
-
}, _callee, null, [[2,
|
|
949
|
+
}, _callee, null, [[2, 19]]);
|
|
1195
950
|
}));
|
|
1196
951
|
return _deploy.apply(this, arguments);
|
|
1197
952
|
}
|
|
1198
953
|
|
|
1199
|
-
function getUrlsToCheck(info, pagesToCheck) {
|
|
1200
|
-
var baseUrl = info.deploy.deploy_ssl_url;
|
|
1201
|
-
return pagesToCheck.map(function (page) {
|
|
1202
|
-
return baseUrl + "/" + page;
|
|
1203
|
-
});
|
|
1204
|
-
}
|
|
1205
|
-
|
|
1206
|
-
function runLighthouse(urlsToCheck) {
|
|
1207
|
-
if (urlsToCheck.length === 0) {
|
|
1208
|
-
return [];
|
|
1209
|
-
}
|
|
1210
|
-
|
|
1211
|
-
var lighthouseConfigDir = "lighthouserc.json";
|
|
1212
|
-
var lighthouseConfig = JSON.parse(fs.readFileSync(lighthouseConfigDir).toString());
|
|
1213
|
-
lighthouseConfig.ci.collect.url = urlsToCheck;
|
|
1214
|
-
fs.writeFileSync(lighthouseConfigDir, JSON.stringify(lighthouseConfig));
|
|
1215
|
-
child_process.execSync('npx @lhci/cli@0.7.x autorun || echo "LHCI failed!"', {
|
|
1216
|
-
encoding: "utf-8"
|
|
1217
|
-
});
|
|
1218
|
-
var links = JSON.parse(fs.readFileSync(".lighthouseci/links.json").toString());
|
|
1219
|
-
return ["## Lighthouse report", Object.entries(links).map(function (_ref2) {
|
|
1220
|
-
var page = _ref2[0],
|
|
1221
|
-
resportUrl = _ref2[1];
|
|
1222
|
-
return "- [" + page + "](" + resportUrl + ")";
|
|
1223
|
-
}).join("\n")];
|
|
1224
|
-
}
|
|
1225
|
-
|
|
1226
954
|
var pluginNetlify = {
|
|
1227
955
|
__proto__: null,
|
|
1228
956
|
deploySite: deploySite,
|
|
@@ -1248,11 +976,11 @@ function generateMDTable(headers, body) {
|
|
|
1248
976
|
function getDefaultGetBundlesFn(bundlePrefix) {
|
|
1249
977
|
return function defaultGetBundlesFn(bundlesDir) {
|
|
1250
978
|
return fs.readdirSync(bundlesDir).map(function (name) {
|
|
1251
|
-
return
|
|
979
|
+
return path.join(bundlesDir, name);
|
|
1252
980
|
}).filter(function (dirName) {
|
|
1253
981
|
return fs.lstatSync(dirName).isDirectory();
|
|
1254
982
|
}).map(function (dirName) {
|
|
1255
|
-
return
|
|
983
|
+
return path.join(dirName, path.basename(dirName).replace(bundlePrefix, "") + ".bundle.js");
|
|
1256
984
|
});
|
|
1257
985
|
};
|
|
1258
986
|
}
|
|
@@ -1285,7 +1013,7 @@ function bundleSizeResults(_ref) {
|
|
|
1285
1013
|
var jsFile = fs.readFileSync(filePath);
|
|
1286
1014
|
var fileSizes = [jsFile].concat(gzip ? [zlib.gzipSync(jsFile)] : [], brotli ? [zlib.brotliCompressSync(jsFile)] : []);
|
|
1287
1015
|
return {
|
|
1288
|
-
filename: renameFn(
|
|
1016
|
+
filename: renameFn(path.basename(filePath)),
|
|
1289
1017
|
sizes: fileSizes.map(function (file) {
|
|
1290
1018
|
return file.length;
|
|
1291
1019
|
})
|
|
@@ -1361,9 +1089,13 @@ function _bundleSize() {
|
|
|
1361
1089
|
|
|
1362
1090
|
if (baseResults) {
|
|
1363
1091
|
_baseResults = baseResults, bundles = _baseResults.bundles, brotli = _baseResults.brotli, gzip = _baseResults.gzip;
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1092
|
+
|
|
1093
|
+
if (bundles) {
|
|
1094
|
+
bundles.forEach(function (bundle) {
|
|
1095
|
+
baseBundles.set(bundle.filename, bundle.sizes);
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1367
1099
|
diffHeaders = ["Filesize diff"].concat(gzip ? ["Gzip diff"] : [], brotli ? ["Brotli diff"] : []);
|
|
1368
1100
|
}
|
|
1369
1101
|
|
|
@@ -1449,8 +1181,6 @@ function _lighthouse() {
|
|
|
1449
1181
|
|
|
1450
1182
|
exports.bundleSize = bundleSize;
|
|
1451
1183
|
exports.bundleSizeResults = bundleSizeResults;
|
|
1452
|
-
exports.eslint = eslint;
|
|
1453
|
-
exports.jest = jest;
|
|
1454
1184
|
exports.lighthouse = lighthouse;
|
|
1455
1185
|
exports.netlify = pluginNetlify;
|
|
1456
1186
|
//# sourceMappingURL=danger-plugins.cjs.development.js.map
|