Minify: Asyncify `getAceFile()`

pull/4765/head
Richard Hansen 2021-02-11 16:08:32 -05:00 committed by John McLear
parent 5cc191f185
commit e573276755
1 changed files with 34 additions and 35 deletions

View File

@ -190,9 +190,8 @@ const minify = (req, res) => {
};
// find all includes in ace.js and embed them.
const getAceFile = (callback) => {
fs.readFile(`${ROOT_DIR}js/ace.js`, 'utf8', (err, data) => {
if (ERR(err, callback)) return;
const getAceFile = async () => {
let data = await util.promisify(fs.readFile)(`${ROOT_DIR}js/ace.js`, 'utf8');
// Find all includes in ace.js and embed them
const filenames = [];
@ -213,7 +212,7 @@ const getAceFile = (callback) => {
// Request the contents of the included file on the server-side and write
// them into the file.
Promise.all(filenames.map(async (filename) => {
await Promise.all(filenames.map(async (filename) => {
// Hostname "invalid.invalid" is a dummy value to allow parsing as a URI.
const baseURI = 'http://invalid.invalid';
let resourceURI = baseURI + path.normalize(path.join('/static/', filename));
@ -227,8 +226,8 @@ const getAceFile = (callback) => {
} else {
console.error(`getAceFile(): error getting ${resourceURI}. Status code: ${status}`);
}
})).then(() => callback(null, data), (err) => callback(err || new Error(err)));
});
}));
return data;
};
// Check for the existance of the file and get the last modification date.
@ -348,7 +347,7 @@ const getFileCompressed = (filename, contentType, callback) => {
const getFile = (filename, callback) => {
if (filename === 'js/ace.js') {
getAceFile(callback);
util.callbackify(getAceFile)(callback);
} else if (filename === 'js/require-kernel.js') {
callback(undefined, requireDefinition());
} else {