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

[Feature] Using Lerna Locally #138

Closed
jamiebuilds opened this issue May 16, 2016 · 10 comments
Closed

[Feature] Using Lerna Locally #138

jamiebuilds opened this issue May 16, 2016 · 10 comments

Comments

@jamiebuilds
Copy link
Contributor

jamiebuilds commented May 16, 2016

I want to encourage people to run lerna locally, but it's kinda annoying using a CLI based tool with tons of commands locally (you end up aliasing all of them to npm scripts or something else and no gross)

So instead I want to make it so that the global /usr/bin/lerna will run the local ./node_modules/.bin/lerna if it exists.

It'd be nice if this could work independently of versioning, so any version of the global CLI can run any version of the local CLI.

I'm considering just making this another package lerna-global that is super dumb: (pseudo code)

require('child_process').exec(process.argv.slice(1).unshift('./node_modules/.bin/lerna'));
@jamiebuilds
Copy link
Contributor Author

https://github.com/timoxley/npm-run

@scriptjs
Copy link

I am wholeheartedly behind running locally but in the way all other modules currently work instead of any tricks with 'usr/bin'. Personally, I dislike -g with anything node and avoid preferring anything global.

I don't use /usr/bin at all when I must install something global. bins from global installs are instead executed from /.local/bin. Global installs do not need sudo in this case. Like many that develop commercially, we rely on sinopia/verdaccio. The npm client is often upgraded more often than node.

@jamiebuilds
Copy link
Contributor Author

I want to encourage as many people to install locally as possible. I wouldn't mind having a separate lerna-cli package just to push people in the right direction. Other packages like gulp have had success doing this.

@scriptjs
Copy link

scriptjs commented Jun 1, 2016

@thejameskyle babel-cli also

@jamiebuilds
Copy link
Contributor Author

babel-cli doesn't resolve to the local version if you have one installed, it depends on babel-core itself

@tjbenton
Copy link

All you have to do is add ./node_modules/.bin or $(npm bin) to your PATH in your bash files. I know this works quite well for mac, because I've been using it for a couple of years and it's allowed me to not install any global dependencies for my projects.

Here's how to add it to your path in your dot files

PATH=./node_modules/.bin:$PATH # adds locally installed node modules to the path
export PATH

You can also make an function for it if you don't like messing with the path

function npm-exec {
   $(npm bin)/$@  
}

If you're using a Makefile You can put this at the top of it and that also adds it to your path.

PATH := $(npm bin):$(PATH)
SHELL := /bin/bash

So the following would work

bootstrap:
    lerna bootstrap

I don't use windows but I asked a co worker who does to look into it. So I will update this if he comes up with anything.

@jamiebuilds
Copy link
Contributor Author

I don't want people messing around with there bash config

@jamiebuilds jamiebuilds changed the title Using Lerna Locally [Feature] Using Lerna Locally Nov 16, 2016
@evocateur
Copy link
Member

ava's pattern here looks really nice. Wouldn't even need that many changes to make work with our patterns.

marionebl added a commit to marionebl/lerna that referenced this issue Nov 17, 2017
marionebl added a commit to marionebl/lerna that referenced this issue Nov 17, 2017
marionebl added a commit to marionebl/lerna that referenced this issue Nov 17, 2017
closes lerna#138

BREAKING CHANGE
lerna now prefers installs resolvable relative to the current working directory.
For situations where a global install was used and an outdated lerna version
is present in the node_modules folder, this might cause breakage.
The issue can be resolved by installing a lerna version that fulfills the version
requirement in lerna.json
@NMFR
Copy link

NMFR commented Nov 28, 2017

Don't know if it will help but you can not have it installed globally:

  • Install it as a dev dependency.
  • Add lerna as a script in package.json:
    {
      ...
      "scripts": {
        "lerna": "lerna"
      }
    }
    
  • Call it locally with npm:
    npm run lerna -- --help
    
    or
    npm run lerna -- init --exact
    

Any arg after -- will be passed to lerna.

XanderLuciano added a commit to XanderLuciano/lerna that referenced this issue Aug 6, 2018
I like to avoid adding global npm packages if I can, and could only find this issue on the topic: lerna#138

The solution provided is clean, simple, and effective. Since we already have a tip for CI setup, I thought it made sense to also include a small snippet about local usage. 

This simple (1 line change) change to package.json is all it takes to accomplish this.
@lock
Copy link

lock bot commented Dec 27, 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 27, 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

6 participants