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: fix: add context nanoid to avoid confusion in mutiply build in one process #1305

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
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 id: 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(),
id: nanoid!(6),
}
}
}
Expand Down Expand Up @@ -320,6 +323,7 @@ impl Compiler {
stats_info: StatsInfo::new(),
resolvers,
optimize_infos: Mutex::new(None),
id: 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.id, 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.id, 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.id, 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.id, 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.id, _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.id, resource.get_resolved_path(), exports_all) }"#
)]
fn parse_barrel_file(
resource: &ResolverResource,
Expand Down