From 947dc8eeed8dfb13488f8b9798f3d9e0d07c27f0 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 11 Feb 2021 16:32:29 -0500 Subject: [PATCH] Minify: Asyncify `getFile()` --- src/node/utils/Minify.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/node/utils/Minify.js b/src/node/utils/Minify.js index 7e9537f12..53357aa28 100644 --- a/src/node/utils/Minify.js +++ b/src/node/utils/Minify.js @@ -305,7 +305,7 @@ const requireLastModified = () => _requireLastModified.toUTCString(); const requireDefinition = () => `var require = ${RequireKernel.kernelSource};\n`; const getFileCompressed = (filename, contentType, callback) => { - getFile(filename, (error, content) => { + util.callbackify(getFile)(filename, (error, content) => { if (error || !content || !settings.minify) { callback(error, content); } else if (contentType === 'application/javascript') { @@ -346,14 +346,10 @@ const getFileCompressed = (filename, contentType, callback) => { }); }; -const getFile = (filename, callback) => { - if (filename === 'js/ace.js') { - util.callbackify(getAceFile)(callback); - } else if (filename === 'js/require-kernel.js') { - callback(undefined, requireDefinition()); - } else { - fs.readFile(ROOT_DIR + filename, callback); - } +const getFile = async (filename) => { + if (filename === 'js/ace.js') return await getAceFile(); + if (filename === 'js/require-kernel.js') return requireDefinition(); + return await util.promisify(fs.readFile)(ROOT_DIR + filename); }; exports.minify = minify;