use structured images with metainfo (blur placeholder) (#48531)

### What?

add support for blur placeholder generation to turbopack

add `StructuredImageModuleType` which is used with `ModuleType::Custom`
to allow importing an image as `{ url, width, height, blurDataURL,
blurWidth, blurHeight }`

in contrast to next.js with webpack this will also generate blur
placeholder in development instead of using a _next/image reference.
This should lead to more production-like experience (at the cost of a
little bit of compilation time).

turbo PR: https://github.com/vercel/turbo/pull/4621

### Why?

Turbopack was crashing on `placeholder="blur"` before.

fixes WEB-534

### Turbopack changes

* https://github.com/vercel/turbo/pull/4521 <!-- OJ Kwon -
feat(contextcondition): support InPath contextcondition -->
* https://github.com/vercel/turbo/pull/4601 <!-- Alex Kirszenberg -
Chunking Context Refactor pt. 3: Address PR comments from pt. 2 -->
* https://github.com/vercel/turbo/pull/4623 <!-- Tobias Koppers -
exclude turborepo from turbopack bench tests -->
* https://github.com/vercel/turbo/pull/4399 <!-- Leah - support
require.context -->
* https://github.com/vercel/turbo/pull/4610 <!-- OJ Kwon - test(subset):
add mdx test into subset -->
* https://github.com/vercel/turbo/pull/4624 <!-- Tobias Koppers - run
benchmarks on windows and macOS too -->
* https://github.com/vercel/turbo/pull/4620 <!-- Alex Kirszenberg - Make
ContainmentTree fully generic -->
* https://github.com/vercel/turbo/pull/4600 <!-- Tobias Koppers - add
getChunkPath method -->
* https://github.com/vercel/turbo/pull/4621 <!-- Tobias Koppers - add
turbopack-image -->
* https://github.com/vercel/turbo/pull/4639 <!-- Tobias Koppers -
restrict snapshot path for windows path length limit -->
* https://github.com/vercel/turbo/pull/4641 <!-- Tobias Koppers - put
webp behind a feature flag -->
This commit is contained in:
Tobias Koppers 2023-04-20 02:18:59 +02:00 committed by GitHub
parent 925bb3b025
commit 189e6a3687
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 498 additions and 70 deletions

203
Cargo.lock generated
View file

@ -400,7 +400,7 @@ dependencies = [
[[package]]
name = "auto-hash-map"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"serde",
]
@ -478,7 +478,7 @@ dependencies = [
"cc",
"cfg-if 1.0.0",
"libc",
"miniz_oxide",
"miniz_oxide 0.6.2",
"object",
"rustc-demangle",
]
@ -666,6 +666,12 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "bytemuck"
version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea"
[[package]]
name = "byteorder"
version = "1.4.3"
@ -803,6 +809,7 @@ dependencies = [
"js-sys",
"num-integer",
"num-traits",
"serde",
"time 0.1.45",
"wasm-bindgen",
"winapi 0.3.9",
@ -912,6 +919,12 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "color_quant"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
[[package]]
name = "combine"
version = "4.6.6"
@ -1402,6 +1415,7 @@ dependencies = [
"ident_case",
"proc-macro2",
"quote",
"strsim",
"syn 1.0.109",
]
@ -1690,6 +1704,15 @@ dependencies = [
"instant",
]
[[package]]
name = "fdeflate"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d329bdeac514ee06249dabc27877490f17f5d371ec693360768b838e19f3ae10"
dependencies = [
"simd-adler32",
]
[[package]]
name = "filetime"
version = "0.2.21"
@ -1715,7 +1738,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841"
dependencies = [
"crc32fast",
"miniz_oxide",
"miniz_oxide 0.6.2",
]
[[package]]
@ -2343,6 +2366,21 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb56e1aa765b4b4f3aadfab769793b7087bb03a4ea4920644a6d238e2df5b9ed"
[[package]]
name = "image"
version = "0.24.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "527909aa81e20ac3a44803521443a765550f09b5130c2c2fa1ea59c2f8f50a3a"
dependencies = [
"bytemuck",
"byteorder",
"color_quant",
"jpeg-decoder",
"num-rational",
"num-traits",
"png",
]
[[package]]
name = "include_dir"
version = "0.7.3"
@ -2530,6 +2568,12 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
[[package]]
name = "jpeg-decoder"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e"
[[package]]
name = "js-sys"
version = "0.3.61"
@ -2973,6 +3017,16 @@ dependencies = [
"adler",
]
[[package]]
name = "miniz_oxide"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7"
dependencies = [
"adler",
"simd-adler32",
]
[[package]]
name = "mintex"
version = "0.1.2"
@ -3357,7 +3411,7 @@ dependencies = [
[[package]]
name = "node-file-trace"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"serde",
@ -3447,6 +3501,17 @@ dependencies = [
"num-traits",
]
[[package]]
name = "num-rational"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.15"
@ -3877,6 +3942,19 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "png"
version = "0.17.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aaeebc51f9e7d2c150d3f3bfeb667f2aa985db5ef1e3d212847bdedb488beeaa"
dependencies = [
"bitflags 1.3.2",
"crc32fast",
"fdeflate",
"flate2",
"miniz_oxide 0.7.1",
]
[[package]]
name = "polling"
version = "2.6.0"
@ -4747,6 +4825,34 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_with"
version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "331bb8c3bf9b92457ab7abecf07078c13f7d270ba490103e84e8b014490cd0b0"
dependencies = [
"base64 0.13.1",
"chrono",
"hex",
"indexmap",
"serde",
"serde_json",
"serde_with_macros",
"time 0.3.20",
]
[[package]]
name = "serde_with_macros"
version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "859011bddcc11f289f07f467cc1fe01c7a941daa4d8f6c40d4d1c92eb6d9319c"
dependencies = [
"darling",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "serde_yaml"
version = "0.8.26"
@ -4868,6 +4974,12 @@ dependencies = [
"libc",
]
[[package]]
name = "simd-adler32"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "238abfbb77c1915110ad968465608b68e869e0772622c9656714e73e5a1a522f"
[[package]]
name = "simdutf8"
version = "0.1.4"
@ -6860,7 +6972,7 @@ dependencies = [
[[package]]
name = "turbo-binding"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"auto-hash-map",
"mdxjs",
@ -6890,14 +7002,16 @@ dependencies = [
"turbopack-dev-server",
"turbopack-ecmascript",
"turbopack-env",
"turbopack-image",
"turbopack-node",
"turbopack-static",
"turbopack-test-utils",
]
[[package]]
name = "turbo-malloc"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"mimalloc",
]
@ -6905,7 +7019,7 @@ dependencies = [
[[package]]
name = "turbo-tasks"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"auto-hash-map",
@ -6935,7 +7049,7 @@ dependencies = [
[[package]]
name = "turbo-tasks-build"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"cargo-lock",
@ -6947,7 +7061,7 @@ dependencies = [
[[package]]
name = "turbo-tasks-bytes"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"bytes",
@ -6962,7 +7076,7 @@ dependencies = [
[[package]]
name = "turbo-tasks-env"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"dotenvy",
@ -6976,7 +7090,7 @@ dependencies = [
[[package]]
name = "turbo-tasks-fetch"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"indexmap",
@ -6993,7 +7107,7 @@ dependencies = [
[[package]]
name = "turbo-tasks-fs"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"auto-hash-map",
@ -7022,7 +7136,7 @@ dependencies = [
[[package]]
name = "turbo-tasks-hash"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"base16",
"hex",
@ -7034,7 +7148,7 @@ dependencies = [
[[package]]
name = "turbo-tasks-macros"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"convert_case 0.6.0",
@ -7048,7 +7162,7 @@ dependencies = [
[[package]]
name = "turbo-tasks-macros-shared"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"proc-macro2",
"quote",
@ -7058,7 +7172,7 @@ dependencies = [
[[package]]
name = "turbo-tasks-memory"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"auto-hash-map",
@ -7080,7 +7194,7 @@ dependencies = [
[[package]]
name = "turbo-tasks-testing"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"auto-hash-map",
@ -7092,10 +7206,11 @@ dependencies = [
[[package]]
name = "turbopack"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"async-recursion",
"futures",
"indexmap",
"lazy_static",
"regex",
@ -7109,6 +7224,7 @@ dependencies = [
"turbopack-css",
"turbopack-ecmascript",
"turbopack-env",
"turbopack-image",
"turbopack-json",
"turbopack-mdx",
"turbopack-node",
@ -7118,7 +7234,7 @@ dependencies = [
[[package]]
name = "turbopack-bench"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"chromiumoxide",
@ -7148,7 +7264,7 @@ dependencies = [
[[package]]
name = "turbopack-cli-utils"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"clap 4.1.11",
@ -7165,7 +7281,7 @@ dependencies = [
[[package]]
name = "turbopack-core"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"async-trait",
@ -7192,7 +7308,7 @@ dependencies = [
[[package]]
name = "turbopack-create-test-app"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"clap 4.1.11",
@ -7205,7 +7321,7 @@ dependencies = [
[[package]]
name = "turbopack-css"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"async-trait",
@ -7227,7 +7343,7 @@ dependencies = [
[[package]]
name = "turbopack-dev"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"indexmap",
@ -7241,13 +7357,14 @@ dependencies = [
"turbo-tasks-hash",
"turbopack",
"turbopack-core",
"turbopack-css",
"turbopack-ecmascript",
]
[[package]]
name = "turbopack-dev-server"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"async-compression",
@ -7281,7 +7398,7 @@ dependencies = [
[[package]]
name = "turbopack-ecmascript"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"async-trait",
@ -7317,7 +7434,7 @@ dependencies = [
[[package]]
name = "turbopack-env"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"indexmap",
@ -7330,10 +7447,28 @@ dependencies = [
"turbopack-ecmascript",
]
[[package]]
name = "turbopack-image"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"base64 0.21.0",
"image",
"indexmap",
"mime",
"serde",
"serde_with",
"turbo-tasks",
"turbo-tasks-build",
"turbo-tasks-fs",
"turbopack-core",
]
[[package]]
name = "turbopack-json"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"serde",
@ -7348,7 +7483,7 @@ dependencies = [
[[package]]
name = "turbopack-mdx"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"mdxjs",
@ -7363,7 +7498,7 @@ dependencies = [
[[package]]
name = "turbopack-node"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"async-stream",
@ -7397,7 +7532,7 @@ dependencies = [
[[package]]
name = "turbopack-static"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"serde",
@ -7413,7 +7548,7 @@ dependencies = [
[[package]]
name = "turbopack-swc-utils"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"swc_core",
"turbo-tasks",
@ -7424,7 +7559,7 @@ dependencies = [
[[package]]
name = "turbopack-test-utils"
version = "0.1.0"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230418.1#e6d32837a3800d2409110c6524dd874e6b0d06fe"
source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230419.4#816fab82aba04ab4bb06867e46bc1105986b82ab"
dependencies = [
"anyhow",
"once_cell",
@ -7442,7 +7577,7 @@ version = "1.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675"
dependencies = [
"cfg-if 0.1.10",
"cfg-if 1.0.0",
"rand",
"static_assertions",
]

View file

@ -42,11 +42,11 @@ swc_relay = { version = "0.2.5" }
testing = { version = "0.33.4" }
# Turbo crates
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230418.1" }
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230419.4" }
# [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-230418.1" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230419.4" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230418.1" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230419.4" }
# General Deps

View file

@ -36,6 +36,8 @@ turbo-binding = { workspace = true, features = [
"__turbopack_dev_server",
"__turbopack_ecmascript",
"__turbopack_env",
"__turbopack_static",
"__turbopack_image",
"__turbopack_node",
] }
turbo-tasks = { workspace = true }

View file

@ -10,8 +10,8 @@
"check": "tsc --noEmit"
},
"dependencies": {
"@vercel/turbopack-dev": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230418.1",
"@vercel/turbopack-node": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230418.1",
"@vercel/turbopack-dev": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230419.4",
"@vercel/turbopack-node": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230419.4",
"anser": "^2.1.1",
"css.escape": "^1.5.1",
"next": "*",

View file

@ -0,0 +1,62 @@
use anyhow::Result;
use indexmap::indexmap;
use turbo_binding::{
turbo::tasks::Value,
turbopack::{
core::{
asset::AssetVc,
context::{AssetContext, AssetContextVc},
plugin::{CustomModuleType, CustomModuleTypeVc},
resolve::ModulePartVc,
},
ecmascript::{
EcmascriptInputTransformsVc, EcmascriptModuleAssetType, EcmascriptModuleAssetVc,
EcmascriptOptions, InnerAssetsVc,
},
r#static::StaticModuleAssetVc,
},
};
use self::source::StructuredImageSourceAsset;
pub(crate) mod source;
/// Module type that analyzes images and offers some meta information like
/// width, height and blur placeholder as export from the module.
#[turbo_tasks::value]
pub struct StructuredImageModuleType {}
#[turbo_tasks::value_impl]
impl StructuredImageModuleTypeVc {
#[turbo_tasks::function]
pub fn new() -> Self {
StructuredImageModuleTypeVc::cell(StructuredImageModuleType {})
}
}
#[turbo_tasks::value_impl]
impl CustomModuleType for StructuredImageModuleType {
#[turbo_tasks::function]
async fn create_module(
&self,
source: AssetVc,
context: AssetContextVc,
_part: Option<ModulePartVc>,
) -> Result<AssetVc> {
let static_asset = StaticModuleAssetVc::new(source, context);
Ok(EcmascriptModuleAssetVc::new_with_inner_assets(
StructuredImageSourceAsset { image: source }.cell().into(),
context,
Value::new(EcmascriptModuleAssetType::Ecmascript),
EcmascriptInputTransformsVc::empty(),
Value::new(EcmascriptOptions {
..Default::default()
}),
context.compile_time_info(),
InnerAssetsVc::cell(indexmap!(
"IMAGE".to_string() => static_asset.into()
)),
)
.into())
}
}

View file

@ -0,0 +1,81 @@
use std::io::Write;
use anyhow::{bail, Result};
use serde::Serialize;
use turbo_binding::{
turbo::{
tasks::primitives::StringVc,
tasks_fs::{rope::RopeBuilder, FileContent},
},
turbopack::{
core::{
asset::{Asset, AssetContent, AssetContentVc, AssetVc},
ident::AssetIdentVc,
},
ecmascript::utils::StringifyJs,
image::process::{get_meta_data, BlurPlaceholderOptions, BlurPlaceholderOptionsVc},
},
};
fn modifier() -> StringVc {
StringVc::cell("structured image object".to_string())
}
#[turbo_tasks::function]
fn blur_options() -> BlurPlaceholderOptionsVc {
BlurPlaceholderOptions {
quality: 70,
size: 8,
}
.cell()
}
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ImageExport<'a> {
width: u32,
height: u32,
#[serde(rename = "blurDataURL")]
blur_data_url: Option<&'a str>,
blur_width: u32,
blur_height: u32,
}
/// An source asset that transforms an image into javascript code which exports
/// an object with meta information like width, height and a blur placeholder.
#[turbo_tasks::value(shared)]
pub struct StructuredImageSourceAsset {
pub image: AssetVc,
}
#[turbo_tasks::value_impl]
impl Asset for StructuredImageSourceAsset {
#[turbo_tasks::function]
fn ident(&self) -> AssetIdentVc {
self.image.ident().with_modifier(modifier())
}
#[turbo_tasks::function]
async fn content(&self) -> Result<AssetContentVc> {
let content = self.image.content().await?;
let AssetContent::File(content) = *content else {
bail!("Input source is not a file and can't be transformed into image information");
};
let mut result = RopeBuilder::from("");
let info = get_meta_data(self.image.ident(), content, Some(blur_options())).await?;
let info = ImageExport {
width: info.width,
height: info.height,
blur_width: info.blur_placeholder.as_ref().map_or(0, |p| p.width),
blur_height: info.blur_placeholder.as_ref().map_or(0, |p| p.height),
blur_data_url: info.blur_placeholder.as_ref().map(|p| p.data_url.as_str()),
};
writeln!(result, "import src from \"IMAGE\";",)?;
writeln!(
result,
"export default {{ src, ...{} }}",
StringifyJs(&info)
)?;
Ok(AssetContent::File(FileContent::Content(result.build().into()).cell()).cell())
}
}

View file

@ -9,6 +9,7 @@ mod babel;
mod embed_js;
pub mod env;
mod fallback;
mod image;
pub mod manifest;
mod next_build;
pub mod next_client;
@ -46,5 +47,6 @@ pub fn register() {
turbopack::dev_server::register();
turbopack::node::register();
turbopack::turbopack::register();
turbopack::image::register();
include!(concat!(env!("OUT_DIR"), "/register.rs"));
}

View file

@ -179,6 +179,8 @@ pub async fn get_client_module_options_context(
let module_options_context = ModuleOptionsContext {
custom_ecmascript_transforms: vec![EcmascriptInputTransform::ServerDirective(
// ServerDirective is not implemented yet and always reports an issue.
// We don't have to pass a valid transition name yet, but the API is prepared.
StringVc::cell("TODO".to_string()),
)],
preset_env_versions: Some(env),

View file

@ -6,7 +6,7 @@ use crate::{
next_client::context::ClientContextType,
next_config::NextConfigVc,
next_shared::transforms::{
get_next_dynamic_transform_rule, get_next_font_transform_rule,
get_next_dynamic_transform_rule, get_next_font_transform_rule, get_next_image_rule,
get_next_modularize_imports_rule, get_next_pages_transforms_rule,
},
};
@ -40,5 +40,7 @@ pub async fn get_next_client_transforms_rules(
rules.push(get_next_dynamic_transform_rule(true, false, false, pages_dir).await?);
rules.push(get_next_image_rule());
Ok(rules)
}

View file

@ -6,7 +6,7 @@ use crate::{
next_config::NextConfigVc,
next_server::context::ServerContextType,
next_shared::transforms::{
get_next_dynamic_transform_rule, get_next_font_transform_rule,
get_next_dynamic_transform_rule, get_next_font_transform_rule, get_next_image_rule,
get_next_modularize_imports_rule, get_next_pages_transforms_rule,
},
};
@ -41,5 +41,7 @@ pub async fn get_next_server_transforms_rules(
rules.push(get_next_dynamic_transform_rule(true, true, is_server_components, pages_dir).await?);
rules.push(get_next_image_rule());
Ok(rules)
}

View file

@ -22,11 +22,15 @@ use turbo_binding::{
CustomTransformVc, CustomTransformer, EcmascriptInputTransform,
EcmascriptInputTransformsVc, TransformContext,
},
turbopack::module_options::{ModuleRule, ModuleRuleCondition, ModuleRuleEffect},
turbopack::module_options::{
ModuleRule, ModuleRuleCondition, ModuleRuleEffect, ModuleType,
},
},
};
use turbo_tasks::trace::TraceRawVcs;
use crate::image::StructuredImageModuleTypeVc;
/// Returns a rule which applies the Next.js page export stripping transform.
pub async fn get_next_pages_transforms_rule(
pages_dir: FileSystemPathVc,
@ -80,6 +84,24 @@ impl CustomTransformer for NextJsStripPageExports {
}
}
/// Returns a rule which applies the Next.js dynamic transform.
pub fn get_next_image_rule() -> ModuleRule {
ModuleRule::new(
ModuleRuleCondition::any(vec![
ModuleRuleCondition::ResourcePathEndsWith(".jpg".to_string()),
ModuleRuleCondition::ResourcePathEndsWith(".jpeg".to_string()),
ModuleRuleCondition::ResourcePathEndsWith(".png".to_string()),
ModuleRuleCondition::ResourcePathEndsWith(".webp".to_string()),
ModuleRuleCondition::ResourcePathEndsWith(".avif".to_string()),
ModuleRuleCondition::ResourcePathEndsWith(".apng".to_string()),
ModuleRuleCondition::ResourcePathEndsWith(".gif".to_string()),
]),
vec![ModuleRuleEffect::ModuleType(ModuleType::Custom(
StructuredImageModuleTypeVc::new().into(),
))],
)
}
/// Returns a rule which applies the Next.js dynamic transform.
pub async fn get_next_dynamic_transform_rule(
is_development: bool,

View file

@ -1,5 +1,6 @@
import Image from 'next/image'
import { img } from '../components/img'
import broken from '../public/broken.jpeg'
import { useEffect } from 'react'
export default function Home() {
@ -13,26 +14,51 @@ export default function Home() {
id="imported"
alt="test imported image"
src={img}
width="100"
height="100"
placeholder="blur"
/>,
<Image
id="local"
alt="test src image"
src="/triangle-black.png"
width="100"
width="116"
height="100"
/>,
]
}
console.log(img)
function runTests() {
it('it should link to imported image', function () {
it('should return image size', function () {
expect(img).toHaveProperty('width', 116)
expect(img).toHaveProperty('height', 100)
})
it('should not return image size for broken images', function () {
expect(broken).toHaveProperty('width', 0)
expect(broken).toHaveProperty('height', 0)
})
it('should have blur placeholder', function () {
expect(img).toHaveProperty(
'blurDataURL',
expect.stringMatching(/^data:image\/png;base64/)
)
expect(img).toHaveProperty('blurWidth', 8)
expect(img).toHaveProperty('blurHeight', 7)
})
it('should not have blur placeholder for broken images', function () {
expect(broken).toHaveProperty('blurDataURL', null)
expect(broken).toHaveProperty('blurWidth', 0)
expect(broken).toHaveProperty('blurHeight', 0)
})
it('should link to imported image', function () {
const img = document.querySelector('#imported')
expect(img.src).toContain(encodeURIComponent('_next/static/assets'))
})
it('it should link to local src image', function () {
it('should link to local src image', function () {
const img = document.querySelector('#local')
expect(img.src).toContain('triangle-black')
})

View file

@ -0,0 +1,21 @@
PlainIssue {
severity: Error,
context: "[project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/image/basic/input/public/broken.jpeg",
category: "image",
title: "Processing image failed",
description: "unable to decode image data\n\nCaused by:\n- The image format could not be determined",
detail: "",
documentation_link: "",
source: None,
sub_issues: [],
processing_path: Some(
[
PlainIssueProcessingPathItem {
context: Some(
"[project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/image/basic/input/pages/index.js",
),
description: "Next.js pages directory",
},
],
),
}

View file

@ -0,0 +1,28 @@
PlainIssue {
severity: Error,
context: "[project]/packages/next-swc/crates/next-dev-tests/tests/integration/webpack/chunks/__skipped__/context-weak/input/index.js",
category: "parse",
title: "error TP1007 require.context(\".\", false, /.+/, \"weak\") is not statically analyze-able: require.context() only supports 1-3 arguments (mode is not supported)",
description: "",
detail: "",
documentation_link: "",
source: Some(
PlainIssueSource {
asset: PlainAsset {
ident: "[project]/packages/next-swc/crates/next-dev-tests/tests/integration/webpack/chunks/__skipped__/context-weak/input/index.js",
},
start: SourcePos {
line: 19,
column: 23,
},
end: SourcePos {
line: 19,
column: 23,
},
},
),
sub_issues: [],
processing_path: Some(
[],
),
}

View file

@ -0,0 +1,28 @@
PlainIssue {
severity: Error,
context: "[project]/packages/next-swc/crates/next-dev-tests/tests/integration/webpack/chunks/__skipped__/context-weak/input/index.js",
category: "parse",
title: "error TP1007 require.context(\".\", false, /two/, \"weak\") is not statically analyze-able: require.context() only supports 1-3 arguments (mode is not supported)",
description: "",
detail: "",
documentation_link: "",
source: Some(
PlainIssueSource {
asset: PlainAsset {
ident: "[project]/packages/next-swc/crates/next-dev-tests/tests/integration/webpack/chunks/__skipped__/context-weak/input/index.js",
},
start: SourcePos {
line: 1,
column: 23,
},
end: SourcePos {
line: 1,
column: 23,
},
},
),
sub_issues: [],
processing_path: Some(
[],
),
}

View file

@ -0,0 +1,28 @@
PlainIssue {
severity: Error,
context: "[project]/packages/next-swc/crates/next-dev-tests/tests/integration/webpack/chunks/__skipped__/context-weak/input/index.js",
category: "parse",
title: "error TP1007 require.context(\".\", true, /.+/, \"weak\") is not statically analyze-able: require.context() only supports 1-3 arguments (mode is not supported)",
description: "",
detail: "",
documentation_link: "",
source: Some(
PlainIssueSource {
asset: PlainAsset {
ident: "[project]/packages/next-swc/crates/next-dev-tests/tests/integration/webpack/chunks/__skipped__/context-weak/input/index.js",
},
start: SourcePos {
line: 25,
column: 23,
},
end: SourcePos {
line: 25,
column: 23,
},
},
),
sub_issues: [],
processing_path: Some(
[],
),
}

View file

@ -1008,8 +1008,8 @@ importers:
'@types/react': ^18.0.26
'@types/react-dom': ^18.0.9
'@vercel/ncc': ^0.36.0
'@vercel/turbopack-dev': https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230418.1
'@vercel/turbopack-node': https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230418.1
'@vercel/turbopack-dev': https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230419.4
'@vercel/turbopack-node': https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230419.4
anser: ^2.1.1
css.escape: ^1.5.1
find-up: ^6.3.0
@ -1021,8 +1021,8 @@ importers:
stacktrace-parser: ^0.1.10
strip-ansi: ^7.0.1
dependencies:
'@vercel/turbopack-dev': '@gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230418.1_react-refresh@0.12.0'
'@vercel/turbopack-node': '@gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230418.1'
'@vercel/turbopack-dev': '@gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230419.4_react-refresh@0.12.0'
'@vercel/turbopack-node': '@gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230419.4'
anser: 2.1.1
css.escape: 1.5.1
next: link:../../../../next
@ -6004,7 +6004,7 @@ packages:
dependencies:
'@mdx-js/mdx': 2.2.1
source-map: 0.7.3
webpack: 5.74.0
webpack: 5.74.0_@swc+core@1.3.51
transitivePeerDependencies:
- supports-color
@ -6674,7 +6674,6 @@ packages:
cpu: [arm64]
os: [darwin]
requiresBuild: true
dev: true
optional: true
/@swc/core-darwin-x64/1.3.51:
@ -6683,7 +6682,6 @@ packages:
cpu: [x64]
os: [darwin]
requiresBuild: true
dev: true
optional: true
/@swc/core-linux-arm-gnueabihf/1.3.51:
@ -6692,7 +6690,6 @@ packages:
cpu: [arm]
os: [linux]
requiresBuild: true
dev: true
optional: true
/@swc/core-linux-arm64-gnu/1.3.51:
@ -6701,7 +6698,6 @@ packages:
cpu: [arm64]
os: [linux]
requiresBuild: true
dev: true
optional: true
/@swc/core-linux-arm64-musl/1.3.51:
@ -6710,7 +6706,6 @@ packages:
cpu: [arm64]
os: [linux]
requiresBuild: true
dev: true
optional: true
/@swc/core-linux-x64-gnu/1.3.51:
@ -6719,7 +6714,6 @@ packages:
cpu: [x64]
os: [linux]
requiresBuild: true
dev: true
optional: true
/@swc/core-linux-x64-musl/1.3.51:
@ -6728,7 +6722,6 @@ packages:
cpu: [x64]
os: [linux]
requiresBuild: true
dev: true
optional: true
/@swc/core-win32-arm64-msvc/1.3.51:
@ -6737,7 +6730,6 @@ packages:
cpu: [arm64]
os: [win32]
requiresBuild: true
dev: true
optional: true
/@swc/core-win32-ia32-msvc/1.3.51:
@ -6746,7 +6738,6 @@ packages:
cpu: [ia32]
os: [win32]
requiresBuild: true
dev: true
optional: true
/@swc/core-win32-x64-msvc/1.3.51:
@ -6755,7 +6746,6 @@ packages:
cpu: [x64]
os: [win32]
requiresBuild: true
dev: true
optional: true
/@swc/core/1.3.51_@swc+helpers@0.5.0:
@ -6780,7 +6770,6 @@ packages:
'@swc/core-win32-arm64-msvc': 1.3.51
'@swc/core-win32-ia32-msvc': 1.3.51
'@swc/core-win32-x64-msvc': 1.3.51
dev: true
/@swc/helpers/0.4.14:
resolution: {integrity: sha512-4C7nX/dvpzB7za4Ql9K81xK3HPxCpHMgwTZVyf+9JQ6VUbn9jjZVN7/Nkdz/Ugzs2CSjqnL/UPXroiVBVHUWUw==}
@ -23778,7 +23767,6 @@ packages:
source-map: 0.6.1
terser: 5.14.1
webpack: 5.74.0_@swc+core@1.3.51
dev: true
/terser-webpack-plugin/5.2.4_webpack@5.74.0:
resolution: {integrity: sha512-E2CkNMN+1cho04YpdANyRrn8CyN4yMy+WdFKZIySFZrGXZxJwJP6PMNGGc/Mcr6qygQHUUqRxnAPmi0M9f00XA==}
@ -25184,7 +25172,6 @@ packages:
- '@swc/core'
- esbuild
- uglify-js
dev: true
/websocket-driver/0.7.3:
resolution: {integrity: sha512-bpxWlvbbB459Mlipc5GBzzZwhoZgGEZLuqPaR0INBGnPAY1vdBX6hPnoFXiw+3yWxDuHyQjO2oXTMyS8A5haFg==}
@ -25590,9 +25577,9 @@ packages:
/zwitch/2.0.4:
resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==}
'@gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230418.1_react-refresh@0.12.0':
resolution: {tarball: https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230418.1}
id: '@gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230418.1'
'@gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230419.4_react-refresh@0.12.0':
resolution: {tarball: https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230419.4}
id: '@gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230419.4'
name: '@vercel/turbopack-dev'
version: 0.0.0
dependencies:
@ -25602,8 +25589,8 @@ packages:
- webpack
dev: false
'@gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230418.1':
resolution: {tarball: https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230418.1}
'@gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230419.4':
resolution: {tarball: https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230419.4}
name: '@vercel/turbopack-node'
version: 0.0.0
dependencies: