From e58e92d89f21706f37e9c427d48b836ebcde6069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=81=A4=E3=81=8D?= Date: Wed, 23 Jul 2025 12:08:03 -0700 Subject: [PATCH] Use bsdtar on windows --- ext/sass/Rakefile | 50 +++---------------------------------- ext/sass/expand-archive.ps1 | 1 - sass-embedded.gemspec | 1 - 3 files changed, 3 insertions(+), 49 deletions(-) delete mode 100644 ext/sass/expand-archive.ps1 diff --git a/ext/sass/Rakefile b/ext/sass/Rakefile index c1901b5b..3d017d03 100644 --- a/ext/sass/Rakefile +++ b/ext/sass/Rakefile @@ -288,59 +288,15 @@ end # This is a FileUtils extension that defines several additional commands to be # added to the FileUtils utility functions. module FileUtils - # PowerShell quirks: - # - `powershell -Command -`: - # Arguments must be part of command, thus cannot pass arguments safely without escaping. - # - `powershell -Command [-args ]`: - # This only works when invoking powershell subshell in powershell. - # - `powershell -Command []`: - # CommandParameters are joined with command and then parsed, thus cannot pass arguments safely without escaping. - # - `powershell -File -`: - # Arguments must be part of file, thus cannot pass arguments safely without escaping. - # - `powershell -File `: - # This is the only way to pass arguments safely without escaping. - def powershell(file, *args) - sh 'powershell', '-NoLogo', '-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-File', file, *args - end - - def junzip(archive, dest = '.') - require 'java' - - Rake.rake_output_message "Archive: #{archive}" if Rake::FileUtilsExt.verbose_flag - - current_directory = java.nio.file.Paths.get(org.jruby.Ruby.getGlobalRuntime.getCurrentDirectory) - zip_file = java.util.zip.ZipFile.new(current_directory.resolve(archive).toFile) - dest_path = current_directory.resolve(dest).normalize - entries = zip_file.entries - while entries.hasMoreElements - entry = entries.nextElement - name = entry.getName - path = dest_path.resolve(name).normalize - raise SecurityError unless path.startsWith(dest_path) - - Rake.rake_output_message " inflating: #{name}" if Rake::FileUtilsExt.verbose_flag - - if entry.isDirectory - java.nio.file.Files.createDirectories(path) - else - java.nio.file.Files.createDirectories(path.getParent) - java.nio.file.Files.copy(zip_file.getInputStream(entry), path) - end - end - ensure - zip_file&.close - end - def unarchive(archive, dest = '.') case archive.downcase when ->(name) { name.include?('.tar.') || name.end_with?('.tar') } mkdir_p dest sh 'tar', '-vxC', dest, '-f', archive, '--no-same-owner', '--no-same-permissions' when ->(name) { name.end_with?('.zip') } - if RUBY_PLATFORM == 'java' - junzip archive, dest - elsif Gem.win_platform? - powershell 'expand-archive.ps1', '-Force', '-LiteralPath', archive, '-DestinationPath', dest + if Gem.win_platform? + mkdir_p dest + sh File.absolute_path('System32/tar.exe', ENV.fetch('SystemRoot', 'C:/Windows')), '-vxC', dest, '-f', archive else sh 'unzip', '-od', dest, archive end diff --git a/ext/sass/expand-archive.ps1 b/ext/sass/expand-archive.ps1 deleted file mode 100644 index 274fdea9..00000000 --- a/ext/sass/expand-archive.ps1 +++ /dev/null @@ -1 +0,0 @@ -Expand-Archive @args diff --git a/sass-embedded.gemspec b/sass-embedded.gemspec index 57674789..1073a171 100644 --- a/sass-embedded.gemspec +++ b/sass-embedded.gemspec @@ -28,7 +28,6 @@ Gem::Specification.new do |spec| spec.extensions = ['ext/sass/Rakefile'] spec.files += [ 'ext/sass/Rakefile', - 'ext/sass/expand-archive.ps1', 'ext/sass/package.json' ] spec.add_dependency 'rake', '>= 13'