-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathcontexts.rs
More file actions
111 lines (101 loc) · 3.3 KB
/
contexts.rs
File metadata and controls
111 lines (101 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
use anyhow::Result;
use serde::{Deserialize, Serialize};
use turbo_rcstr::RcStr;
use turbo_tasks::{TaskInput, Vc, trace::TraceRawVcs};
use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{
chunk::{
ChunkingContext, MangleType, MinifyType, SourceMapsType,
module_id_strategies::ModuleIdStrategy,
},
environment::Environment,
module_graph::export_usage::OptionExportUsageInfo,
};
use crate::{config::Config, mode::Mode};
use super::LibraryChunkingContext;
#[derive(Clone, Debug, PartialEq, Eq, Hash, TaskInput, TraceRawVcs, Serialize, Deserialize)]
pub struct LibraryChunkingContextOptions {
pub mode: Vc<Mode>,
pub root_path: FileSystemPath,
pub output_root: FileSystemPath,
pub output_root_to_root_path: RcStr,
pub environment: Vc<Environment>,
pub module_id_strategy: Vc<Box<dyn ModuleIdStrategy>>,
pub no_mangling: Vc<bool>,
pub runtime_root: Vc<Option<RcStr>>,
pub runtime_export: Vc<Vec<RcStr>>,
pub config: Vc<Config>,
pub export_usage: Vc<OptionExportUsageInfo>,
}
#[turbo_tasks::function]
pub async fn get_library_chunking_context(
options: LibraryChunkingContextOptions,
) -> Result<Vc<Box<dyn ChunkingContext>>> {
let LibraryChunkingContextOptions {
mode,
root_path,
output_root,
output_root_to_root_path,
environment,
module_id_strategy,
no_mangling,
runtime_root,
runtime_export,
config,
export_usage,
} = options;
let minify = config.minify(mode);
let concatenate_modules = config.concatenate_modules(mode);
let mode = mode.await?;
let runtime_type = {
#[cfg(feature = "test")]
{
use turbopack_ecmascript_runtime::RuntimeType;
match config.runtime_type_str().await?.as_deref() {
Some(rt) if rt.eq_ignore_ascii_case("Development") => RuntimeType::Development,
Some(rt) if rt.eq_ignore_ascii_case("Production") => RuntimeType::Production,
_ => RuntimeType::Dummy,
}
}
#[cfg(not(feature = "test"))]
{
mode.runtime_type()
}
};
let output = config.output().await?;
let mut builder = LibraryChunkingContext::builder(
root_path,
output_root,
output_root_to_root_path,
environment.to_resolved().await?,
runtime_type,
(*runtime_root.await?).clone(),
(*runtime_export.await?).clone(),
)
.minify_type(if mode.is_production() && *minify.await? {
MinifyType::Minify {
mangle: (!*no_mangling.await?).then_some(MangleType::OptimalSize),
}
} else {
MinifyType::NoMinify
})
.source_maps(if *config.source_maps().await? {
SourceMapsType::Full
} else {
SourceMapsType::None
})
.asset_base_path(output.asset_prefix.clone())
.module_id_strategy(module_id_strategy.to_resolved().await?)
.export_usage(*export_usage.await?);
if !mode.is_development()
&& let Some(filename) = &output.filename
{
builder = builder.filename(filename.clone());
}
if mode.is_development() {
builder = builder.use_file_source_map_uris();
} else {
builder = builder.module_merging(*concatenate_modules.await?)
}
Ok(Vc::upcast(builder.build()))
}