Patch deprecated Buffer API usage in vite-plugin

This commit is contained in:
Joseph Garrone 2024-05-19 08:51:13 +02:00
parent 5602dc58ff
commit e63cd68a3e

View File

@ -37,15 +37,7 @@ transformCodebase({
fs.rmSync(join("dist", "ncc_out"), { "recursive": true }); fs.rmSync(join("dist", "ncc_out"), { "recursive": true });
{ patchDeprecatedBufferApiUsage(join("dist", "bin", "main.js"));
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"));
}
fs.chmodSync( fs.chmodSync(
join("dist", "bin", "main.js"), join("dist", "bin", "main.js"),
@ -77,8 +69,20 @@ transformCodebase({
fs.rmSync(join("dist", "ncc_out"), { "recursive": true }); fs.rmSync(join("dist", "ncc_out"), { "recursive": true });
patchDeprecatedBufferApiUsage(join("dist", "vite-plugin", "index.js"));
function run(command: string) { function run(command: string) {
console.log(`$ ${command}`); console.log(`$ ${command}`);
child_process.execSync(command, { "stdio": "inherit" }); 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"));
}