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

fix: error when workspaces are not defined #472

Merged
merged 7 commits into from
Jan 10, 2022
11 changes: 11 additions & 0 deletions cli/internal/backends/nodejs/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ var NodejsYarnBackend = api.LanguageBackend{
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 {
Expand Down Expand Up @@ -53,6 +56,11 @@ var NodejsPnpmBackend = api.LanguageBackend{
if err := yaml.Unmarshal(bytes, &pnpmWorkspaces); err != nil {
return nil, fmt.Errorf("pnpm-workspace.yaml: %w", err)
}

if len(pnpmWorkspaces.Packages) == 0 {
return nil, fmt.Errorf("pnpm-workspace.yaml: no packages found. Turborepo requires PNPM workspaces and thus packages to be defined in the root pnpm-workspace.yaml")
}

return pnpmWorkspaces.Packages, nil
},
GetPackageDir: func() string {
Expand All @@ -73,6 +81,9 @@ var NodejsNpmBackend = api.LanguageBackend{
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 NPM workspaces to be defined in the root package.json")
}
return pkg.Workspaces, nil
},
GetPackageDir: func() string {
Expand Down
3 changes: 2 additions & 1 deletion cli/internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ func WithGraph(rootpath string, config *config.Config) Option {
c.RootPackageJSON = pkg

spaces, err := c.Backend.GetWorkspaceGlobs()

if err != nil {
return err
return fmt.Errorf("could not detect workspaces: %w", err)
}

// Calculate the global hash
Expand Down