Skip to content

Commit 5802ba8

Browse files
authored
Turbopack Build: Implement browserslist for CSS / JS (#80603)
## What? Implement browserslist for CSS / JS handling in Turbopack. For JS it's not fully implemented yet, but for CSS it should be good now.
1 parent 5c15979 commit 5802ba8

File tree

30 files changed

+267
-86
lines changed

30 files changed

+267
-86
lines changed

Cargo.lock

Lines changed: 6 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ lightningcss = { version = "1.0.0-alpha.66", features = [
362362
"serde",
363363
"visitor",
364364
"into_owned",
365+
"browserslist"
365366
] }
366367
lightningcss-napi = { version = "0.4.4", default-features = false, features = [
367368
"visitor",
@@ -434,4 +435,6 @@ vergen-gitcl = { version = "1.0.8", features = [
434435
webbrowser = "0.8.7"
435436

436437
[patch.crates-io]
438+
lightningcss = { git = "https://github.com/timneutkens/lightningcss", branch = "add/browserslist-options"}
439+
parcel_selectors = { git = "https://github.com/timneutkens/lightningcss", branch = "add/browserslist-options"}
437440
mdxjs = { git = "https://github.com/kdy1/mdxjs-rs.git", branch = "swc-core-29" }

crates/next-api/benches/hmr.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
extern crate turbo_tasks_malloc;
22

33
use std::{
4+
env,
45
fs::{create_dir_all, write},
56
mem::forget,
67
path::{Path, PathBuf},
@@ -183,7 +184,10 @@ impl HmrBenchmark {
183184
project_path: RcStr::from(project_path.clone()),
184185
next_config: load_next_config(),
185186
js_config: RcStr::from("{}"),
186-
env: vec![],
187+
env: vec![(
188+
RcStr::from("PATH"),
189+
RcStr::from(env::var("PATH").unwrap_or_default()),
190+
)],
187191
define_env: DefineEnv {
188192
client: vec![],
189193
edge: vec![],

crates/next-api/src/app.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ impl AppProject {
242242
self.project().next_config(),
243243
NextRuntime::NodeJs,
244244
self.project().encryption_key(),
245+
self.project().server_compile_time_info().environment(),
245246
))
246247
}
247248

@@ -255,6 +256,7 @@ impl AppProject {
255256
self.project().next_config(),
256257
NextRuntime::Edge,
257258
self.project().encryption_key(),
259+
self.project().edge_compile_time_info().environment(),
258260
))
259261
}
260262

@@ -268,6 +270,7 @@ impl AppProject {
268270
self.project().next_config(),
269271
NextRuntime::NodeJs,
270272
self.project().encryption_key(),
273+
self.project().server_compile_time_info().environment(),
271274
))
272275
}
273276

@@ -281,6 +284,7 @@ impl AppProject {
281284
self.project().next_config(),
282285
NextRuntime::Edge,
283286
self.project().encryption_key(),
287+
self.project().edge_compile_time_info().environment(),
284288
))
285289
}
286290

@@ -592,6 +596,7 @@ impl AppProject {
592596
self.project().next_config(),
593597
NextRuntime::NodeJs,
594598
self.project().encryption_key(),
599+
self.project().server_compile_time_info().environment(),
595600
))
596601
}
597602

@@ -605,6 +610,7 @@ impl AppProject {
605610
self.project().next_config(),
606611
NextRuntime::Edge,
607612
self.project().encryption_key(),
613+
self.project().edge_compile_time_info().environment(),
608614
))
609615
}
610616

crates/next-api/src/pages.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ impl PagesProject {
450450
self.project().next_config(),
451451
NextRuntime::NodeJs,
452452
self.project().encryption_key(),
453+
self.project().server_compile_time_info().environment(),
453454
))
454455
}
455456

@@ -465,6 +466,7 @@ impl PagesProject {
465466
self.project().next_config(),
466467
NextRuntime::Edge,
467468
self.project().encryption_key(),
469+
self.project().edge_compile_time_info().environment(),
468470
))
469471
}
470472

@@ -480,6 +482,7 @@ impl PagesProject {
480482
self.project().next_config(),
481483
NextRuntime::NodeJs,
482484
self.project().encryption_key(),
485+
self.project().server_compile_time_info().environment(),
483486
))
484487
}
485488

@@ -495,6 +498,7 @@ impl PagesProject {
495498
self.project().next_config(),
496499
NextRuntime::Edge,
497500
self.project().encryption_key(),
501+
self.project().edge_compile_time_info().environment(),
498502
))
499503
}
500504

@@ -510,6 +514,7 @@ impl PagesProject {
510514
self.project().next_config(),
511515
NextRuntime::NodeJs,
512516
self.project().encryption_key(),
517+
self.project().server_compile_time_info().environment(),
513518
))
514519
}
515520

@@ -527,6 +532,7 @@ impl PagesProject {
527532
self.project().next_config(),
528533
NextRuntime::Edge,
529534
self.project().encryption_key(),
535+
self.project().edge_compile_time_info().environment(),
530536
))
531537
}
532538

crates/next-api/src/project.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ impl Project {
986986
Ok(get_edge_compile_time_info(
987987
self.project_path(),
988988
this.define_env.edge(),
989+
self.env(),
989990
))
990991
}
991992

@@ -1306,6 +1307,7 @@ impl Project {
13061307
self.next_config(),
13071308
NextRuntime::Edge,
13081309
self.encryption_key(),
1310+
self.edge_compile_time_info().environment(),
13091311
),
13101312
get_edge_resolve_options_context(
13111313
self.project_path(),
@@ -1361,6 +1363,7 @@ impl Project {
13611363
self.next_config(),
13621364
NextRuntime::NodeJs,
13631365
self.encryption_key(),
1366+
self.server_compile_time_info().environment(),
13641367
),
13651368
get_server_resolve_options_context(
13661369
self.project_path(),
@@ -1473,6 +1476,7 @@ impl Project {
14731476
self.next_config(),
14741477
NextRuntime::NodeJs,
14751478
self.encryption_key(),
1479+
self.server_compile_time_info().environment(),
14761480
),
14771481
get_server_resolve_options_context(
14781482
self.project_path(),
@@ -1528,6 +1532,7 @@ impl Project {
15281532
self.next_config(),
15291533
NextRuntime::Edge,
15301534
self.encryption_key(),
1535+
self.edge_compile_time_info().environment(),
15311536
),
15321537
get_edge_resolve_options_context(
15331538
self.project_path(),

crates/next-core/src/next_client/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ pub async fn get_client_module_options_context(
342342
source_maps,
343343
..Default::default()
344344
},
345-
preset_env_versions: Some(env),
345+
environment: Some(env),
346346
execution_context: Some(execution_context),
347347
tree_shaking_mode: tree_shaking_mode_for_user_code,
348348
enable_postcss_transform,

crates/next-core/src/next_edge/context.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::Result;
22
use turbo_rcstr::{RcStr, rcstr};
33
use turbo_tasks::{FxIndexMap, OptionVcExt, ResolvedVc, Vc};
4-
use turbo_tasks_env::EnvMap;
4+
use turbo_tasks_env::{EnvMap, ProcessEnv};
55
use turbo_tasks_fs::FileSystemPath;
66
use turbopack::{css::chunk::CssChunkType, resolve_options_context::ResolveOptionsContext};
77
use turbopack_browser::BrowserChunkingContext;
@@ -14,7 +14,7 @@ use turbopack_core::{
1414
CompileTimeDefineValue, CompileTimeDefines, CompileTimeInfo, DefineableNameSegment,
1515
FreeVarReference, FreeVarReferences,
1616
},
17-
environment::{EdgeWorkerEnvironment, Environment, ExecutionEnvironment},
17+
environment::{EdgeWorkerEnvironment, Environment, ExecutionEnvironment, NodeJsVersion},
1818
free_var_references,
1919
};
2020
use turbopack_ecmascript::chunk::EcmascriptChunkType;
@@ -83,10 +83,16 @@ async fn next_edge_free_vars(
8383
pub async fn get_edge_compile_time_info(
8484
project_path: Vc<FileSystemPath>,
8585
define_env: Vc<EnvMap>,
86+
process_env: Vc<Box<dyn ProcessEnv>>,
8687
) -> Result<Vc<CompileTimeInfo>> {
8788
CompileTimeInfo::builder(
8889
Environment::new(ExecutionEnvironment::EdgeWorker(
89-
EdgeWorkerEnvironment {}.resolved_cell(),
90+
EdgeWorkerEnvironment {
91+
node_version: NodeJsVersion::resolved_cell(NodeJsVersion::Current(
92+
process_env.to_resolved().await?,
93+
)),
94+
}
95+
.resolved_cell(),
9096
))
9197
.to_resolved()
9298
.await?,

crates/next-core/src/next_server/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ pub async fn get_server_module_options_context(
414414
next_config: Vc<NextConfig>,
415415
next_runtime: NextRuntime,
416416
encryption_key: ResolvedVc<RcStr>,
417+
environment: ResolvedVc<Environment>,
417418
) -> Result<Vc<ModuleOptionsContext>> {
418419
let next_mode = mode.await?;
419420
let mut next_server_rules = get_next_server_transforms_rules(
@@ -553,6 +554,7 @@ pub async fn get_server_module_options_context(
553554
..Default::default()
554555
},
555556
execution_context: Some(execution_context),
557+
environment: Some(environment),
556558
css: CssOptionsContext {
557559
source_maps,
558560
..Default::default()

packages/next/src/build/swc/generated-native.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function lightningCssTransformStyleAttribute(
2828

2929
/* auto-generated by NAPI-RS */
3030

31-
export class ExternalObject<T> {
31+
export declare class ExternalObject<T> {
3232
readonly '': {
3333
readonly '': unique symbol
3434
[K: symbol]: T

0 commit comments

Comments
 (0)