Skip to content

Commit

Permalink
fix(LoaderStrategy): add .ts to allow for ts-node usage (#87)
Browse files Browse the repository at this point in the history
fixes #86

Co-authored-by: Antonio Román <kyradiscord@gmail.com>
  • Loading branch information
favna and kyranet committed Jun 23, 2021
1 parent b93dbf2 commit 193abcd
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/lib/strategies/LoaderStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,22 @@ import { classExtends, isClass } from './Shared';
* Modules and CommonJS with reloading support.
*/
export class LoaderStrategy<T extends Piece> implements ILoaderStrategy<T> {
private readonly clientUsesESModules: boolean = getRootData().type === 'ESM';
private readonly supportedExtensions: readonly string[] = ['.js', '.cjs', '.mjs'];
public clientUsesESModules = getRootData().type === 'ESM';
public supportedExtensions = ['.js', '.cjs', '.mjs'];

public constructor() {
/**
* If {@linkplain https://github.com/TypeStrong/ts-node ts-node} is being used
* we conditionally need to register files ending in the `.ts` file extension.
*
* This is because `ts-node` builds files into memory, so we have to scan the
* source `.ts` files, rather than files emitted with any of the JavaScript
* extensions.
*/
if (Reflect.has(process, Symbol.for('ts-node.register.instance'))) {
this.supportedExtensions.push('.ts');
}
}

public filter(path: string): FilterResult {
// Retrieve the file extension.
Expand Down

0 comments on commit 193abcd

Please sign in to comment.