rnx-kit/packages/metro-plugin-cyclic-depende...
renovate[bot] 57013d2191
fix(deps): update eslint (major) (#3394)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Tommy Nguyen <4123478+tido64@users.noreply.github.com>
2024-10-17 14:41:52 +00:00
..
src
test
CHANGELOG.md RELEASING: Releasing 44 package(s) (#3342) 2024-09-11 08:59:50 +02:00
README.md
eslint.config.js
package.json fix(deps): update eslint (major) (#3394) 2024-10-17 14:41:52 +00:00
tsconfig.json

README.md

@rnx-kit/metro-plugin-cyclic-dependencies-detector

Build npm version

@rnx-kit/metro-plugin-cyclic-dependencies-detector detects cyclic import chains that may cause issues in your bundle.

Usage

Import and add the plugin to MetroSerializer in your metro.config.js, and optionally configure it to your liking:

 const { makeMetroConfig } = require("@rnx-kit/metro-config");
+const {
+  CyclicDependencies,
+} = require("@rnx-kit/metro-plugin-cyclic-dependencies-detector");
+const { MetroSerializer } = require("@rnx-kit/metro-serializer");

 module.exports = makeMetroConfig({
   serializer: {
+    customSerializer: MetroSerializer([
+      CyclicDependencies({
+        includeNodeModules: false,
+        linesOfContext: 1,
+        throwOnError: true,
+      }),
+    ]),
   },
 });

Options

Key Type Default Description
includeNodeModules boolean false Whether to scan node_modules.
linesOfContext number 1 Number of extra modules to print for context.
throwOnError boolean true Whether to throw when cycles are detected.