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

Fix package substrings for getChangedPackages #1533

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

Closed
wants to merge 1 commit into from
Closed

Fix package substrings for getChangedPackages #1533

wants to merge 1 commit into from

Conversation

wvanrensselaer
Copy link
Contributor

See #1528

Changed files belonging to a package which was a substring of another package (e.g. react, react-dom) were sometimes not included in the turbo changed packages.

I haven't worked much in Golang, let me know if there's a more idiomatic way to handle this.

@vercel
Copy link

vercel bot commented Jul 14, 2022

@wvanrensselaer is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

@@ -204,7 +204,8 @@ func getChangedPackages(changedFiles []string, packageInfos map[interface{}]*fs.
for _, changedFile := range changedFiles {
found := false
for pkgName, pkgInfo := range packageInfos {
if pkgName != util.RootPkgName && strings.HasPrefix(changedFile, pkgInfo.Dir) {
// Add trailing slash to avoid package substring conflicts: (e.g. react, react-dom)
if pkgName != util.RootPkgName && strings.HasPrefix(changedFile, pkgInfo.Dir+"/") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Will! I noticed this breaks one of the other tests where the changedFile is libs/libB (no trailing slash)... TBH I'm not sure how realistic that case is, but it might be better to check each full path segment in the dirname.

I didn't want to step on your PR, I made a commit on a fork here: 015cb34

Feel free to cherry pick (if you can do that from a fork), or just pull in the code. It includes a few changes to the unit tests that I think are needed too (the unit tests take packageInfos as part of ctx)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice catch, yeah was wondering if that case could come about. Would need at least a package.json for turbo to consider a directory a package, but then the directory wouldn't be the changed file, the package.json would. But maybe I'm not thinking of an edge case.

Using OS path separator is a good call, wasn't sure if these paths were OS-scoped. But looks like Nathan put up a PR so I'll close this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wvanrensselaer You're 100% correct that it's weird, but (without checking) I suspect that's in there to protect from a weird symlink-to-directory edge case we always have to watch out for.

kodiakhq bot pushed a commit that referenced this pull request Jul 15, 2022
Previously we didn't properly check for package prefixes being at actual file-addressing boundaries. This PR resolves the issue.

Fixes #1528
Closes #1533

Co-authored-by: Will Van Rensselaer <35181014+wvanrensselaer@users.noreply.github.com>
Co-authored-by: Joe Boyle <8823810+helloitsjoe@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants