Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact: remove lazy_static #1103

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ hyper = { version = "0.14.27", features = ["full"] }
hyper-staticfile = "0.9.5"
hyper-tungstenite = "0.10.0"
indexmap = "2.0.0"
lazy_static = "1.4.0"
md5 = "0.7.0"
mdxjs = "0.1.14"
merge-source-map = "1.2.0"
Expand Down
10 changes: 5 additions & 5 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ pub use swc_core::ecma::{
};
pub use {
anyhow, base64, cached, clap, colored, config, convert_case, fs_extra, futures, glob, hyper,
hyper_staticfile, hyper_tungstenite, indexmap, lazy_static, md5, mdxjs, merge_source_map,
mime_guess, notify, notify_debouncer_full, path_clean, pathdiff, petgraph, rayon, regex,
sailfish, serde, serde_json, serde_xml_rs, serde_yaml, svgr_rs, swc_emotion,
swc_error_reporters, swc_node_comments, thiserror, tokio, tokio_tungstenite, toml, tracing,
tracing_subscriber, tungstenite, twox_hash,
hyper_staticfile, hyper_tungstenite, indexmap, md5, mdxjs, merge_source_map, mime_guess,
notify, notify_debouncer_full, path_clean, pathdiff, petgraph, rayon, regex, sailfish, serde,
serde_json, serde_xml_rs, serde_yaml, svgr_rs, swc_emotion, swc_error_reporters,
swc_node_comments, thiserror, tokio, tokio_tungstenite, toml, tracing, tracing_subscriber,
tungstenite, twox_hash,
};

#[macro_export]
Expand Down
21 changes: 10 additions & 11 deletions crates/mako/src/ast/file.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::hash::Hasher;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::{Arc, OnceLock};

use mako_core::anyhow::{anyhow, Result};
use mako_core::base64::alphabet::STANDARD;
use mako_core::base64::{engine, Engine};
use mako_core::lazy_static::lazy_static;
use mako_core::pathdiff::diff_paths;
use mako_core::regex::Regex;
use mako_core::thiserror::Error;
Expand Down Expand Up @@ -90,14 +89,14 @@ impl Default for File {
}
}

// e.g.
lazy_static! {
static ref VIRTUAL: String = "virtual:".to_string();
}
const VIRTUAL: &str = "virtual:";

fn css_source_map_regex() -> &'static Regex {
static CSS_SOURCE_MAP_REGEXP: OnceLock<Regex> = OnceLock::new();

lazy_static! {
static ref CSS_SOURCE_MAP_REGEXP: Regex =
Regex::new(r"/\*# sourceMappingURL=data:application/json;base64,(.*?) \*/").unwrap();
CSS_SOURCE_MAP_REGEXP.get_or_init(|| {
Regex::new(r"/\*# sourceMappingURL=data:application/json;base64,(.*?) \*/").unwrap()
})
}

impl File {
Expand All @@ -117,7 +116,7 @@ impl File {
parse_path(&path.to_string_lossy()).unwrap()
};
let pathname = PathBuf::from(pathname);
let is_virtual = path.starts_with(&*VIRTUAL) ||
let is_virtual = path.starts_with(VIRTUAL) ||
// TODO: remove this specific logic
params.iter().any(|(k, _)| k == "asmodule");
let is_under_node_modules = path.to_string_lossy().contains("node_modules");
Expand Down Expand Up @@ -271,7 +270,7 @@ impl File {
let mut chain = vec![];
match &self.content {
Some(Content::Css(content)) => {
if let Some(captures) = CSS_SOURCE_MAP_REGEXP.captures(content) {
if let Some(captures) = css_source_map_regex().captures(content) {
let source_map_base64 = captures.get(1).unwrap().as_str().to_string();
chain.push(base64_decode(source_map_base64.as_bytes()));
}
Expand Down
26 changes: 12 additions & 14 deletions crates/mako/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::path::Path;
use std::sync::Arc;

use mako_core::anyhow::{anyhow, Result};
use mako_core::lazy_static::lazy_static;
use mako_core::mdxjs::{compile, Options as MdxOptions};
use mako_core::serde_xml_rs::from_str as from_xml_str;
use mako_core::serde_yaml::{from_str as from_yaml_str, Value as YamlValue};
Expand Down Expand Up @@ -31,19 +30,18 @@ enum LoadError {
CompileMdError { path: String, reason: String },
}

lazy_static! {
static ref JS_EXTENSIONS: Vec<&'static str> = vec!["js", "jsx", "ts", "tsx", "cjs", "mjs"];
static ref CSS_EXTENSIONS: Vec<&'static str> = vec!["css"];
static ref JSON_EXTENSIONS: Vec<&'static str> = vec!["json", "json5"];
static ref YAML_EXTENSIONS: Vec<&'static str> = vec!["yaml", "yml"];
static ref XML_EXTENSIONS: Vec<&'static str> = vec!["xml"];
static ref WASM_EXTENSIONS: Vec<&'static str> = vec!["wasm"];
static ref TOML_EXTENSIONS: Vec<&'static str> = vec!["toml"];
static ref SVG_EXTENSIONS: Vec<&'static str> = vec!["svg"];
static ref MD_EXTENSIONS: Vec<&'static str> = vec!["md", "mdx"];
static ref UNSUPPORTED_EXTENSIONS: Vec<&'static str> = vec!["sass", "scss", "stylus"];
static ref SVGR_NAMED_EXPORT: String = r#"ReactComponent"#.to_string();
}
const JS_EXTENSIONS: [&str; 6] = ["js", "jsx", "ts", "tsx", "cjs", "mjs"];
const CSS_EXTENSIONS: [&str; 1] = ["css"];
const JSON_EXTENSIONS: [&str; 2] = ["json", "json5"];
const YAML_EXTENSIONS: [&str; 2] = ["yaml", "yml"];
const XML_EXTENSIONS: [&str; 1] = ["xml"];
const WASM_EXTENSIONS: [&str; 1] = ["wasm"];
const TOML_EXTENSIONS: [&str; 1] = ["toml"];
const SVG_EXTENSIONS: [&str; 1] = ["svg"];
const MD_EXTENSIONS: [&str; 2] = ["md", "mdx"];
const UNSUPPORTED_EXTENSIONS: [&str; 3] = ["sass", "scss", "stylus"];

const SVGR_NAMED_EXPORT: &str = r#"ReactComponent"#;

pub struct Load {}

Expand Down
4 changes: 0 additions & 4 deletions packages/mako/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

/* auto-generated by NAPI-RS */

export interface TransformOutput {
code: string;
map?: string;
}
export interface JsHooks {
load?: (filePath: string) => Promise<{ content: string; type: 'css' | 'js' }>;
generateEnd?: (data: {
Expand Down
Loading