-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(functions): always resolve absolute path in container
- Loading branch information
1 parent
1639067
commit f262424
Showing
2 changed files
with
13 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -278,37 +278,32 @@ func resolveHostPath(hostPath string, fsys afero.Fs) string { | |
if filepath.IsAbs(hostPath) { | ||
return getModulePath(hostPath) | ||
} | ||
cwd, err := os.Getwd() | ||
if err != nil { | ||
return hostPath | ||
} | ||
rel := filepath.Join(FunctionsDir, hostPath) | ||
if strings.HasPrefix(rel, FunctionsDir) { | ||
return hostPath | ||
} | ||
rebased := filepath.Join(cwd, rel) | ||
exists, err := afero.Exists(fsys, rebased) | ||
exists, err := afero.Exists(fsys, rel) | ||
if err != nil { | ||
logger := GetDebugLogger() | ||
fmt.Fprintln(logger, err) | ||
} | ||
if !exists { | ||
return hostPath | ||
} | ||
if strings.HasPrefix(rel, FunctionsDir) { | ||
suffix := strings.TrimPrefix(rel, FunctionsDir) | ||
return path.Join(DockerFuncDirPath, filepath.ToSlash(suffix)) | ||
} | ||
// Directory imports need to be suffixed with / | ||
// Ref: https://deno.com/[email protected]/basics/import_maps | ||
if strings.HasSuffix(hostPath, "/") { | ||
rel += "/" | ||
if strings.HasSuffix(hostPath, string(filepath.Separator)) { | ||
rel += string(filepath.Separator) | ||
} | ||
return getModulePath(rel) | ||
} | ||
|
||
func getModulePath(hostPath string) string { | ||
mod := path.Join(DockerModsDir, GetPathHash(hostPath)) | ||
if strings.HasSuffix(hostPath, "/") { | ||
if strings.HasSuffix(hostPath, string(filepath.Separator)) { | ||
mod += "/" | ||
} | ||
if ext := filepath.Ext(hostPath); len(ext) > 0 { | ||
} else if ext := filepath.Ext(hostPath); len(ext) > 0 { | ||
mod += ext | ||
} | ||
return mod | ||
|
This file contains 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