nicoalbanese / kirimase

Build full-stack Next.js apps, incredibly fast
https://kirimase.dev
MIT License
2.64k stars 122 forks source link

Dependency Installation Fails Using Bun with Certain Options #18

Closed kddige closed 1 year ago

kddige commented 1 year ago

Description: When using bun as a package manager in conjunction with certain package and database options, the dependency installation occasionally fails.

Steps to reproduce:

  1. Execute the command kirimase init.
  2. When prompted to choose a package manager, select bun.
  3. When prompted to add packages, choose drizzle.
  4. For DB Type, opt for mysql.
  5. For the provider, pick Mysql2.
  6. During the dependency installation phase, the process breaks with the following error:
    bun add v0.8.1 (16b4bf34)
    error: unrecognised dependency format: 
    An error occurred: command "bun add -D drizzle-kit tsx dotenv " exited with code undefined

Possible Cause and Solution: I suspect that the underlying issue might stem from the trailing space at the end of the command. A potential fix could involve trimming the command string before execution.

Next Steps: I'm currently looking into this problem. I'll open a PR once I've found a solution.

kddige commented 1 year ago

Update: I've managed to resolve the issue by making the following change:

In the file: utils.ts at b5b8234

I added:

export const runCommand = async (command: string, args: string[]) => {
  const formattedArgs = args.filter((a) => a !== ""); // <- Filter out any literal empty string arugment -, if an empty string argument is needed it should be passed explicitly as ["arg1", "arg2", '""'] or ["\"\""]
  try {
    await execa(command, formattedArgs, { stdio: "inherit" });
  } catch (error) {
    throw new Error(
      `command "${command} ${formattedArgs.join(" ")}" exited with code ${error.code}`
    );
  }
};

It seems execa treats any empty string arguments, as a literal argument: "", this caused execa to run bun add as:

bun add -D drizzle drizzle-orm drizzle-zod zod mysql2 "" <-- the "" here was the problem

While this issue can potentially be addressed at a higher level than the runCommand function, I'm inclined to believe that no argument would necessitate an empty string, if none is explicit passed?

Would appreciate your thoughts on this, i have also opened a PR here: https://github.com/nicoalbanese/kirimase/pull/19

nicoalbanese commented 1 year ago

Thanks @kddige - I've merged it into main. Appreciate you sorting it out.

nicoalbanese commented 1 year ago

Bun still failing with Sqlite push command. I'm going to hold off including bun for now given the issues, and hopefully in next few days there will be a resolution!

nicoalbanese commented 1 year ago

0.0.13 now adds support for bun. It's almost fully supported, however I've had to remove the ability to use sqlite with drizzle as drizzle-kit's sqlite driver doesn't yet support bun.