Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

deps: don't bring node polyfills into browser (#64740)

Uladzimir Havenchyk7b7d02442acc
diff --git a/.eslintrc.js b/.eslintrc.js
index bf1041df178..5e048f908ce 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -136,7 +136,7 @@ module.exports = {
},
env: {
browser: true,
- es6: true,
+ es2020: true,
commonjs: true,
jest: true,
"jest/globals": true,
diff --git a/frontend/test/jest-setup.js b/frontend/test/jest-setup.js
index ab77c6bed94..da4a0e81a26 100644
--- a/frontend/test/jest-setup.js
+++ b/frontend/test/jest-setup.js
@@ -1,4 +1,3 @@
-/* eslint-disable no-undef */
import { Crypto, CryptoKey } from "@peculiar/webcrypto";
import { TextDecoder, TextEncoder } from "util";
import { ReadableStream } from "web-streams-polyfill";
diff --git a/package.json b/package.json
index c0aee9f1af5..02ba0e41056 100644
--- a/package.json
+++ b/package.json
@@ -104,7 +104,7 @@
"mustache": "^2.3.2",
"normalizr": "^3.0.2",
"ora": "^8.0.1",
- "password-generator": "^2.0.1",
+ "password-generator": "^2.3.2",
"process": "^0.11.10",
"prop-types": "^15.5.7",
"re-reselect": "^4.0.1",
diff --git a/patches/password-generator+2.3.2.patch b/patches/password-generator+2.3.2.patch
new file mode 100644
index 00000000000..e77ee860f23
--- /dev/null
+++ b/patches/password-generator+2.3.2.patch
@@ -0,0 +1,23 @@
+diff --git a/node_modules/password-generator/lib/password-generator.js b/node_modules/password-generator/lib/password-generator.js
+index 4048bc1..e5d478b 100644
+--- a/node_modules/password-generator/lib/password-generator.js
++++ b/node_modules/password-generator/lib/password-generator.js
+@@ -91,13 +91,15 @@
+
+
+ getRandomValues = function (buf) {
++ // override root to be able to run in both node and browser env
++ root = globalThis;
+ if (root.crypto && root.crypto.getRandomValues) {
+ root.crypto.getRandomValues(buf);
+ } else if (typeof root.msCrypto === "object" && typeof root.msCrypto.getRandomValues === 'function') {
+ root.msCrypto.getRandomValues(buf);
+- } else if (module.exports === password && typeof require !== "undefined") {
+- var bytes = require("crypto").randomBytes(buf.length);
+- buf.set(bytes);
++ // require('crypto') fails due to bundler's static analysis
++ // both node and browsers have getRandomValues nowadays,
++ // so require is removed
+ } else {
+ throw new Error("No secure random number generator available.");
+ }
diff --git a/rspack.main.config.js b/rspack.main.config.js
index ea731d977c7..9c52ce198ca 100644
--- a/rspack.main.config.js
+++ b/rspack.main.config.js
@@ -6,7 +6,6 @@ const fs = require("fs");
const rspack = require("@rspack/core");
const ReactRefreshPlugin = require("@rspack/plugin-react-refresh");
const HtmlWebpackPlugin = require("html-webpack-plugin");
-const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
const WebpackNotifierPlugin = require("webpack-notifier");
const {
@@ -248,6 +247,9 @@ const config = {
"sdk-ee-plugins": resolveEnterprisePathOrNoop("/sdk-plugins"),
"sdk-specific-imports": SRC_PATH + "/lib/noop",
},
+ fallback: {
+ buffer: require.resolve("buffer/"),
+ },
},
optimization: {
runtimeChunk: "single",
@@ -315,14 +317,16 @@ const config = {
template: __dirname + "/resources/frontend_client/index_template.html",
}),
new rspack.BannerPlugin(getBannerOptions(LICENSE_TEXT)),
- new NodePolyfillPlugin(), // for crypto, among others
+ // https://github.com/orgs/remarkjs/discussions/903
+ new rspack.ProvidePlugin({
+ process: "process/browser.js",
+ Buffer: ["buffer", "Buffer"],
+ }),
new rspack.EnvironmentPlugin({
WEBPACK_BUNDLE: "development",
MB_LOG_ANALYTICS: "false",
ENABLE_CLJS_HOT_RELOAD: process.env.ENABLE_CLJS_HOT_RELOAD ?? "false",
}),
- // https://github.com/remarkjs/remark/discussions/903
- new rspack.ProvidePlugin({ process: "process/browser.js" }),
],
};
diff --git a/yarn.lock b/yarn.lock
index 49b46d9b429..5deb7f7c24d 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -16659,7 +16659,7 @@ pascal-case@^3.1.2:
no-case "^3.0.4"
tslib "^2.0.3"
-password-generator@^2.0.1:
+password-generator@^2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/password-generator/-/password-generator-2.3.2.tgz#9626f778d64d26f7c2f73b64389407e28f62eecd"
integrity sha512-kJWUrdveSAqHCeWJWnv5vNc89hFHM5au+pvKja5+xCTxlRF3zQaecJlR6hSoOotAJtQ3otQq4/Q4iWc/TxsXhA==