Unverified Commit 29d53c87 authored by Donny/강동윤's avatar Donny/강동윤 Committed by GitHub

feat(next-swc): Pass names of side-effect-free packages (#63268)

### What?

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

Turbopack counterpart: https://github.com/vercel/turbo/pull/7731

### Why?

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

### How?

Closes PACK-2527
parent c9439b56
This diff is collapsed.
......@@ -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
......
use anyhow::{Context, Result};
use turbo_tasks::{TryJoinIterExt, ValueToString, Vc};
use turbo_tasks_fs::glob::Glob;
use turbopack_binding::turbopack::{
core::{
asset::{Asset, AssetContent},
......@@ -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)
}
}
......
......@@ -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()
};
......
......@@ -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
......
......@@ -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()
};
......
......@@ -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",
......
......@@ -1071,8 +1071,8 @@ importers:
specifier: 0.26.4
version: 0.26.4
'@vercel/turbopack-ecmascript-runtime':
specifier: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240327.2
version: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240327.2'
specifier: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240329.2
version: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240329.2'
acorn:
specifier: 8.5.0
version: 8.5.0
......@@ -25486,8 +25486,8 @@ packages:
/zwitch@2.0.4:
resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==}
'@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240327.2':
resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240327.2}
'@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240329.2':
resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240329.2}
name: '@vercel/turbopack-ecmascript-runtime'
version: 0.0.0
dependencies:
......
import { join } from 'path'
import { createNextDescribe } from 'e2e-utils'
import { hasRedbox } from 'next-test-utils'
createNextDescribe(
'optimizePackageImports - mui',
{
env: {
NEXT_TEST_MODE: '1',
},
files: join(__dirname, 'fixture-tremor'),
dependencies: {
'@headlessui/react': '^1.7.18',
'@headlessui/tailwindcss': '^0.2.0',
'@remixicon/react': '^4.2.0',
'@tremor/react': '^3.14.1',
},
},
({ next }) => {
it('should work', async () => {
// Without barrel optimization, the reproduction breaks.
const browser = await next.browser('/')
expect(await hasRedbox(browser)).toBe(false)
})
}
)
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode
}>) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
import { Card } from '@tremor/react'
export default function Example() {
return <Card></Card>
}
/** @type {import('next').NextConfig} */
const nextConfig = {}
export default nextConfig
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment