Avoid breaking node retrocompatibility with dist patch

This commit is contained in:
Joseph Garrone 2024-05-19 09:02:04 +02:00
parent 8c6303f016
commit 3a4b44a83c

View File

@ -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);