Skip to content

Commit

Permalink
feat(next-swc): Pass names of side-effect-free packages (#63268)
Browse files Browse the repository at this point in the history
### What?

Pass the names of side-effect-free packages specified in `experimental.optimizePackageImports`.

Turbopack counterpart: vercel/turborepo#7731

### Why?

Some packages like `@tremor/react` causes a problem without `optimizePackageImports`.

### How?

Closes PACK-2527
  • Loading branch information
kdy1 committed Mar 29, 2024
1 parent c9439b5 commit 29d53c8
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 44 deletions.
70 changes: 35 additions & 35 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ swc_core = { version = "0.90.24", features = [
testing = { version = "0.35.21" }

# Turbo crates
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240327.2" }
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240329.2" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240327.2" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240329.2" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240327.2" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240329.2" }

# General Deps

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::{Context, Result};
use turbo_tasks::{TryJoinIterExt, ValueToString, Vc};
use turbo_tasks_fs::glob::Glob;
use turbopack_binding::turbopack::{
core::{
asset::{Asset, AssetContent},
Expand Down Expand Up @@ -68,7 +69,7 @@ impl EcmascriptChunkPlaceable for IncludeModulesModule {
}

#[turbo_tasks::function]
fn is_marked_as_side_effect_free(self: Vc<Self>) -> Vc<bool> {
fn is_marked_as_side_effect_free(self: Vc<Self>, _: Vc<Glob>) -> Vc<bool> {
Vc::cell(true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ pub async fn get_client_module_options_context(
execution_context: Some(execution_context),
tree_shaking_mode: Some(TreeShakingMode::ReexportsOnly),
enable_postcss_transform,
side_effect_free_packages: next_config.optimize_package_imports().await?.clone_value(),
..Default::default()
};

Expand Down
11 changes: 11 additions & 0 deletions packages/next-swc/crates/next-core/src/next_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,17 @@ impl NextConfig {
.unwrap_or(false),
))
}

#[turbo_tasks::function]
pub async fn optimize_package_imports(self: Vc<Self>) -> Result<Vc<Vec<String>>> {
Ok(Vc::cell(
self.await?
.experimental
.optimize_package_imports
.clone()
.unwrap_or_default(),
))
}
}

/// A subset of ts/jsconfig that next.js implicitly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ pub async fn get_server_module_options_context(
tree_shaking_mode: Some(TreeShakingMode::ReexportsOnly),
import_externals: *next_config.import_externals().await?,
ignore_dynamic_requests: true,
side_effect_free_packages: next_config.optimize_package_imports().await?.clone_value(),
..Default::default()
};

Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
"@types/ws": "8.2.0",
"@vercel/ncc": "0.34.0",
"@vercel/nft": "0.26.4",
"@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240327.2",
"@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240329.2",
"acorn": "8.5.0",
"amphtml-validator": "1.0.35",
"anser": "1.4.9",
Expand Down
Loading

0 comments on commit 29d53c8

Please sign in to comment.