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

WIP - Draft V3 environment serialization-skip #201

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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: 1 addition & 0 deletions 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/atlaspack/src/atlaspack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ impl Atlaspack {
let asset_graph = match request_result {
RequestResult::AssetGraph(result) => {
self.commit_assets(result.graph.assets.as_slice()).unwrap();

result.graph
}
_ => panic!("TODO"),
Expand Down
2 changes: 1 addition & 1 deletion crates/atlaspack/src/requests/asset_graph_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl AssetGraphBuilder {
*state = DependencyState::Resolved;
AssetRequest {
code: code.clone(),
env: dependency.env.clone(),
env: dependency.env.clone().into(),
file_path: path,
project_root: self.request_context.project_root.clone(),
pipeline: pipeline.clone(),
Expand Down
67 changes: 43 additions & 24 deletions crates/atlaspack/src/requests/target_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::collections::BTreeMap;
use std::hash::Hash;
use std::path::Path;
use std::path::PathBuf;
use std::sync::Arc;

use async_trait::async_trait;
use atlaspack_core::config_loader::ConfigFile;
Expand Down Expand Up @@ -383,7 +382,7 @@ impl TargetRequest {
.clone()
.unwrap_or_else(|| default_dist_dir(&package_json.path)),
dist_entry: None,
env: Arc::new(Environment {
env: Environment {
context,
engines: package_json_engines,
include_node_modules: IncludeNodeModules::from(context),
Expand All @@ -406,7 +405,8 @@ impl TargetRequest {
.source_maps
.then(TargetSourceMapOptions::default),
source_type: SourceType::Module,
}),
}
.into(),
loc: None,
name: String::from("default"),
public_url: self.default_target_options.public_url.clone(),
Expand Down Expand Up @@ -538,7 +538,7 @@ impl TargetRequest {
}
},
dist_entry,
env: Arc::new(Environment {
env: Environment {
context,
engines,
include_node_modules: target_descriptor
Expand Down Expand Up @@ -569,7 +569,8 @@ impl TargetRequest {
},
},
..Environment::default()
}),
}
.into(),
loc: None, // TODO
name: String::from(target_name),
public_url: target_descriptor
Expand Down Expand Up @@ -672,10 +673,11 @@ mod tests {
fn default_target() -> Target {
Target {
dist_dir: PathBuf::from("packages/test/dist"),
env: Arc::new(Environment {
env: Environment {
output_format: OutputFormat::Global,
..Environment::default()
}),
}
.into(),
name: String::from("default"),
..Target::default()
}
Expand Down Expand Up @@ -955,7 +957,8 @@ mod tests {
context: EnvironmentContext::Browser,
output_format: OutputFormat::CommonJS,
..builtin_default_env()
}),
})
.into(),
name: String::from("browser"),
..Target::default()
}]
Expand Down Expand Up @@ -990,7 +993,8 @@ mod tests {
context: EnvironmentContext::Browser,
output_format: OutputFormat::EsModule,
..builtin_default_env()
}),
})
.into(),
name: String::from("browser"),
..Target::default()
}]
Expand All @@ -1013,7 +1017,8 @@ mod tests {
context: EnvironmentContext::Node,
output_format: OutputFormat::CommonJS,
..builtin_default_env()
}),
})
.into(),
name: String::from("main"),
..Target::default()
}]
Expand Down Expand Up @@ -1049,7 +1054,8 @@ mod tests {
output_format: OutputFormat::CommonJS,
should_optimize: true,
..builtin_default_env()
}),
})
.into(),
name: String::from("main"),
..Target::default()
}]
Expand All @@ -1072,7 +1078,8 @@ mod tests {
context: EnvironmentContext::Node,
output_format: OutputFormat::EsModule,
..builtin_default_env()
}),
})
.into(),
name: String::from("module"),
..Target::default()
}]
Expand Down Expand Up @@ -1108,7 +1115,8 @@ mod tests {
output_format: OutputFormat::EsModule,
should_optimize: true,
..builtin_default_env()
}),
})
.into(),
name: String::from("module"),
..Target::default()
}]
Expand Down Expand Up @@ -1143,7 +1151,8 @@ mod tests {
context: EnvironmentContext::Node,
output_format: OutputFormat::EsModule,
..builtin_default_env()
}),
})
.into(),
name: String::from("types"),
..Target::default()
}]
Expand All @@ -1166,7 +1175,8 @@ mod tests {
context: EnvironmentContext::Node,
output_format: OutputFormat::CommonJS,
..builtin_default_env()
}),
})
.into(),
name: String::from("types"),
..Target::default()
}]
Expand Down Expand Up @@ -1211,7 +1221,8 @@ mod tests {
context: EnvironmentContext::Browser,
output_format: OutputFormat::CommonJS,
..env()
}),
})
.into(),
name: String::from("browser"),
..Target::default()
},
Expand All @@ -1222,7 +1233,8 @@ mod tests {
context: EnvironmentContext::Node,
output_format: OutputFormat::CommonJS,
..env()
}),
})
.into(),
name: String::from("main"),
..Target::default()
},
Expand All @@ -1233,7 +1245,8 @@ mod tests {
context: EnvironmentContext::Node,
output_format: OutputFormat::EsModule,
..env()
}),
})
.into(),
name: String::from("module"),
..Target::default()
},
Expand All @@ -1244,7 +1257,8 @@ mod tests {
context: EnvironmentContext::Node,
output_format: OutputFormat::CommonJS,
..env()
}),
})
.into(),
name: String::from("types"),
..Target::default()
},
Expand Down Expand Up @@ -1272,7 +1286,8 @@ mod tests {
should_optimize: true,
should_scope_hoist: false,
..Environment::default()
}),
})
.into(),
name: String::from("custom"),
..Target::default()
}]
Expand Down Expand Up @@ -1312,7 +1327,8 @@ mod tests {
output_format: OutputFormat::CommonJS,
should_optimize: true,
..Environment::default()
}),
})
.into(),
name: String::from("custom"),
..Target::default()
}]
Expand Down Expand Up @@ -1355,7 +1371,8 @@ mod tests {
output_format: OutputFormat::Global,
should_optimize: true,
..Environment::default()
}),
})
.into(),
name: String::from("custom"),
..Target::default()
}]
Expand All @@ -1380,7 +1397,8 @@ mod tests {
output_format: OutputFormat::CommonJS,
should_optimize: true,
..Environment::default()
}),
})
.into(),
name: String::from("custom"),
..Target::default()
}]
Expand Down Expand Up @@ -1458,7 +1476,8 @@ mod tests {
output_format,
should_optimize: true,
..Environment::default()
}),
})
.into(),
name: String::from("custom"),
..Target::default()
}],
Expand Down
1 change: 1 addition & 0 deletions crates/atlaspack_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ atlaspack_sourcemap = { path = "../atlaspack_sourcemap" }
atlaspack_filesystem = { path = "../atlaspack_filesystem" }
caniuse_database = { path = "../caniuse_database" }

thread_local = { workspace = true }
anyhow = { workspace = true }
async-trait = { workspace = true }
bitflags = { workspace = true }
Expand Down
8 changes: 4 additions & 4 deletions crates/atlaspack_core/src/types/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use super::environment::Environment;
use super::file_type::FileType;
use super::json::JSONObject;
use super::symbol::Symbol;
use super::Dependency;
use super::{BundleBehavior, SourceMap};
use super::{Dependency, EnvironmentRef};

pub type AssetId = String;

Expand Down Expand Up @@ -154,7 +154,7 @@ pub struct Asset {
pub bundle_behavior: MaybeBundleBehavior,

/// The environment of the asset
pub env: Arc<Environment>,
pub env: EnvironmentRef,

/// The file path to the asset
pub file_path: PathBuf,
Expand Down Expand Up @@ -295,7 +295,7 @@ impl Asset {

Ok(Self {
code,
env,
env: env.into(),
file_path,
file_type,
id,
Expand Down Expand Up @@ -337,7 +337,7 @@ impl Asset {
Self {
bundle_behavior: Some(BundleBehavior::Inline),
code,
env,
env: env.into(),
file_path,
file_type,
id,
Expand Down
7 changes: 4 additions & 3 deletions crates/atlaspack_core/src/types/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use super::json::JSONObject;
use super::source::SourceLocation;
use super::symbol::Symbol;
use super::target::Target;
use super::EnvironmentRef;
use super::FileType;

#[allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -49,7 +50,7 @@ pub fn create_dependency_id(
}

/// A dependency denotes a connection between two assets
#[derive(Hash, PartialEq, Clone, Debug, Default, Deserialize, Serialize)]
#[derive(Hash, PartialEq, Clone, Debug, Deserialize, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Dependency {
/// Controls the behavior of the bundle the resolved asset is placed into
Expand All @@ -59,7 +60,7 @@ pub struct Dependency {
pub bundle_behavior: MaybeBundleBehavior,

/// The environment of the dependency
pub env: Arc<Environment>,
pub env: EnvironmentRef,

/// The location within the source file where the dependency was found
#[serde(default)]
Expand Down Expand Up @@ -190,7 +191,7 @@ impl Dependency {

pub fn new(specifier: String, env: Arc<Environment>) -> Dependency {
Dependency {
env,
env: env.into(),
meta: JSONObject::new(),
specifier,
..Dependency::default()
Expand Down
Loading
Loading