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

Ensure dependencySatisfies only considers actual dependencies (includes a fix for invalid results within monorepo scenarios) #1070

Conversation

NullVoxPopuli
Copy link
Collaborator

Resolves: #1067

@@ -12,7 +12,7 @@ export default function dependencySatisfies(path: NodePath<t.CallExpression>, st
if (path.node.arguments.length !== 2) {
throw error(path, `dependencySatisfies takes exactly two arguments, you passed ${path.node.arguments.length}`);
}
let [packageName, range] = path.node.arguments;
const [packageName, range] = path.node.arguments;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

needed to be const due to the function usage in line 35

@NullVoxPopuli
Copy link
Collaborator Author

can I make this draft after submission? 🙃
I need to:

  • add a test
  • confirm this actually works in my real app

@lifeart lifeart marked this pull request as draft January 10, 2022 20:20
@lifeart
Copy link
Collaborator

lifeart commented Jan 10, 2022

@NullVoxPopuli I converted it to draft

@NullVoxPopuli
Copy link
Collaborator Author

@lifeart thank you!

@ef4
Copy link
Contributor

ef4 commented Jan 12, 2022

Some of the existing babel tests were misleading you I think (process.cwd has nothing to do with the resolving for example). I cleaned them up.

There is a similar step still needed for the glimmer tests I think.

@ef4
Copy link
Contributor

ef4 commented Jan 12, 2022

The remaining test failures happen because the PackageCache at this layer doesn't distinguish which Package is the app vs any other library, and Package.prototype.dependencies is strict about only listing devDependencies if it knows the Package is the app. So at the moment dependencySatisfies will miss devDependencies of apps.

I'm refactoring PackageCache so that threading through the app root path is mandatory, so it can always give correct answers about the app's dependencies. Up until now we hadn't needed that here.

@NullVoxPopuli
Copy link
Collaborator Author

Thanks for poking at this! This'll be a huge help!

@ef4
Copy link
Contributor

ef4 commented Jan 12, 2022

The two remaining failures are just sporadic, I confirmed they're passing locally.

(We have so many different jobs that even low-probability failures in CI are likely to accumulate and cause a bad run.)

@ef4 ef4 marked this pull request as ready for review January 12, 2022 20:41
@ef4
Copy link
Contributor

ef4 commented Jan 12, 2022

This is ready to go. I hijacked your PR and made it a much better change. 😄

One thing we can consider doing next is making packageCache.resolve strict like this by default. There are definitely some cases in embroider/compat where we'd want to opt into non-strict resolve, but it would be a good default.

@ef4 ef4 merged commit f39b6f0 into embroider-build:master Jan 12, 2022
@NullVoxPopuli
Copy link
Collaborator Author

Thank you!! <3

@rwjblue rwjblue added the bug Something isn't working label Jan 12, 2022
@rwjblue rwjblue changed the title Do not try to resolve packages that are not declared in dependencies Ensure dependencySatisfies only considers actual dependencies (includes a fix for invalid results within monorepo scenarios) Jan 12, 2022
ef4 added a commit to emberjs/ember-render-modifiers that referenced this pull request Jan 13, 2022
This addon uses `dependencySatisfies` to check the ember-source version. But unless you have a peerDep on ember-source, that was unreliable depending on Yarn/NPM optimization behaviors. And now as of embroider-build/embroider#1070 we're making `dependencySatisfies` strict so that it won't accidentally work sometimes when you don't actually declare a dependency or peerDependency.
anehx added a commit to anehx/ember-engines that referenced this pull request Jan 17, 2022
This package uses `dependencySatisfies` of `@embroider/macros` which is
only reliable if a `peerDependency` for the package exists. If not, the
macro checks for a dependency in the `ember-engines` package when a
monorepo structure is used. This behaviour happens since embroider
v0.50.1 which includes an important fix for monorepos:
embroider-build/embroider#1070
@anehx
Copy link

anehx commented Jan 17, 2022

Thanks for this fix, this resolves a lot of issues I had with packages using dependencySatisfies in a monorepo! 🎉 However, since this makes dependencySatisfies much stricter (needing at least a peerDependency) we should make sure it's properly documented. Also, this should maybe even be marked as a breaking change? I'm not informed enough on why the peerDependency is required to add the documentation myself but I'd really appreciate if someone with that knowledge could add it (@NullVoxPopuli or @ef4 maybe? 😉 ).

Also, I'm wondering if a peer dependency should really be needed - what happens if a package wants to check whether a certain package is installed or not? A peer dependency for such a case would be wrong, no? This might be what @ef4 meant here: #1070 (comment) ?

anehx added a commit to anehx/ember-engines that referenced this pull request Jan 20, 2022
This package uses `dependencySatisfies` of `@embroider/macros` which is
only reliable if a `peerDependency` for the package exists. If not, the
macro checks for a dependency in the `ember-engines` package when a
monorepo structure is used. This behaviour happens since embroider
v0.50.1 which includes an important fix for monorepos:
embroider-build/embroider#1070
@ef4
Copy link
Contributor

ef4 commented Jan 25, 2022

what happens if a package wants to check whether a certain package is installed or not? A peer dependency for such a case would be wrong, no?

For that we use optional peer dependencies.

anehx added a commit to anehx/ember-engines that referenced this pull request Mar 4, 2022
This package uses `dependencySatisfies` of `@embroider/macros` which is
only reliable if a `peerDependency` for the package exists. If not, the
macro checks for a dependency in the `ember-engines` package when a
monorepo structure is used. This behaviour happens since embroider
v0.50.1 which includes an important fix for monorepos:
embroider-build/embroider#1070
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

in a yarn-monorepo, dependencySatisfies is always true when referencing packages in the monorepo
5 participants