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

Support .js imports from typescript #510

Merged
merged 3 commits into from
Feb 21, 2020
Merged

Support .js imports from typescript #510

merged 3 commits into from
Feb 21, 2020

Conversation

guybedford
Copy link
Contributor

@guybedford guybedford commented Feb 20, 2020

This resolves #508 in allowing the pattern for TypeScript code using .js extensions to reference other TypeScript files.

This is currently recommended by the TypeScript team (microsoft/TypeScript#16577 (comment)) as an approach for writing TypeScript that will include the file extensions in the output files when using tsc manually, resulting in Node.js and browser compatibility for the output.

With this PR, ncc doesn't have to break enabling this workflow for users, while remaining backwards compatible with the previous behaviour so it would be fine to release this as a minor.

src/index.js Outdated Show resolved Hide resolved
@styfle
Copy link
Member

styfle commented Feb 20, 2020

@guybedford Do we also need too add this behavior to node-file-trace?

@styfle styfle changed the title Support .js ts imports Support .js imports from typescript Feb 20, 2020
@guybedford
Copy link
Contributor Author

@styfle thanks for the quick review. Yes ideally node-file-trace would include the same (if it doesn't support it already), and this is something I'd recommend checking in other workflows too.

@guybedford
Copy link
Contributor Author

Ok, I've included a guard that this extension fallback only happens when importing from another TypeScript file, and I also added a test here for nested imports of .ts.

Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Supporting .js imports for TypeScript
2 participants