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

feat: support TS directory imports for ESM #422

Merged
merged 1 commit into from
May 20, 2022
Merged
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
7 changes: 5 additions & 2 deletions src/module-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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[] = ['.js', '.mjs', '.cjs']
const s_EXTENSIONS: string[] = ['.ts', '.js', '.mjs', '.cjs']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should .jsx or .tsx file extensions be included?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peternhale aren't .jsx and .tsx files specific to react development?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Anything in oclif that prevents one from using react?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peternhale I just don't see the use case for using jsx syntax in a CLI. I'd rather not support it until someone comes along with a convincing use case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely want to play around with https://github.com/vadimdemedes/ink at some point. Might add it then 😄


/**
* Provides a mechanism to use dynamic import / import() with tsconfig -> module: commonJS as otherwise import() gets
Expand Down Expand Up @@ -110,6 +110,9 @@ export default class ModuleLoader {
case '.js':
return getPackageType.sync(filePath) === 'module'

case '.ts':
return getPackageType.sync(filePath) === 'module'

case '.mjs':
return true

Expand Down Expand Up @@ -155,7 +158,7 @@ export default class ModuleLoader {
// Try all supported extensions.
let foundPath = ModuleLoader.findFile(filePath)
if (!foundPath && isDirectory) {
// Since filePath is a directory, try looking for index.js file.
// Since filePath is a directory, try looking for index file.
foundPath = ModuleLoader.findFile(path.join(filePath, 'index'))
}

Expand Down