module Bootsnap::CompileCache::JSON

def init!

def init!
  require('json')
  require('msgpack')
  self.msgpack_factory = MessagePack::Factory.new
  self.supported_options = [:symbolize_names]
  if ::JSON.parse('["foo"]', freeze: true).first.frozen?
    self.supported_options = [:freeze]
  end
  self.supported_options.freeze
end

def input_to_output(data, kwargs)

def input_to_output(data, kwargs)
  ::JSON.parse(data, **(kwargs || {}))
end

def input_to_storage(payload, _)

def input_to_storage(payload, _)
  obj = ::JSON.parse(payload)
  msgpack_factory.dump(obj)
end

def install!(cache_dir)

def install!(cache_dir)
  self.cache_dir = cache_dir
  init!
  if ::JSON.respond_to?(:load_file)
    ::JSON.singleton_class.prepend(Patch)
  end
end

def precompile(path, cache_dir: self.cache_dir)

def precompile(path, cache_dir: self.cache_dir)
  Bootsnap::CompileCache::Native.precompile(
    cache_dir,
    path.to_s,
    self,
  )
end

def storage_to_output(data, kwargs)

def storage_to_output(data, kwargs)
  if kwargs && kwargs.key?(:symbolize_names)
    kwargs[:symbolize_keys] = kwargs.delete(:symbolize_names)
  end
  msgpack_factory.load(data, kwargs)
end