Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(turbopack): Use ResolvedVc for turbopack-env #73202

Merged
merged 9 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions turbopack/crates/turbopack-env/src/asset.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::io::Write;

use anyhow::Result;
use turbo_tasks::Vc;
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_env::ProcessEnv;
use turbo_tasks_fs::{rope::RopeBuilder, File, FileSystemPath};
use turbopack_core::{
Expand All @@ -16,17 +16,20 @@ use turbopack_ecmascript::utils::StringifyJs;
#[turbo_tasks::value]
pub struct ProcessEnvAsset {
/// The root path which we can construct our env asset path.
root: Vc<FileSystemPath>,
root: ResolvedVc<FileSystemPath>,

/// A HashMap filled with the env key/values.
env: Vc<Box<dyn ProcessEnv>>,
env: ResolvedVc<Box<dyn ProcessEnv>>,
}

#[turbo_tasks::value_impl]
impl ProcessEnvAsset {
#[turbo_tasks::function]
pub fn new(root: Vc<FileSystemPath>, env: Vc<Box<dyn ProcessEnv>>) -> Vc<Self> {
ProcessEnvAsset { root, env }.cell()
pub async fn new(
root: ResolvedVc<FileSystemPath>,
env: ResolvedVc<Box<dyn ProcessEnv>>,
) -> Result<Vc<Self>> {
Ok(ProcessEnvAsset { root, env }.cell())
}
}

Expand Down
8 changes: 4 additions & 4 deletions turbopack/crates/turbopack-env/src/embeddable.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use anyhow::Result;
use turbo_rcstr::RcStr;
use turbo_tasks::Vc;
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_env::{EnvMap, ProcessEnv};
use turbopack_ecmascript::utils::StringifyJs;

/// Encodes values as JS strings so that they can be safely injected into a JS
/// output.
#[turbo_tasks::value]
pub struct EmbeddableProcessEnv {
prior: Vc<Box<dyn ProcessEnv>>,
prior: ResolvedVc<Box<dyn ProcessEnv>>,
}

#[turbo_tasks::value_impl]
impl EmbeddableProcessEnv {
#[turbo_tasks::function]
pub fn new(prior: Vc<Box<dyn ProcessEnv>>) -> Vc<Self> {
EmbeddableProcessEnv { prior }.cell()
pub fn new(prior: ResolvedVc<Box<dyn ProcessEnv>>) -> Result<Vc<Self>> {
Ok(EmbeddableProcessEnv { prior }.cell())
}
}

Expand Down
10 changes: 5 additions & 5 deletions turbopack/crates/turbopack-env/src/issue.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use turbo_tasks::Vc;
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::FileSystemPath;
use turbopack_core::issue::{Issue, IssueStage, OptionStyledString, StyledString};

/// An issue that occurred while resolving the parsing or evaluating the .env.
#[turbo_tasks::value(shared)]
pub struct ProcessEnvIssue {
pub path: Vc<FileSystemPath>,
pub description: Vc<StyledString>,
pub path: ResolvedVc<FileSystemPath>,
pub description: ResolvedVc<StyledString>,
}

#[turbo_tasks::value_impl]
Expand All @@ -23,11 +23,11 @@ impl Issue for ProcessEnvIssue {

#[turbo_tasks::function]
fn file_path(&self) -> Vc<FileSystemPath> {
self.path
*self.path
}

#[turbo_tasks::function]
fn description(&self) -> Vc<OptionStyledString> {
Vc::cell(Some(self.description))
Vc::cell(Some(*self.description))
}
}
24 changes: 15 additions & 9 deletions turbopack/crates/turbopack-env/src/try_env.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use turbo_tasks::Vc;
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_env::{DotenvProcessEnv, EnvMap, ProcessEnv};
use turbo_tasks_fs::FileSystemPath;
use turbopack_core::issue::{IssueExt, StyledString};
Expand All @@ -8,22 +8,27 @@ use crate::ProcessEnvIssue;

#[turbo_tasks::value]
pub struct TryDotenvProcessEnv {
dotenv: Vc<DotenvProcessEnv>,
prior: Vc<Box<dyn ProcessEnv>>,
path: Vc<FileSystemPath>,
dotenv: ResolvedVc<DotenvProcessEnv>,
prior: ResolvedVc<Box<dyn ProcessEnv>>,
path: ResolvedVc<FileSystemPath>,
}

#[turbo_tasks::value_impl]
impl TryDotenvProcessEnv {
#[turbo_tasks::function]
pub fn new(prior: Vc<Box<dyn ProcessEnv>>, path: Vc<FileSystemPath>) -> Vc<Self> {
let dotenv = DotenvProcessEnv::new(Some(prior), path);
TryDotenvProcessEnv {
pub async fn new(
prior: ResolvedVc<Box<dyn ProcessEnv>>,
path: ResolvedVc<FileSystemPath>,
) -> Result<Vc<Self>> {
let dotenv = DotenvProcessEnv::new(Some(*prior), *path)
.to_resolved()
.await?;
Ok(TryDotenvProcessEnv {
dotenv,
prior,
path,
}
.cell()
.cell())
}
}

Expand All @@ -50,7 +55,8 @@ impl ProcessEnv for TryDotenvProcessEnv {
// read_all_with_prior will wrap a current error with a context containing the
// failing file, which we don't really care about (we report the filepath as the
// Issue context, not the description). So extract the real error.
description: StyledString::Text(e.root_cause().to_string().into()).cell(),
description: StyledString::Text(e.root_cause().to_string().into())
.resolved_cell(),
}
.cell()
.emit();
Expand Down
Loading