Skip to content

Commit

Permalink
processor: Avoid checking version via ExecJS
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackSpider8391 committed May 24, 2021
1 parent c7999bf commit a5ce508
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
3 changes: 1 addition & 2 deletions autoprefixer-rails.gemspec
Expand Up @@ -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"
Expand Down
36 changes: 20 additions & 16 deletions lib/autoprefixer-rails/processor.rb
Expand Up @@ -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

Expand Down

0 comments on commit a5ce508

Please sign in to comment.