Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for new webpack asset manifest format #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/minipack/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ def initialize(path, cache: false)
def lookup_pack_with_chunks!(name, type: nil)
manifest_pack_type = manifest_type(name, type)
manifest_pack_name = manifest_name(name, manifest_pack_type)
paths = data['entrypoints']&.dig(manifest_pack_name, manifest_pack_type) || handle_missing_entry(name)
paths = data['entrypoints']&.dig(manifest_pack_name, manifest_pack_type) ||
data['entrypoints']&.dig(manifest_pack_name, 'assets', manifest_pack_type) ||
handle_missing_entry(name)

entries = data['entrypoints']&.dig(manifest_pack_name, manifest_pack_type).map do |source|
entries = paths.map do |source|
entry_from_source(source) || handle_missing_entry(name)
end

Expand Down Expand Up @@ -107,7 +109,7 @@ def load_data
JSON.parse(data)
end

# The `manifest_name` method strips of the file extension of the name, because in the
# The `manifest_name` method strips off the file extension of the name, because in the
# manifest hash the entrypoints are defined by their pack name without the extension.
# When the user provides a name with a file extension, we want to try to strip it off.
def manifest_name(name, pack_type)
Expand Down
8 changes: 5 additions & 3 deletions spec/minipack/manifest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
describe '#lookup_pack_with_chunks!' do
subject { described_class.new(path, cache: false).lookup_pack_with_chunks!(name, type: type) }

let(:path) { File.expand_path('../support/files/manifest.json', __dir__) }
let(:type) { nil }

context 'with name with ext' do
let(:path) { File.expand_path('../support/files/manifest.json', __dir__) }
let(:name) { 'application.js' }
let(:type) { nil }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this seems like a default, you can probably leave it up in the describe scope and override it as needed (like on line 37)


it do
expected = Minipack::Manifest::ChunkGroup.new(
Expand All @@ -33,6 +32,7 @@
end

context 'with name without ext' do
let(:path) { File.expand_path('../support/files/manifest_with_prefetch.json', __dir__) }
let(:name) { 'application' }
let(:type) { 'js' }

Expand All @@ -47,7 +47,9 @@
end

context 'when non exist name is given' do
let(:path) { File.expand_path('../support/files/manifest.json', __dir__) }
let(:name) { 'foo.js' }
let(:type) { nil }

it { expect { subject }.to raise_error Minipack::Manifest::MissingEntryError }
end
Expand Down
49 changes: 49 additions & 0 deletions spec/support/files/manifest_with_prefetch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"test.js": "/assets/web/pack/test-9a55da116417a39a9d1b.js",
"dummy_thumbnail.png": "/assets/web/pack/dummy_thumbnail-757606db2b4802bb4147a968315df2df.png",
"icon/avatar.png": "/assets/web/pack/icon/avatar-50b0773f02d0149e39468afa4b6567af.png",
"item_group_editor.css": "/packs/item_group_editor-5d7c7164b8a0a9d675fad9ab410eaa8d.css",
"item_group_editor.js": "/packs/item_group_editor-857e5bfa272e71b6384046f68ba29d44.js",
"item_group_editor.js.map": "/packs/item_group_editor.js.map",
"union-ok.png": "/packs/union-ok-857e5bfa272e71b6384046f68ba29d44.png",
"union-ok@2x.png": "/packs/union-ok@2x-5d7c7164b8a0a9d675fad9ab410eaa8d.png",
"vendors~application~bootstrap.js": "/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js",
"vendors~application.js": "/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js",
"application.js": "/packs/application-k344a6d59eef8632c9d1.js",
"application.css": "/packs/application-k344a6d59eef8632c9d1.chunk.css",
"hello_stimulus.css": "/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css",
"1.css": "/packs/1-c20632e7baf2c81200d3.chunk.css",
"entrypoints": {
"application": {
"assets": {
"js": [
"/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js",
"/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js",
"/packs/application-k344a6d59eef8632c9d1.js"
],
"css": [
"/packs/1-c20632e7baf2c81200d3.chunk.css",
"/packs/application-k344a6d59eef8632c9d1.chunk.css"
]
},
"prefetch": {
"js": [
"prefetch.js"
]
},
"preload": {
"js": [
"preload.js"
]
}
},
"hello_stimulus": {
"assets": {
"css": [
"/packs/1-c20632e7baf2c81200d3.chunk.css",
"/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css"
]
}
}
}
}