Skip to content

Commit

Permalink
fix: checking Promise object in filesystem #1782 (#1795)
Browse files Browse the repository at this point in the history
* fix: checking Promise object in filesystem #1782
  • Loading branch information
jcubic committed Jul 17, 2023
1 parent 1b7a893 commit 3a39a83
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/models/FileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import pify from 'pify'
import { compareStrings } from '../utils/compareStrings.js'
import { dirname } from '../utils/dirname.js'
import { rmRecursive } from '../utils/rmRecursive.js'
import { isPromiseLike } from '../utils/types.js'

function isPromiseFs(fs) {
const test = targetFs => {
Expand All @@ -14,7 +15,7 @@ function isPromiseFs(fs) {
return e
}
}
return test(fs).constructor.name === 'Promise'
return isPromiseLike(test(fs))
}

// List of commands all filesystems are expected to provide. `rm` is not
Expand Down
11 changes: 11 additions & 0 deletions src/utils/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function isPromiseLike(obj) {
return isObject(obj) && isFunction(obj.then) && isFunction(obj.catch)
}

export function isObject(obj) {
return obj && typeof obj === 'object'
}

export function isFunction(obj) {
return typeof obj === 'function'
}

0 comments on commit 3a39a83

Please sign in to comment.