Skip to content

Commit 6effdac

Browse files
authored
refactor: remove the lazy_static crate (#27)
1 parent 1103ddf commit 6effdac

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ repository = "https://github.com/yarnpkg/pnp-rs"
1111
byteorder = "1"
1212
clean-path = "0.2.1"
1313
concurrent_lru = "^0.2"
14-
fancy-regex = { version = "^0.13.0", default-features = false }
14+
fancy-regex = { version = "^0.13.0", default-features = false, features = ["std"] }
1515
indexmap = { version = "2.7.1", features = ["serde"] }
16-
lazy_static = "1"
1716
miniz_oxide = "^0.7"
1817
mmap-rs = { version = "^0.6", optional = true }
1918
path-slash = "0.2.1"

src/lib.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ use std::{
99
collections::hash_map::Entry,
1010
hash::BuildHasherDefault,
1111
path::{Path, PathBuf},
12+
sync::OnceLock,
1213
};
1314

1415
use fancy_regex::Regex;
1516
use indexmap::IndexMap;
16-
use lazy_static::lazy_static;
1717
use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
1818
use serde::{Deserialize, Serialize};
1919
use serde_with::{DefaultOnNull, serde_as};
@@ -183,14 +183,16 @@ pub fn load_pnp_manifest<P: AsRef<Path>>(p: P) -> Result<Manifest, Error> {
183183
}))
184184
})?;
185185

186-
lazy_static! {
187-
static ref RE: Regex = Regex::new(
188-
"(const[ \\r\\n]+RAW_RUNTIME_STATE[ \\r\\n]*=[ \\r\\n]*|hydrateRuntimeState\\(JSON\\.parse\\()'"
189-
)
190-
.unwrap();
191-
}
186+
static RE: OnceLock<Regex> = OnceLock::new();
192187

193-
let manifest_match = RE.find(&manifest_content)
188+
let manifest_match =
189+
RE.get_or_init(|| {
190+
Regex::new(
191+
"(const[ \\r\\n]+RAW_RUNTIME_STATE[ \\r\\n]*=[ \\r\\n]*|hydrateRuntimeState\\(JSON\\.parse\\()'"
192+
)
193+
.unwrap()
194+
})
195+
.find(&manifest_content)
194196
.unwrap_or_default()
195197
.ok_or_else(|| Error::FailedManifestHydration(Box::new(FailedManifestHydration {
196198
message: String::from("We failed to locate the PnP data payload inside its manifest file. Did you manually edit the file?"),

0 commit comments

Comments
 (0)