Fix translations transform build errors (#24631)

Let gulp handle transform errors
pull/24664/head
Wendelin 2025-03-17 14:02:41 +01:00 committed by GitHub
parent d8b6de2afd
commit 06b969f6b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 27 deletions

View File

@ -40,8 +40,8 @@ class CustomJSON extends Transform {
this._reviver = reviver; this._reviver = reviver;
} }
// eslint-disable-next-line @typescript-eslint/naming-convention
async _transform(file, _, callback) { async _transform(file, _, callback) {
try {
let obj = JSON.parse(file.contents.toString(), this._reviver); let obj = JSON.parse(file.contents.toString(), this._reviver);
if (this._func) obj = this._func(obj, file.path); if (this._func) obj = this._func(obj, file.path);
for (const [outObj, dir] of Array.isArray(obj) ? obj : [[obj, ""]]) { for (const [outObj, dir] of Array.isArray(obj) ? obj : [[obj, ""]]) {
@ -51,9 +51,6 @@ class CustomJSON extends Transform {
this.push(outFile); this.push(outFile);
} }
callback(null); callback(null);
} catch (err) {
callback(err);
}
} }
} }
@ -68,25 +65,19 @@ class MergeJSON extends Transform {
this._reviver = reviver; this._reviver = reviver;
} }
// eslint-disable-next-line @typescript-eslint/naming-convention
async _transform(file, _, callback) { async _transform(file, _, callback) {
try {
this._objects.push(JSON.parse(file.contents.toString(), this._reviver)); this._objects.push(JSON.parse(file.contents.toString(), this._reviver));
if (!this._outFile) this._outFile = file.clone({ contents: false }); if (!this._outFile) this._outFile = file.clone({ contents: false });
callback(null); callback(null);
} catch (err) {
callback(err);
}
} }
// eslint-disable-next-line @typescript-eslint/naming-convention
async _flush(callback) { async _flush(callback) {
try {
const mergedObj = merge(this._startObj, ...this._objects); const mergedObj = merge(this._startObj, ...this._objects);
this._outFile.contents = Buffer.from(JSON.stringify(mergedObj)); this._outFile.contents = Buffer.from(JSON.stringify(mergedObj));
this._outFile.stem = this._stem; this._outFile.stem = this._stem;
callback(null, this._outFile); callback(null, this._outFile);
} catch (err) {
callback(err);
}
} }
} }