aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cli/internal/util/backends.go
blob: 66941ad71839e01365538e1bbf86de766c4f3aad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package util

import (
	"fmt"
	"io/ioutil"
	"path/filepath"

	"github.com/vercel/turbo/cli/internal/yaml"
)

// YarnRC Represents contents of .yarnrc.yml
type YarnRC struct {
	NodeLinker string `yaml:"nodeLinker"`
}

// IsNMLinker Checks that Yarn is set to use the node-modules linker style
func IsNMLinker(cwd string) (bool, error) {
	yarnRC := &YarnRC{}

	bytes, err := ioutil.ReadFile(filepath.Join(cwd, ".yarnrc.yml"))
	if err != nil {
		return false, fmt.Errorf(".yarnrc.yml: %w", err)
	}

	if yaml.Unmarshal(bytes, yarnRC) != nil {
		return false, fmt.Errorf(".yarnrc.yml: %w", err)
	}

	return yarnRC.NodeLinker == "node-modules", nil
}