Make the process locales plugin properly async (#2940)

This commit is contained in:
absidue 2022-12-11 08:42:35 +01:00 committed by GitHub
parent e96116af10
commit b33af1c812
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 6 deletions

View File

@ -1,7 +1,10 @@
const { existsSync, readFileSync } = require('fs')
const { brotliCompressSync, constants } = require('zlib')
const { brotliCompress, constants } = require('zlib')
const { promisify } = require('util')
const { load: loadYaml } = require('js-yaml')
const brotliCompressAsync = promisify(brotliCompress)
class ProcessLocalesPlugin {
constructor(options = {}) {
this.compress = !!options.compress
@ -34,9 +37,9 @@ class ProcessLocalesPlugin {
},
async (_assets) => {
const promises = []
for (const { locale, data } of this.locales) {
promises.push(new Promise((resolve) => {
promises.push(new Promise(async (resolve) => {
if (Object.prototype.hasOwnProperty.call(data, 'Locale Name')) {
delete data['Locale Name']
}
@ -46,7 +49,7 @@ class ProcessLocalesPlugin {
if (this.compress) {
filename += '.br'
output = this.compressLocale(output)
output = await this.compressLocale(output)
}
compilation.emitAsset(
@ -78,10 +81,10 @@ class ProcessLocalesPlugin {
}
}
compressLocale(data) {
async compressLocale(data) {
const buffer = Buffer.from(data, 'utf-8')
return brotliCompressSync(buffer, {
return await brotliCompressAsync(buffer, {
params: {
[constants.BROTLI_PARAM_MODE]: constants.BROTLI_MODE_TEXT,
[constants.BROTLI_PARAM_QUALITY]: constants.BROTLI_MAX_QUALITY,