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"); return result.messages.$allMessages.map((msg) => `${msg.prefix}\t${msg.message}`).join("\r\n");
}; };
const done = (doneErr, result?) => { const done = (doneErr, result?: ReportResult) => {
const allErrors = ((result || {}).errors || {}).$allMessages || []; const allErrors = (result && result.errors && result.errors.$allMessages) || [];
const allWarns = ((result || {}).warns || {}).$allMessages || []; const allWarns = (result && result.warns && result.errors.$allMessages) || [];
const allInfos = ((result || {}).infos || {}).$allMessages || []; const allInfos = (result && result.infos && result.errors.$allMessages) || [];
const errorMessage = (allErrors[0] || {}).message || doneErr; const errorMessage = (allErrors[0] && allErrors[0].message) || doneErr;
const warnMessage = (allWarns[0] || {}).message; const warnMessage = allWarns[0] && allWarns[0].message;
const infoMessage = (allInfos[allInfos.length - 1] || {}).message; const infoMessage = allInfos[allInfos.length - 1] && allInfos[allInfos.length - 1].message;
writeReport(release, doneErr, result, (writeErr) => { writeReport(release, doneErr, result, (writeErr) => {
statusQueue.push((queueCallback) => parallel([ statusQueue.push((queueCallback) => parallel([
@ -173,12 +173,12 @@ export const build = (options, buildCallback) => {
return exists(join(exported, "mbs.json"), (exists) => { return exists(join(exported, "mbs.json"), (exists) => {
if (!exists) { if (!exists) {
return done(null, "MBSNotFound"); return done("MBSNotFound");
} }
return readFile(join(exported, "mbs.json"), (readErr, data) => { return readFile(join(exported, "mbs.json"), (readErr, data) => {
if (readErr) { if (readErr) {
return done(readErr, "MBSUnableToRead"); return done(`MBSUnableToRead: ${readErr}`);
} }
const { value, error } = JSONParse(data); const { value, error } = JSONParse(data);
@ -186,7 +186,7 @@ export const build = (options, buildCallback) => {
if (error) { if (error) {
console.log(`Malformed data: ${data}`); console.log(`Malformed data: ${data}`);
return done(error, "MBSMalformed"); return done("MBSMalformed");
} }
return processTask(value, { 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 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) || []; 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({ const data = JSON.stringify({
date: Date.now(), date: Date.now(),
err, err,
result, result,
}); } as Report);
const readable = new ReadableStreamBuffer(readableStreamBufferOptions); const readable = new ReadableStreamBuffer(readableStreamBufferOptions);
const writeStream = createWriteStream(join(releaseDir, reportFilename)); const writeStream = createWriteStream(join(releaseDir, reportFilename));

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

Loading…
Cancel
Save