microsoft / rnx-kit

Modern, scalable tools. Exceptional developer experience.
https://microsoft.github.io/rnx-kit/
MIT License
1.46k stars 94 forks source link

ignoredModules Option Not Functioning as Expected #3207

Closed gobi-G closed 4 days ago

gobi-G commented 1 week ago

What happened?

Description The ignoredModules option in metro-plugin-duplicates-checker does not seem to work as intended. Regardless of whether I provide the full path to specific modules or use a pattern, the plugin still checks subpackages.

Context I am working on a monorepo where I need the plugin to ignore all subpackages and only check the root-level packages for duplicates. Here is the relevant part of my metro.config.js:

const { makeMetroConfig } = require('@rnx-kit/metro-config');
const {
  DuplicateDependencies,
} = require('@rnx-kit/metro-plugin-duplicates-checker');
const { MetroSerializer } = require('@rnx-kit/metro-serializer');

const metroConfig = makeMetroConfig({
  serializer: {
    customSerializer: MetroSerializer([
      DuplicateDependencies({
        ignoredModules: ['**/node_modules/*/node_modules/**'],
        throwOnError: true,
      }),
    ]),
  },
});

module.exports = metroConfig;

Expected Behavior I expect the ignoredModules option to prevent the plugin from checking subpackages, such as:

/Users/username/Documents/my-project/node_modules/subpackage/node_modules/@module

Only the root-level packages should be checked, like:

/Users/username/Documents/my-project/node_modules/@module

Actual Behavior Despite the configuration, the plugin continues to check subpackages and reports duplicates that are nested within other node_modules directories.

Request Please provide guidance on how to properly configure ignoredModules to effectively ignore subpackages in a monorepo environment, or address the issue if it is a bug.

Affected Package

@rnx-kit/metro-plugin-duplicates-checker

Version

2.1.3

Which platforms are you seeing this issue on?

System Information

System:
  OS: macOS 14.5
  CPU: (8) arm64 Apple M1
  Memory: 119.17 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.9.0
    path: /usr/local/bin/node
  Yarn:
    version: 4.2.1
    path: /usr/local/bin/yarn
  npm:
    version: 10.1.0
    path: /usr/local/bin/npm
  Watchman:
    version: 2024.01.22.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/gobiganjeyamoorthy/.asdf/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK:
    API Levels:
      - "29"
      - "30"
      - "31"
      - "33"
      - "34"
    Build Tools:
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 33.0.0
      - 33.0.1
      - 34.0.0
    System Images:
      - android-29 | Google APIs ARM 64 v8a
      - android-29 | Google APIs Intel x86 Atom_64
      - android-31 | ARM 64 v8a
      - android-31 | Google APIs ARM 64 v8a
      - android-31 | Google APIs Intel x86 Atom_64
      - android-33 | Google APIs ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11076708
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.9
    path: /usr/bin/javac
  Ruby:
    version: 3.3.0
    path: /Users/gobiganjeyamoorthy/.asdf/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react: 18.2.0
  react-native: 0.73.7
  react-native-macos: Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Steps to Reproduce

  1. Create a monorepo setup with multiple packages.
  2. Configure metro.config.js with the ignoredModules option as shown above.
  3. Run the Metro bundler and observe that subpackages are still being checked.

Code of Conduct

tido64 commented 4 days ago

You can find the documentation in the README.md: https://github.com/microsoft/rnx-kit/tree/main/packages/metro-plugin-duplicates-checker#options

It states that ignoredModules is a "list of modules that can be ignored", meaning you should use package names here. It does not say that it's a list of paths or glob patterns.

Unless package names don't work, the option works as expected. I'm closing this issue. Feel free to open a new issue if you hit others issues.