Skip to content

Commit

Permalink
node-file-trace fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkirsz committed Jun 12, 2023
1 parent b17a4df commit cc93003
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
36 changes: 22 additions & 14 deletions crates/node-file-trace/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![feature(min_specialization)]
#![feature(arbitrary_self_types)]
#![feature(async_fn_in_trait)]

mod nft_json;

Expand All @@ -22,8 +24,8 @@ use serde::Deserialize;
use serde::Serialize;
use tokio::sync::mpsc::channel;
use turbo_tasks::{
backend::Backend, util::FormatDuration, Nothing, TaskId, TransientInstance, TransientValue,
TurboTasks, TurboTasksBackendApi, UpdateInfo, Value, Vc,
backend::Backend, util::FormatDuration, TaskId, TransientInstance, TransientValue, TurboTasks,
TurboTasksBackendApi, UpdateInfo, Value, Vc,
};
use turbo_tasks_fs::{
glob::Glob, DirectoryEntry, DiskFileSystem, FileSystem, FileSystemPath, ReadGlobResult,
Expand Down Expand Up @@ -200,7 +202,7 @@ async fn create_fs(name: &str, context: &str, watch: bool) -> Result<Vc<Box<dyn
} else {
fs.await?.invalidate();
}
Ok(fs.into())
Ok(Vc::upcast(fs))
}

async fn add_glob_results(
Expand Down Expand Up @@ -233,7 +235,7 @@ async fn add_glob_results(
}

#[turbo_tasks::function]
async fn input_to_modules<'a>(
async fn input_to_modules(
fs: Vc<Box<dyn FileSystem>>,
input: Vec<String>,
exact: bool,
Expand All @@ -247,11 +249,15 @@ async fn input_to_modules<'a>(
.clone()
.map(|p| p.trim_start_matches(&context).to_owned());

let context: Vc<Box<dyn AssetContext>> =
create_module_asset(root, process_cwd, module_options, resolve_options).into();
let context: Vc<Box<dyn AssetContext>> = Vc::upcast(create_module_asset(
root,
process_cwd,
module_options,
resolve_options,
));

let mut list = Vec::new();
for input in input.iter() {
for input in input {
if exact {
let source = Vc::upcast(SourceAsset::new(root.join(input)));
list.push(context.process(
Expand Down Expand Up @@ -490,22 +496,24 @@ async fn run<B: Backend + 'static, F: Future<Output = ()>>(
resolve_options,
);

let source = TransientValue::new(output.into());
let issues = Issue::peek_issues_with_path(output)
let source = TransientValue::new(output.node);
let issues = output
.peek_issues_with_path()
.await?
.strongly_consistent()
.await?;

let console_ui = ConsoleUi::new(log_options);
Vc::upcast(console_ui).report_issues(TransientInstance::new(issues), source);
Vc::upcast::<Box<dyn IssueReporter>>(console_ui)
.report_issues(TransientInstance::new(issues), source);

if has_return_value {
let output_read_ref = output.await?;
let output_iter = output_read_ref.iter().cloned();
sender.send(output_iter.collect::<Vec<String>>()).await?;
drop(sender);
}
Ok(Nothing::new().into())
Ok(Vc::<()>::cell(()).node)
})
});
finish(tt, task).await?;
Expand Down Expand Up @@ -582,7 +590,7 @@ async fn main_operation(
let nft_asset = NftJsonAsset::new(*module);
let path = nft_asset.ident().path().await?.path.clone();
output_nft_assets.push(path);
emits.push(emit_asset(nft_asset.into()));
emits.push(emit_asset(Vc::upcast(nft_asset)));
}
// Wait for all files to be emitted
for emit in emits {
Expand Down Expand Up @@ -646,12 +654,12 @@ async fn create_module_asset(
let glob_mappings = vec![
(
root,
Glob::new("**/*/next/dist/server/next.js"),
Glob::new("**/*/next/dist/server/next.js".to_string()),
ImportMapping::Ignore.into(),
),
(
root,
Glob::new("**/*/next/dist/bin/next"),
Glob::new("**/*/next/dist/bin/next".to_string()),
ImportMapping::Ignore.into(),
),
];
Expand Down
4 changes: 2 additions & 2 deletions crates/node-file-trace/src/nft_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Asset for NftJsonAsset {
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)),
path.fs.root().join(format!("{}.nft.json", path.path)),
))
}

Expand Down Expand Up @@ -55,6 +55,6 @@ impl Asset for NftJsonAsset {
"files": result
});

Ok(File::from(json.to_string()).into())
Ok(AssetContent::file(File::from(json.to_string()).into()))
}
}

0 comments on commit cc93003

Please sign in to comment.