mono_repo_deps 0.1.14 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/example/bounded_contexts/cart/cart_core/Package.rb +2 -2
- data/lib/mono_repo_deps/package/dependency_bypasser.rb +15 -16
- data/lib/mono_repo_deps/package/factory.rb +2 -7
- data/lib/mono_repo_deps/package/initializer.rb +19 -11
- data/lib/mono_repo_deps/package/repo.rb +9 -1
- data/lib/mono_repo_deps/package.rb +10 -7
- data/lib/mono_repo_deps/task/manager.rb +4 -23
- data/lib/mono_repo_deps/version.rb +1 -1
- data/lib/mono_repo_deps.rb +2 -30
- data/mono_repo_deps.gemspec +70 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95e49884e5cf67ed63ea7575df321c0166b5ac505b602d99facf24b866dff026
|
4
|
+
data.tar.gz: e9ce0647794d26570f0e45af5346e27778bc7bc67edce058b801c20250055513
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f8e7acfd621406055e2091119857f595d6ba1899f90b5e6c164210f6c81dcb635359942f91cc1797197e4ab83bc89eae6db7837bdeafcd8491d3a1cc93d3d8a
|
7
|
+
data.tar.gz: c04cef773cdb54ca0357d827f9594767203f291c4416d1f5a1557d03f9febeaf86524ef7f1ae39e5b7e8f3a84a417cf74e56e8d60cedbfbc2599fdc8e460fbda
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
1
3
|
class MonoRepoDeps::Package::DependencyBypasser
|
2
4
|
include MonoRepoDeps::Mixins
|
3
5
|
|
@@ -11,31 +13,28 @@ class MonoRepoDeps::Package::DependencyBypasser
|
|
11
13
|
params(
|
12
14
|
package_name: Symbol,
|
13
15
|
env: Symbol,
|
14
|
-
only: T.nilable(T::Array[Symbol]),
|
15
|
-
skip: T.nilable(T::Array[Symbol]),
|
16
|
-
imported: T::Array[Symbol],
|
17
|
-
packages_order: T::Array[Symbol],
|
18
16
|
)
|
19
17
|
.returns(T::Array[Symbol])
|
20
18
|
end
|
21
|
-
def call(package_name:, env
|
19
|
+
def call(package_name:, env:)
|
20
|
+
walk(package_name: package_name, env: env, imported: Set.new)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def walk(package_name:, env:, imported:, packages_order: [])
|
22
26
|
package = packages_repo.find!(package_name)
|
23
27
|
|
24
|
-
return
|
25
|
-
imported.push(package.name)
|
28
|
+
return if !imported.add?(package_name)
|
26
29
|
|
27
30
|
package_dependencies = package.get_dependencies(env)
|
28
|
-
|
29
|
-
package_dependencies
|
30
|
-
|
31
|
-
|
32
|
-
self.call(
|
33
|
-
package_name: dependency_dto.name,
|
34
|
-
skip: dependency_dto.skip,
|
35
|
-
only: dependency_dto.only,
|
31
|
+
|
32
|
+
package_dependencies.each do |name|
|
33
|
+
walk(
|
34
|
+
package_name: name,
|
36
35
|
imported: imported,
|
37
36
|
packages_order: packages_order,
|
38
|
-
env:
|
37
|
+
env: MonoRepoDeps::Package::DEFAULT_ENV,
|
39
38
|
)
|
40
39
|
end
|
41
40
|
|
@@ -30,7 +30,6 @@ class MonoRepoDeps::Package::Factory
|
|
30
30
|
package.get_dependency_envs.each do |env|
|
31
31
|
already_imported = package
|
32
32
|
.get_dependencies(env)
|
33
|
-
.map(&:name)
|
34
33
|
.group_by{ |e| e }
|
35
34
|
.select { |k, v| v.size > 1 }
|
36
35
|
.keys
|
@@ -59,17 +58,13 @@ class MonoRepoDeps::Package::Factory
|
|
59
58
|
sig do
|
60
59
|
params(
|
61
60
|
package_name: T.any(Symbol, String),
|
62
|
-
skip: T.nilable(T::Array[Symbol]),
|
63
|
-
only: T.nilable(T::Array[Symbol]),
|
64
61
|
)
|
65
62
|
.void
|
66
63
|
end
|
67
|
-
def import(package_name
|
64
|
+
def import(package_name)
|
68
65
|
package_name = package_name.to_sym
|
69
|
-
skip = skip&.map(&:to_sym)
|
70
|
-
only = only&.map(&:to_sym)
|
71
66
|
|
72
|
-
@dependencies[@current_env] <<
|
67
|
+
@dependencies[@current_env] << package_name
|
73
68
|
|
74
69
|
nil
|
75
70
|
end
|
@@ -14,24 +14,32 @@ class MonoRepoDeps::Package::Initializer
|
|
14
14
|
params(
|
15
15
|
package_name: T.any(Symbol, String),
|
16
16
|
env: Symbol,
|
17
|
-
|
17
|
+
prevent_eager_load: T::Boolean
|
18
18
|
)
|
19
19
|
.void
|
20
20
|
end
|
21
|
-
def call(package_name, env:,
|
22
|
-
|
23
|
-
|
21
|
+
def call(package_name, env:, prevent_eager_load: false)
|
22
|
+
package = repo.find!(package_name.to_sym)
|
23
|
+
sorted_packages = nil
|
24
24
|
|
25
25
|
time = Benchmark.realtime do
|
26
|
-
|
27
|
-
.call(package_name:
|
28
|
-
.map { repo.find(
|
29
|
-
|
30
|
-
|
31
|
-
.
|
26
|
+
sorted_packages = dependency_bypasser
|
27
|
+
.call(package_name: package.name, env: env)
|
28
|
+
.map { |name| repo.find(name) }
|
29
|
+
|
30
|
+
sorted_packages.each do |sorted_package|
|
31
|
+
MonoRepoDeps.current_project.loader.push_dir(sorted_package.workdir_path)
|
32
|
+
MonoRepoDeps.current_project.loader.loader.do_not_eager_load(sorted_package.workdir_path) if prevent_eager_load
|
33
|
+
end
|
34
|
+
|
35
|
+
MonoRepoDeps.current_project.loader.setup
|
36
|
+
|
37
|
+
sorted_packages.each do |package|
|
38
|
+
require package.entrypoint_file if File.exist?(package.entrypoint_file)
|
39
|
+
end
|
32
40
|
end
|
33
41
|
|
34
|
-
puts "imported package '#{package_name}' with #{
|
42
|
+
puts "imported package '#{package_name}' with #{sorted_packages.size} dependencies in #{'%.2f' % time} seconds for env: #{env}"
|
35
43
|
|
36
44
|
nil
|
37
45
|
end
|
@@ -16,7 +16,15 @@ class MonoRepoDeps::Package::Repo
|
|
16
16
|
|
17
17
|
sig do
|
18
18
|
params(
|
19
|
-
name: T.nilable(
|
19
|
+
name: T.nilable(
|
20
|
+
T.any(
|
21
|
+
String,
|
22
|
+
Symbol,
|
23
|
+
T::Array[
|
24
|
+
T.any(String, Symbol)
|
25
|
+
]
|
26
|
+
)
|
27
|
+
),
|
20
28
|
)
|
21
29
|
.returns(T::Array[MonoRepoDeps::Package])
|
22
30
|
end
|
@@ -5,14 +5,12 @@ class MonoRepoDeps::Package
|
|
5
5
|
|
6
6
|
DEFAULT_ENV = :_default_
|
7
7
|
|
8
|
-
DependencyDto = Struct.new(:name, :only, :skip, keyword_init: true)
|
9
|
-
|
10
8
|
sig do
|
11
9
|
params(
|
12
10
|
name: Symbol,
|
13
11
|
root_path: String,
|
14
12
|
package_dirname: String,
|
15
|
-
dependencies: T::Hash[Symbol,
|
13
|
+
dependencies: T::Hash[Symbol, Symbol]
|
16
14
|
)
|
17
15
|
.void
|
18
16
|
end
|
@@ -26,12 +24,13 @@ class MonoRepoDeps::Package
|
|
26
24
|
end
|
27
25
|
|
28
26
|
sig do
|
29
|
-
params(env: T.nilable(Symbol)).returns(T::Array[
|
27
|
+
params(env: T.nilable(Symbol)).returns(T::Array[Symbol])
|
30
28
|
end
|
31
29
|
def get_dependencies(env = nil)
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
default_deps = @dependencies.fetch(DEFAULT_ENV, [])
|
31
|
+
env_deps = @dependencies.fetch(env, [])
|
32
|
+
|
33
|
+
default_deps | env_deps
|
35
34
|
end
|
36
35
|
|
37
36
|
def get_dependency_envs
|
@@ -45,4 +44,8 @@ class MonoRepoDeps::Package
|
|
45
44
|
def entrypoint_file
|
46
45
|
File.join( self.workdir_path, "#{name}.rb" )
|
47
46
|
end
|
47
|
+
|
48
|
+
def specs_path
|
49
|
+
File.join( self.root_path, '/spec/' )
|
50
|
+
end
|
48
51
|
end
|
@@ -13,7 +13,7 @@ class MonoRepoDeps::Task::Manager
|
|
13
13
|
args: T.anything,
|
14
14
|
kwargs: T.anything
|
15
15
|
)
|
16
|
-
.
|
16
|
+
.returns(T::Boolean)
|
17
17
|
end
|
18
18
|
def method_missing(method_name, *args, **kwargs)
|
19
19
|
task = MonoRepoDeps.current_project.tasks.detect { _1.name == method_name } || (raise StandardError.new("task '#{method_name}' not found for project"))
|
@@ -22,34 +22,15 @@ class MonoRepoDeps::Task::Manager
|
|
22
22
|
when :package
|
23
23
|
statuses = kwargs[:packages].inject({}) do |result, package_name|
|
24
24
|
package = packages_repo.find!(package_name.to_sym)
|
25
|
-
result[package.name] =
|
25
|
+
result[package.name] = task.block.call(package, kwargs[:args])
|
26
26
|
result
|
27
27
|
end
|
28
28
|
|
29
|
-
failed_packages = statuses.reject {|package_name, exitstatus| exitstatus
|
29
|
+
failed_packages = statuses.reject {|package_name, exitstatus| exitstatus == 0}
|
30
30
|
|
31
|
-
|
32
|
-
puts failed_packages.keys
|
33
|
-
exit 1
|
34
|
-
end
|
31
|
+
failed_packages.any? ? false : true
|
35
32
|
else
|
36
33
|
raise StandardError.new("unsupported task subject: #{task.on}")
|
37
34
|
end
|
38
35
|
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def do_in_child(block, *args)
|
43
|
-
read, write = IO.pipe
|
44
|
-
|
45
|
-
pid = fork do
|
46
|
-
read.close
|
47
|
-
block.call(*args)
|
48
|
-
end
|
49
|
-
|
50
|
-
write.close
|
51
|
-
Process.wait(pid)
|
52
|
-
|
53
|
-
exit($?.exitstatus)
|
54
|
-
end
|
55
36
|
end
|
data/lib/mono_repo_deps.rb
CHANGED
@@ -45,12 +45,12 @@ module MonoRepoDeps
|
|
45
45
|
class << self
|
46
46
|
attr_accessor :current_project
|
47
47
|
|
48
|
-
def init_package(package_name = nil, from: caller_locations.first.path, env: nil)
|
48
|
+
def init_package(package_name = nil, from: caller_locations.first.path, env: nil, prevent_eager_load: false)
|
49
49
|
sync_current_project!(from) do
|
50
50
|
package_name ||= Container["package.builder"].call(from, current_project.root_path, current_project.package_dirname).name
|
51
51
|
env ||= current_project.env
|
52
52
|
|
53
|
-
Container["package.initializer"].call(package_name, env: env)
|
53
|
+
Container["package.initializer"].call(package_name, env: env, prevent_eager_load: prevent_eager_load)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -84,34 +84,6 @@ module MonoRepoDeps
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
def check_classes(from = caller_locations.first.path)
|
88
|
-
sync_current_project!(from) do
|
89
|
-
all_packages = Container["package.repo"].all
|
90
|
-
total_count = all_packages.size
|
91
|
-
imported = []
|
92
|
-
packages_order = []
|
93
|
-
|
94
|
-
all_packages.each_with_index do |package, idx|
|
95
|
-
puts "loading package #{package.name} (#{idx+1}/#{total_count}/#{imported.size})"
|
96
|
-
|
97
|
-
Container["package.dependency_bypasser"].call(
|
98
|
-
package_name: package.name,
|
99
|
-
imported: imported,
|
100
|
-
packages_order: packages_order,
|
101
|
-
env: current_project.env
|
102
|
-
)
|
103
|
-
end
|
104
|
-
|
105
|
-
packages_order
|
106
|
-
.uniq
|
107
|
-
.map { Container["package.repo"].find(_1) }
|
108
|
-
.each { current_project.loader.push_dir(_1.workdir_path) }
|
109
|
-
.tap { current_project.loader.setup }
|
110
|
-
.each { require _1.entrypoint_file if File.exist?(_1.entrypoint_file) }
|
111
|
-
.tap { current_project.loader.check_classes }
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
87
|
def sync_current_project!(path, &block)
|
116
88
|
path = File.expand_path(path)
|
117
89
|
path = File.dirname(path) unless File.directory?(path)
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/mono_repo_deps/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "mono_repo_deps"
|
7
|
+
spec.version = MonoRepoDeps::VERSION
|
8
|
+
spec.authors = ["Nikita Kononov"]
|
9
|
+
spec.email = ["vocrsz@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "A Ruby gem for efficiently managing dependencies within a monorepo."
|
12
|
+
spec.description = <<-DESC
|
13
|
+
MonoRepoDeps is a powerful tool designed to streamline the process of splitting code into separate packages
|
14
|
+
within a monorepository. It provides a flexible and easy-to-use solution for managing dependencies between
|
15
|
+
packages, making it ideal for large-scale projects with complex codebases.
|
16
|
+
|
17
|
+
Key Features:
|
18
|
+
- Simplifies the organization of code in a monorepo structure.
|
19
|
+
- Manages dependencies seamlessly between different packages.
|
20
|
+
- Enhances collaboration and code sharing among teams working on interconnected components.
|
21
|
+
- Offers a straightforward and customizable configuration for your monorepo setup.
|
22
|
+
|
23
|
+
How to Use:
|
24
|
+
- Install the gem using `gem install MonoRepoDeps`.
|
25
|
+
- Configure MonoRepoDeps with your monorepo specifications.
|
26
|
+
- Enjoy a more efficient and organized development workflow.
|
27
|
+
|
28
|
+
Visit the official documentation for detailed instructions and examples.
|
29
|
+
|
30
|
+
GitHub Repository: https://github.com/droidlabs/MonoRepoDeps
|
31
|
+
DESC
|
32
|
+
spec.homepage = "https://github.com/droidlabs/mono_repo_deps"
|
33
|
+
spec.license = "MIT"
|
34
|
+
spec.required_ruby_version = ">= 2.7.0"
|
35
|
+
|
36
|
+
# spec.metadata["allowed_push_host"] = "Set to your gem server 'https://example.com'"
|
37
|
+
|
38
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
39
|
+
spec.metadata["source_code_uri"] = "https://github.com/droidlabs/mono_repo_deps"
|
40
|
+
spec.metadata["changelog_uri"] = "https://github.com/droidlabs/mono_repo_deps"
|
41
|
+
|
42
|
+
# Specify which files should be added to the gem when it is released.
|
43
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
44
|
+
spec.files = Dir.chdir(__dir__) do
|
45
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
46
|
+
(File.expand_path(f) == __FILE__) ||
|
47
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
spec.bindir = "exe"
|
51
|
+
spec.executables = spec.files.grep(/\Aexe\//) { |f| File.basename(f) }
|
52
|
+
spec.require_paths = ["lib"]
|
53
|
+
|
54
|
+
spec.add_dependency 'sorbet-runtime', "~> 0.5.11164"
|
55
|
+
|
56
|
+
spec.add_dependency "dry-auto_inject", "~> 1.0.1"
|
57
|
+
spec.add_dependency "dry-core", "~> 1.0.0"
|
58
|
+
spec.add_dependency "dry-configurable", "~> 1.0.1"
|
59
|
+
spec.add_dependency "dry-container", "~> 0.11.0"
|
60
|
+
spec.add_dependency "dry-system", "~> 1.0.1"
|
61
|
+
|
62
|
+
spec.add_dependency "zeitwerk", "~> 2.6.12"
|
63
|
+
|
64
|
+
spec.add_dependency "thor"
|
65
|
+
|
66
|
+
spec.add_development_dependency "bundler", "~> 2.2"
|
67
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
68
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
69
|
+
spec.add_development_dependency "pry"
|
70
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mono_repo_deps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Kononov
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sorbet-runtime
|
@@ -284,6 +284,7 @@ files:
|
|
284
284
|
- lib/mono_repo_deps/task.rb
|
285
285
|
- lib/mono_repo_deps/task/manager.rb
|
286
286
|
- lib/mono_repo_deps/version.rb
|
287
|
+
- mono_repo_deps.gemspec
|
287
288
|
- sig/mono_repo_deps.rbs
|
288
289
|
homepage: https://github.com/droidlabs/mono_repo_deps
|
289
290
|
licenses:
|
@@ -292,7 +293,7 @@ metadata:
|
|
292
293
|
homepage_uri: https://github.com/droidlabs/mono_repo_deps
|
293
294
|
source_code_uri: https://github.com/droidlabs/mono_repo_deps
|
294
295
|
changelog_uri: https://github.com/droidlabs/mono_repo_deps
|
295
|
-
post_install_message:
|
296
|
+
post_install_message:
|
296
297
|
rdoc_options: []
|
297
298
|
require_paths:
|
298
299
|
- lib
|
@@ -308,7 +309,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
308
309
|
version: '0'
|
309
310
|
requirements: []
|
310
311
|
rubygems_version: 3.1.6
|
311
|
-
signing_key:
|
312
|
+
signing_key:
|
312
313
|
specification_version: 4
|
313
314
|
summary: A Ruby gem for efficiently managing dependencies within a monorepo.
|
314
315
|
test_files: []
|