Ash FrameworkAF
Ash Framework8mo ago
12 replies
Shahryar

Igniter `Proceed with changes` message when there is no changes

Hi, as you see this is my simple code for igniter, i am using update_file function, because before it i have a function that ensure_package_json_exists.
I do not know why it shows me even there is not changes Proceed with changes?
It is is my bug?
I tried to use create_or_update_file function, but if file exist and there is not anything to change, it still shows Proceed with changes?

    def update_package_json_deps(igniter, deps, options \\ []) do
      package_json_path = "assets/package.json"
      parsed_deps = parse_deps(deps)
      deps_key = if options[:dev], do: "devDependencies", else: "dependencies"

      new_igniter =
        igniter
        |> Igniter.update_file(package_json_path, fn source ->
          original_content = Rewrite.Source.get(source, :content)

          case Jason.decode(original_content) do
            {:ok, json} ->
              existing_deps = Map.get(json, deps_key, %{})

              formatted =
                Enum.reduce(parsed_deps, existing_deps, fn {name, version}, acc ->
                  Map.put(acc, name, version)
                end)
                |> then(&Map.put(json, deps_key, &1))
                |> Jason.encode!(pretty: true)

              Rewrite.Source.update(source, :content, formatted)

            {:error, _} ->
              igniter
              |> Igniter.add_issue("Failed to parse package.json. Ensure it contains valid JSON.")
          end
        end)

      new_igniter
    end


Another question is when i use create_or_update_file i should give the address of file, but sometimes the file dose not exist yet in my disk, for example i created it before this function and this file exists in my igniter var and still is not written.
what should i do for this?
thank you in advance
Screenshot_2025-05-25_at_15.55.49.png
Solution
I think the latest version of igniter may have a fix for this?
Was this page helpful?