diff --git a/client/package.json b/client/package.json index 18138057d8f..2841b4983d0 100644 --- a/client/package.json +++ b/client/package.json @@ -165,6 +165,7 @@ "babel-jest": "^29.7.0", "babel-plugin-transform-import-meta": "^2.2.1", "buffer": "^6.0.3", + "circular-dependency-plugin": "^5.2.2", "cpy-cli": "^5.0.0", "css-loader": "^7.1.2", "css-minimizer-webpack-plugin": "^5.0.1", diff --git a/client/webpack.config.js b/client/webpack.config.js index a651c1e26a5..67c9dd1fce4 100644 --- a/client/webpack.config.js +++ b/client/webpack.config.js @@ -8,6 +8,7 @@ const { DumpMetaPlugin } = require("dumpmeta-webpack-plugin"); const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin"); const TerserPlugin = require("terser-webpack-plugin"); const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin"); +const CircularDependencyPlugin = require("circular-dependency-plugin"); const scriptsBase = path.join(__dirname, "src"); const testsBase = path.join(__dirname, "tests"); @@ -301,6 +302,23 @@ module.exports = (env = {}, argv = {}) => { }, }; + // Only include CircularDependencyPlugin in development mode + if (targetEnv === "development") { + buildconfig.plugins.push( + new CircularDependencyPlugin({ + // exclude detection of files based on a RegExp + exclude: /a\.js|node_modules|src\/libs/, + // add errors to webpack instead of warnings + failOnError: !!process.env.CIRCULAR_DEPENDENCY_FAIL_ON_ERROR, + // allow import cycles that include an asyncronous import, + // e.g. via import(/* webpackMode: "weak" */ './file.js') + allowAsyncCycles: false, + // set the current working directory for displaying module paths + cwd: process.cwd(), + }) + ); + } + if (process.env.GXY_BUILD_SOURCEMAPS) { buildconfig.devtool = "eval-cheap-module-source-map"; } diff --git a/client/yarn.lock b/client/yarn.lock index 8fcf2e5df9d..7e38dd9abc1 100644 --- a/client/yarn.lock +++ b/client/yarn.lock @@ -4397,6 +4397,11 @@ ci-info@^3.2.0: resolved "https://registry.npmjs.org/ci-info/-/ci-info-3.3.2.tgz" integrity sha512-xmDt/QIAdeZ9+nfdPsaBCpMvHNLFiLdjj59qjqn+6iPe6YmHGQ35sBnQ8uslRBXFmXkiZQOJRjvQeoGppoTjjg== +circular-dependency-plugin@^5.2.2: + version "5.2.2" + resolved "https://registry.yarnpkg.com/circular-dependency-plugin/-/circular-dependency-plugin-5.2.2.tgz#39e836079db1d3cf2f988dc48c5188a44058b600" + integrity sha512-g38K9Cm5WRwlaH6g03B9OEz/0qRizI+2I7n+Gz+L5DxXJAPAiWQvwlYNm1V1jkdpUv95bOe/ASm2vfi/G560jQ== + circular-json@^0.5.0: version "0.5.9" resolved "https://registry.npmjs.org/circular-json/-/circular-json-0.5.9.tgz"