lib/sewing_kit/webpack/manifest.rb in sewing_kit-0.6.2 vs lib/sewing_kit/webpack/manifest.rb in sewing_kit-0.7.0
- old
+ new
@@ -9,46 +9,57 @@
def initialize(message, orig)
super "#{message} (original error #{orig})"
end
end
+ class LegacyManifestError < StandardError
+ def initialize(manifest)
+ super "manifest must contain 'entrypoints' key (found: #{manifest})"
+ end
+ end
+
class << self
# :nodoc:
- def asset_paths(source)
- paths = manifest[source]
- paths || {}
+ def asset_paths(entrypointName)
+ metadata['entrypoints'][entrypointName]
end
def clear_cache!
- @manifest = nil
- @manifest_expiry_time = nil
+ @metadata = nil
+ @metadata_expiry_time = nil
end
def manifest
+ metadata['assets']
+ end
+
+ private
+
+ def metadata
if ::Rails.env.production?
# Cache at class level, as JSON loading/parsing can be expensive.
- @manifest ||= load_manifest
+ @metadata ||= load_metadata
else
# In development, the manifest may change.
# A short cache lifetime avoids time consuming node callouts.
- if self.instance_variable_defined?('@manifest_expiry_time') && @manifest_expiry_time && @manifest_expiry_time >= Time.now
- @manifest
+ if self.instance_variable_defined?('@metadata_expiry_time') && @metadata_expiry_time && @metadata_expiry_time >= Time.now
+ @metadata
else
- @manifest = load_manifest
- @manifest_expiry_time = Time.now + 4
+ @metadata = load_metadata
+ @metadata_expiry_time = Time.now + 4
end
end
- @manifest
+ raise LegacyManifestError.new(@metadata) if !@metadata['entrypoints']
+
+ @metadata
end
- private
-
def manifest_bundled?
!manifest["errors"].any? { |error| error.include? "Module build failed" }
end
- def load_manifest
+ def load_metadata
JSON.parse(`node_modules/.bin/sewing-kit manifest --mode #{mode}`)
rescue => e
raise ManifestLoadError.new("Could not load compiled manifest - have you run `rake sewing_kit:build`?", e)
end