loader: support imports from vendor directories

This fixes https://github.com/tinygo-org/tinygo/issues/1518.
Этот коммит содержится в:
Ayke van Laethem 2021-01-21 15:38:15 +01:00 коммит произвёл Ron Evans
родитель a5e2b27884
коммит 36db75b366

Просмотреть файл

@ -52,7 +52,8 @@ type PackageJSON struct {
CFiles []string CFiles []string
// Dependency information // Dependency information
Imports []string Imports []string
ImportMap map[string]string
// Error information // Error information
Error *struct { Error *struct {
@ -411,6 +412,9 @@ func (p *Package) Import(to string) (*types.Package, error) {
if to == "unsafe" { if to == "unsafe" {
return types.Unsafe, nil return types.Unsafe, nil
} }
if newTo, ok := p.ImportMap[to]; ok && !strings.HasSuffix(newTo, ".test]") {
to = newTo
}
if imported, ok := p.program.Packages[to]; ok { if imported, ok := p.program.Packages[to]; ok {
return imported.Pkg, nil return imported.Pkg, nil
} else { } else {