Repository navigation
Conversation
JSON if it existsJSON, if it exists, otherwise fallback to Jason
|
Hi @joshk!! We definitely want to do this but, because we cannot require v1.18 (it is too new), we need to depend on Jason anyway, so there isn't much benefit. My suggestion is to simply replace Jason by JSON in the future, but we will probably have to wait two years for doing so. Other than that, I hope you are doing well and happy holidays! |
|
@josevalim I understand we can't require using latest |
|
Optional dependencies are not installed by default, which means that if we make Jason optional, all projects that depend on |
phoenixframework/phoenix#6481 made Elixir v1.18 and OTP 27 required for Perhaps now is a good time to take this to the finish line? As noted in phoenixframework/phoenix#6815, this is one of the three Phoenix app dependencies that keep |
|
I'd say we can do it and release as 0.11, so nobody can complain about the breaking change anyway? |
|
Yes, I think we can do it here. But the most important ones are Phoenix and Ecto because they interact with your own structs and changing them changes the meaning. This one can be done at any time! |
|
The only issue is that we may break the current Phoenix installer. So I guess we need to keep jason optional indeed. Then we can do it immediately. |
| case Application.get_env(:esbuild, :json_library) do | ||
| nil -> | ||
| case Code.ensure_loaded(JSON) do | ||
| {:module, _} -> JSON | ||
| {:error, _} -> Jason | ||
| end | ||
|
|
||
| lib -> | ||
| lib | ||
| end |
There was a problem hiding this comment.
We could replicate the Phoenix implementation for now:
| case Application.get_env(:esbuild, :json_library) do | |
| nil -> | |
| case Code.ensure_loaded(JSON) do | |
| {:module, _} -> JSON | |
| {:error, _} -> Jason | |
| end | |
| lib -> | |
| lib | |
| end | |
| Application.get_env(:esbuild, :json_library, Jason) |
That way the default remains Jason, but we may it an optional dep... hmm how bad is that actually? (That's what we ended up with in Phoenix, Jason is still the default library but the dependency is optional and we don't check it's available at runtime)
There was a problem hiding this comment.
There is no need for all of that. Phoenix has to be customizable because of user structs and all not. In here, we just need any module. So we use JSON, otherwise fallback to Jason as an optional dep, or raise.
I'm unsure if this is the best approach, so consider this more of a draft than a complete solution.
The intent is to use the
JSONmodule from Elixir 1.18.x instead ofJason, but I've kept theJasondep as the fallback.I do think it would be better to have
Jasonas an optional dep and have the project which is usingEsbuildincludeJasoninstead, but this would also require changes when creating new Phoenix projects to make sureJasonis added in the deps.