From 8936a99a52acfe43815010f768a693345e24a919 Mon Sep 17 00:00:00 2001 From: Ifuhao <34829055+Ifuhao@users.noreply.github.com> Date: Wed, 20 Sep 2023 14:23:39 +0800 Subject: [PATCH] =?UTF-8?q?[FIX]=E4=BF=AE=E5=A4=8D=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E5=88=86=E9=9A=94=E7=AC=A6=E5=9C=A8=E4=B8=8D=E5=90=8C=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E7=B3=BB=E7=BB=9F=E4=B8=AD=E7=9A=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=20(#9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/detector.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/detector.go b/core/detector.go index 69747a4..dbdd8ea 100644 --- a/core/detector.go +++ b/core/detector.go @@ -135,7 +135,7 @@ func (c *CyclicDetector) Parse() error { } c.AbsPath = abs - c.RootPath = abs[strings.LastIndex(abs, "/")+1:] + c.RootPath = abs[strings.LastIndex(abs, string(os.PathSeparator))+1:] c.ModuleName = modFile.Module.Mod.Path if err = c.ParseFilters(c.SourceFilter); err != nil { @@ -196,7 +196,8 @@ func (c *CyclicDetector) ParseNodeResolver(path string) ([]*NodeResolver, error) continue } for _, imp := range value.Imports { - importValues[key] = append(importValues[key], imp.Path.Value[1:len(imp.Path.Value)-1]) + impPathValue := imp.Path.Value[1 : len(imp.Path.Value)-1] + importValues[key] = append(importValues[key], strings.ReplaceAll(impPathValue, "/", string(os.PathSeparator))) } relFilePath := strings.ReplaceAll(filePath, c.AbsPath, "") nodeResolvers = append(nodeResolvers, &NodeResolver{ @@ -227,11 +228,11 @@ func (c *CyclicDetector) ParseNodeResolver(path string) ([]*NodeResolver, error) } func GetNodePathName(content string) (filePath, nodeName string) { - contains := strings.Contains(content, "/") + contains := strings.Contains(content, string(os.PathSeparator)) if !contains { return content, content } - index := strings.LastIndex(content, "/") + index := strings.LastIndex(content, string(os.PathSeparator)) return content[:index], content[index+1:] } @@ -250,7 +251,7 @@ func (c *CyclicDetector) buildNodeRelation() ([][]*NodeResolver, map[string]int) for _, node := range c.NodeResolvers { depends := make([][]*NodeResolver, 0) for _, in := range node.ImportValues { - subPkg := in[strings.LastIndex(in, "/")+1:] + subPkg := in[strings.LastIndex(in, string(os.PathSeparator))+1:] pkgs := c.NodePackageMap[in] pkgMap := make(map[string]int, 0) simple := true