-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include package.json when user specifies inputs
We want to include each workspace's package.json as an input when the user has configured a smaller set of inputs, because the package.json defines the actual task turbo will execute for that workspace (via scripts). If that task definition changes, we want to consider the cache invalid. We only apply this inclusion when inputs are defined, because if inputs are _not_ defined, _all_ git-tracked files are included in the hash, 'which will already include the package.json file.
- Loading branch information
Showing
2 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,24 +239,43 @@ func TestGetPackageDeps(t *testing.T) { | |
|
||
repoRoot := fs.AbsolutePathFromUpstream(t.TempDir()) | ||
myPkgDir := repoRoot.Join("my-pkg") | ||
|
||
// create the dir first | ||
err := myPkgDir.MkdirAll() | ||
assert.NilError(t, err, "CreateDir") | ||
|
||
// create file 1 | ||
committedFilePath := myPkgDir.Join("committed-file") | ||
err := committedFilePath.EnsureDir() | ||
assert.NilError(t, err, "EnsureDir") | ||
err = committedFilePath.WriteFile([]byte("committed bytes"), 0644) | ||
assert.NilError(t, err, "WriteFile") | ||
|
||
// create file 2 | ||
deletedFilePath := myPkgDir.Join("deleted-file") | ||
err = deletedFilePath.WriteFile([]byte("delete-me"), 0644) | ||
assert.NilError(t, err, "WriteFile") | ||
|
||
// create file 3 | ||
nestedPath := myPkgDir.Join("dir", "nested-file") | ||
assert.NilError(t, nestedPath.EnsureDir(), "EnsureDir") | ||
assert.NilError(t, nestedPath.WriteFile([]byte("nested"), 0644), "WriteFile") | ||
|
||
// create a package.json | ||
packageJSONPath := myPkgDir.Join("package.json") | ||
err = packageJSONPath.WriteFile([]byte("{}"), 0644) | ||
assert.NilError(t, err, "WriteFile") | ||
|
||
// set up git repo and commit all | ||
requireGitCmd(t, repoRoot, "init", ".") | ||
requireGitCmd(t, repoRoot, "config", "--local", "user.name", "test") | ||
requireGitCmd(t, repoRoot, "config", "--local", "user.email", "[email protected]") | ||
requireGitCmd(t, repoRoot, "add", ".") | ||
requireGitCmd(t, repoRoot, "commit", "-m", "foo") | ||
|
||
// remove a file | ||
err = deletedFilePath.Remove() | ||
assert.NilError(t, err, "Remove") | ||
|
||
// create another untracked file in git | ||
uncommittedFilePath := myPkgDir.Join("uncommitted-file") | ||
err = uncommittedFilePath.WriteFile([]byte("uncommitted bytes"), 0644) | ||
assert.NilError(t, err, "WriteFile") | ||
|
@@ -265,25 +284,30 @@ func TestGetPackageDeps(t *testing.T) { | |
opts *PackageDepsOptions | ||
expected map[turbopath.AnchoredUnixPath]string | ||
}{ | ||
// base case. when inputs aren't specified, all files hashes are computed | ||
{ | ||
opts: &PackageDepsOptions{ | ||
PackagePath: "my-pkg", | ||
}, | ||
expected: map[turbopath.AnchoredUnixPath]string{ | ||
"committed-file": "3a29e62ea9ba15c4a4009d1f605d391cdd262033", | ||
"uncommitted-file": "4e56ad89387e6379e4e91ddfe9872cf6a72c9976", | ||
"package.json": "9e26dfeeb6e641a33dae4961196235bdb965b21b", | ||
"dir/nested-file": "bfe53d766e64d78f80050b73cd1c88095bc70abb", | ||
}, | ||
}, | ||
// with inputs, only the specified inputs are hashed | ||
{ | ||
opts: &PackageDepsOptions{ | ||
PackagePath: "my-pkg", | ||
InputPatterns: []string{"uncommitted-file"}, | ||
}, | ||
expected: map[turbopath.AnchoredUnixPath]string{ | ||
"package.json": "9e26dfeeb6e641a33dae4961196235bdb965b21b", | ||
"uncommitted-file": "4e56ad89387e6379e4e91ddfe9872cf6a72c9976", | ||
}, | ||
}, | ||
// inputs with glob pattern also works | ||
{ | ||
opts: &PackageDepsOptions{ | ||
PackagePath: "my-pkg", | ||
|
@@ -292,16 +316,19 @@ func TestGetPackageDeps(t *testing.T) { | |
expected: map[turbopath.AnchoredUnixPath]string{ | ||
"committed-file": "3a29e62ea9ba15c4a4009d1f605d391cdd262033", | ||
"uncommitted-file": "4e56ad89387e6379e4e91ddfe9872cf6a72c9976", | ||
"package.json": "9e26dfeeb6e641a33dae4961196235bdb965b21b", | ||
"dir/nested-file": "bfe53d766e64d78f80050b73cd1c88095bc70abb", | ||
}, | ||
}, | ||
// inputs with another glob pattern works | ||
{ | ||
opts: &PackageDepsOptions{ | ||
PackagePath: "my-pkg", | ||
InputPatterns: []string{"**/{uncommitted,committed}-file"}, | ||
}, | ||
expected: map[turbopath.AnchoredUnixPath]string{ | ||
"committed-file": "3a29e62ea9ba15c4a4009d1f605d391cdd262033", | ||
"package.json": "9e26dfeeb6e641a33dae4961196235bdb965b21b", | ||
"uncommitted-file": "4e56ad89387e6379e4e91ddfe9872cf6a72c9976", | ||
}, | ||
}, | ||
|