synvert-core 1.32.1 → 1.33.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3c2e2aa7e3cb3eb9d99c5e2a17a92dafc5e0fe6772329e96fb6a80483a5abf5
4
- data.tar.gz: 92df973552a4554bb59d9d56296cca6fe8e57a3dabd1d424b3344fa10f20651c
3
+ metadata.gz: bc05338573c2a8a930dfbbafec5aa122da815e072fea47e1ac9c83f97753fa97
4
+ data.tar.gz: 40764685f615c7b236e6f96a8242d9b9088dce8c5901384e9ef74428ce04a0da
5
5
  SHA512:
6
- metadata.gz: 98be499a994210b2ccbd76d73b6d97a2fd9ea46724aef6d329694662e84186c4cf9ecb7beac15102d27881c5db4337fd8f485b54aff012a6e3eebcedc19c9766
7
- data.tar.gz: 1e2cf1d95019f79ac85e2344f00ef37aac814a2eaec3fbf508c962050d1cc2e64d9d553be4126688fb44978fae680c73de5b050e4f4fc78919fd28942cf4b011
6
+ metadata.gz: 5a02ad97db0eaea55a971d5fd58c244f49ce442e2d38dd170d41132e55ecb785f39627e90826454f89f55d3f7b41b701c6bdca46b58639d9fbb185924d1eaf35
7
+ data.tar.gz: e64da537b70a1d2f4e25b9a0e74955b9f51acdcd57f1dd241bf8a497af57b1c7f2ff427a400dfbe3fff00dc23c556ec54f59f01eea9879cd0ee56b99a6f6d41f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.33.1 (2024-02-23)
4
+
5
+ * Try 10 times at maximum when process
6
+
7
+ ## 1.33.0 (2024-02-18)
8
+
9
+ * Add `Configuration.respect_gitignore`
10
+ * Glob files with `git check-ignore` if `Configuration.respect_gitignore` is true
11
+
3
12
  ## 1.32.1 (2024-02-17)
4
13
 
5
14
  * Update `node_mutation` to 1.23.2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- synvert-core (1.32.1)
4
+ synvert-core (1.33.1)
5
5
  activesupport (< 7.0.0)
6
6
  node_mutation (>= 1.23.2)
7
7
  node_query (>= 1.15.1)
@@ -16,7 +16,7 @@ PATH
16
16
  GEM
17
17
  remote: https://rubygems.org/
18
18
  specs:
19
- activesupport (6.1.7.6)
19
+ activesupport (6.1.7.7)
20
20
  concurrent-ruby (~> 1.0, >= 1.0.2)
21
21
  i18n (>= 1.6, < 2)
22
22
  minitest (>= 5.1)
@@ -52,7 +52,7 @@ GEM
52
52
  method_source (1.0.0)
53
53
  minitest (5.22.2)
54
54
  nenv (0.3.0)
55
- node_mutation (1.23.2)
55
+ node_mutation (1.23.3)
56
56
  node_query (1.15.1)
57
57
  notiffany (0.1.3)
58
58
  nenv (~> 0.1)
@@ -7,6 +7,7 @@ module Synvert::Core
7
7
  # @!attribute [w] root_path
8
8
  # @!attribute [w] skip_paths
9
9
  # @!attribute [w] only_paths
10
+ # @!attribute [w] respect_gitignore
10
11
  # @!attribute [w] show_run_process
11
12
  # @!attribute [w] number_of_workers
12
13
  # @!attribute [w] single_quote
@@ -16,6 +17,7 @@ module Synvert::Core
16
17
  attr_writer :root_path,
17
18
  :skip_paths,
18
19
  :only_paths,
20
+ :respect_gitignore,
19
21
  :show_run_process,
20
22
  :number_of_workers,
21
23
  :single_quote,
@@ -44,6 +46,13 @@ module Synvert::Core
44
46
  @only_paths || []
45
47
  end
46
48
 
49
+ # Check if respect .gitignore
50
+ #
51
+ # @return [Boolean] default is true
52
+ def respect_gitignore
53
+ @respect_gitignore.nil? ? true : @respect_gitignore
54
+ end
55
+
47
56
  # Check if show run process.
48
57
  #
49
58
  # @return [Boolean] default is false
@@ -47,8 +47,9 @@ module Synvert::Core
47
47
  puts @file_path if Configuration.show_run_process
48
48
 
49
49
  absolute_file_path = File.join(Configuration.root_path, @file_path)
50
- # It keeps running until no conflict.
51
- loop do
50
+ # It keeps running until no conflict,
51
+ # it will try 10 times at maximum.
52
+ 10.times do
52
53
  source = read_source(absolute_file_path)
53
54
  encoded_source = Engine.encode(File.extname(file_path), source)
54
55
  @current_mutation = NodeMutation.new(source, adapter: @rewriter.parser)
@@ -3,6 +3,7 @@
3
3
  require 'net/http'
4
4
  require 'uri'
5
5
  require 'open-uri'
6
+ require 'open3'
6
7
 
7
8
  module Synvert::Core
8
9
  class Utils
@@ -35,11 +36,21 @@ module Synvert::Core
35
36
  # @return [Array<String>] file paths
36
37
  def glob(file_patterns)
37
38
  Dir.chdir(Configuration.root_path) do
38
- all_files =
39
- file_patterns.flat_map do |file_pattern|
40
- Dir.glob(file_pattern)
39
+ all_files = file_patterns.flat_map { |pattern| Dir.glob(pattern) }
40
+ ignored_files = []
41
+
42
+ if Configuration.respect_gitignore
43
+ Open3.popen3('git check-ignore --stdin') do |stdin, stdout, stderr, wait_thr|
44
+ stdin.puts(all_files.join("\n"))
45
+ stdin.close
46
+
47
+ ignored_files = stdout.read.split("\n")
41
48
  end
42
- filter_only_paths(all_files) - get_skip_files
49
+ end
50
+
51
+ filtered_files = filter_only_paths(all_files - ignored_files)
52
+
53
+ filtered_files -= get_explicitly_skipped_files
43
54
  end
44
55
  end
45
56
 
@@ -85,16 +96,16 @@ module Synvert::Core
85
96
  # Filter only paths with `Configuration.only_paths`.
86
97
  # @return [Array<String>] filtered file paths
87
98
  def filter_only_paths(all_files)
88
- return all_files if Configuration.only_paths.size == 0
99
+ return all_files if Configuration.only_paths.empty?
89
100
 
90
101
  Configuration.only_paths.flat_map do |only_path|
91
102
  all_files.filter { |file_path| file_path.starts_with?(only_path) }
92
103
  end
93
104
  end
94
105
 
95
- # Get skip files.
96
- # @return [Array<String>] skip files
97
- def get_skip_files
106
+ # Get skipped files.
107
+ # @return [Array<String>] skipped files
108
+ def get_explicitly_skipped_files
98
109
  Configuration.skip_paths.flat_map do |skip_path|
99
110
  if File.directory?(skip_path)
100
111
  Dir.glob(File.join(skip_path, "**/*"))
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '1.32.1'
5
+ VERSION = '1.33.1'
6
6
  end
7
7
  end
@@ -58,16 +58,42 @@ module Synvert::Core
58
58
  before do
59
59
  Configuration.only_paths = []
60
60
  Configuration.skip_paths = []
61
+ Configuration.respect_gitignore = false
61
62
  end
62
63
 
63
- it 'gets all files' do
64
- expect(Dir).to receive(:glob).with('**/*.rb').and_return(
65
- [
66
- 'app/models/post.rb',
67
- 'app/controllers/posts_controller.rb'
68
- ]
69
- )
70
- expect(described_class.glob(['**/*.rb'])).to eq(['app/models/post.rb', 'app/controllers/posts_controller.rb'])
64
+ context 'Configuration.respect_gitignore is false' do
65
+ it 'gets all files' do
66
+ expect(Dir).to receive(:glob).with('**/*.rb').and_return(
67
+ [
68
+ 'app/models/post.rb',
69
+ 'app/controllers/posts_controller.rb'
70
+ ]
71
+ )
72
+ expect(described_class.glob(['**/*.rb'])).to eq(['app/models/post.rb', 'app/controllers/posts_controller.rb'])
73
+ end
74
+ end
75
+
76
+ context 'Configuration.respect_gitignore is true' do
77
+ before do
78
+ Configuration.respect_gitignore = true
79
+ end
80
+
81
+ it 'correctly filters out ignored files' do
82
+ file_patterns = ["**/*.rb"]
83
+ all_files = ["app/models/post.rb", "app/controllers/posts_controller.rb", "app/controllers/temp.tmp"]
84
+ not_ignored_files = ["app/models/post.rb", "app/controllers/posts_controller.rb"]
85
+ command_output = "app/controllers/temp.tmp\n"
86
+
87
+ allow(Open3).to receive(:popen3).with('git check-ignore --stdin').and_yield(
88
+ instance_double(IO, puts: nil, close: nil),
89
+ StringIO.new(command_output),
90
+ StringIO.new(''),
91
+ instance_double(Process::Waiter, value: instance_double(Process::Status, success?: true))
92
+ )
93
+ allow(Dir).to receive(:glob).and_return(all_files)
94
+
95
+ expect(described_class.glob(file_patterns)).to match_array(not_ignored_files)
96
+ end
71
97
  end
72
98
 
73
99
  it 'filters only paths' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synvert-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.32.1
4
+ version: 1.33.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-17 00:00:00.000000000 Z
11
+ date: 2024-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport