cli-diagnostics: Keep track of missing file sources for nicer frame advice
MODIFY
packages/@romejs/cli-diagnostics/DiagnosticsPrinter.ts
packages/@romejs/cli-diagnostics/DiagnosticsPrinter.ts
@@ -42,6 +42,7 @@ import {
UnknownFilePath,
UnknownFilePathMap,
UnknownFilePathSet,
+ AbsoluteFilePathSet,
} from '@romejs/path';
import {Number1, Number0} from '@romejs/ob1';
import {existsSync, readFileTextSync, lstatSync} from '@romejs/fs';
@@ -138,6 +139,7 @@ export default class DiagnosticsPrinter extends Error {
this.filteredCount = 0;
this.truncatedCount = 0;
+ this.missingFileSources = new AbsoluteFilePathSet();
this.fileSources = new UnknownFilePathMap();
this.fileMtimes = new UnknownFilePathMap();
this.beforeFooterPrint = [];
@@ -149,6 +151,8 @@ export default class DiagnosticsPrinter extends Error {
flags: DiagnosticsPrinterFlags;
cwd: AbsoluteFilePath;
readFile: DiagnosticsFileReader;
+
+ missingFileSources: AbsoluteFilePathSet;
fileSources: DiagnosticsPrinterFileSources;
fileMtimes: DiagnosticsPrinterFileMtimes;
@@ -344,8 +348,11 @@ export default class DiagnosticsPrinter extends Error {
continue;
}
- const stats = this.readFile(path.assertAbsolute());
- if (stats !== undefined) {
+ const abs = path.assertAbsolute();
+ const stats = this.readFile(abs);
+ if (stats === undefined) {
+ this.missingFileSources.add(abs);
+ } else {
this.addFileSource(dep, stats);
}
}
@@ -477,6 +484,7 @@ export default class DiagnosticsPrinter extends Error {
for (const item of advice) {
const noSpacer = printAdvice(item, {
flags: this.flags,
+ missingFileSources: this.missingFileSources,
fileSources: this.fileSources,
diagnostic: diag,
reporter,

MODIFY
packages/@romejs/cli-diagnostics/printAdvice.ts
packages/@romejs/cli-diagnostics/printAdvice.ts
@@ -28,10 +28,11 @@ import {formatAnsi} from '@romejs/string-ansi';
import {DiagnosticsPrinterFlags} from './types';
import {number0Neg1} from '@romejs/ob1';
import {DiagnosticsPrinterFileSources} from './DiagnosticsPrinter';
-import {createUnknownFilePath} from '@romejs/path';
+import {createUnknownFilePath, AbsoluteFilePathSet} from '@romejs/path';
type AdvicePrintOptions = {
flags: DiagnosticsPrinterFlags;
+ missingFileSources: AbsoluteFilePathSet;
fileSources: DiagnosticsPrinterFileSources;
reporter: Reporter;
diagnostic: Diagnostic;
@@ -143,6 +144,11 @@ function printFrame(
});
} else if (filename !== undefined) {
lines = opts.fileSources.get(path);
+ } else if (
+ path.isAbsolute() &&
+ opts.missingFileSources.has(path.assertAbsolute())
+ ) {
+ lines = [formatAnsi.dim('file does not exist')];
}
if (lines === undefined) {
lines = [];

cli-diagnostics: Keep track of missing file sources for nicer frame advice