This repository was archived by the owner on Oct 10, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +23
-44
lines changed Expand file tree Collapse file tree 2 files changed +23
-44
lines changed Original file line number Diff line number Diff line change 1
- const path = require ( 'path' )
1
+ const { basename , sep } = require ( 'path' )
2
2
3
3
const pWaitFor = require ( 'p-wait-for' )
4
4
5
5
// Default filter when scanning for files
6
6
const defaultFilter = ( filePath ) => {
7
- if ( filePath == null ) return false
8
- const filename = path . basename ( filePath )
9
- switch ( true ) {
10
- case filename === 'node_modules' :
11
- case filename . startsWith ( '.' ) && filename !== '.well-known' :
12
- case filename . match ( / ( \/ _ _ M A C O S X | \/ \. ) / ) :
13
- return false
14
- default :
15
- return true
7
+ if ( filePath == null ) {
8
+ return false
16
9
}
10
+
11
+ const filename = basename ( filePath )
12
+ return (
13
+ filename !== 'node_modules' &&
14
+ ! ( filename . startsWith ( '.' ) && filename !== '.well-known' ) &&
15
+ ! filename . includes ( '/__MACOSX' ) &&
16
+ ! filename . includes ( '/.' )
17
+ )
17
18
}
18
19
19
20
// normalize windows paths to unix paths
@@ -23,7 +24,7 @@ const normalizePath = (relname) => {
23
24
}
24
25
return (
25
26
relname
26
- . split ( path . sep )
27
+ . split ( sep )
27
28
// .map(segment => encodeURI(segment)) // TODO I'm fairly certain we shouldn't encodeURI here, thats only for the file upload step
28
29
. join ( '/' )
29
30
)
Original file line number Diff line number Diff line change @@ -16,38 +16,16 @@ test('normalizePath should throw the error if name is invalid', (t) => {
16
16
t . throws ( ( ) => normalizePath ( '#' ) )
17
17
} )
18
18
19
- test ( 'pass empty name to defaultFilter' , ( t ) => {
20
- const cases = [
21
- {
22
- input : null ,
23
- expect : false ,
24
- } ,
25
- {
26
- input : undefined ,
27
- expect : false ,
28
- } ,
29
- {
30
- input : 'foo/bar/baz.js' ,
31
- expect : true ,
32
- } ,
33
- {
34
- input : 'directory/node_modules' ,
35
- expect : false ,
36
- } ,
37
- {
38
- input : 'directory/.gitignore' ,
39
- expect : false ,
40
- } ,
41
- {
42
- input : 'directory/.well-known' ,
43
- expect : true ,
44
- } ,
45
- {
46
- input : '__MACOSX' ,
47
- expect : true ,
48
- } ,
49
- ]
50
- cases . forEach ( ( { input, expect } ) => {
51
- t . is ( defaultFilter ( input ) , expect )
19
+ const filteredFiles = [ 'foo/bar/baz.js' , 'directory/.well-known' , '__MACOSX' ]
20
+ filteredFiles . forEach ( ( filePath ) => {
21
+ test ( `filters ${ filePath } ` , ( t ) => {
22
+ t . true ( defaultFilter ( filePath ) )
23
+ } )
24
+ } )
25
+
26
+ const unfilteredFiles = [ null , undefined , 'directory/node_modules' , 'directory/.gitignore' ]
27
+ unfilteredFiles . forEach ( ( filePath ) => {
28
+ test ( `does not filter ${ filePath } ` , ( t ) => {
29
+ t . false ( defaultFilter ( filePath ) )
52
30
} )
53
31
} )
You can’t perform that action at this time.
0 commit comments