UNPKG

2.68 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.LightReport = void 0;
4const Report_1 = require("./Report");
5const StreamReport_1 = require("./StreamReport");
6class LightReport extends Report_1.Report {
7 constructor({ configuration, stdout, suggestInstall = true }) {
8 super();
9 this.errorCount = 0;
10 this.configuration = configuration;
11 this.stdout = stdout;
12 this.suggestInstall = suggestInstall;
13 }
14 static async start(opts, cb) {
15 const report = new this(opts);
16 try {
17 await cb(report);
18 }
19 catch (error) {
20 report.reportExceptionOnce(error);
21 }
22 finally {
23 await report.finalize();
24 }
25 return report;
26 }
27 hasErrors() {
28 return this.errorCount > 0;
29 }
30 exitCode() {
31 return this.hasErrors() ? 1 : 0;
32 }
33 reportCacheHit(locator) {
34 }
35 reportCacheMiss(locator) {
36 }
37 startTimerSync(what, cb) {
38 return cb();
39 }
40 async startTimerPromise(what, cb) {
41 return await cb();
42 }
43 async startCacheReport(cb) {
44 return await cb();
45 }
46 reportSeparator() {
47 }
48 reportInfo(name, text) {
49 }
50 reportWarning(name, text) {
51 }
52 reportError(name, text) {
53 this.errorCount += 1;
54 this.stdout.write(`${this.configuration.format(`➤`, `redBright`)} ${this.formatNameWithHyperlink(name)}: ${text}\n`);
55 }
56 reportProgress(progress) {
57 const promise = Promise.resolve().then(async () => {
58 // eslint-disable-next-line no-empty-pattern
59 for await (const {} of progress) {
60 // No need to do anything; we just want to consume the progress events
61 }
62 });
63 const stop = () => {
64 // Nothing to stop
65 };
66 return { ...promise, stop };
67 }
68 reportJson(data) {
69 // Just ignore the json output
70 }
71 async finalize() {
72 if (this.errorCount > 0) {
73 this.stdout.write(`${this.configuration.format(`➤`, `redBright`)} Errors happened when preparing the environment required to run this command.\n`);
74 if (this.suggestInstall) {
75 this.stdout.write(`${this.configuration.format(`➤`, `redBright`)} This might be caused by packages being missing from the lockfile, in which case running "yarn install" might help.\n`);
76 }
77 }
78 }
79 formatNameWithHyperlink(name) {
80 return StreamReport_1.formatNameWithHyperlink(name, {
81 configuration: this.configuration,
82 json: false,
83 });
84 }
85}
86exports.LightReport = LightReport;