Unverified Commit 3066987f authored by Alexander Lyon's avatar Alexander Lyon Committed by GitHub

Remove the node-file-trace crate (#70998)

### What?

This is a 2nd prefactor for adding node-file-trace into turbopack. When implementing this, we have a few options namely:

- a) expose turbotrace (node-file-trace-rs) as a napi library and try to insert it into the current codebase
- b) expose turbotrace and try to reuse the turbo backend
- c) move turobtrace into the rust process and do it in parallel with everything else

We chose c

We have already ripped out the js code path, this PR nukes the now-orphaned node-file-trace rust binary and napi bindings.

### Why?

The crate is unmaintained and probably will not be used in its current form.
parent fbb3a766
...@@ -4106,7 +4106,6 @@ dependencies = [ ...@@ -4106,7 +4106,6 @@ dependencies = [
"next-build", "next-build",
"next-core", "next-core",
"next-custom-transforms", "next-custom-transforms",
"node-file-trace",
"once_cell", "once_cell",
"owo-colors 3.5.0", "owo-colors 3.5.0",
"rand", "rand",
...@@ -4159,27 +4158,6 @@ dependencies = [ ...@@ -4159,27 +4158,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "node-file-trace"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"console-subscriber",
"serde",
"serde_json",
"tokio",
"turbo-tasks",
"turbo-tasks-build",
"turbo-tasks-fs",
"turbo-tasks-malloc",
"turbo-tasks-memory",
"turbopack",
"turbopack-cli-utils",
"turbopack-core",
"turbopack-resolve",
]
[[package]] [[package]]
name = "nom" name = "nom"
version = "7.1.3" version = "7.1.3"
......
...@@ -40,7 +40,6 @@ next-custom-transforms = { path = "crates/next-custom-transforms" } ...@@ -40,7 +40,6 @@ next-custom-transforms = { path = "crates/next-custom-transforms" }
# Turbopack # Turbopack
auto-hash-map = { path = "turbopack/crates/turbo-tasks-auto-hash-map" } auto-hash-map = { path = "turbopack/crates/turbo-tasks-auto-hash-map" }
node-file-trace = { path = "turbopack/crates/node-file-trace", default-features = false }
swc-ast-explorer = { path = "turbopack/crates/turbopack-swc-ast-explorer" } swc-ast-explorer = { path = "turbopack/crates/turbopack-swc-ast-explorer" }
turbo-prehash = { path = "turbopack/crates/turbo-prehash" } turbo-prehash = { path = "turbopack/crates/turbo-prehash" }
turbo-tasks-malloc = { path = "turbopack/crates/turbo-tasks-malloc", default-features = false } turbo-tasks-malloc = { path = "turbopack/crates/turbo-tasks-malloc", default-features = false }
......
...@@ -111,7 +111,6 @@ next-api = { workspace = true } ...@@ -111,7 +111,6 @@ next-api = { workspace = true }
next-build = { workspace = true } next-build = { workspace = true }
next-core = { workspace = true } next-core = { workspace = true }
node-file-trace = { workspace = true, features = ["node-api"] }
mdxjs = { workspace = true, features = ["serializable"] } mdxjs = { workspace = true, features = ["serializable"] }
turbo-tasks-malloc = { workspace = true, default-features = false, features = [ turbo-tasks-malloc = { workspace = true, default-features = false, features = [
......
...@@ -60,8 +60,6 @@ pub mod transform; ...@@ -60,8 +60,6 @@ pub mod transform;
pub mod turbo_trace_server; pub mod turbo_trace_server;
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
pub mod turbopack; pub mod turbopack;
#[cfg(not(target_arch = "wasm32"))]
pub mod turbotrace;
pub mod util; pub mod util;
// Declare build-time information variables generated in build.rs // Declare build-time information variables generated in build.rs
......
use std::{path::PathBuf, sync::Arc};
use napi::bindgen_prelude::*;
use node_file_trace::{start, Args};
use turbopack::{
module_options::{EcmascriptOptionsContext, ModuleOptionsContext},
resolve_options_context::ResolveOptionsContext,
};
use crate::next_api::utils::{self, NextTurboTasks};
#[napi]
pub fn create_turbo_tasks(
output_path: String,
persistent_caching: bool,
memory_limit: Option<i64>,
) -> External<NextTurboTasks> {
let limit = memory_limit.map(|u| u as usize).unwrap_or(usize::MAX);
let turbo_tasks =
utils::create_turbo_tasks(PathBuf::from(&output_path), persistent_caching, limit)
.expect("Failed to create TurboTasks");
External::new_with_size_hint(turbo_tasks, limit)
}
#[napi]
pub async fn run_turbo_tracing(
options: Buffer,
turbo_tasks: External<NextTurboTasks>,
) -> napi::Result<Vec<String>> {
let args: Args = serde_json::from_slice(options.as_ref())?;
let args = Arc::new(args);
let module_options = Some(ModuleOptionsContext {
ecmascript: EcmascriptOptionsContext {
enable_types: true,
..Default::default()
},
enable_mdx: true,
..Default::default()
});
let resolve_options = Some(ResolveOptionsContext {
..Default::default()
});
let files = match &*turbo_tasks {
NextTurboTasks::Memory(turbo_tasks) => {
start(args, turbo_tasks.clone(), module_options, resolve_options).await?
}
NextTurboTasks::PersistentCaching(turbo_tasks) => {
start(args, turbo_tasks.clone(), module_options, resolve_options).await?
}
};
Ok(files.into_iter().map(|f| f.to_string()).collect())
}
[package]
name = "node-file-trace"
version = "0.1.0"
description = "TBD"
license = "MPL-2.0"
edition = "2021"
[[bin]]
name = "node-file-trace"
path = "src/main.rs"
bench = false
[features]
default = ["cli", "custom_allocator"]
cli = ["dep:clap", "turbo-tasks-malloc"]
persistent_cache = []
serializable = []
tokio_console = [
"dep:console-subscriber",
"tokio/tracing",
"turbo-tasks/tokio_tracing",
]
node-api = []
custom_allocator = ["turbo-tasks-malloc", "turbo-tasks-malloc/custom_allocator"]
[lints]
workspace = true
[dependencies]
anyhow = { workspace = true }
clap = { workspace = true, optional = true, features = ["derive"] }
console-subscriber = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
tokio = { workspace = true, features = ["full"] }
turbo-tasks = { workspace = true }
turbo-tasks-fs = { workspace = true }
turbo-tasks-malloc = { workspace = true, optional = true, default-features = false }
turbo-tasks-memory = { workspace = true }
turbopack = { workspace = true }
turbopack-cli-utils = { workspace = true }
turbopack-core = { workspace = true }
turbopack-resolve = { workspace = true }
[build-dependencies]
turbo-tasks-build = { workspace = true }
use turbo_tasks_build::generate_register;
fn main() {
generate_register();
}
This diff is collapsed.
#![feature(min_specialization)]
#![allow(clippy::needless_return)] // clippy bug causes false positive
use std::sync::Arc;
use anyhow::Result;
use clap::Parser;
use node_file_trace::{start, Args};
use turbo_tasks::TurboTasks;
use turbo_tasks_memory::MemoryBackend;
#[global_allocator]
static ALLOC: turbo_tasks_malloc::TurboMalloc = turbo_tasks_malloc::TurboMalloc;
#[tokio::main]
async fn main() -> Result<()> {
#[cfg(feature = "tokio_console")]
console_subscriber::init();
let args = Arc::new(Args::parse());
let should_print = matches!(&*args, Args::Print { .. });
let turbo_tasks = TurboTasks::new(MemoryBackend::new(
args.common().memory_limit.unwrap_or(usize::MAX),
));
let result = start(args, turbo_tasks, None, None).await?;
if should_print {
for file in result.iter() {
println!("{}", file);
}
}
Ok(())
}
use anyhow::Result;
use serde_json::json;
use turbo_tasks::Vc;
use turbo_tasks_fs::{File, FileSystem};
use turbopack_core::{
asset::{Asset, AssetContent},
ident::AssetIdent,
module::Module,
output::OutputAsset,
reference::all_modules_and_affecting_sources,
};
#[turbo_tasks::value(shared)]
pub struct NftJsonAsset {
entry: Vc<Box<dyn Module>>,
}
#[turbo_tasks::value_impl]
impl NftJsonAsset {
#[turbo_tasks::function]
pub fn new(entry: Vc<Box<dyn Module>>) -> Vc<Self> {
NftJsonAsset { entry }.cell()
}
}
#[turbo_tasks::value_impl]
impl OutputAsset for NftJsonAsset {
#[turbo_tasks::function]
async fn ident(&self) -> Result<Vc<AssetIdent>> {
let path = self.entry.ident().path().await?;
Ok(AssetIdent::from_path(
path.fs
.root()
.join(format!("{}.nft.json", path.path).into()),
))
}
}
#[turbo_tasks::value_impl]
impl Asset for NftJsonAsset {
#[turbo_tasks::function]
async fn content(&self) -> Result<Vc<AssetContent>> {
let parent_dir = self.entry.ident().path().parent().await?;
// For clippy -- This explicit deref is necessary
let entry_path = &*self.entry.ident().path().await?;
let mut result = Vec::new();
if let Some(self_path) = parent_dir.get_relative_path_to(entry_path) {
let set = all_modules_and_affecting_sources(self.entry);
for asset in set.await?.iter() {
let path = asset.ident().path().await?;
if let Some(rel_path) = parent_dir.get_relative_path_to(&path) {
if rel_path != self_path {
result.push(rel_path);
}
}
}
result.sort();
result.dedup();
}
let json = json!({
"version": 1,
"files": result
});
Ok(AssetContent::file(File::from(json.to_string()).into()))
}
}
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