Skip to content

Commit 36081e0

Browse files
authored
deps: update it-glob (#520)
Updates it-glob to use fast-glob for a speedup vs minimatch.
1 parent 6a62d1c commit 36081e0

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

packages/unixfs/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
"ipfs-unixfs-exporter": "^13.5.0",
171171
"ipfs-unixfs-importer": "^15.2.4",
172172
"it-all": "^3.0.4",
173-
"it-glob": "^2.0.6",
173+
"it-glob": "^3.0.0",
174174
"it-last": "^3.0.4",
175175
"it-pipe": "^3.0.1",
176176
"merge-options": "^3.0.4",
@@ -190,7 +190,7 @@
190190
"wherearewe": "^2.0.1"
191191
},
192192
"browser": {
193-
"./dist/src/utils/glob-source.js": false,
193+
"./dist/src/utils/glob-source.js": "./dist/src/utils/glob-source.browser.js",
194194
"fs": false,
195195
"path": false,
196196
"url": false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// eslint-disable-next-line require-yield
2+
export async function * globSource (): AsyncGenerator<any> {
3+
throw new Error('Not supported in browsers')
4+
}

packages/unixfs/src/utils/glob-source.ts

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
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'
34
import Path from 'path'
45
import glob from 'it-glob'
56
import { InvalidParametersError } from '../errors.js'
67
import { toMtime } from './to-mtime.js'
78
import type { MtimeLike } from 'ipfs-unixfs'
89
import type { ImportCandidate } from 'ipfs-unixfs-importer'
10+
import type { Options } from 'it-glob'
911

1012
export interface GlobSourceOptions {
1113
/**
@@ -58,15 +60,23 @@ export async function * globSource (cwd: string, pattern: string, options: GlobS
5860
cwd = Path.resolve(process.cwd(), cwd)
5961
}
6062

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,
6469
absolute: true,
6570
dot: Boolean(options.hidden),
66-
follow: options.followSymlinks != null ? options.followSymlinks : true
67-
})
71+
followSymbolicLinks: options.followSymlinks != null ? options.followSymlinks : true
72+
}
6873

6974
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+
7080
const stat = await fsp.stat(p)
7181

7282
let mode = options.mode
@@ -82,7 +92,7 @@ export async function * globSource (cwd: string, pattern: string, options: GlobS
8292
}
8393

8494
yield {
85-
path: toPosix(p.replace(cwd, '')),
95+
path: p.replace(cwd, ''),
8696
content: stat.isFile() ? fs.createReadStream(p) : undefined,
8797
mode,
8898
mtime: toMtime(mtime)

0 commit comments

Comments
 (0)