@@ -33,6 +33,19 @@ defmodule TailwindCompiler.Native do
3333 System . get_env ( "TAILWIND_COMPILER_WASM" ) != nil
3434 end
3535
36+ @ doc """
37+ Returns the custom WASM install path from `TAILWIND_COMPILER_WASM`, or `nil`
38+ if the env var is unset or set to `"true"` (meaning use the default location).
39+ """
40+ def wasm_install_path do
41+ case System . get_env ( "TAILWIND_COMPILER_WASM" ) do
42+ nil -> nil
43+ "true" -> nil
44+ "1" -> nil
45+ path -> path
46+ end
47+ end
48+
3649 @ doc """
3750 Returns the NIF path (without extension) for `:erlang.load_nif/2`.
3851 Uses `:code.priv_dir/1` so it works at runtime (including in releases).
@@ -95,13 +108,28 @@ defmodule TailwindCompiler.Native do
95108 end
96109
97110 defp ensure_wasm do
98- path = wasm_file_path ( )
111+ # Always download to the default cache location first
112+ case wasm_path ( ) do
113+ { :ok , cached_path } ->
114+ # If a custom path was given, copy there
115+ case wasm_install_path ( ) do
116+ nil ->
117+ :ok
118+
119+ custom ->
120+ dest = if Path . extname ( custom ) == ".wasm" do
121+ custom
122+ else
123+ Path . join ( custom , "tailwind_compiler.wasm" )
124+ end
125+
126+ File . mkdir_p! ( Path . dirname ( dest ) )
127+ File . cp! ( cached_path , dest )
128+ log ( "Installed WASM binary to #{ dest } " )
129+ end
99130
100- unless File . exists? ( path ) do
101- case download_wasm ( ) do
102- :ok -> :ok
103- { :error , reason } -> log ( "Warning: could not download WASM binary: #{ inspect ( reason ) } " )
104- end
131+ { :error , reason } ->
132+ log ( "Warning: could not download WASM binary: #{ inspect ( reason ) } " )
105133 end
106134 end
107135
0 commit comments