Skip to content

fix(intellij): honor PUB_CACHE when generating IDE files - #1059

Merged
spydon merged 5 commits into
invertase:mainfrom
AzazelSensei:fix/intellij-pub-cache
Aug 14, 2026
Merged

fix(intellij): honor PUB_CACHE when generating IDE files#1059
spydon merged 5 commits into
invertase:mainfrom
AzazelSensei:fix/intellij-pub-cache

Conversation

@AzazelSensei

Copy link
Copy Markdown
Contributor

Bug Description

IntelliJ file generation looks up Melos templates (and writes the generated melos script path) as if the pub cache is always $HOME/.pub-cache. With PUB_CACHE pointed somewhere else, bootstrap throws PathNotFoundException on the template file.

Fixes #749

Root Cause

Isolate.resolvePackageUri can still resolve to $HOME/.pub-cache/hosted/pub.dev/melos-… after a global activate into a custom cache. getMelosBinForIde() also hardcoded that default.

Fix

  • Honor PUB_CACHE when remapping a missing default-cache template root
  • Use PUB_CACHE for the generated IntelliJ script path
  • Leave local/path installs alone when the isolate-resolved tree already has templates

How to Verify

  1. export PUB_CACHE=/tmp/custom-pub-cache
  2. dart pub global activate --source path packages/melos (or a hosted install)
  3. melos bootstrap in a workspace with IntelliJ generation enabled
  4. Templates are written; run configs point at $PUB_CACHE/bin/melos

Test Plan

  • Added regression tests for pub-cache lookup and the IDE script path
  • Existing IntelliJ/utils tests still pass
  • CI

Risk Assessment

Low — only remaps when the isolate-resolved path has no templates/ directory and sits under the default pub cache.

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Updates IntelliJ generation to honor custom Dart pub-cache locations.

Changes:

  • Adds pub-cache detection and template-root remapping.
  • Uses PUB_CACHE when 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.

Comment thread packages/melos/lib/src/common/utils.dart Outdated
Comment thread packages/melos/lib/src/common/intellij_project.dart Outdated
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.
@CLAassistant

CLAassistant commented Aug 13, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@AzazelSensei

Copy link
Copy Markdown
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 melos on PATH, so a custom PUB_CACHE actually gets used.

@github-actions github-actions Bot added the needs attention OP has responded and the issue needs looking at again. label Aug 13, 2026
existsSync throws on /root/.pub-cache under Linux CI. Tests now
compare normalized paths so Windows does not see a slash mismatch.
@spydon

spydon commented Aug 14, 2026

Copy link
Copy Markdown
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 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.

Since this accidentally reverted the #789 fix (and needed some other changes) I pushed some updates to the branch, but it should be ready to merge now. :)

@spydon
spydon enabled auto-merge (squash) August 14, 2026 23:21
@spydon
spydon merged commit 4c2fa47 into invertase:main Aug 14, 2026
8 checks passed
@spydon

spydon commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

This is now released in Melos v8.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs attention OP has responded and the issue needs looking at again.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Error while generating IntelliJ files with custom PUB_CACHE location

4 participants