boltpkg / bolt

⚡️ Super-powered JavaScript project management
MIT License
2.35k stars 82 forks source link

Problem with install and linking (on fresh monorepo) #177

Open tunnckoCore opened 6 years ago

tunnckoCore commented 6 years ago
Title Description
Version ^0.20.7
Type issue
node 10.3.0, yarn 1.7
Operating System ArchLinux
Short Description fresh bolt install problem

Detailed description

I have fresh monorepo with 4 packages in it. Link to it https://github.com/olstenlarck/hela/tree/v3-major.

Basic assumption is to just run bolt install in the project root and everything to be installed and linked. But it errors with that it can't link external dependencies of the each project.

~/tunnckoCore/hela v3-major *
❯ bolt install
⚡️   bolt v0.20.7 (node v10.3.0)
🔎   [1/3] Validating project...
📦   [2/3] Installing project dependencies...
$ /home/charlike/.config/yarn/global/node_modules/bolt/node_modules/.bin/yarn config get user-agent yarn/1.7.0 npm/?node/v10.3.0 linux x64
yarn install v1.7.0
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.58s.
🔗   [3/3] Linking workspace dependencies...
error Package "@hela/core" dependency "execa-pro" must be added to project dependencies.
error Package "@hela/core" dependency "sade" must be added to project dependencies.
error Cannot symlink invalid set of dependencies.

I figured out that Bolt needs to install each dependency for each project seprately, using bolt like

bolt w @hela/cli add <deps for that package>
bolt w @hela/core add <deps for that package>
bolt w @hela/dargs add <deps for that package>
bolt w @hela/config-tunnckocore add <deps for that package>

So it adds all of them to the root dependencies and once they are there, then cleaning all of the packages' node_modules (e.g. rm -rf packages/cli/node_modules) and running bolt install on the root - everything works without errors.

I can understand why this is needed. But first, there is no docs for this. And second, it would be better before doing anything and the install, to scan each package deps in the defined workpaces, add then add them to the project root and after that start the install process.

This will simplify the manual process that i've done.

So bolt install should act like that:

Oh, okey, workspaces is packages/*, i'm going to scan each package deps - there is packages/core with two deps in its package.json - I'm going to add them as dependencies to the project root (e.g. bolw w @hela/core <found deps>). Okey, there is packages/cli with 3 dependencies, one of which is the packages/core - i'm going to add them to the project root, except the package from packages/core. Okey, i'm done, i'll run bolt install now.

ajaymathur commented 6 years ago

Hey @olstenlarck, Thanks for raising the issue.

I don't think we should ever update dependencies in package.json automatically as it might create confusion ( user may confuse why did package json update on install ? ).

I agree documentation is missing. We are working on the new website with all the documentation - https://github.com/boltpkg/website/tree/docusaurus

tunnckoCore commented 6 years ago

It won't be confusion. What confusion?

user may confuse why did package json update on install ?

It will not touch the packages' package.json, it will just copy each dependency from each pacakge into the roots' package.json. And even more, it isn't needed to call the install command - just copy paste.

Say we have mono repo with packages/foo, packages/bar and packages/qux. Qux will have 3 dependencies - Foo, Bar and lets say execa. Bar will have chalk and pify. Foo will have eslint and prettier.

So what Bolt can do first is to collect all deps - execa, chalk, prettier, Foo and Bar, exclude those that are from the monorepo and just put the rest into the root package.json. And after that start the install.

It's acceptable to have updates on the root package.json, because it will be updated anyway when you call manually bolt w [name] add for each dependency.

sudoJoe commented 5 years ago

I think it would be better to copy them into a temporary file other than the package json.

Otherwise, pushing to git after install would result in changes being saved to the root package.json that aren't desirable.

For example, I keep only globally used dev dependencies (i.e. jest, typescript, typedoc, lint-staged, eslint, prettier) in the root package.jsn, and have multiple workspaces/worktrees in the monorepo that DO NOT share dependencies.

nvenegas commented 4 years ago

I figured out that Bolt needs to install each dependency for each project seprately, using bolt like

bolt w @hela/cli add <deps for that package>
bolt w @hela/core add <deps for that package>
bolt w @hela/dargs add <deps for that package>
bolt w @hela/config-tunnckocore add <deps for that package>

I just came across this bootstrapping manual work and jq was handy, e.g.,

jq -r '.dependencies | to_entries[] | "\(.key)@\(.value)"' packages/cli/package.json | xargs bolt w @hella/cli add
jq -r '.devDependencies | to_entries[] | "\(.key)@\(.value)"' packages/cli/package.json | xargs bolt w @hella/cli add --dev