Skip to content

Commit

Permalink
deps: update it-glob (#520)
Browse files Browse the repository at this point in the history
Updates it-glob to use fast-glob for a speedup vs minimatch.
  • Loading branch information
achingbrain authored Apr 26, 2024
1 parent 6a62d1c commit 36081e0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/unixfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
"ipfs-unixfs-exporter": "^13.5.0",
"ipfs-unixfs-importer": "^15.2.4",
"it-all": "^3.0.4",
"it-glob": "^2.0.6",
"it-glob": "^3.0.0",
"it-last": "^3.0.4",
"it-pipe": "^3.0.1",
"merge-options": "^3.0.4",
Expand All @@ -190,7 +190,7 @@
"wherearewe": "^2.0.1"
},
"browser": {
"./dist/src/utils/glob-source.js": false,
"./dist/src/utils/glob-source.js": "./dist/src/utils/glob-source.browser.js",
"fs": false,
"path": false,
"url": false
Expand Down
4 changes: 4 additions & 0 deletions packages/unixfs/src/utils/glob-source.browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line require-yield
export async function * globSource (): AsyncGenerator<any> {
throw new Error('Not supported in browsers')
}
26 changes: 18 additions & 8 deletions packages/unixfs/src/utils/glob-source.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import fs from 'fs'
import fsp from 'fs/promises'
import fs from 'node:fs'
import fsp from 'node:fs/promises'
import os from 'node:os'
import Path from 'path'
import glob from 'it-glob'
import { InvalidParametersError } from '../errors.js'
import { toMtime } from './to-mtime.js'
import type { MtimeLike } from 'ipfs-unixfs'
import type { ImportCandidate } from 'ipfs-unixfs-importer'
import type { Options } from 'it-glob'

export interface GlobSourceOptions {
/**
Expand Down Expand Up @@ -58,15 +60,23 @@ export async function * globSource (cwd: string, pattern: string, options: GlobS
cwd = Path.resolve(process.cwd(), cwd)
}

const globOptions = Object.assign({}, {
nodir: false,
realpath: false,
if (os.platform() === 'win32') {
cwd = toPosix(cwd)
}

const globOptions: Options = {
onlyFiles: false,
absolute: true,
dot: Boolean(options.hidden),
follow: options.followSymlinks != null ? options.followSymlinks : true
})
followSymbolicLinks: options.followSymlinks != null ? options.followSymlinks : true
}

for await (const p of glob(cwd, pattern, globOptions)) {
// Workaround for https://github.com/micromatch/micromatch/issues/251
if (Path.basename(p).startsWith('.') && options.hidden !== true) {
continue
}

const stat = await fsp.stat(p)

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

yield {
path: toPosix(p.replace(cwd, '')),
path: p.replace(cwd, ''),
content: stat.isFile() ? fs.createReadStream(p) : undefined,
mode,
mtime: toMtime(mtime)
Expand Down

0 comments on commit 36081e0

Please sign in to comment.