Fixed messages prefixes processing; more type annotations

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 8 years ago
parent 11f9cdba9b
commit 7bbefd1555
  1. 20
      BuildServer/lib/builder.ts
  2. 4
      BuildServer/lib/report-processor.ts
  3. 24
      BuildServer/lib/task-processor.ts

@ -115,13 +115,13 @@ export const build = (options, buildCallback) => {
return result.messages.$allMessages.map((msg) => `${msg.prefix}\t${msg.message}`).join("\r\n");
};
const done = (doneErr, result?) => {
const allErrors = ((result || {}).errors || {}).$allMessages || [];
const allWarns = ((result || {}).warns || {}).$allMessages || [];
const allInfos = ((result || {}).infos || {}).$allMessages || [];
const errorMessage = (allErrors[0] || {}).message || doneErr;
const warnMessage = (allWarns[0] || {}).message;
const infoMessage = (allInfos[allInfos.length - 1] || {}).message;
const done = (doneErr, result?: ReportResult) => {
const allErrors = (result && result.errors && result.errors.$allMessages) || [];
const allWarns = (result && result.warns && result.errors.$allMessages) || [];
const allInfos = (result && result.infos && result.errors.$allMessages) || [];
const errorMessage = (allErrors[0] && allErrors[0].message) || doneErr;
const warnMessage = allWarns[0] && allWarns[0].message;
const infoMessage = allInfos[allInfos.length - 1] && allInfos[allInfos.length - 1].message;
writeReport(release, doneErr, result, (writeErr) => {
statusQueue.push((queueCallback) => parallel([
@ -173,12 +173,12 @@ export const build = (options, buildCallback) => {
return exists(join(exported, "mbs.json"), (exists) => {
if (!exists) {
return done(null, "MBSNotFound");
return done("MBSNotFound");
}
return readFile(join(exported, "mbs.json"), (readErr, data) => {
if (readErr) {
return done(readErr, "MBSUnableToRead");
return done(`MBSUnableToRead: ${readErr}`);
}
const { value, error } = JSONParse(data);
@ -186,7 +186,7 @@ export const build = (options, buildCallback) => {
if (error) {
console.log(`Malformed data: ${data}`);
return done(error, "MBSMalformed");
return done("MBSMalformed");
}
return processTask(value, {

@ -24,12 +24,12 @@ const getAllErrors = (report: Report): Message[] => (report.result && report.res
const getAllWarns = (report: Report): Message[] => (report.result && report.result.warns && report.result.errors.$allMessages) || [];
const getAllInfos = (report: Report): Message[] => (report.result && report.result.infos && report.result.errors.$allMessages) || [];
export const writeReport = (releaseDir, err, result: ReportResult, callback) => {
export const writeReport = (releaseDir, err, result: ReportResult | undefined, callback) => {
const data = JSON.stringify({
date: Date.now(),
err,
result,
});
} as Report);
const readable = new ReadableStreamBuffer(readableStreamBufferOptions);
const writeStream = createWriteStream(join(releaseDir, reportFilename));

@ -36,19 +36,25 @@ const createTaskProcessor = (task: TaskInfo, outerProcessor: TaskProcessorCore,
const pushMessage = (list, message, parts, index) => {
if (!index) {
list.$allMessages = list.$allMessages || [];
list.$allMessages.push({
message,
prefix: parts.join("/"),
});
}
list.$messages = list.$messages || [];
if (index === parts.length) {
return list.$messages.push(message);
if (index < parts.length) {
if (!list[parts[index]]) {
list[parts[index]] = {};
}
return pushMessage(list[parts[index]], message, parts, index + 1);
}
return pushMessage(list, message, parts, index + 1);
if (!list.$messages) {
list.$messages = [];
}
return list.$messages.push(message);
};
const addFlag = (flags) => (flagName) => {
@ -58,10 +64,10 @@ const addFlag = (flags) => (flagName) => {
const containsFlag = (flags) => (flagName) => flags[flagName];
export const processTask = (task, context, callback) => {
const errors = {};
const warns = {};
const infos = {};
const messages = {};
const errors: MessagesRoot = { $allMessages: [] };
const warns: MessagesRoot = { $allMessages: [] };
const infos: MessagesRoot = { $allMessages: [] };
const messages: MessagesRoot = { $allMessages: [] };
const messageProcessor = (list) => (message, prefix) => {
const parts = prefix.split("/");

Loading…
Cancel
Save