Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk committed Dec 24, 2024
1 parent d95adb8 commit 11003c6
Show file tree
Hide file tree
Showing 6 changed files with 449 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ esbuild.cpuprofile
!packages/rspack-test-tools/tests/treeShakingCases/node_modules

# Binding artifacts
artifacts
/artifacts/

# Node Addons
npm/**/*.node
Expand Down
28 changes: 28 additions & 0 deletions crates/rspack_core/src/artifacts/cgm_hash_artifact.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use rspack_collections::IdentifierMap;
use rspack_hash::RspackHashDigest;

use crate::{ModuleIdentifier, RuntimeSpec, RuntimeSpecMap};

#[derive(Debug, Default)]
pub struct CgmHashArtifact {
module_to_hashes: IdentifierMap<RuntimeSpecMap<RspackHashDigest>>,
}

impl CgmHashArtifact {
pub fn is_empty(&self) -> bool {
self.module_to_hashes.is_empty()
}

pub fn get(&self, module: &ModuleIdentifier, runtime: &RuntimeSpec) -> Option<&RspackHashDigest> {
let hashes = self.module_to_hashes.get(module)?;
hashes.get(runtime)
}

pub fn set_hashes(&mut self, module: ModuleIdentifier, hashes: RuntimeSpecMap<RspackHashDigest>) {
self.module_to_hashes.insert(module, hashes);
}

pub fn remove(&mut self, module: &ModuleIdentifier) -> Option<RuntimeSpecMap<RspackHashDigest>> {
self.module_to_hashes.remove(module)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use rspack_collections::IdentifierMap;

use crate::{ModuleIdentifier, RuntimeGlobals, RuntimeSpec, RuntimeSpecMap};

#[derive(Debug, Default)]
pub struct CgmRuntimeRequirementsArtifact {
module_to_runtime_requirements: IdentifierMap<RuntimeSpecMap<RuntimeGlobals>>,
}

impl CgmRuntimeRequirementsArtifact {
pub fn is_empty(&self) -> bool {
self.module_to_runtime_requirements.is_empty()
}

pub fn get(&self, module: &ModuleIdentifier, runtime: &RuntimeSpec) -> Option<&RuntimeGlobals> {
let requirements = self.module_to_runtime_requirements.get(module)?;
requirements.get(runtime)
}

pub fn set_runtime_requirements(
&mut self,
module: ModuleIdentifier,
runtime_requirements_map: RuntimeSpecMap<RuntimeGlobals>,
) {
self
.module_to_runtime_requirements
.insert(module, runtime_requirements_map);
}

pub fn remove(&mut self, module: &ModuleIdentifier) -> Option<RuntimeSpecMap<RuntimeGlobals>> {
self.module_to_runtime_requirements.remove(module)
}
}
Loading

0 comments on commit 11003c6

Please sign in to comment.