From e63cd68a3e37e92f2baf8f255b02571b99574dfc Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Sun, 19 May 2024 08:51:13 +0200 Subject: [PATCH] Patch deprecated Buffer API usage in vite-plugin --- scripts/build.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/scripts/build.ts b/scripts/build.ts index 31ddea1b..edc2c984 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -37,15 +37,7 @@ transformCodebase({ fs.rmSync(join("dist", "ncc_out"), { "recursive": true }); -{ - const before = fs.readFileSync(join("dist", "bin", "main.js")).toString("utf8"); - - const after = before.replace(`var buffer = new Buffer(toRead);`, `var buffer = Buffer.allocUnsafe(toRead);`); - - assert(after !== before); - - fs.writeFileSync(join("dist", "bin", "main.js"), Buffer.from(after, "utf8")); -} +patchDeprecatedBufferApiUsage(join("dist", "bin", "main.js")); fs.chmodSync( join("dist", "bin", "main.js"), @@ -77,8 +69,20 @@ transformCodebase({ fs.rmSync(join("dist", "ncc_out"), { "recursive": true }); +patchDeprecatedBufferApiUsage(join("dist", "vite-plugin", "index.js")); + function run(command: string) { console.log(`$ ${command}`); child_process.execSync(command, { "stdio": "inherit" }); } + +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);`); + + assert(after !== before); + + fs.writeFileSync(filePath, Buffer.from(after, "utf8")); +}