func relativeToContextRootFn()

in sg/internal/source/fs.go [33:48]


func relativeToContextRootFn(contextRoot string) func(string) string {
	if contextRoot == "" {
		return func(path string) string {
			return path
		}
	}

	return func(s string) string {
		rel, err := filepath.Rel(contextRoot, s)
		if err != nil {
			// NOTE: we don't expect this as we guard this in loadSourceFromPaths.
			panic(fmt.Sprintf("path %q is not relative to context root %q", s, contextRoot))
		}
		return rel
	}
}