farmfe_core 2.1.0

Core types and data structures for farm.
#![feature(let_chains)]
#![feature(box_patterns)]
#![deny(clippy::all)]
#![allow(clippy::ptr_arg)]
#![feature(trivial_bounds)]
#![allow(clippy::redundant_closure_call)]
#![allow(clippy::to_string_trait_impl)]
#![allow(clippy::macro_metavars_in_unsafe)]
#![allow(clippy::too_long_first_doc_paragraph)]

// #![feature(unsize)]
// #![feature(trait_upcasting)]
pub mod cache;
pub mod common;
pub mod config;
pub mod context;
pub mod error;
pub mod module;
pub mod plugin;
pub mod resource;
pub mod stats;

pub use cache::cacheable::*;
pub use farmfe_macro_cache_item::cache_item;

/// Version of this core crate, if the core data structures changed,
/// and the changes will affect the memory layout,
/// like adding or removing a field, this version should be bumped.
/// So plugin loader can recognize compatibility of the dynamic library plugins and the core.
pub const VERSION: &str = "0.5.0";

// re-export common external crates
pub use dashmap;
pub use heck;
pub use lazy_static;
pub use parking_lot;
pub use petgraph;
#[cfg(feature = "profile")]
pub use puffin;
pub use rayon;
pub use regex;
pub use relative_path;
pub use rkyv;
pub use serde;
pub use serde_json;
pub use swc_common;
pub use swc_css_ast;
pub use swc_ecma_ast;
pub use swc_ecma_parser;
pub use swc_html_ast;
pub use wax;

// re-export common type alias
pub type HashMap<K, V> = rustc_hash::FxHashMap<K, V>;
pub type HashSet<K> = rustc_hash::FxHashSet<K>;
pub type DashMap<K, V> = dashmap::DashMap<K, V, rustc_hash::FxBuildHasher>;

#[macro_export]
macro_rules! farm_profile_scope {
  ($s:expr) => {
    #[cfg(feature = "profile")]
    let msg = farmfe_utils::transform_string_to_static_str(String::from($s));
    #[cfg(feature = "profile")]
    farmfe_core::puffin::profile_scope!(msg);
  };
}

#[macro_export]
macro_rules! farm_profile_function {
  ($s:expr) => {
    #[cfg(feature = "profile")]
    {
      let msg = farmfe_utils::transform_string_to_static_str(String::from($s));
      farmfe_core::puffin::profile_function!(msg);
    }
  };

  () => {
    farm_profile_function!("")
  };
}

#[macro_export]
macro_rules! serialize {
  ($t:expr) => {{
    let bytes = rkyv::to_bytes::<rkyv::rancor::Error>($t).unwrap();
    bytes.to_vec()
  }};
}

#[macro_export]
macro_rules! deserialize {
  ($bytes:expr, $ty:ty, $archived_ty:ty) => {{
    let archived = unsafe { rkyv::access_unchecked::<$archived_ty>($bytes) };
    let deserialized: $ty = rkyv::deserialize::<$ty, rkyv::rancor::Error>(archived).unwrap();

    deserialized
  }};

  ($bytes:expr, $ty:ty) => {{
    deserialize!($bytes, $ty, rkyv::Archived::<$ty>)
  }};
}