diff --git a/spec/lucky/asset_builder/base_spec.cr b/spec/lucky/asset_builder/base_spec.cr deleted file mode 100644 index d79a4e6a0..000000000 --- a/spec/lucky/asset_builder/base_spec.cr +++ /dev/null @@ -1,52 +0,0 @@ -require "../../spec_helper" -require "../../../src/lucky/asset_builder/base" - -class TestAssetBuilder < Lucky::AssetBuilder::Base - @manifest_path : String - @manifest_content : Hash(String, String) - - def initialize(@manifest_path : String, @manifest_content : Hash(String, String)) - end - - def manifest_path : String - @manifest_path - end - - def parse_manifest(manifest_content : String) : Hash(String, String) - @manifest_content - end -end - -describe Lucky::AssetBuilder::Base do - describe "#normalize_key" do - it "removes leading slash" do - builder = TestAssetBuilder.new("test.json", {} of String => String) - builder.normalize_key("/images/logo.png").should eq("images/logo.png") - end - - it "removes assets/ prefix" do - builder = TestAssetBuilder.new("test.json", {} of String => String) - builder.normalize_key("assets/images/logo.png").should eq("images/logo.png") - end - - it "removes both leading slash and assets/ prefix" do - builder = TestAssetBuilder.new("test.json", {} of String => String) - builder.normalize_key("/assets/images/logo.png").should eq("images/logo.png") - end - - it "leaves other paths unchanged" do - builder = TestAssetBuilder.new("test.json", {} of String => String) - builder.normalize_key("images/logo.png").should eq("images/logo.png") - end - end - - describe "#load_manifest" do - it "raises error when manifest doesn't exist" do - builder = TestAssetBuilder.new("/non/existent/path.json", {} of String => String) - - expect_raises(Lucky::AssetBuilder::MissingManifestError) do - builder.load_manifest - end - end - end -end diff --git a/spec/lucky/asset_builder/mix_spec.cr b/spec/lucky/asset_builder/mix_spec.cr deleted file mode 100644 index a74536ce4..000000000 --- a/spec/lucky/asset_builder/mix_spec.cr +++ /dev/null @@ -1,48 +0,0 @@ -require "../../spec_helper" -require "../../../src/lucky/asset_builder/mix" - -describe Lucky::AssetBuilder::Mix do - describe "#manifest_path" do - it "defaults to ./public/mix-manifest.json" do - builder = Lucky::AssetBuilder::Mix.new - builder.manifest_path.should eq("./public/mix-manifest.json") - end - - it "accepts custom path" do - builder = Lucky::AssetBuilder::Mix.new("/custom/path.json") - builder.manifest_path.should eq("/custom/path.json") - end - end - - describe "#parse_manifest" do - it "parses Mix manifest format correctly" do - manifest_json = <<-JSON - { - "/js/app.js": "/js/app.12345.js", - "/css/app.css": "/css/app.67890.css", - "/images/logo.png": "/images/logo.abcde.png" - } - JSON - - builder = Lucky::AssetBuilder::Mix.new - result = builder.parse_manifest(manifest_json) - - result["js/app.js"].should eq("/js/app.12345.js") - result["css/app.css"].should eq("/css/app.67890.css") - result["images/logo.png"].should eq("/images/logo.abcde.png") - end - - it "normalizes keys by removing leading slashes" do - manifest_json = <<-JSON - { - "/assets/js/app.js": "/assets/js/app.12345.js" - } - JSON - - builder = Lucky::AssetBuilder::Mix.new - result = builder.parse_manifest(manifest_json) - - result["js/app.js"].should eq("/assets/js/app.12345.js") - end - end -end diff --git a/spec/lucky/asset_builder/server_integration_spec.cr b/spec/lucky/asset_builder/server_integration_spec.cr deleted file mode 100644 index 616e8740e..000000000 --- a/spec/lucky/asset_builder/server_integration_spec.cr +++ /dev/null @@ -1,23 +0,0 @@ -require "../../spec_helper" -require "../../../src/lucky/server" -require "../../../src/lucky/asset_builder/mix" -require "../../../src/lucky/asset_builder/vite" - -describe "Lucky::Server asset build system integration" do - it "defaults to Mix builder" do - Lucky::Server.settings.asset_build_system.should be_a(Lucky::AssetBuilder::Mix) - end - - it "can be configured to use Vite" do - Lucky::Server.temp_config(asset_build_system: Lucky::AssetBuilder::Vite.new) do - Lucky::Server.settings.asset_build_system.should be_a(Lucky::AssetBuilder::Vite) - end - end - - it "can use custom manifest paths" do - custom_builder = Lucky::AssetBuilder::Mix.new("/custom/manifest.json") - Lucky::Server.temp_config(asset_build_system: custom_builder) do - Lucky::Server.settings.asset_build_system.manifest_path.should eq("/custom/manifest.json") - end - end -end diff --git a/spec/lucky/asset_builder/vite_spec.cr b/spec/lucky/asset_builder/vite_spec.cr deleted file mode 100644 index 501212d2f..000000000 --- a/spec/lucky/asset_builder/vite_spec.cr +++ /dev/null @@ -1,102 +0,0 @@ -require "../../spec_helper" -require "../../../src/lucky/asset_builder/vite" - -describe Lucky::AssetBuilder::Vite do - describe "#manifest_path" do - it "defaults to ./public/.vite/manifest.json" do - builder = Lucky::AssetBuilder::Vite.new - builder.manifest_path.should eq("./public/.vite/manifest.json") - end - - it "accepts custom path" do - builder = Lucky::AssetBuilder::Vite.new("/custom/vite.json") - builder.manifest_path.should eq("/custom/vite.json") - end - end - - describe "#parse_manifest" do - it "parses Vite manifest format correctly" do - manifest_json = <<-JSON - { - "src/js/app.js": { - "file": "assets/app.12345.js", - "src": "src/js/app.js", - "isEntry": true - }, - "src/css/app.scss": { - "file": "assets/app.67890.css", - "src": "src/css/app.scss", - "isEntry": true - }, - "_shared-B7PI925R.js": { - "file": "assets/shared-B7PI925R.js", - "name": "shared" - }, - "src/images/logo.png": { - "file": "assets/logo.abcde.png", - "src": "src/images/logo.png" - } - } - JSON - - builder = Lucky::AssetBuilder::Vite.new - result = builder.parse_manifest(manifest_json) - - result["js/app.js"].should eq("/assets/app.12345.js") - result["css/app.scss"].should eq("/assets/app.67890.css") - result["images/logo.png"].should eq("/assets/logo.abcde.png") - # Shared chunks (starting with _) should be ignored - result.has_key?("_shared-B7PI925R.js").should be_false - end - - it "ignores entries without src property" do - manifest_json = <<-JSON - { - "_chunk-ABC123.js": { - "file": "assets/chunk-ABC123.js" - }, - "style.css": { - "file": "assets/style.12345.css" - } - } - JSON - - builder = Lucky::AssetBuilder::Vite.new - result = builder.parse_manifest(manifest_json) - - result.empty?.should be_true - end - - it "strips src/ prefix from keys" do - manifest_json = <<-JSON - { - "src/assets/images/logo.png": { - "file": "images/logo.12345.png", - "src": "src/assets/images/logo.png" - } - } - JSON - - builder = Lucky::AssetBuilder::Vite.new - result = builder.parse_manifest(manifest_json) - - result["images/logo.png"].should eq("/images/logo.12345.png") - end - - it "handles keys without src/ prefix" do - manifest_json = <<-JSON - { - "images/direct.png": { - "file": "images/direct.12345.png", - "src": "images/direct.png" - } - } - JSON - - builder = Lucky::AssetBuilder::Vite.new - result = builder.parse_manifest(manifest_json) - - result["images/direct.png"].should eq("/images/direct.12345.png") - end - end -end diff --git a/src/lucky/asset_builder/base.cr b/src/lucky/asset_builder/base.cr deleted file mode 100644 index b0266bba3..000000000 --- a/src/lucky/asset_builder/base.cr +++ /dev/null @@ -1,25 +0,0 @@ -module Lucky::AssetBuilder - abstract class Base - abstract def manifest_path : String - abstract def parse_manifest(manifest_content : String) : Hash(String, String) - - def load_manifest : Hash(String, String) - unless File.exists?(manifest_path) - raise MissingManifestError.new(manifest_path) - end - - manifest_content = File.read(manifest_path) - parse_manifest(manifest_content) - end - - def normalize_key(key : String) : String - key.gsub(/^\//, "").gsub(/^assets\//, "") - end - end - - class MissingManifestError < Exception - def initialize(path : String) - super("Manifest at #{path} does not exist. Make sure you have compiled your assets.") - end - end -end diff --git a/src/lucky/asset_builder/mix.cr b/src/lucky/asset_builder/mix.cr deleted file mode 100644 index 246cdb09f..000000000 --- a/src/lucky/asset_builder/mix.cr +++ /dev/null @@ -1,27 +0,0 @@ -require "json" -require "./base" - -module Lucky::AssetBuilder - class Mix < Base - @manifest_path : String - - def initialize(@manifest_path : String = "./public/mix-manifest.json") - end - - def manifest_path : String - @manifest_path - end - - def parse_manifest(manifest_content : String) : Hash(String, String) - manifest = JSON.parse(manifest_content) - result = {} of String => String - - manifest.as_h.each do |key, value| - normalized_key = normalize_key(key) - result[normalized_key] = value.as_s - end - - result - end - end -end diff --git a/src/lucky/asset_builder/vite.cr b/src/lucky/asset_builder/vite.cr deleted file mode 100644 index 9eb0726d5..000000000 --- a/src/lucky/asset_builder/vite.cr +++ /dev/null @@ -1,56 +0,0 @@ -require "json" -require "./base" - -module Lucky::AssetBuilder - class Vite < Base - @manifest_path : String - - def initialize(@manifest_path : String = "./public/.vite/manifest.json") - end - - def manifest_path : String - @manifest_path - end - - def parse_manifest(manifest_content : String) : Hash(String, String) - manifest = JSON.parse(manifest_content) - result = {} of String => String - - # Check if this is a dev manifest (has "url" and "inputs" properties) - if manifest["url"]? && manifest["inputs"]? - # This is a dev manifest from vite-plugin-dev-manifest - base_url = manifest["url"].as_s - inputs = manifest["inputs"].as_h - - inputs.each do |_, value| - # In dev mode, we store the full URL to the source file - path = value.as_s - # Remove src/ prefix to match Lucky's convention - normalized_key = path.starts_with?("src/") ? path[4..] : path - normalized_key = normalize_key(normalized_key) - result[normalized_key] = base_url + path - end - else - # This is a production manifest - manifest.as_h.each do |key, value| - # Skip chunks that start with underscore (these are shared chunks) - next if key.starts_with?("_") - - # Only process entries that have a src property (actual source files) - if value["src"]? - # Use the src path as the key, stripping "src/" prefix - src_path = value["src"].as_s - normalized_key = src_path.starts_with?("src/") ? src_path[4..] : src_path - normalized_key = normalize_key(normalized_key) - - # Get the output file path - file_path = value["file"].as_s - result[normalized_key] = "/#{file_path}" - end - end - end - - result - end - end -end diff --git a/src/lucky/server.cr b/src/lucky/server.cr index f097e2f5b..34c380337 100644 --- a/src/lucky/server.cr +++ b/src/lucky/server.cr @@ -1,7 +1,3 @@ -require "./asset_builder/base" -require "./asset_builder/mix" -require "./asset_builder/vite" - # Class for configuring server settings # # The settings created here can be customized in each Lucky app by modifying them in your config/server.cr @@ -11,7 +7,6 @@ class Lucky::Server setting host : String setting port : Int32 setting asset_host : String = "" - setting asset_build_system : Lucky::AssetBuilder::Base = Lucky::AssetBuilder::Mix.new setting gzip_enabled : Bool = false setting gzip_content_types : Array(String) = %w( application/json