-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add rust types * Remove bitflags * Use ahash for better platform support * Reexport core types
- Loading branch information
1 parent
ef63bff
commit a4a4033
Showing
20 changed files
with
1,479 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
//! Core re-implementation in Rust | ||
pub mod hash; | ||
pub mod types; | ||
|
||
/// New-type for paths relative to a project-root | ||
pub mod project_path; | ||
|
||
/// Request types and run functions | ||
pub mod requests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
mod asset; | ||
pub use self::asset::*; | ||
|
||
mod bundle; | ||
pub use self::bundle::*; | ||
|
||
mod dependency; | ||
pub use self::dependency::*; | ||
|
||
mod environment; | ||
pub use self::environment::*; | ||
|
||
mod file_type; | ||
pub use self::file_type::*; | ||
|
||
mod json; | ||
pub use self::json::*; | ||
|
||
mod parcel_options; | ||
pub use self::parcel_options::*; | ||
|
||
mod source; | ||
pub use self::source::*; | ||
|
||
mod symbol; | ||
pub use self::symbol::*; | ||
|
||
mod target; | ||
pub use self::target::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
use std::hash::Hash; | ||
use std::hash::Hasher; | ||
use std::num::NonZeroU32; | ||
use std::path::PathBuf; | ||
|
||
use ahash::AHasher; | ||
use serde::Deserialize; | ||
use serde::Serialize; | ||
|
||
use super::bundle::BundleBehavior; | ||
use super::environment::Environment; | ||
use super::file_type::FileType; | ||
use super::json::JSONObject; | ||
use super::symbol::Symbol; | ||
|
||
#[derive(PartialEq, Hash, Clone, Copy, Debug)] | ||
pub struct AssetId(pub NonZeroU32); | ||
|
||
/// An asset is a file or part of a file that may represent any data type including source code, binary data, etc. | ||
/// | ||
/// Note that assets may exist in the file system or virtually. | ||
/// | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Asset { | ||
/// The file type of the asset, which may change during transformation | ||
#[serde(rename = "type")] | ||
pub asset_type: FileType, | ||
|
||
/// Controls which bundle the asset is placed into | ||
pub bundle_behavior: BundleBehavior, | ||
|
||
/// The environment of the asset | ||
pub env: Environment, | ||
|
||
/// The file path to the asset | ||
pub file_path: PathBuf, | ||
|
||
/// Indicates if the asset is used as a bundle entry | ||
/// | ||
/// This controls whether a bundle can be split into multiple, or whether all of the | ||
/// dependencies must be placed in a single bundle. | ||
/// | ||
pub is_bundle_splittable: bool, | ||
|
||
/// Whether this asset is part of the project, and not an external dependency | ||
/// | ||
/// This indicates that transformation using the project configuration should be applied. | ||
/// | ||
pub is_source: bool, | ||
|
||
/// Plugin specific metadata for the asset | ||
pub meta: JSONObject, | ||
|
||
/// The pipeline defined in .parcelrc that the asset should be processed with | ||
pub pipeline: Option<String>, | ||
|
||
/// The transformer options for the asset from the dependency query string | ||
pub query: Option<String>, | ||
|
||
/// Whether this asset can be omitted if none of its exports are being used | ||
/// | ||
/// This is initially set by the resolver, but can be overridden by transformers. | ||
/// | ||
pub side_effects: bool, | ||
|
||
/// Statistics about the asset | ||
pub stats: AssetStats, | ||
|
||
/// The symbols that the asset exports | ||
pub symbols: Vec<Symbol>, | ||
|
||
/// A unique key that identifies an asset | ||
/// | ||
/// When a transformer returns multiple assets, it can give them unique keys to identify them. | ||
/// This can be used to find assets during packaging, or to create dependencies between multiple | ||
/// assets returned by a transformer by using the unique key as the dependency specifier. | ||
/// | ||
pub unique_key: Option<String>, | ||
} | ||
|
||
impl Asset { | ||
pub fn id(&self) -> u64 { | ||
let mut hasher = AHasher::default(); | ||
|
||
self.asset_type.hash(&mut hasher); | ||
self.env.hash(&mut hasher); | ||
self.file_path.hash(&mut hasher); | ||
self.pipeline.hash(&mut hasher); | ||
self.query.hash(&mut hasher); | ||
self.unique_key.hash(&mut hasher); | ||
|
||
hasher.finish() | ||
} | ||
} | ||
|
||
/// Statistics that pertain to an asset | ||
#[derive(Clone, Debug, Default, Deserialize, Serialize)] | ||
pub struct AssetStats { | ||
pub size: u32, | ||
pub time: u32, | ||
} |
Oops, something went wrong.