From 8c7eeb8fd9f3d7c30e079ece77ccb1cc5b7196cc Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Sat, 11 Dec 2021 14:03:24 +0300 Subject: [PATCH] Replaced deprecated Buffer constructor with `Buffer.from` --- package.json | 2 +- scripts/buffer-fix.ts | 10 ++++++++++ scripts/index.ts | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 scripts/buffer-fix.ts create mode 100644 scripts/index.ts diff --git a/package.json b/package.json index 4ea68ab..d5234d7 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "GitHub Action that helps you publish your Minecraft mods", "main": "src/index.ts", "scripts": { - "build": "ncc build --source-map --license license.txt", + "build": "ncc build --source-map --license license.txt && ncc run scripts/index.ts", "test:lint": "eslint src/**/*.ts && eslint test/**/*.ts", "test:unit": "jest", "test": "npm run test:lint && npm run test:unit" diff --git a/scripts/buffer-fix.ts b/scripts/buffer-fix.ts new file mode 100644 index 0000000..1b27a4b --- /dev/null +++ b/scripts/buffer-fix.ts @@ -0,0 +1,10 @@ +import fs from "fs"; + +export default function fixDeprecatedBuffer() { + const files = fs.readdirSync("./dist", { withFileTypes: true }); + for (const file of files.filter(x => x.isFile())) { + const content = fs.readFileSync(`./dist/${file.name}`, "utf8"); + const fixedContent = content.replace(/new Buffer\(/g, "Buffer.from("); + fs.writeFileSync(`./dist/${file.name}`, fixedContent, "utf8"); + } +} diff --git a/scripts/index.ts b/scripts/index.ts new file mode 100644 index 0000000..2aa131f --- /dev/null +++ b/scripts/index.ts @@ -0,0 +1,3 @@ +import fixDeprecatedBuffer from "./buffer-fix"; + +fixDeprecatedBuffer();