Skip to content

Commit

Permalink
fix: Support windows by replacing zip command. (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lagyu authored May 18, 2023
1 parent 06e5ff8 commit bd8ff33
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/NextjsBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down

0 comments on commit bd8ff33

Please sign in to comment.