Migrate to once_cell (#2750)

* Replace lazy_static with once_cell.

* Migrate to clap v3, so 1 less lazy_static.

* Convert with `.into()`.
This commit is contained in:
Kaede Hoshikawa 2022-06-24 23:32:00 +09:00 committed by GitHub
parent 54de041981
commit 6b89e21034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 174 additions and 188 deletions

View File

@ -11,10 +11,10 @@ rand = { version = "0.8", features = ["small_rng"] }
yew = { path = "../../packages/yew" }
yew-router = { path = "../../packages/yew-router" }
serde = { version = "1.0", features = ["derive"] }
lazy_static = "1.4.0"
gloo-timers = "0.2"
wasm-logger = "0.2"
instant = { version = "0.1", features = ["wasm-bindgen"] }
once_cell = "1"
[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2", features = ["js"] }

View File

@ -1,5 +1,5 @@
use lazy_static::lazy_static;
use lipsum::MarkovChain;
use once_cell::sync::Lazy;
use rand::distributions::Bernoulli;
use rand::rngs::StdRng;
use rand::seq::IteratorRandom;
@ -9,13 +9,11 @@ const KEYWORDS: &str = include_str!("../data/keywords.txt");
const SYLLABLES: &str = include_str!("../data/syllables.txt");
const YEW_CONTENT: &str = include_str!("../data/yew.txt");
lazy_static! {
static ref YEW_CHAIN: MarkovChain<'static> = {
let mut chain = MarkovChain::new();
chain.learn(YEW_CONTENT);
chain
};
}
static YEW_CHAIN: Lazy<MarkovChain<'static>> = Lazy::new(|| {
let mut chain = MarkovChain::new();
chain.learn(YEW_CONTENT);
chain
});
pub struct Generator {
pub seed: u32,

View File

@ -14,5 +14,5 @@ wasm-logger = "0.2"
yew = { path = "../../packages/yew", features = ["csr"] }
yew-router = { path = "../../packages/yew-router" }
serde = { version = "1.0", features = ["derive"] }
lazy_static = "1.4.0"
once_cell = "1"
gloo-timers = "0.2"

View File

@ -1,5 +1,5 @@
use lazy_static::lazy_static;
use lipsum::MarkovChain;
use once_cell::sync::Lazy;
use rand::distributions::Bernoulli;
use rand::rngs::SmallRng;
use rand::seq::IteratorRandom;
@ -9,13 +9,11 @@ const KEYWORDS: &str = include_str!("../data/keywords.txt");
const SYLLABLES: &str = include_str!("../data/syllables.txt");
const YEW_CONTENT: &str = include_str!("../data/yew.txt");
lazy_static! {
static ref YEW_CHAIN: MarkovChain<'static> = {
let mut chain = MarkovChain::new();
chain.learn(YEW_CONTENT);
chain
};
}
static YEW_CHAIN: Lazy<MarkovChain<'static>> = Lazy::new(|| {
let mut chain = MarkovChain::new();
chain.learn(YEW_CONTENT);
chain
});
pub struct Generator {
pub seed: u64,

View File

@ -17,7 +17,6 @@ proc-macro = true
[dependencies]
boolinator = "2"
lazy_static = "1"
proc-macro-error = "1"
proc-macro2 = "1"
quote = "1"

View File

@ -1,6 +1,6 @@
use std::collections::HashSet;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use syn::parse::{Parse, ParseStream};
use syn::{Expr, ExprTuple};
@ -64,154 +64,146 @@ impl Parse for ElementProps {
}
}
lazy_static! {
static ref BOOLEAN_SET: HashSet<&'static str> = {
vec![
// Living Standard
// From: https://html.spec.whatwg.org/#attributes-3
// where `Value` = Boolean attribute
// Note: `checked` is uniquely handled in the html! macro.
"allowfullscreen",
"async",
"autofocus",
"autoplay",
"controls",
"default",
"defer",
"disabled",
"formnovalidate",
"hidden",
"ismap",
"itemscope",
"loop",
"multiple",
"muted",
"nomodule",
"novalidate",
"open",
"playsinline",
"readonly",
"required",
"reversed",
"selected",
"truespeed",
]
.into_iter()
.collect()
};
}
static BOOLEAN_SET: Lazy<HashSet<&'static str>> = Lazy::new(|| {
[
// Living Standard
// From: https://html.spec.whatwg.org/#attributes-3
// where `Value` = Boolean attribute
// Note: `checked` is uniquely handled in the html! macro.
"allowfullscreen",
"async",
"autofocus",
"autoplay",
"controls",
"default",
"defer",
"disabled",
"formnovalidate",
"hidden",
"ismap",
"itemscope",
"loop",
"multiple",
"muted",
"nomodule",
"novalidate",
"open",
"playsinline",
"readonly",
"required",
"reversed",
"selected",
"truespeed",
]
.into()
});
lazy_static! {
static ref LISTENER_SET: HashSet<&'static str> = {
vec![
// Living Standard
// From: https://html.spec.whatwg.org/multipage/webappapis.html#globaleventhandlers
"onabort",
"onauxclick",
"onblur",
"oncancel",
"oncanplay",
"oncanplaythrough",
"onchange",
"onclick",
"onclose",
"oncontextmenu",
"oncuechange",
"ondblclick",
"ondrag",
"ondragend",
"ondragenter",
"ondragexit",
"ondragleave",
"ondragover",
"ondragstart",
"ondrop",
"ondurationchange",
"onemptied",
"onended",
"onerror",
"onfocus",
// onfocusin + onfocusout not in standard but added due to browser support
// see issue 1896: https://github.com/yewstack/yew/issues/1896
"onfocusin",
"onfocusout",
"onformdata",
"oninput",
"oninvalid",
"onkeydown",
"onkeypress",
"onkeyup",
"onload",
"onloadeddata",
"onloadedmetadata",
"onloadstart",
"onmousedown",
"onmouseenter",
"onmouseleave",
"onmousemove",
"onmouseout",
"onmouseover",
"onmouseup",
"onpause",
"onplay",
"onplaying",
"onprogress",
"onratechange",
"onreset",
"onresize",
"onscroll",
"onsecuritypolicyviolation",
"onseeked",
"onseeking",
"onselect",
"onslotchange",
"onstalled",
"onsubmit",
"onsuspend",
"ontimeupdate",
"ontoggle",
"onvolumechange",
"onwaiting",
"onwheel",
// Standard HTML Document and Element
// From: https://html.spec.whatwg.org/multipage/webappapis.html#documentandelementeventhandlers
"oncopy",
"oncut",
"onpaste",
// Others
// From: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers
"onanimationcancel",
"onanimationend",
"onanimationiteration",
"onanimationstart",
"ongotpointercapture",
"onloadend",
"onlostpointercapture",
"onpointercancel",
"onpointerdown",
"onpointerenter",
"onpointerleave",
"onpointerlockchange",
"onpointerlockerror",
"onpointermove",
"onpointerout",
"onpointerover",
"onpointerup",
"onselectionchange",
"onselectstart",
"onshow",
"ontouchcancel",
"ontouchend",
"ontouchmove",
"ontouchstart",
"ontransitioncancel",
"ontransitionend",
"ontransitionrun",
"ontransitionstart",
]
.into_iter()
.collect()
};
}
static LISTENER_SET: Lazy<HashSet<&'static str>> = Lazy::new(|| {
[
// Living Standard
// From: https://html.spec.whatwg.org/multipage/webappapis.html#globaleventhandlers
"onabort",
"onauxclick",
"onblur",
"oncancel",
"oncanplay",
"oncanplaythrough",
"onchange",
"onclick",
"onclose",
"oncontextmenu",
"oncuechange",
"ondblclick",
"ondrag",
"ondragend",
"ondragenter",
"ondragexit",
"ondragleave",
"ondragover",
"ondragstart",
"ondrop",
"ondurationchange",
"onemptied",
"onended",
"onerror",
"onfocus",
// onfocusin + onfocusout not in standard but added due to browser support
// see issue 1896: https://github.com/yewstack/yew/issues/1896
"onfocusin",
"onfocusout",
"onformdata",
"oninput",
"oninvalid",
"onkeydown",
"onkeypress",
"onkeyup",
"onload",
"onloadeddata",
"onloadedmetadata",
"onloadstart",
"onmousedown",
"onmouseenter",
"onmouseleave",
"onmousemove",
"onmouseout",
"onmouseover",
"onmouseup",
"onpause",
"onplay",
"onplaying",
"onprogress",
"onratechange",
"onreset",
"onresize",
"onscroll",
"onsecuritypolicyviolation",
"onseeked",
"onseeking",
"onselect",
"onslotchange",
"onstalled",
"onsubmit",
"onsuspend",
"ontimeupdate",
"ontoggle",
"onvolumechange",
"onwaiting",
"onwheel",
// Standard HTML Document and Element
// From: https://html.spec.whatwg.org/multipage/webappapis.html#documentandelementeventhandlers
"oncopy",
"oncut",
"onpaste",
// Others
// From: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers
"onanimationcancel",
"onanimationend",
"onanimationiteration",
"onanimationstart",
"ongotpointercapture",
"onloadend",
"onlostpointercapture",
"onpointercancel",
"onpointerdown",
"onpointerenter",
"onpointerleave",
"onpointerlockchange",
"onpointerlockerror",
"onpointermove",
"onpointerout",
"onpointerover",
"onpointerup",
"onselectionchange",
"onselectstart",
"onshow",
"ontouchcancel",
"ontouchend",
"ontouchmove",
"ontouchstart",
"ontransitioncancel",
"ontransitionend",
"ontransitionrun",
"ontransitionstart",
]
.into()
});

View File

@ -13,7 +13,7 @@ git2 = "=0.14.2" # see https://github.com/rust-lang/git2-rs/issues/838 fixed wit
regex = "1"
reqwest = { version = "0.11", features = ["blocking", "json"] }
serde = { version = "1", features = ["derive"] }
structopt = "0.3"
strum = { version = "0.24", features = ["derive"] }
lazy_static = "1.4.0"
clap = { version = "3", features = ["derive"] }
semver = "1.0"
once_cell = "1"

View File

@ -1,6 +1,6 @@
use anyhow::{bail, Result};
use clap::Parser;
use semver::Version;
use structopt::StructOpt;
use crate::create_log_lines::create_log_lines;
use crate::get_latest_version::get_latest_version;
@ -11,7 +11,7 @@ use crate::write_log_lines::write_log_lines;
use crate::write_version_changelog::write_changelog_file;
use crate::yew_package::YewPackage;
#[derive(StructOpt)]
#[derive(Parser)]
pub struct Cli {
/// package to generate changelog for
pub package: YewPackage,
@ -23,23 +23,23 @@ pub struct Cli {
pub from: Option<String>,
/// To commit. (ex. commit hash or for tags "refs/tags/yew-v0.19.3")
#[structopt(short = "r", long, default_value = "HEAD")]
#[clap(short = 'r', long, default_value = "HEAD")]
pub to: String,
/// Path to changelog file
#[structopt(short = "f", long, default_value = "CHANGELOG.md")]
#[clap(short = 'f', long, default_value = "CHANGELOG.md")]
pub changelog_path: String,
/// Skip writing changelog file
#[structopt(short, long)]
#[clap(short, long)]
pub skip_file_write: bool,
/// Skip getting the next version
#[structopt(short = "b", long)]
#[clap(short = 'b', long)]
pub skip_get_bump_version: bool,
/// Github token
#[structopt(short = "t", long)]
#[clap(short = 't', long)]
pub token: Option<String>,
}

View File

@ -2,19 +2,18 @@ use std::sync::Mutex;
use anyhow::{anyhow, Context, Result};
use git2::{Error, Oid, Repository};
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use regex::Regex;
use crate::github_issue_labels_fetcher::GitHubIssueLabelsFetcher;
use crate::github_user_fetcher::GitHubUsersFetcher;
use crate::log_line::LogLine;
lazy_static! {
static ref REGEX_FOR_ISSUE_ID_CAPTURE: Regex = Regex::new(r"\s*\(#(\d+)\)").unwrap();
static ref GITHUB_USERS_FETCHER: Mutex<GitHubUsersFetcher> = Default::default();
static ref GITHUB_ISSUE_LABELS_FETCHER: Mutex<GitHubIssueLabelsFetcher> = Default::default();
static ref PACKAGE_LABELS: Vec<String> = vec![];
}
static REGEX_FOR_ISSUE_ID_CAPTURE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"\s*\(#(\d+)\)").unwrap());
static GITHUB_USERS_FETCHER: Lazy<Mutex<GitHubUsersFetcher>> = Lazy::new(Default::default);
static GITHUB_ISSUE_LABELS_FETCHER: Lazy<Mutex<GitHubIssueLabelsFetcher>> =
Lazy::new(Default::default);
pub fn create_log_line(
repo: &Repository,

View File

@ -1,7 +1,7 @@
use anyhow::Result;
use changelog::Cli;
use structopt::StructOpt;
use clap::Parser;
fn main() -> Result<()> {
Cli::from_args().run()
Cli::parse().run()
}