From 47081db8dedacc2f553d53cd157f1db8cbd9ad2e Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Thu, 14 Mar 2024 12:15:40 -0600 Subject: [PATCH] fix: ensure string is passed to process.emitWarning (#1015) * fix: ensure string is passed to process.emitWarning * fix: allow ts-path to find tsx files --- src/config/plugin.ts | 5 +++-- src/config/ts-path.ts | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/config/plugin.ts b/src/config/plugin.ts index e6ba4e9a3..7d68a7674 100644 --- a/src/config/plugin.ts +++ b/src/config/plugin.ts @@ -343,7 +343,7 @@ export class Plugin implements IPlugin { } private addErrorScope(err: any, scope?: string) { - err.name = `${err.name} Plugin: ${this.name}` + err.name = err.name ?? inspect(err).trim() err.detail = compact([ err.detail, `module: ${this._base}`, @@ -431,6 +431,7 @@ export class Plugin implements IPlugin { private warn(err: CLIError | Error | string, scope?: string): void { if (typeof err === 'string') err = new Error(err) - process.emitWarning(this.addErrorScope(err, scope)) + const warning = this.addErrorScope(err, scope) + process.emitWarning(warning.name, warning) } } diff --git a/src/config/ts-path.ts b/src/config/ts-path.ts index fe1a153fc..a37a094ff 100644 --- a/src/config/ts-path.ts +++ b/src/config/ts-path.ts @@ -1,3 +1,4 @@ +import {access} from 'node:fs/promises' import {join, relative as pathRelative, sep} from 'node:path' import * as TSNode from 'ts-node' @@ -212,8 +213,23 @@ async function determinePath(root: string, orig: string): Promise { debug(`lib dir: ${lib}`) debug(`src dir: ${src}`) - debug(`src commands dir: ${out}`) - if (existsSync(out) || existsSync(out + '.ts')) { + debug(`src directory to find: ${out}`) + + if (existsSync(out)) { + debug(`Found source directory for ${orig} at ${out}`) + return out + } + + const sourceFiles = await Promise.all([ + access(`${out}.ts`) + .then(() => `${out}.ts`) + .catch(() => false), + access(`${out}.tsx`) + .then(() => `${out}.tsx`) + .catch(() => false), + ]) + + if (sourceFiles.some(Boolean)) { debug(`Found source file for ${orig} at ${out}`) return out }