1
1
import { minimatch } from 'minimatch' ;
2
2
import { lstatSync , readdirSync } from 'node:fs' ;
3
- import { join } from 'node:path' ;
3
+ import { basename , join } from 'node:path' ;
4
+ import { IGNORE_OS_FILES } from '../constants/constants' ;
4
5
import type { SatelliteConfig } from '../types/satellite.config' ;
5
6
6
7
export const listSourceFiles = ( {
@@ -9,13 +10,24 @@ export const listSourceFiles = ({
9
10
} : { sourceAbsolutePath : string } & Required < Pick < SatelliteConfig , 'ignore' > > ) : string [ ] => {
10
11
const sourceFiles = files ( sourceAbsolutePath ) ;
11
12
12
- const filteredEmptyFiles = sourceFiles . filter ( ( file ) => lstatSync ( file ) . size > 0 ) ;
13
+ return sourceFiles . filter ( ( file ) => filterFile ( { file, ignore} ) ) ;
14
+ } ;
15
+
16
+ const filterFile = ( {
17
+ file,
18
+ ignore
19
+ } : { file : string } & Required < Pick < SatelliteConfig , 'ignore' > > ) : boolean => {
20
+ // File must not be empty >= 0kb
21
+ if ( lstatSync ( file ) . size <= 0 ) {
22
+ return false ;
23
+ }
13
24
14
- const filteredSourceFiles = filteredEmptyFiles . filter (
15
- ( file ) => ignore . find ( ( pattern ) => minimatch ( file , pattern ) ) === undefined
16
- ) ;
25
+ // Ignore .DS_Store on Mac or Thumbs.db on Windows
26
+ if ( IGNORE_OS_FILES . includes ( basename ( file ) . toLowerCase ( ) ) ) {
27
+ return false ;
28
+ }
17
29
18
- return filteredSourceFiles ;
30
+ return ignore . find ( ( pattern ) => minimatch ( file , pattern ) ) === undefined ;
19
31
} ;
20
32
21
33
const files = ( source : string ) : string [ ] =>
0 commit comments