Skip to content

Commit 55a59e7

Browse files
authoredApr 9, 2020
fix(file-list): do not define fs.statAsync (#3467)
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
1 parent 007d093 commit 55a59e7

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed
 

‎lib/file-list.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { promisify } = require('util')
44
const mm = require('minimatch')
55
const Glob = require('glob').Glob
66
const fs = require('graceful-fs')
7-
fs.statAsync = promisify(fs.stat)
7+
const statAsync = promisify(fs.stat.bind(fs))
88
const pathLib = require('path')
99
const _ = require('lodash')
1010

@@ -189,7 +189,7 @@ class FileList {
189189
const file = new File(path)
190190
this._getFilesByPattern(pattern.pattern).push(file)
191191

192-
const [stat] = await Promise.all([fs.statAsync(path), this._refreshing])
192+
const [stat] = await Promise.all([statAsync(path), this._refreshing])
193193
file.mtime = stat.mtime
194194
await this._preprocess(file)
195195

@@ -207,7 +207,7 @@ class FileList {
207207
return this.files
208208
}
209209

210-
const [stat] = await Promise.all([fs.statAsync(path), this._refreshing])
210+
const [stat] = await Promise.all([statAsync(path), this._refreshing])
211211
if (force || stat.mtime > file.mtime) {
212212
file.mtime = stat.mtime
213213
await this._preprocess(file)

‎test/unit/file-list.spec.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,10 @@ describe('FileList', () => {
442442
clock = sinon.useFakeTimers()
443443
// This hack is needed to ensure lodash is using the fake timers
444444
// from sinon
445+
446+
// fs.stat needs to be spied before file-list is required
447+
sinon.spy(mockFs, 'stat')
448+
445449
List = proxyquire('../../lib/file-list', {
446450
lodash: _.runInContext(),
447451
helper: helper,
@@ -455,6 +459,7 @@ describe('FileList', () => {
455459

456460
afterEach(() => {
457461
clock.restore()
462+
mockFs.stat.restore()
458463
})
459464

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

512517
return list.refresh().then(() => {
513518
preprocess.resetHistory()
514-
sinon.spy(mockFs, 'statAsync')
515519

516520
return Promise.all([
517521
list.addFile('/some/d.js'),
518522
list.addFile('/some/d.js')
519523
]).then(() => {
520524
expect(preprocess).to.have.been.calledOnce
521-
expect(mockFs.statAsync).to.have.been.calledOnce
525+
expect(mockFs.stat).to.have.been.calledOnce
522526
})
523527
})
524528
})

0 commit comments

Comments
 (0)
Please sign in to comment.