Skip to content

Commit

Permalink
fix: allow .tsx and .jsx help class files (#1016)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley authored Mar 15, 2024
1 parent 7fdc399 commit 0b7385f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/help/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import stripAnsi from 'strip-ansi'
import {colorize} from '../cli-ux/theme'
import write from '../cli-ux/write'
import {Command} from '../command'
import {tsPath} from '../config/ts-path'
import {error} from '../errors/error'
import * as Interfaces from '../interfaces'
import {load} from '../module-loader'
Expand Down Expand Up @@ -394,8 +395,9 @@ export async function loadHelpClass(config: Interfaces.Config): Promise<HelpBase

if (configuredClass) {
try {
const exported = (await load(config, configuredClass)) as HelpBaseDerived
return extractClass(exported) as HelpBaseDerived
const path = (await tsPath(config.root, configuredClass)) ?? configuredClass
const exported = await load<HelpBaseDerived>(config, path)
return extractClass(exported)
} catch (error: any) {
throw new Error(
`Unable to load configured help class "${configuredClass}", failed with message:\n${error.message}`,
Expand Down
7 changes: 3 additions & 4 deletions src/module-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const getPackageType = require('get-package-type')
/**
* Defines file extension resolution when source files do not have an extension.
*/
// eslint-disable-next-line camelcase
const s_EXTENSIONS: string[] = ['.ts', '.js', '.mjs', '.cjs', '.mts', '.cts']

const SUPPORTED_EXTENSIONS: string[] = ['.ts', '.js', '.mjs', '.cjs', '.mts', '.cts', '.tsx', '.jsx']

const isPlugin = (config: IConfig | IPlugin): config is IPlugin => (<IPlugin>config).type !== undefined

Expand Down Expand Up @@ -215,8 +215,7 @@ async function resolvePath(config: IConfig | IPlugin, modulePath: string): Promi
* @returns {string | null} Modified file path including extension or null if file is not found.
*/
function findFile(filePath: string): null | string {
// eslint-disable-next-line camelcase
for (const extension of s_EXTENSIONS) {
for (const extension of SUPPORTED_EXTENSIONS) {
const testPath = `${filePath}${extension}`

if (existsSync(testPath)) {
Expand Down

0 comments on commit 0b7385f

Please sign in to comment.