From 2413f7e0e76bef011bcb161c114facbdf1a6f21b Mon Sep 17 00:00:00 2001 From: Thanabodee Charoenpiriyakij Date: Sat, 14 Jun 2025 22:30:30 +0700 Subject: [PATCH] Revert "Load runtime config by default (#18)" This reverts commit 9645ccda00392e28ef78383fcad2d0a83c95662c. --- README.md | 4 ++-- lib/mix/tasks/bun.ex | 24 +++++++++++++++++++----- lib/mix/tasks/bun.install.ex | 8 ++++++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4343482..ee96eb6 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ def deps do end ``` -Once installed, change your config (i.e. `config/config.exs` or -`config/runtime.exs`) to pick your bun version of choice: +Once installed, change your `config/config.exs` to pick your +bun version of choice: ```elixir config :bun, version: "1.1.22" diff --git a/lib/mix/tasks/bun.ex b/lib/mix/tasks/bun.ex index 208fad6..d2f8437 100644 --- a/lib/mix/tasks/bun.ex +++ b/lib/mix/tasks/bun.ex @@ -13,19 +13,33 @@ defmodule Mix.Tasks.Bun do If bun is not installed, it is automatically downloaded. Note the arguments given to this task will be appended to any configured arguments. + + ## Options + + * `--runtime-config` - load the runtime configuration + before executing command + + Note flags to control this Mix task must be given before the + profile: + + $ mix bun --runtime-config default assets/js/app.js + """ @shortdoc "Invokes bun with the profile and args" - use Mix.Task - @requirements ["app.config"] + use Mix.Task @impl true def run(args) do - switches = [] - {_opts, remaining_args} = OptionParser.parse_head!(args, switches: switches) + switches = [runtime_config: :boolean] + {opts, remaining_args} = OptionParser.parse_head!(args, switches: switches) - Application.ensure_all_started(:bun) + if opts[:runtime_config] do + Mix.Task.run("app.config") + else + Application.ensure_all_started(:bun) + end Mix.Task.reenable("bun") install_and_run(remaining_args) diff --git a/lib/mix/tasks/bun.install.ex b/lib/mix/tasks/bun.install.ex index ea90f99..5659a27 100644 --- a/lib/mix/tasks/bun.install.ex +++ b/lib/mix/tasks/bun.install.ex @@ -14,6 +14,9 @@ defmodule Mix.Tasks.Bun.Install do ## Options + * `--runtime-config` - load the runtime configuration + before executing command + * `--if-missing` - install only if the given version does not exist """ @@ -21,14 +24,14 @@ defmodule Mix.Tasks.Bun.Install do @shortdoc "Installs bun under _build" use Mix.Task - @requirements ["app.config"] - @impl true def run(args) do valid_options = [runtime_config: :boolean, if_missing: :boolean] case OptionParser.parse_head!(args, strict: valid_options) do {opts, []} -> + if opts[:runtime_config], do: Mix.Task.run("app.config") + if opts[:if_missing] && latest_version?() do :ok else @@ -40,6 +43,7 @@ defmodule Mix.Tasks.Bun.Install do Invalid arguments to bun.install, expected one of: mix bun.install + mix bun.install --runtime-config mix bun.install --if-missing """) end