Class: Webpacker::Remote::Manifest

Inherits:
Manifest
  • Object
show all
Defined in:
lib/webpacker/remote/manifest.rb

Instance Method Summary collapse

Instance Method Details

#loadObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/webpacker/remote/manifest.rb', line 6

def load
  # load from network, upstream version operates pathnames:
  # if config.manifest_path.exist?
  #   JSON.parse config.manifest_path.read
  # else
  #   {}
  # end
  if public_manifest_content_uri
    public_manifest_content
  else
    {}
  end
end

#lookup(name, pack_type = {}) ⇒ Object



50
51
52
53
54
# File 'lib/webpacker/remote/manifest.rb', line 50

def lookup(name, pack_type = {})
  return unless (path = super)

  File.join(config.root_path.to_s, path)
end

#lookup_pack_with_chunks(name, pack_type = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/webpacker/remote/manifest.rb', line 27

def lookup_pack_with_chunks(name, pack_type = {})
  # `super` method copy
  manifest_pack_type = manifest_type(pack_type[:type])
  manifest_pack_name = manifest_name(name, manifest_pack_type)
  assets = find('entrypoints')[manifest_pack_name]
  # patched super behavior:
  # - keys in webpack-assets-manifest-3: entrypoints.main.{js/css}
  # - keys in webpack-assets-manifest-5: entrypoints.main.assets.{js/css}
  # `shakapacker` just has this inline:
  # find("entrypoints")[manifest_pack_name]["assets"][manifest_pack_type]
  assets = assets['assets'] if assets.key?('assets')
  paths = assets[manifest_pack_type]
  # end of `super` method copy

  # remote-webpacker addition: full URIs
  # railsy webpacker returns relative paths from its manifest
  # because `action_view` resolves them using `config.action_controller.asset_host`
  # but remote-webpacker tuned to have bundles from several locations
  paths.map { |p| File.join(config.root_path.to_s, p) }
rescue NoMethodError
  nil
end

#manifest_dataObject

additional api to be able to put additional data into the manifest because ‘find` and `data` are private



58
59
60
# File 'lib/webpacker/remote/manifest.rb', line 58

def manifest_data
  data
end

#refreshObject

be more failsafe than railsy webpacker since we do networking



21
22
23
24
25
# File 'lib/webpacker/remote/manifest.rb', line 21

def refresh
  @data = load
rescue Webpacker::Remote::Error
  @data
end