Class: ReactOnRails::PacksGenerator
- Inherits:
-
Object
- Object
- ReactOnRails::PacksGenerator
- Defined in:
- lib/react_on_rails/packs_generator.rb
Overview
rubocop:disable Metrics/ClassLength
This class handles two INDEPENDENT classification systems:
-
BUNDLE PLACEMENT (.client. / .server. file suffixes) Controls which webpack bundle imports a file. Pre-dates React Server Components.
-
Component.client.jsx → client bundle only
-
Component.server.jsx → server bundle (and RSC bundle when RSC enabled; requires a paired .client. file)
-
Component.jsx (no suffix) → both bundles
These suffixes only make sense for client components, as server components exist only in the RSC bundle. Methods: common_component_to_path, client_component_to_path, server_component_to_path
-
-
RSC CLASSIFICATION (‘use client’ directive) Controls how a component is registered when RSC support is enabled (Pro feature).
-
Has ‘use client’ → ReactOnRails.register() → React Client Component
-
Lacks ‘use client’ → registerServerComponent() → React Server Component
Method: client_entrypoint?
-
These are orthogonal. A .client.jsx file can be a React Server Component (if it lacks ‘use client’), and a .server.jsx file can be a React Client Component (if it has ‘use client’).
Constant Summary collapse
- CONTAINS_CLIENT_OR_SERVER_REGEX =
/\.(server|client)($|\.)/- COMPONENT_EXTENSIONS =
/\.(jsx?|tsx?)$/- SERVER_BUNDLE_SOURCE_EXTENSIONS =
Fallback order when the configured server bundle file is missing. Keep .jsx before TypeScript extensions as the closest migration fallback for apps moving from JS/JSX to TS. The configured extension is excluded, so server-bundle.js tries .jsx, .ts, .tsx, …
%w[.js .jsx .ts .tsx .mts .cts .mjs .cjs].freeze
- SERVER_BUNDLE_IMPORT_EXTENSION_COMMENT_EXTENSIONS =
import/extensions suppressions are needed when generated imports include an explicit .js extension.
%w[.jsx .ts .tsx .mts .cts .mjs .cjs].freeze
- MINIMUM_SHAKAPACKER_VERSION_FOR_AUTO_BUNDLING =
Auto-registration requires nested_entries support which was added in 7.0.0 Note: The gemspec requires Shakapacker >= 6.0 for basic functionality
"7.0.0"- GENERATED_PACKS_LOCK_TTL_SECONDS =
Longer than any realistic pack generation; LOCK_NB still gates the actual clear.
120
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.instance ⇒ Object
43 44 45 |
# File 'lib/react_on_rails/packs_generator.rb', line 43 def self.instance @instance ||= PacksGenerator.new end |
Instance Method Details
#generate_packs_if_stale ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/react_on_rails/packs_generator.rb', line 53 def generate_packs_if_stale return unless ReactOnRails.configuration.auto_load_bundle @server_bundle_entrypoint = nil verbose = ENV["REACT_ON_RAILS_VERBOSE"] == "true" with_generated_packs_lock(verbose:) do add_generated_pack_to_server_bundle if generated_files_present_and_up_to_date? clean_non_generated_files_with_feedback(verbose:) puts Rainbow("✅ Generated packs are up to date, no regeneration needed").green if verbose else clean_generated_directories_with_feedback(verbose:) generate_packs(verbose:) end end ensure @server_bundle_entrypoint = nil end |
#react_on_rails_npm_package ⇒ Object
47 48 49 50 51 |
# File 'lib/react_on_rails/packs_generator.rb', line 47 def react_on_rails_npm_package return "react-on-rails-pro" if ReactOnRails::Utils.react_on_rails_pro? "react-on-rails" end |