sek-consulting / solid-ui

Beautifully designed components. Built with Kobalte & corvu. Styled with Tailwind CSS.
https://www.solid-ui.com
MIT License
680 stars 25 forks source link

CLI package manager #38

Closed jer3m01 closed 2 months ago

jer3m01 commented 7 months ago

The CLI to add components doesn't seem to allow you to change the package manager user and defaults to yarn. pnpx solidui-cli@latest add # Tries to use yarn add

Would be great to save the package manager to config used during initialization.

sek-consulting commented 7 months ago

Thanks for the feedback. For the add command we currently have the following function in place:

export async function installPackages(...packages: string[]) {
  const packageManager = await detect()

  switch (packageManager) {
    case "yarn":
    case "pnpm":
      runCommand(`${packageManager} add ${packages.join(" ")}`, "Installing dependencies")
      break
    default:
      runCommand(`${packageManager} install ${packages.join(" ")}`, "Installing dependencies")
  }
}

With detect() comming from detect-package-manager.

But we could just ask for the package manager at the start of init and just save it for later use. Especially since we ask for the package manager anyway.

sek-consulting commented 7 months ago

I had a deeper look at how shadcn handled the package manager stuff. And it's nearly identical to what we're currently doing, the only difference is that shadcn-ui just answers the question if you would like to install deps for you and installs everything. It also assumes that you installed some kinds of dependencies beforehand since the package manager checks for lock files.

I really would love to leave it like it's now.

But back to your problem: Why did it fall back to yarn? The only reason I could think of is that you set up the project and initialized solid-ui without every installing dependencies. Is that correct?

oscartbeaumont commented 5 months ago

It would be nice to have a way to manually override the package manager that is used because I don't think an automatic solution can cover all cases.

In my case, I'm using a pnpm monorepo.

This means the pnpm-lock.yaml exists at the root of the monorepo and not within the subpackages.

This causes the auto-detection code to not see the lockfile when run within the subpackages causing it to fall back to yarn.

I also have local dependencies within the monorepo which yarn fails to resolve causing it to error out.

I managed to trick it into working by adding an empty pnpm-lock.yaml file into the subpackage.

I wonder if you could copy something like this from create-t3-app which I'm fairly sure is able to detect the package manager which invoked the command.

Also thanks for all your work on this project!

sek-consulting commented 5 months ago

Thanks for the input :) I'll look into the T3-App implementation.

The idea I currently have in mind would be to use the detection method as some kind of "default" value for the package manager prompt. And then use the saved option for all further needs.

This should be the best option for all use cases. :)

declanchiu commented 3 months ago

Thanks for the input :)感谢您的投入:) I'll look into the T3-App implementation. 我将研究 T3-App 的实现。

The idea I currently have in mind would be to use the detection method as some kind of "default" value for the package manager prompt. And then use the saved option for all further needs.我目前想到的想法是使用检测方法作为包管理器提示的某种“默认”值。然后使用保存的选项来满足所有进一步的需求。

This should be the best option for all use cases. :)这应该是所有用例的最佳选择。 :)

I'm very interested in this project, so your idea is to list all the package managers and let the user choose? 🤔

sek-consulting commented 2 months ago

@declanchiu I'm still not sure about that. I would like to have as little options as possible for the cli.

And looking at the other implementations they also have detections methods and skip the manual selection completely: shadcn/ui: https://github.com/shadcn-ui/ui/blob/main/packages/cli/src/utils/get-package-manager.ts shadcn-svelte: https://github.com/huntabyte/shadcn-svelte/blob/main/packages/cli/src/utils/get-package-manager.ts

I really like the implementation for svelte that huntabyte and I might switch to that one.

wesleycoder commented 2 months ago

I've been trying to use solidui-cli with bun and most of the setup works ok, but when trying to add a component the cli hangs trying to install packages with yarn.

I'll keep an eye on this issue, and I'm available to do any tests if you'll guide me through what you need.

wesleycoder commented 2 months ago

I've got a workaround for my case, but I think it may be a different case from this issue.

In my case I'm working on a monorepo setup with bun, for this my bun.lockb file is hoisted to the root folder of the monorepo.

Looking at the detect-package-manager, which solidui-cli uses, I've seen that they have a naive approach of simply looking if the file exists on the current path. For this i've created an empty bun.lockb file on the sub package that uses solidui and the bun solidui-cli add worked.

I would suggest not using the detect-package-manager and instead use @antfu/ni which shadcn-ui uses, it has a more complete approach using the find-up package which solves my case.

I'll try and put up a PR for this, if not useful or anything let me know :)