Conversation
refactor!: commandDir removed (due to not working with ESM)
|
@shadowspawn this is a work in progress, but porting over tests is going pretty smoothly so far. |
|
Oh ho, exciting! |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
@shadowspawn switched to using
@shadowspawn thanks for the PR on cliui, I think this is mostly addressed (although I expect we'll have some follow up PRs on that repo). I was able to stop skipping all the tests related to string wrapping 👍 |
|
I have done a pass through whole PR and made some minor comments and questions, nothing blocking. I plan to do a little user testing on old and new commandDir next. |
|
The documentation for Lines 272 to 278 in ef28c98 The previous code was passing through user supplied options object so the user could also supply other |
There was a problem hiding this comment.
I'm sure I've broken some other things with this major overhaul, we'll keep this in beta for a healthy length of time.
Qualified approval. I think .commandDir() still a work in progress with include/exclude to implement or deprecate. But overall and notwithstanding .commandDir(), up to at least beta quality with what I saw and tried.
Nice work!
Co-authored-by: John Gee <john@ruru.gen.nz>
|
Regarding:
@shadowspawn I've added back support for
Given that this behaviour isn't documented in yargs, I think it's not a breaking change to remove it. |
| // disable recursion to support nested directories of subcommands | ||
| if (typeof opts.recurse !== 'boolean') opts.recurse = false; | ||
| this.requireCache.add(callerFile); | ||
| const fullDirPath = join(dirname(callerFile), dir); |
There was a problem hiding this comment.
Hey, I found that commandDir has been changed to be relative from here on. I just want to know the reason. Is it related to security concerns? Because in my case, I use the commandDir feature extensively to load commands from various locations (v17.7.2), not just from a single project directory. For example, I combine project commands, home directory commands, and global directory commands. With this change, my approach has become completely unfeasible. So I'd like to know if there's an option that allows the directory to be an absolute directory.
There was a problem hiding this comment.
Except for the above case, there is another scenario that would also fail. Put yargs in the @org/core package, and export an API to launch CLI tools. Then, add commands from another package that imports @org/core and passes the directory via the API.
There was a problem hiding this comment.
The intent is that the directory passed into .commandDir() can be absolute, and it is probably an oversight (bug) if an absolute path passed into .commandDir() does not work.
Have you confirmed this problem at runtime, or is this feedback from code inspection?
(I won't have time to try reproducing and look carefully until later.)
There was a problem hiding this comment.
I prepared a demo repo for this issue. It can be reproduced. When you have time, you can give it a shot.
https://github.com/vipzhicheng/test-yargs-next
Logically, fullDirPath is callerFile dir + passed in dir, I hope it is just passed in dir, like before.
There was a problem hiding this comment.
Thanks for the example repo, and I reproduced the issue as described.
High level, I suspect replacing path.join with path.resolve at some level is appropriate.
I checked original package for comparison and it does use path.resolve in implementation: https://github.com/troygoode/node-require-directory/blob/d1fd7dc2eaf02832de94dbe1af0c52271697050e/index.js#L56C1-L57C1
There was a problem hiding this comment.
@vipzhicheng Would you like to make a new issue, or even a PR, or shall I open one based on this info?
Thanks for taking a look at the pre-release and reporting the issue. Much appreciated.
There was a problem hiding this comment.
I have made a PR #2465, Please take a look.
Just like you suggested, it works in my test repo and also still passes all npm run test after the change.
See: https://joyeecheung.github.io/blog/2024/03/18/require-esm-in-node-js/ for what's motivating this work.
Yargs build step to be dual-mode ESM / CJS had created a fragile build process that has been hard to upgrade over the years. I'm quite excited to remove it.
Known Breaking Changes:
commandDir. If you are providing a module directly, acommandproperty must be set.^20.19.0 || ^22.12.0 || >=23(there were fixes to issues with require ESM in patch releases of 20.x and 22.x which is why the complicated version range is necessary).yargs.parse(),yargs.argv.TODO:
Notes
cliui doesn't wrap properly because it's using an old version of wrap-ansi. TODO, unravel this problem.fixed thanks @shadowspawn.1000 lbs 🦍 in the room, should we figure out a replacement forFigured out how to makecommandDir, perhaps usingcreateRequire? could this be a follow up PR to reduce the scope of this work? (CC: @shadowspawn thoughts).commandDirwork, including inferring name of command from directory.BEGIN_COMMIT_OVERRIDE
feat!: yargs is now ESM first
refactor!: command names are not derived from modules passed to
command.refactor!: singleton usage of yargs yargs.foo, yargs().argv, has been removed.
build!: minimum node.js versions now
^20.19.0 || ^22.12.0 || >=23.END_COMMIT_OVERRIDE