Skip to content

feat(config): global remapping override of dependencies #12420

@mshakeg

Description

@mshakeg

Component

Forge

Describe the feature you would like

When using Soldeer to manage dependencies, installed packages often contain their own remappings.txt files that reference node_modules/ paths (since they were originally designed for npm/pnpm). When Foundry compiles files within these dependencies, it uses the dependency's local remappings.txt instead of the project's global remappings, causing compilation failures.

Current Behavior:

  1. Soldeer installs dependencies to dependencies/ folder (e.g., dependencies/dep-with-node-modules-deps-1.0.0/)
  2. Installed dependencies contain their own remappings.txt files with paths like:
    solmate/=node_modules/solmate/
    @openzeppelin/contracts/=node_modules/@openzeppelin/contracts/
    
  3. When Foundry compiles files inside dependencies/dep-with-node-modules-deps-1.0.0/src/, it uses the dependency's remappings.txt, not the project's
  4. Since node_modules/ doesn't exist (we're using Soldeer), compilation fails with "No such file or directory" errors

Why This Happens:

  • Dependencies are often published as npm packages or git repos with their own build configuration
  • Their remappings.txt assumes npm-style node_modules/ directory structure
  • Foundry's remapping resolution is hierarchical - it uses the closest remappings.txt to the file being compiled
  • Project-level remappings.txt does NOT override dependency-level ones

Current Workarounds (all problematic):

  1. Manually edit dependency remappings.txt: Fragile, gets overwritten on soldeer update
  2. Symlink node_modules: Hacky, breaks clean dependency management
  3. Define remappings in foundry.toml: Doesn't actually override dependency-level remappings.txt files

Solution

Provide a mechanism to make project-level remappings truly global, overriding any remappings.txt files found in dependencies.

Option A: Soldeer Configuration Flag

Add a soldeer config option to ignore/override dependency remappings:

[soldeer]
remappings_generate = true
remappings_override = true  # NEW: Project remappings override dependency remappings

Option B: Foundry Configuration Flag

Add a foundry.toml option to enforce global remappings:

[profile.default]
remappings_scope = "global"  # NEW: Use only project-level remappings, ignore dependency remappings

Expected Behavior:

With either of these solutions implemented:

  1. Developer installs dependencies via soldeer
  2. Project-level remappings.txt defines all import paths using soldeer directory structure
  3. When Foundry compiles files anywhere in the project (including inside dependencies), it uses only the project-level remappings
  4. Dependencies compile successfully without manual intervention

Benefits:

  • ✅ Clean dependency management with soldeer
  • ✅ No manual editing of dependency files
  • ✅ Works across soldeer updates
  • ✅ Predictable, reproducible builds
  • ✅ Aligns with soldeer's goal of replacing npm/git submodules

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions