Unverified Commit f8cb5d60 authored by xusd320's avatar xusd320 Committed by GitHub

chore(turbopack-node): remove some outdated codes (#86111)

These codes are outdated.
parent bbfd5fb2
...@@ -2,27 +2,17 @@ ...@@ -2,27 +2,17 @@
#![feature(arbitrary_self_types)] #![feature(arbitrary_self_types)]
#![feature(arbitrary_self_types_pointers)] #![feature(arbitrary_self_types_pointers)]
use std::thread::available_parallelism; use anyhow::Result;
use anyhow::{Result, bail};
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, TryFlatJoinIterExt, Vc}; use turbo_tasks::{ResolvedVc, TryFlatJoinIterExt, Vc};
use turbo_tasks_env::ProcessEnv; use turbo_tasks_fs::{File, FileSystemPath};
use turbo_tasks_fs::{File, FileSystemPath, to_sys_path};
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
changed::content_changed,
chunk::{ChunkingContext, ChunkingContextExt, EvaluatableAsset, EvaluatableAssets},
module::Module,
module_graph::{ModuleGraph, chunk_group_info::ChunkGroupEntry},
output::{ExpandOutputAssetsInput, OutputAsset, OutputAssets, expand_output_assets}, output::{ExpandOutputAssetsInput, OutputAsset, OutputAssets, expand_output_assets},
source_map::GenerateSourceMap, source_map::GenerateSourceMap,
virtual_output::VirtualOutputAsset, virtual_output::VirtualOutputAsset,
}; };
use self::pool::NodeJsPool;
pub mod debug; pub mod debug;
pub mod embed_js; pub mod embed_js;
pub mod evaluate; pub mod evaluate;
...@@ -112,93 +102,3 @@ fn emit_package_json(dir: FileSystemPath) -> Result<Vc<()>> { ...@@ -112,93 +102,3 @@ fn emit_package_json(dir: FileSystemPath) -> Result<Vc<()>> {
dir, dir,
)) ))
} }
/// Creates a node.js renderer pool for an entrypoint.
#[turbo_tasks::function(operation)]
pub async fn get_renderer_pool_operation(
cwd: FileSystemPath,
env: ResolvedVc<Box<dyn ProcessEnv>>,
intermediate_asset: ResolvedVc<Box<dyn OutputAsset>>,
intermediate_output_path: FileSystemPath,
output_root: FileSystemPath,
project_dir: FileSystemPath,
debug: bool,
) -> Result<Vc<NodeJsPool>> {
emit_package_json(intermediate_output_path.clone())?.await?;
emit(*intermediate_asset, output_root.clone())
.as_side_effect()
.await?;
let assets_for_source_mapping =
internal_assets_for_source_mapping(*intermediate_asset, output_root.clone());
let entrypoint = intermediate_asset.path().owned().await?;
let Some(cwd) = to_sys_path(cwd.clone()).await? else {
bail!(
"can only render from a disk filesystem, but `cwd = {}`",
cwd.value_to_string().await?
);
};
let Some(entrypoint) = to_sys_path(entrypoint.clone()).await? else {
bail!(
"can only render from a disk filesystem, but `entrypoint = {}`",
entrypoint.value_to_string().await?
);
};
// Invalidate pool when code content changes
content_changed(*ResolvedVc::upcast(intermediate_asset)).await?;
Ok(NodeJsPool::new(
cwd,
entrypoint,
env.read_all()
.await?
.iter()
.map(|(k, v)| (k.clone(), v.clone()))
.collect(),
assets_for_source_mapping.to_resolved().await?,
output_root,
project_dir,
available_parallelism().map_or(1, |v| v.get()),
debug,
)
.cell())
}
/// Converts a module graph into node.js executable assets
#[turbo_tasks::function]
pub async fn get_intermediate_asset(
chunking_context: Vc<Box<dyn ChunkingContext>>,
main_entry: ResolvedVc<Box<dyn EvaluatableAsset>>,
other_entries: Vc<EvaluatableAssets>,
) -> Result<Vc<Box<dyn OutputAsset>>> {
Ok(chunking_context.root_entry_chunk_group_asset(
chunking_context
.chunk_path(None, main_entry.ident(), None, rcstr!(".js"))
.owned()
.await?,
other_entries.with_entry(*main_entry),
ModuleGraph::from_modules(
Vc::cell(vec![ChunkGroupEntry::Entry(
other_entries
.await?
.into_iter()
.copied()
.chain(std::iter::once(main_entry))
.map(ResolvedVc::upcast)
.collect(),
)]),
false,
),
OutputAssets::empty(),
OutputAssets::empty(),
))
}
#[derive(Clone, Debug)]
#[turbo_tasks::value(shared)]
pub struct ResponseHeaders {
pub status: u16,
pub headers: Vec<(RcStr, RcStr)>,
}
use std::{ use std::{
borrow::Cow,
cmp::max, cmp::max,
fmt::{Debug, Display}, fmt::{Debug, Display},
future::Future, future::Future,
...@@ -71,9 +70,6 @@ impl FormattingMode { ...@@ -71,9 +70,6 @@ impl FormattingMode {
struct NodeJsPoolProcess { struct NodeJsPoolProcess {
child: Option<Child>, child: Option<Child>,
connection: TcpStream, connection: TcpStream,
assets_for_source_mapping: ResolvedVc<AssetsForSourceMapping>,
assets_root: FileSystemPath,
project_dir: FileSystemPath,
stdout_handler: OutputStreamHandler<ChildStdout, Stdout>, stdout_handler: OutputStreamHandler<ChildStdout, Stdout>,
stderr_handler: OutputStreamHandler<ChildStderr, Stderr>, stderr_handler: OutputStreamHandler<ChildStderr, Stderr>,
debug: bool, debug: bool,
...@@ -107,39 +103,6 @@ impl PartialEq for NodeJsPoolProcess { ...@@ -107,39 +103,6 @@ impl PartialEq for NodeJsPoolProcess {
} }
} }
impl NodeJsPoolProcess {
pub async fn apply_source_mapping<'a>(
&self,
text: &'a str,
formatting_mode: FormattingMode,
) -> Result<Cow<'a, str>> {
let text = unmangle_identifiers(text, |content| formatting_mode.magic_identifier(content));
match text {
Cow::Borrowed(text) => {
apply_source_mapping(
text,
*self.assets_for_source_mapping,
self.assets_root.clone(),
self.project_dir.clone(),
formatting_mode,
)
.await
}
Cow::Owned(ref text) => {
let cow = apply_source_mapping(
text,
*self.assets_for_source_mapping,
self.assets_root.clone(),
self.project_dir.clone(),
formatting_mode,
)
.await?;
Ok(Cow::Owned(cow.into_owned()))
}
}
}
}
const CONNECT_TIMEOUT: Duration = Duration::from_secs(30); const CONNECT_TIMEOUT: Duration = Duration::from_secs(30);
#[derive(Clone, PartialEq, Eq, Hash)] #[derive(Clone, PartialEq, Eq, Hash)]
...@@ -456,9 +419,6 @@ impl NodeJsPoolProcess { ...@@ -456,9 +419,6 @@ impl NodeJsPoolProcess {
let mut process = Self { let mut process = Self {
child: Some(child), child: Some(child),
connection, connection,
assets_for_source_mapping,
assets_root: assets_root.clone(),
project_dir: project_dir.clone(),
stdout_handler, stdout_handler,
stderr_handler, stderr_handler,
debug, debug,
...@@ -958,18 +918,6 @@ impl NodeJsOperation { ...@@ -958,18 +918,6 @@ impl NodeJsOperation {
self.allow_process_reuse = false; self.allow_process_reuse = false;
} }
} }
pub async fn apply_source_mapping<'a>(
&self,
text: &'a str,
formatting_mode: FormattingMode,
) -> Result<Cow<'a, str>> {
if let Some(process) = self.process.as_ref() {
process.apply_source_mapping(text, formatting_mode).await
} else {
Ok(Cow::Borrowed(text))
}
}
} }
impl Drop for NodeJsOperation { impl Drop for NodeJsOperation {
......
...@@ -9,7 +9,6 @@ use const_format::concatcp; ...@@ -9,7 +9,6 @@ use const_format::concatcp;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use regex::Regex; use regex::Regex;
pub use trace::{StackFrame, TraceResult, trace_source_map}; pub use trace::{StackFrame, TraceResult, trace_source_map};
use tracing::{Level, instrument};
use turbo_tasks::{ReadRef, Vc}; use turbo_tasks::{ReadRef, Vc};
use turbo_tasks_fs::{ use turbo_tasks_fs::{
FileLinesContent, FileSystemPath, source_context::get_source_context, to_sys_path, FileLinesContent, FileSystemPath, source_context::get_source_context, to_sys_path,
...@@ -17,12 +16,11 @@ use turbo_tasks_fs::{ ...@@ -17,12 +16,11 @@ use turbo_tasks_fs::{
use turbopack_cli_utils::source_context::format_source_context_lines; use turbopack_cli_utils::source_context::format_source_context_lines;
use turbopack_core::{ use turbopack_core::{
PROJECT_FILESYSTEM_NAME, SOURCE_URL_PROTOCOL, PROJECT_FILESYSTEM_NAME, SOURCE_URL_PROTOCOL,
output::OutputAsset,
source_map::{GenerateSourceMap, SourceMap}, source_map::{GenerateSourceMap, SourceMap},
}; };
use turbopack_ecmascript::magic_identifier::unmangle_identifiers; use turbopack_ecmascript::magic_identifier::unmangle_identifiers;
use crate::{AssetsForSourceMapping, internal_assets_for_source_mapping, pool::FormattingMode}; use crate::{AssetsForSourceMapping, pool::FormattingMode};
pub mod trace; pub mod trace;
...@@ -332,38 +330,3 @@ impl StructuredError { ...@@ -332,38 +330,3 @@ impl StructuredError {
Ok(message) Ok(message)
} }
} }
pub async fn trace_stack(
error: StructuredError,
root_asset: Vc<Box<dyn OutputAsset>>,
output_path: FileSystemPath,
project_dir: FileSystemPath,
) -> Result<String> {
let assets_for_source_mapping =
internal_assets_for_source_mapping(root_asset, output_path.clone());
trace_stack_with_source_mapping_assets(
error,
assets_for_source_mapping,
output_path,
project_dir,
)
.await
}
#[instrument(level = Level::TRACE, skip_all)]
pub async fn trace_stack_with_source_mapping_assets(
error: StructuredError,
assets_for_source_mapping: Vc<AssetsForSourceMapping>,
output_path: FileSystemPath,
project_dir: FileSystemPath,
) -> Result<String> {
error
.print(
assets_for_source_mapping,
output_path,
project_dir,
FormattingMode::Plain,
)
.await
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment