Skip to content
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
15 changes: 8 additions & 7 deletions crates/pack-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,18 @@ impl Endpoint for AppEndpoint {

let dist_root = this.project.dist_root().await?;

let (server_paths, client_paths) = (vec![], vec![]);

let written_endpoint = EndpointOutputPaths::NodeJs {
server_entry_path: dist_root.path.to_string(),
server_paths,
client_paths,
// FIXME: No server path when bundling library
server_paths: vec![],
client_paths: vec![],
};

let output_assets = if *this.project.should_create_webpack_stats().await? {
let should_create_webpack_stats = *this.project.should_create_webpack_stats().await?;

let output_assets = if !should_create_webpack_stats {
output_assets
} else {
let webpack_stats = generate_webpack_stats(output_assets, this.project.dist_root());
let webpack_stats_read = webpack_stats.await?;
let dist_root_owned = this.project.dist_root().owned().await?;
Expand All @@ -386,8 +389,6 @@ impl Endpoint for AppEndpoint {
.to_resolved()
.await?;
output_assets.concatenate(*ResolvedVc::cell(vec![ResolvedVc::upcast(stats_output)]))
} else {
output_assets
};

Ok(EndpointOutput {
Expand Down
6 changes: 2 additions & 4 deletions crates/pack-api/src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,11 @@ impl Endpoint for LibraryEndpoint {

let dist_root = self.project().dist_root().await?;

let (server_paths, client_paths) = (vec![], vec![]);

let written_endpoint = EndpointOutputPaths::NodeJs {
// FIXME: No server path when bundling library
server_entry_path: dist_root.to_string(),
server_paths,
client_paths,
server_paths: vec![],
client_paths: vec![],
};

Ok(EndpointOutput {
Expand Down
10 changes: 4 additions & 6 deletions crates/pack-core/src/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use turbopack_core::{
#[turbo_tasks::function]
pub async fn emit_assets(
assets: Vc<ExpandedOutputAssets>,
node_root: FileSystemPath,
_node_root: FileSystemPath,
client_relative_path: FileSystemPath,
client_output_path: FileSystemPath,
) -> Result<()> {
Expand All @@ -24,18 +24,16 @@ pub async fn emit_assets(
.iter()
.copied()
.map(|asset| {
let node_root = node_root.clone();
let client_relative_path = client_relative_path.clone();
let client_output_path = client_output_path.clone();

async move {
let path = asset.path();
let span = tracing::trace_span!("emit asset", name = %path.to_string().await?);
// We allow to write output out of dist path, this is different with next.js
async move {
let path = path.await?;
Ok(if path.is_inside_ref(&node_root) {
Some(emit(*asset))
} else if path.is_inside_ref(&client_relative_path) {
Ok(if path.is_inside_ref(&client_relative_path) {
// Client assets are emitted to the client output path, which is prefixed
// with _next. We need to rebase them to remove that
// prefix.
Expand All @@ -45,7 +43,7 @@ pub async fn emit_assets(
client_output_path,
))
} else {
None
Some(emit(*asset))
})
}
.instrument(span)
Expand Down
16 changes: 12 additions & 4 deletions crates/pack-napi/src/pack_api/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ use pack_core::tracing_presets::{
TRACING_TURBOPACK_TARGETS,
};
use tracing::Instrument;
use tracing_subscriber::{EnvFilter, Registry, layer::SubscriberExt, util::SubscriberInitExt};
use tracing_subscriber::{
EnvFilter, Registry, fmt::format::FmtSpan, layer::SubscriberExt, util::SubscriberInitExt,
};
use turbo_rcstr::RcStr;
use turbo_tasks::{
NonLocalValue, OperationValue, PrettyPrintError, ReadRef, ResolvedVc, TaskInput,
Expand Down Expand Up @@ -367,12 +369,18 @@ pub async fn project_new(
});
} else {
TRACING_INIT.call_once(|| {
let env_filter = EnvFilter::try_from_default_env();
let env_filter_enabled = env_filter.is_ok();
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::try_from_default_env().unwrap_or_else(|_| {
.with_env_filter(env_filter.unwrap_or_else(|_| {
EnvFilter::new("pack_napi=info,pack_api=info,pack_core=info")
}))
.with_target(false)
.with_span_events(tracing_subscriber::fmt::format::FmtSpan::NONE)
.with_target(env_filter_enabled)
.with_span_events(if env_filter_enabled {
FmtSpan::CLOSE
} else {
FmtSpan::NONE
})
.with_timer(tracing_subscriber::fmt::time::ChronoLocal::new(
"%Y-%m-%d %H:%M:%S.%3f".to_string(),
))
Expand Down
72 changes: 36 additions & 36 deletions package-lock.json

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

3 changes: 3 additions & 0 deletions packages/pack-shared/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ export interface HtmlConfig {
inject?: boolean | "body" | "head";
scriptLoading?: "blocking" | "defer" | "module";
meta?: Record<string, string | { [key: string]: string }>;
output?: {
path?: string;
};
}

export interface StyledComponentsConfig {
Expand Down
3 changes: 1 addition & 2 deletions packages/pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@swc/helpers": "0.5.15",
"@utoo/pack-shared": "*",
"@utoo/style-loader": "^1.0.0",
"domparser-rs": "^0.0.5",
"domparser-rs": "^0.0.7",
"find-up": "4.1.0",
"nanoid": "^3.3.11",
"picocolors": "^1.1.1",
Expand All @@ -67,7 +67,6 @@
"styled-jsx": "^5.1.6",
"typescript": "^5.8.3"
},

"engines": {
"node": ">= 20"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/pack/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async function buildInternal(
packPath: getPackPath(),
},
{
persistentCaching: false,
persistentCaching: bundleOptions.config.persistentCaching ?? false,
},
);

Expand Down
2 changes: 1 addition & 1 deletion packages/pack/src/core/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export async function createHotReloader(
packPath: getPackPath(),
},
{
persistentCaching: true,
persistentCaching: bundleOptions.config.persistentCaching ?? false,
},
);

Expand Down
5 changes: 4 additions & 1 deletion packages/pack/src/plugins/HtmlPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ export class HtmlPlugin {

const finalHtml = doc.outerHTML;
const filename = this.config.filename || "index.html";
fs.writeFileSync(path.join(outputDir, filename), finalHtml);
fs.writeFileSync(
path.join(this.config.output?.path ?? outputDir, filename),
finalHtml,
);
}
}
2 changes: 2 additions & 0 deletions packages/pack/src/utils/htmlEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ export function processHtmlEntry(config: ConfigComplete, projectPath: string) {
}

newEntries.push({
...entry,
import: scriptPath,
html: {
...entry.html,
template: entry.import,
templateContent: doc.outerHTML,
filename: path.basename(entry.import),
Expand Down
Loading