From 790715726a4c527f0a27a8e47dd2134ea760ac11 Mon Sep 17 00:00:00 2001 From: MengYX Date: Wed, 4 Mar 2020 08:37:16 +0800 Subject: [PATCH] Add temporary solution to fix compatibility for Edge 18 --- src/fix-compatibility.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/fix-compatibility.js diff --git a/src/fix-compatibility.js b/src/fix-compatibility.js new file mode 100644 index 0000000..159555d --- /dev/null +++ b/src/fix-compatibility.js @@ -0,0 +1,20 @@ +//TODO: Use other method to fix this +// !! Only Temporary Solution +// it seems like that @babel/plugin-proposal-object-rest-spread not working +// to fix up the compatibility for Edge 18 and some older Chromium +// now manually edit the dependency files + +const fs = require('fs'); +const filePath = "../node_modules/file-type/core.js"; +const regReplace = /{\s*([a-zA-Z0-9:,\s]*),\s*\.\.\.([a-zA-Z0-9]*)\s*};/m; +if (fs.existsSync(filePath)) { + let data = fs.readFileSync(filePath).toString(); + const regResult = regReplace.exec(data); + if (regResult != null) { + data = data.replace(regResult[0], + "Object.assign({ " + regResult[1] + " }, " + regResult[2] + ");" + ); + } + fs.writeFileSync(filePath, data); + console.log("Object rest spread in file-type fixed!") +}