Sha256: ff97def7a3020487568e05f82ebab7f32789d636d197a78fb1114e9ba091789d

Contents?: true

Size: 686 Bytes

Versions: 34

Compression:

Stored size: 686 Bytes

Contents

require 'opal-parser'

module Kernel
  def __prepare_require__(path)
    name = `Opal.normalize(#{path})`
    full_path = name.end_with?('.rb') ? name : name + '.rb'

    if `!Opal.modules[#{name}]`
      ruby = File.read(full_path)
      compiler = Opal::Compiler.new(ruby, requirable: true, file: name)
      js = compiler.compile
      compiler.requires.each do |sub_path|
        __prepare_require__(sub_path)
      end
      `eval(#{js})`
    end

    name
  rescue => e
    raise [path, name, full_path].inspect + e.message
  end

  def require(path)
    `Opal.require(#{__prepare_require__(path)})`
  end

  def load(path)
    `Opal.load(#{__prepare_require__(path)})`
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
opal-1.7.4 stdlib/nodejs/require.rb
opal-1.7.3 stdlib/nodejs/require.rb
opal-1.7.2 stdlib/nodejs/require.rb
opal-1.7.1 stdlib/nodejs/require.rb
opal-1.7.0 stdlib/nodejs/require.rb
opal-1.7.0.rc1 stdlib/nodejs/require.rb
opal-1.6.1 stdlib/nodejs/require.rb
opal-1.6.0 stdlib/nodejs/require.rb
opal-1.6.0.rc1 stdlib/nodejs/require.rb
opal-1.6.0.alpha1 stdlib/nodejs/require.rb
opal-1.5.1 stdlib/nodejs/require.rb
opal-1.5.0 stdlib/nodejs/require.rb
opal-1.5.0.rc1 stdlib/nodejs/require.rb
opal-1.4.1 stdlib/nodejs/require.rb
opal-1.4.0 stdlib/nodejs/require.rb
opal-1.4.0.alpha1 stdlib/nodejs/require.rb
opal-1.3.2 stdlib/nodejs/require.rb
opal-1.3.1 stdlib/nodejs/require.rb
opal-1.3.0 stdlib/nodejs/require.rb
opal-1.3.0.rc1 stdlib/nodejs/require.rb