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,20 +40,17 @@ 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, ""]]) { const outFile = file.clone({ contents: false });
const outFile = file.clone({ contents: false }); outFile.contents = Buffer.from(JSON.stringify(outObj));
outFile.contents = Buffer.from(JSON.stringify(outObj)); outFile.dirname += `/${dir}`;
outFile.dirname += `/${dir}`; this.push(outFile);
this.push(outFile);
}
callback(null);
} catch (err) {
callback(err);
} }
callback(null);
} }
} }
@ -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);
}
} }
} }