--if-missing flag for standalone CLI wrappers
If you work on any Phoenix applications that leverage the standalone versions of build tools like esbuild, Tailwind, or Dart Sass, you are likely familiar with the method for installing binaries for these tools:
mix tailwind.install
mix esbuild.install
mix sass.install
For projects that include setup scripts, you've likely even updated one of your scripts to include this step. If you have, you may have noticed you are re-downloading the binaries every time you install them.
› mix esbuild.install
06:45:32.664 [debug] Downloading esbuild from https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.14.0.tgz
Fortunately, the install scripts for the packages include an --if-missing
flag. With this flag set, it will only fetch the binary if you do not already have it (even accounting for the version!)
# first install
› mix esbuild.install --if-missing
06:45:32.664 [debug] Downloading esbuild from https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.14.0.tgz
# try again, nothing is downloaded
› mix esbuild.install --if-missing
# updated config to bump esbuild version
› mix esbuild.install --if-missing
06:53:23.520 [debug] Downloading esbuild from https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.14.1.tgz
For documentation on this and other install flags, you can check the project's "Mix Tasks" section in HexDocs. Here are the links for tailwind
, esbuild
, and dart_sass
.