react-manifest-rails 0.2.33 → 0.3.0
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 +4 -4
- data/CHANGELOG.md +53 -0
- data/README.md +3 -0
- data/lib/react_manifest/ast_extractor.rb +70 -0
- data/lib/react_manifest/configuration.rb +37 -1
- data/lib/react_manifest/generator.rb +362 -63
- data/lib/react_manifest/gitignore_patcher.rb +75 -0
- data/lib/react_manifest/railtie.rb +6 -0
- data/lib/react_manifest/scanner.rb +6 -10
- data/lib/react_manifest/symbol_extractor.rb +37 -4
- data/lib/react_manifest/vendor/ast_extractor.js +19 -0
- data/lib/react_manifest/vendor/build/README.md +19 -0
- data/lib/react_manifest/vendor/build/entry.js +137 -0
- data/lib/react_manifest/vendor/build/package-lock.json +524 -0
- data/lib/react_manifest/vendor/build/package.json +11 -0
- data/lib/react_manifest/version.rb +1 -1
- data/lib/react_manifest.rb +35 -7
- data/tasks/react_manifest.rake +24 -0
- metadata +22 -1
|
@@ -30,9 +30,44 @@ module ReactManifest
|
|
|
30
30
|
|
|
31
31
|
module_function
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
# Uses the AST engine (mini_racer) when available; falls back to regex
|
|
34
|
+
# extraction for this content on any AST failure (unavailable engine,
|
|
35
|
+
# parse error, unsupported syntax such as TypeScript).
|
|
36
|
+
def extract_definitions(content, file_path: nil)
|
|
34
37
|
return [] unless content
|
|
35
38
|
|
|
39
|
+
if ast_engine_available?
|
|
40
|
+
result = AstExtractor.extract_definitions(content, file_path: file_path)
|
|
41
|
+
return result if result
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
regex_extract_definitions(content)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def extract_usages(content, file_path: nil)
|
|
48
|
+
return [] unless content
|
|
49
|
+
|
|
50
|
+
if ast_engine_available?
|
|
51
|
+
result = AstExtractor.extract_usages(content, file_path: file_path)
|
|
52
|
+
return result if result
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
regex_extract_usages(content)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Decided once per process: does `require "mini_racer"` succeed?
|
|
59
|
+
def ast_engine_available?
|
|
60
|
+
return @ast_engine_available if defined?(@ast_engine_available)
|
|
61
|
+
|
|
62
|
+
@ast_engine_available = begin
|
|
63
|
+
require_relative "ast_extractor"
|
|
64
|
+
true
|
|
65
|
+
rescue LoadError
|
|
66
|
+
false
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def regex_extract_definitions(content)
|
|
36
71
|
symbols = []
|
|
37
72
|
DEFINITION_PATTERNS.each do |pattern|
|
|
38
73
|
content.scan(pattern) { |m| symbols << m[0] }
|
|
@@ -40,9 +75,7 @@ module ReactManifest
|
|
|
40
75
|
symbols.uniq
|
|
41
76
|
end
|
|
42
77
|
|
|
43
|
-
def
|
|
44
|
-
return [] unless content
|
|
45
|
-
|
|
78
|
+
def regex_extract_usages(content)
|
|
46
79
|
local_syms = Set.new
|
|
47
80
|
DEFINITION_PATTERNS.each { |p| content.scan(p) { |m| local_syms << m[0] } }
|
|
48
81
|
|