invertase / melos

🌋 A tool for managing Dart projects with multiple packages. With IntelliJ and Vscode IDE support. Supports automated versioning, changelogs & publishing via Conventional Commits.
https://melos.invertase.dev/~melos-latest
Apache License 2.0
1.08k stars 193 forks source link

fix: melos overrides the applied filter for dependents/dependencies #675

Closed xsahil03x closed 4 months ago

xsahil03x commented 4 months ago

Is there an existing issue for this?

Version

5.2.1

Description

Currently, the order in which melos exec calculates the packages are as follows:

https://github.com/invertase/melos/blob/main/packages/melos/lib/src/package.dart#L597-L628

  1. filters (eg: applyIgnore, applyDirExists, applyFileExists)
  2. applyDiff
  3. applyIncludeDependentsOrDependencies if enabled

Because we are executing applyIncludeDependentsOrDependencies at the last step, the added packages skips all the filters applied on the first step. So even tho a package is skipped in the first step, it can re-appear through the last applyIncludeDependentsOrDependencies step.

Steps to reproduce

Suppose we have a monorepo with 2 packages.

Package Dependencies Have Changes Contains Test
Package A Package B false false
Package B - true true

Now if we try to run the command:

melos exec --fail-fast --dir-exists="test" --diff=origin/main...HEAD -c 1 --include-dependents -- flutter test

Ideally the command should only run for Package B as Package A contains no test. But in the current implementation it will also include Package A as it depends on Package B.

Expected behavior

The filters should also be applied on dependents/dependencies.

Screenshots

No response

Additional context and comments

No response

spydon commented 4 months ago
--include-dependents    Include all transitive dependents for each package that matches the other filters. The included packages skip --ignore and --diff checks.

This is not a bug, it is how it is intended to work, and also how the docs describe it.

xsahil03x commented 4 months ago
--include-dependents    Include all transitive dependents for each package that matches the other filters. The included packages skip --ignore and --diff checks.

This is not a bug, it is how it is intended to work, and also how the docs describe it.

Thanks, i missed.

Pavel-Sulimau commented 3 months ago

Hey @xsahil03x, I ended up implementing the approach of setting the global MELOS_PACKAGES filter with the values from melos list --diff=origin/main...HEAD --include-dependents in the CI pipeline for our big project.

The approach is described in https://itnext.io/flutter-selective-ci-checks-2d79ffbd26e5 article. Hopefully, it may be a workaround for you as well!