From 95ee5a9dac84b812a5904d528c93aa19b3187bb9 Mon Sep 17 00:00:00 2001 From: Jinbao1001 Date: Tue, 25 Jun 2024 11:26:27 +0800 Subject: [PATCH] fix: add context nanoid to avoid confusion in mutiply build in one process --- crates/mako/src/compiler.rs | 4 ++++ crates/mako/src/generate/chunk_pot/ast_impl.rs | 6 +++--- crates/mako/src/generate/chunk_pot/str_impl.rs | 4 ++-- crates/mako/src/visitors/optimize_package_imports.rs | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/mako/src/compiler.rs b/crates/mako/src/compiler.rs index a94be0bb9..06d71cceb 100644 --- a/crates/mako/src/compiler.rs +++ b/crates/mako/src/compiler.rs @@ -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}; @@ -37,6 +38,7 @@ pub struct Context { pub resolvers: Resolvers, pub static_cache: RwLock, pub optimize_infos: Mutex>>, + pub nanoid: String, } #[derive(Default)] @@ -123,6 +125,7 @@ impl Default for Context { resolvers, optimize_infos: Mutex::new(None), static_cache: Default::default(), + nanoid: nanoid!(6), } } } @@ -320,6 +323,7 @@ impl Compiler { stats_info: StatsInfo::new(), resolvers, optimize_infos: Mutex::new(None), + nanoid: nanoid!(6), }), }) } diff --git a/crates/mako/src/generate/chunk_pot/ast_impl.rs b/crates/mako/src/generate/chunk_pot/ast_impl.rs index 56aa50b74..3ddad2b1a 100644 --- a/crates/mako/src/generate/chunk_pot/ast_impl.rs +++ b/crates/mako/src/generate/chunk_pot/ast_impl.rs @@ -33,7 +33,7 @@ use crate::generate::transform::transform_css_generate; type = "SizedCache", 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, @@ -123,7 +123,7 @@ pub(crate) fn render_css_chunk( type = "SizedCache", 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, @@ -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, diff --git a/crates/mako/src/generate/chunk_pot/str_impl.rs b/crates/mako/src/generate/chunk_pot/str_impl.rs index 1621199e1..767363232 100644 --- a/crates/mako/src/generate/chunk_pot/str_impl.rs +++ b/crates/mako/src/generate/chunk_pot/str_impl.rs @@ -106,7 +106,7 @@ pub(super) fn render_entry_js_chunk( type = "SizedCache", 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, @@ -155,7 +155,7 @@ type EmittedWithMapping = (String, Option>); key = "String", type = "SizedCache", 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, diff --git a/crates/mako/src/visitors/optimize_package_imports.rs b/crates/mako/src/visitors/optimize_package_imports.rs index 9cd106cf9..ddfa7dbe1 100644 --- a/crates/mako/src/visitors/optimize_package_imports.rs +++ b/crates/mako/src/visitors/optimize_package_imports.rs @@ -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,