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 getting workspace ignores in case of non-monorepo #4268

Merged
merged 4 commits into from
Mar 21, 2023
Merged

Fix getting workspace ignores in case of non-monorepo #4268

merged 4 commits into from
Mar 21, 2023

Conversation

stefanofa
Copy link
Contributor

Description

Hey @mehulkar I tried to fix #4140 .
This is my first time reading or writing in go so it's likely I may have done something wrong.

The way I did it is a bit redundant, as in the case of a monorepo the call to getWorkspaceGlobs is made 2 times and so is not the most efficient. Unfortunately I think I lack a lot of context to try and come up with a better solution, but I felt like trying :)

@stefanofa stefanofa requested a review from a team as a code owner March 20, 2023 18:33
@stefanofa stefanofa requested review from tknickman and chris-olszewski and removed request for a team March 20, 2023 18:33
@vercel
Copy link

vercel bot commented Mar 20, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
examples-designsystem-docs 🔄 Building (Inspect) Mar 20, 2023 at 9:16PM (UTC)
9 Ignored Deployments
Name Status Preview Comments Updated
examples-basic-web ⬜️ Ignored (Inspect) Mar 20, 2023 at 9:16PM (UTC)
examples-cra-web ⬜️ Ignored (Inspect) Mar 20, 2023 at 9:16PM (UTC)
examples-gatsby-web ⬜️ Ignored (Inspect) Mar 20, 2023 at 9:16PM (UTC)
examples-kitchensink-blog ⬜️ Ignored (Inspect) Mar 20, 2023 at 9:16PM (UTC)
examples-native-web ⬜️ Ignored (Inspect) Mar 20, 2023 at 9:16PM (UTC)
examples-nonmonorepo ⬜️ Ignored (Inspect) Mar 20, 2023 at 9:16PM (UTC)
examples-svelte-web ⬜️ Ignored (Inspect) Mar 20, 2023 at 9:16PM (UTC)
examples-tailwind-web ⬜️ Ignored (Inspect) Mar 20, 2023 at 9:16PM (UTC)
examples-vite-web ⬜️ Ignored (Inspect) Mar 20, 2023 at 9:16PM (UTC)

@vercel
Copy link

vercel bot commented Mar 20, 2023

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

A member of the Team first needs to authorize it.

Copy link
Contributor

@mehulkar mehulkar left a comment

Choose a reason for hiding this comment

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

Hey! thanks for taking a stab at this!

The way I did it is a bit redundant, as in the case of a monorepo the call to getWorkspaceGlobs is made 2 times and so is not the most efficient.

Just making sure, do you mean there's a duplicate call to fs.ReadPackageJSON?

Instead of fs.ReadPackageJSON twice, how about returning a custom error from getWorkspaceGlobs (instead of fmt.Errorf()), and returning the ignores: ["node_modules/**] in that case, but bubbling up all other errors?

Happy to give you another pointer to custom error handling if you want!

PS, I know @tknickman also said he might have time to take a look at this, in case he had a different solution in mind.

@stefanofa
Copy link
Contributor Author

Just making sure, do you mean there's a duplicate call to fs.ReadPackageJSON?

Yes, that's what I meant.

By the way, I tried the refactor you suggested!

Copy link
Contributor

@mehulkar mehulkar left a comment

Choose a reason for hiding this comment

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

Couple more questions:

  • What happens in a real monorepo when the workspace config is missing?
  • In npm and pnpm implementations of getWorkspaceIgnores, the default return value is **/node_modules/**. Should we use that as the default here also? Or can we trust the user that if the workspaces config is missing, then we really only want to ignore the root ./node_modules?

cli/internal/packagemanager/yarn.go Outdated Show resolved Hide resolved
cli/internal/packagemanager/yarn.go Outdated Show resolved Hide resolved
stefanofa and others added 2 commits March 20, 2023 22:10
Co-authored-by: Mehul Kar <mehul.kar@vercel.com>
@chris-olszewski
Copy link
Contributor

What happens in a real monorepo when the workspace config is missing?

This should still error as we call packageManager.GetWorkspaces in the BuildPackageGraph context constructor.

* In `npm` and `pnpm` implementations of `getWorkspaceIgnores`, the default return value is `**/node_modules/**`. Should we use that as the default here also? Or can we trust the user that if the workspaces config is missing, then we really only want to ignore the root `./node_modules`?

I think from my groking that node_modules/** matches what yarn does by default: https://github.com/yarnpkg/yarn/blob/3119382885ea373d3c13d6a846de743eca8c914b/src/config.js#L816

@mehulkar
Copy link
Contributor

Let's merge this into my branch then!

@mehulkar mehulkar merged commit 25d4d9b into vercel:mk/4140 Mar 21, 2023
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.

None yet

3 participants