Closed alexanderl19 closed 2 years ago
I love your idea. Would you open a pull request for this? Not directly related to this issue though, I'm also thinking about having an interactive prompt to allow users to choose which package manager to use (kind of busy to get around to it right now)
Yeah, I'd be more than happy to open a PR.
I'm not actually quite sure what's the most optimal way to implement this feature though. A few options that come to mind are:
If the second option is possible, the package manager prompt is probably pretty redundant. For example, I don't see why someone would run the cli with yarn and then want packages installed via npm.
Thanks for the input! Combining your idea, the flow is going to look like this (right?):
--node-pm
is specified, use that as a package manager for npmCommand
npm
I did some digging and turns out VS Code also has a package manager detection feature.
I believe they're using which-pm under the hood. https://github.com/microsoft/vscode/blob/ba2dd825803b5f95d5dcce927afc3a4882ed0f84/extensions/npm/package.json#L27
If you're okay with adding an additional dependency, which-pm-runs seems to be a good fit for what we're trying to accomplish.
Here's an updated list of how the package manager would be determined, in order from highest priority to lowest.
In terms of the package manager selection, I think these options would work:
@alexanderl19 Nice finds! Just skimmed through which-pm-runs and realized that there were just a few lines of code, meaning nothing affects package size.
Note: create-something -> the another create- app generated by create-create-app
--template
) or an interactive prompt. If there are no multiple templates available, just skip 1
.package.json
in the root of the selected template directory, go to 3
. Otherwise, do nothing.--node-pm
CLI flag is specified, just use that. Otherwise, detect running package manager and use it. If failed to detect, use npm.We won't expose any config for Node.js package manager on create
function because it's just redundant. Bear in mind that in the future I might reconsider the design based on further feedback.
I think we're on the same page now, so I'll work up a PR when I'm able to find some time. Thanks for all the input!
Quality of life feature for displaying commands in caveat text. Would support use cases such as https://github.com/vercel/next.js/blob/0cb2037a41c27d4ced57b5479e27edf96f748083/packages/create-next-app/create-app.ts#L308-L326.
packageManager variable in AfterHookOptions:
or with a helper function