diff --git a/packages/unixfs/package.json b/packages/unixfs/package.json index 5423a4d24..e12de5ba9 100644 --- a/packages/unixfs/package.json +++ b/packages/unixfs/package.json @@ -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", @@ -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 diff --git a/packages/unixfs/src/utils/glob-source.browser.ts b/packages/unixfs/src/utils/glob-source.browser.ts new file mode 100644 index 000000000..43b84f7eb --- /dev/null +++ b/packages/unixfs/src/utils/glob-source.browser.ts @@ -0,0 +1,4 @@ +// eslint-disable-next-line require-yield +export async function * globSource (): AsyncGenerator { + throw new Error('Not supported in browsers') +} diff --git a/packages/unixfs/src/utils/glob-source.ts b/packages/unixfs/src/utils/glob-source.ts index bc0944782..cda76860d 100644 --- a/packages/unixfs/src/utils/glob-source.ts +++ b/packages/unixfs/src/utils/glob-source.ts @@ -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 { /** @@ -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 @@ -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)