1
- import fs from 'fs'
2
- import fsp from 'fs/promises'
1
+ import fs from 'node:fs'
2
+ import fsp from 'node:fs/promises'
3
+ import os from 'node:os'
3
4
import Path from 'path'
4
5
import glob from 'it-glob'
5
6
import { InvalidParametersError } from '../errors.js'
6
7
import { toMtime } from './to-mtime.js'
7
8
import type { MtimeLike } from 'ipfs-unixfs'
8
9
import type { ImportCandidate } from 'ipfs-unixfs-importer'
10
+ import type { Options } from 'it-glob'
9
11
10
12
export interface GlobSourceOptions {
11
13
/**
@@ -58,15 +60,23 @@ export async function * globSource (cwd: string, pattern: string, options: GlobS
58
60
cwd = Path . resolve ( process . cwd ( ) , cwd )
59
61
}
60
62
61
- const globOptions = Object . assign ( { } , {
62
- nodir : false ,
63
- realpath : false ,
63
+ if ( os . platform ( ) === 'win32' ) {
64
+ cwd = toPosix ( cwd )
65
+ }
66
+
67
+ const globOptions : Options = {
68
+ onlyFiles : false ,
64
69
absolute : true ,
65
70
dot : Boolean ( options . hidden ) ,
66
- follow : options . followSymlinks != null ? options . followSymlinks : true
67
- } )
71
+ followSymbolicLinks : options . followSymlinks != null ? options . followSymlinks : true
72
+ }
68
73
69
74
for await ( const p of glob ( cwd , pattern , globOptions ) ) {
75
+ // Workaround for https://github.com/micromatch/micromatch/issues/251
76
+ if ( Path . basename ( p ) . startsWith ( '.' ) && options . hidden !== true ) {
77
+ continue
78
+ }
79
+
70
80
const stat = await fsp . stat ( p )
71
81
72
82
let mode = options . mode
@@ -82,7 +92,7 @@ export async function * globSource (cwd: string, pattern: string, options: GlobS
82
92
}
83
93
84
94
yield {
85
- path : toPosix ( p . replace ( cwd , '' ) ) ,
95
+ path : p . replace ( cwd , '' ) ,
86
96
content : stat . isFile ( ) ? fs . createReadStream ( p ) : undefined ,
87
97
mode,
88
98
mtime : toMtime ( mtime )
0 commit comments