Skip to content

solidity loader: fall back to project-relative resolution for bare specs#39

Merged
exo-nikita merged 1 commit into
mainfrom
claude/amazing-carson-hHyFA
Jun 5, 2026
Merged

solidity loader: fall back to project-relative resolution for bare specs#39
exo-nikita merged 1 commit into
mainfrom
claude/amazing-carson-hHyFA

Conversation

@exo-nikita

Copy link
Copy Markdown
Collaborator

Summary

Foundry-style import "src/Foo.sol" previously required a no-op src/=src/ virtual remapping to resolve, because resolveSolImport only covered remappings, relative paths, and @scope/pkg Node-style imports. When none of those matched, the spec was reported as a missing import.

This change adds a fourth strategy: when baseDir is provided and nothing else resolved, accept the spec as-is if a real file sits at <baseDir>/<spec>. Equivalent to an implicit <top>/=<top>/ remapping for any top-level directory in the project.

Safety:

  • statSync().isFile() filters out directories — prevents EISDIR mid-walk in processWave.
  • relative()-based check rejects specs that escape baseDir.
  • isAbsolute() blocks absolute specifiers like /etc/passwd.
  • Fallback is gated on baseDir so pure-function callers without fs context still get null.

Test plan

  • 8 new tests in tests/solidity-loader.test.js and tests/bundle-cmd.test.js covering: happy path, missing files, path traversal, absolute paths, directories, no-baseDir, walk via collectSolidityFilesFromDisk, end-to-end via buildSolidityBundle.
  • All 64 prior loader/bundle tests still pass.
  • oxlint clean on changed files.

Generated by Claude Code

Foundry-style `import "src/Foo.sol"` previously required a no-op
`src/=src/` virtual remapping to resolve, because resolveSolImport only
covered remappings, relative paths, and `@scope/pkg` Node-style imports.
When none of those matched, the spec was reported as a missing import.

Add a fourth strategy: when baseDir is provided and nothing else
resolved, accept the spec as-is if a real file sits at
`<baseDir>/<spec>`. Gated on statSync().isFile() so a directory match
doesn't sneak into the wave and blow up with EISDIR at readFile time.
Path-traversal-safe: relative()-based check rejects specs that escape
baseDir, and absolute specifiers are rejected outright.
@exo-nikita exo-nikita merged commit 3f26198 into main Jun 5, 2026
2 checks passed
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