diff --git a/src/template.js b/src/template.js index 4586d6059..81da8c68c 100644 --- a/src/template.js +++ b/src/template.js @@ -2,10 +2,9 @@ import * as _ from './util/underscore.js' import path from 'path' import {anySeries} from './util/promise.js' import fs from 'fs' -import {promisify} from 'util' -const statFileAsync = promisify(fs.stat) -const readFileAsync = promisify(fs.readFile) +const statFileAsync = _.promisify(fs.stat) +const readFileAsync = _.promisify(fs.readFile) export async function resolve (filepath, root, options) { if (!path.extname(filepath)) { diff --git a/src/util/underscore.js b/src/util/underscore.js index e6b1fe8b5..c70429f74 100644 --- a/src/util/underscore.js +++ b/src/util/underscore.js @@ -9,6 +9,16 @@ export function isString (value) { return toStr.call(value) === '[object String]' } +export function promisify (fn) { + return function () { + return new Promise((resolve, reject) => { + fn(...arguments, (err, result) => { + err ? reject(err) : resolve(result) + }) + }) + } +} + export function stringify (value) { if (isNil(value)) { return String(value)