From 106322ccff1397b82ea7cf4a92bc8d3590eed801 Mon Sep 17 00:00:00 2001 From: J Sachs Date: Tue, 31 Jan 2023 17:54:30 +0100 Subject: [PATCH] feat: choose between npm and yarn as package manager for NextJS build (#77) * feat: choose between npm and yarn as package manager for NextJS build * Apply suggestions from code review --------- Co-authored-by: Mischa Spiegelmock --- src/NextjsBase.ts | 6 ++++++ src/NextjsBuild.ts | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/NextjsBase.ts b/src/NextjsBase.ts index 98a48e8f..44307441 100644 --- a/src/NextjsBase.ts +++ b/src/NextjsBase.ts @@ -49,6 +49,12 @@ export interface NextjsBaseProps { */ readonly nodeEnv?: string; + /** + * Optional value used to install NextJS node dependencies. + * It defaults to "npm" + */ + readonly packageManager?: "npm" | "yarn" | "pnpm"; + /** * 0 - no compression, fatest * 9 - maximum compression, slowest diff --git a/src/NextjsBuild.ts b/src/NextjsBuild.ts index 21c8f831..08d76a71 100644 --- a/src/NextjsBuild.ts +++ b/src/NextjsBuild.ts @@ -133,9 +133,11 @@ export class NextjsBuild extends Construct { }; const buildPath = this.props.buildPath ?? nextjsPath; + const packageManager = this.props.packageManager ?? "npm"; + const buildCommand = packageManager === "yarn" ? ['build'] : ['run', 'build']; // run build - console.debug('├ Running "npm build" in', buildPath); - const buildResult = spawn.sync('npm', ['run', 'build'], { + console.debug(`├ Running "${packageManager} build" in`, buildPath); + const buildResult = spawn.sync(packageManager, buildCommand, { cwd: buildPath, stdio: this.props.quiet ? 'ignore' : 'inherit', env: buildEnv,