Sha256: 0d8e040f000b2f18948a5a037f3f912d512a80bb7bb69637702b0594f22c87c9

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

require 'benchmark'

class Mona::Package::Initializer
  include Mona::Mixins

  Inject = Mona::Deps[
    "package.dependency_bypasser",
    "package.repo"
  ]

  include Inject

  sig do
    params(
      package_name: T.any(Symbol, String),
      env: Symbol,
      prevent_eager_load: T::Boolean
    )
    .void
  end
  def call(package_name, env:, prevent_eager_load: false)
    package = repo.find!(package_name.to_sym)
    sorted_packages = nil

    time = Benchmark.realtime do
      sorted_packages = dependency_bypasser
        .call(package_name: package.name, env: env)
        .map { |name| repo.find(name) }

      sorted_packages.each do |sorted_package|
        Mona.current_project.loader.push_dir(sorted_package.workdir_path)
        Mona.current_project.loader.loader.do_not_eager_load(sorted_package.workdir_path) if prevent_eager_load
      end

      Mona.current_project.loader.setup

      sorted_packages.each do |package|
        require package.entrypoint_file if File.exist?(package.entrypoint_file)
      end
    end

    puts "imported package '#{package_name}' with #{sorted_packages.size} dependencies in #{'%.2f' % time} seconds for env: #{env}"

    nil
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mona-0.2.3 lib/mona/package/initializer.rb
mona-0.2.2 lib/mona/package/initializer.rb