Skip to content

fix(exec): set MELOS_PARENT_PACKAGE_* for example packages - #1123

Merged
spydon merged 2 commits into
mainfrom
fix/example-parent-package-env
Nov 16, 2026
Merged

spydon merged 2 commits into
mainfrom
fix/example-parent-package-env

Conversation

@Lyokone

@Lyokone Lyokone commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

Since 7.0.0 (#834), melos exec hasn't set MELOS_PARENT_PACKAGE_NAME, _VERSION and _PATH for an example package such as my_package/example. Package.isExample started checking the directory above the package (my_package) rather than the package's own directory.

The fix: isExample now checks the package's own directory name again. exec sets the variables only when the directory above is a workspace package, as before 7.0.0, and takes the values from that package. The environment variable docs now say "directory" instead of "package name".

Behaviour changes, back to the pre-7.0.0 behaviour:

  • A package nested inside an example, such as example/app, no longer gets the example folder's package as its parent.
  • A top-level example package never gets the workspace root as its parent.

Tests

exec_test.dart, "exec sets the parent package variables for an example package": melos exec runs a Dart script that prints the variables in a, a/example, a/example/app and a top-level example. Only a/example should get a as its parent. Without the fix, a/example gets nothing and a/example/app gets a_example.

Type of Change

  • ✨ feat -- New feature (non-breaking change which adds functionality)
  • 🛠️ fix -- Bug fix (non-breaking change which fixes an issue)
  • ❌ ! -- Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 refactor -- Code refactor
  • ✅ ci -- Build configuration change
  • 📝 docs -- Documentation
  • 🗑️ chore -- Chore

`Package.isExample` checked the directory above the package, so for
`my_package/example` it was false and `melos exec` never set the
parent package variables. It now checks the package's own directory,
which is what `exec` assumes when it reads `../pubspec.yaml`.
@docs-page

docs-page Bot commented Nov 16, 2026

Copy link
Copy Markdown

To preview the documentation for this pull request, visit the following URL:

melos.invertase.dev/~1123

Documentation is deployed and generated using docs.page

With the directory check alone, a top-level `example` package got the
workspace root as its parent. The parent must now be a workspace
package, as it was before 7.0.0, and its name, version and path come
from that package instead of re-parsing its pubspec.

@spydon spydon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm!

@spydon
spydon merged commit d11594c into main Nov 16, 2026
12 checks passed
@spydon
spydon deleted the fix/example-parent-package-env branch November 16, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants