Refactor ES chunk evaluate logic into a Runtime trait (#47116)

This is the Next.js side of https://github.com/vercel/turbo/pull/4141
This commit is contained in:
Alex Kirszenberg 2023-03-22 11:28:49 +01:00 committed by GitHub
parent f029023a3c
commit 8195e1947b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 385 additions and 340 deletions

File diff suppressed because it is too large Load diff

View file

@ -46,36 +46,37 @@ swc_emotion = { version = "0.29.10" }
testing = { version = "0.31.31" }
# Turbo crates
auto-hash-map = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
node-file-trace = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
swc-ast-explorer = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbo-malloc = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1", default-features = false }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbo-tasks-build = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbo-tasks-env = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbo-tasks-fetch = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1", default-features = false }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbo-tasks-hash = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbo-tasks-macros = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbo-tasks-macros-shared = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbo-tasks-memory = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbo-tasks-testing = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbo-updater = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbopack = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbopack-cli-utils = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbopack-core = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbopack-create-test-app = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbopack-css = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbopack-dev-server = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbopack-ecmascript = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbopack-env = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbopack-json = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbopack-mdx = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbopack-node = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbopack-static = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbopack-swc-utils = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbopack-test-utils = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
turbopack-tests = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230321.1" }
auto-hash-map = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
node-file-trace = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
swc-ast-explorer = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbo-malloc = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2", default-features = false }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbo-tasks-build = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbo-tasks-env = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbo-tasks-fetch = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2", default-features = false }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbo-tasks-hash = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbo-tasks-macros = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbo-tasks-macros-shared = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbo-tasks-memory = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbo-tasks-testing = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbo-updater = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbopack = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbopack-cli-utils = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbopack-core = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbopack-create-test-app = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbopack-css = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbopack-dev = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbopack-dev-server = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbopack-ecmascript = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbopack-env = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbopack-json = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbopack-mdx = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbopack-node = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbopack-static = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbopack-swc-utils = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbopack-test-utils = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
turbopack-tests = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230322.2" }
# General Deps

View file

@ -26,6 +26,7 @@ turbo-tasks-fs = { workspace = true }
turbo-tasks-hash = { workspace = true }
turbopack = { workspace = true }
turbopack-core = { workspace = true }
turbopack-dev = { workspace = true }
turbopack-dev-server = { workspace = true }
turbopack-ecmascript = { workspace = true }
turbopack-env = { workspace = true }

View file

@ -9,7 +9,7 @@
"build:compiled": "node build.mjs"
},
"dependencies": {
"@vercel/turbopack-runtime": "https://gitpkg.now.sh/vercel/turbo/crates/turbopack-ecmascript/js?8a8038f94",
"@vercel/turbopack-dev-runtime": "https://gitpkg.now.sh/vercel/turbo/crates/turbopack-dev/js?turbopack-230321.3",
"anser": "^2.1.1",
"css.escape": "^1.5.1",
"next": "*",

View file

@ -8,13 +8,13 @@ import type {
Issue,
ResourceIdentifier,
ServerMessage,
} from "@vercel/turbopack-runtime/types/protocol";
} from "@vercel/turbopack-dev-runtime/types/protocol";
import type {
ChunkPath,
ModuleId,
UpdateCallback,
TurbopackGlobals,
} from "@vercel/turbopack-runtime/types";
} from "@vercel/turbopack-dev-runtime/types";
import stripAnsi from "@vercel/turbopack-next/compiled/strip-ansi";

View file

@ -1,4 +1,4 @@
import type { Issue } from "@vercel/turbopack-runtime/types/protocol";
import type { Issue } from "@vercel/turbopack-dev-runtime/types/protocol";
import * as Bus from "./internal/bus";
import { parseStack } from "./internal/helpers/parseStack";

View file

@ -1,6 +1,6 @@
import * as React from "react";
import type { Issue } from "@vercel/turbopack-runtime/types/protocol";
import type { Issue } from "@vercel/turbopack-dev-runtime/types/protocol";
import * as Bus from "./bus";
import { ShadowPortal } from "./components/ShadowPortal";

View file

@ -1,6 +1,6 @@
import { StackFrame } from "stacktrace-parser";
import type { Issue } from "@vercel/turbopack-runtime/types/protocol";
import type { Issue } from "@vercel/turbopack-dev-runtime/types/protocol";
export const TYPE_BUILD_OK = "build-ok";
export const TYPE_TURBOPACK_ISSUES = "turbopack-error";

View file

@ -1,6 +1,6 @@
import * as React from 'react'
import { Issue } from '@vercel/turbopack-runtime/types/protocol'
import { Issue } from '@vercel/turbopack-dev-runtime/types/protocol'
import {
TYPE_UNHANDLED_ERROR,

View file

@ -1,4 +1,4 @@
import { Issue } from '@vercel/turbopack-runtime/types/protocol'
import { Issue } from '@vercel/turbopack-dev-runtime/types/protocol'
import { LeftRightDialogHeader } from '../components/LeftRightDialogHeader'
import { DialogBody, DialogBodyProps } from '../components/Dialog'

View file

@ -1,3 +1,3 @@
import { ChunkPath } from "@vercel/turbopack-runtime/types";
import { ChunkPath } from "@vercel/turbopack-dev-runtime/types";
export type ChunkGroup = ChunkPath[];

View file

@ -15,7 +15,6 @@ use turbopack::{
ModuleAssetContextVc,
};
use turbopack_core::{
chunk::dev::DevChunkingContextVc,
compile_time_info::CompileTimeInfoVc,
context::{AssetContext, AssetContextVc},
environment::{EnvironmentIntention, ServerAddrVc},
@ -23,6 +22,7 @@ use turbopack_core::{
source_asset::SourceAssetVc,
virtual_asset::VirtualAssetVc,
};
use turbopack_dev::DevChunkingContextVc;
use turbopack_dev_server::{
html::DevHtmlAssetVc,
source::{
@ -30,7 +30,7 @@ use turbopack_dev_server::{
},
};
use turbopack_ecmascript::{
chunk::EcmascriptChunkPlaceablesVc, magic_identifier, utils::stringify_js,
chunk::EcmascriptChunkPlaceablesVc, magic_identifier, utils::StringifyJs,
EcmascriptInputTransformsVc, EcmascriptModuleAssetType, EcmascriptModuleAssetVc, InnerAssetsVc,
};
use turbopack_env::ProcessEnvAssetVc;
@ -107,7 +107,6 @@ async fn next_client_transition(
Ok(NextClientTransition {
is_app: true,
server_root,
client_chunking_context,
client_module_options_context,
client_resolve_options_context,
@ -575,7 +574,7 @@ impl AppRendererVc {
));
}
}
Ok((stringify_js(segment_path), imports))
Ok((StringifyJs(segment_path).to_string(), imports))
});
futures
})
@ -600,7 +599,7 @@ impl AppRendererVc {
"import {}, {{ chunks as {} }} from {};\n",
identifier,
chunks_identifier,
stringify_js(p)
StringifyJs(p)
)?
}
}
@ -610,7 +609,7 @@ impl AppRendererVc {
r#"("TURBOPACK {{ transition: next-client }}");
import BOOTSTRAP from {};
"#,
stringify_js(&page)
StringifyJs(&page)
)?;
}
@ -621,7 +620,7 @@ import BOOTSTRAP from {};
writeln!(
result,
" {key}: {{ module: {identifier}, chunks: {chunks_identifier} }},",
key = stringify_js(key),
key = StringifyJs(key),
)?;
}
result += " },";

View file

@ -42,6 +42,7 @@ pub fn register() {
turbo_tasks::register();
turbo_tasks_fs::register();
turbo_tasks_fetch::register();
turbopack_dev::register();
turbopack_dev_server::register();
turbopack_node::register();
turbopack::register();

View file

@ -15,13 +15,14 @@ use turbopack::{
ModuleAssetContextVc,
};
use turbopack_core::{
chunk::{dev::DevChunkingContextVc, ChunkingContextVc},
chunk::ChunkingContextVc,
compile_time_defines,
compile_time_info::{CompileTimeDefinesVc, CompileTimeInfo, CompileTimeInfoVc},
context::AssetContextVc,
environment::{BrowserEnvironment, EnvironmentIntention, EnvironmentVc, ExecutionEnvironment},
resolve::{parse::RequestVc, pattern::Pattern},
};
use turbopack_dev::DevChunkingContextVc;
use turbopack_env::ProcessEnvAssetVc;
use turbopack_node::execution_context::ExecutionContextVc;

View file

@ -1,7 +1,6 @@
use anyhow::Result;
use indexmap::indexmap;
use turbo_tasks::{primitives::OptionStringVc, Value};
use turbo_tasks_fs::FileSystemPathVc;
use turbopack::{
ecmascript::chunk_group_files_asset::ChunkGroupFilesAsset,
module_options::ModuleOptionsContextVc,
@ -10,7 +9,9 @@ use turbopack::{
ModuleAssetContextVc,
};
use turbopack_core::{
asset::AssetVc, chunk::ChunkingContextVc, compile_time_info::CompileTimeInfoVc,
asset::AssetVc,
chunk::{ChunkingContext, ChunkingContextVc},
compile_time_info::CompileTimeInfoVc,
context::AssetContext,
};
use turbopack_ecmascript::{
@ -33,7 +34,6 @@ pub struct NextClientTransition {
pub client_module_options_context: ModuleOptionsContextVc,
pub client_resolve_options_context: ResolveOptionsContextVc,
pub client_chunking_context: ChunkingContextVc,
pub server_root: FileSystemPathVc,
pub runtime_entries: RuntimeEntriesVc,
}
@ -99,9 +99,10 @@ impl Transition for NextClientTransition {
let asset = ChunkGroupFilesAsset {
asset: asset.into(),
// This ensures that the chunk group files asset will strip out the _next prefix from
// all chunk paths, which is what the Next.js renderer code expects.
client_root: self.client_chunking_context.output_root().join("_next"),
chunking_context: self.client_chunking_context,
base_path: self.server_root.join("_next"),
server_root: self.server_root,
runtime_entries: Some(runtime_entries),
};

View file

@ -1,4 +1,4 @@
use anyhow::Result;
use anyhow::{bail, Result};
use turbo_tasks::{primitives::StringVc, Value};
use turbopack::ecmascript::chunk::{
EcmascriptChunkItemVc, EcmascriptChunkPlaceable, EcmascriptChunkPlaceableVc, EcmascriptChunkVc,
@ -13,6 +13,7 @@ use turbopack_core::{
ident::AssetIdentVc,
reference::AssetReferencesVc,
};
use turbopack_ecmascript::chunk::EcmascriptChunkingContextVc;
#[turbo_tasks::function]
fn modifier() -> StringVc {
@ -58,8 +59,14 @@ impl ChunkableAsset for InChunkingContextAsset {
#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for InChunkingContextAsset {
#[turbo_tasks::function]
fn as_chunk_item(&self, _context: ChunkingContextVc) -> EcmascriptChunkItemVc {
self.asset.as_chunk_item(self.chunking_context)
async fn as_chunk_item(
&self,
_context: EcmascriptChunkingContextVc,
) -> Result<EcmascriptChunkItemVc> {
let Some(chunking_context) = EcmascriptChunkingContextVc::resolve_from(&self.chunking_context).await? else {
bail!("chunking context is not an EcmascriptChunkingContext")
};
Ok(self.asset.as_chunk_item(chunking_context))
}
#[turbo_tasks::function]

View file

@ -2,13 +2,10 @@ use anyhow::{bail, Result};
use indoc::formatdoc;
use turbo_tasks::{primitives::StringVc, TryJoinIterExt, Value};
use turbo_tasks_fs::FileSystemPathVc;
use turbopack::ecmascript::{
chunk::{
EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkItemContentVc,
EcmascriptChunkItemVc, EcmascriptChunkPlaceable, EcmascriptChunkPlaceableVc,
EcmascriptChunkVc, EcmascriptExports, EcmascriptExportsVc,
},
utils::stringify_js,
use turbopack::ecmascript::chunk::{
EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkItemContentVc,
EcmascriptChunkItemVc, EcmascriptChunkPlaceable, EcmascriptChunkPlaceableVc, EcmascriptChunkVc,
EcmascriptExports, EcmascriptExportsVc,
};
use turbopack_core::{
asset::{Asset, AssetContentVc, AssetVc},
@ -20,7 +17,7 @@ use turbopack_core::{
ident::AssetIdentVc,
reference::AssetReferencesVc,
};
use turbopack_ecmascript::utils::stringify_js_pretty;
use turbopack_ecmascript::{chunk::EcmascriptChunkingContextVc, utils::StringifyJs};
#[turbo_tasks::function]
fn modifier() -> StringVc {
@ -79,7 +76,7 @@ impl EcmascriptChunkPlaceable for WithChunksAsset {
#[turbo_tasks::function]
async fn as_chunk_item(
self_vc: WithChunksAssetVc,
context: ChunkingContextVc,
context: EcmascriptChunkingContextVc,
) -> Result<EcmascriptChunkItemVc> {
Ok(WithChunksChunkItem {
context,
@ -113,20 +110,24 @@ impl WithChunksAssetVc {
#[turbo_tasks::value]
struct WithChunksChunkItem {
context: ChunkingContextVc,
context: EcmascriptChunkingContextVc,
inner: WithChunksAssetVc,
}
#[turbo_tasks::value_impl]
impl EcmascriptChunkItem for WithChunksChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> ChunkingContextVc {
fn chunking_context(&self) -> EcmascriptChunkingContextVc {
self.context
}
#[turbo_tasks::function]
async fn content(&self) -> Result<EcmascriptChunkItemContentVc> {
let inner = self.inner.await?;
let Some(inner_chunking_context) = EcmascriptChunkingContextVc::resolve_from(inner.chunking_context).await? else {
bail!("the chunking context is not an EcmascriptChunkingContextVc");
};
let group = self.inner.chunk_group();
let chunks = group.chunks().await?;
let server_root = inner.server_root.await?;
@ -144,25 +145,24 @@ impl EcmascriptChunkItem for WithChunksChunkItem {
client_chunks.push(serde_json::Value::String(path.to_string()));
}
}
let module_id = stringify_js(
&*inner
.asset
.as_chunk_item(inner.chunking_context)
.id()
.await?,
);
let module_id = &*inner
.asset
.as_chunk_item(inner_chunking_context)
.id()
.await?;
Ok(EcmascriptChunkItemContent {
inner_code: formatdoc! {
r#"
__turbopack_esm__({{
default: () => {},
chunks: () => {},
chunks: () => chunks,
chunkListPath: () => {},
}});
const chunks = {:#};
"#,
module_id,
stringify_js_pretty(&client_chunks),
stringify_js(&chunk_list_path),
StringifyJs(&module_id),
StringifyJs(&chunk_list_path),
StringifyJs(&client_chunks),
}
.into(),
..Default::default()

View file

@ -1,4 +1,4 @@
use anyhow::Result;
use anyhow::{Context, Result};
use turbo_tasks::{primitives::StringVc, Value};
use turbopack::ecmascript::chunk::{
EcmascriptChunkItemVc, EcmascriptChunkPlaceable, EcmascriptChunkPlaceableVc, EcmascriptChunkVc,
@ -13,6 +13,7 @@ use turbopack_core::{
ident::AssetIdentVc,
reference::AssetReferencesVc,
};
use turbopack_ecmascript::chunk::EcmascriptChunkingContextVc;
#[turbo_tasks::function]
fn modifier() -> StringVc {
@ -63,8 +64,18 @@ impl ChunkableAsset for WithChunkingContextScopeAsset {
#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for WithChunkingContextScopeAsset {
#[turbo_tasks::function]
fn as_chunk_item(&self, context: ChunkingContextVc) -> EcmascriptChunkItemVc {
self.asset.as_chunk_item(context.with_layer(&self.layer))
async fn as_chunk_item(
&self,
context: EcmascriptChunkingContextVc,
) -> Result<EcmascriptChunkItemVc> {
Ok(self.asset.as_chunk_item(
EcmascriptChunkingContextVc::resolve_from(context.with_layer(&self.layer))
.await?
.context(
"ChunkingContextVc::with_layer should not return a different kind of chunking \
context",
)?,
))
}
#[turbo_tasks::function]

View file

@ -1,14 +1,11 @@
use anyhow::Result;
use anyhow::{Context, Result};
use indoc::formatdoc;
use turbo_tasks::{primitives::StringVc, Value, ValueToString, ValueToStringVc};
use turbo_tasks_fs::FileSystemPathVc;
use turbopack::ecmascript::{
chunk::{
EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkItemContentVc,
EcmascriptChunkItemVc, EcmascriptChunkPlaceable, EcmascriptChunkPlaceableVc,
EcmascriptChunkVc, EcmascriptExports, EcmascriptExportsVc,
},
utils::stringify_js,
use turbopack::ecmascript::chunk::{
EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkItemContentVc,
EcmascriptChunkItemVc, EcmascriptChunkPlaceable, EcmascriptChunkPlaceableVc, EcmascriptChunkVc,
EcmascriptExports, EcmascriptExportsVc,
};
use turbopack_core::{
asset::{Asset, AssetContentVc, AssetVc},
@ -21,7 +18,7 @@ use turbopack_core::{
reference::{AssetReference, AssetReferenceVc, AssetReferencesVc},
resolve::{ResolveResult, ResolveResultVc},
};
use turbopack_ecmascript::utils::stringify_js_pretty;
use turbopack_ecmascript::{chunk::EcmascriptChunkingContextVc, utils::StringifyJs};
#[turbo_tasks::function]
fn modifier() -> StringVc {
@ -76,16 +73,21 @@ impl ChunkableAsset for WithClientChunksAsset {
#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for WithClientChunksAsset {
#[turbo_tasks::function]
fn as_chunk_item(
async fn as_chunk_item(
self_vc: WithClientChunksAssetVc,
context: ChunkingContextVc,
) -> EcmascriptChunkItemVc {
WithClientChunksChunkItem {
context: context.with_layer("rsc"),
context: EcmascriptChunkingContextVc,
) -> Result<EcmascriptChunkItemVc> {
Ok(WithClientChunksChunkItem {
context: EcmascriptChunkingContextVc::resolve_from(context.with_layer("rsc"))
.await?
.context(
"ChunkingContextVc::with_layer should not return a different kind of chunking \
context",
)?,
inner: self_vc,
}
.cell()
.into()
.into())
}
#[turbo_tasks::function]
@ -97,14 +99,14 @@ impl EcmascriptChunkPlaceable for WithClientChunksAsset {
#[turbo_tasks::value]
struct WithClientChunksChunkItem {
context: ChunkingContextVc,
context: EcmascriptChunkingContextVc,
inner: WithClientChunksAssetVc,
}
#[turbo_tasks::value_impl]
impl EcmascriptChunkItem for WithClientChunksChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> ChunkingContextVc {
fn chunking_context(&self) -> EcmascriptChunkingContextVc {
self.context
}
@ -113,7 +115,7 @@ impl EcmascriptChunkItem for WithClientChunksChunkItem {
let inner = self.inner.await?;
let group = ChunkGroupVc::from_asset(
inner.asset.into(),
self.context,
self.context.into(),
Value::new(AvailabilityInfo::Root {
current_availability_root: inner.asset.into(),
}),
@ -140,7 +142,7 @@ impl EcmascriptChunkItem for WithClientChunksChunkItem {
}
}
let module_id = stringify_js(&*inner.asset.as_chunk_item(self.context).id().await?);
let module_id = inner.asset.as_chunk_item(self.context).id().await?;
Ok(EcmascriptChunkItemContent {
inner_code: formatdoc!(
// We store the chunks in a binding, otherwise a new array would be created every
@ -150,10 +152,10 @@ impl EcmascriptChunkItem for WithClientChunksChunkItem {
default: () => __turbopack_import__({}),
chunks: () => chunks,
}});
const chunks = {};
const chunks = {:#};
"#,
module_id,
stringify_js_pretty(&client_chunks),
StringifyJs(&module_id),
StringifyJs(&client_chunks),
)
.into(),
..Default::default()

View file

@ -13,6 +13,7 @@ use turbopack::evaluate_context::node_evaluate_asset_context;
use turbopack_core::{
asset::Asset,
changed::any_content_changed,
chunk::ChunkingContext,
context::AssetContext,
ident::AssetIdentVc,
issue::IssueContextExt,
@ -558,7 +559,7 @@ pub async fn load_next_config_internal(
) -> Result<NextConfigVc> {
let ExecutionContext {
project_path,
intermediate_output_path,
chunking_context,
env,
} = *execution_context.await?;
let mut import_map = ImportMap::default();
@ -587,14 +588,14 @@ pub async fn load_next_config_internal(
next_asset("entry/config/next.js"),
Value::new(ReferenceType::Entry(EntryReferenceSubType::Undefined)),
);
let config_value = evaluate(
project_path,
load_next_config_asset,
project_path,
env,
config_asset.map_or_else(|| AssetIdentVc::from_path(project_path), |c| c.ident()),
context,
intermediate_output_path,
chunking_context.with_layer("next_config"),
None,
vec![],
config_changed,

View file

@ -16,7 +16,7 @@ use turbopack_core::{
virtual_asset::VirtualAssetVc,
};
use turbopack_ecmascript::{
chunk_group_files_asset::ChunkGroupFilesAsset, utils::stringify_js, EcmascriptInputTransform,
chunk_group_files_asset::ChunkGroupFilesAsset, utils::StringifyJs, EcmascriptInputTransform,
EcmascriptInputTransformsVc, EcmascriptModuleAssetType, EcmascriptModuleAssetVc, InnerAssetsVc,
};
@ -85,8 +85,8 @@ impl Transition for NextEdgeTransition {
let mut new_content = RopeBuilder::from(
format!(
"const NAME={};\nconst PAGE = {};\n",
stringify_js(&self.entry_name),
stringify_js(path)
StringifyJs(&self.entry_name),
StringifyJs(path)
)
.into_bytes(),
);
@ -112,9 +112,8 @@ impl Transition for NextEdgeTransition {
let asset = ChunkGroupFilesAsset {
asset: new_asset.into(),
client_root: self.output_path,
chunking_context: self.edge_chunking_context,
base_path: self.output_path,
server_root: self.output_path,
runtime_entries: None,
};

View file

@ -436,7 +436,6 @@ async fn get_mock_stylesheet(
let root = mock_fs.root();
let val = evaluate(
loader_path,
mocked_response_asset,
root,
env,

View file

@ -15,7 +15,7 @@ use turbopack_core::{
};
use turbopack_dev_server::source::{asset_graph::AssetGraphContentSourceVc, ContentSourceVc};
use turbopack_ecmascript::{
utils::stringify_js, EcmascriptInputTransform, EcmascriptInputTransformsVc,
utils::StringifyJs, EcmascriptInputTransform, EcmascriptInputTransformsVc,
EcmascriptModuleAssetType, EcmascriptModuleAssetVc, InnerAssetsVc,
};
@ -60,7 +60,7 @@ impl PageLoaderAssetVc {
writeln!(
result,
"const PAGE_PATH = {};\n",
stringify_js(&format!("/{}", &*this.pathname.await?))
StringifyJs(&format_args!("/{}", &*this.pathname.await?))
)?;
let page_loader_path = next_js_file_path("entry/page-loader.ts");
@ -137,9 +137,9 @@ impl Asset for PageLoaderAsset {
.collect();
let content = format!(
"__turbopack_load_page_chunks__({}, {})\n",
stringify_js(&this.pathname.await?),
stringify_js(&chunk_paths)
"__turbopack_load_page_chunks__({}, {:#})\n",
StringifyJs(&this.pathname.await?),
StringifyJs(&chunk_paths)
);
Ok(AssetContentVc::from(File::from(content)))

View file

@ -11,12 +11,13 @@ use turbo_tasks_fs::{FileContent, FileSystemPathVc};
use turbopack::{transition::TransitionsByNameVc, ModuleAssetContextVc};
use turbopack_core::{
asset::AssetVc,
chunk::{dev::DevChunkingContextVc, ChunkingContextVc},
chunk::ChunkingContextVc,
context::{AssetContext, AssetContextVc},
environment::{EnvironmentIntention, ServerAddrVc},
reference_type::{EntryReferenceSubType, ReferenceType},
source_asset::SourceAssetVc,
};
use turbopack_dev::DevChunkingContextVc;
use turbopack_dev_server::{
html::DevHtmlAssetVc,
source::{
@ -123,7 +124,6 @@ pub async fn create_page_source(
client_module_options_context,
client_resolve_options_context,
client_compile_time_info,
server_root,
runtime_entries: client_runtime_entries,
}
.cell()

View file

@ -13,7 +13,7 @@ use turbopack::{evaluate_context::node_evaluate_asset_context, transition::Trans
use turbopack_core::{
asset::AssetVc,
changed::any_content_changed,
chunk::dev::DevChunkingContextVc,
chunk::ChunkingContext,
context::{AssetContext, AssetContextVc},
environment::{EnvironmentIntention::Middleware, ServerAddrVc},
ident::AssetIdentVc,
@ -23,6 +23,7 @@ use turbopack_core::{
source_asset::SourceAssetVc,
virtual_asset::VirtualAssetVc,
};
use turbopack_dev::DevChunkingContextVc;
use turbopack_ecmascript::{
EcmascriptInputTransform, EcmascriptInputTransformsVc, EcmascriptModuleAssetType,
EcmascriptModuleAssetVc, InnerAssetsVc, OptionEcmascriptModuleAssetVc,
@ -354,10 +355,9 @@ async fn route_internal(
) -> Result<RouterResultVc> {
let ExecutionContext {
project_path,
intermediate_output_path,
chunking_context,
env,
} = *execution_context.await?;
let intermediate_output_path = intermediate_output_path.join("router");
let context = node_evaluate_asset_context(
project_path,
@ -365,7 +365,7 @@ async fn route_internal(
Some(edge_transition_map(
server_addr,
project_path,
intermediate_output_path,
chunking_context.output_root(),
next_config,
execution_context,
)),
@ -382,13 +382,12 @@ async fn route_internal(
bail!("Next.js requires a disk path to check for valid routes");
};
let result = evaluate(
project_path,
router_asset,
project_path,
env,
AssetIdentVc::from_path(project_path),
context,
intermediate_output_path,
chunking_context.with_layer("router"),
None,
vec![
JsonValueVc::cell(request),

View file

@ -18,7 +18,7 @@ pub async fn resolve_runtime_request(
bail!("turbopack runtime asset is not placeable")
}
} else {
// The @vercel/turbopack-runtime module is not installed.
// The @vercel/turbopack-dev-runtime module is not installed.
bail!("could not resolve the `{}` module", runtime_request_path)
}
}

View file

@ -3,7 +3,7 @@ PlainIssue {
context: "[project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/pages/hello.emit",
category: "loaders",
title: "Issue while running loader",
description: "Error: Error!\n at module.exports (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/node_modules/emit-loader/index.js:4:18)\n at LOADER_EXECUTION (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4134)\n at runSyncOrAsync (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4145)\n at iterateNormalLoaders (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:5782)\n at <unknown> (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:5426)\n at readResource (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/.next/build/webpack_loaders/chunks/[turbopack-node]_transforms_webpack-loaders.ts_fa48d1._.js:55:17)\n at <unknown> (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:6160)\n at processResource (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:5308)\n at iteratePitchingLoaders (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4667)\n at iteratePitchingLoaders (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4764)\n at <unknown> (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4896)\n at handleResult (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:1424)\n at loadLoader (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:963)\n at iteratePitchingLoaders (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4794)\n at runLoaders (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:8590)\n at <unknown> (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/.next/build/webpack_loaders/chunks/[turbopack-node]_transforms_webpack-loaders.ts_fa48d1._.js:35:9)\n at <anonymous>\n at Module.transform (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/.next/build/webpack_loaders/chunks/[turbopack-node]_transforms_webpack-loaders.ts_fa48d1._.js:28:12)\n at <unknown> (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/.next/build/webpack_loaders/chunks/[turbopack-node]__c3ef78._.js:13:212)\n at Module.run (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/.next/build/webpack_loaders/chunks/[turbopack-node]_ipc_evaluate.ts_f5e151._.js:172:45)\n",
description: "Error: Error!\n at module.exports (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/node_modules/emit-loader/index.js:4:18)\n at LOADER_EXECUTION (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4134)\n at runSyncOrAsync (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4145)\n at iterateNormalLoaders (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:5782)\n at <unknown> (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:5426)\n at readResource (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/.next/build/chunks/webpack_loaders/[turbopack-node]_transforms_webpack-loaders.ts_59baa9._.js:55:17)\n at <unknown> (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:6160)\n at processResource (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:5308)\n at iteratePitchingLoaders (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4667)\n at iteratePitchingLoaders (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4764)\n at <unknown> (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4896)\n at handleResult (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:1424)\n at loadLoader (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:963)\n at iteratePitchingLoaders (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4794)\n at runLoaders (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:8590)\n at <unknown> (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/.next/build/chunks/webpack_loaders/[turbopack-node]_transforms_webpack-loaders.ts_59baa9._.js:35:9)\n at <anonymous>\n at Module.transform (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/.next/build/chunks/webpack_loaders/[turbopack-node]_transforms_webpack-loaders.ts_59baa9._.js:28:12)\n at <unknown> (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/.next/build/chunks/webpack_loaders/[turbopack-node]__6b13f0._.js:13:229)\n at Module.run (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/.next/build/chunks/webpack_loaders/[turbopack-node]_ipc_evaluate.ts_7910c7._.js:172:45)\n",
detail: "",
documentation_link: "",
source: None,

View file

@ -3,7 +3,7 @@ PlainIssue {
context: "[project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/pages/hello.emit",
category: "loaders",
title: "Issue while running loader",
description: "Error: Warning!\n at module.exports (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/node_modules/emit-loader/index.js:2:20)\n at LOADER_EXECUTION (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4134)\n at runSyncOrAsync (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4145)\n at iterateNormalLoaders (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:5782)\n at <unknown> (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:5426)\n at readResource (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/.next/build/webpack_loaders/chunks/[turbopack-node]_transforms_webpack-loaders.ts_fa48d1._.js:55:17)\n at <unknown> (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:6160)\n at processResource (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:5308)\n at iteratePitchingLoaders (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4667)\n at iteratePitchingLoaders (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4764)\n at <unknown> (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4896)\n at handleResult (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:1424)\n at loadLoader (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:963)\n at iteratePitchingLoaders (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4794)\n at runLoaders (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:8590)\n at <unknown> (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/.next/build/webpack_loaders/chunks/[turbopack-node]_transforms_webpack-loaders.ts_fa48d1._.js:35:9)\n at <anonymous>\n at Module.transform (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/.next/build/webpack_loaders/chunks/[turbopack-node]_transforms_webpack-loaders.ts_fa48d1._.js:28:12)\n at <unknown> (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/.next/build/webpack_loaders/chunks/[turbopack-node]__c3ef78._.js:13:212)\n at Module.run (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/.next/build/webpack_loaders/chunks/[turbopack-node]_ipc_evaluate.ts_f5e151._.js:172:45)\n",
description: "Error: Warning!\n at module.exports (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/node_modules/emit-loader/index.js:2:20)\n at LOADER_EXECUTION (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4134)\n at runSyncOrAsync (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4145)\n at iterateNormalLoaders (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:5782)\n at <unknown> (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:5426)\n at readResource (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/.next/build/chunks/webpack_loaders/[turbopack-node]_transforms_webpack-loaders.ts_59baa9._.js:55:17)\n at <unknown> (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:6160)\n at processResource (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:5308)\n at iteratePitchingLoaders (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4667)\n at iteratePitchingLoaders (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4764)\n at <unknown> (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4896)\n at handleResult (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:1424)\n at loadLoader (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:963)\n at iteratePitchingLoaders (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:4794)\n at runLoaders (packages/next/dist/compiled/loader-runner/LoaderRunner.js:1:8590)\n at <unknown> (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/.next/build/chunks/webpack_loaders/[turbopack-node]_transforms_webpack-loaders.ts_59baa9._.js:35:9)\n at <anonymous>\n at Module.transform (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/.next/build/chunks/webpack_loaders/[turbopack-node]_transforms_webpack-loaders.ts_59baa9._.js:28:12)\n at <unknown> (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/.next/build/chunks/webpack_loaders/[turbopack-node]__6b13f0._.js:13:229)\n at Module.run (packages/next-swc/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/.next/build/chunks/webpack_loaders/[turbopack-node]_ipc_evaluate.ts_7910c7._.js:172:45)\n",
detail: "",
documentation_link: "",
source: None,

View file

@ -57,8 +57,10 @@ turbo-malloc = { workspace = true, default-features = false }
turbo-tasks = { workspace = true }
turbo-tasks-fs = { workspace = true }
turbo-tasks-memory = { workspace = true }
turbopack = { workspace = true }
turbopack-cli-utils = { workspace = true }
turbopack-core = { workspace = true }
turbopack-dev = { workspace = true }
turbopack-dev-server = { workspace = true }
turbopack-node = { workspace = true }
webbrowser = { workspace = true }

View file

@ -34,6 +34,7 @@ use turbo_tasks::{
};
use turbo_tasks_fs::{DiskFileSystemVc, FileSystem, FileSystemVc};
use turbo_tasks_memory::MemoryBackend;
use turbopack::evaluate_context::node_build_environment;
use turbopack_cli_utils::issue::{ConsoleUiVc, LogOptions};
use turbopack_core::{
environment::ServerAddr,
@ -41,6 +42,7 @@ use turbopack_core::{
resolve::{parse::RequestVc, pattern::QueryMapVc},
server_fs::ServerFileSystemVc,
};
use turbopack_dev::DevChunkingContextVc;
use turbopack_dev_server::{
introspect::IntrospectionSource,
source::{
@ -274,9 +276,18 @@ async fn source(
let env = load_env(project_path);
let build_output_root = output_fs.root().join(".next/build");
let execution_context = ExecutionContextVc::new(project_path, build_output_root, env);
let build_chunking_context = DevChunkingContextVc::builder(
project_path,
build_output_root,
build_output_root.join("chunks"),
build_output_root.join("assets"),
node_build_environment(),
)
.build();
let next_config = load_next_config(execution_context.join("next_config"));
let execution_context = ExecutionContextVc::new(project_path, build_chunking_context, env);
let next_config = load_next_config(execution_context.with_layer("next_config"));
let output_root = output_fs.root().join(".next/server");
let server_addr = ServerAddr::new(*server_addr).cell();

View file

@ -992,7 +992,7 @@ importers:
'@types/react': ^18.0.26
'@types/react-dom': ^18.0.9
'@vercel/ncc': ^0.36.0
'@vercel/turbopack-runtime': https://gitpkg.now.sh/vercel/turbo/crates/turbopack-ecmascript/js?8a8038f94
'@vercel/turbopack-dev-runtime': https://gitpkg.now.sh/vercel/turbo/crates/turbopack-dev/js?turbopack-230321.3
anser: ^2.1.1
css.escape: ^1.5.1
find-up: ^6.3.0
@ -1004,7 +1004,7 @@ importers:
stacktrace-parser: ^0.1.10
strip-ansi: ^7.0.1
dependencies:
'@vercel/turbopack-runtime': '@gitpkg.now.sh/vercel/turbo/crates/turbopack-ecmascript/js?8a8038f94_react-refresh@0.12.0'
'@vercel/turbopack-dev-runtime': '@gitpkg.now.sh/vercel/turbo/crates/turbopack-dev/js?turbopack-230321.3_react-refresh@0.12.0'
anser: 2.1.1
css.escape: 1.5.1
next: link:../../../../next
@ -25414,10 +25414,10 @@ packages:
/zwitch/2.0.4:
resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==}
'@gitpkg.now.sh/vercel/turbo/crates/turbopack-ecmascript/js?8a8038f94_react-refresh@0.12.0':
resolution: {tarball: https://gitpkg.now.sh/vercel/turbo/crates/turbopack-ecmascript/js?8a8038f94}
id: '@gitpkg.now.sh/vercel/turbo/crates/turbopack-ecmascript/js?8a8038f94'
name: '@vercel/turbopack-runtime'
'@gitpkg.now.sh/vercel/turbo/crates/turbopack-dev/js?turbopack-230321.3_react-refresh@0.12.0':
resolution: {tarball: https://gitpkg.now.sh/vercel/turbo/crates/turbopack-dev/js?turbopack-230321.3}
id: '@gitpkg.now.sh/vercel/turbo/crates/turbopack-dev/js?turbopack-230321.3'
name: '@vercel/turbopack-dev-runtime'
version: 0.0.0
dependencies:
'@next/react-refresh-utils': 13.2.4_react-refresh@0.12.0