Unverified Commit 98fd3456 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: query conditions in rules follow-ups (#88801)

Rebase of https://github.com/vercel/next.js/pull/87291
parent 9e933be7
......@@ -2106,6 +2106,13 @@ mod tests {
"browser",
{
"path": { "type": "glob", "value": "*.svg"},
"query": {
"type": "regex",
"value": {
"source": "@someQuery",
"flags": ""
}
},
"content": {
"source": "@someTag",
"flags": ""
......@@ -2140,7 +2147,10 @@ mod tests {
source: rcstr!("@someTag"),
flags: rcstr!(""),
}),
query: None,
query: Some(ConfigConditionQuery::Regex(RegexComponents {
source: rcstr!("@someQuery"),
flags: rcstr!(""),
})),
},
]
.into(),
......
......@@ -197,6 +197,9 @@ module.exports = {
{
any: [
{ path: '*.svg' },
// 'query' matches anywhere in the full query string,
// which can be empty, or start with `?`.
{ query: /[?&]svgr(?=&|$)/ },
// 'content' is always a RegExp, and can match
// anywhere in the file.
{ content: /\<svg\W/ },
......
import { NextResponse } from 'next/server'
import foo from '../../foo.js'
import bar from '../../bar.js'
// @ts-expect-error -- ignore
import bar from '../../bar.js?test=hi'
export async function GET(_req) {
return NextResponse.json(
......
......@@ -35,7 +35,10 @@ export default {
condition: {
any: [
{
all: ['development', { not: { not: { content: /export/ } } }],
all: [
'development',
{ not: { not: { query: /test=hi/, content: /export/ } } },
],
},
],
},
......@@ -49,7 +52,10 @@ export default {
// this should match on production
{
condition: {
all: [{ not: 'development' }, { content: /export/ }],
all: [
{ not: 'development' },
{ query: /test=hi/, content: /export/ },
],
},
loaders: [
{
......
......@@ -132,9 +132,6 @@ async fn rule_condition_from_webpack_condition(
}
None => {}
}
if let Some(content) = content {
rule_conditions.push(RuleCondition::ResourceContentEsRegex(content.await?));
}
match &query {
Some(ConditionQuery::Constant(value)) => {
rule_conditions.push(RuleCondition::ResourceQueryEquals(value.clone().into()));
......@@ -144,6 +141,10 @@ async fn rule_condition_from_webpack_condition(
}
None => {}
}
// Add the content condition last since matching requires a more expensive file read.
if let Some(content) = content {
rule_conditions.push(RuleCondition::ResourceContentEsRegex(content.await?));
}
RuleCondition::All(rule_conditions)
}
})
......
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