Skip to content

Use workspace root when constructing Entrypoint in getExecutableForCommand and ensureUpToDate - #4863

Open
sigurdm wants to merge 1 commit into
dart-lang:masterfrom
sigurdm:fix-61950
Open

Use workspace root when constructing Entrypoint in getExecutableForCommand and ensureUpToDate#4863
sigurdm wants to merge 1 commit into
dart-lang:masterfrom
sigurdm:fix-61950

Conversation

@sigurdm

@sigurdm sigurdm commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Fixes sub-directory executable resolution and workspace member invalidation when resolution is out of date.

  1. Sub-directory executable resolution:
    In commit a87b84d (Allow invoking getExecutableForCommand everywhere in workspace #4257, Dart 3.5.0), getExecutableForCommand was updated to allow running commands from package subdirectories (cd lib && dart run ...). However, when invoked from a sub-directory without a pubspec.yaml while resolution was out of date or snapshot compilation was required, Entrypoint was constructed with workingDir pointing to the sub-directory. This caused relative path resolution against .dart_tool/package_config.json to be computed relative to the sub-directory, failing with Could not find a file named "pubspec.yaml" in ".../lib".
  • Resolves the target package directory using a shared _rootPackageDir helper in both isResolutionUpToDate and Entrypoint.ensureUpToDate.
  • Uses workspaceRootDir when constructing Entrypoint in getExecutableForCommand.
  1. Workspace resolution invalidation:
    When new packages were added to a workspace without running pub get:
  • isLockFileUpToDate only checked root.immediateDependencies, missing the immediate dependencies of other workspace packages (workspaceRoot.transitiveWorkspace).
  • isPackagePathsMappingUpToDateWithLockfile only verified that no extra mappings existed, missing when workspace packages were missing from .dart_tool/package_config.json.
  • This update checks immediate dependencies across all packages in workspaceRoot.transitiveWorkspace in isLockFileUpToDate, and ensures all packages in workspaceRoot.transitiveWorkspace exist in packagePathsMapping.

Fixes dart-lang/sdk#61950

@sigurdm
sigurdm force-pushed the fix-61950 branch 7 times, most recently from f8729c3 to bd826da Compare August 17, 2026 12:35
@sigurdm
sigurdm requested a review from jonasfj August 17, 2026 12:43
@davidmorgan

Copy link
Copy Markdown

Gemini thinks this fixes half the linked issue but not the other half:

PR #4863 #4863 fixes running executables from sub-directories (cd lib && dart run ...), but does not address workspace resolution invalidation.

In build_command_define_test.dart:140-178:

  1. A single-package workspace with root_pkg is resolved by dart run.
  2. New workspace members pkg_a and pkg_b are added to the workspace pubspec.yaml, and root_pkg adds dependencies on pkg_a and pkg_b.
  3. dart run build_runner build --force-jit --workspace runs at the workspace root.
  4. Entrypoint.isResolutionUpToDate:
    • Checks root.immediateDependencies against the lockfile. Because root is the workspace root pubspec.yaml, its immediateDependencies is empty. The dependencies of workspaceRoot.transitiveWorkspace members
    (root_pkg, pkg_a, pkg_b) are never checked.
    • Checks isPackageConfigUpToDate, which only ensures package_config.json contains no extra keys, but does not verify that all workspace members and their dependencies are present in package_config.json.
  5. isResolutionUpToDate returns true, skipping pub get, leaving package_config.json without pkg_a and pkg_b.

@sigurdm

sigurdm commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @davidmorgan! Good catch — isResolutionUpToDate was missing workspace checks in two places:

  1. In isLockFileUpToDate, it only checked root.immediateDependencies instead of checking the dependencies across all packages in workspaceRoot.transitiveWorkspace.
  2. In isPackagePathsMappingUpToDateWithLockfile, it checked for extra mappings but didn't verify that every package in workspaceRoot.transitiveWorkspace was present in package_config.json.

Both checks have been added along with a unit test (Invalidates resolution when new package added to workspace) in commit f496d51e5.

Comment thread lib/src/entrypoint.dart Outdated
…mmand and ensureUpToDate

Fixes sub-directory executable resolution when resolution is out of date or executable snapshot compilation is needed.
Relates to dart-lang/sdk#61950.
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.

"dart run" breaks in subpath with outdated lock

3 participants