Skip to content

Commit

Permalink
Fix cannot find version of process
Browse files Browse the repository at this point in the history
- The error occurs that is because process of execjs has been removed from rails/execjs@b0be19c
- to fix it, use shell script instead of execjs eval
- Fix ai#203
  • Loading branch information
ksh-code committed May 24, 2021
1 parent b12a0d8 commit 66b9cb8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
3 changes: 0 additions & 3 deletions autoprefixer-rails.gemspec
Expand Up @@ -20,9 +20,6 @@ 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_development_dependency "rails"
s.add_development_dependency "rake"
s.add_development_dependency "rspec-rails"
Expand Down
19 changes: 16 additions & 3 deletions lib/autoprefixer-rails/processor.rb
Expand Up @@ -9,7 +9,7 @@
module AutoprefixerRails
# Ruby to JS wrapper for Autoprefixer processor instance
class Processor
SUPPORTED_RUNTIMES = [ExecJS::Runtimes::Node, ExecJS::Runtimes::MiniRacer]
SUPPORTED_RUNTIMES = [ExecJS::Runtimes::Node, ExecJS::Runtimes::MiniRacer].freeze

def initialize(params = {})
@params = params || {}
Expand Down Expand Up @@ -131,7 +131,8 @@ def find_config(file)
def runtime
@runtime ||= begin
if ExecJS.runtime == ExecJS::Runtimes::Node
version = ExecJS.runtime.eval("process.version")

version = nodejs_version
major = version.match(/^v(\d+)/)[1].to_i

# supports 10, 12, 14+
Expand All @@ -147,7 +148,7 @@ def 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 ')}
please switch to #{SUPPORTED_RUNTIMES.map(&:name).join(" or ")}
MSG
end
end
Expand All @@ -157,5 +158,17 @@ def build_js
path = root.join("../../vendor/autoprefixer.js")
path.read
end

def nodejs_version
begin
`node --version`
rescue StandardError
Errno::ENOENT
end || begin
`nodejs --version`
rescue StandardError
Errno::ENOENT
end
end
end
end

0 comments on commit 66b9cb8

Please sign in to comment.