From 3a4b44a83c0262f9ef7c6ae8b85d0846627c41b7 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Sun, 19 May 2024 09:02:04 +0200 Subject: [PATCH] Avoid breaking node retrocompatibility with dist patch --- scripts/build.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/build.ts b/scripts/build.ts index edc2c984..756839b1 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -80,7 +80,10 @@ function run(command: string) { function patchDeprecatedBufferApiUsage(filePath: string) { const before = fs.readFileSync(filePath).toString("utf8"); - const after = before.replace(`var buffer = new Buffer(toRead);`, `var buffer = Buffer.allocUnsafe(toRead);`); + const after = before.replace( + `var buffer = new Buffer(toRead);`, + `var buffer = Buffer.allocUnsafe ? Buffer.allocUnsafe(toRead) : new Buffer(toRead);` + ); assert(after !== before);