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