-
Notifications
You must be signed in to change notification settings - Fork 994
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
the way we import yargs (lag of documentation) #2045
Comments
@soroushm thank you for the question, I will make an effort to update the documentation with a better explanation. The preferred approach to use is Newer ESM syntax only supports |
@bcoe is that any difference between the two import? import yargs from 'yargs/yargs'
import yargs from 'yargs' |
If you're writing TypeScript, and using the CJS version of the library,
If you're using the ESM version of the library:
|
This looks a good issue for potential improvements to basic recommended patterns, CommonJS vs ESM, and singleton vs factory. The TypeScript instructions could cover |
A musing rather than a recommendation at this point. The magic Reference: #2068 (comment) There could be a small section on the appealing concise but magic singleton invocation: Edit: found another reference that Line 72 in e517318
|
I found importing from So I think Hopefully #2067 has been fixed by addition of separate ESM entry point. (Edit: |
I keep seeing issues with some TypeScript combinations due to the differences in default exports. I wonder whether adding a named export for the yargs factory function would be much simpler to use from TypeScript?! |
Hey @shadowspawn, I'm hoping to start dabbling in OSS a bit again, so digging through some old issues. Thanks for your work on yargs.
I wonder if we should consider deprecating the old singleton behaviour. I think it would be less confusing if The downside of this, is that a lot of folks in the world are using the singleton approach and would need help upgrading. |
Am I correct in thinking that the main benefit (currently) of
Yup, going to break lots of people upgrading. However, people will also be hitting this going from CJS to ESM without causing too many complaints. A related change I would like to investigate is making it easy to use the factory method and implicitly obtain the arguments from For interest, in Commander I have likewise been preparing for dropping the default export of a singleton for years. One decision I made early on was to add a named export of a singleton so it was still available for explicit use, but (eventually) not as the default export. That provides another route for people transitioning. |
I running Yargs in cli, the advanced documentation have two different ways to use yargs,
I will glade somebody explain to me why we need to use yargs as a function?
and do we need it for simple usage like below?
instead of using like this
The text was updated successfully, but these errors were encountered: