Sha256: 9c36456f43b8a1cd887b9f457e936e433ece536ba6e7cbecd9a2dd8a52abc1f1

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

require 'benchmark'

class MonoRepoDeps::Package::Initializer
  include MonoRepoDeps::Mixins

  Inject = MonoRepoDeps::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|
        MonoRepoDeps.current_project.loader.push_dir(sorted_package.workdir_path)
        MonoRepoDeps.current_project.loader.loader.do_not_eager_load(sorted_package.workdir_path) if prevent_eager_load
      end

      MonoRepoDeps.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
mono_repo_deps-0.2.1 lib/mono_repo_deps/package/initializer.rb
mono_repo_deps-0.2.0 lib/mono_repo_deps/package/initializer.rb