synvert-core 1.17.0 → 1.18.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +6 -6
- data/README.md +2 -2
- data/lib/synvert/core/rewriter.rb +2 -54
- data/lib/synvert/core/utils.rb +38 -0
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/rewriter_spec.rb +3 -12
- data/spec/synvert/core/utils_spec.rb +25 -0
- data/synvert-core-ruby.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 036a5a2a642e96b611185e400b4f458be77f2622c3ef996bdac4bc0cbda1df70
|
4
|
+
data.tar.gz: 51ec847622d9018176f4dceb51a2a9ac623c1129abea3012d6e2faab650ee7f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c739ddf2691480f5d53fe0033eb24a5c0e784116fec98eff71a58d1d1745a853790121a89979b32624fcb65ea104b837a744b9353fde8ef74ef227433e9be7f
|
7
|
+
data.tar.gz: 95ad1ab6a96a33f0299aa012f7731915a7af3794b805b5e5743ddd2d11c48e29dc34019773a3948b96db94aea814d928558c0ee0409a750dae3e85c6d503ec67
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
synvert-core (1.
|
4
|
+
synvert-core (1.18.1)
|
5
5
|
activesupport (< 7.0.0)
|
6
6
|
erubis
|
7
7
|
node_mutation (>= 1.8.2)
|
8
8
|
node_query (>= 1.12.0)
|
9
9
|
parallel
|
10
10
|
parser
|
11
|
-
parser_node_ext (>= 0.
|
11
|
+
parser_node_ext (>= 0.9.0)
|
12
12
|
|
13
13
|
GEM
|
14
14
|
remote: https://rubygems.org/
|
15
15
|
specs:
|
16
|
-
activesupport (6.1.7.
|
16
|
+
activesupport (6.1.7.2)
|
17
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
18
|
i18n (>= 1.6, < 2)
|
19
19
|
minitest (>= 5.1)
|
@@ -21,7 +21,7 @@ GEM
|
|
21
21
|
zeitwerk (~> 2.3)
|
22
22
|
ast (2.4.2)
|
23
23
|
coderay (1.1.3)
|
24
|
-
concurrent-ruby (1.
|
24
|
+
concurrent-ruby (1.2.0)
|
25
25
|
diff-lcs (1.5.0)
|
26
26
|
erubis (2.7.0)
|
27
27
|
fakefs (1.8.0)
|
@@ -59,7 +59,7 @@ GEM
|
|
59
59
|
parallel (1.22.1)
|
60
60
|
parser (3.2.0.0)
|
61
61
|
ast (~> 2.4.1)
|
62
|
-
parser_node_ext (0.
|
62
|
+
parser_node_ext (0.10.0)
|
63
63
|
parser
|
64
64
|
pry (0.14.1)
|
65
65
|
coderay (~> 1.1)
|
@@ -83,7 +83,7 @@ GEM
|
|
83
83
|
rspec-support (3.10.3)
|
84
84
|
shellany (0.0.1)
|
85
85
|
thor (1.2.1)
|
86
|
-
tzinfo (2.0.
|
86
|
+
tzinfo (2.0.6)
|
87
87
|
concurrent-ruby (~> 1.0)
|
88
88
|
zeitwerk (2.6.6)
|
89
89
|
|
data/README.md
CHANGED
@@ -69,7 +69,6 @@ DSLs are as follows
|
|
69
69
|
* [remove_file](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#remove_file-instance_method) - remove a file
|
70
70
|
* [helper_method](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#helper_method-instance_method) - define a helper method
|
71
71
|
* [add_snippet](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#add_snippet-instance_method) - call another rewriter
|
72
|
-
* [todo](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#todo-instance_method) - set todo
|
73
72
|
* [redo_until_no_change](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#redo_until_no_change-instance_method) - run the snippet until no change
|
74
73
|
|
75
74
|
Scopes:
|
@@ -93,7 +92,8 @@ Actions:
|
|
93
92
|
* [insert_after](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#insert_after-instance_method) - insert the code next to the current node
|
94
93
|
* [insert_before](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#insert_before-instance_method) - insert the code previous to the current node
|
95
94
|
* [replace](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#replace-instance_method) - replace the code of specified child nodes
|
96
|
-
* [delete](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#delete-instance_method) - delete the code specified child nodes
|
95
|
+
* [delete](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#delete-instance_method) - delete the code in specified child nodes
|
96
|
+
* [remove](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#remove-instance_method) - remove the whole code of current node
|
97
97
|
* [wrap](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#wrap-instance_method) - wrap the current node with code
|
98
98
|
* [replace_with](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#replace_with-instance_method) - replace the whole code of current node
|
99
99
|
* [warn](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#warn-instance_method) - warn message
|
@@ -330,28 +330,6 @@ module Synvert::Core
|
|
330
330
|
@helpers << { name: name, block: block }
|
331
331
|
end
|
332
332
|
|
333
|
-
# It sets todo of the rewriter.
|
334
|
-
# Or get todo.
|
335
|
-
# @example
|
336
|
-
# Synvert::Rewriter.new 'rails', 'upgrade_3_2_to_4_0' do
|
337
|
-
# todo <<~EOS
|
338
|
-
# 1. Rails 4.0 no longer supports loading plugins from vendor/plugins. You must replace any plugins by extracting them to gems and adding them to your Gemfile. If you choose not to make them gems, you can move them into, say, lib/my_plugin/* and add an appropriate initializer in config/initializers/my_plugin.rb.
|
339
|
-
# 2. Make the following changes to your Gemfile.
|
340
|
-
# gem 'sass-rails', '~> 4.0.0'
|
341
|
-
# gem 'coffee-rails', '~> 4.0.0'
|
342
|
-
# gem 'uglifier', '>= 1.3.0'
|
343
|
-
# EOS
|
344
|
-
# end
|
345
|
-
# @param todo [String] rewriter todo.
|
346
|
-
# @return [String] rewriter todo.
|
347
|
-
def todo(todo = nil)
|
348
|
-
if todo
|
349
|
-
@todo = todo
|
350
|
-
else
|
351
|
-
@todo
|
352
|
-
end
|
353
|
-
end
|
354
|
-
|
355
333
|
# Rerun the snippet until no change.
|
356
334
|
# @example
|
357
335
|
# Synvert::Rewriter.new 'ruby', 'nested_class_definition' do
|
@@ -369,46 +347,16 @@ module Synvert::Core
|
|
369
347
|
# @yieldparam file_path [String] file path.
|
370
348
|
def handle_one_file(file_patterns)
|
371
349
|
if Configuration.number_of_workers > 1
|
372
|
-
Parallel.map(
|
350
|
+
Parallel.map(Utils.glob(file_patterns), in_processes: Configuration.number_of_workers) do |file_path|
|
373
351
|
yield(file_path)
|
374
352
|
end
|
375
353
|
else
|
376
|
-
|
354
|
+
Utils.glob(file_patterns).map do |file_path|
|
377
355
|
yield(file_path)
|
378
356
|
end
|
379
357
|
end
|
380
358
|
end
|
381
359
|
|
382
|
-
# Get file paths.
|
383
|
-
# @return [Array<String>] file paths
|
384
|
-
def get_file_paths(file_patterns)
|
385
|
-
Dir.chdir(Configuration.root_path) do
|
386
|
-
only_paths = Configuration.only_paths.size > 0 ? Configuration.only_paths : ["."]
|
387
|
-
only_paths.flat_map do |only_path|
|
388
|
-
file_patterns.flat_map do |file_pattern|
|
389
|
-
pattern = only_path == "." ? file_pattern : File.join(only_path, file_pattern)
|
390
|
-
Dir.glob(pattern)
|
391
|
-
end
|
392
|
-
end - get_skip_files
|
393
|
-
end
|
394
|
-
end
|
395
|
-
|
396
|
-
# Get skip files.
|
397
|
-
# @return [Array<String>] skip files
|
398
|
-
def get_skip_files
|
399
|
-
Configuration.skip_paths.flat_map do |skip_path|
|
400
|
-
if File.directory?(skip_path)
|
401
|
-
Dir.glob(File.join(skip_path, "**/*"))
|
402
|
-
elsif File.file?(skip_path)
|
403
|
-
[skip_path]
|
404
|
-
elsif skip_path.end_with?("**") || skip_path.end_with?("**/")
|
405
|
-
Dir.glob(File.join(skip_path, "*"))
|
406
|
-
else
|
407
|
-
Dir.glob(skip_path)
|
408
|
-
end
|
409
|
-
end
|
410
|
-
end
|
411
|
-
|
412
360
|
def merge_test_results(results)
|
413
361
|
@test_results += results.select { |result| result.affected? }
|
414
362
|
end
|
data/lib/synvert/core/utils.rb
CHANGED
@@ -27,6 +27,18 @@ module Synvert::Core
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
# Glob file paths.
|
31
|
+
# @param file_patterns [Array<String>] file patterns
|
32
|
+
# @return [Array<String>] file paths
|
33
|
+
def glob(file_patterns)
|
34
|
+
Dir.chdir(Configuration.root_path) do
|
35
|
+
all_files = file_patterns.flat_map do |file_pattern|
|
36
|
+
Dir.glob(file_pattern)
|
37
|
+
end
|
38
|
+
filter_only_paths(all_files) - get_skip_files
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
30
42
|
private
|
31
43
|
|
32
44
|
def is_valid_url?(url)
|
@@ -65,6 +77,32 @@ module Synvert::Core
|
|
65
77
|
|
66
78
|
url.sub('//github.com/', '//raw.githubusercontent.com/').sub('/blob/', '/')
|
67
79
|
end
|
80
|
+
|
81
|
+
# Filter only paths with `Configuration.only_paths`.
|
82
|
+
# @return [Array<String>] filtered file paths
|
83
|
+
def filter_only_paths(all_files)
|
84
|
+
return all_files if Configuration.only_paths.size == 0
|
85
|
+
|
86
|
+
Configuration.only_paths.flat_map do |only_path|
|
87
|
+
all_files.filter { |file_path| file_path.starts_with?(only_path) }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# Get skip files.
|
92
|
+
# @return [Array<String>] skip files
|
93
|
+
def get_skip_files
|
94
|
+
Configuration.skip_paths.flat_map do |skip_path|
|
95
|
+
if File.directory?(skip_path)
|
96
|
+
Dir.glob(File.join(skip_path, "**/*"))
|
97
|
+
elsif File.file?(skip_path)
|
98
|
+
[skip_path]
|
99
|
+
elsif skip_path.end_with?("**") || skip_path.end_with?("**/")
|
100
|
+
Dir.glob(File.join(skip_path, "*"))
|
101
|
+
else
|
102
|
+
Dir.glob(skip_path)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
68
106
|
end
|
69
107
|
end
|
70
108
|
end
|
data/lib/synvert/core/version.rb
CHANGED
@@ -86,7 +86,7 @@ module Synvert::Core
|
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'delegates process to instances if if_ruby matches' do
|
89
|
-
expect(
|
89
|
+
expect(Utils).to receive(:glob).with(['config/routes.rb']).and_return(['config/routes.rb'])
|
90
90
|
expect(File).to receive(:exist?).with('./.ruby-version').and_return(true)
|
91
91
|
expect(File).to receive(:read).with('./.ruby-version').and_return('2.0.0')
|
92
92
|
expect_any_instance_of(Rewriter::Instance).to receive(:process)
|
@@ -112,7 +112,7 @@ module Synvert::Core
|
|
112
112
|
end
|
113
113
|
|
114
114
|
it 'delegates process to instances if if_gem matches' do
|
115
|
-
expect(
|
115
|
+
expect(Utils).to receive(:glob).with(['config/routes.rb']).and_return(['config/routes.rb'])
|
116
116
|
expect_any_instance_of(Rewriter::GemSpec).to receive(:match?).and_return(true)
|
117
117
|
expect_any_instance_of(Rewriter::Instance).to receive(:process)
|
118
118
|
rewriter =
|
@@ -125,7 +125,7 @@ module Synvert::Core
|
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'delegates process to instances if if_ruby and if_gem do not exist' do
|
128
|
-
expect(
|
128
|
+
expect(Utils).to receive(:glob).with(['config/routes.rb']).and_return(['config/routes.rb'])
|
129
129
|
expect_any_instance_of(Rewriter::Instance).to receive(:process)
|
130
130
|
rewriter =
|
131
131
|
Rewriter.new 'group', 'name' do
|
@@ -256,15 +256,6 @@ module Synvert::Core
|
|
256
256
|
expect(instance.dynamic_helper('arg1', 'arg2')).to eq 'dynamic result'
|
257
257
|
end
|
258
258
|
|
259
|
-
it 'parses todo' do
|
260
|
-
rewriter =
|
261
|
-
Rewriter.new 'group', 'name' do
|
262
|
-
todo "this rewriter doesn't do blah blah blah"
|
263
|
-
end
|
264
|
-
rewriter.process
|
265
|
-
expect(rewriter.todo).to eq "this rewriter doesn't do blah blah blah"
|
266
|
-
end
|
267
|
-
|
268
259
|
it 'parses redo_until_no_change' do
|
269
260
|
rewriter =
|
270
261
|
Rewriter.new 'group', 'name' do
|
@@ -53,5 +53,30 @@ module Synvert::Core
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
describe '.glob' do
|
58
|
+
before do
|
59
|
+
Configuration.only_paths = []
|
60
|
+
Configuration.skip_paths = []
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'gets all files' do
|
64
|
+
expect(Dir).to receive(:glob).with('**/*.rb').and_return(['app/models/post.rb', 'app/controllers/posts_controller.rb'])
|
65
|
+
expect(described_class.glob(['**/*.rb'])).to eq(['app/models/post.rb', 'app/controllers/posts_controller.rb'])
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'filters only paths' do
|
69
|
+
Configuration.only_paths = ['app/models']
|
70
|
+
expect(Dir).to receive(:glob).with('**/*.rb').and_return(['app/models/post.rb', 'app/controllers/posts_controller.rb'])
|
71
|
+
expect(described_class.glob(['**/*.rb'])).to eq(['app/models/post.rb'])
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'skip files' do
|
75
|
+
Configuration.skip_paths = ['app/controllers/**/*']
|
76
|
+
expect(Dir).to receive(:glob).with('**/*.rb').and_return(['app/models/post.rb', 'app/controllers/posts_controller.rb'])
|
77
|
+
expect(Dir).to receive(:glob).with('app/controllers/**/*').and_return(['app/controllers/posts_controller.rb'])
|
78
|
+
expect(described_class.glob(['**/*.rb'])).to eq(['app/models/post.rb'])
|
79
|
+
end
|
80
|
+
end
|
56
81
|
end
|
57
82
|
end
|
data/synvert-core-ruby.gemspec
CHANGED
@@ -24,6 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_runtime_dependency "node_query", ">= 1.12.0"
|
25
25
|
spec.add_runtime_dependency "node_mutation", ">= 1.8.2"
|
26
26
|
spec.add_runtime_dependency "parser"
|
27
|
-
spec.add_runtime_dependency "parser_node_ext", ">= 0.
|
27
|
+
spec.add_runtime_dependency "parser_node_ext", ">= 0.9.0"
|
28
28
|
spec.add_runtime_dependency "parallel"
|
29
29
|
end
|
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.
|
4
|
+
version: 1.18.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: 2023-
|
11
|
+
date: 2023-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: 0.9.0
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
96
|
+
version: 0.9.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: parallel
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|