Skip to main content

turbopack/
runtime_asset_context.rs

1use turbo_rcstr::rcstr;
2use turbo_tasks::{ResolvedVc, Result, Vc};
3use turbopack_core::{
4    compile_time_info::CompileTimeInfo, context::AssetContext, environment::Environment,
5    ident::Layer,
6};
7
8use crate::{
9    ModuleAssetContext,
10    module_options::{EcmascriptOptionsContext, ModuleOptionsContext, TypescriptTransformOptions},
11};
12
13/// Returns the runtime asset context used to compile embedded runtime
14/// TypeScript files (e.g. the turbopack-ecmascript-runtime JS sources).
15#[turbo_tasks::function]
16pub async fn get_runtime_asset_context(
17    environment: ResolvedVc<Environment>,
18) -> Result<Vc<Box<dyn AssetContext>>> {
19    let module_options_context = ModuleOptionsContext {
20        ecmascript: EcmascriptOptionsContext {
21            enable_typescript_transform: Some(
22                TypescriptTransformOptions::default().resolved_cell(),
23            ),
24            inline_helpers: true,
25            ..Default::default()
26        },
27        environment: Some(environment),
28        follow_reexports: true,
29        module_fragments_enabled: false,
30        ..Default::default()
31    }
32    .cell();
33    let compile_time_info = CompileTimeInfo::builder(environment).cell().await?;
34
35    let asset_context: Vc<Box<dyn AssetContext>> = Vc::upcast(ModuleAssetContext::new(
36        Default::default(),
37        compile_time_info,
38        module_options_context,
39        Vc::default(),
40        Layer::new(rcstr!("runtime")),
41    ));
42
43    Ok(asset_context)
44}