Add polyfill for buffer (#1677)
* Add polyfill for buffer * Add deprecation notice
This commit is contained in:
parent
6b38401361
commit
bee11905dd
1725
pnpm-lock.yaml
1725
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -30,7 +30,10 @@
|
|||
"postcss-easy-import": "^4.0.0",
|
||||
"postcss-loader": "^6.2.1",
|
||||
"stylelint": "^14.3.0",
|
||||
"webpack": "^5.73.0",
|
||||
"stylelint-config-standard": "^24.0.0"
|
||||
"stylelint-config-standard": "^24.0.0",
|
||||
"webpack": "^5.73.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"buffer": "^6.0.3"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,13 @@
|
|||
import WebpackModules from "@modules/webpackmodules";
|
||||
import Logger from "@common/logger";
|
||||
|
||||
|
||||
Object.defineProperty(window, "Buffer", {
|
||||
get() {return Buffer.getBuffer().Buffer;},
|
||||
get() {
|
||||
Logger.warn("Deprecated", `Usage of the Buffer global is deprecated. Consider using web standards such as Uint8Array and TextDecoder/TextEncoder.`);
|
||||
return Buffer;
|
||||
},
|
||||
configurable: true,
|
||||
enumerable: false
|
||||
});
|
||||
|
||||
export default class Buffer {
|
||||
static getBuffer() {
|
||||
if (this.cached) return this.cached;
|
||||
|
||||
this.cached = WebpackModules.getByProps("INSPECT_MAX_BYTES");
|
||||
|
||||
return this.cached;
|
||||
}
|
||||
}
|
||||
export default Buffer;
|
|
@ -5,7 +5,7 @@ import vm from "./vm";
|
|||
import fs from "./fs";
|
||||
import request from "./request";
|
||||
import https from "./https";
|
||||
import Buffer from "./buffer";
|
||||
import buffer from "./buffer";
|
||||
import crypto from "./crypto";
|
||||
import Remote from "./remote";
|
||||
import Logger from "common/logger";
|
||||
|
@ -37,7 +37,7 @@ export const createRequire = function (path) {
|
|||
case "process": return window.process;
|
||||
case "vm": return vm;
|
||||
case "module": return Module;
|
||||
case "buffer": return Buffer.getBuffer();
|
||||
case "buffer": return buffer;
|
||||
case "crypto": return crypto;
|
||||
|
||||
default:
|
||||
|
|
|
@ -6,7 +6,7 @@ const basePkg = require("../package.json");
|
|||
|
||||
module.exports = {
|
||||
mode: "development",
|
||||
target: "node",
|
||||
target: "electron-renderer",
|
||||
devtool: false,
|
||||
entry: "./src/index.js",
|
||||
output: {
|
||||
|
@ -31,7 +31,10 @@ module.exports = {
|
|||
data$: path.resolve("src", "modules"),
|
||||
builtins$: path.resolve("src", "modules"),
|
||||
common: path.resolve(__dirname, "..", "common")
|
||||
}
|
||||
},
|
||||
fallback: {
|
||||
buffer: require.resolve("buffer/"),
|
||||
},
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
|
@ -53,7 +56,10 @@ module.exports = {
|
|||
}),
|
||||
new webpack.DefinePlugin({
|
||||
"process.env.__VERSION__": JSON.stringify(basePkg.version)
|
||||
})
|
||||
}),
|
||||
new webpack.ProvidePlugin({
|
||||
Buffer: [require.resolve("buffer/"), "Buffer"],
|
||||
}),
|
||||
],
|
||||
optimization: {
|
||||
minimizer: [
|
||||
|
|
Loading…
Reference in New Issue