Module: RequireHooks::Bootsnap::CompilerExt

Defined in:
lib/require-hooks/mode/bootsnap.rb

Overview

For new Bootsnap

Instance Method Summary collapse

Instance Method Details

#input_to_storage(source, path) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/require-hooks/mode/bootsnap.rb', line 33

def input_to_storage(source, path, *)
  ctx = RequireHooks.context_for(path)
  return super if ctx.empty?

  new_contents = ctx.perform_source_transform(path)
  hijacked = ctx.try_hijack_load(path, new_contents)

  if hijacked
    raise TypeError, "Unsupported bytecode format for #{path}: #{hijack.class}" unless hijacked.is_a?(::RubyVM::InstructionSequence)
    return hijacked.to_binary
  elsif new_contents
    return RubyVM::InstructionSequence.compile(new_contents, path, path, 1, @compile_options).to_binary
  end

  super
rescue SyntaxError, TypeError
  ::Bootsnap::CompileCache::UNCOMPILABLE
end