Skip to content

Commit

Permalink
Merge pull request #17 from Dobefu/issue/15-prisma-gen-alt-pm-fails
Browse files Browse the repository at this point in the history
Resolve an issue where Prisma generation would fail on alternative package managers
  • Loading branch information
ankur-arch authored Aug 2, 2024
2 parents 53e3e6d + 03d319c commit bc1f4be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions playground/components/PostList.server.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const post = await prisma.post.findFirst();
</script>

<template>
<div>Posts</div>
<p>{{ post?.title ?? "There is no post." }}</p>
<div>
<div>Posts</div>
<p>{{ post?.title ?? "There is no post." }}</p>
</div>
</template>
18 changes: 12 additions & 6 deletions src/package-utils/setup-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { execa } from "execa";
import {
installingPrismaClientWithPM,
installingPrismaCLIWithPM,
} from "./detect-pm";
import {
log,
logError,
Expand All @@ -25,7 +29,7 @@ export async function isPrismaCLIInstalled(
directory: string,
): Promise<boolean> {
try {
await execa("prisma", ["version"], { cwd: directory });
await execa("npx", ["prisma", "version"], { cwd: directory });
logSuccess(PREDEFINED_LOG_MESSAGES.isPrismaCLIinstalled.yes);
return true;
} catch (error) {
Expand All @@ -36,9 +40,10 @@ export async function isPrismaCLIInstalled(
}

export async function installPrismaCLI(directory: string) {

try {
await execa("npm", ["install", "prisma", "--save-dev"], {
const installCmd = installingPrismaCLIWithPM();

await execa(installCmd.pm, installCmd.command, {
cwd: directory,
});
logSuccess(PREDEFINED_LOG_MESSAGES.installPrismaCLI.yes);
Expand Down Expand Up @@ -67,7 +72,7 @@ export async function initPrisma({
provider = "sqlite",
datasourceUrl,
}: PrismaInitOptions) {
const command = ["prisma", "init", "--datasource-provider"];
const command = ["npx", "prisma", "init", "--datasource-provider"];

command.push(provider);

Expand Down Expand Up @@ -172,10 +177,11 @@ export async function generateClient(
) {
log(PREDEFINED_LOG_MESSAGES.generatePrismaClient.action);


if (installPrismaClient) {
try {
await execa("npm", ["install", "@prisma/client", "--save-dev"], {
const installCmd = installingPrismaClientWithPM();

await execa(installCmd.pm, installCmd.command, {
cwd: directory,
});
} catch (error) {
Expand Down

0 comments on commit bc1f4be

Please sign in to comment.