Skip to content

Commit

Permalink
replace EcmascriptModuleAssetVc::new with ReferenceType::Internal
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed May 25, 2023
1 parent d728639 commit a1b2c13
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 89 deletions.
8 changes: 3 additions & 5 deletions packages/next-swc/crates/next-core/src/app_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ use crate::{
get_entrypoints, get_global_metadata, Components, Entrypoint, GlobalMetadataVc, LoaderTree,
LoaderTreeVc, Metadata, MetadataItem, MetadataWithAltItem, OptionAppDirVc,
},
asset_helpers::as_es_module_asset,
bootstrap::{route_bootstrap, BootstrapConfigVc},
embed_js::{next_asset, next_js_file, next_js_file_path},
env::env_for_js,
Expand Down Expand Up @@ -890,12 +889,11 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}";
.push(format!("import {identifier} from \"{inner_module_id}\";"));
state.inner_assets.insert(
inner_module_id,
as_es_module_asset(
state.context.process(
TextContentSourceAssetVc::new(SourceAssetVc::new(*alt_path).into())
.into(),
state.context,
)
.into(),
Value::new(ReferenceType::Internal(InnerAssetsVc::empty())),
),
);
writeln!(state.loader_tree_code, "{s} alt: {identifier},")?;
}
Expand Down
27 changes: 0 additions & 27 deletions packages/next-swc/crates/next-core/src/asset_helpers.rs

This file was deleted.

9 changes: 3 additions & 6 deletions packages/next-swc/crates/next-core/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ use turbopack_binding::turbopack::{
ecmascript::{resolve::esm_resolve, utils::StringifyJs, EcmascriptModuleAssetVc},
};

use crate::asset_helpers::as_es_module_asset;

#[turbo_tasks::function]
pub async fn route_bootstrap(
asset: AssetVc,
Expand Down Expand Up @@ -102,7 +100,7 @@ pub async fn bootstrap(
config.insert("PAGE".to_string(), path.to_string());
config.insert("PATHNAME".to_string(), pathname);

let config_asset = as_es_module_asset(
let config_asset = context.process(
VirtualAssetVc::new(
asset.ident().path().join("bootstrap-config.ts"),
File::from(
Expand All @@ -115,9 +113,8 @@ pub async fn bootstrap(
.into(),
)
.as_asset(),
context,
)
.as_asset();
Value::new(ReferenceType::Internal(InnerAssetsVc::empty())),
);

let mut inner_assets = inner_assets.await?.clone_value();
inner_assets.insert("ENTRY".to_string(), asset);
Expand Down
1 change: 0 additions & 1 deletion packages/next-swc/crates/next-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod app_render;
mod app_segment_config;
mod app_source;
pub mod app_structure;
mod asset_helpers;
mod babel;
mod bootstrap;
mod embed_js;
Expand Down
15 changes: 4 additions & 11 deletions packages/next-swc/crates/next-core/src/next_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@ use turbopack_binding::{
context::AssetContext,
ident::AssetIdentVc,
issue::{Issue, IssueContextExt, IssueSeverity, IssueSeverityVc, IssueVc},
reference_type::{EntryReferenceSubType, ReferenceType},
reference_type::{EntryReferenceSubType, InnerAssetsVc, ReferenceType},
resolve::{
find_context_file,
options::{ImportMap, ImportMapping},
FindContextFileResult, ResolveAliasMap, ResolveAliasMapVc,
},
source_asset::SourceAssetVc,
},
ecmascript::{
EcmascriptInputTransformsVc, EcmascriptModuleAssetType, EcmascriptModuleAssetVc,
},
ecmascript_plugin::transform::{
emotion::EmotionTransformConfig, relay::RelayConfig,
styled_components::StyledComponentsTransformConfig,
Expand Down Expand Up @@ -670,15 +667,11 @@ pub async fn load_next_config_internal(
let config_changed = config_asset.map_or_else(CompletionVc::immutable, |config_asset| {
// This invalidates the execution when anything referenced by the config file
// changes
let config_asset = EcmascriptModuleAssetVc::new(
let config_asset = context.process(
config_asset.into(),
context,
Value::new(EcmascriptModuleAssetType::Ecmascript),
EcmascriptInputTransformsVc::cell(vec![]),
Default::default(),
context.compile_time_info(),
Value::new(ReferenceType::Internal(InnerAssetsVc::empty())),
);
any_content_changed(config_asset.into())
any_content_changed(config_asset)
});
let load_next_config_asset = context.process(
next_asset("entry/config/next.js"),
Expand Down
39 changes: 20 additions & 19 deletions packages/next-swc/crates/next-core/src/next_font/google/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,11 @@ async fn get_mock_stylesheet(
tasks_fs::{DiskFileSystemVc, File, FileSystem},
},
turbopack::{
core::{context::AssetContext, ident::AssetIdentVc},
core::{
context::AssetContext,
ident::AssetIdentVc,
reference_type::{InnerAssetsVc, ReferenceType},
},
ecmascript::{
EcmascriptInputTransformsVc, EcmascriptModuleAssetType, EcmascriptModuleAssetVc,
},
Expand Down Expand Up @@ -440,26 +444,23 @@ async fn get_mock_stylesheet(
} = *execution_context.await?;
let context = node_evaluate_asset_context(execution_context, None, None);
let loader_path = mock_fs.root().join("loader.js");
let mocked_response_asset = EcmascriptModuleAssetVc::new(
VirtualAssetVc::new(
loader_path,
File::from(format!(
"import data from './{}'; export default function load() {{ return data; }};",
response_path
.file_name()
.context("Must exist")?
.to_string_lossy(),
))
let mocked_response_asset = context
.process(
VirtualAssetVc::new(
loader_path,
File::from(format!(
"import data from './{}'; export default function load() {{ return data; }};",
response_path
.file_name()
.context("Must exist")?
.to_string_lossy(),
))
.into(),
)
.into(),
Value::new(ReferenceType::Internal(InnerAssetsVc::empty())),
)
.into(),
context,
Value::new(EcmascriptModuleAssetType::Ecmascript),
EcmascriptInputTransformsVc::cell(vec![]),
Default::default(),
context.compile_time_info(),
)
.into();
.into();

let root = mock_fs.root();
let val = evaluate(
Expand Down
7 changes: 4 additions & 3 deletions packages/next-swc/crates/next-core/src/page_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ impl PageLoaderAssetVc {
let module = this.client_context.process(
loader_entry_asset,
Value::new(ReferenceType::Internal(
InnerAssetsVc::cell(indexmap! {
"PAGE".to_string() => this.client_context.process(this.entry_asset, Value::new(ReferenceType::Entry(EntryReferenceSubType::Page)))
}))),
InnerAssetsVc::cell(indexmap! {
"PAGE".to_string() => this.client_context.process(this.entry_asset, Value::new(ReferenceType::Entry(EntryReferenceSubType::Page)))
})
)),
);

let Some(module) = EvaluatableAssetVc::resolve_from(module).await? else {
Expand Down
30 changes: 13 additions & 17 deletions packages/next-swc/crates/next-core/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use turbopack_binding::{
},
turbopack::{
core::{
asset::AssetVc,
asset::{AssetOptionVc, AssetVc},
changed::any_content_changed,
chunk::ChunkingContext,
context::{AssetContext, AssetContextVc},
Expand All @@ -29,7 +29,6 @@ use turbopack_binding::{
virtual_asset::VirtualAssetVc,
},
dev::DevChunkingContextVc,
ecmascript::OptionEcmascriptModuleAssetVc,
node::{
evaluate::evaluate,
execution_context::{ExecutionContext, ExecutionContextVc},
Expand All @@ -42,7 +41,6 @@ use turbopack_binding::{
};

use crate::{
asset_helpers::as_es_module_asset,
embed_js::next_asset,
mode::NextMode,
next_config::NextConfigVc,
Expand Down Expand Up @@ -143,16 +141,16 @@ async fn get_config(
context: AssetContextVc,
project_path: FileSystemPathVc,
configs: StringsVc,
) -> Result<OptionEcmascriptModuleAssetVc> {
) -> Result<AssetOptionVc> {
let find_config_result = find_context_file(project_path, configs);
let config_asset = match &*find_config_result.await? {
FindContextFileResult::Found(config_path, _) => Some(as_es_module_asset(
FindContextFileResult::Found(config_path, _) => Some(context.process(
SourceAssetVc::new(*config_path).as_asset(),
context,
Value::new(ReferenceType::Internal(InnerAssetsVc::empty())),
)),
FindContextFileResult::NotFound(_) => None,
};
Ok(OptionEcmascriptModuleAssetVc::cell(config_asset))
Ok(AssetOptionVc::cell(config_asset))
}

#[turbo_tasks::function]
Expand Down Expand Up @@ -184,30 +182,29 @@ async fn config_assets(
let (manifest, config) = match &*middleware_config {
Some(c) => {
let manifest = context.with_transition("next-edge").process(
c.as_asset(),
*c,
Value::new(ReferenceType::EcmaScriptModules(
EcmaScriptModulesReferenceSubType::Undefined,
)),
);
let config = parse_config_from_source(c.as_asset());
let config = parse_config_from_source(*c);
(manifest, config)
}
None => {
let manifest = as_es_module_asset(
let manifest = context.process(
VirtualAssetVc::new(
project_path.join("middleware.js"),
File::from("export default [];").into(),
)
.as_asset(),
context,
)
.as_asset();
Value::new(ReferenceType::Internal(InnerAssetsVc::empty())),
);
let config = NextSourceConfigVc::default();
(manifest, config)
}
};

let config_asset = as_es_module_asset(
let config_asset = context.process(
VirtualAssetVc::new(
project_path.join("middleware_config.js"),
File::from(format!(
Expand All @@ -217,9 +214,8 @@ async fn config_assets(
.into(),
)
.as_asset(),
context,
)
.as_asset();
Value::new(ReferenceType::Internal(InnerAssetsVc::empty())),
);

Ok(InnerAssetsVc::cell(indexmap! {
"MIDDLEWARE_CHUNK_GROUP".to_string() => manifest,
Expand Down

0 comments on commit a1b2c13

Please sign in to comment.