Skip to content

Commit a5b5190

Browse files
Bakhtier Gaibulloevclaude
authored andcommitted
fix: handle OS-level absolute paths in module resolver
The module resolver was incorrectly treating OS-level absolute paths (like /Users/...) as project-relative paths (like /module), causing path duplication when resolving entry points. This fix distinguishes between the two by checking if the absolute path has multiple path segments. The issue occurred because: 1. The resolver checked for absolute paths with fs.existsSync() 2. If the file didn't exist or the check failed, it fell through to the project-relative handler 3. The project-relative handler (resolveAbsolute) would strip the leading '/' and concatenate with baseUrl, causing duplication The fix checks if an absolute path has multiple segments (e.g., /Users/foo/bar vs /module) to determine if it's an OS-level absolute path or a project-relative path. Fixes the issue where 'somon run hello_world.som' would fail with a duplicated path error.
1 parent ed52ef3 commit a5b5190

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

src/module-system/module-resolver.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,19 @@ export class ModuleResolver {
5555
}
5656

5757
// Handle already absolute file paths
58-
if (path.isAbsolute(specifier) && fs.existsSync(specifier)) {
59-
return {
60-
resolvedPath: specifier,
61-
isExternalLibrary: false,
62-
extension: path.extname(specifier),
63-
};
58+
// Check if it's an OS-level absolute path (not project-relative like "/module")
59+
// We distinguish by checking if it's absolute AND has path separators beyond the first character
60+
if (path.isAbsolute(specifier)) {
61+
const normalizedPath = path.normalize(specifier);
62+
// If the path has multiple segments (e.g., /Users/... or C:\Users\...), treat as OS absolute
63+
const pathSegments = normalizedPath.split(path.sep).filter(s => s.length > 0);
64+
if (pathSegments.length > 1) {
65+
return {
66+
resolvedPath: normalizedPath,
67+
isExternalLibrary: false,
68+
extension: path.extname(normalizedPath),
69+
};
70+
}
6471
}
6572

6673
// Handle relative imports (./module, ../module)

0 commit comments

Comments
 (0)