Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workaround for windows x yarn users #93

Merged
merged 8 commits into from
Dec 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ package-lock.json
.turbo
.vercel
turbo
turbo.exe
.DS_Store
cache
.env
vendor/
dist
data
node_modules
turgo
packages/turbo-server/data/
packages/turbo-server/uploads/
packages/*/node_modules
Expand Down
9 changes: 4 additions & 5 deletions internal/cache/cache_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cache

import (
"fmt"
"path"
"path/filepath"
"turbo/internal/config"
"turbo/internal/fs"
Expand All @@ -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) {
Expand All @@ -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
}
Expand All @@ -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)
}
}
Expand Down
7 changes: 3 additions & 4 deletions internal/config/vercel_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"path"
"path/filepath"
"turbo/internal/fs"

Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package context
import (
"fmt"
"log"
"path"
"path/filepath"
"sort"
"strings"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions internal/fs/copy_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package fs

import (
"os"
"path"
"path/filepath"

"github.com/karrick/godirwalk"
)
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 3 additions & 2 deletions internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"os"
"path"
"path/filepath"
"strings"
"turbo/internal/util"

Expand All @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down
8 changes: 8 additions & 0 deletions internal/fs/iswin_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build !windows
// +build !windows

package fs

func CheckIfWindows() bool {
return false
}
8 changes: 8 additions & 0 deletions internal/fs/iswin_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build windows
// +build windows

package fs

func CheckIfWindows() bool {
return true
}
17 changes: 10 additions & 7 deletions internal/fs/lockfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
"regexp"
"strings"

Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand All @@ -102,23 +105,23 @@ 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
}
} else {
if contentsOfLock != nil {
err = yaml.Unmarshal(contentsOfLock, &prettyLockFile)
if err != nil {
return &YarnLockfile{}, err
return &YarnLockfile{}, fmt.Errorf("could not unmarshal yaml: %w", err)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/fs/package_deps_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"fmt"
"os/exec"
"path"
"path/filepath"
"regexp"
"strings"
"turbo/internal/util"
Expand Down Expand Up @@ -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...)
Expand Down
Loading