Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow .tsx and .jsx help class files #1016

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading