fs: promisify exists correctly · nodejs/node@6e0eccd

@@ -28,7 +28,7 @@ const constants = process.binding('constants').fs;

2828

const { S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_IFSOCK } = constants;

2929

const util = require('util');

3030

const pathModule = require('path');

31-

const { isUint8Array } = process.binding('util');

31+

const { isUint8Array, createPromise, promiseResolve } = process.binding('util');

32323333

const binding = process.binding('fs');

3434

const fs = exports;

@@ -308,6 +308,15 @@ fs.exists = function(path, callback) {

308308

}

309309

};

310310311+

Object.defineProperty(fs.exists, internalUtil.promisify.custom, {

312+

value: (path) => {

313+

const promise = createPromise();

314+

fs.exists(path, (exists) => promiseResolve(promise, exists));

315+

return promise;

316+

}

317+

});

318+319+311320

fs.existsSync = function(path) {

312321

try {

313322

handleError((path = getPathFromURL(path)));