Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
a2b10ab0
Unverified
Commit
a2b10ab0
authored
Jan 28, 2026
by
Niklas Mischkulnig
Committed by
GitHub
Jan 28, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[backport] Turbopack: fix NFT tracing of sharp 0.34 (#82340) (#89151)
parent
662f6412
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
699 additions
and
32 deletions
+699
-32
lib.rs
turbopack/crates/turbopack-core/src/lib.rs
+1
-0
node_addon_module.rs
turbopack/crates/turbopack-core/src/node_addon_module.rs
+150
-0
lib.rs
turbopack/crates/turbopack/src/lib.rs
+4
-0
mod.rs
turbopack/crates/turbopack/src/module_options/mod.rs
+1
-1
module_rule.rs
turbopack/crates/turbopack/src/module_options/module_rule.rs
+1
-0
node-file-trace.rs
turbopack/crates/turbopack/tests/node-file-trace.rs
+12
-0
sharp030.js
...s/turbopack/tests/node-file-trace/integration/sharp030.js
+13
-0
sharp033.js
...s/turbopack/tests/node-file-trace/integration/sharp033.js
+13
-0
package.json
...opack/crates/turbopack/tests/node-file-trace/package.json
+3
-1
pnpm-lock.yaml
...ack/crates/turbopack/tests/node-file-trace/pnpm-lock.yaml
+501
-30
No files found.
turbopack/crates/turbopack-core/src/lib.rs
View file @
a2b10ab0
...
@@ -25,6 +25,7 @@ pub mod introspect;
...
@@ -25,6 +25,7 @@ pub mod introspect;
pub
mod
issue
;
pub
mod
issue
;
pub
mod
module
;
pub
mod
module
;
pub
mod
module_graph
;
pub
mod
module_graph
;
pub
mod
node_addon_module
;
pub
mod
output
;
pub
mod
output
;
pub
mod
package_json
;
pub
mod
package_json
;
pub
mod
proxied_asset
;
pub
mod
proxied_asset
;
...
...
turbopack/crates/turbopack-core/src/node_addon_module.rs
0 → 100644
View file @
a2b10ab0
use
std
::
sync
::
LazyLock
;
use
anyhow
::
Result
;
use
regex
::
Regex
;
use
turbo_rcstr
::
rcstr
;
use
turbo_tasks
::{
FxIndexSet
,
ResolvedVc
,
TryJoinIterExt
,
Vc
};
use
turbo_tasks_fs
::{
FileSystemEntryType
,
FileSystemPath
};
use
crate
::{
asset
::{
Asset
,
AssetContent
},
file_source
::
FileSource
,
ident
::
AssetIdent
,
module
::
Module
,
raw_module
::
RawModule
,
reference
::{
ModuleReferences
,
TracedModuleReference
},
resolve
::
pattern
::{
Pattern
,
PatternMatch
,
read_matches
},
source
::
Source
,
};
/// A module corresponding to `.node` files.
#[turbo_tasks
::
value]
pub
struct
NodeAddonModule
{
source
:
ResolvedVc
<
Box
<
dyn
Source
>>
,
}
#[turbo_tasks
::
value_impl]
impl
NodeAddonModule
{
#[turbo_tasks
::
function]
pub
fn
new
(
source
:
ResolvedVc
<
Box
<
dyn
Source
>>
)
->
Vc
<
NodeAddonModule
>
{
NodeAddonModule
{
source
}
.cell
()
}
}
#[turbo_tasks
::
value_impl]
impl
Module
for
NodeAddonModule
{
#[turbo_tasks
::
function]
fn
ident
(
&
self
)
->
Vc
<
AssetIdent
>
{
self
.source
.ident
()
.with_modifier
(
rcstr!
(
"node addon"
))
}
#[turbo_tasks
::
function]
async
fn
references
(
&
self
)
->
Result
<
Vc
<
ModuleReferences
>>
{
static
SHARP_BINARY_REGEX
:
LazyLock
<
Regex
>
=
LazyLock
::
new
(||
Regex
::
new
(
"/sharp-(
\\
w+-
\\
w+).node$"
)
.unwrap
());
let
module_path
=
self
.source
.ident
()
.path
()
.await
?
;
// For most .node binaries, we usually assume that they are standalone dynamic library
// binaries that get loaded by some `require` call. So the binary itself doesn't read any
// files by itself, but only when instructed to from the JS side.
//
// For sharp, that is not the case:
// 1. `node_modules/sharp/lib/sharp.js` does `require("@img/sharp-${arch}/sharp.node")`
// which ends up resolving to ...
// 2. @img/sharp-darwin-arm64/lib/sharp-darwin-arm64.node. That is however a dynamic library
// that uses the OS loader to load yet another binary (you can view these via `otool -L`
// on macOS or `ldd` on Linux):
// 3. @img/sharp-libvips-darwin-arm64/libvips.dylib
//
// We could either try to parse the binary and read these dependencies, or (as we do in the
// following) special case sharp and hardcode this dependency.
//
// The JS @vercel/nft implementation has a similar special case:
// https://github.com/vercel/nft/blob/7e915aa02073ec57dc0d6528c419a4baa0f03d40/src/utils/special-cases.ts#L151-L181
if
SHARP_BINARY_REGEX
.is_match
(
&
module_path
.path
)
{
// module_path might be something like
// node_modules/@img/sharp-darwin-arm64/lib/sharp-darwin-arm64.node
let
arch
=
SHARP_BINARY_REGEX
.captures
(
&
module_path
.path
)
.unwrap
()
.get
(
1
)
.unwrap
()
.as_str
();
let
package_name
=
format!
(
"@img/sharp-libvips-{arch}"
);
for
folder
in
[
// This is the list of rpaths (lookup paths) of the shared library, at least on
// macOS and Linux https://github.com/lovell/sharp/blob/c01e272db522a8b7d174bd3be7400a4a87f08702/src/binding.gyp#L158-L201
"../.."
,
"../../.."
,
"../../node_modules"
,
"../../../node_modules"
,
]
.iter
()
.filter_map
(|
p
|
module_path
.parent
()
.join
(
p
)
.ok
()
?
.join
(
&
package_name
)
.ok
())
{
if
matches!
(
&*
folder
.get_type
()
.await
?
,
FileSystemEntryType
::
Directory
|
FileSystemEntryType
::
Symlink
)
{
return
Ok
(
dir_references
(
folder
));
}
}
};
// Most addon modules don't have references to other modules.
Ok
(
ModuleReferences
::
empty
())
}
}
#[turbo_tasks
::
value_impl]
impl
Asset
for
NodeAddonModule
{
#[turbo_tasks
::
function]
fn
content
(
&
self
)
->
Vc
<
AssetContent
>
{
self
.source
.content
()
}
}
#[turbo_tasks
::
function]
async
fn
dir_references
(
package_dir
:
FileSystemPath
)
->
Result
<
Vc
<
ModuleReferences
>>
{
let
matches
=
read_matches
(
package_dir
.clone
(),
rcstr!
(
""
),
true
,
Pattern
::
new
(
Pattern
::
Dynamic
),
)
.await
?
;
let
mut
results
:
FxIndexSet
<
FileSystemPath
>
=
FxIndexSet
::
default
();
for
pat_match
in
matches
.into_iter
()
{
match
pat_match
{
PatternMatch
::
File
(
_
,
file
)
=>
{
let
realpath
=
file
.realpath_with_links
()
.await
?
;
results
.extend
(
realpath
.symlinks
.iter
()
.cloned
());
match
&
realpath
.path_or_error
{
Ok
(
path
)
=>
{
results
.insert
(
path
.clone
());
}
Err
(
e
)
=>
anyhow
::
bail!
(
e
.as_error_message
(
file
,
&
realpath
)),
}
}
PatternMatch
::
Directory
(
..
)
=>
{}
}
}
Ok
(
Vc
::
cell
(
results
.into_iter
()
.map
(
async
|
p
|
{
Ok
(
ResolvedVc
::
upcast
(
TracedModuleReference
::
new
(
Vc
::
upcast
(
RawModule
::
new
(
Vc
::
upcast
(
FileSource
::
new
(
p
),
))))
.to_resolved
()
.await
?
,
))
})
.try_join
()
.await
?
,
))
}
turbopack/crates/turbopack/src/lib.rs
View file @
a2b10ab0
...
@@ -36,6 +36,7 @@ use turbopack_core::{
...
@@ -36,6 +36,7 @@ use turbopack_core::{
ident
::
Layer
,
ident
::
Layer
,
issue
::{
IssueExt
,
IssueSource
,
StyledString
,
module
::
ModuleIssue
},
issue
::{
IssueExt
,
IssueSource
,
StyledString
,
module
::
ModuleIssue
},
module
::
Module
,
module
::
Module
,
node_addon_module
::
NodeAddonModule
,
output
::
OutputAsset
,
output
::
OutputAsset
,
raw_module
::
RawModule
,
raw_module
::
RawModule
,
reference_type
::{
reference_type
::{
...
@@ -233,6 +234,9 @@ async fn apply_module_type(
...
@@ -233,6 +234,9 @@ async fn apply_module_type(
}
}
ModuleType
::
Json
=>
ResolvedVc
::
upcast
(
JsonModuleAsset
::
new
(
*
source
)
.to_resolved
()
.await
?
),
ModuleType
::
Json
=>
ResolvedVc
::
upcast
(
JsonModuleAsset
::
new
(
*
source
)
.to_resolved
()
.await
?
),
ModuleType
::
Raw
=>
ResolvedVc
::
upcast
(
RawModule
::
new
(
*
source
)
.to_resolved
()
.await
?
),
ModuleType
::
Raw
=>
ResolvedVc
::
upcast
(
RawModule
::
new
(
*
source
)
.to_resolved
()
.await
?
),
ModuleType
::
NodeAddon
=>
{
ResolvedVc
::
upcast
(
NodeAddonModule
::
new
(
*
source
)
.to_resolved
()
.await
?
)
}
ModuleType
::
CssModule
=>
ResolvedVc
::
upcast
(
ModuleType
::
CssModule
=>
ResolvedVc
::
upcast
(
ModuleCssAsset
::
new
(
*
source
,
Vc
::
upcast
(
module_asset_context
))
ModuleCssAsset
::
new
(
*
source
,
Vc
::
upcast
(
module_asset_context
))
.to_resolved
()
.to_resolved
()
...
...
turbopack/crates/turbopack/src/module_options/mod.rs
View file @
a2b10ab0
...
@@ -411,7 +411,7 @@ impl ModuleOptions {
...
@@ -411,7 +411,7 @@ impl ModuleOptions {
RuleCondition
::
any
(
vec!
[
RuleCondition
::
ResourcePathEndsWith
(
RuleCondition
::
any
(
vec!
[
RuleCondition
::
ResourcePathEndsWith
(
".node"
.to_string
(),
".node"
.to_string
(),
)]),
)]),
vec!
[
ModuleRuleEffect
::
ModuleType
(
ModuleType
::
Raw
)],
vec!
[
ModuleRuleEffect
::
ModuleType
(
ModuleType
::
NodeAddon
)],
),
),
// WebAssembly
// WebAssembly
ModuleRule
::
new
(
ModuleRule
::
new
(
...
...
turbopack/crates/turbopack/src/module_options/module_rule.rs
View file @
a2b10ab0
...
@@ -119,6 +119,7 @@ pub enum ModuleType {
...
@@ -119,6 +119,7 @@ pub enum ModuleType {
},
},
Json
,
Json
,
Raw
,
Raw
,
NodeAddon
,
CssModule
,
CssModule
,
Css
{
Css
{
ty
:
CssModuleAssetType
,
ty
:
CssModuleAssetType
,
...
...
turbopack/crates/turbopack/tests/node-file-trace.rs
View file @
a2b10ab0
...
@@ -158,6 +158,18 @@ static ALLOC: turbo_tasks_malloc::TurboMalloc = turbo_tasks_malloc::TurboMalloc;
...
@@ -158,6 +158,18 @@ static ALLOC: turbo_tasks_malloc::TurboMalloc = turbo_tasks_malloc::TurboMalloc;
#[case
::
sentry(
"integration/sentry.js"
)]
#[case
::
sentry(
"integration/sentry.js"
)]
#[case
::
sequelize(
"integration/sequelize.js"
)]
#[case
::
sequelize(
"integration/sequelize.js"
)]
#[case
::
serialport(
"integration/serialport.js"
)]
#[case
::
serialport(
"integration/serialport.js"
)]
#[cfg_attr(
target_os
=
"windows"
,
should_panic(expected
=
"Something went wrong installing the
\
"
sharp
\
" module"
),
case
::
sharp030(
"integration/sharp030.js"
)
)]
#[cfg_attr(not(target_os
=
"windows"
),
case
::
sharp030(
"integration/sharp030.js"
))]
#[cfg_attr(
target_os
=
"windows"
,
should_panic(expected
=
"Something went wrong installing the
\
"
sharp
\
" module"
),
case
::
sharp033(
"integration/sharp033.js"
)
)]
#[cfg_attr(not(target_os
=
"windows"
),
case
::
sharp033(
"integration/sharp033.js"
))]
#[cfg_attr(
#[cfg_attr(
target_os
=
"windows"
,
target_os
=
"windows"
,
should_panic(expected
=
"Something went wrong installing the
\
"
sharp
\
" module"
),
should_panic(expected
=
"Something went wrong installing the
\
"
sharp
\
" module"
),
...
...
turbopack/crates/turbopack/tests/node-file-trace/integration/sharp030.js
0 → 100644
View file @
a2b10ab0
const
sharp
=
require
(
'sharp030'
)
const
path
=
require
(
'path'
)
const
roundedCorners
=
Buffer
.
from
(
'<svg><rect x="0" y="0" width="200" height="200" rx="50" ry="50"/></svg>'
)
sharp
(
roundedCorners
).
resize
(
200
,
200
).
png
().
toBuffer
()
sharp
(
path
.
resolve
(
__dirname
,
'fixtures/vercel.svg'
))
.
resize
({
width
:
100
,
height
:
100
})
.
jpeg
()
.
toBuffer
()
turbopack/crates/turbopack/tests/node-file-trace/integration/sharp033.js
0 → 100644
View file @
a2b10ab0
const
sharp
=
require
(
'sharp033'
)
const
path
=
require
(
'path'
)
const
roundedCorners
=
Buffer
.
from
(
'<svg><rect x="0" y="0" width="200" height="200" rx="50" ry="50"/></svg>'
)
sharp
(
roundedCorners
).
resize
(
200
,
200
).
png
().
toBuffer
()
sharp
(
path
.
resolve
(
__dirname
,
'fixtures/vercel.svg'
))
.
resize
({
width
:
100
,
height
:
100
})
.
jpeg
()
.
toBuffer
()
turbopack/crates/turbopack/tests/node-file-trace/package.json
View file @
a2b10ab0
...
@@ -101,7 +101,9 @@
...
@@ -101,7 +101,9 @@
"semver"
:
"^7.1.1"
,
"semver"
:
"^7.1.1"
,
"sequelize"
:
"^5.9.3"
,
"sequelize"
:
"^5.9.3"
,
"serialport"
:
"^13.0.0"
,
"serialport"
:
"^13.0.0"
,
"sharp"
:
"^0.30.0"
,
"sharp030"
:
"npm:sharp@^0.30.0"
,
"sharp033"
:
"npm:sharp@^0.33.0"
,
"sharp"
:
"^0.34.0"
,
"shiki"
:
"^0.14.5"
,
"shiki"
:
"^0.14.5"
,
"socket.io"
:
"^2.4.0"
,
"socket.io"
:
"^2.4.0"
,
"socket.io-client"
:
"^2.2.0"
,
"socket.io-client"
:
"^2.2.0"
,
...
...
turbopack/crates/turbopack/tests/node-file-trace/pnpm-lock.yaml
View file @
a2b10ab0
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment