Skip to content

Commit 84e1f60

Browse files
authored
Merge pull request #38 from tonymarklove/ignore-vendor-package-yml
2 parents b0670c8 + 37278d8 commit 84e1f60

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

lib/packwerk/application_validator.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def package_glob
331331
end
332332

333333
def package_manifests(glob_pattern)
334-
Dir.glob(File.join(glob_pattern, Packwerk::PackageSet::PACKAGE_CONFIG_FILENAME)).map { |f| File.realpath(f) }
334+
PackageSet.package_paths(@configuration.root_path, glob_pattern).map(&:to_s)
335335
end
336336

337337
def relative_paths(paths)

lib/packwerk/package_set.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ def load_all_from(root_path, package_pathspec: nil)
2525
new(packages)
2626
end
2727

28-
private
29-
3028
def package_paths(root_path, package_pathspec)
29+
bundle_path_match = Bundler.bundle_path.join("**").to_s
30+
3131
Dir.glob(File.join(root_path, package_pathspec, PACKAGE_CONFIG_FILENAME))
32-
.map! { |path| Pathname.new(path) }
32+
.map { |path| Pathname.new(path) }.reject { |path| path.realpath.fnmatch(bundle_path_match) }
3333
end
3434

35+
private
36+
3537
def create_root_package_if_none_in(packages)
3638
return if packages.any?(&:root?)
3739
packages << Package.new(name: Package::ROOT_PACKAGE_NAME, config: nil)

lib/packwerk/run_context.rb

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def from_configuration(configuration, reference_lister: nil)
3939
new(
4040
root_path: configuration.root_path,
4141
load_paths: configuration.load_paths,
42+
package_paths: configuration.package_paths,
4243
inflector: ActiveSupport::Inflector,
4344
custom_associations: configuration.custom_associations,
4445
reference_lister: default_reference_lister,

test/fixtures/skeleton/vendor/cache/gems/example/package.yml

Whitespace-only changes.

test/unit/cli_test.rb

+12-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,12 @@ class CliTest < Minitest::Test
113113

114114
test "#execute_command with init subcommand runs application validation generator for non-Rails app" do
115115
string_io = StringIO.new
116-
configuration = stub(root_path: @temp_dir, load_paths: ["path"], custom_associations: ["cached_belongs_to"])
116+
configuration = stub(
117+
root_path: @temp_dir,
118+
load_paths: ["path"],
119+
package_paths: "**/",
120+
custom_associations: ["cached_belongs_to"]
121+
)
117122
cli = ::Packwerk::Cli.new(configuration: configuration, out: string_io)
118123

119124
Packwerk::Generators::ApplicationValidation.expects(:generate).returns(true)
@@ -125,7 +130,12 @@ class CliTest < Minitest::Test
125130

126131
test "#execute_command with init subcommand runs application validation generator, fails and prints error" do
127132
string_io = StringIO.new
128-
configuration = stub(root_path: @temp_dir, load_paths: ["path"], custom_associations: ["cached_belongs_to"])
133+
configuration = stub(
134+
root_path: @temp_dir,
135+
load_paths: ["path"],
136+
package_paths: "**/",
137+
custom_associations: ["cached_belongs_to"]
138+
)
129139
cli = ::Packwerk::Cli.new(configuration: configuration, out: string_io)
130140

131141
Packwerk::Generators::ApplicationValidation.expects(:generate).returns(false)

test/unit/package_set_test.rb

+11
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,16 @@ class PackageSetTest < Minitest::Test
3131
test "#fetch returns nil for unknown package name" do
3232
assert_nil(@package_set.fetch("components/unknown"))
3333
end
34+
35+
test ".package_paths excludes paths inside the gem directory" do
36+
vendor_package_path = Pathname.new("test/fixtures/skeleton/vendor/cache/gems/example/package.yml")
37+
38+
package_paths = PackageSet.package_paths("test/fixtures/skeleton", "**")
39+
assert_includes(package_paths, vendor_package_path)
40+
41+
Bundler.expects(:bundle_path).returns(Rails.root.join("vendor/cache/gems"))
42+
package_paths = PackageSet.package_paths("test/fixtures/skeleton", "**")
43+
refute_includes(package_paths, vendor_package_path)
44+
end
3445
end
3546
end

0 commit comments

Comments
 (0)