Skip to content

Commit

Permalink
fix(file-list): do not define fs.statAsync (#3467)
Browse files Browse the repository at this point in the history
Defining fs.statAsync affects other modules such as bluebird which
throws an error because of the 'Async'-suffix:

> Cannot promisify an API that has normal methods with 'Async'-suffix
> See http://goo.gl/MqrFmX

Fixes: #3466
  • Loading branch information
matz3 authored Apr 9, 2020
1 parent 007d093 commit 55a59e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/file-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { promisify } = require('util')
const mm = require('minimatch')
const Glob = require('glob').Glob
const fs = require('graceful-fs')
fs.statAsync = promisify(fs.stat)
const statAsync = promisify(fs.stat.bind(fs))
const pathLib = require('path')
const _ = require('lodash')

Expand Down Expand Up @@ -189,7 +189,7 @@ class FileList {
const file = new File(path)
this._getFilesByPattern(pattern.pattern).push(file)

const [stat] = await Promise.all([fs.statAsync(path), this._refreshing])
const [stat] = await Promise.all([statAsync(path), this._refreshing])
file.mtime = stat.mtime
await this._preprocess(file)

Expand All @@ -207,7 +207,7 @@ class FileList {
return this.files
}

const [stat] = await Promise.all([fs.statAsync(path), this._refreshing])
const [stat] = await Promise.all([statAsync(path), this._refreshing])
if (force || stat.mtime > file.mtime) {
file.mtime = stat.mtime
await this._preprocess(file)
Expand Down
8 changes: 6 additions & 2 deletions test/unit/file-list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,10 @@ describe('FileList', () => {
clock = sinon.useFakeTimers()
// This hack is needed to ensure lodash is using the fake timers
// from sinon

// fs.stat needs to be spied before file-list is required
sinon.spy(mockFs, 'stat')

List = proxyquire('../../lib/file-list', {
lodash: _.runInContext(),
helper: helper,
Expand All @@ -455,6 +459,7 @@ describe('FileList', () => {

afterEach(() => {
clock.restore()
mockFs.stat.restore()
})

it('does not add excluded files', () => {
Expand Down Expand Up @@ -511,14 +516,13 @@ describe('FileList', () => {

return list.refresh().then(() => {
preprocess.resetHistory()
sinon.spy(mockFs, 'statAsync')

return Promise.all([
list.addFile('/some/d.js'),
list.addFile('/some/d.js')
]).then(() => {
expect(preprocess).to.have.been.calledOnce
expect(mockFs.statAsync).to.have.been.calledOnce
expect(mockFs.stat).to.have.been.calledOnce
})
})
})
Expand Down

0 comments on commit 55a59e7

Please sign in to comment.