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.
@@ -1,3 +1,3 @@
1
1
  module ReactManifest
2
- VERSION = "0.2.33".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
@@ -14,6 +14,7 @@ require "react_manifest/application_analyzer"
14
14
  require "react_manifest/application_migrator"
15
15
  require "react_manifest/layout_patcher"
16
16
  require "react_manifest/sprockets_manifest_patcher"
17
+ require "react_manifest/gitignore_patcher"
17
18
  require "react_manifest/watcher"
18
19
  require "react_manifest/reporter"
19
20
  require "react_manifest/view_helpers"
@@ -55,10 +56,7 @@ module ReactManifest
55
56
  bundles << shared if shared
56
57
 
57
58
  # 2. always_include bundles (e.g. ux_main)
58
- config.always_include.each do |b|
59
- resolved = resolve_bundle_reference(config, b)
60
- bundles << resolved if resolved && !bundles.include?(resolved)
61
- end
59
+ append_always_include(config, bundles)
62
60
 
63
61
  # 3. Controller-specific bundle
64
62
  # Try fully-namespaced first: admin/users → ux_admin_users
@@ -74,6 +72,18 @@ module ReactManifest
74
72
  bundles
75
73
  end
76
74
 
75
+ # Ensure the manifest dir is gitignored (and .keep present). Honors
76
+ # config.manage_gitignore. Returns true if it appended the .gitignore entry.
77
+ # Best-effort: a filesystem error is logged and swallowed (never breaks boot).
78
+ def reconcile_gitignore!(config = configuration)
79
+ return false unless config.manage_gitignore?
80
+
81
+ GitignorePatcher.new(config).reconcile!
82
+ rescue StandardError => e
83
+ Rails.logger&.warn("[ReactManifest] gitignore reconcile skipped: #{e.message}")
84
+ false
85
+ end
86
+
77
87
  # Resolve a controller bundle from a React component symbol.
78
88
  #
79
89
  # This is primarily used to support react-rails `react_component` calls,
@@ -102,6 +112,12 @@ module ReactManifest
102
112
  shared = resolve_bundle_reference(config, config.shared_bundle)
103
113
  bundles << shared if shared
104
114
 
115
+ # always_include bundles are delivered on every page. react_component does
116
+ # NOT go through resolve_bundles, so it must emit them here too — this is
117
+ # what makes always_include symbols available without inlining them into
118
+ # controller manifests (which would double-declare, see Generator).
119
+ append_always_include(config, bundles)
120
+
105
121
  root = resolve_bundle_reference(config, root_bundle)
106
122
  bundles << root if root && !bundles.include?(root)
107
123
 
@@ -142,6 +158,15 @@ module ReactManifest
142
158
 
143
159
  private
144
160
 
161
+ # Append each configured always_include bundle (deduped) to +bundles+.
162
+ def append_always_include(config, bundles)
163
+ config.always_include.each do |b|
164
+ resolved = resolve_bundle_reference(config, b)
165
+ bundles << resolved if resolved && !bundles.include?(resolved)
166
+ end
167
+ bundles
168
+ end
169
+
145
170
  def component_bundle_map(config)
146
171
  component_maps(config)[:symbol_to_bundle]
147
172
  end
@@ -163,13 +188,16 @@ module ReactManifest
163
188
  bundle_name = ctrl[:bundle_name]
164
189
  files = js_files_in_controller(ctrl[:path], config)
165
190
  bundle_files[bundle_name].concat(files)
191
+ isolated = config.isolated_app_dirs.include?(ctrl[:name])
166
192
 
167
193
  files.each do |file_path|
168
194
  extract_defined_symbols(file_path).each do |symbol|
169
195
  next unless symbol.match?(/\A[A-Z][A-Za-z0-9_]*\z/)
170
196
 
171
197
  # Keep first writer to ensure deterministic behavior if a symbol is duplicated.
172
- symbol_to_bundle[symbol] ||= bundle_name
198
+ # Isolated dirs never register into the shared symbol index (see
199
+ # Generator#build_controller_context for the full rationale).
200
+ symbol_to_bundle[symbol] ||= bundle_name unless isolated
173
201
  bundle_own_symbols[bundle_name] << symbol
174
202
  end
175
203
  end
@@ -211,14 +239,14 @@ module ReactManifest
211
239
 
212
240
  def extract_defined_symbols(file_path)
213
241
  content = File.read(file_path, encoding: "utf-8")
214
- SymbolExtractor.extract_definitions(content)
242
+ SymbolExtractor.extract_definitions(content, file_path: file_path)
215
243
  rescue Errno::ENOENT, Errno::EACCES, Encoding::InvalidByteSequenceError
216
244
  []
217
245
  end
218
246
 
219
247
  def extract_used_component_symbols(file_path)
220
248
  content = File.read(file_path, encoding: "utf-8")
221
- SymbolExtractor.extract_usages(content)
249
+ SymbolExtractor.extract_usages(content, file_path: file_path)
222
250
  rescue Errno::ENOENT, Errno::EACCES, Encoding::InvalidByteSequenceError
223
251
  []
224
252
  end
@@ -80,6 +80,22 @@ namespace :react_manifest do
80
80
  puts " ✓ #{written} written, #{unchanged} unchanged"
81
81
  end
82
82
 
83
+ # 6. Ensure generated manifests are gitignored
84
+ puts "\n6) Gitignoring generated manifests..."
85
+ if config.manage_gitignore?
86
+ patcher = ReactManifest::GitignorePatcher.new(config)
87
+ result = patcher.patch!
88
+ if result.appended
89
+ puts " ✓ added #{patcher.pattern} to .gitignore"
90
+ puts " → one-time cleanup for previously-committed manifests:"
91
+ puts " git rm --cached #{File.dirname(patcher.pattern)}/*.js"
92
+ else
93
+ puts " ✓ #{patcher.pattern} already ignored"
94
+ end
95
+ else
96
+ puts " (skipped — config.manage_gitignore is false)"
97
+ end
98
+
83
99
  # Done
84
100
  puts "\n=== Setup #{'(dry-run) ' if config.dry_run?}complete ==="
85
101
  puts "Start your Rails server — react_bundle_tag will serve the right JS per controller." unless config.dry_run?
@@ -130,6 +146,14 @@ namespace :react_manifest do
130
146
  scan_result = scanner.scan(classification)
131
147
  dep_map = ReactManifest::DependencyMap.new(scan_result)
132
148
  dep_map.print_report
149
+
150
+ reasons = ReactManifest::Generator.new(config).promotion_reasons
151
+ unless reasons.empty?
152
+ puts "\nPromotions (app/ components emitted into #{config.shared_bundle}):"
153
+ reasons.sort.each do |req, bundles|
154
+ puts " #{req} <- used by: #{bundles.sort.join(', ')}"
155
+ end
156
+ end
133
157
  end
134
158
 
135
159
  desc "Analyze application*.js files — show what migrate_application would change"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react-manifest-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.33
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Noonan
@@ -119,6 +119,20 @@ dependencies:
119
119
  - - "~>"
120
120
  - !ruby/object:Gem::Version
121
121
  version: '3.0'
122
+ - !ruby/object:Gem::Dependency
123
+ name: mini_racer
124
+ requirement: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ type: :development
130
+ prerelease: false
131
+ version_requirements: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
122
136
  description: |
123
137
  react-manifest-rails automatically generates per-controller Sprockets manifest
124
138
  files for Rails applications using react-rails + Sprockets. It eliminates the
@@ -137,9 +151,11 @@ files:
137
151
  - lib/react_manifest.rb
138
152
  - lib/react_manifest/application_analyzer.rb
139
153
  - lib/react_manifest/application_migrator.rb
154
+ - lib/react_manifest/ast_extractor.rb
140
155
  - lib/react_manifest/configuration.rb
141
156
  - lib/react_manifest/dependency_map.rb
142
157
  - lib/react_manifest/generator.rb
158
+ - lib/react_manifest/gitignore_patcher.rb
143
159
  - lib/react_manifest/layout_patcher.rb
144
160
  - lib/react_manifest/logging.rb
145
161
  - lib/react_manifest/path_utils.rb
@@ -149,6 +165,11 @@ files:
149
165
  - lib/react_manifest/sprockets_manifest_patcher.rb
150
166
  - lib/react_manifest/symbol_extractor.rb
151
167
  - lib/react_manifest/tree_classifier.rb
168
+ - lib/react_manifest/vendor/ast_extractor.js
169
+ - lib/react_manifest/vendor/build/README.md
170
+ - lib/react_manifest/vendor/build/entry.js
171
+ - lib/react_manifest/vendor/build/package-lock.json
172
+ - lib/react_manifest/vendor/build/package.json
152
173
  - lib/react_manifest/version.rb
153
174
  - lib/react_manifest/view_helpers.rb
154
175
  - lib/react_manifest/watcher.rb