From 109e6f055445a6a4c11727f75d3f937f10a5da3d Mon Sep 17 00:00:00 2001 From: Ben Irvin Date: Mon, 20 May 2024 15:16:05 +0200 Subject: [PATCH] fix: log levels (#10) Co-authored-by: Josh --- .changeset/red-frogs-cry.md | 5 +++++ src/node/tasks/dts/diagnostic.ts | 38 ++++++++++++++++---------------- 2 files changed, 24 insertions(+), 19 deletions(-) create mode 100644 .changeset/red-frogs-cry.md diff --git a/.changeset/red-frogs-cry.md b/.changeset/red-frogs-cry.md new file mode 100644 index 0000000..12554da --- /dev/null +++ b/.changeset/red-frogs-cry.md @@ -0,0 +1,5 @@ +--- +'@strapi/pack-up': patch +--- + +Use correct log level for all errors diff --git a/src/node/tasks/dts/diagnostic.ts b/src/node/tasks/dts/diagnostic.ts index 5ce66b8..17b5b6c 100644 --- a/src/node/tasks/dts/diagnostic.ts +++ b/src/node/tasks/dts/diagnostic.ts @@ -8,35 +8,35 @@ const printDiagnostic = ( diagnostic: ts.Diagnostic, { logger, cwd }: { logger: Logger; cwd: string } ) => { + let output = ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine); + if (diagnostic.file && diagnostic.start) { const { line, character } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine); const file = path.relative(cwd, diagnostic.file.fileName); - const output = [ + output = [ `${chalk.cyan(file)}:${chalk.cyan(line + 1)}:${chalk.cyan(character + 1)} - `, `${chalk.gray(`TS${diagnostic.code}:`)} ${message}`, ].join(''); + } - switch (diagnostic.category) { - case ts.DiagnosticCategory.Error: - logger.error(output); - break; - case ts.DiagnosticCategory.Warning: - logger.warn(output); - break; - case ts.DiagnosticCategory.Message: - logger.info(output); - break; - case ts.DiagnosticCategory.Suggestion: - logger.info(output); - break; - default: - break; - } - } else { - logger.info(ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine)); + switch (diagnostic.category) { + case ts.DiagnosticCategory.Error: + logger.error(output); + break; + case ts.DiagnosticCategory.Warning: + logger.warn(output); + break; + case ts.DiagnosticCategory.Message: + logger.info(output); + break; + case ts.DiagnosticCategory.Suggestion: + logger.info(output); + break; + default: + break; } };