lib/sewing_kit/webpack/manifest/development.rb in sewing_kit-0.32.0.pre.beta.pre.4 vs lib/sewing_kit/webpack/manifest/development.rb in sewing_kit-0.91.0
- old
+ new
@@ -8,32 +8,48 @@
def initialize
super
@metadata_path = nil
end
+ def asset_dependencies(entrypoint_name, _target)
+ current_metadata = metadata
+ if current_metadata.key?('development')
+ current_metadata['development']['hangTight']
+ else
+ current_metadata['entrypoints'][entrypoint_name]
+ end
+ end
+
def clear_cache!
super
@metadata_path = nil
end
+ def manifest
+ raise OnlyUseInProductionError
+ end
+
def metadata
load_metadata
end
def load_metadata
begin
- return load_metadata_from_fs(@metadata_path) if @metadata_path
+ if @metadata_path
+ result = load_metadata_from_fs(@metadata_path)
+ return normalize_metadata(result)
+ end
rescue => e
Rails.logger.warn "[sewing_kit] could not read manifest from #{@metadata_path}; falling back to node. #{e}"
@metadata_path = nil
end
result = SewingKit::Webpack::Manifest::Base.load_metadata_from_node
- raise LegacyManifestError, result unless result['entrypoints'] || result['development']
- @metadata_path = result && result['path']
- result
+ metadata = normalize_metadata(result)
+ @metadata_path = metadata && metadata['path']
+ metadata
end
def load_metadata_from_fs(path)
begin
json_str = File.read(path)
@@ -48,11 +64,26 @@
end
end
protected
+ def normalize_metadata(maybe_array_metadata)
+ if maybe_array_metadata.is_a?(Array)
+ maybe_array_metadata.last
+ else
+ maybe_array_metadata
+ end
+ end
+
def mode
'development'
+ end
+ end
+
+ class OnlyUseInProductionError < StandardError
+ def initialize
+ super "The SewingKit::Webpack::Manifest#manifest is intended "\
+ "for deploying assets to a CDN. Do not use it in development."
end
end
end
end
end