diff --git a/.github/workflows/ci-go.yml b/.github/workflows/ci-go.yml index 94f6ecaf33355..78a1cf89269ce 100644 --- a/.github/workflows/ci-go.yml +++ b/.github/workflows/ci-go.yml @@ -11,7 +11,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] steps: - name: Set up Go 1.x diff --git a/.gitignore b/.gitignore index 50ef8a60cb2ed..26b9c28cab537 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ package-lock.json .turbo .vercel turbo +turbo.exe .DS_Store cache .env @@ -14,7 +15,6 @@ vendor/ dist data node_modules -turgo packages/turbo-server/data/ packages/turbo-server/uploads/ packages/*/node_modules diff --git a/internal/cache/cache_fs.go b/internal/cache/cache_fs.go index 61dc6306e7f37..1ca040625f166 100644 --- a/internal/cache/cache_fs.go +++ b/internal/cache/cache_fs.go @@ -2,7 +2,6 @@ package cache import ( "fmt" - "path" "path/filepath" "turbo/internal/config" "turbo/internal/fs" @@ -22,7 +21,7 @@ func newFsCache(config *config.Config) Cache { // Fetch returns true if items are cached. It moves them into position as a side effect. func (f *fsCache) Fetch(target, hash string, _unusedOutputGlobs []string) (bool, []string, error) { - cachedFolder := path.Join(f.cacheDirectory, hash) + cachedFolder := filepath.Join(f.cacheDirectory, hash) // If it's not in the cache bail now if !fs.PathExists(cachedFolder) { @@ -32,7 +31,7 @@ func (f *fsCache) Fetch(target, hash string, _unusedOutputGlobs []string) (bool, // Otherwise, copy it into position err := fs.RecursiveCopyOrLinkFile(cachedFolder, target, fs.DirPermissions, true, true) if err != nil { - return false, nil, fmt.Errorf("error moving cache from artifact into %v: %w", target, err) + return false, nil, fmt.Errorf("error moving artifact from cache into %v: %w", target, err) } return true, nil, nil } @@ -48,11 +47,11 @@ func (f *fsCache) Put(target, hash string, files []string) error { return fmt.Errorf("error constructing relative path from %v to %v: %w", target, file, err) } if !fs.IsDirectory(file) { - if err := fs.EnsureDir(path.Join(f.cacheDirectory, hash, rel)); err != nil { + if err := fs.EnsureDir(filepath.Join(f.cacheDirectory, hash, rel)); err != nil { return fmt.Errorf("error ensuring directory file from cache: %w", err) } - if err := fs.CopyOrLinkFile(file, path.Join(f.cacheDirectory, hash, rel), fs.DirPermissions, fs.DirPermissions, true, true); err != nil { + if err := fs.CopyOrLinkFile(file, filepath.Join(f.cacheDirectory, hash, rel), fs.DirPermissions, fs.DirPermissions, true, true); err != nil { return fmt.Errorf("error copying file from cache: %w", err) } } diff --git a/internal/config/vercel_config.go b/internal/config/vercel_config.go index 2c54e3d7a8fa7..28de86a592952 100644 --- a/internal/config/vercel_config.go +++ b/internal/config/vercel_config.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io/ioutil" - "path" "path/filepath" "turbo/internal/fs" @@ -86,12 +85,12 @@ func GetVercelAuthConfig(customConfigPath string) (*VercelAuthConfig, error) { // for the original implementation. It tries to search find and then respect legacy // configuration directories func getConfigFilePath(filename string) (string, error) { - if vcDataDir, e := xdg.SearchDataFile(path.Join("com.vercel.cli", filename)); e != nil { - tempDir := path.Join(xdg.Home, ".now", filename) + if vcDataDir, e := xdg.SearchDataFile(filepath.Join("com.vercel.cli", filename)); e != nil { + tempDir := filepath.Join(xdg.Home, ".now", filename) if fs.IsDirectory(tempDir) { return tempDir, nil } else { - if nowDataDir, f := xdg.SearchDataFile(path.Join("now", filename)); f != nil { + if nowDataDir, f := xdg.SearchDataFile(filepath.Join("now", filename)); f != nil { return "", fmt.Errorf("config file %s found. Please login with `vercel login`", filename) } else { return nowDataDir, nil diff --git a/internal/context/context.go b/internal/context/context.go index 143f913b7457f..f7f278b044039 100644 --- a/internal/context/context.go +++ b/internal/context/context.go @@ -3,7 +3,6 @@ package context import ( "fmt" "log" - "path" "path/filepath" "sort" "strings" @@ -158,7 +157,7 @@ func WithGraph(rootpath string, config *config.Config) Option { } // this should go into the bacend abstraction - if c.Backend.Name == "nodejs-yarn" { + if c.Backend.Name == "nodejs-yarn" && !fs.CheckIfWindows() { lockfile, err := fs.ReadLockfile(config.Cache.Dir) if err != nil { return fmt.Errorf("yarn.lock: %w", err) @@ -190,7 +189,8 @@ func WithGraph(rootpath string, config *config.Config) Option { globalDeps.Add(val) } } - } else if c.Backend.Name != "nodejs-yarn" { + } + if c.Backend.Name != "nodejs-yarn" || fs.CheckIfWindows() { // If we are not in Yarn, add the specfile and lockfile to global deps globalDeps.Add(c.Backend.Specfile) globalDeps.Add(c.Backend.Lockfile) @@ -294,7 +294,7 @@ func (c *Context) loadPackageDepsHash(pkg *fs.PackageJSON) error { return err } - ignorePkg, err := safeCompileIgnoreFile(path.Join(pkg.Dir, ".gitignore")) + ignorePkg, err := safeCompileIgnoreFile(filepath.Join(pkg.Dir, ".gitignore")) if err != nil { return err } @@ -345,7 +345,7 @@ func (c *Context) ResolveWorkspaceRootDeps() (*fs.PackageJSON, error) { for dep, version := range pkg.PeerDependencies { pkg.UnresolvedExternalDeps[dep] = version } - if c.Backend.Name == "nodejs-yarn" { + if c.Backend.Name == "nodejs-yarn" && !fs.CheckIfWindows() { pkg.SubLockfile = make(fs.YarnLockfile) c.ResolveDepGraph(&lockfileWg, pkg.UnresolvedExternalDeps, depSet, seen, pkg) lockfileWg.Wait() @@ -461,7 +461,7 @@ func (c *Context) parsePackageJSON(fileName string) error { } func (c *Context) ResolveDepGraph(wg *sync.WaitGroup, unresolvedDirectDeps map[string]string, resolveDepsSet mapset.Set, seen mapset.Set, pkg *fs.PackageJSON) { - if c.Backend.Name != "nodejs-yarn" { + if fs.CheckIfWindows() || c.Backend.Name != "nodejs-yarn" { return } for directDepName, unresolvedVersion := range unresolvedDirectDeps { diff --git a/internal/fs/copy_file.go b/internal/fs/copy_file.go index 0a3ca43b7266f..d7eaeca703a28 100644 --- a/internal/fs/copy_file.go +++ b/internal/fs/copy_file.go @@ -2,7 +2,7 @@ package fs import ( "os" - "path" + "path/filepath" "github.com/karrick/godirwalk" ) @@ -52,7 +52,7 @@ func RecursiveCopyOrLinkFile(from string, to string, mode os.FileMode, link, fal } if info.IsDir() { return WalkMode(from, func(name string, isDir bool, fileMode os.FileMode) error { - dest := path.Join(to, name[len(from):]) + dest := filepath.Join(to, name[len(from):]) if isDir { return os.MkdirAll(dest, DirPermissions) } diff --git a/internal/fs/fs.go b/internal/fs/fs.go index a8e91ba729136..fa6f53413e468 100644 --- a/internal/fs/fs.go +++ b/internal/fs/fs.go @@ -7,6 +7,7 @@ import ( "log" "os" "path" + "path/filepath" "strings" "turbo/internal/util" @@ -20,7 +21,7 @@ const DirPermissions = os.ModeDir | 0775 // EnsureDir ensures that the directory of the given file has been created. func EnsureDir(filename string) error { - dir := path.Dir(filename) + dir := filepath.Dir(filename) err := os.MkdirAll(dir, DirPermissions) if err != nil && FileExists(dir) { // It looks like this is a file and not a directory. Attempt to remove it; this can @@ -103,7 +104,7 @@ func IsDirectory(path string) bool { // IsPackage returns true if the given directory name is a package (i.e. contains a build file) func IsPackage(buildFileNames []string, name string) bool { for _, buildFileName := range buildFileNames { - if FileExists(path.Join(name, buildFileName)) { + if FileExists(filepath.Join(name, buildFileName)) { return true } } diff --git a/internal/fs/iswin_other.go b/internal/fs/iswin_other.go new file mode 100644 index 0000000000000..5b880e9326fa4 --- /dev/null +++ b/internal/fs/iswin_other.go @@ -0,0 +1,8 @@ +//go:build !windows +// +build !windows + +package fs + +func CheckIfWindows() bool { + return false +} diff --git a/internal/fs/iswin_windows.go b/internal/fs/iswin_windows.go new file mode 100644 index 0000000000000..6f0128d77402e --- /dev/null +++ b/internal/fs/iswin_windows.go @@ -0,0 +1,8 @@ +//go:build windows +// +build windows + +package fs + +func CheckIfWindows() bool { + return true +} diff --git a/internal/fs/lockfile.go b/internal/fs/lockfile.go index 48d0947bd79e3..7bf0bdb49aa67 100644 --- a/internal/fs/lockfile.go +++ b/internal/fs/lockfile.go @@ -7,7 +7,7 @@ import ( "io" "io/ioutil" "os" - "path" + "path/filepath" "regexp" "strings" @@ -47,10 +47,12 @@ func ReadLockfile(cacheDir string) (*YarnLockfile, error) { var prettyLockFile = YarnLockfile{} hash, err := HashFile("yarn.lock") - contentsOfLock, err := ioutil.ReadFile(path.Join(cacheDir, fmt.Sprintf("%v-turbo-lock.yaml", hash))) + contentsOfLock, err := ioutil.ReadFile(filepath.Join(cacheDir, fmt.Sprintf("%v-turbo-lock.yaml", hash))) if err != nil { + contentsB, err := ioutil.ReadFile("yarn.lock") if err != nil { + fmt.Println("readfile") return nil, fmt.Errorf("yarn.lock: %w", err) } lines := strings.Split(string(contentsB), "\n") @@ -75,11 +77,12 @@ func ReadLockfile(cacheDir string) (*YarnLockfile, error) { next := a.ReplaceAllStringFunc(output, func(m string) string { parts := a.FindStringSubmatch(m) - return fmt.Sprintf("%v: %v", parts[1], parts[2]) + return fmt.Sprintf("%s: %s", parts[1], parts[2]) }) err = yaml.Unmarshal([]byte(next), &lockfile) if err != nil { + fmt.Println("unmarshal") return &YarnLockfile{}, err } // This final step is important, it splits any deps with multiple-resolutions @@ -102,15 +105,15 @@ func ReadLockfile(cacheDir string) (*YarnLockfile, error) { fmt.Println(err.Error()) return &YarnLockfile{}, err } - if err = EnsureDir(path.Join(cacheDir)); err != nil { + if err = EnsureDir(cacheDir); err != nil { fmt.Println(err.Error()) return &YarnLockfile{}, err } - if err = EnsureDir(path.Join(cacheDir, fmt.Sprintf("%v-turbo-lock.yaml", hash))); err != nil { + if err = EnsureDir(filepath.Join(cacheDir, fmt.Sprintf("%v-turbo-lock.yaml", hash))); err != nil { fmt.Println(err.Error()) return &YarnLockfile{}, err } - if err = ioutil.WriteFile(path.Join(cacheDir, fmt.Sprintf("%v-turbo-lock.yaml", hash)), []byte(better), 0644); err != nil { + if err = ioutil.WriteFile(filepath.Join(cacheDir, fmt.Sprintf("%v-turbo-lock.yaml", hash)), []byte(better), 0644); err != nil { fmt.Println(err.Error()) return &YarnLockfile{}, err } @@ -118,7 +121,7 @@ func ReadLockfile(cacheDir string) (*YarnLockfile, error) { if contentsOfLock != nil { err = yaml.Unmarshal(contentsOfLock, &prettyLockFile) if err != nil { - return &YarnLockfile{}, err + return &YarnLockfile{}, fmt.Errorf("could not unmarshal yaml: %w", err) } } } diff --git a/internal/fs/package_deps_hash.go b/internal/fs/package_deps_hash.go index 3afb123f65f54..23af9681b2d16 100644 --- a/internal/fs/package_deps_hash.go +++ b/internal/fs/package_deps_hash.go @@ -4,7 +4,7 @@ import ( "bytes" "fmt" "os/exec" - "path" + "path/filepath" "regexp" "strings" "turbo/internal/util" @@ -91,7 +91,7 @@ func GitHashForFiles(filesToHash []string, PackagePath string) (map[string]strin var input = []string{"hash-object"} for _, filename := range filesToHash { - input = append(input, path.Join(PackagePath, filename)) + input = append(input, filepath.Join(PackagePath, filename)) } // fmt.Println(input) cmd := exec.Command("git", input...) diff --git a/internal/prune/prune.go b/internal/prune/prune.go index 2327576f90646..b8eebaed4fbf4 100644 --- a/internal/prune/prune.go +++ b/internal/prune/prune.go @@ -6,7 +6,7 @@ import ( "io/ioutil" "log" "os" - "path" + "path/filepath" "strings" "sync" "turbo/internal/config" @@ -110,16 +110,16 @@ func (c *PruneCommand) Run(args []string) int { c.Config.Logger.Trace("external deps", "value", target.UnresolvedExternalDeps) c.Config.Logger.Trace("internal deps", "value", target.InternalDeps) c.Config.Logger.Trace("docker", "value", pruneOptions.docker) - c.Config.Logger.Trace("out dir", "value", path.Join(pruneOptions.cwd, "out")) + c.Config.Logger.Trace("out dir", "value", filepath.Join(pruneOptions.cwd, "out")) if ctx.Backend.Name != "nodejs-yarn" { c.logError(c.Config.Logger, "", fmt.Errorf("this command is not yet implemented for %s", ctx.Backend.Name)) return 1 } - logger.Printf("Generating pruned monorepo for %v in %v", ui.Bold(pruneOptions.scope), ui.Bold(path.Join(pruneOptions.cwd, "out"))) + logger.Printf("Generating pruned monorepo for %v in %v", ui.Bold(pruneOptions.scope), ui.Bold(filepath.Join(pruneOptions.cwd, "out"))) - err = fs.EnsureDir(path.Join(pruneOptions.cwd, "out", "package.json")) + err = fs.EnsureDir(filepath.Join(pruneOptions.cwd, "out", "package.json")) if err != nil { c.logError(c.Config.Logger, "", fmt.Errorf("could not create directory: %w", err)) return 1 @@ -166,8 +166,8 @@ func (c *PruneCommand) Run(args []string) int { } workspaces = append(workspaces, ctx.PackageInfos[internalDep].Dir) if pruneOptions.docker { - targetDir := path.Join(pruneOptions.cwd, "out", "full", ctx.PackageInfos[internalDep].Dir) - jsonDir := path.Join(pruneOptions.cwd, "out", "json", ctx.PackageInfos[internalDep].PackageJSONPath) + targetDir := filepath.Join(pruneOptions.cwd, "out", "full", ctx.PackageInfos[internalDep].Dir) + jsonDir := filepath.Join(pruneOptions.cwd, "out", "json", ctx.PackageInfos[internalDep].PackageJSONPath) if err := fs.EnsureDir(targetDir); err != nil { c.logError(c.Config.Logger, "", fmt.Errorf("Failed to create folder %v for %v: %w", targetDir, internalDep, err)) return 1 @@ -185,7 +185,7 @@ func (c *PruneCommand) Run(args []string) int { return 1 } } else { - targetDir := path.Join(pruneOptions.cwd, "out", ctx.PackageInfos[internalDep].Dir) + targetDir := filepath.Join(pruneOptions.cwd, "out", ctx.PackageInfos[internalDep].Dir) if err := fs.EnsureDir(targetDir); err != nil { c.logError(c.Config.Logger, "", fmt.Errorf("Failed to create folder %v for %v: %w", targetDir, internalDep, err)) return 1 @@ -205,29 +205,29 @@ func (c *PruneCommand) Run(args []string) int { c.Config.Logger.Trace("new worksapces", "value", workspaces) if pruneOptions.docker { if fs.FileExists(".gitignore") { - if err := fs.CopyFile(".gitignore", path.Join(pruneOptions.cwd, "out", "full", ".gitignore"), fs.DirPermissions); err != nil { + if err := fs.CopyFile(".gitignore", filepath.Join(pruneOptions.cwd, "out", "full", ".gitignore"), fs.DirPermissions); err != nil { c.logError(c.Config.Logger, "", fmt.Errorf("Failed to copy root .gitignore: %w", err)) return 1 } } - if err := fs.CopyFile("package.json", path.Join(pruneOptions.cwd, "out", "full", "package.json"), fs.DirPermissions); err != nil { + if err := fs.CopyFile("package.json", filepath.Join(pruneOptions.cwd, "out", "full", "package.json"), fs.DirPermissions); err != nil { c.logError(c.Config.Logger, "", fmt.Errorf("Failed to copy root package.json: %w", err)) return 1 } - if err := fs.CopyFile("package.json", path.Join(pruneOptions.cwd, "out", "json", "package.json"), fs.DirPermissions); err != nil { + if err := fs.CopyFile("package.json", filepath.Join(pruneOptions.cwd, "out", "json", "package.json"), fs.DirPermissions); err != nil { c.logError(c.Config.Logger, "", fmt.Errorf("Failed to copy root package.json: %w", err)) return 1 } } else { if fs.FileExists(".gitignore") { - if err := fs.CopyFile(".gitignore", path.Join(pruneOptions.cwd, "out", ".gitignore"), fs.DirPermissions); err != nil { + if err := fs.CopyFile(".gitignore", filepath.Join(pruneOptions.cwd, "out", ".gitignore"), fs.DirPermissions); err != nil { c.logError(c.Config.Logger, "", fmt.Errorf("Failed to copy root .gitignore: %w", err)) return 1 } } - if err := fs.CopyFile("package.json", path.Join(pruneOptions.cwd, "out", "package.json"), fs.DirPermissions); err != nil { + if err := fs.CopyFile("package.json", filepath.Join(pruneOptions.cwd, "out", "package.json"), fs.DirPermissions); err != nil { c.logError(c.Config.Logger, "", fmt.Errorf("Failed to copy root package.json: %w", err)) return 1 } @@ -238,19 +238,19 @@ func (c *PruneCommand) Run(args []string) int { c.logError(c.Config.Logger, "", fmt.Errorf("Failed to materialize sub-lockfile. This can happen if your lockfile contains merge conflicts or is somehow corrupted. Please report this if it occurs: %w", err)) return 1 } - err = ioutil.WriteFile(path.Join(pruneOptions.cwd, "out", "yarn.lock"), next, fs.DirPermissions) + err = ioutil.WriteFile(filepath.Join(pruneOptions.cwd, "out", "yarn.lock"), next, fs.DirPermissions) if err != nil { c.logError(c.Config.Logger, "", fmt.Errorf("Failed to write sub-lockfile: %w", err)) return 1 } // because of yarn being yarn, we need to inject lines in between each block of YAML to make it "valid" syml - f, err := os.Open(path.Join(path.Join(pruneOptions.cwd, "out", "yarn.lock"))) + f, err := os.Open(filepath.Join(filepath.Join(pruneOptions.cwd, "out", "yarn.lock"))) if err != nil { c.logError(c.Config.Logger, "", fmt.Errorf("Failed to massage lockfile: %w", err)) } defer f.Close() - output, err := os.Create(path.Join(pruneOptions.cwd, "out", "yarn-tmp.lock")) + output, err := os.Create(filepath.Join(pruneOptions.cwd, "out", "yarn-tmp.lock")) writer := bufio.NewWriter(output) if err != nil { c.logError(c.Config.Logger, "", fmt.Errorf("Failed create tempory lockfile: %w", err)) @@ -271,7 +271,7 @@ func (c *PruneCommand) Run(args []string) int { } writer.Flush() // make sure to flush the log write before we start saving it. - err = os.Rename(path.Join(pruneOptions.cwd, "out", "yarn-tmp.lock"), path.Join(pruneOptions.cwd, "out", "yarn.lock")) + err = os.Rename(filepath.Join(pruneOptions.cwd, "out", "yarn-tmp.lock"), filepath.Join(pruneOptions.cwd, "out", "yarn.lock")) if err != nil { c.logError(c.Config.Logger, "", fmt.Errorf("Failed finalize lockfile: %w", err)) } diff --git a/internal/run/run.go b/internal/run/run.go index af090b7ea790c..f1789278947a1 100644 --- a/internal/run/run.go +++ b/internal/run/run.go @@ -148,13 +148,7 @@ func (c *RunCommand) Run(args []string) int { hasRepoGlobalFileChanged := false var changedFiles []string if runOptions.since != "" { - changedFilesRelativeToGitRoot := git.ChangedFiles(runOptions.since, true, "") - // We need to convert relative path of changed files to git root, to relative path to cwd - for _, f := range changedFilesRelativeToGitRoot { - repoRoot := filepath.Dir(gitRepoRoot) - pathToTarget := filepath.Join(repoRoot, f) - changedFiles = append(changedFiles, strings.Replace(pathToTarget, cwd+"/", "", 1)) - } + changedFiles = git.ChangedFiles(runOptions.since, true, cwd) } ignoreSet := make(util.Set) @@ -432,8 +426,8 @@ func (c *RunCommand) Run(args []string) int { targetUi.Error(fmt.Sprintf("Hashing error: %v", err)) // @TODO probably should abort fatally??? } - logFileName := path.Join(pack.Dir, ".turbo", fmt.Sprintf("turbo-%v.log", task)) - targetLogger.Debug("log file", "path", path.Join(runOptions.cwd, logFileName)) + logFileName := filepath.Join(pack.Dir, ".turbo", fmt.Sprintf("turbo-%v.log", task)) + targetLogger.Debug("log file", "path", filepath.Join(runOptions.cwd, logFileName)) // Cache --------------------------------------------- // We create the real task outputs now so we can potentially use them to @@ -454,7 +448,7 @@ func (c *RunCommand) Run(args []string) int { if err != nil { targetUi.Error(fmt.Sprintf("error fetching from cache: %s", err)) } else if hit { - if runOptions.stream && fs.FileExists(path.Join(runOptions.cwd, logFileName)) { + if runOptions.stream && fs.FileExists(filepath.Join(runOptions.cwd, logFileName)) { logReplayWaitGroup.Add(1) targetUi.Output(fmt.Sprintf("cache hit, replaying output %s", ui.Dim(hash))) go replayLogs(targetLogger, targetUi, runOptions, logFileName, hash, &logReplayWaitGroup, false) @@ -465,9 +459,16 @@ func (c *RunCommand) Run(args []string) int { } } // Setup log file - fs.EnsureDir(logFileName) - output, err := os.Create(path.Join(runOptions.cwd, logFileName)) + if err := fs.EnsureDir(filepath.Join(runOptions.cwd, pack.Dir, ".turbo", fmt.Sprintf("turbo-%v.log", task))); err != nil { + tracer(TargetBuildFailed, err) + c.logError(targetLogger, actualPrefix, err) + if runOptions.bail { + os.Exit(1) + } + } + output, err := os.Create(filepath.Join(runOptions.cwd, pack.Dir, ".turbo", fmt.Sprintf("turbo-%v.log", task))) if err != nil { + fmt.Println("here") tracer(TargetBuildFailed, err) c.logError(targetLogger, actualPrefix, err) if runOptions.bail { @@ -549,7 +550,7 @@ func (c *RunCommand) Run(args []string) int { targetUi.Error(fmt.Sprintf("Error: command finished with error: %s", err)) os.Exit(1) } else { - f, err := os.Open(path.Join(runOptions.cwd, logFileName)) + f, err := os.Open(filepath.Join(runOptions.cwd, logFileName)) if err != nil { targetUi.Warn(fmt.Sprintf("failed reading logs: %v", err)) } @@ -578,7 +579,7 @@ func (c *RunCommand) Run(args []string) int { targetLogger.Debug("caching output", "outputs", outputs) var filesToBeCached = make(util.Set) for _, output := range outputs { - results, err := doublestar.Glob(path.Join(pack.Dir, strings.TrimPrefix(output, "!"))) + results, err := doublestar.Glob(filepath.Join(pack.Dir, strings.TrimPrefix(output, "!"))) if err != nil { targetUi.Error(fmt.Sprintf("Could not find output artifacts in %v, likely invalid glob %v: %s", pack.Dir, output, err)) } @@ -802,7 +803,7 @@ func parseRunArgs(args []string, cwd string) (*RunOptions, error) { } // We can only set this cache folder after we know actual cwd - runOptions.cacheFolder = path.Join(runOptions.cwd, unresolvedCacheFolder) + runOptions.cacheFolder = filepath.Join(runOptions.cwd, unresolvedCacheFolder) return runOptions, nil } @@ -882,7 +883,7 @@ func hasGraphViz() bool { func replayLogs(logger hclog.Logger, prefixUi cli.Ui, runOptions *RunOptions, logFileName, hash string, wg *sync.WaitGroup, silent bool) { defer wg.Done() logger.Debug("start replaying logs") - f, err := os.Open(path.Join(runOptions.cwd, logFileName)) + f, err := os.Open(filepath.Join(runOptions.cwd, logFileName)) if err != nil && !silent { prefixUi.Warn(fmt.Sprintf("error reading logs: %v", err)) logger.Error(fmt.Sprintf("error reading logs: %v", err.Error())) diff --git a/internal/run/run_test.go b/internal/run/run_test.go index 5fc431c91df14..a139f3cc2686c 100644 --- a/internal/run/run_test.go +++ b/internal/run/run_test.go @@ -2,6 +2,7 @@ package run import ( "fmt" + "path/filepath" "testing" "turbo/internal/context" "turbo/internal/util" @@ -28,7 +29,7 @@ func TestParseConfig(t *testing.T) { cache: true, forceExecution: false, profile: "", - cacheFolder: "node_modules/.cache/turbo", + cacheFolder: filepath.FromSlash("node_modules/.cache/turbo"), }, }, { @@ -45,7 +46,7 @@ func TestParseConfig(t *testing.T) { forceExecution: false, profile: "", cwd: "zop", - cacheFolder: "zop/node_modules/.cache/turbo", + cacheFolder: filepath.FromSlash("zop/node_modules/.cache/turbo"), }, }, { @@ -62,7 +63,7 @@ func TestParseConfig(t *testing.T) { forceExecution: false, profile: "", scope: []string{"foo", "blah"}, - cacheFolder: "node_modules/.cache/turbo", + cacheFolder: filepath.FromSlash("node_modules/.cache/turbo"), }, }, { @@ -78,7 +79,7 @@ func TestParseConfig(t *testing.T) { cache: true, forceExecution: false, profile: "", - cacheFolder: "node_modules/.cache/turbo", + cacheFolder: filepath.FromSlash("node_modules/.cache/turbo"), }, }, { @@ -94,7 +95,7 @@ func TestParseConfig(t *testing.T) { cache: true, forceExecution: false, profile: "", - cacheFolder: "node_modules/.cache/turbo", + cacheFolder: filepath.FromSlash("node_modules/.cache/turbo"), }, }, { @@ -110,7 +111,7 @@ func TestParseConfig(t *testing.T) { cache: true, forceExecution: false, profile: "", - cacheFolder: "node_modules/.cache/turbo", + cacheFolder: filepath.FromSlash("node_modules/.cache/turbo"), passThroughArgs: []string{"--boop", "zoop"}, }, }, @@ -127,7 +128,7 @@ func TestParseConfig(t *testing.T) { cache: true, forceExecution: false, profile: "", - cacheFolder: "node_modules/.cache/turbo", + cacheFolder: filepath.FromSlash("node_modules/.cache/turbo"), passThroughArgs: []string{}, }, }, diff --git a/internal/scm/git.go b/internal/scm/git.go index 50544db7f7ada..590aa2e5445d4 100644 --- a/internal/scm/git.go +++ b/internal/scm/git.go @@ -8,7 +8,6 @@ import ( "log" "os" "os/exec" - "path" "path/filepath" "strconv" "strings" @@ -101,7 +100,7 @@ func (g *git) ChangedFiles(fromCommit string, includeUntracked bool, relativeTo } func (g *git) fixGitRelativePath(worktreePath, relativeTo string) string { - p, err := filepath.Rel(relativeTo, path.Join(g.repoRoot, worktreePath)) + p, err := filepath.Rel(relativeTo, filepath.Join(g.repoRoot, worktreePath)) if err != nil { log.Fatalf("unable to determine relative path for %s and %s", g.repoRoot, relativeTo) } diff --git a/internal/scm/scm.go b/internal/scm/scm.go index 32db1c108f7bc..c8eefc9e3d795 100644 --- a/internal/scm/scm.go +++ b/internal/scm/scm.go @@ -5,7 +5,7 @@ package scm import ( "fmt" "log" - "path" + "path/filepath" "turbo/internal/fs" ) @@ -35,7 +35,7 @@ type SCM interface { // New returns a new SCM instance for this repo root. // It returns nil if there is no known implementation there. func New(repoRoot string) SCM { - if fs.PathExists(path.Join(repoRoot, ".git")) { + if fs.PathExists(filepath.Join(repoRoot, ".git")) { return &git{repoRoot: repoRoot} } return nil diff --git a/internal/ui/term/cursor_test.go b/internal/ui/term/cursor_test.go index f0607c5eae5a5..270ebe8b9fcbb 100644 --- a/internal/ui/term/cursor_test.go +++ b/internal/ui/term/cursor_test.go @@ -1,6 +1,8 @@ +//go:build !windows +// +build !windows + // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 - package cursor import ( diff --git a/scripts/e2e/e2e.ts b/scripts/e2e/e2e.ts index d74232c4a6c1c..bc5b6471c0aaa 100644 --- a/scripts/e2e/e2e.ts +++ b/scripts/e2e/e2e.ts @@ -59,9 +59,15 @@ function runSmokeTests( assert.ok(!!chash, "No hash for c:test"); const splitMessage = chash.split(" "); const hash = splitMessage[splitMessage.length - 1]; - const logFilePath = `${ - repo.subdir ? repo.subdir + "/" : "" - }node_modules/.cache/turbo/${hash}/.turbo/turbo-test.log`; + const logFilePath = path.join( + repo.subdir ? repo.subdir + "/" : "", + "node_modules", + ".cache", + "turbo", + hash, + ".turbo", + "turbo-test.log" + ); let text = ""; assert.not.throws(() => { text = repo.readFileSync(logFilePath); @@ -70,7 +76,7 @@ function runSmokeTests( assert.ok(text.includes("testing c"), "Contains correct output"); repo.newBranch("my-feature-branch"); repo.commitFiles({ - [`packages/a/test.js`]: `console.log('testingz a');`, + [path.join("packages", "a", "test.js")]: `console.log('testingz a');`, }); const sinceResults = repo.turbo( diff --git a/scripts/monorepo.ts b/scripts/monorepo.ts index 13bb26b731f37..a242d9f7b1f5c 100644 --- a/scripts/monorepo.ts +++ b/scripts/monorepo.ts @@ -156,7 +156,20 @@ importers: addPackage(name, internalDeps = []) { return this.commitFiles({ - [`packages/${name}/build.js`]: `console.log('building ${name}');`, + [`packages/${name}/build.js`]: ` +const fs = require('fs'); +const path = require('path'); +console.log('building ${name}'); + +if (!fs.existsSync(path.join(__dirname, 'dist'))){ + fs.mkdirSync(path.join(__dirname, 'dist')); +} + +fs.copyFileSync( + path.join(__dirname, 'build.js'), + path.join(__dirname, 'dist', 'build.js') +); +`, [`packages/${name}/test.js`]: `console.log('testing ${name}');`, [`packages/${name}/lint.js`]: `console.log('linting ${name}');`, [`packages/${name}/package.json`]: { @@ -164,8 +177,7 @@ importers: version: "0.1.0", license: "MIT", scripts: { - build: - "node ./build.js && mkdir -p dist && cp build.js dist/build.js;", + build: "node ./build.js", test: "node ./test.js", lint: "node ./lint.js", },