这是indexloc提供的服务,不要输入任何密码
Skip to content
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
38 changes: 33 additions & 5 deletions cli/internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package context

import (
"fmt"
"log"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -36,6 +37,7 @@ type Context struct {
Dir string
RootNode string
RootPackageJSON *fs.PackageJSON
TurboConfig *fs.TurboConfigJSON
GlobalHashableEnvPairs []string
GlobalHashableEnvNames []string
GlobalHash string
Expand Down Expand Up @@ -97,12 +99,38 @@ func WithGraph(rootpath string, config *config.Config) Option {
return fmt.Errorf("could not get cwd: %w", err)
}

pkg, err := fs.ReadPackageJSON("package.json")
packageJSONPath := path.Join(rootpath, "package.json")
pkg, err := fs.ReadPackageJSON(packageJSONPath)
if err != nil {
return fmt.Errorf("package.json: %w", err)
}
c.RootPackageJSON = pkg

// If turbo.json exists, we use that
// If pkg.Turbo exists, we warn about running the migration
// Use pkg.Turbo if turbo.json doesn't exist
// If neither exists, it's a fatal error
turboJSONPath := path.Join(rootpath, "turbo.json")
if !fs.FileExists(turboJSONPath) {
if pkg.LegacyTurboConfig == nil {
// TODO: suggestion on how to create one
return fmt.Errorf("Could not find turbo.json. Follow directions at https://turborepo.org/docs/getting-started to create one")
} else {
log.Println("[WARNING] Turbo configuration now lives in \"turbo.json\". Migrate to turbo.json by running \"npx @turbo/codemod create-turbo-config\"")
c.TurboConfig = pkg.LegacyTurboConfig
}
} else {
turbo, err := fs.ReadTurboConfigJSON(turboJSONPath)
if err != nil {
return fmt.Errorf("turbo.json: %w", err)
}
c.TurboConfig = turbo
if pkg.LegacyTurboConfig != nil {
log.Println("[WARNING] Ignoring legacy \"turbo\" key in package.json, using turbo.json instead. Consider deleting the \"turbo\" key from package.json")
pkg.LegacyTurboConfig = nil
}
}

if backend, err := backends.GetBackend(cwd, pkg); err != nil {
return err
} else {
Expand Down Expand Up @@ -132,9 +160,9 @@ func WithGraph(rootpath string, config *config.Config) Option {
globalDeps := make(util.Set)

// Calculate global file and env var dependencies
if len(pkg.Turbo.GlobalDependencies) > 0 {
if len(c.TurboConfig.GlobalDependencies) > 0 {
var globs []string
for _, v := range pkg.Turbo.GlobalDependencies {
for _, v := range c.TurboConfig.GlobalDependencies {
if strings.HasPrefix(v, "$") {
trimmed := strings.TrimPrefix(v, "$")
c.GlobalHashableEnvNames = append(c.GlobalHashableEnvNames, trimmed)
Expand Down Expand Up @@ -188,7 +216,7 @@ func WithGraph(rootpath string, config *config.Config) Option {
return fmt.Errorf("error hashing global dependencies %w", err)
}
c.GlobalHash = globalHash
targets, err := GetTargetsFromArguments(c.Args, &c.RootPackageJSON.Turbo)
targets, err := GetTargetsFromArguments(c.Args, c.TurboConfig)
if err != nil {
return err
}
Expand Down Expand Up @@ -284,7 +312,7 @@ func (c *Context) loadPackageDepsHash(pkg *fs.PackageJSON) error {
return nil
}

func (c *Context) ResolveWorkspaceRootDeps() (error) {
func (c *Context) ResolveWorkspaceRootDeps() error {
seen := mapset.NewSet()
var lockfileWg sync.WaitGroup
pkg := c.RootPackageJSON
Expand Down
22 changes: 21 additions & 1 deletion cli/internal/fs/package_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,35 @@ import (
"sync"
)

// TurboConfigJSON is the root turborepo configuration
type TurboConfigJSON struct {
// Base Git branch
Base string `json:"baseBranch,omitempty"`
// Global root filesystem dependencies
GlobalDependencies []string `json:"globalDependencies,omitempty"`
TurboCacheOptions string `json:"cacheOptions,omitempty"`
Outputs []string `json:"outputs,omitempty"`
// RemoteCacheUrl is the Remote Cache API URL
RemoteCacheUrl string `json:"remoteCacheUrl,omitempty"`
// Pipeline is a map of Turbo pipeline entries which define the task graph
// and cache behavior on a per task or per package-task basis.
Pipeline map[string]Pipeline
}

func ReadTurboConfigJSON(path string) (*TurboConfigJSON, error) {
b, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
var turboConfig *TurboConfigJSON
err = json.Unmarshal(b, &turboConfig)
if err != nil {
println("error unmarshalling", err.Error())
return nil, err
}
return turboConfig, nil
}

type PPipeline struct {
Outputs *[]string `json:"outputs"`
Cache *bool `json:"cache,omitempty"`
Expand Down Expand Up @@ -64,7 +84,7 @@ type PackageJSON struct {
UnresolvedExternalDeps map[string]string
ExternalDeps []string
SubLockfile YarnLockfile
Turbo TurboConfigJSON `json:"turbo"`
LegacyTurboConfig *TurboConfigJSON `json:"turbo"`
Mu sync.Mutex
FilesHash string
ExternalDepsHash string
Expand Down
6 changes: 3 additions & 3 deletions cli/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func (c *RunCommand) Run(args []string) int {
runState.Listen(c.Ui, time.Now())
engine := core.NewScheduler(&ctx.TopologicalGraph)
var logReplayWaitGroup sync.WaitGroup
for taskName, value := range ctx.RootPackageJSON.Turbo.Pipeline {
for taskName, value := range ctx.TurboConfig.Pipeline {
topoDeps := make(util.Set)
deps := make(util.Set)
if util.IsPackageTask(taskName) {
Expand Down Expand Up @@ -410,10 +410,10 @@ func (c *RunCommand) Run(args []string) int {
}
// Hash ---------------------------------------------
// first check for package-tasks
pipeline, ok := ctx.RootPackageJSON.Turbo.Pipeline[fmt.Sprintf("%v", id)]
pipeline, ok := ctx.TurboConfig.Pipeline[fmt.Sprintf("%v", id)]
if !ok {
// then check for regular tasks
altpipe, notcool := ctx.RootPackageJSON.Turbo.Pipeline[task]
altpipe, notcool := ctx.TurboConfig.Pipeline[task]
// if neither, then bail
if !notcool && !ok {
return nil
Expand Down
31 changes: 14 additions & 17 deletions cli/scripts/generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,7 @@ turbo-linux
[type]: "*",
},
}
: {
turbo: {
pipeline: {
build: {
outputs: ["dist/**/*"],
dependsOn: ["^build"],
},
test: {
dependsOn: ["build"],
},
dev: {
cache: false,
},
},
},
};
: {};

fs.writeFileSync(
path.join(root, "package.json"),
Expand All @@ -108,7 +93,7 @@ turbo-linux
private: true,
workspaces: ["packages/*"],
...deps,
packageManager: "yarn@1.22.17"
packageManager: "yarn@1.22.17",
},
null,
2
Expand Down Expand Up @@ -157,6 +142,18 @@ turbo-linux
provider: "local",
cacheUrl: "https://1a77600385dd.ngrok.io",
},
pipeline: {
build: {
outputs: ["dist/**/*"],
dependsOn: ["^build"],
},
test: {
dependsOn: ["build"],
},
dev: {
cache: false,
},
},
},
null,
2
Expand Down
17 changes: 10 additions & 7 deletions cli/scripts/monorepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ importers:
execa.sync("yarn", ["install"], {
cwd,
env: {
"YARN_ENABLE_IMMUTABLE_INSTALLS": "false"
}
YARN_ENABLE_IMMUTABLE_INSTALLS: "false",
},
});
this.commitAll();
return;
Expand All @@ -182,10 +182,10 @@ importers:
test: `${turboPath} run test`,
lint: `${turboPath} run lint`,
},
turbo: {
baseBranch: "origin/main",
...turboConfig,
},
},
"turbo.json": {
baseBranch: "origin/main",
...turboConfig,
},
});
}
Expand Down Expand Up @@ -222,7 +222,10 @@ fs.copyFileSync(
internalDeps.reduce((deps, dep) => {
return {
...deps,
[dep]: (this.npmClient === "pnpm" || this.npmClient === "berry") ? "workspace:*" : "*",
[dep]:
this.npmClient === "pnpm" || this.npmClient === "berry"
? "workspace:*"
: "*",
};
}, {})),
},
Expand Down
19 changes: 0 additions & 19 deletions create-turbo/templates/_shared_ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,6 @@
"prettier": "^2.5.1",
"turbo": "*"
},
"turbo": {
"pipeline": {
"build": {
"dependsOn": [
"^build"
],
"outputs": [
"dist/**",
".next/**"
]
},
"lint": {
"outputs": []
},
"dev": {
"cache": false
}
}
},
"engines": {
"npm": ">=7.0.0",
"node": ">=14.0.0"
Expand Down
14 changes: 14 additions & 0 deletions create-turbo/templates/_shared_ts/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**"]
},
"lint": {
"outputs": []
},
"dev": {
"cache": false
}
}
}
19 changes: 0 additions & 19 deletions create-turbo/templates/npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,5 @@
"devDependencies": {
"prettier": "^2.5.1",
"turbo": "*"
},
"turbo": {
"pipeline": {
"build": {
"dependsOn": [
"^build"
],
"outputs": [
"dist/**",
".next/**"
]
},
"lint": {
"outputs": []
},
"dev": {
"cache": false
}
}
}
}
14 changes: 14 additions & 0 deletions create-turbo/templates/npm/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**"]
},
"lint": {
"outputs": []
},
"dev": {
"cache": false
}
}
}
19 changes: 0 additions & 19 deletions create-turbo/templates/pnpm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,5 @@
"devDependencies": {
"prettier": "^2.5.1",
"turbo": "latest"
},
"turbo": {
"pipeline": {
"build": {
"dependsOn": [
"^build"
],
"outputs": [
"dist/**",
".next/**"
]
},
"lint": {
"outputs": []
},
"dev": {
"cache": false
}
}
}
}
14 changes: 14 additions & 0 deletions create-turbo/templates/pnpm/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**"]
},
"lint": {
"outputs": []
},
"dev": {
"cache": false
}
}
}
19 changes: 0 additions & 19 deletions create-turbo/templates/yarn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,5 @@
"devDependencies": {
"prettier": "^2.5.1",
"turbo": "*"
},
"turbo": {
"pipeline": {
"build": {
"dependsOn": [
"^build"
],
"outputs": [
"dist/**",
".next/**"
]
},
"lint": {
"outputs": []
},
"dev": {
"cache": false
}
}
}
}
Loading