Minify: Asyncify `getFile()`

pull/4765/head
Richard Hansen 2021-02-11 16:32:29 -05:00 committed by John McLear
parent 5d7c07e81c
commit 947dc8eeed
1 changed files with 5 additions and 9 deletions

View File

@ -305,7 +305,7 @@ const requireLastModified = () => _requireLastModified.toUTCString();
const requireDefinition = () => `var require = ${RequireKernel.kernelSource};\n`; const requireDefinition = () => `var require = ${RequireKernel.kernelSource};\n`;
const getFileCompressed = (filename, contentType, callback) => { const getFileCompressed = (filename, contentType, callback) => {
getFile(filename, (error, content) => { util.callbackify(getFile)(filename, (error, content) => {
if (error || !content || !settings.minify) { if (error || !content || !settings.minify) {
callback(error, content); callback(error, content);
} else if (contentType === 'application/javascript') { } else if (contentType === 'application/javascript') {
@ -346,14 +346,10 @@ const getFileCompressed = (filename, contentType, callback) => {
}); });
}; };
const getFile = (filename, callback) => { const getFile = async (filename) => {
if (filename === 'js/ace.js') { if (filename === 'js/ace.js') return await getAceFile();
util.callbackify(getAceFile)(callback); if (filename === 'js/require-kernel.js') return requireDefinition();
} else if (filename === 'js/require-kernel.js') { return await util.promisify(fs.readFile)(ROOT_DIR + filename);
callback(undefined, requireDefinition());
} else {
fs.readFile(ROOT_DIR + filename, callback);
}
}; };
exports.minify = minify; exports.minify = minify;