Skip to content

Commit

Permalink
fix: add context nanoid to avoid confusion in mutiply build in one pr…
Browse files Browse the repository at this point in the history
…ocess
  • Loading branch information
Jinbao1001 committed Jun 25, 2024
1 parent 9bd915b commit 95ee5a9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions crates/mako/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use mako_core::swc_common::sync::Lrc;
use mako_core::swc_common::{Globals, SourceMap, DUMMY_SP};
use mako_core::swc_ecma_ast::Ident;
use mako_core::tracing::debug;
use nanoid::nanoid;

use crate::ast::comments::Comments;
use crate::config::{Config, OutputMode};
Expand All @@ -37,6 +38,7 @@ pub struct Context {
pub resolvers: Resolvers,
pub static_cache: RwLock<MemoryChunkFileCache>,
pub optimize_infos: Mutex<Option<Vec<OptimizeChunksInfo>>>,
pub nanoid: String,
}

#[derive(Default)]
Expand Down Expand Up @@ -123,6 +125,7 @@ impl Default for Context {
resolvers,
optimize_infos: Mutex::new(None),
static_cache: Default::default(),
nanoid: nanoid!(6),
}
}
}
Expand Down Expand Up @@ -320,6 +323,7 @@ impl Compiler {
stats_info: StatsInfo::new(),
resolvers,
optimize_infos: Mutex::new(None),
nanoid: nanoid!(6),
}),
})
}
Expand Down
6 changes: 3 additions & 3 deletions crates/mako/src/generate/chunk_pot/ast_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::generate::transform::transform_css_generate;
type = "SizedCache<String , ChunkFile>",
create = "{ SizedCache::with_size(500) }",
key = "String",
convert = r#"{format!("{}.{:x}",chunk_pot.chunk_id,chunk_pot.stylesheet.as_ref().unwrap().raw_hash)}"#
convert = r#"{format!("{}.{}.{:x}",context.nanoid, chunk_pot.chunk_id,chunk_pot.stylesheet.as_ref().unwrap().raw_hash)}"#
)]
pub(crate) fn render_css_chunk(
chunk_pot: &ChunkPot,
Expand Down Expand Up @@ -123,7 +123,7 @@ pub(crate) fn render_css_chunk(
type = "SizedCache<String , ChunkFile>",
create = "{ SizedCache::with_size(500) }",
key = "String",
convert = r#"{format!("{}.{:x}", chunk_pot.chunk_id, chunk_pot.js_hash)}"#
convert = r#"{format!("{}.{}.{:x}", context.nanoid, chunk_pot.chunk_id, chunk_pot.js_hash)}"#
)]
pub(crate) fn render_normal_js_chunk(
chunk_pot: &ChunkPot,
Expand Down Expand Up @@ -210,7 +210,7 @@ pub(crate) fn render_entry_js_chunk(
#[cached(
result = true,
key = "String",
convert = r#"{format!("{}",pot.js_hash)}"#
convert = r#"{format!("{}.{}", context.nanoid, pot.js_hash)}"#
)]
fn render_entry_chunk_js_without_full_hash(
pot: &ChunkPot,
Expand Down
4 changes: 2 additions & 2 deletions crates/mako/src/generate/chunk_pot/str_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub(super) fn render_entry_js_chunk(
type = "SizedCache<String , ChunkFile>",
create = "{ SizedCache::with_size(500) }",
key = "String",
convert = r#"{format!("{}.{:x}", chunk_pot.chunk_id, chunk_pot.js_hash)}"#
convert = r#"{format!("{}.{}.{:x}", context.nanoid, chunk_pot.chunk_id, chunk_pot.js_hash)}"#
)]
pub(super) fn render_normal_js_chunk(
chunk_pot: &ChunkPot,
Expand Down Expand Up @@ -155,7 +155,7 @@ type EmittedWithMapping = (String, Option<Vec<(BytePos, LineCol)>>);
key = "String",
type = "SizedCache<String , EmittedWithMapping>",
create = "{ SizedCache::with_size(20000) }",
convert = r#"{format!("{}-{}", _raw_hash, module_id)}"#
convert = r#"{format!("{}-{}-{}", context.nanoid, _raw_hash, module_id)}"#
)]
fn emit_module_with_mapping(
module_id: &str,
Expand Down
2 changes: 1 addition & 1 deletion crates/mako/src/visitors/optimize_package_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ fn build_import_stmts(
#[cached(
result = true,
key = "String",
convert = r#"{ format!("{:?}_{:}", resource.get_resolved_path(), exports_all) }"#
convert = r#"{ format!("{}_{:?}_{:}", context.nanoid, resource.get_resolved_path(), exports_all) }"#
)]
fn parse_barrel_file(
resource: &ResolverResource,
Expand Down

0 comments on commit 95ee5a9

Please sign in to comment.