Module: RequireHooks::Bootsnap::CompileCacheExt

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

Instance Method Summary collapse

Instance Method Details

#input_to_storage(source, path) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/require-hooks/mode/bootsnap.rb', line 8

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).to_binary
  end

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