Class: ReactOnRails::TestHelper::WebpackAssetsStatusChecker

Inherits:
Object
  • Object
show all
Includes:
Utils::Required
Defined in:
lib/react_on_rails/test_helper/webpack_assets_status_checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Required

#required

Constructor Details

#initialize(generated_assets_full_path: required("generated_assets_full_path"), source_path: required("source_path"), webpack_generated_files: required("webpack_generated_files")) ⇒ WebpackAssetsStatusChecker

Returns a new instance of WebpackAssetsStatusChecker.



18
19
20
21
22
23
24
25
26
# File 'lib/react_on_rails/test_helper/webpack_assets_status_checker.rb', line 18

def initialize(
  generated_assets_full_path: required("generated_assets_full_path"),
  source_path: required("source_path"),
  webpack_generated_files: required("webpack_generated_files")
)
  @generated_assets_full_path = generated_assets_full_path
  @source_path = source_path
  @webpack_generated_files = webpack_generated_files
end

Instance Attribute Details

#generated_assets_full_pathObject (readonly)

source_path is typically configured in the webpacker.yml file for source_path or for legacy React on Rails, it’s /client, where all client files go



16
17
18
# File 'lib/react_on_rails/test_helper/webpack_assets_status_checker.rb', line 16

def generated_assets_full_path
  @generated_assets_full_path
end

#source_pathObject (readonly)

source_path is typically configured in the webpacker.yml file for source_path or for legacy React on Rails, it’s /client, where all client files go



16
17
18
# File 'lib/react_on_rails/test_helper/webpack_assets_status_checker.rb', line 16

def source_path
  @source_path
end

Instance Method Details

#stale_generated_files(files) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/react_on_rails/test_helper/webpack_assets_status_checker.rb', line 32

def stale_generated_files(files)
  manifest_needed = ReactOnRails::WebpackerUtils.using_webpacker? &&
                    !ReactOnRails::WebpackerUtils.manifest_exists?

  return ["manifest.json"] if manifest_needed

  most_recent_mtime = Utils.find_most_recent_mtime(files)
  all_compiled_assets.each_with_object([]) do |webpack_generated_file, stale_gen_list|
    if !File.exist?(webpack_generated_file) ||
       File.mtime(webpack_generated_file) < most_recent_mtime
      stale_gen_list << webpack_generated_file
    end
    stale_gen_list
  end
end

#stale_generated_webpack_filesObject



28
29
30
# File 'lib/react_on_rails/test_helper/webpack_assets_status_checker.rb', line 28

def stale_generated_webpack_files
  stale_generated_files(client_files)
end