This commit is contained in:
parent
f2ebcf560f
commit
b95d2954ba
5 changed files with 77 additions and 30 deletions
27
cli/main.go
27
cli/main.go
|
|
@ -28,17 +28,38 @@ type DirectoryResolver struct {
|
|||
directories []string
|
||||
}
|
||||
|
||||
func (r *DirectoryResolver) Resolve(path string) (string, error) {
|
||||
func (r *DirectoryResolver) Resolve(from, path string) (*core.ImportResult, error) {
|
||||
// relative imports
|
||||
relpath := filepath.Join(filepath.Dir(from), path)
|
||||
if f, err := os.ReadFile(relpath); err == nil {
|
||||
return &core.ImportResult{
|
||||
Source: string(f),
|
||||
Path: relpath,
|
||||
}, nil
|
||||
}
|
||||
|
||||
for _, d := range r.directories {
|
||||
pth := filepath.Join(d, path)
|
||||
f, err := os.ReadFile(pth)
|
||||
|
||||
if err == nil {
|
||||
return string(f), nil
|
||||
return &core.ImportResult{
|
||||
Source: string(f),
|
||||
Path: pth,
|
||||
}, nil
|
||||
}
|
||||
|
||||
pth = filepath.Join(pth, "main.ang")
|
||||
f, err = os.ReadFile(pth)
|
||||
if err == nil {
|
||||
return &core.ImportResult{
|
||||
Source: string(f),
|
||||
Path: pth,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", errors.New("couldn't resolve import")
|
||||
return nil, errors.New("couldn't resolve import")
|
||||
}
|
||||
|
||||
func (r *DirectoryResolver) IsSame(a, b string) bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue