     end
   end
 
-  # Optimize the ones coming from deps by avoiding code/erl_prim_loader
-  defp read_app(app, deps, lib_path) when is_map_key(deps, app) do
-    File.read("#{lib_path}/#{app}/ebin/#{app}.app")
-  end
-
-  defp read_app(app, _deps, _lib_path) do
+  # The app didn't come from a dep, go through the slow path (code/erl_prim_loader)
+  defp read_app(app, nil) do
     name = Atom.to_charlist(app) ++ '.app'
 
     with [_ | _] = path <- :code.where_is_file(name),
          {:ok, bin, _full_name} <- :erl_prim_loader.get_file(path),
          do: {:ok, bin}
+  end
+
+  defp read_app(app, lib_path) do
+    File.read("#{lib_path}/#{app}/ebin/#{app}.app")
   end
 
   defp consult_app_file(bin) do

    :ok
  end

  defp stream_apps(initial) do
    Stream.unfold({initial, %{}, %{}}, &stream_app/1)
  end

  # We already processed this app, skip it.
  defp stream_app({[app | apps], seen, done}) when is_map_key(seen, app) do
    stream_app({apps, seen, done})
  end

  # We haven't processed this app, emit it.
  defp stream_app({[app | apps], seen, done}) do
    {app, {apps, Map.put(seen, app, true), done}}
  end

  # We have processed all apps and all seen have been done.
  defp stream_app({[], seen, done}) when map_size(seen) == map_size(done) do
    nil
  end

  # We have processed all apps but there is work being done.
  defp stream_app({[], seen, done}) do
    receive do
      {:done, app, children} -> stream_app({children, seen, Map.put(done, app, true)})
    end
  end

  defp load_app(app, deps, lib_path, validate_compile_env?) do
    if Application.spec(app, :vsn) do
      :ok
    else
      with {:ok, bin} <- read_app(app, deps, lib_path),
           {:ok, {:application, _, properties} = application_data} <- consult_app_file(bin),
           :ok <- :application.load(application_data) do
        if compile_env = validate_compile_env? && properties[:compile_env] do


    app = config[:app]
    _ = Code.prepend_path(Mix.Project.compile_path())
    load_app(app, lib_path, validate_compile_env?)
    result
  end

