Current section

26 Versions

Jump to

Compare versions

6 files changed
+2 additions
-138 deletions
  @@ -38,7 +38,6 @@ Website: https://hologram.page
38 38
39 39 * [@absowoot](https://github.com/absowoot)
40 40 * Oban, [@oban-bg](https://github.com/oban-bg)
41 - * Lucas Sifoni, [@Lucassifoni](https://github.com/Lucassifoni)
42 41 * Robert Urbańczyk, [@robertu](https://github.com/robertu)
43 42 * Moss Piglet, [@moss-piglet](https://github.com/moss-piglet)
  @@ -1,6 +1,5 @@
1 1 {
2 2 "dependencies": {
3 - "@biomejs/biome": "^2",
4 3 "esbuild": "^0.28",
5 4 "lodash": "^4",
6 5 "snabbdom": "^3",
  @@ -9,7 +9,7 @@
9 9 {<<"UI">>,<<"https://hologram.page/ui">>},
10 10 {<<"Website">>,<<"https://hologram.page">>}]}.
11 11 {<<"name">>,<<"hologram">>}.
12 - {<<"version">>,<<"0.9.0">>}.
12 + {<<"version">>,<<"0.9.1">>}.
13 13 {<<"description">>,
14 14 <<"Full stack isomorphic Elixir web framework that can be used on top of Phoenix.">>}.
15 15 {<<"elixir">>,<<"~> 1.0">>}.
  @@ -14,11 +14,6 @@ defmodule Hologram.Compiler do
14 14 alias Hologram.Compiler.IR
15 15 alias Hologram.Reflection
16 16
17 - # Windows cmd.exe has a command line length limit of 8191 characters.
18 - # Use half of that to account for unpredictable quoting overhead added by Erlang's System.cmd.
19 - # Batches run in parallel so there's no performance penalty from smaller batches.
20 - @max_cmd_line_length 4_096
21 -
22 17 @doc """
23 18 Aggregates JS imports from all Elixir modules referenced by the given MFAs.
24 19 Returns a map with:
  @@ -421,65 +416,6 @@ defmodule Hologram.Compiler do
421 416 }
422 417 end
423 418
424 - @doc """
425 - Formats the given JavaScript files with Biome.
426 -
427 - Benchmark: https://github.com/bartblast/hologram/blob/master/benchmarks/compiler/format_files_2/README.md
428 - """
429 - @spec format_files(list(T.file_path()), T.opts()) :: non_neg_integer
430 - # sobelow_skip ["CI.System"]
431 - def format_files(file_paths, opts) do
432 - base_args = [
433 - "format",
434 - "--write",
435 - # Effectively disable the size check (1 GB)
436 - "--files-max-size=#{1024 * 1024 * 1024}"
437 - ]
438 -
439 - # Run from the project root, not from inside assets_dir, so version managers like
440 - # asdf/mise resolve the Node.js version from the consuming project's config rather
441 - # than any .tool-versions inside a git-checked-out dependency.
442 - cmd_opts = [parallelism: true, stderr_to_stdout: true]
443 -
444 - args_length =
445 - base_args
446 - |> Enum.map(&(String.length(&1) + 1))
447 - |> Enum.sum()
448 -
449 - base_length = String.length(opts[:formatter_bin_path]) + args_length
450 -
451 - batches = batch_file_paths(file_paths, base_length)
452 -
453 - results =
454 - batches
455 - |> Enum.map(fn batch ->
456 - Task.async(fn ->
457 - cmd_args = base_args ++ batch
458 -
459 - {exit_msg, exit_status} =
460 - SystemUtils.cmd_cross_platform(opts[:formatter_bin_path], cmd_args, cmd_opts)
461 -
462 - {exit_msg, exit_status, batch}
463 - end)
464 - end)
465 - |> Task.await_many(:infinity)
466 -
467 - Enum.each(results, fn {exit_msg, exit_status, batch} ->
468 - if exit_status != 0 do
469 - raise RuntimeError,
470 - message: """
471 - Biome formatter failed (probably there were JavaScript syntax errors).
472 - Formatter binary: #{opts[:formatter_bin_path]}
473 - Exit status: #{exit_status}
474 - Output: #{exit_msg}
475 - Files: #{Enum.join(batch, ", ")}
476 - """
477 - end
478 - end)
479 -
480 - length(batches)
481 - end
482 -
483 419 @doc """
484 420 Extracts JavaScript source code for the given ported Erlang function.
485 421
  @@ -690,26 +626,6 @@ defmodule Hologram.Compiler do
690 626 end)
691 627 end
692 628
693 - defp batch_file_paths(file_paths, base_length) do
694 - Enum.chunk_while(
695 - file_paths,
696 - {[], base_length},
697 - fn path, {batch, length} ->
698 - new_length = length + String.length(path) + 1
699 -
700 - if batch != [] and new_length > @max_cmd_line_length do
701 - {:cont, Enum.reverse(batch), {[path], base_length + String.length(path) + 1}}
702 - else
703 - {:cont, {[path | batch], new_length}}
704 - end
705 - end,
706 - fn
707 - {[], _length} -> {:cont, []}
708 - {batch, _length} -> {:cont, Enum.reverse(batch), []}
709 - end
710 - )
711 - end
712 -
713 629 defp create_entry_file(js, entry_name, tmp_dir) do
714 630 entry_file_path = Path.join(tmp_dir, "#{entry_name}.entry.js")
715 631 File.write!(entry_file_path, js)
  @@ -37,20 +37,6 @@ defmodule Mix.Tasks.Compile.Hologram do
37 37 end
38 38 end
39 39
40 - defp bin_available?(cmd) do
41 - args = ["--version"]
42 - opts = [parallelism: true, stderr_to_stdout: true]
43 -
44 - try do
45 - case SystemUtils.cmd_cross_platform(cmd, args, opts) do
46 - {_output, 0} -> true
47 - _cmd_result -> false
48 - end
49 - rescue
50 - _error -> false
51 - end
52 - end
53 -
54 40 defp build_default_opts do
55 41 root_dir = Reflection.root_dir()
56 42 assets_dir = Path.join([root_dir, "deps", "hologram", "assets"])
  @@ -61,8 +47,6 @@ defmodule Mix.Tasks.Compile.Hologram do
61 47 assets_dir: assets_dir,
62 48 build_dir: build_dir,
63 49 esbuild_bin_path: Path.join([node_modules_path, ".bin", "esbuild"]),
64 - # Biome is almost x20 faster than Prettier in Hologram benchmarks
65 - formatter_bin_path: Path.join([node_modules_path, ".bin", "biome"]),
66 50 js_dir: Path.join(assets_dir, "js"),
67 51 node_modules_path: node_modules_path,
68 52 static_dir: Path.join([root_dir, "priv", "static", "hologram"]),
  @@ -85,8 +69,6 @@ defmodule Mix.Tasks.Compile.Hologram do
85 69
86 70 Compiler.maybe_install_js_deps(assets_dir, build_dir)
87 71
88 - opts = maybe_adjust_formatter_bin_path(opts)
89 -
90 72 {old_module_digest_plt, module_digest_plt_dump_path} =
91 73 Compiler.maybe_load_module_digest_plt(build_dir, supervisor: sup)
92 74
  @@ -139,13 +121,6 @@ defmodule Mix.Tasks.Compile.Hologram do
139 121 {entry_name, entry_file_path, "page"}
140 122 end)
141 123
142 - page_entry_file_paths =
143 - Enum.map(page_entry_files_info, fn {_entry_name, entry_file_path, _bundle_name} ->
144 - entry_file_path
145 - end)
146 -
147 - Compiler.format_files([runtime_entry_file_path | page_entry_file_paths], opts)
148 -
149 124 entry_files_info = [{"runtime", runtime_entry_file_path, "runtime"} | page_entry_files_info]
150 125
151 126 old_build_static_artifacts =
  @@ -195,31 +170,6 @@ defmodule Mix.Tasks.Compile.Hologram do
195 170 Enum.any?(@ls_build_dirs, fn dir -> dir in path_components end)
196 171 end
197 172
198 - defp maybe_adjust_formatter_bin_path(opts) do
199 - system_formatter_cmd = "biome"
200 -
201 - formatter_bin_path =
202 - Enum.find([opts[:formatter_bin_path], system_formatter_cmd], &bin_available?/1)
203 -
204 - case formatter_bin_path do
205 - nil ->
206 - raise RuntimeError,
207 - message: """
208 - Biome formatter failed to run.
209 -
210 - Neither the bundled biome binary nor a system-installed biome could be executed.
211 - This can happen on systems where dynamically linked binaries are not supported,
212 - such as NixOS or musl-based distributions (e.g., Alpine Linux).
213 -
214 - To fix this, install biome and ensure it's available in your PATH.
215 - For installation options, see: https://biomejs.dev/guides/manual-installation/
216 - """
217 -
218 - path ->
219 - Keyword.put(opts, :formatter_bin_path, path)
220 - end
221 - end
222 -
223 173 defp maybe_remove_file(lock_path) do
224 174 if File.exists?(lock_path) do
225 175 File.rm(lock_path)
Loading more files…