From 62efe2721aa2e0490858d441e273ff68200f6505 Mon Sep 17 00:00:00 2001 From: Jacob <33708767+jacobtread@users.noreply.github.com> Date: Wed, 27 Aug 2025 13:24:53 +1200 Subject: [PATCH] fix: windows use powershell to extract zip file (#2005) * fix: windows use powershell to extract zip file For windows platforms the unzip utility is not on systems by default, this changes it so that on windows powershell is used in combination with Expand-Archive to extract the zip file * chore: apply prettier formatting * chore: update test snapshots * chore: finish updating snapshots * fix: prevent shell injection * feat: update snapshots * feat: use alternative param style for Extract-Archive * tests: prettier and regen snapshots * tests: regen snapshots --- .../templates/installer/npm/binary-install.js | 34 ++++++++++++++---- cargo-dist/templates/installer/npm/binary.js | 2 +- .../snapshots/axolotlsay_action_commit.snap | 36 ++++++++++++++----- .../tests/snapshots/axolotlsay_alias.snap | 36 ++++++++++++++----- ...axolotlsay_alias_ignores_missing_bins.snap | 36 ++++++++++++++----- .../axolotlsay_attestations_filters.snap | 36 ++++++++++++++----- .../axolotlsay_attestations_host.snap | 36 ++++++++++++++----- .../tests/snapshots/axolotlsay_basic.snap | 36 ++++++++++++++----- .../snapshots/axolotlsay_basic_bins.snap | 36 ++++++++++++++----- .../snapshots/axolotlsay_basic_lies.snap | 36 ++++++++++++++----- .../axolotlsay_build_setup_steps.snap | 36 ++++++++++++++----- .../axolotlsay_disable_source_tarball.snap | 36 ++++++++++++++----- .../snapshots/axolotlsay_edit_existing.snap | 36 ++++++++++++++----- .../axolotlsay_homebrew_packages.snap | 36 ++++++++++++++----- .../tests/snapshots/axolotlsay_musl.snap | 36 ++++++++++++++----- .../snapshots/axolotlsay_musl_no_gnu.snap | 36 ++++++++++++++----- .../axolotlsay_no_homebrew_publish.snap | 36 ++++++++++++++----- .../snapshots/axolotlsay_several_aliases.snap | 36 ++++++++++++++----- .../tests/snapshots/axolotlsay_updaters.snap | 36 ++++++++++++++----- .../axolotlsay_user_global_build_job.snap | 36 ++++++++++++++----- .../snapshots/axolotlsay_user_host_job.snap | 36 ++++++++++++++----- .../axolotlsay_user_local_build_job.snap | 36 ++++++++++++++----- .../snapshots/axolotlsay_user_plan_job.snap | 36 ++++++++++++++----- .../axolotlsay_user_publish_job.snap | 36 ++++++++++++++----- 24 files changed, 644 insertions(+), 184 deletions(-) diff --git a/cargo-dist/templates/installer/npm/binary-install.js b/cargo-dist/templates/installer/npm/binary-install.js index 4775d7426..7dedbf7a9 100644 --- a/cargo-dist/templates/installer/npm/binary-install.js +++ b/cargo-dist/templates/installer/npm/binary-install.js @@ -13,7 +13,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -47,6 +47,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -122,12 +124,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { diff --git a/cargo-dist/templates/installer/npm/binary.js b/cargo-dist/templates/installer/npm/binary.js index 3e8f15d84..95e2a9d5c 100644 --- a/cargo-dist/templates/installer/npm/binary.js +++ b/cargo-dist/templates/installer/npm/binary.js @@ -96,7 +96,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_action_commit.snap b/cargo-dist/tests/snapshots/axolotlsay_action_commit.snap index e04c988cf..f046b1d36 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_action_commit.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_action_commit.snap @@ -2521,7 +2521,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -2555,6 +2555,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -2630,12 +2632,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2798,7 +2818,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_alias.snap b/cargo-dist/tests/snapshots/axolotlsay_alias.snap index af8415d9e..0c264d951 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_alias.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_alias.snap @@ -2474,7 +2474,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -2508,6 +2508,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -2583,12 +2585,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2751,7 +2771,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_alias_ignores_missing_bins.snap b/cargo-dist/tests/snapshots/axolotlsay_alias_ignores_missing_bins.snap index 644c25746..96e81ffea 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_alias_ignores_missing_bins.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_alias_ignores_missing_bins.snap @@ -2478,7 +2478,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -2512,6 +2512,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -2587,12 +2589,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2755,7 +2775,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_attestations_filters.snap b/cargo-dist/tests/snapshots/axolotlsay_attestations_filters.snap index f5b096f94..3e1aec5e6 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_attestations_filters.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_attestations_filters.snap @@ -2521,7 +2521,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -2555,6 +2555,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -2630,12 +2632,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2798,7 +2818,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_attestations_host.snap b/cargo-dist/tests/snapshots/axolotlsay_attestations_host.snap index 2a086f006..0d5b81692 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_attestations_host.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_attestations_host.snap @@ -2521,7 +2521,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -2555,6 +2555,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -2630,12 +2632,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2798,7 +2818,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_basic.snap b/cargo-dist/tests/snapshots/axolotlsay_basic.snap index 2825a3509..9b70923fb 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_basic.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_basic.snap @@ -2560,7 +2560,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -2594,6 +2594,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -2669,12 +2671,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2837,7 +2857,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_basic_bins.snap b/cargo-dist/tests/snapshots/axolotlsay_basic_bins.snap index 96af5e469..b73540ed9 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_basic_bins.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_basic_bins.snap @@ -2521,7 +2521,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -2555,6 +2555,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -2630,12 +2632,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2798,7 +2818,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_basic_lies.snap b/cargo-dist/tests/snapshots/axolotlsay_basic_lies.snap index 5e8a48ce0..7fc08e2e3 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_basic_lies.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_basic_lies.snap @@ -2446,7 +2446,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -2480,6 +2480,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -2555,12 +2557,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2723,7 +2743,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_build_setup_steps.snap b/cargo-dist/tests/snapshots/axolotlsay_build_setup_steps.snap index 39ec1a31f..6c47180e8 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_build_setup_steps.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_build_setup_steps.snap @@ -2443,7 +2443,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -2477,6 +2477,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -2552,12 +2554,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2720,7 +2740,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_disable_source_tarball.snap b/cargo-dist/tests/snapshots/axolotlsay_disable_source_tarball.snap index fb24f5ebb..ec7def630 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_disable_source_tarball.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_disable_source_tarball.snap @@ -2443,7 +2443,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -2477,6 +2477,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -2552,12 +2554,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2720,7 +2740,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap b/cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap index 6cc78c37d..c3e76c9eb 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap @@ -2443,7 +2443,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -2477,6 +2477,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -2552,12 +2554,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2720,7 +2740,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_homebrew_packages.snap b/cargo-dist/tests/snapshots/axolotlsay_homebrew_packages.snap index dfed318fd..18d55eeb9 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_homebrew_packages.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_homebrew_packages.snap @@ -2443,7 +2443,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -2477,6 +2477,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -2552,12 +2554,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2720,7 +2740,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_musl.snap b/cargo-dist/tests/snapshots/axolotlsay_musl.snap index c60e57dab..c1797d9cc 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_musl.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_musl.snap @@ -1829,7 +1829,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -1863,6 +1863,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -1938,12 +1940,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2106,7 +2126,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap b/cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap index 93e7d8f36..02b87d38c 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap @@ -1809,7 +1809,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -1843,6 +1843,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -1918,12 +1920,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2086,7 +2106,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap b/cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap index 4e460382c..682f8dd9e 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap @@ -2443,7 +2443,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -2477,6 +2477,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -2552,12 +2554,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2720,7 +2740,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_several_aliases.snap b/cargo-dist/tests/snapshots/axolotlsay_several_aliases.snap index 6156d0f32..e9380d8b7 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_several_aliases.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_several_aliases.snap @@ -2478,7 +2478,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -2512,6 +2512,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -2587,12 +2589,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2755,7 +2775,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_updaters.snap b/cargo-dist/tests/snapshots/axolotlsay_updaters.snap index 47d6c611f..8e817ea98 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_updaters.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_updaters.snap @@ -2455,7 +2455,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -2489,6 +2489,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -2564,12 +2566,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2732,7 +2752,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_user_global_build_job.snap b/cargo-dist/tests/snapshots/axolotlsay_user_global_build_job.snap index 01c0ddb9e..f61b2dc3e 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_user_global_build_job.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_user_global_build_job.snap @@ -2443,7 +2443,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -2477,6 +2477,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -2552,12 +2554,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2720,7 +2740,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_user_host_job.snap b/cargo-dist/tests/snapshots/axolotlsay_user_host_job.snap index b291a81c4..5e7e7bfe2 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_user_host_job.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_user_host_job.snap @@ -2443,7 +2443,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -2477,6 +2477,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -2552,12 +2554,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2720,7 +2740,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_user_local_build_job.snap b/cargo-dist/tests/snapshots/axolotlsay_user_local_build_job.snap index abb44857a..0ba0f6e23 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_user_local_build_job.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_user_local_build_job.snap @@ -2443,7 +2443,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -2477,6 +2477,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -2552,12 +2554,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2720,7 +2740,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_user_plan_job.snap b/cargo-dist/tests/snapshots/axolotlsay_user_plan_job.snap index d05b1d26d..03f6c02c3 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_user_plan_job.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_user_plan_job.snap @@ -2443,7 +2443,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -2477,6 +2477,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -2552,12 +2554,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2720,7 +2740,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; }; diff --git a/cargo-dist/tests/snapshots/axolotlsay_user_publish_job.snap b/cargo-dist/tests/snapshots/axolotlsay_user_publish_job.snap index a9188c229..9dccaefb2 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_user_publish_job.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_user_publish_job.snap @@ -2443,7 +2443,7 @@ const error = (msg) => { }; class Package { - constructor(name, url, filename, zipExt, binaries) { + constructor(platform, name, url, filename, zipExt, binaries) { let errors = []; if (typeof url !== "string") { errors.push("url must be a string"); @@ -2477,6 +2477,8 @@ class Package { '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})'; error(errorMsg); } + + this.platform = platform; this.url = url; this.name = name; this.filename = filename; @@ -2552,12 +2554,30 @@ class Package { ); } } else if (this.zipExt == ".zip") { - const result = spawnSync("unzip", [ - "-q", - tempFile, - "-d", - this.installDirectory, - ]); + let result; + if (this.platform.includes("windows")) { + // Windows does not have "unzip" by default on many installations, instead + // we use Expand-Archive from powershell + result = spawnSync("powershell.exe", [ + "-NoProfile", + "-NonInteractive", + "-Command", + `& { + param([string]$LiteralPath, [string]$DestinationPath) + Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force + }`, + tempFile, + this.installDirectory, + ]); + } else { + result = spawnSync("unzip", [ + "-q", + tempFile, + "-d", + this.installDirectory, + ]); + } + if (result.status == 0) { resolve(); } else if (result.error) { @@ -2720,7 +2740,7 @@ const getPackage = () => { const url = `${artifactDownloadUrl}/${platform.artifactName}`; let filename = platform.artifactName; let ext = platform.zipExt; - let binary = new Package(name, url, filename, ext, platform.bins); + let binary = new Package(platform, name, url, filename, ext, platform.bins); return binary; };