Class: Opal::CliRunners::Firefox

Inherits:
Object
  • Object
show all
Defined in:
opal/lib/opal/cli_runners/firefox.rb

Constant Summary collapse

SCRIPT_PATH =
File.expand_path('firefox_cdp_interface.rb', __dir__).freeze
DEFAULT_CHROME_HOST =
'localhost'
DEFAULT_CHROME_PORT =

makes sure it doesn't accidentally connect to a lingering chrome

9333

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Firefox

Returns a new instance of Firefox.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'opal/lib/opal/cli_runners/firefox.rb', line 26

def initialize(data)
  builder = data[:builder].call
  options = data[:options]
  argv    = data[:argv]

  if argv && argv.any?
    warn "warning: ARGV is not supported by the Firefox runner #{argv.inspect}"
  end

  @output  = options.fetch(:output, $stdout)
  @builder = builder
end

Instance Attribute Details

#builderObject (readonly)

Returns the value of attribute builder.



39
40
41
# File 'opal/lib/opal/cli_runners/firefox.rb', line 39

def builder
  @builder
end

#exit_statusObject (readonly)

Returns the value of attribute exit_status.



39
40
41
# File 'opal/lib/opal/cli_runners/firefox.rb', line 39

def exit_status
  @exit_status
end

#outputObject (readonly)

Returns the value of attribute output.



39
40
41
# File 'opal/lib/opal/cli_runners/firefox.rb', line 39

def output
  @output
end

Class Method Details

.call(data) ⇒ Object



21
22
23
24
# File 'opal/lib/opal/cli_runners/firefox.rb', line 21

def self.call(data)
  runner = new(data)
  runner.run
end

Instance Method Details

#runObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'opal/lib/opal/cli_runners/firefox.rb', line 41

def run
  mktmpdir do |dir|
    with_firefox_server do
      prepare_files_in(dir)

      env = {
        'CHROME_HOST' => chrome_host,
        'CHROME_PORT' => chrome_port.to_s,
        'NODE_PATH' => File.join(__dir__, 'node_modules')
      }
      env['OPAL_CDP_EXT'] = builder.output_extension

      cmd = [
        RbConfig.ruby,
        "#{__dir__}/../../../exe/opal",
        '--no-exit',
        '-I', __dir__,
        '-r', 'source-map-support-node',
        SCRIPT_PATH,
        dir
      ]

      Kernel.exec(env, *cmd)
    end
  end
end