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

fix(next-core): enable image extensions (#55460)



### What?

Enables the image extensions supported by turbopack.

Also fixes test fixture to assert error overlay header.


Closes WEB-1587
parent c6c38916
...@@ -156,7 +156,7 @@ jobs: ...@@ -156,7 +156,7 @@ jobs:
build: >- build: >-
set -e && set -e &&
apt update && apt update &&
apt install -y pkg-config xz-utils && apt install -y pkg-config xz-utils dav1d libdav1d-dev &&
rustup toolchain install "${RUST_TOOLCHAIN}" && rustup toolchain install "${RUST_TOOLCHAIN}" &&
rustup default "${RUST_TOOLCHAIN}" && rustup default "${RUST_TOOLCHAIN}" &&
rustup target add x86_64-unknown-linux-gnu && rustup target add x86_64-unknown-linux-gnu &&
...@@ -177,7 +177,7 @@ jobs: ...@@ -177,7 +177,7 @@ jobs:
build: >- build: >-
set -e && set -e &&
apk update && apk update &&
apk add --no-cache libc6-compat pkgconfig && apk add --no-cache libc6-compat pkgconfig dav1d libdav1d dav1d-dev &&
rustup toolchain install "${RUST_TOOLCHAIN}" && rustup toolchain install "${RUST_TOOLCHAIN}" &&
rustup default "${RUST_TOOLCHAIN}" && rustup default "${RUST_TOOLCHAIN}" &&
rustup target add x86_64-unknown-linux-musl && rustup target add x86_64-unknown-linux-musl &&
...@@ -196,7 +196,7 @@ jobs: ...@@ -196,7 +196,7 @@ jobs:
build: >- build: >-
set -e && set -e &&
apt update && apt update &&
apt install -y pkg-config xz-utils && apt install -y pkg-config xz-utils dav1d libdav1d-dev &&
export JEMALLOC_SYS_WITH_LG_PAGE=16 && export JEMALLOC_SYS_WITH_LG_PAGE=16 &&
rustup toolchain install "${RUST_TOOLCHAIN}" && rustup toolchain install "${RUST_TOOLCHAIN}" &&
rustup default "${RUST_TOOLCHAIN}" && rustup default "${RUST_TOOLCHAIN}" &&
...@@ -218,7 +218,7 @@ jobs: ...@@ -218,7 +218,7 @@ jobs:
build: >- build: >-
set -e && set -e &&
apk update && apk update &&
apk add --no-cache libc6-compat pkgconfig && apk add --no-cache libc6-compat pkgconfig dav1d libdav1d dav1d-dev &&
export JEMALLOC_SYS_WITH_LG_PAGE=16 && export JEMALLOC_SYS_WITH_LG_PAGE=16 &&
npm i -g "@napi-rs/cli@${NAPI_CLI_VERSION}" && npm i -g "@napi-rs/cli@${NAPI_CLI_VERSION}" &&
rustup toolchain install "${RUST_TOOLCHAIN}" && rustup toolchain install "${RUST_TOOLCHAIN}" &&
......
...@@ -21,6 +21,13 @@ native-tls = ["next-dev/native-tls"] ...@@ -21,6 +21,13 @@ native-tls = ["next-dev/native-tls"]
rustls-tls = ["next-dev/rustls-tls"] rustls-tls = ["next-dev/rustls-tls"]
serializable = ["next-dev/serializable"] serializable = ["next-dev/serializable"]
image-webp = ["next-core/image-webp"] image-webp = ["next-core/image-webp"]
image-avif = ["next-core/image-avif"]
# Enable all the available image codec support.
# Currently this is identical to `image-webp`, as we are not able to build
# other codecs easily yet.
image-extended = [
"image-webp",
]
# Enable dhat profiling allocator for heap profiling. # Enable dhat profiling allocator for heap profiling.
__internal_dhat-heap = ["dhat"] __internal_dhat-heap = ["dhat"]
......
...@@ -73,6 +73,7 @@ native-tls = ["turbopack-binding/__turbo_tasks_fetch_native-tls"] ...@@ -73,6 +73,7 @@ native-tls = ["turbopack-binding/__turbo_tasks_fetch_native-tls"]
rustls-tls = ["turbopack-binding/__turbo_tasks_fetch_rustls-tls"] rustls-tls = ["turbopack-binding/__turbo_tasks_fetch_rustls-tls"]
plugin = ["turbopack-binding/__swc_core_binding_napi_plugin"] plugin = ["turbopack-binding/__swc_core_binding_napi_plugin"]
image-webp = ["turbopack-binding/__turbopack_image_webp"] image-webp = ["turbopack-binding/__turbopack_image_webp"]
image-avif = ["turbopack-binding/__turbopack_image_avif"]
# enable "HMR" for embedded assets # enable "HMR" for embedded assets
dynamic_embed_contents = [ dynamic_embed_contents = [
......
...@@ -28,11 +28,16 @@ pub fn get_next_image_rule() -> ModuleRule { ...@@ -28,11 +28,16 @@ pub fn get_next_image_rule() -> ModuleRule {
ModuleRuleCondition::ResourcePathEndsWith(".jpg".to_string()), ModuleRuleCondition::ResourcePathEndsWith(".jpg".to_string()),
ModuleRuleCondition::ResourcePathEndsWith(".jpeg".to_string()), ModuleRuleCondition::ResourcePathEndsWith(".jpeg".to_string()),
ModuleRuleCondition::ResourcePathEndsWith(".png".to_string()), ModuleRuleCondition::ResourcePathEndsWith(".png".to_string()),
ModuleRuleCondition::ResourcePathEndsWith(".webp".to_string()),
ModuleRuleCondition::ResourcePathEndsWith(".avif".to_string()),
ModuleRuleCondition::ResourcePathEndsWith(".apng".to_string()), ModuleRuleCondition::ResourcePathEndsWith(".apng".to_string()),
ModuleRuleCondition::ResourcePathEndsWith(".gif".to_string()), ModuleRuleCondition::ResourcePathEndsWith(".gif".to_string()),
ModuleRuleCondition::ResourcePathEndsWith(".svg".to_string()), ModuleRuleCondition::ResourcePathEndsWith(".svg".to_string()),
ModuleRuleCondition::ResourcePathEndsWith(".bmp".to_string()),
ModuleRuleCondition::ResourcePathEndsWith(".ico".to_string()),
// These images may not be encoded by turbopack depends on the feature availability
// As turbopack-image returns raw bytes if compile time codec support is not enabled:
// ref:https://github.com/vercel/turbo/pull/5967
ModuleRuleCondition::ResourcePathEndsWith(".webp".to_string()),
ModuleRuleCondition::ResourcePathEndsWith(".avif".to_string()),
]), ]),
vec![ModuleRuleEffect::ModuleType(ModuleType::Custom( vec![ModuleRuleEffect::ModuleType(ModuleType::Custom(
Vc::upcast(StructuredImageModuleType::new(Value::new( Vc::upcast(StructuredImageModuleType::new(Value::new(
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
"private": true, "private": true,
"scripts": { "scripts": {
"clean": "node ../../scripts/rm.mjs native", "clean": "node ../../scripts/rm.mjs native",
"build-native": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --features plugin,rustls-tls,image-webp --js false native", "build-native": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --features plugin,rustls-tls,image-extended --js false native",
"build-native-release": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --release --features plugin,rustls-tls,image-webp,tracing/release_max_level_info --js false native", "build-native-release": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --release --features plugin,rustls-tls,image-extended,tracing/release_max_level_info --js false native",
"build-native-no-plugin": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --features image-webp --js false native", "build-native-no-plugin": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --features image-webp --js false native",
"build-native-no-plugin-woa": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --cargo-flags=--no-default-features --features native-tls,image-webp --js false native", "build-native-no-plugin-woa": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --cargo-flags=--no-default-features --features native-tls,image-webp --js false native",
"build-native-no-plugin-woa-release": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --release --cargo-flags=--no-default-features --features native-tls,image-webp,tracing/release_max_level_info --js false native", "build-native-no-plugin-woa-release": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --release --cargo-flags=--no-default-features --features native-tls,image-webp,tracing/release_max_level_info --js false native",
......
...@@ -781,28 +781,15 @@ export async function hasRedbox(browser: BrowserInterface, expected = true) { ...@@ -781,28 +781,15 @@ export async function hasRedbox(browser: BrowserInterface, expected = true) {
export async function getRedboxHeader(browser: BrowserInterface) { export async function getRedboxHeader(browser: BrowserInterface) {
return retry( return retry(
() => { () => {
if (shouldRunTurboDevTest()) { return evaluate(browser, () => {
return evaluate(browser, () => { const portal = [].slice
const portal = [].slice .call(document.querySelectorAll('nextjs-portal'))
.call(document.querySelectorAll('nextjs-portal')) .find((p) =>
.find((p) => p.shadowRoot.querySelector('[data-nextjs-dialog-header]')
p.shadowRoot.querySelector('[data-nextjs-turbo-dialog-body]') )
) const root = portal?.shadowRoot
const root = portal?.shadowRoot return root?.querySelector('[data-nextjs-dialog-header]')?.innerText
return root?.querySelector('[data-nextjs-turbo-dialog-body]') })
?.innerText
})
} else {
return evaluate(browser, () => {
const portal = [].slice
.call(document.querySelectorAll('nextjs-portal'))
.find((p) =>
p.shadowRoot.querySelector('[data-nextjs-dialog-header]')
)
const root = portal?.shadowRoot
return root?.querySelector('[data-nextjs-dialog-header]')?.innerText
})
}
}, },
10000, 10000,
500, 500,
......
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