File tree 5 files changed +27
-2
lines changed
packages/vite/src/node/plugins
5 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -861,7 +861,9 @@ async function compileCSS(
861
861
// https://github.com/postcss/postcss/blob/main/docs/guidelines/plugin.md#3-dependencies
862
862
const { dir, glob : globPattern = '**' } = message
863
863
const pattern =
864
- normalizePath ( path . resolve ( path . dirname ( id ) , dir ) ) + `/` + globPattern
864
+ glob . escapePath ( normalizePath ( path . resolve ( path . dirname ( id ) , dir ) ) ) +
865
+ `/` +
866
+ globPattern
865
867
const files = glob . sync ( pattern , {
866
868
ignore : [ '**/node_modules/**' ]
867
869
} )
Original file line number Diff line number Diff line change @@ -317,9 +317,11 @@ test('treeshaken async chunk', async () => {
317
317
test ( 'PostCSS dir-dependency' , async ( ) => {
318
318
const el1 = await page . $ ( '.dir-dep' )
319
319
const el2 = await page . $ ( '.dir-dep-2' )
320
+ const el3 = await page . $ ( '.dir-dep-3' )
320
321
321
322
expect ( await getColor ( el1 ) ) . toBe ( 'grey' )
322
323
expect ( await getColor ( el2 ) ) . toBe ( 'grey' )
324
+ expect ( await getColor ( el3 ) ) . toBe ( 'grey' )
323
325
324
326
if ( ! isBuild ) {
325
327
editFile ( 'glob-dep/foo.css' , ( code ) =>
@@ -334,6 +336,13 @@ test('PostCSS dir-dependency', async () => {
334
336
await untilUpdated ( ( ) => getColor ( el2 ) , 'red' )
335
337
expect ( await getColor ( el1 ) ) . toBe ( 'blue' )
336
338
339
+ editFile ( 'glob-dep/nested (dir)/baz.css' , ( code ) =>
340
+ code . replace ( 'color: grey' , 'color: green' )
341
+ )
342
+ await untilUpdated ( ( ) => getColor ( el3 ) , 'green' )
343
+ expect ( await getColor ( el1 ) ) . toBe ( 'blue' )
344
+ expect ( await getColor ( el2 ) ) . toBe ( 'red' )
345
+
337
346
// test add/remove
338
347
removeFile ( 'glob-dep/bar.css' )
339
348
await untilUpdated ( ( ) => getColor ( el2 ) , 'black' )
Original file line number Diff line number Diff line change
1
+ .dir-dep-3 {
2
+ color : grey;
3
+ }
Original file line number Diff line number Diff line change @@ -113,6 +113,9 @@ <h1>CSS</h1>
113
113
< p class ="dir-dep-2 ">
114
114
PostCSS dir-dependency (file 2): this should be grey too
115
115
</ p >
116
+ < p class ="dir-dep-3 ">
117
+ PostCSS dir-dependency (file 3): this should be grey too
118
+ </ p >
116
119
117
120
< p class ="url-separated ">
118
121
URL separation preservation: should have valid background-image
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ function testDirDep() {
16
16
AtRule ( atRule , { result, Comment } ) {
17
17
if ( atRule . name === 'test' ) {
18
18
const pattern = normalizePath (
19
- path . resolve ( path . dirname ( result . opts . from ) , './glob-dep/*.css' )
19
+ path . resolve ( path . dirname ( result . opts . from ) , './glob-dep/**/* .css' )
20
20
)
21
21
const files = glob . sync ( pattern )
22
22
const text = files . map ( ( f ) => fs . readFileSync ( f , 'utf-8' ) ) . join ( '\n' )
@@ -30,6 +30,14 @@ function testDirDep() {
30
30
glob : '*.css' ,
31
31
parent : result . opts . from
32
32
} )
33
+
34
+ result . messages . push ( {
35
+ type : 'dir-dependency' ,
36
+ plugin : 'dir-dep' ,
37
+ dir : './glob-dep/nested (dir)' , // includes special characters in glob
38
+ glob : '*.css' ,
39
+ parent : result . opts . from
40
+ } )
33
41
}
34
42
}
35
43
}
You can’t perform that action at this time.
0 commit comments