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

lerna assumes it manages git root #555

Closed
joscha opened this issue Jan 31, 2017 · 10 comments
Closed

lerna assumes it manages git root #555

joscha opened this issue Jan 31, 2017 · 10 comments

Comments

@joscha
Copy link
Contributor

joscha commented Jan 31, 2017

When using lerna within a folder of a repository, e.g.

/ <-- here is the git root
/maven-project-a/ <-- calling `lerna init` here, this folder also has a `package.json`

it assumes that the lerna.json and package.json file will live in the root folder, e.g. creating a structure like this:

/lerna.json
/package.json (empty with only the lerna package)
/project-a/ (package.json here is unaltered)

if I move lerna.json into the project-a folder and add lerna to the dependencies of that package.json I get

lerna bootstrap
Lerna v2.0.0-beta.34
`package.json` does not exist, have you run `lerna init`?

when running lerna bootstrap from within project-a.

Would you accept a PR that teaches lerna to stop searching for a lerna config in the git root if it is invoked from a subdirectory which has a valid package.json (e.g. "dependencies": { "lerna": "2.0.0-beta.34" }) and a valid lerna.json?

@doug-wade
Copy link
Contributor

You can use the packages option in lerna.json to configure maven-project-a/packages/ to be where your lerna modules are located, which should allow you to structure your project however is most convenient for maven. Does that cover your use case, or is there something more I'm missing?

@joscha
Copy link
Contributor Author

joscha commented Jan 31, 2017

Thanks for the answer @doug-wade, the packages location is actually not the problem, adapting that path works fine. The problem lies in lerna thinking its not been lerna inited when the lerna managed package is not equal to the git root. I can create a gist to demonstrate the problem if that is easier?

@doug-wade
Copy link
Contributor

@joscha I think in this case a repro repository would be best, since then I can clone it and use it locally -- unless there's some cool gist feature I don't know about, to use it locally would take a lot of copy-paste.

@joscha
Copy link
Contributor Author

joscha commented Feb 1, 2017

sure, @doug-wade, repo is here: https://github.com/joscha/lerna-broken-nesting-example

@joscha
Copy link
Contributor Author

joscha commented Feb 7, 2017

@doug-wade were you able to verify the problem or is there anything else I can provide?

@evocateur
Copy link
Member

@joscha I understand this problem, and I could've sworn there were a couple other issues recently with basically the same problem. In any case...

Right now, we are indeed making the assumption that lerna.json lives in the repo root, which we obtain in the normal git plumbing fashion (git rev-parse --show-toplevel). It's robust because it doesn't care what your CWD is, and so on.

Alternatively, we could use a package like find-up to locate lerna.json, which would largely enable your desired pattern (with the caveat that you'd always need to run lerna commands with $CWD == /maven-project-a/, in your example).

TODOs, as I see them:

  • The Repository class needs to use findUp("lerna.json") to set its rootPath property.
  • We need to resolve the "chicken vs egg" problem for lerna init, namely that lerna.json won't exist (and thus all the Repository setup needs to be delayable or re-baseable?).
  • lerna init should accept an optional argument specifying the root directory, otherwise defaulting to process.cwd().

PRs welcome. :)

@joscha
Copy link
Contributor Author

joscha commented Feb 28, 2017

Thanks for the answer @evocateur - we had to abandon our plans to use lerna in the meantime, due to #377 and also a few comments here and there that suggested that lerna functionality might be picked up by yarn, so I won't be investing time in this issue for now. We can close the issue or leave it open (as I think other people might have similar issues and might be interested in following through the TODOs).

@evocateur
Copy link
Member

I understand completely, @joscha. We'll leave this open so it's easier for others with the same issue to find.

@joscha
Copy link
Contributor Author

joscha commented Mar 18, 2017

🎉 thanks @evocateur

@lock
Copy link

lock bot commented Dec 28, 2018

This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants