microsoft / dts-gen

dts-gen creates starter TypeScript definition files for any module or library.
MIT License
2.43k stars 102 forks source link

Fix expression-file by using require and path.resolve #168

Open aminya opened 3 years ago

aminya commented 3 years ago

Use it until this is merged:

npm install -g @aminya/dts-gen

dts-gen --expression-file=./your_file.js

Description

It fixes expression-file to support any JavaScript file as the input.

Fixes #58 Fixes #65 Fixes #105

Reasoning

It seems that eval acts buggy when it comes to resolving dependencies. But require doesn't have this issue as it is just what Node uses by default. Also, path.resolve is needed before passing the file path to require.

Suggestion

If I could, I would have renamed expression-file to file and renamed the current file argument to output-file. The naming of the arguments is inaccurate and confusing.

ghost commented 3 years ago

CLA assistant check
All CLA requirements met.

aminya commented 3 years ago

@orta @sandersn Could you take a look at this?

aminya commented 3 years ago

To fix #58, I would prefer to add a new option instead of changing what --expression-file means.

I wanted to call this --file but it is already taken (it should have been --output-file. Maybe --input-file is a good name.

It's likely that the fix for #65 will be more complicated, since it will have to retain the eval-last-expression behaviour of --expression-file.

There is no such requirement. People use --expression-file as a workaround because there is no other way to generate types for a file. Even if we removed this option, I doubt anyone would complain.

aminya commented 3 years ago

@sandersn Should we fix #169?

Aericio commented 2 years ago

How can I build and try this branch?

aminya commented 2 years ago

I can publish this on npm if you like. It is more maintained than dts-gen.

Aericio commented 2 years ago

That'd be great.

aminya commented 2 years ago

Here you go. I have published it until this is merged:

npm install -g @aminya/dts-gen

dts-gen --expression-file=./your_file.js
tomaszs commented 1 year ago

Anyone?