Unverified Commit c8ac2a52 authored by xusd320's avatar xusd320 Committed by GitHub

refactor(turbopack): remove lazy_static dependency (#80226)

## Why
lazy_static  is deprecated, see [Officially deprecate lazy_static #214
](https://github.com/rust-lang-nursery/lazy-static.rs/issues/214)
parent 737d3199
...@@ -4216,7 +4216,6 @@ dependencies = [ ...@@ -4216,7 +4216,6 @@ dependencies = [
"indoc", "indoc",
"itertools 0.10.5", "itertools 0.10.5",
"lazy-regex", "lazy-regex",
"lazy_static",
"mime_guess", "mime_guess",
"modularize_imports", "modularize_imports",
"next-custom-transforms", "next-custom-transforms",
...@@ -4268,7 +4267,6 @@ dependencies = [ ...@@ -4268,7 +4267,6 @@ dependencies = [
"hex", "hex",
"indexmap 2.7.1", "indexmap 2.7.1",
"indoc", "indoc",
"lazy_static",
"modularize_imports", "modularize_imports",
"once_cell", "once_cell",
"pathdiff", "pathdiff",
...@@ -9361,7 +9359,6 @@ dependencies = [ ...@@ -9361,7 +9359,6 @@ dependencies = [
"anyhow", "anyhow",
"codspeed-criterion-compat", "codspeed-criterion-compat",
"difference", "difference",
"lazy_static",
"regex", "regex",
"rstest", "rstest",
"rstest_reuse", "rstest_reuse",
...@@ -9513,7 +9510,6 @@ dependencies = [ ...@@ -9513,7 +9510,6 @@ dependencies = [
"either", "either",
"futures", "futures",
"indexmap 2.7.1", "indexmap 2.7.1",
"lazy_static",
"once_cell", "once_cell",
"patricia_tree", "patricia_tree",
"petgraph 0.6.3", "petgraph 0.6.3",
...@@ -9627,7 +9623,6 @@ dependencies = [ ...@@ -9627,7 +9623,6 @@ dependencies = [
"either", "either",
"indexmap 2.7.1", "indexmap 2.7.1",
"indoc", "indoc",
"lazy_static",
"num-bigint", "num-bigint",
"num-traits", "num-traits",
"once_cell", "once_cell",
...@@ -9831,7 +9826,6 @@ name = "turbopack-resolve" ...@@ -9831,7 +9826,6 @@ name = "turbopack-resolve"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"lazy_static",
"regex", "regex",
"serde", "serde",
"serde_json", "serde_json",
......
...@@ -14,9 +14,7 @@ members = [ ...@@ -14,9 +14,7 @@ members = [
"turbopack/xtask", "turbopack/xtask",
] ]
exclude = [ exclude = ["crates/next-error-code-swc-plugin"]
"crates/next-error-code-swc-plugin",
]
[workspace.lints.clippy] [workspace.lints.clippy]
too_many_arguments = "allow" too_many_arguments = "allow"
...@@ -350,15 +348,14 @@ image = { version = "0.25.0", default-features = false } ...@@ -350,15 +348,14 @@ image = { version = "0.25.0", default-features = false }
indexmap = "2.7.1" indexmap = "2.7.1"
indoc = "2.0.0" indoc = "2.0.0"
itertools = "0.10.5" itertools = "0.10.5"
lazy_static = "1.4.0"
lightningcss = { version = "1.0.0-alpha.66", features = [ lightningcss = { version = "1.0.0-alpha.66", features = [
"serde", "serde",
"visitor", "visitor",
"into_owned", "into_owned",
] } ] }
lightningcss-napi = { version = "0.4.4", default-features = false, features = [ lightningcss-napi = { version = "0.4.4", default-features = false, features = [
"visitor" "visitor",
]} ] }
markdown = "1.0.0-alpha.18" markdown = "1.0.0-alpha.18"
mime = "0.3.16" mime = "0.3.16"
napi = { version = "2", default-features = false, features = [ napi = { version = "2", default-features = false, features = [
...@@ -418,8 +415,12 @@ triomphe = { git = "https://github.com/sokra/triomphe", branch = "sokra/unstable ...@@ -418,8 +415,12 @@ triomphe = { git = "https://github.com/sokra/triomphe", branch = "sokra/unstable
unsize = "1.1.0" unsize = "1.1.0"
url = "2.2.2" url = "2.2.2"
urlencoding = "2.1.2" urlencoding = "2.1.2"
vergen = { version = "9.0.6", features = ["cargo"] } vergen = { version = "9.0.6", features = [
vergen-gitcl = { version = "1.0.8", features = ["cargo"] } "cargo",
] }
vergen-gitcl = { version = "1.0.8", features = [
"cargo",
] }
webbrowser = "0.8.7" webbrowser = "0.8.7"
[patch.crates-io] [patch.crates-io]
......
...@@ -28,7 +28,6 @@ mime_guess = "2.0.4" ...@@ -28,7 +28,6 @@ mime_guess = "2.0.4"
indoc = { workspace = true } indoc = { workspace = true }
allsorts = { workspace = true } allsorts = { workspace = true }
futures = { workspace = true } futures = { workspace = true }
lazy_static = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }
tracing = { workspace = true } tracing = { workspace = true }
rustc-hash = { workspace = true } rustc-hash = { workspace = true }
...@@ -69,7 +68,9 @@ turbopack = { workspace = true } ...@@ -69,7 +68,9 @@ turbopack = { workspace = true }
turbopack-browser = { workspace = true } turbopack-browser = { workspace = true }
turbopack-core = { workspace = true } turbopack-core = { workspace = true }
turbopack-ecmascript = { workspace = true } turbopack-ecmascript = { workspace = true }
turbopack-ecmascript-plugins = { workspace = true, features = ["transform_emotion"] } turbopack-ecmascript-plugins = { workspace = true, features = [
"transform_emotion",
] }
turbopack-ecmascript-runtime = { workspace = true } turbopack-ecmascript-runtime = { workspace = true }
turbopack-image = { workspace = true } turbopack-image = { workspace = true }
turbopack-node = { workspace = true } turbopack-node = { workspace = true }
......
use std::sync::LazyLock;
use anyhow::Result; use anyhow::Result;
use lazy_static::lazy_static;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, Vc}; use turbo_tasks::{ResolvedVc, Vc};
...@@ -21,24 +22,26 @@ use turbopack_core::{ ...@@ -21,24 +22,26 @@ use turbopack_core::{
use crate::{next_server::ServerContextType, next_telemetry::ModuleFeatureTelemetry}; use crate::{next_server::ServerContextType, next_telemetry::ModuleFeatureTelemetry};
lazy_static! { // Set of the features we want to track, following existing references in
// Set of the features we want to track, following existing references in webpack/plugins/telemetry-plugin. // webpack/plugins/telemetry-plugin.
static ref FEATURE_MODULES: FxHashMap<&'static str, Vec<&'static str>> = FxHashMap::from_iter([ static FEATURE_MODULES: LazyLock<FxHashMap<&'static str, Vec<&'static str>>> =
( LazyLock::new(|| {
"next", FxHashMap::from_iter([
vec![ (
"/image", "next",
"/future/image", vec![
"/legacy/image", "/image",
"/script", "/future/image",
"/dynamic", "/legacy/image",
"/font/google", "/script",
"/font/local" "/dynamic",
] "/font/google",
), "/font/local",
("@next", vec!["/font/google", "/font/local"]) ],
]); ),
} ("@next", vec!["/font/google", "/font/local"]),
])
});
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
pub struct InvalidImportModuleIssue { pub struct InvalidImportModuleIssue {
......
...@@ -38,7 +38,6 @@ serde_json = { workspace = true, features = ["preserve_order"] } ...@@ -38,7 +38,6 @@ serde_json = { workspace = true, features = ["preserve_order"] }
sha1 = "0.10.1" sha1 = "0.10.1"
tracing = { version = "0.1.37" } tracing = { version = "0.1.37" }
anyhow = { workspace = true } anyhow = { workspace = true }
lazy_static = { workspace = true }
swc_core = { workspace = true, features = [ swc_core = { workspace = true, features = [
"base", "base",
...@@ -73,5 +72,5 @@ remove_console = "0.42.0" ...@@ -73,5 +72,5 @@ remove_console = "0.42.0"
preset_env_base = "3.0.1" preset_env_base = "3.0.1"
[dev-dependencies] [dev-dependencies]
swc_core = { workspace = true, features = ["testing_transform"]} swc_core = { workspace = true, features = ["testing_transform"] }
testing = { workspace = true } testing = { workspace = true }
use std::iter::FromIterator; use std::{iter::FromIterator, sync::LazyLock};
use lazy_static::lazy_static;
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
use swc_core::{ use swc_core::{
atoms::atom, atoms::atom,
...@@ -15,15 +14,15 @@ use swc_core::{ ...@@ -15,15 +14,15 @@ use swc_core::{
use super::{ExportInfo, ExportInfoWarning}; use super::{ExportInfo, ExportInfoWarning};
lazy_static! { static EXPORTS_SET: LazyLock<FxHashSet<&'static str>> = LazyLock::new(|| {
static ref EXPORTS_SET: FxHashSet<&'static str> = FxHashSet::from_iter([ FxHashSet::from_iter([
"getStaticProps", "getStaticProps",
"getServerSideProps", "getServerSideProps",
"generateImageMetadata", "generateImageMetadata",
"generateSitemaps", "generateSitemaps",
"generateStaticParams", "generateStaticParams",
]); ])
} });
pub(crate) struct CollectExportsVisitor { pub(crate) struct CollectExportsVisitor {
pub export_info: Option<ExportInfo>, pub export_info: Option<ExportInfo>,
......
...@@ -22,13 +22,12 @@ data-encoding = { workspace = true } ...@@ -22,13 +22,12 @@ data-encoding = { workspace = true }
either = { workspace = true } either = { workspace = true }
futures = { workspace = true } futures = { workspace = true }
indexmap = { workspace = true } indexmap = { workspace = true }
lazy_static = { workspace = true }
once_cell = { workspace = true } once_cell = { workspace = true }
patricia_tree = "0.5.5" patricia_tree = "0.5.5"
petgraph = { workspace = true, features = ["serde-1"] } petgraph = { workspace = true, features = ["serde-1"] }
roaring = { version = "0.10.10", features = ["serde"] } roaring = { version = "0.10.10", features = ["serde"] }
ref-cast = "1.0.20" ref-cast = "1.0.20"
rustc-hash ={ workspace = true } rustc-hash = { workspace = true }
regex = { workspace = true } regex = { workspace = true }
serde = { workspace = true, features = ["rc"] } serde = { workspace = true, features = ["rc"] }
serde_bytes = { workspace = true } serde_bytes = { workspace = true }
......
use std::sync::LazyLock;
use anyhow::{Ok, Result}; use anyhow::{Ok, Result};
use lazy_static::lazy_static;
use regex::Regex; use regex::Regex;
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, TryJoinIterExt, ValueToString, Vc}; use turbo_tasks::{ResolvedVc, TryJoinIterExt, ValueToString, Vc};
...@@ -89,12 +90,12 @@ fn split_off_query_fragment(mut raw: &str) -> (Pattern, RcStr, RcStr) { ...@@ -89,12 +90,12 @@ fn split_off_query_fragment(mut raw: &str) -> (Pattern, RcStr, RcStr) {
(Pattern::Constant(RcStr::from(raw)), query, hash) (Pattern::Constant(RcStr::from(raw)), query, hash)
} }
lazy_static! { static WINDOWS_PATH: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^[A-Za-z]:\\|\\\\").unwrap());
static ref WINDOWS_PATH: Regex = Regex::new(r"^[A-Za-z]:\\|\\\\").unwrap(); static URI_PATH: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^([^/\\:]+:)(.+)$").unwrap());
static ref URI_PATH: Regex = Regex::new(r"^([^/\\:]+:)(.+)$").unwrap(); static DATA_URI_REMAINDER: LazyLock<Regex> =
static ref DATA_URI_REMAINDER: Regex = Regex::new(r"^([^;,]*)(?:;([^,]+))?,(.*)$").unwrap(); LazyLock::new(|| Regex::new(r"^([^;,]*)(?:;([^,]+))?,(.*)$").unwrap());
static ref MODULE_PATH: Regex = Regex::new(r"^((?:@[^/]+/)?[^/]+)(.*)$").unwrap(); static MODULE_PATH: LazyLock<Regex> =
} LazyLock::new(|| Regex::new(r"^((?:@[^/]+/)?[^/]+)(.*)$").unwrap());
impl Request { impl Request {
/// Turns the request into a string. /// Turns the request into a string.
......
...@@ -2,10 +2,10 @@ use std::{ ...@@ -2,10 +2,10 @@ use std::{
collections::{VecDeque, hash_map::Entry}, collections::{VecDeque, hash_map::Entry},
fmt::Display, fmt::Display,
mem::take, mem::take,
sync::LazyLock,
}; };
use anyhow::Result; use anyhow::Result;
use lazy_static::lazy_static;
use regex::Regex; use regex::Regex;
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
...@@ -846,11 +846,11 @@ impl Pattern { ...@@ -846,11 +846,11 @@ impl Pattern {
} }
} }
Pattern::Dynamic => { Pattern::Dynamic => {
lazy_static! { static FORBIDDEN: LazyLock<Regex> = LazyLock::new(|| {
static ref FORBIDDEN: Regex = Regex::new(r"(/|^)(ROOT|\.|/|(node_modules|__tests?__)(/|$))").unwrap()
Regex::new(r"(/|^)(ROOT|\.|/|(node_modules|__tests?__)(/|$))").unwrap(); });
static ref FORBIDDEN_MATCH: Regex = Regex::new(r"\.d\.ts$|\.map$").unwrap(); static FORBIDDEN_MATCH: LazyLock<Regex> =
} LazyLock::new(|| Regex::new(r"\.d\.ts$|\.map$").unwrap());
if let Some(m) = FORBIDDEN.find(value) { if let Some(m) = FORBIDDEN.find(value) {
MatchResult::Consumed { MatchResult::Consumed {
remaining: value, remaining: value,
...@@ -932,11 +932,11 @@ impl Pattern { ...@@ -932,11 +932,11 @@ impl Pattern {
} }
} }
Pattern::Dynamic => { Pattern::Dynamic => {
lazy_static! { static FORBIDDEN: LazyLock<Regex> = LazyLock::new(|| {
static ref FORBIDDEN: Regex = Regex::new(r"(/|^)(ROOT|\.|/|(node_modules|__tests?__)(/|$))").unwrap()
Regex::new(r"(/|^)(ROOT|\.|/|(node_modules|__tests?__)(/|$))").unwrap(); });
static ref FORBIDDEN_MATCH: Regex = Regex::new(r"\.d\.ts$|\.map$").unwrap(); static FORBIDDEN_MATCH: LazyLock<Regex> =
} LazyLock::new(|| Regex::new(r"\.d\.ts$|\.map$").unwrap());
if let Some(m) = FORBIDDEN.find(value) { if let Some(m) = FORBIDDEN.find(value) {
MatchResult::Consumed { MatchResult::Consumed {
remaining: value, remaining: value,
...@@ -1046,11 +1046,11 @@ impl Pattern { ...@@ -1046,11 +1046,11 @@ impl Pattern {
} }
} }
Pattern::Dynamic => { Pattern::Dynamic => {
lazy_static! { static FORBIDDEN: LazyLock<Regex> = LazyLock::new(|| {
static ref FORBIDDEN: Regex = Regex::new(r"(/|^)(\.|(node_modules|__tests?__)(/|$))").unwrap()
Regex::new(r"(/|^)(\.|(node_modules|__tests?__)(/|$))").unwrap(); });
static ref FORBIDDEN_MATCH: Regex = Regex::new(r"\.d\.ts$|\.map$").unwrap(); static FORBIDDEN_MATCH: LazyLock<Regex> =
} LazyLock::new(|| Regex::new(r"\.d\.ts$|\.map$").unwrap());
if let Some(m) = FORBIDDEN.find(value) { if let Some(m) = FORBIDDEN.find(value) {
NextConstantUntilResult::Consumed(value, Some(m.start())) NextConstantUntilResult::Consumed(value, Some(m.start()))
} else if FORBIDDEN_MATCH.find(value).is_some() { } else if FORBIDDEN_MATCH.find(value).is_some() {
......
...@@ -21,7 +21,6 @@ data-encoding = { workspace = true } ...@@ -21,7 +21,6 @@ data-encoding = { workspace = true }
either = { workspace = true } either = { workspace = true }
indexmap = { workspace = true } indexmap = { workspace = true }
indoc = { workspace = true } indoc = { workspace = true }
lazy_static = { workspace = true }
num-bigint = "0.4" num-bigint = "0.4"
num-traits = "0.2.15" num-traits = "0.2.15"
once_cell = { workspace = true } once_cell = { workspace = true }
......
...@@ -18,14 +18,20 @@ pub mod unreachable; ...@@ -18,14 +18,20 @@ pub mod unreachable;
pub mod util; pub mod util;
pub mod worker; pub mod worker;
use std::{borrow::Cow, collections::BTreeMap, future::Future, mem::take, ops::Deref, sync::Arc}; use std::{
borrow::Cow,
collections::BTreeMap,
future::Future,
mem::take,
ops::Deref,
sync::{Arc, LazyLock},
};
use anyhow::{Result, bail}; use anyhow::{Result, bail};
use constant_condition::{ConstantConditionCodeGen, ConstantConditionValue}; use constant_condition::{ConstantConditionCodeGen, ConstantConditionValue};
use constant_value::ConstantValueCodeGen; use constant_value::ConstantValueCodeGen;
use either::Either; use either::Either;
use indexmap::map::Entry; use indexmap::map::Entry;
use lazy_static::lazy_static;
use num_traits::Zero; use num_traits::Zero;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use parking_lot::Mutex; use parking_lot::Mutex;
...@@ -632,15 +638,14 @@ pub(crate) async fn analyse_ecmascript_module_internal( ...@@ -632,15 +638,14 @@ pub(crate) async fn analyse_ecmascript_module_internal(
if let Some(comments) = comments.get_leading(pos) { if let Some(comments) = comments.get_leading(pos) {
for comment in comments.iter() { for comment in comments.iter() {
if let CommentKind::Line = comment.kind { if let CommentKind::Line = comment.kind {
lazy_static! { static REFERENCE_PATH: LazyLock<Regex> = LazyLock::new(|| {
static ref REFERENCE_PATH: Regex = Regex::new(r#"^/\s*<reference\s*path\s*=\s*["'](.+)["']\s*/>\s*$"#)
Regex::new(r#"^/\s*<reference\s*path\s*=\s*["'](.+)["']\s*/>\s*$"#) .unwrap()
.unwrap(); });
static ref REFERENCE_TYPES: Regex = Regex::new( static REFERENCE_TYPES: LazyLock<Regex> = LazyLock::new(|| {
r#"^/\s*<reference\s*types\s*=\s*["'](.+)["']\s*/>\s*$"# Regex::new(r#"^/\s*<reference\s*types\s*=\s*["'](.+)["']\s*/>\s*$"#)
) .unwrap()
.unwrap(); });
}
let text = &comment.text; let text = &comment.text;
if let Some(m) = REFERENCE_PATH.captures(text) { if let Some(m) = REFERENCE_PATH.captures(text) {
let path = &m[1]; let path = &m[1];
...@@ -673,10 +678,8 @@ pub(crate) async fn analyse_ecmascript_module_internal( ...@@ -673,10 +678,8 @@ pub(crate) async fn analyse_ecmascript_module_internal(
let mut paths_by_pos = Vec::new(); let mut paths_by_pos = Vec::new();
for (pos, comments) in comments.trailing.iter() { for (pos, comments) in comments.trailing.iter() {
for comment in comments.iter().rev() { for comment in comments.iter().rev() {
lazy_static! { static SOURCE_MAP_FILE_REFERENCE: LazyLock<Regex> =
static ref SOURCE_MAP_FILE_REFERENCE: Regex = LazyLock::new(|| Regex::new(r"# sourceMappingURL=(.*)$").unwrap());
Regex::new(r"# sourceMappingURL=(.*)$").unwrap();
}
if let Some(m) = SOURCE_MAP_FILE_REFERENCE.captures(&comment.text) { if let Some(m) = SOURCE_MAP_FILE_REFERENCE.captures(&comment.text) {
let path = m.get(1).unwrap().as_str(); let path = m.get(1).unwrap().as_str();
paths_by_pos.push((pos, path)); paths_by_pos.push((pos, path));
...@@ -687,10 +690,9 @@ pub(crate) async fn analyse_ecmascript_module_internal( ...@@ -687,10 +690,9 @@ pub(crate) async fn analyse_ecmascript_module_internal(
let mut source_map_from_comment = false; let mut source_map_from_comment = false;
if let Some((_, path)) = paths_by_pos.into_iter().max_by_key(|&(pos, _)| pos) { if let Some((_, path)) = paths_by_pos.into_iter().max_by_key(|&(pos, _)| pos) {
lazy_static! { static JSON_DATA_URL_BASE64: LazyLock<Regex> = LazyLock::new(|| {
static ref JSON_DATA_URL_BASE64: Regex = Regex::new(r"^data:application\/json;(?:charset=utf-8;)?base64").unwrap()
Regex::new(r"^data:application\/json;(?:charset=utf-8;)?base64").unwrap(); });
}
let origin_path = origin.origin_path(); let origin_path = origin.origin_path();
if path.ends_with(".map") { if path.ends_with(".map") {
let source_map_origin = origin_path.parent().join(path.into()); let source_map_origin = origin_path.parent().join(path.into());
......
...@@ -14,7 +14,6 @@ workspace = true ...@@ -14,7 +14,6 @@ workspace = true
[dependencies] [dependencies]
anyhow = { workspace = true } anyhow = { workspace = true }
lazy_static = { workspace = true }
regex = { workspace = true } regex = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
......
use std::sync::LazyLock;
use anyhow::Result; use anyhow::Result;
use lazy_static::lazy_static;
use regex::Regex; use regex::Regex;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
...@@ -86,17 +87,16 @@ pub async fn resolve_node_pre_gyp_files( ...@@ -86,17 +87,16 @@ pub async fn resolve_node_pre_gyp_files(
config_file_pattern: Vc<Pattern>, config_file_pattern: Vc<Pattern>,
compile_target: Vc<CompileTarget>, compile_target: Vc<CompileTarget>,
) -> Result<Vc<ModuleResolveResult>> { ) -> Result<Vc<ModuleResolveResult>> {
lazy_static! { static NAPI_VERSION_TEMPLATE: LazyLock<Regex> = LazyLock::new(|| {
static ref NAPI_VERSION_TEMPLATE: Regex = Regex::new(r"\{(napi_build_version|node_napi_label)\}")
Regex::new(r"\{(napi_build_version|node_napi_label)\}") .expect("create napi_build_version regex failed")
.expect("create napi_build_version regex failed"); });
static ref PLATFORM_TEMPLATE: Regex = static PLATFORM_TEMPLATE: LazyLock<Regex> =
Regex::new(r"\{platform\}").expect("create node_platform regex failed"); LazyLock::new(|| Regex::new(r"\{platform\}").expect("create node_platform regex failed"));
static ref ARCH_TEMPLATE: Regex = static ARCH_TEMPLATE: LazyLock<Regex> =
Regex::new(r"\{arch\}").expect("create node_arch regex failed"); LazyLock::new(|| Regex::new(r"\{arch\}").expect("create node_arch regex failed"));
static ref LIBC_TEMPLATE: Regex = static LIBC_TEMPLATE: LazyLock<Regex> =
Regex::new(r"\{libc\}").expect("create node_libc regex failed"); LazyLock::new(|| Regex::new(r"\{libc\}").expect("create node_libc regex failed"));
}
let config = resolve_raw(context_dir, config_file_pattern, true) let config = resolve_raw(context_dir, config_file_pattern, true)
.first_source() .first_source()
.await?; .await?;
...@@ -261,12 +261,11 @@ pub async fn resolve_node_gyp_build_files( ...@@ -261,12 +261,11 @@ pub async fn resolve_node_gyp_build_files(
context_dir: Vc<FileSystemPath>, context_dir: Vc<FileSystemPath>,
compile_target: Vc<CompileTarget>, compile_target: Vc<CompileTarget>,
) -> Result<Vc<ModuleResolveResult>> { ) -> Result<Vc<ModuleResolveResult>> {
lazy_static! { // TODO Proper parser
// TODO Proper parser static GYP_BUILD_TARGET_NAME: LazyLock<Regex> = LazyLock::new(|| {
static ref GYP_BUILD_TARGET_NAME: Regex = Regex::new(r#"['"]target_name['"]\s*:\s*(?:"(.*?)"|'(.*?)')"#)
Regex::new(r#"['"]target_name['"]\s*:\s*(?:"(.*?)"|'(.*?)')"#) .expect("create napi_build_version regex failed")
.expect("create napi_build_version regex failed"); });
}
let binding_gyp_pat = Pattern::new(Pattern::Constant(rcstr!("binding.gyp"))); let binding_gyp_pat = Pattern::new(Pattern::Constant(rcstr!("binding.gyp")));
let gyp_file = resolve_raw(context_dir, binding_gyp_pat, true); let gyp_file = resolve_raw(context_dir, binding_gyp_pat, true);
if let [binding_gyp] = &gyp_file.primary_sources().await?[..] { if let [binding_gyp] = &gyp_file.primary_sources().await?[..] {
...@@ -370,15 +369,15 @@ pub async fn resolve_node_bindings_files( ...@@ -370,15 +369,15 @@ pub async fn resolve_node_bindings_files(
context_dir: Vc<FileSystemPath>, context_dir: Vc<FileSystemPath>,
file_name: RcStr, file_name: RcStr,
) -> Result<Vc<ModuleResolveResult>> { ) -> Result<Vc<ModuleResolveResult>> {
lazy_static! { static BINDINGS_TRY: LazyLock<[&'static str; 5]> = LazyLock::new(|| {
static ref BINDINGS_TRY: [&'static str; 5] = [ [
"build/bindings", "build/bindings",
"build/Release", "build/Release",
"build/Release/bindings", "build/Release/bindings",
"out/Release/bindings", "out/Release/bindings",
"Release/bindings", "Release/bindings",
]; ]
} });
let mut root_context_dir = context_dir; let mut root_context_dir = context_dir;
loop { loop {
let resolved = resolve_raw( let resolved = resolve_raw(
......
...@@ -18,7 +18,6 @@ workspace = true ...@@ -18,7 +18,6 @@ workspace = true
[dependencies] [dependencies]
anyhow = { workspace = true } anyhow = { workspace = true }
lazy_static = { workspace = true }
regex = { workspace = true } regex = { workspace = true }
rustc-hash = { workspace = true } rustc-hash = { workspace = true }
smallvec = { workspace = true } smallvec = { workspace = true }
......
...@@ -12,14 +12,13 @@ use std::{ ...@@ -12,14 +12,13 @@ use std::{
}, },
io::{ErrorKind, Write as _}, io::{ErrorKind, Write as _},
path::{Path, PathBuf}, path::{Path, PathBuf},
sync::{Arc, Mutex}, sync::{Arc, LazyLock, Mutex},
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use anyhow::{Context, Result, anyhow}; use anyhow::{Context, Result, anyhow};
use difference::Changeset; use difference::Changeset;
use helpers::print_changeset; use helpers::print_changeset;
use lazy_static::lazy_static;
use regex::Regex; use regex::Regex;
use rstest::*; use rstest::*;
use rstest_reuse::{ use rstest_reuse::{
...@@ -393,9 +392,8 @@ fn node_file_trace<B: Backend + 'static>( ...@@ -393,9 +392,8 @@ fn node_file_trace<B: Backend + 'static>(
timeout_len: u64, timeout_len: u64,
create_turbo_tasks: impl Fn(&Path) -> Arc<TurboTasks<B>>, create_turbo_tasks: impl Fn(&Path) -> Arc<TurboTasks<B>>,
) { ) {
lazy_static! { static BENCH_SUITES: LazyLock<Arc<Mutex<Vec<BenchSuite>>>> =
static ref BENCH_SUITES: Arc<Mutex<Vec<BenchSuite>>> = Arc::new(Mutex::new(Vec::new())); LazyLock::new(|| Arc::new(Mutex::new(Vec::new())));
};
let r = &mut { let r = &mut {
let mut builder = if multi_threaded { let mut builder = if multi_threaded {
...@@ -633,24 +631,20 @@ async fn exec_node(directory: &str, path: &str) -> Result<CommandOutput> { ...@@ -633,24 +631,20 @@ async fn exec_node(directory: &str, path: &str) -> Result<CommandOutput> {
} }
fn clean_stderr(str: &str) -> String { fn clean_stderr(str: &str) -> String {
lazy_static! { static EXPERIMENTAL_WARNING: LazyLock<Regex> =
static ref EXPERIMENTAL_WARNING: Regex = LazyLock::new(|| Regex::new(r"\(node:\d+\) ExperimentalWarning:").unwrap());
Regex::new(r"\(node:\d+\) ExperimentalWarning:").unwrap(); static DEPRECATION_WARNING: LazyLock<Regex> =
static ref DEPRECATION_WARNING: Regex = LazyLock::new(|| Regex::new(r"\(node:\d+\) \[DEP\d+] DeprecationWarning:").unwrap());
Regex::new(r"\(node:\d+\) \[DEP\d+] DeprecationWarning:").unwrap();
}
let str = EXPERIMENTAL_WARNING.replace_all(str, "(node:XXXX) ExperimentalWarning:"); let str = EXPERIMENTAL_WARNING.replace_all(str, "(node:XXXX) ExperimentalWarning:");
let str = DEPRECATION_WARNING.replace_all(&str, "(node:XXXX) [DEPXXXX] DeprecationWarning:"); let str = DEPRECATION_WARNING.replace_all(&str, "(node:XXXX) [DEPXXXX] DeprecationWarning:");
str.to_string() str.to_string()
} }
fn diff(expected: &str, actual: &str) -> String { fn diff(expected: &str, actual: &str) -> String {
lazy_static! { static JAVASCRIPT_TIMESTAMP: LazyLock<Regex> =
static ref JAVASCRIPT_TIMESTAMP: Regex = LazyLock::new(|| Regex::new(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z").unwrap());
Regex::new(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z").unwrap(); static JAVASCRIPT_DATE_TIME: LazyLock<Regex> =
static ref JAVASCRIPT_DATE_TIME: Regex = LazyLock::new(|| Regex::new(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{6}").unwrap());
Regex::new(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{6}").unwrap();
}
// Remove timestamps from the output. // Remove timestamps from the output.
if JAVASCRIPT_DATE_TIME.replace_all(JAVASCRIPT_TIMESTAMP.replace_all(actual, "").as_ref(), "") if JAVASCRIPT_DATE_TIME.replace_all(JAVASCRIPT_TIMESTAMP.replace_all(actual, "").as_ref(), "")
== JAVASCRIPT_DATE_TIME == JAVASCRIPT_DATE_TIME
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment