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
e3980f0c
Commit
e3980f0c
authored
Oct 16, 2025
by
Niklas Mischkulnig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP debugging
parent
8e3102cf
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
28 deletions
+47
-28
alias_map.rs
turbopack/crates/turbopack-core/src/resolve/alias_map.rs
+28
-5
pattern.rs
turbopack/crates/turbopack-core/src/resolve/pattern.rs
+18
-22
typescript.rs
turbopack/crates/turbopack-resolve/src/typescript.rs
+1
-1
No files found.
turbopack/crates/turbopack-core/src/resolve/alias_map.rs
View file @
e3980f0c
...
@@ -562,6 +562,12 @@ where
...
@@ -562,6 +562,12 @@ where
}
}
}
}
AliasKey
::
Wildcard
{
suffix
}
=>
{
AliasKey
::
Wildcard
{
suffix
}
=>
{
println!
(
"AliasKey::Wildcard {} {}*{}"
,
self
.request
.describe_as_string
(),
prefix
,
suffix
);
// This is quite messy as we'd have to match against the FS to do this
// This is quite messy as we'd have to match against the FS to do this
// properly. For now, try to support as many cases as possible (and as are
// properly. For now, try to support as many cases as possible (and as are
// actually used).
// actually used).
...
@@ -570,6 +576,7 @@ where
...
@@ -570,6 +576,7 @@ where
// The request is a constant string, so the PatriciaMap lookup already
// The request is a constant string, so the PatriciaMap lookup already
// ensured that the prefix is matching the request.
// ensured that the prefix is matching the request.
let
remaining
=
&
request
[
prefix
.len
()
..
];
let
remaining
=
&
request
[
prefix
.len
()
..
];
println!
(
"1"
);
remaining
.ends_with
(
&**
suffix
)
remaining
.ends_with
(
&**
suffix
)
}
else
if
let
Pattern
::
Concatenation
(
req
)
=
self
.request
}
else
if
let
Pattern
::
Concatenation
(
req
)
=
self
.request
&&
let
[
&&
let
[
...
@@ -582,6 +589,7 @@ where
...
@@ -582,6 +589,7 @@ where
// The request might be more specific than the mapping, e.g. for
// The request might be more specific than the mapping, e.g. for
// `require('@/foo/' + dyn)` into a `@/*` mapping
// `require('@/foo/' + dyn)` into a `@/*` mapping
println!
(
"2"
);
req_prefix
.starts_with
(
&**
prefix
)
req_prefix
.starts_with
(
&**
prefix
)
}
else
if
let
Pattern
::
Concatenation
(
req
)
=
self
.request
}
else
if
let
Pattern
::
Concatenation
(
req
)
=
self
.request
&&
let
[
&&
let
[
...
@@ -590,12 +598,16 @@ where
...
@@ -590,12 +598,16 @@ where
Pattern
::
Constant
(
req_suffix
),
Pattern
::
Constant
(
req_suffix
),
]
=
req
.as_slice
()
]
=
req
.as_slice
()
{
{
println!
(
"3"
);
req_prefix
.starts_with
(
&**
prefix
)
&&
req_suffix
.ends_with
(
&**
suffix
)
req_prefix
.starts_with
(
&**
prefix
)
&&
req_suffix
.ends_with
(
&**
suffix
)
}
else
if
!
self
.request
.could_match
(
prefix
)
{
}
else
if
!
self
.request
.could_match
(
prefix
)
{
// There's no way it could match if the prefix can't match.
// If the whole of the prefix doesn't match, then it can't possibly
// match.
println!
(
"4"
);
false
false
}
else
if
suffix
.is_empty
()
{
}
else
if
suffix
.is_empty
()
{
// Prefix matches the request, and suffix is empty.
// Prefix could match the request, and suffix is empty.
println!
(
"5"
);
true
true
}
else
{
}
else
{
// It may or may not match, throw an error.
// It may or may not match, throw an error.
...
@@ -607,13 +619,24 @@ where
...
@@ -607,13 +619,24 @@ where
suffix
,
suffix
,
)));
)));
};
};
println!
(
"AliasKey::Wildcard {} {}*{}, {}"
,
self
.request
.describe_as_string
(),
prefix
,
suffix
,
is_match
);
if
is_match
{
if
is_match
{
let
mut
remaining
=
self
.request
.clone
();
let
mut
remaining
=
self
.request
.clone
();
if
let
Err
(
e
)
=
remaining
.strip_prefix_len
(
prefix
.len
())
{
if
let
Err
(
e
)
=
remaining
.strip_constant_prefix_len
(
prefix
.len
())
{
return
Some
(
Err
(
e
.context
(
self
.request
.describe_as_string
())));
return
Some
(
Err
(
e
.context
(
format!
(
"{}.strip_constant_prefix_len({:?}.len())"
,
self
.request
.describe_as_string
(),
prefix
))));
}
}
remaining
.strip_suffix_len
(
suffix
.len
());
remaining
.strip_
constant_
suffix_len
(
suffix
.len
());
let
output
=
template
.replace
(
&
remaining
);
let
output
=
template
.replace
(
&
remaining
);
return
Some
(
Ok
(
AliasMatch
{
return
Some
(
Ok
(
AliasMatch
{
...
...
turbopack/crates/turbopack-core/src/resolve/pattern.rs
View file @
e3980f0c
...
@@ -227,18 +227,18 @@ impl Pattern {
...
@@ -227,18 +227,18 @@ impl Pattern {
longest_common_suffix
(
&
strings
)
longest_common_suffix
(
&
strings
)
}
}
pub
fn
strip_prefix
(
&
self
,
prefix
:
&
str
)
->
Result
<
Option
<
Self
>>
{
pub
fn
strip_
constant_
prefix
(
&
self
,
prefix
:
&
str
)
->
Result
<
Option
<
Self
>>
{
if
self
.must_match
(
prefix
)
{
if
self
.must_match
(
prefix
)
{
let
mut
pat
=
self
.clone
();
let
mut
pat
=
self
.clone
();
pat
.strip_prefix_len
(
prefix
.len
())
?
;
pat
.strip_
constant_
prefix_len
(
prefix
.len
())
?
;
Ok
(
Some
(
pat
))
Ok
(
Some
(
pat
))
}
else
{
}
else
{
Ok
(
None
)
Ok
(
None
)
}
}
}
}
pub
fn
strip_prefix_len
(
&
mut
self
,
len
:
usize
)
->
Result
<
()
>
{
pub
fn
strip_
constant_
prefix_len
(
&
mut
self
,
len
:
usize
)
->
Result
<
()
>
{
fn
strip_
prefix_
internal
(
pattern
:
&
mut
Pattern
,
chars_to_strip
:
&
mut
usize
)
->
Result
<
()
>
{
fn
strip_internal
(
pattern
:
&
mut
Pattern
,
chars_to_strip
:
&
mut
usize
)
->
Result
<
()
>
{
match
pattern
{
match
pattern
{
Pattern
::
Constant
(
c
)
=>
{
Pattern
::
Constant
(
c
)
=>
{
let
c_len
=
c
.len
();
let
c_len
=
c
.len
();
...
@@ -252,15 +252,15 @@ impl Pattern {
...
@@ -252,15 +252,15 @@ impl Pattern {
Pattern
::
Concatenation
(
list
)
=>
{
Pattern
::
Concatenation
(
list
)
=>
{
for
c
in
list
{
for
c
in
list
{
if
*
chars_to_strip
>
0
{
if
*
chars_to_strip
>
0
{
strip_
prefix_
internal
(
c
,
chars_to_strip
)
?
;
strip_internal
(
c
,
chars_to_strip
)
?
;
}
}
}
}
}
}
Pattern
::
Alternatives
(
_
)
=>
{
Pattern
::
Alternatives
(
_
)
=>
{
bail!
(
"strip_
prefix
pattern must be normalized"
);
bail!
(
"strip_
constant_prefix_len
pattern must be normalized"
);
}
}
Pattern
::
Dynamic
|
Pattern
::
DynamicNoSlash
=>
{
Pattern
::
Dynamic
|
Pattern
::
DynamicNoSlash
=>
{
bail!
(
"strip_
prefix
prefix is too long"
);
bail!
(
"strip_
constant_prefix_len
prefix is too long"
);
}
}
}
}
Ok
(())
Ok
(())
...
@@ -269,21 +269,17 @@ impl Pattern {
...
@@ -269,21 +269,17 @@ impl Pattern {
match
&
mut
*
self
{
match
&
mut
*
self
{
c
@
Pattern
::
Constant
(
_
)
|
c
@
Pattern
::
Concatenation
(
_
)
=>
{
c
@
Pattern
::
Constant
(
_
)
|
c
@
Pattern
::
Concatenation
(
_
)
=>
{
let
mut
len_local
=
len
;
let
mut
len_local
=
len
;
strip_
prefix_
internal
(
c
,
&
mut
len_local
)
?
;
strip_internal
(
c
,
&
mut
len_local
)
?
;
}
}
Pattern
::
Alternatives
(
list
)
=>
{
Pattern
::
Alternatives
(
list
)
=>
{
for
c
in
list
{
for
c
in
list
{
let
mut
len_local
=
len
;
let
mut
len_local
=
len
;
strip_
prefix_
internal
(
c
,
&
mut
len_local
)
?
;
strip_internal
(
c
,
&
mut
len_local
)
?
;
}
}
}
}
Pattern
::
Dynamic
|
Pattern
::
DynamicNoSlash
=>
{
Pattern
::
Dynamic
|
Pattern
::
DynamicNoSlash
=>
{
if
len
>
0
{
if
len
>
0
{
bail!
(
bail!
(
"strip_constant_prefix_len prefix is too long"
,);
"strip_prefix prefix ({}) is too long: {}"
,
len
,
self
.describe_as_string
()
);
}
}
}
}
};
};
...
@@ -293,8 +289,8 @@ impl Pattern {
...
@@ -293,8 +289,8 @@ impl Pattern {
Ok
(())
Ok
(())
}
}
pub
fn
strip_suffix_len
(
&
mut
self
,
len
:
usize
)
{
pub
fn
strip_
constant_
suffix_len
(
&
mut
self
,
len
:
usize
)
{
fn
strip_
suffix_
internal
(
pattern
:
&
mut
Pattern
,
chars_to_strip
:
&
mut
usize
)
{
fn
strip_internal
(
pattern
:
&
mut
Pattern
,
chars_to_strip
:
&
mut
usize
)
{
match
pattern
{
match
pattern
{
Pattern
::
Constant
(
c
)
=>
{
Pattern
::
Constant
(
c
)
=>
{
let
c_len
=
c
.len
();
let
c_len
=
c
.len
();
...
@@ -308,7 +304,7 @@ impl Pattern {
...
@@ -308,7 +304,7 @@ impl Pattern {
Pattern
::
Concatenation
(
list
)
=>
{
Pattern
::
Concatenation
(
list
)
=>
{
for
c
in
list
.iter_mut
()
.rev
()
{
for
c
in
list
.iter_mut
()
.rev
()
{
if
*
chars_to_strip
>
0
{
if
*
chars_to_strip
>
0
{
strip_
suffix_
internal
(
c
,
chars_to_strip
);
strip_internal
(
c
,
chars_to_strip
);
}
}
}
}
}
}
...
@@ -324,12 +320,12 @@ impl Pattern {
...
@@ -324,12 +320,12 @@ impl Pattern {
match
&
mut
*
self
{
match
&
mut
*
self
{
c
@
Pattern
::
Constant
(
_
)
|
c
@
Pattern
::
Concatenation
(
_
)
=>
{
c
@
Pattern
::
Constant
(
_
)
|
c
@
Pattern
::
Concatenation
(
_
)
=>
{
let
mut
len_local
=
len
;
let
mut
len_local
=
len
;
strip_
suffix_
internal
(
c
,
&
mut
len_local
);
strip_internal
(
c
,
&
mut
len_local
);
}
}
Pattern
::
Alternatives
(
list
)
=>
{
Pattern
::
Alternatives
(
list
)
=>
{
for
c
in
list
{
for
c
in
list
{
let
mut
len_local
=
len
;
let
mut
len_local
=
len
;
strip_
suffix_
internal
(
c
,
&
mut
len_local
);
strip_internal
(
c
,
&
mut
len_local
);
}
}
}
}
Pattern
::
Dynamic
|
Pattern
::
DynamicNoSlash
=>
{
Pattern
::
Dynamic
|
Pattern
::
DynamicNoSlash
=>
{
...
@@ -2169,9 +2165,9 @@ mod tests {
...
@@ -2169,9 +2165,9 @@ mod tests {
}
}
#[test]
#[test]
fn
strip_prefix
()
{
fn
strip_
constant_
prefix
()
{
fn
strip
(
mut
pat
:
Pattern
,
n
:
usize
)
->
Pattern
{
fn
strip
(
mut
pat
:
Pattern
,
n
:
usize
)
->
Pattern
{
pat
.strip_prefix_len
(
n
)
.unwrap
();
pat
.strip_
constant_
prefix_len
(
n
)
.unwrap
();
pat
pat
}
}
...
@@ -2212,7 +2208,7 @@ mod tests {
...
@@ -2212,7 +2208,7 @@ mod tests {
#[test]
#[test]
fn
strip_suffix
()
{
fn
strip_suffix
()
{
fn
strip
(
mut
pat
:
Pattern
,
n
:
usize
)
->
Pattern
{
fn
strip
(
mut
pat
:
Pattern
,
n
:
usize
)
->
Pattern
{
pat
.strip_suffix_len
(
n
);
pat
.strip_
constant_
suffix_len
(
n
);
pat
pat
}
}
...
...
turbopack/crates/turbopack-resolve/src/typescript.rs
View file @
e3980f0c
...
@@ -426,7 +426,7 @@ pub async fn type_resolve(
...
@@ -426,7 +426,7 @@ pub async fn type_resolve(
fragment
:
_
,
fragment
:
_
,
}
=
&*
request
.await
?
}
=
&*
request
.await
?
{
{
let
mut
m
=
if
let
Some
(
mut
stripped
)
=
m
.strip_prefix
(
"@"
)
?
{
let
mut
m
=
if
let
Some
(
mut
stripped
)
=
m
.strip_
constant_
prefix
(
"@"
)
?
{
stripped
.replace_constants
(
&
|
c
|
Some
(
Pattern
::
Constant
(
c
.replace
(
"/"
,
"__"
)
.into
())));
stripped
.replace_constants
(
&
|
c
|
Some
(
Pattern
::
Constant
(
c
.replace
(
"/"
,
"__"
)
.into
())));
stripped
stripped
}
else
{
}
else
{
...
...
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