From bd8ff33aa39a0a0bf9a89742d11f05bc305e31e7 Mon Sep 17 00:00:00 2001 From: Lagyu <33177050+Lagyu@users.noreply.github.com> Date: Thu, 18 May 2023 12:47:15 +0900 Subject: [PATCH] fix: Support windows by replacing zip command. (#103) --- src/NextjsBuild.ts | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/NextjsBuild.ts b/src/NextjsBuild.ts index fa6998d8..31e64291 100644 --- a/src/NextjsBuild.ts +++ b/src/NextjsBuild.ts @@ -189,14 +189,31 @@ export function createArchive({ } // run script to create zipfile, preserving symlinks for node_modules (e.g. pnpm structure) - const result = spawn.sync( - 'bash', // getting ENOENT when specifying 'node' here for some reason - [ - quiet ? '-c' : '-xc', - [`cd '${directory}'`, `zip -ryq${compressionLevel} '${zipFilePath}' ${fileGlob}`].join('&&'), - ], - { stdio: 'inherit' } - ); + let result; + const isWindows = process.platform === 'win32'; + if (isWindows) { + const psCompressionLevel = compressionLevel === 0 ? 'NoCompression' : 'Fastest'; + result = spawn.sync( + 'powershell.exe', + [ + '-NoLogo', + '-NoProfile', + '-NonInteractive', + '-Command', + `Compress-Archive -Path '${directory}\\*' -DestinationPath '${zipFilePath}' -CompressionLevel ${psCompressionLevel}`, + ], + { stdio: 'inherit' } + ); + } else { + result = spawn.sync( + 'bash', // getting ENOENT when specifying 'node' here for some reason + [ + quiet ? '-c' : '-xc', + [`cd '${directory}'`, `zip -ryq${compressionLevel} '${zipFilePath}' ${fileGlob}`].join('&&'), + ], + { stdio: 'inherit' } + ); + } if (result.status !== 0) { throw new Error(`There was a problem generating the package for ${zipFileName} with ${directory}: ${result.error}`); }