Skip to content

Commit

Permalink
fix: ensure string is passed to process.emitWarning (#1015)
Browse files Browse the repository at this point in the history
* fix: ensure string is passed to process.emitWarning

* fix: allow ts-path to find tsx files
  • Loading branch information
mdonnalley authored Mar 14, 2024
1 parent 7126bc3 commit 47081db
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/config/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down Expand Up @@ -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)
}
}
20 changes: 18 additions & 2 deletions src/config/ts-path.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -212,8 +213,23 @@ async function determinePath(root: string, orig: string): Promise<string> {

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
}
Expand Down

0 comments on commit 47081db

Please sign in to comment.