Sha256: ef3c4dcb146c433bf318636d38676e4747512f039729001c6cecb4c8748efb64

Contents?: true

Size: 1.66 KB

Versions: 10

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

# First, expose the global #on_wasm? helper
module Kernel
  if RUBY_PLATFORM.include?("wasm")
    def on_wasm? = true
  else
    def on_wasm? = false
  end
end

# Only load shims when running within a Wasm runtime
return unless on_wasm?

# Setup Bundler
require "/bundle/setup"
require "bundler"

# Load core classes and deps patches
$LOAD_PATH.unshift File.expand_path("shims", __dir__)

# Misc patches

# Make gem no-op
define_singleton_method(:gem) { |*| nil }

# Patch Bundler.require to simply require files without looking at specs
def Bundler.require(*groups)
  Bundler.definition.dependencies_for([:wasm]).each do |dep|
    required_file = nil
    # Based on https://github.com/rubygems/rubygems/blob/8a079e9061ad4aaf2bc0b9007da8f362b7a2e1f2/bundler/lib/bundler/runtime.rb#L57
    begin
      Array(dep.autorequire || dep.name).each do |file|
        file = dep.name if file == true
        required_file = file
        begin
          Kernel.require file
        rescue RuntimeError => e
          raise e if e.is_a?(LoadError) # we handle this a little later
          raise Bundler::GemRequireError.new e,
            "There was an error while trying to load the gem '#{file}'."
        end
      end
    rescue LoadError => e
      raise if dep.autorequire || e.path != required_file

      if dep.autorequire.nil? && dep.name.include?("-")
        begin
          namespaced_file = dep.name.tr("-", "/")
          Kernel.require namespaced_file
        rescue LoadError => e
          raise if e.path != namespaced_file
        end
      end
    end
  end
end

class Thread
  def self.new(...)
    f = Fiber.new(...)
    def f.value = resume
    f
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
wasmify-rails-0.2.3 lib/wasmify/rails/shim.rb
wasmify-rails-0.2.2 lib/wasmify/rails/shim.rb
wasmify-rails-0.2.1 lib/wasmify/rails/shim.rb
wasmify-rails-0.2.0 lib/wasmify/rails/shim.rb
wasmify-rails-0.1.5 lib/wasmify/rails/shim.rb
wasmify-rails-0.1.4 lib/wasmify/rails/shim.rb
wasmify-rails-0.1.3 lib/wasmify/rails/shim.rb
wasmify-rails-0.1.2 lib/wasmify/rails/shim.rb
wasmify-rails-0.1.1 lib/wasmify/rails/shim.rb
wasmify-rails-0.1.0 lib/wasmify/rails/shim.rb