Skip to content

Commit

Permalink
Support Buffer results from Webpack loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Aug 2, 2024
1 parent 514fad5 commit 9388834
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions turbopack/crates/turbopack-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ anyhow = { workspace = true }
async-stream = "0.3.4"
async-trait = { workspace = true }
const_format = "0.2.30"
either = { workspace = true, features = ["serde"] }
futures = { workspace = true }
futures-retry = { workspace = true }
indexmap = { workspace = true, features = ["serde"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ const transform = (
if (!result.result) return reject(new Error("No result from loaders"));
const [source, map] = result.result;
resolve({
source: Buffer.isBuffer(source) ? source.toString("utf8") : source,
source: Buffer.isBuffer(source) ? [...source] : source,
map:
typeof map === "string"
? map
Expand Down
7 changes: 5 additions & 2 deletions turbopack/crates/turbopack-node/src/transforms/webpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::mem::take;

use anyhow::{bail, Context, Result};
use async_trait::async_trait;
use either::Either;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value as JsonValue};
use turbo_tasks::{
Expand Down Expand Up @@ -56,7 +57,9 @@ use crate::{
#[serde(rename_all = "camelCase")]
#[turbo_tasks::value(serialization = "custom")]
struct WebpackLoadersProcessingResult {
source: RcStr,
#[serde(with = "either::serde_untagged")]
#[turbo_tasks(trace_ignore)]
source: Either<RcStr, Vec<u8>>,
map: Option<RcStr>,
#[turbo_tasks(trace_ignore)]
assets: Option<Vec<EmittedAsset>>,
Expand Down Expand Up @@ -250,7 +253,7 @@ impl WebpackLoadersProcessedAsset {
} else {
None
};
let file = File::from(processed.source);
let file = either::for_both!(processed.source, source => File::from(source));
let assets = emitted_assets_to_virtual_sources(processed.assets);
let content = AssetContent::File(FileContent::Content(file).cell()).cell();
Ok(ProcessWebpackLoadersResult {
Expand Down

0 comments on commit 9388834

Please sign in to comment.