Skip to content

Commit

Permalink
fix: fix unixfs import (#222)
Browse files Browse the repository at this point in the history
Update import for `MtimeLike` type otherwise incorrect paths are generated during compilation.
  • Loading branch information
achingbrain authored Nov 18, 2022
1 parent b0c7d35 commit 1dc939f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/files/glob-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,19 @@ const glob = require('it-glob')
const Path = require('path')
const errCode = require('err-code')

/**
* @typedef {import('ipfs-unixfs').MtimeLike} MtimeLike
* @typedef {import('../types').GlobSourceOptions} GlobSourceOptions
* @typedef {import('../types').GlobSourceResult} GlobSourceResult
*/

/**
* Create an async iterator that yields paths that match requested glob pattern
*
* @param {string} cwd - The directory to start matching the pattern in
* @param {string} pattern - Glob pattern to match
* @param {Object} [options] - Optional options
* @param {boolean} [options.hidden] - Include .dot files in matched paths
* @param {boolean} [options.followSymlinks] - follow symlinks
* @param {boolean} [options.preserveMode] - preserve mode
* @param {boolean} [options.preserveMtime] - preserve mtime
* @param {number} [options.mode] - mode to use - if preserveMode is true this will be ignored
* @param {import('ipfs-unixfs').MtimeLike} [options.mtime] - mtime to use - if preserveMtime is true this will be ignored
* @returns {AsyncGenerator<{
* path: string;
* content: AsyncIterable<Buffer> | undefined;
* mode: number | undefined;
* mtime: import("ipfs-unixfs/types/src/types").MtimeLike | undefined;
* }, void, unknown>} File objects that match glob
* @param {GlobSourceOptions} [options] - Optional options
* @returns {AsyncGenerator<GlobSourceResult, void, unknown>} File objects that match glob
*/
module.exports = async function * globSource (cwd, pattern, options) {
options = options || {}
Expand Down
40 changes: 40 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Readable as NodeReadableStream } from 'stream'
import type { MtimeLike } from 'ipfs-unixfs'

interface ProgressStatus {
total: number
Expand Down Expand Up @@ -64,3 +65,42 @@ export interface ExtendedResponse extends Response {

ndjson: () => AsyncGenerator<any, void, undefined>
}

export interface GlobSourceOptions {
/**
* Include .dot files in matched paths
*/
hidden?: boolean

/**
* follow symlinks
*/
followSymlinks?: boolean

/**
* Preserve mode
*/
preserveMode?: boolean

/**
* Preserve mtime
*/
preserveMtime?: boolean

/**
* mode to use - if preserveMode is true this will be ignored
*/
mode?: number

/**
* mtime to use - if preserveMtime is true this will be ignored
*/
mtime?: MtimeLike
}

export interface GlobSourceResult {
path: string
content: AsyncIterable<Uint8Array> | undefined
mode: number | undefined
mtime: MtimeLike | undefined
}

0 comments on commit 1dc939f

Please sign in to comment.