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 +24
-45
lines changed
Expand file tree Collapse file tree 2 files changed +24
-45
lines changed Original file line number Diff line number Diff line change 1- const path = require ( 'path' )
1+ const { basename , sep } = require ( 'path' )
22
33const pWaitFor = require ( 'p-wait-for' )
44
55// Default filter when scanning for files
6- const defaultFilter = ( filename ) => {
7- if ( filename == null ) return false
8- const n = path . basename ( filename )
9- switch ( true ) {
10- case n === 'node_modules' :
11- case n . startsWith ( '.' ) && n !== '.well-known' :
12- case n . match ( / ( \/ _ _ M A C O S X | \/ \. ) / ) :
13- return false
14- default :
15- return true
6+ const defaultFilter = ( filePath ) => {
7+ if ( filePath == null ) {
8+ return false
169 }
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+ )
1718}
1819
1920// normalize windows paths to unix paths
@@ -23,7 +24,7 @@ const normalizePath = (relname) => {
2324 }
2425 return (
2526 relname
26- . split ( path . sep )
27+ . split ( sep )
2728 // .map(segment => encodeURI(segment)) // TODO I'm fairly certain we shouldn't encodeURI here, thats only for the file upload step
2829 . join ( '/' )
2930 )
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) => {
1616 t . throws ( ( ) => normalizePath ( '#' ) )
1717} )
1818
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 ( ( c ) => {
51- t . is ( defaultFilter ( c . input ) , c . 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 ) )
5230 } )
5331} )
You can’t perform that action at this time.
0 commit comments