Unverified Commit c5299239 authored by OJ Kwon's avatar OJ Kwon Committed by GitHub

feat(next-swc): lightningcss binding (#62604)

### What

This PR enables lightningcss features in next-swc. Currently this is for
the native build targets only, for the wasm there are some unknown build
error prevents to enable this.

Closes PACK-2607
parent acdf052e
This diff is collapsed.
......@@ -92,11 +92,14 @@ indoc = "2.0.0"
itertools = "0.10.5"
lazy_static = "1.4.0"
log = "0.4.17"
lightningcss = { version = "1.0.0-alpha.50", features = [
lightningcss = { version = "=1.0.0-alpha.54", features = [
"serde",
"visitor",
"into_owned",
] }
lightningcss-napi = { version = "0.1.0", default-features = false, features = [
"visitor"
]}
mime = "0.3.16"
nohash-hasher = "0.2.0"
once_cell = "1.17.1"
......
......@@ -68,6 +68,10 @@ napi = { version = "2", default-features = false, features = [
"serde-json",
"tokio_rt",
"error_anyhow",
# Lightningcss uses this features
"napi4",
"napi5",
"compat-mode"
] }
napi-derive = "2"
next-custom-transforms = { workspace = true }
......@@ -83,6 +87,7 @@ urlencoding = {workspace = true}
# Dependencies for the native, non-wasm32 build.
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
lightningcss-napi = { workspace = true }
tokio = { workspace = true, features = ["full"] }
turbo-tasks = { workspace = true }
next-api = { workspace = true }
......
use napi::{CallContext, JsObject, JsUnknown};
use napi_derive::{js_function, module_exports};
#[allow(clippy::not_unsafe_ptr_arg_deref)]
#[js_function(1)]
fn transform(ctx: CallContext) -> napi::Result<JsUnknown> {
lightningcss_napi::transform(ctx)
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
#[js_function(1)]
fn transform_style_attribute(ctx: CallContext) -> napi::Result<JsUnknown> {
lightningcss_napi::transform_style_attribute(ctx)
}
#[cfg_attr(not(target_arch = "wasm32"), module_exports)]
fn init(mut exports: JsObject) -> napi::Result<()> {
exports.create_named_method("lightningCssTransform", transform)?;
exports.create_named_method(
"lightningCssTransformStyleAttribute",
transform_style_attribute,
)?;
Ok(())
}
......@@ -49,6 +49,8 @@ use turbopack_binding::swc::core::{
#[cfg(not(target_arch = "wasm32"))]
pub mod app_structure;
#[cfg(not(target_arch = "wasm32"))]
pub mod css;
pub mod mdx;
pub mod minify;
#[cfg(not(target_arch = "wasm32"))]
......
......@@ -15,7 +15,7 @@
"rust-check-fmt": "cd ../..; cargo fmt -- --check",
"rust-check-clippy": "cargo clippy --workspace --all-targets -- -D warnings -A deprecated",
"rust-check-napi-rustls": "cargo check -p next-swc-napi",
"test-cargo-unit": "cargo nextest run --workspace --release --no-fail-fast"
"test-cargo-unit": "cargo nextest run --workspace --exclude next-swc-napi --release --no-fail-fast --features rustls-tls"
},
"napi": {
"name": "next-swc",
......
......@@ -173,6 +173,12 @@ export interface Binding {
teardownTraceSubscriber?: any
initHeapProfiler?: any
teardownHeapProfiler?: any
css: {
lightning: {
transform(transformOptions: any): Promise<any>
transformStyleAttr(attrOptions: any): Promise<any>
}
}
}
export async function loadBindings(
......@@ -1444,6 +1450,14 @@ function loadNative(importPath?: string) {
compileSync: (src: string, options: any) =>
bindings.mdxCompileSync(src, toBuffer(getMdxOptions(options))),
},
css: {
lightning: {
transform: (transformOptions: any) =>
bindings.lightningCssTransform(transformOptions),
transformStyleAttr: (transformAttrOptions: any) =>
bindings.lightningCssTransformStyleAttribute(transformAttrOptions),
},
},
}
return nativeBindings
}
......
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