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