Fix ts_auto_deps to run on Windows

We must convert backslashes before comparing paths with canonical ones.

See #269

PiperOrigin-RevId: 213634618
diff --git a/ts_auto_deps/analyze/analyze.go b/ts_auto_deps/analyze/analyze.go
index b9ad5fe..04a8f57 100644
--- a/ts_auto_deps/analyze/analyze.go
+++ b/ts_auto_deps/analyze/analyze.go
@@ -338,7 +338,7 @@
 	for i, src := range srcs {
 		_, pkg, file := edit.ParseLabel(src)
 		// TODO(jdhamlik): Handle generated files.
-		srcs[i] = filepath.Clean(filepath.Join(pkg, file))
+		srcs[i] = platform.Normalize(filepath.Clean(filepath.Join(pkg, file)))
 	}
 	return srcs, nil
 }
diff --git a/ts_auto_deps/analyze/imports.go b/ts_auto_deps/analyze/imports.go
index f11d78a..28f6501 100644
--- a/ts_auto_deps/analyze/imports.go
+++ b/ts_auto_deps/analyze/imports.go
@@ -7,6 +7,7 @@
 	"strings"
 	"sync"
 
+	"github.com/bazelbuild/rules_typescript/ts_auto_deps/platform"
 	"github.com/bazelbuild/rules_typescript/ts_auto_deps/workspace"
 )
 
@@ -33,7 +34,7 @@
 	if strings.HasPrefix(i.importPath, "./") || strings.HasPrefix(i.importPath, "../") {
 		// If the import is relative to the source location, use the source
 		// location to form a "canonical" path from the root.
-		return filepath.Clean(filepath.Join(filepath.Dir(i.location.sourcePath), i.importPath))
+		return platform.Normalize(filepath.Clean(filepath.Join(filepath.Dir(i.location.sourcePath), i.importPath)))
 	} else if trim := strings.TrimPrefix(i.importPath, workspace.Name()+"/"); trim != i.importPath {
 		return trim
 	}
diff --git a/ts_auto_deps/analyze/loader.go b/ts_auto_deps/analyze/loader.go
index 96ecb4c..0308267 100644
--- a/ts_auto_deps/analyze/loader.go
+++ b/ts_auto_deps/analyze/loader.go
@@ -10,6 +10,7 @@
 	"time"
 
 	"github.com/bazelbuild/buildtools/edit"
+	"github.com/bazelbuild/rules_typescript/ts_auto_deps/platform"
 	"github.com/bazelbuild/rules_typescript/ts_auto_deps/workspace"
 	"github.com/golang/protobuf/proto"
 
@@ -376,7 +377,7 @@
 		return imported
 	}
 	_, pkg, _ := edit.ParseLabel(label)
-	return filepath.Join(pkg, moduleRoot, trim)
+	return platform.Normalize(filepath.Join(pkg, moduleRoot, trim))
 }
 
 // parsePackageName parses and returns the scope and package of imported. For
diff --git a/ts_auto_deps/platform/file.go b/ts_auto_deps/platform/file.go
index beb7e3f..493b35e 100644
--- a/ts_auto_deps/platform/file.go
+++ b/ts_auto_deps/platform/file.go
@@ -5,12 +5,15 @@
 	"io/ioutil"
 	"os"
 	"path/filepath"
+	"strings"
 )
 
 const (
 	filePerms = 0666
 )
 
+var pathReplacer = strings.NewReplacer("\\", "/")
+
 // ReadFile reads the contents of name.
 func ReadFile(ctx context.Context, name string) ([]byte, error) {
 	return ioutil.ReadFile(name)
@@ -30,3 +33,8 @@
 func Glob(ctx context.Context, pattern string) ([]string, error) {
 	return filepath.Glob(pattern)
 }
+
+// Normalize converts Windows path separators into POSIX
+func Normalize(path string) string {
+	return pathReplacer.Replace(path)
+}
diff --git a/ts_auto_deps/updater/updater.go b/ts_auto_deps/updater/updater.go
index dc1a7e6..a866e85 100644
--- a/ts_auto_deps/updater/updater.go
+++ b/ts_auto_deps/updater/updater.go
@@ -195,17 +195,18 @@
 		return nil, err
 	}
 	g3Path, err := filepath.Rel(workspaceRoot, absPath)
+	normalizedG3Path := platform.Normalize(g3Path)
 	if err != nil {
 		return nil, fmt.Errorf("failed to resolve workspace relative path: %s", err)
 	}
 	data, err := platform.ReadFile(ctx, buildFilePath)
 	if err != nil {
 		if os.IsNotExist(err) {
-			return &build.File{Path: g3Path, Build: true}, nil
+			return &build.File{Path: normalizedG3Path, Build: true}, nil
 		}
 		return nil, fmt.Errorf("reading %q: %s", buildFilePath, err)
 	}
-	return build.ParseBuild(g3Path, data)
+	return build.ParseBuild(normalizedG3Path, data)
 }
 
 type srcSet map[string]bool
@@ -755,7 +756,7 @@
 		}
 		return ruleName
 	}
-	pkg := filepath.Dir(bld.Path)
+	pkg := platform.Normalize(filepath.Dir(bld.Path))
 	return fmt.Sprintf("//%s:%s", pkg, strings.TrimPrefix(ruleName, ":"))
 }
 
@@ -1032,7 +1033,7 @@
 	}
 	var newPaths []string
 	for k := range fileSet {
-		newPaths = append(newPaths, k)
+		newPaths = append(newPaths, platform.Normalize(k))
 	}
 	return newPaths
 }