From 3b3d2442c89f6d83ac35b67577bf276f9c3192c9 Mon Sep 17 00:00:00 2001 From: Albert Song Date: Mon, 24 May 2021 16:43:58 +0800 Subject: [PATCH] processor: Avoid checking version via ExecJS see https://github.com/ai/autoprefixer-rails/issues/203 --- autoprefixer-rails.gemspec | 3 +-- lib/autoprefixer-rails/processor.rb | 36 ++++++++++++++++------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/autoprefixer-rails.gemspec b/autoprefixer-rails.gemspec index 90c210c..a60024b 100644 --- a/autoprefixer-rails.gemspec +++ b/autoprefixer-rails.gemspec @@ -20,8 +20,7 @@ Gem::Specification.new do |s| s.homepage = "https://github.com/ai/autoprefixer-rails" s.license = "MIT" - # see #203, `process` is undefined in 2.8 - s.add_dependency "execjs", "< 2.8.0" + s.add_dependency "execjs", "> 0" s.add_development_dependency "rails" s.add_development_dependency "rake" diff --git a/lib/autoprefixer-rails/processor.rb b/lib/autoprefixer-rails/processor.rb index a8ddc6e..20600ce 100644 --- a/lib/autoprefixer-rails/processor.rb +++ b/lib/autoprefixer-rails/processor.rb @@ -130,25 +130,29 @@ def find_config(file) # Lazy load for JS library def runtime @runtime ||= begin - if ExecJS.runtime == ExecJS::Runtimes::Node - version = ExecJS.runtime.eval("process.version") - major = version.match(/^v(\d+)/)[1].to_i - - # supports 10, 12, 14+ - unless [10, 12].include?(major) || major >= 14 - raise "Autoprefixer doesn’t support Node #{version}. Update it." - end - end - ExecJS.compile(build_js) rescue ExecJS::RuntimeError - raise if SUPPORTED_RUNTIMES.include?(ExecJS.runtime) - # Only complain about unsupported runtimes when it failed to parse our script. - raise <<~MSG - Your ExecJS runtime #{ExecJS.runtime.name} isn't supported by autoprefixer-rails, - please switch to #{SUPPORTED_RUNTIMES.map(&:name).join(' or ')} - MSG + + case ExecJS.runtime + when ExecJS::Runtimes::Node + node_command = ExecJS.runtime.send(:binary) rescue "Unknown" + + raise <<~MSG + Your nodejs binary failed to load autoprefixer script file, + please check if you're running a supported version (10, 12, 14+) + + ENV["PATH"] = #{ENV["PATH"]} + binary = #{node_command} + MSG + when *SUPPORTED_RUNTIMES + raise + else + raise <<~MSG + Your ExecJS runtime #{ExecJS.runtime.name} isn't supported by autoprefixer-rails, + please switch to #{SUPPORTED_RUNTIMES.map(&:name).join(' or ')} + MSG + end end end