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

Add fileSuffix option #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mike-marcacci
Copy link
Contributor

TypeScript projects that use several moduleResolution settings (including "NodeNext") require that file imports include the entire filename (with extension) in their references.

This adds a --fileSuffix option which can be set to .js in these scenarios.

TypeScript projects that use several `moduleResolution` settings (including "NodeNext") require that file imports include the entire filename (with extension) in their references.

This adds a `--fileSuffix` option which can be set to `.js` in these scenarios.
@dderevjanik
Copy link
Owner

dderevjanik commented May 3, 2024

@mike-marcacci Thanks for your contribution!

Initially, I misunderstood the purpose of --fileSuffix and assumed it would add a suffix to every generated file. Upon reading your comments, I now understand that it's related to module resolutions, particularly for TypeScript projects using "NodeNext".

I wonder if we should consider renaming this option to better reflect its purpose or the reason behind its creation, perhaps something like --moduleResolution=NodeNext? This could make it clearer for future users. What do you think?

EDIT: or something like --NodeNextModuleResolution

@dderevjanik dderevjanik mentioned this pull request May 3, 2024
@mike-marcacci
Copy link
Contributor Author

mike-marcacci commented May 3, 2024

Hey @dderevjanik, thanks for the quick response!

I used --fileSuffix since I'm not entirely sure if there are valid scenarios where the files built by TS (or some combination of TS and another build tool) may actually have .mjs or .cjs file extensions, so I left the flag flexible enough to support that scenario.

I don't personally have that use-case, and it might not even be a good practice or even possible, so I'm perfectly happy to change this to --NodeNextModuleResolution.

Let me know if you still have a preference for --NodeNextModuleResolution and I'll update this PR with those changes.

@dderevjanik
Copy link
Owner

@mike-marcacci

Was thinking about it again and would be nice to have --moduleResolution option similar to Typescript version, where you can specify module resolution strategy. To not overcomplicate it, let's start with supporting only two "Node" (by default) and "NodeNext" (suffix imports with .js).

Initially, we could support two resolution strategies: "Node" (which would be the default) and "NodeNext" (which would suffix imports with .js). Implementing this wouldn't necessarily complicate things; we could refactor the addSafeImport() function to accommodate an additional argument moduleResolution, utilizing a switch/case structure to handle different resolution strategies.

By aligning with TypeScript's convention, users of wsdl-tsclient would find it easier to locate and utilize their desired options. Plus, it sets the stage for potential future enhancements in line with TypeScript's capabilities.

What are your thoughts on this approach?

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.

None yet

2 participants