fix: properly handle values vs code in configure

This commit is contained in:
Zach Daniel 2024-08-13 16:07:52 -04:00
parent ccdbfee957
commit 14552bcef9
4 changed files with 28 additions and 26 deletions

View file

@ -177,7 +177,7 @@ defmodule Igniter.Code.Keyword do
:error ->
to_append =
case zipper.node do
[{{:__block__, meta, _}, {:__block__, _, _}} | _] ->
[{{:__block__, meta, _}, _} | _] ->
value =
value
|> Sourceror.to_string()

View file

@ -50,7 +50,7 @@ defmodule Igniter.Project.Config do
value =
case value do
{:code, value} -> value
value -> Macro.escape(value)
value -> Sourceror.parse_string!(Sourceror.to_string(Macro.escape(value)))
end
updater = opts[:updater] || fn zipper -> {:ok, Common.replace_code(zipper, value)} end

View file

@ -27,7 +27,7 @@
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
"owl": {:hex, :owl, "0.11.0", "2cd46185d330aa2400f1c8c3cddf8d2ff6320baeff23321d1810e58127082cae", [:mix], [{:ucwidth, "~> 0.2", [hex: :ucwidth, repo: "hexpm", optional: true]}], "hexpm", "73f5783f0e963cc04a061be717a0dbb3e49ae0c4bfd55fb4b78ece8d33a65efe"},
"rewrite": {:hex, :rewrite, "0.10.5", "6afadeae0b9d843b27ac6225e88e165884875e0aed333ef4ad3bf36f9c101bed", [:mix], [{:glob_ex, "~> 0.1", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.0", [hex: :sourceror, repo: "hexpm", optional: false]}], "hexpm", "51cc347a4269ad3a1e7a2c4122dbac9198302b082f5615964358b4635ebf3d4f"},
"sourceror": {:hex, :sourceror, "1.5.0", "3e65d5fbb1a8e2864ad6411262c8018fee73474f5789dda12285c82999253d5d", [:mix], [], "hexpm", "4a32b5d189d8453f73278c15712f8731b89e9211e50726b798214b303b51bfc7"},
"sourceror": {:hex, :sourceror, "1.6.0", "9907884e1449a4bd7dbaabe95088ed4d9a09c3c791fb0103964e6316bc9448a7", [:mix], [], "hexpm", "e90aef8c82dacf32c89c8ef83d1416fc343cd3e5556773eeffd2c1e3f991f699"},
"spitfire": {:hex, :spitfire, "0.1.3", "7ea0f544005dfbe48e615ed90250c9a271bfe126914012023fd5e4b6b82b7ec7", [:mix], [], "hexpm", "d53b5107bcff526a05c5bb54c95e77b36834550affd5830c9f58760e8c543657"},
"statistex": {:hex, :statistex, "1.0.0", "f3dc93f3c0c6c92e5f291704cf62b99b553253d7969e9a5fa713e5481cd858a5", [:mix], [], "hexpm", "ff9d8bee7035028ab4742ff52fc80a2aa35cece833cf5319009b52f1b5a86c27"},
"ucwidth": {:hex, :ucwidth, "0.2.0", "1f0a440f541d895dff142275b96355f7e91e15bca525d4a0cc788ea51f0e3441", [:mix], [], "hexpm", "c1efd1798b8eeb11fb2bec3cafa3dd9c0c3647bee020543f0340b996177355bf"},

View file

@ -219,7 +219,7 @@ defmodule Igniter.Project.ConfigTest do
test "it merges with 2 arg version of existing config with the config set to [] and the path is one level deeper than existing" do
%{rewrite: rewrite} =
Igniter.new()
|> Igniter.create_new_elixir_file(
|> Igniter.create_new_file(
"config/fake.exs",
"""
import Config
@ -244,11 +244,7 @@ defmodule Igniter.Project.ConfigTest do
config :level1,
version: "1.0.0",
level2: [
level3: [
args: 1
]
]
level2: [level3: 1]
"""
end
@ -352,15 +348,22 @@ defmodule Igniter.Project.ConfigTest do
@tag :regression
test "arbitrary data structures can be used as values" do
:erlang.system_flag(:backtrace_depth, 1000)
%{rewrite: rewrite} =
Igniter.new()
|> Igniter.create_new_elixir_file("config/fake.exs", """
|> Igniter.create_new_file("config/fake.exs", """
import Config
config :level1, :level2, level3: [{"hello", "world"}]
""")
|> Igniter.Project.Config.configure("fake.exs", :level1, [:level2, :level3], [
{"hello1", "world1"}
])
|> Igniter.Project.Config.configure(
"fake.exs",
:level1,
[:level2, :level3],
[
{"hello1", "world1"}
]
)
config_file = Rewrite.source!(rewrite, "config/fake.exs")
@ -374,7 +377,7 @@ defmodule Igniter.Project.ConfigTest do
test "quoted code can be used as values" do
%{rewrite: rewrite} =
Igniter.new()
|> Igniter.create_new_elixir_file(
|> Igniter.create_new_file(
"config/fake.exs",
"""
import Config
@ -388,16 +391,19 @@ defmodule Igniter.Project.ConfigTest do
"fake.exs",
:tailwind,
[:default, :args],
quote(
do:
~w(--config=tailwind.config.js --input=css/app.css --output=../output/assets/app.css)
)
{:code,
Sourceror.parse_string!("""
~w(--config=tailwind.config.js --input=css/app.css --output=../output/assets/app.css)
""")}
)
|> Igniter.Project.Config.configure(
"fake.exs",
:tailwind,
[:default, :cd],
quote(do: Path.expand("../assets", __DIR__))
{:code,
Sourceror.parse_string!("""
Path.expand("../assets", __DIR__)
""")}
)
config_file = Rewrite.source!(rewrite, "config/fake.exs")
@ -409,13 +415,9 @@ defmodule Igniter.Project.ConfigTest do
config :tailwind,
version: "1.0.0",
default: [
args: ~w(
--config=tailwind.config.js
--input=css/app.css
--output=../output/assets/app.css
),
cd: Path.expand("../assets", __DIR__)
]
args: ~w(--config=tailwind.config.js --input=css/app.css --output=../output/assets/app.css),
cd: Path.expand("../assets", __DIR__)
]
"""
end