solidity loader: fall back to project-relative resolution for bare specs#39
Merged
Conversation
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.
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.
Summary
Foundry-style
import "src/Foo.sol"previously required a no-opsrc/=src/virtual remapping to resolve, becauseresolveSolImportonly covered remappings, relative paths, and@scope/pkgNode-style imports. When none of those matched, the spec was reported as a missing import.This change adds a fourth strategy: when
baseDiris 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 inprocessWave.relative()-based check rejects specs that escapebaseDir.isAbsolute()blocks absolute specifiers like/etc/passwd.baseDirso pure-function callers without fs context still getnull.Test plan
tests/solidity-loader.test.jsandtests/bundle-cmd.test.jscovering: happy path, missing files, path traversal, absolute paths, directories, no-baseDir, walk viacollectSolidityFilesFromDisk, end-to-end viabuildSolidityBundle.oxlintclean on changed files.Generated by Claude Code