fix(intellij): honor PUB_CACHE when generating IDE files - #1059
Merged
Conversation
Template lookup and the generated melos script path assumed $HOME/.pub-cache. That fails when PUB_CACHE is set to a custom location. Fix invertase#749
1 task
There was a problem hiding this comment.
Pull request overview
Updates IntelliJ generation to honor custom Dart pub-cache locations.
Changes:
- Adds pub-cache detection and template-root remapping.
- Uses
PUB_CACHEwhen resolving the Melos executable. - Adds regression tests for cache resolution and IDE paths.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
packages/melos/lib/src/common/environment_variable_key.dart |
Defines the PUB_CACHE key. |
packages/melos/lib/src/common/utils.dart |
Resolves and remaps pub-cache paths. |
packages/melos/lib/src/common/intellij_project.dart |
Resolves the IDE Melos executable path. |
packages/melos/test/utils_test.dart |
Tests pub-cache path behavior. |
packages/melos/test/common/intellij_project_test.dart |
Tests IDE executable resolution. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Windows can resolve the package under Roaming even when Local is set, so remapping only the Local default missed that path. The shell script template also never used scriptPath, so IntelliJ still ran whatever melos was on PATH. Point SCRIPT_PATH at the resolved bin.
Contributor
Author
|
Updated from the review notes. Windows remapping now tries both Local and Roaming before deciding the isolate path is not a default cache. The run configuration template writes SCRIPT_PATH / SCRIPT_OPTIONS instead of |
existsSync throws on /root/.pub-cache under Linux CI. Tests now compare normalized paths so Windows does not see a slash mismatch.
Collaborator
|
@AzazelSensei can you sign the CLA as prompted above? :) |
…_CACHE remap Address review feedback: - Restore the SCRIPT_TEXT-based run configuration template from invertase#789 so melos keeps resolving from PATH. A fixed SCRIPT_PATH into the pub cache breaks shims, symlinks, and workspace installs, and writes machine-specific absolute paths into committed .idea files. - Revert the PUB_CACHE branch of getMelosBinForIde accordingly, and hoist the loop-invariant bin path computation out of writeMelosScripts. - Keep getMelosRoot generic: the templates probe now lives at the IntelliJ call site and is passed to applyPubCacheOverride as a parameter. - Validate the rewritten root: only remap when the probe subdirectory actually exists under PUB_CACHE, otherwise keep the resolved root so errors name a real path. - Guard paths already inside PUB_CACHE (prevents doubling a nested cache path), compare paths with p.equals instead of ==, absolutize a relative PUB_CACHE the way pub does, and skip the remap when no default cache location can be determined (HOME unset). - Drop the unused getPubCacheDirectory/defaultPubCacheDirectory helpers, reuse io.dart's dirExists (wrapped to treat unreadable paths as missing), and memoize the resolved melos root. - Test the remap against real directories, and assert that PUB_CACHE does not change the generated run configuration XML.
spydon
enabled auto-merge (squash)
August 14, 2026 23:21
Collaborator
|
This is now released in Melos v8.3.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug Description
IntelliJ file generation looks up Melos templates (and writes the generated
melosscript path) as if the pub cache is always$HOME/.pub-cache. WithPUB_CACHEpointed somewhere else, bootstrap throwsPathNotFoundExceptionon the template file.Fixes #749
Root Cause
Isolate.resolvePackageUrican still resolve to$HOME/.pub-cache/hosted/pub.dev/melos-…after a global activate into a custom cache.getMelosBinForIde()also hardcoded that default.Fix
PUB_CACHEwhen remapping a missing default-cache template rootPUB_CACHEfor the generated IntelliJ script pathHow to Verify
export PUB_CACHE=/tmp/custom-pub-cachedart pub global activate --source path packages/melos(or a hosted install)melos bootstrapin a workspace with IntelliJ generation enabled$PUB_CACHE/bin/melosTest Plan
Risk Assessment
Low — only remaps when the isolate-resolved path has no
templates/directory and sits under the default pub cache.