Unverified Commit bd802d13 authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

[turbopack] Handle relative paths before matching in node file traces (#82539)

# Fix glob handling for NFT JSON asset includes and excludes

The current webpack version uses the  https://www.npmjs.com/package/glob package to match and notably only handles `../` when it appears in a prefix position ([ref](https://www.npmjs.com/package/glob#:~:text=..%20path%20portions%20are%20not%20handled%20unless%20they%20appear%20at%20the%20start%20of%20the%20pattern)), so we do the exact same thing here.

This allows our read_glob traversal to only consider traversing 'down' from the root since we can preprocess the patterns to not include `../` or `./`

Part-Of PACK-5219
parent 5bbd5ddf
This diff is collapsed.
......@@ -21,10 +21,10 @@ module.exports = {
},
outputFileTracingIncludes: {
'/index': ['include-me/**/*'],
'/route1': ['include-me/**/*'],
'/route1': ['./include-me/**/*'],
},
outputFileTracingExcludes: {
'/index': ['public/exclude-me/**/*'],
'/route1': ['public/exclude-me/**/*'],
'/route1': ['./public/exclude-me/**/*'],
},
}
......@@ -35,16 +35,12 @@ describe('build trace with extra entries', () => {
join(appDir, '.next/server/app/route1/route.js.nft.json')
)
expect(
appDirRoute1Trace.files.some(
(file) => file === '../../../../include-me/hello.txt'
)
).toBe(true)
expect(
appDirRoute1Trace.files.some(
(file) => file === '../../../../include-me/second.txt'
)
).toBe(true)
expect(appDirRoute1Trace.files).toContain(
'../../../../include-me/hello.txt'
)
expect(appDirRoute1Trace.files).toContain(
'../../../../include-me/second.txt'
)
expect(
appDirRoute1Trace.files.some((file) => file.includes('exclude-me'))
).toBe(false)
......@@ -89,16 +85,8 @@ describe('build trace with extra entries', () => {
expect(
indexTrace.files.some((file) => file.includes('some-cms/index.js'))
).toBe(true)
expect(
indexTrace.files.some(
(file) => file === '../../../include-me/hello.txt'
)
).toBe(true)
expect(
indexTrace.files.some(
(file) => file === '../../../include-me/second.txt'
)
).toBe(true)
expect(indexTrace.files).toContain('../../../include-me/hello.txt')
expect(indexTrace.files).toContain('../../../include-me/second.txt')
expect(
indexTrace.files.some((file) => file.includes('exclude-me'))
).toBe(false)
......
use std::fmt::Display;
use anyhow::Result;
use regex::bytes::{Regex, RegexBuilder};
use serde::{Deserialize, Serialize};
......@@ -35,6 +37,12 @@ impl PartialEq for Glob {
}
impl Eq for Glob {}
impl Display for Glob {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Glob({})", self.glob)
}
}
#[derive(Serialize, Deserialize)]
#[serde(transparent)]
#[repr(transparent)]
......
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