这是indexloc提供的服务,不要输入任何密码
Skip to content

Add yarn berry node_modules linker, CRLF/LF, and update prune #544

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

Merged
merged 29 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
14663a4
fix: cleanup + yarn berry
samchouse Jan 11, 2022
bc07300
fix: fix some bugs
samchouse Jan 11, 2022
d75b34f
fix: more cleanup
samchouse Jan 11, 2022
5092fbb
berry e2e
samchouse Jan 11, 2022
e84ccf0
fix: staticcheck
samchouse Jan 11, 2022
7986017
fix: requested changes
samchouse Jan 11, 2022
73d352b
fix: add iswin_other.go back
samchouse Jan 12, 2022
bf7d683
fix: crlf on unix and lf on windows
samchouse Jan 12, 2022
f27701a
fix: fix some requested changes
samchouse Jan 12, 2022
a17f6c7
fix: requested changes
samchouse Jan 12, 2022
91158bb
fix: forgot to remove this
samchouse Jan 12, 2022
1d4635c
fix: prune command support for yarn berry
samchouse Jan 12, 2022
65259f1
docs: update docs
samchouse Jan 12, 2022
c4e94a7
fix: requested changes
samchouse Jan 12, 2022
fcb10a9
fix: better backend checks
samchouse Jan 13, 2022
ea3221a
fix: update action file
samchouse Jan 13, 2022
a489b38
fix: update node install
samchouse Jan 13, 2022
ef6d0bd
fix: fixed ci :D
samchouse Jan 13, 2022
97992bd
feat: compat check
samchouse Jan 13, 2022
6f2a689
fix: requested changes
samchouse Jan 13, 2022
8b1d3be
fix: error out
samchouse Jan 13, 2022
8aa5a56
ci: fix
samchouse Jan 13, 2022
138066e
Merge branch 'main' into main
jaredpalmer Jan 13, 2022
d85b787
Update cli/internal/backends/nodejs/nodejs.go
samchouse Jan 13, 2022
21a4ca3
Update cli/internal/backends/nodejs/nodejs.go
jaredpalmer Jan 13, 2022
ef5d3be
Update cli/internal/backends/nodejs/nodejs.go
jaredpalmer Jan 13, 2022
b1df6d1
Update cli/internal/backends/nodejs/nodejs.go
jaredpalmer Jan 13, 2022
883efe8
Update cli/internal/context/context.go
jaredpalmer Jan 13, 2022
1b49254
Update cli/internal/backends/nodejs/nodejs.go
jaredpalmer Jan 13, 2022
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/ISSUE_TEMPLATE/-bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ body:
- npm
- pnpm
- Yarn v1
- Yarn v2/v3 (not supported)
- Yarn v2/v3 (node_modules linker only)
validations:
required: true
- type: dropdown
Expand Down
41 changes: 25 additions & 16 deletions .github/workflows/ci-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ jobs:
os: [ubuntu-latest, macos-latest]

steps:
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 2

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.17.5
id: go

- name: Setup Node.js environment
uses: actions/setup-node@v1.4.4
uses: actions/setup-node@v2
with:
cache: yarn
cache-dependency-path: yarn.lock
node-version: 14

- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 2
node-version: 16

- name: Build & Unit Test
run: yarn turbo run test --scope=cli
Expand All @@ -57,23 +57,23 @@ jobs:
os: [windows-latest]

steps:
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 2

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.17.5
id: wingo

- name: Setup Node.js environment
uses: actions/setup-node@v1.4.4
uses: actions/setup-node@v2
with:
cache: yarn
cache-dependency-path: yarn.lock
node-version: 14

- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 2
node-version: 16

- name: go test
run: cd cli && go test ./cmd/... ./internal/...
Expand Down Expand Up @@ -105,6 +105,15 @@ jobs:
os: [ubuntu-latest, macos-latest]

steps:
- name: Install Sponge
shell: bash
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get install -y moreutils
else
brew install moreutils
fi

- name: Check out code
uses: actions/checkout@v2
with:
Expand All @@ -117,11 +126,11 @@ jobs:
id: go

- name: Setup Node.js environment
uses: actions/setup-node@v2.5.0
uses: actions/setup-node@v2
with:
cache: yarn
cache-dependency-path: yarn.lock
node-version: 14.x
node-version: 16

- run: npm i -g pnpm

Expand Down
7 changes: 0 additions & 7 deletions cli/cmd/turbo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"
"time"
"turbo/internal/config"
"turbo/internal/info"
"turbo/internal/login"
prune "turbo/internal/prune"
"turbo/internal/run"
Expand Down Expand Up @@ -78,18 +77,12 @@ func main() {
"unlink": func() (cli.Command, error) {
return &login.UnlinkCommand{Config: cf, Ui: ui}, nil
},
"graph": func() (cli.Command, error) {
return &info.GraphCommand{Config: cf, Ui: ui}, nil
},
"login": func() (cli.Command, error) {
return &login.LoginCommand{Config: cf, Ui: ui}, nil
},
"logout": func() (cli.Command, error) {
return &login.LogoutCommand{Config: cf, Ui: ui}, nil
},
"me": func() (cli.Command, error) {
return &login.MeCommand{Config: cf, Ui: ui}, nil
},
}

// Capture the defer statements below so the "done" message comes last
Expand Down
2 changes: 1 addition & 1 deletion cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.16

require (
github.com/AlecAivazis/survey/v2 v2.2.12
github.com/Masterminds/semver v1.5.0
github.com/adrg/xdg v0.3.3
github.com/armon/go-radix v1.0.0 // indirect
github.com/bmatcuk/doublestar/v4 v4.0.2
Expand All @@ -25,7 +26,6 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/reflectwalk v1.0.1 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pascaldekloe/name v1.0.1
github.com/pkg/errors v0.9.1
github.com/posener/complete v1.2.1 // indirect
github.com/pyr-sh/dag v1.0.0
Expand Down
2 changes: 0 additions & 2 deletions cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ github.com/mitchellh/reflectwalk v1.0.1 h1:FVzMWA5RllMAKIdUSC8mdWo3XtwoecrH79BY7
github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pascaldekloe/name v1.0.1 h1:9lnXOHeqeHHnWLbKfH6X98+4+ETVqFqxN09UXSjcMb0=
github.com/pascaldekloe/name v1.0.1/go.mod h1:Z//MfYJnH4jVpQ9wkclwu2I2MkHmXTlT9wR5UZScttM=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
6 changes: 5 additions & 1 deletion cli/internal/api/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package api

// LanguageBackend is an abstraction across programming languages and their related package managers
import "turbo/internal/fs"

// LanguageBackend is an abstraction across programming languages and their related package managers
type LanguageBackend struct {
// Name is the name of the language backend
Name string
Expand Down Expand Up @@ -34,4 +35,7 @@ type LanguageBackend struct {
GetWorkspaceGlobs func() ([]string, error)
// Returns run command
GetRunCommand func() []string

// Detect if the project is using a specific package manager
Detect func(string, *fs.PackageJSON, *LanguageBackend) (bool, error)
}
18 changes: 8 additions & 10 deletions cli/internal/backends/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,26 @@ import (
"turbo/internal/api"
"turbo/internal/backends/nodejs"
"turbo/internal/fs"
"turbo/internal/util"
)

var backends = []api.LanguageBackend{
nodejs.NodejsYarnBackend,
nodejs.NodejsBerryBackend,
nodejs.NodejsNpmBackend,
nodejs.NodejsPnpmBackend,
}

func GetBackend() (*api.LanguageBackend, error) {
func GetBackend(cwd string, pkg *fs.PackageJSON) (*api.LanguageBackend, error) {
for _, b := range backends {
if fs.FileExists(b.Specfile) &&
fs.FileExists(b.Lockfile) {
return &b, nil
hit, err := b.Detect(cwd, pkg, &b)
if err != nil {
return nil, err
}
}

for _, b := range backends {
if fs.FileExists(b.Specfile) ||
fs.FileExists(b.Lockfile) {
if hit {
return &b, nil
}
}

return &api.LanguageBackend{}, errors.New("could not determine language / package management backend")
return nil, errors.New(util.Sprintf("could not determine language / package management backend. Please set the \"packageManager\" property in your package.json (${UNDERLINE}https://nodejs.org/api/packages.html#packagemanager)${RESET}"))
}
94 changes: 93 additions & 1 deletion cli/internal/backends/nodejs/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package nodejs
import (
"fmt"
"io/ioutil"

"turbo/internal/api"
"turbo/internal/fs"
"turbo/internal/util"

"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -34,6 +34,76 @@ var NodejsYarnBackend = api.LanguageBackend{
GetRunCommand: func() []string {
return []string{"yarn", "run"}
},
Detect: func(cwd string, pkg *fs.PackageJSON, backend *api.LanguageBackend) (bool, error) {
if pkg.PackageManager != "" {
packageManager, version := util.GetPackageManagerAndVersion(pkg.PackageManager)

if packageManager != "yarn" {
return false, nil
}

isBerry, err := util.IsBerry(cwd, version)
if err != nil {
return false, fmt.Errorf("could not determine yarn version (v1 or berry): %w", err)
}

if !isBerry {
return true, nil
}
}

return false, nil
},
}

var NodejsBerryBackend = api.LanguageBackend{
Name: "nodejs-berry",
Specfile: "package.json",
Lockfile: "yarn.lock",
FilenamePatterns: nodejsPatterns,
GetWorkspaceGlobs: func() ([]string, error) {
pkg, err := fs.ReadPackageJSON("package.json")
if err != nil {
return nil, fmt.Errorf("package.json: %w", err)
}
if len(pkg.Workspaces) == 0 {
return nil, fmt.Errorf("package.json: no workspaces found. Turborepo requires Yarn workspaces to be defined in the root package.json")
}
return pkg.Workspaces, nil
},
GetPackageDir: func() string {
return "node_modules"
},
GetRunCommand: func() []string {
return []string{"yarn", "run"}
},
Detect: func(cwd string, pkg *fs.PackageJSON, backend *api.LanguageBackend) (bool, error) {
if pkg.PackageManager != "" {
packageManager, version := util.GetPackageManagerAndVersion(pkg.PackageManager)

if packageManager != "yarn" {
return false, nil
}

isBerry, err := util.IsBerry(cwd, version)
if err != nil {
return false, fmt.Errorf("could not determine yarn version (v1 or berry): %w", err)
}

if isBerry {
isNMLinker, err := util.IsNMLinker(cwd)
if err != nil {
return false, fmt.Errorf("could not determine if yarn is using `nodeLinker: node-modules`: %w", err)
} else if !isNMLinker {
return false, fmt.Errorf("only yarn v2/v3 with `nodeLinker: node-modules` is supported at this time")
}

return true, nil
}
}

return false, nil
},
}

// PnpmWorkspaces is a representation of workspace package globs found
Expand Down Expand Up @@ -69,6 +139,17 @@ var NodejsPnpmBackend = api.LanguageBackend{
GetRunCommand: func() []string {
return []string{"pnpm", "run"}
},
Detect: func(_ string, pkg *fs.PackageJSON, backend *api.LanguageBackend) (bool, error) {
if pkg.PackageManager != "" {
packageManager, _ := util.GetPackageManagerAndVersion(pkg.PackageManager)

if packageManager == "pnpm" {
return true, nil
}
}

return false, nil
},
}

var NodejsNpmBackend = api.LanguageBackend{
Expand All @@ -92,4 +173,15 @@ var NodejsNpmBackend = api.LanguageBackend{
GetRunCommand: func() []string {
return []string{"npm", "run"}
},
Detect: func(_ string, pkg *fs.PackageJSON, backend *api.LanguageBackend) (bool, error) {
if pkg.PackageManager != "" {
packageManager, _ := util.GetPackageManagerAndVersion(pkg.PackageManager)

if packageManager == "npm" {
return true, nil
}
}

return false, nil
},
}
Loading