From c5ba83280b6d2a0994a9bdfdd833d6870ac50289 Mon Sep 17 00:00:00 2001 From: remin Date: Tue, 28 Nov 2023 10:37:13 +0900 Subject: [PATCH] fix(wb): error "/bin/sh: prisma: command not found" in a Next.js project without Prisma (#205) --- packages/wb/src/project.ts | 5 ++++ .../wb/src/scripts/execution/nextScripts.ts | 29 +++++++++---------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/packages/wb/src/project.ts b/packages/wb/src/project.ts index 3765234d..cb514783 100644 --- a/packages/wb/src/project.ts +++ b/packages/wb/src/project.ts @@ -74,6 +74,11 @@ export class Project { return JSON.parse(fs.readFileSync(path.join(this.dirPath, 'package.json'), 'utf8')); } + @memoize + get hasPrisma(): boolean { + return !!this.packageJson.dependencies?.['prisma']; + } + @memoize get dockerPackageJson(): PackageJson { return path.dirname(this.findFile('Dockerfile')) === this.dirPath diff --git a/packages/wb/src/scripts/execution/nextScripts.ts b/packages/wb/src/scripts/execution/nextScripts.ts index a4288b03..f81d33b4 100644 --- a/packages/wb/src/scripts/execution/nextScripts.ts +++ b/packages/wb/src/scripts/execution/nextScripts.ts @@ -22,26 +22,25 @@ class NextScripts extends BaseExecutionScripts { override startProduction(project: Project, argv: ScriptArgv, port: number): string { return `NODE_ENV=production YARN concurrently --raw --kill-others-on-fail - "${prismaScripts.reset(project)} && ${project.buildCommand} && PORT=${port} pm2-runtime start ${project.findFile( - 'ecosystem.config.cjs' - )} ${argv.normalizedArgsText ?? ''}" + "${[ + ...(project.hasPrisma ? [prismaScripts.reset(project)] : []), + project.buildCommand, + `PORT=${port} pm2-runtime start ${project.findFile('ecosystem.config.cjs')} ${argv.normalizedArgsText ?? ''}`, + ].join(' && ')}" "${this.waitAndOpenApp(project, argv, port)}"`; } - override testE2E( - project: Project, - argv: ScriptArgv, - { - playwrightArgs = 'test tests/e2e', - startCommand = `${prismaScripts.reset(project)} && ${ - project.buildCommand - } && pm2-runtime start ${project.findFile('ecosystem.config.cjs')}`, - }: TestE2EOptions - ): string { + override testE2E(project: Project, argv: ScriptArgv, options: TestE2EOptions): string { return super.testE2E(project, argv, { - playwrightArgs, + playwrightArgs: options.playwrightArgs ?? 'test tests/e2e', prismaDirectory: 'db', - startCommand, + startCommand: + options.startCommand ?? + [ + ...(project.hasPrisma ? [prismaScripts.reset(project)] : []), + project.buildCommand, + `pm2-runtime start ${project.findFile('ecosystem.config.cjs')}`, + ].join(' && '), }); }