perf(elixir): evaluate version lazily (#2172)
This commit is contained in:
parent
2532251a13
commit
bb160d9207
|
@ -808,12 +808,12 @@ The module will be shown if any of the following conditions are met:
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Option | Default | Description |
|
| Option | Default | Description |
|
||||||
| ---------- | ------------------------------------------------------- | --------------------------------------------------------------- |
|
| ---------- | --------------------------------------------------------- | --------------------------------------------------------------- |
|
||||||
| `symbol` | `"💧 "` | The symbol used before displaying the version of Elixir/Erlang. |
|
| `symbol` | `"💧 "` | The symbol used before displaying the version of Elixir/Erlang. |
|
||||||
| `style` | `"bold purple"` | The style for the module. |
|
| `style` | `"bold purple"` | The style for the module. |
|
||||||
| `format` | `'via [$symbol$version \(OTP $otp_version\)]($style) '` | The format for the module elixir. |
|
| `format` | `'via [$symbol($version \(OTP $otp_version\) )]($style)'` | The format for the module elixir. |
|
||||||
| `disabled` | `false` | Disables the `elixir` module. |
|
| `disabled` | `false` | Disables the `elixir` module. |
|
||||||
|
|
||||||
### Variables
|
### Variables
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub struct ElixirConfig<'a> {
|
||||||
impl<'a> RootModuleConfig<'a> for ElixirConfig<'a> {
|
impl<'a> RootModuleConfig<'a> for ElixirConfig<'a> {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
ElixirConfig {
|
ElixirConfig {
|
||||||
format: "via [$symbol$version \\(OTP $otp_version\\)]($style) ",
|
format: "via [$symbol($version \\(OTP $otp_version\\) )]($style)",
|
||||||
symbol: "💧 ",
|
symbol: "💧 ",
|
||||||
style: "bold purple",
|
style: "bold purple",
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
|
|
@ -4,7 +4,9 @@ use crate::configs::elixir::ElixirConfig;
|
||||||
use crate::formatter::StringFormatter;
|
use crate::formatter::StringFormatter;
|
||||||
use crate::utils;
|
use crate::utils;
|
||||||
|
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
use std::ops::Deref;
|
||||||
const ELIXIR_VERSION_PATTERN: &str = "\
|
const ELIXIR_VERSION_PATTERN: &str = "\
|
||||||
Erlang/OTP (?P<otp>\\d+)[^\\n]+
|
Erlang/OTP (?P<otp>\\d+)[^\\n]+
|
||||||
|
|
||||||
|
@ -21,7 +23,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (otp_version, elixir_version) = get_elixir_version()?;
|
let versions = Lazy::new(get_elixir_version);
|
||||||
|
|
||||||
let mut module = context.new_module("elixir");
|
let mut module = context.new_module("elixir");
|
||||||
let config = ElixirConfig::try_load(module.config);
|
let config = ElixirConfig::try_load(module.config);
|
||||||
|
@ -36,8 +38,16 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.map(|variable| match variable {
|
.map(|variable| match variable {
|
||||||
"version" => Some(Ok(&elixir_version)),
|
"version" => versions
|
||||||
"otp_version" => Some(Ok(&otp_version)),
|
.deref()
|
||||||
|
.as_ref()
|
||||||
|
.map(|(_, elixir_version)| elixir_version)
|
||||||
|
.map(Ok),
|
||||||
|
"otp_version" => versions
|
||||||
|
.deref()
|
||||||
|
.as_ref()
|
||||||
|
.map(|(otp_version, _)| otp_version)
|
||||||
|
.map(Ok),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.parse(None)
|
.parse(None)
|
||||||
|
@ -110,8 +120,8 @@ Elixir 1.10 (compiled with Erlang/OTP 22)
|
||||||
File::create(dir.path().join("mix.exs"))?.sync_all()?;
|
File::create(dir.path().join("mix.exs"))?.sync_all()?;
|
||||||
|
|
||||||
let expected = Some(format!(
|
let expected = Some(format!(
|
||||||
"via {} ",
|
"via {}",
|
||||||
Color::Purple.bold().paint("💧 1.10 (OTP 22)")
|
Color::Purple.bold().paint("💧 1.10 (OTP 22) ")
|
||||||
));
|
));
|
||||||
let output = ModuleRenderer::new("elixir").path(dir.path()).collect();
|
let output = ModuleRenderer::new("elixir").path(dir.path()).collect();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue