spago icon indicating copy to clipboard operation
spago copied to clipboard

Autoinstall missing packages

Open klntsky opened this issue 1 year ago • 5 comments

Instead of suggesting the user to copy-paste the command from the terminal, like here:

[error] Some of your project files import modules from packages that are not in the direct dependencies of your project.
To fix this error add the following packages to the list of dependencies in your config:
- aff
- datetime
- foldable-traversable
- maybe
- newtype
- numbers
- ordered-collections
- transformers
You may add these dependencies by running the following command:
spago install aff datetime foldable-traversable maybe newtype numbers ordered-collections transformers

a flag could be added, e.g. spago install --missing to install these automatically

klntsky avatar Apr 08 '24 15:04 klntsky

I considered this before (I would have called the flag --pedantic-packages-autofix) but ultimately decided to not go for it - and the main reason is that in a monorepo setting with many packages you would get different spago commands to copypaste, and it could be that you would then decide to enable the pedantic check for some packages but not for others. Then the autofix would need to be tailored to a specific package. Then there's the issue of tests: you would get a separate command to fix dependencies in your test suites. Again, it could be that instead of fixing it you would want to disable the pedantic check for those.

So in the end I am not sure it would be actually more convenient than having the commands printed there?

f-f avatar Apr 12 '24 23:04 f-f

BTW, could you explain a bit more: it seems that spago build sometimes builds my project without complaint and then I try to publish, it warns about missing deps.

E.g. https://github.com/garganscript/purescript-sequences/blob/spago-next/spago.yaml

I added only prelude as a dependency and it builds just fine. However, there's lots of other deps such as arrays etc but it doesn't complain about them missing. Also, spago ls deps returns prelude only. I can run spago repl and test out the code, and in .spago/p I can see the arrays module being installed.

So I'm a bit confused what to put in dependencies now.

CGenie avatar Apr 16 '24 05:04 CGenie

@CGenie the publishing checks include verifying that the dependencies of your package are accurate, so that:

  • the list of dependencies does not contain packages that are not being imported by your modules
  • the modules in your package do not import modules from packages that are not declared in the dependencies

These are both situations that you would not easily detect when just writing code. They are also not critical, in the sense that during normal development you might only care about your package compiling, rather than the project manifest being 100% accurate.

It's possible to have Spago check this for you on a one-off basis, by enabling the --pedantic-packages flag when building, or on a regular basis by setting pedanticPackages: true in the config file (look it up in the docs).

The default situation is that Spago does not check until it's required, which is at the time of publishing your package - this is what just happened to you

f-f avatar Apr 19 '24 08:04 f-f

Btw, the reason why you can have only prelude in the list of dependencies and have all the other packages available (such as array, etc) is that you have things like quickcheck in the dependencies list of your test package. That brings in all those packages and makes them "available" for your build to use.

Running spago ls deps --transitive will list out all the packages that are brought in as dependencies of your dependencies. And spago graph packages will give you a graph (in various formats) based on the dependency relations.

f-f avatar Apr 19 '24 08:04 f-f

Thank you!

CGenie avatar Apr 19 '24 08:04 CGenie

I will close this for now since I am still holding the opinion that I detailed above, but let's reopen it if the inconvenience gets too big 🙂

f-f avatar Jul 25 '24 23:07 f-f