Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

linklocal

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

linklocal

Install local dependencies as symlinks.

  • 2.4.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2K
decreased by-69.76%
Maintainers
1
Weekly downloads
 
Created
Source

linklocal

Requires npm 2.0.0 and above. Links both development and production dependencies.

Build Status

Installation

npm install -g linklocal

Usage

linklocal --help

  Usage: linklocal [options] <dir>

  Options:

    -h, --help             output usage information
    -V, --version          output the version number
    -u, --unlink           Unlink local dependencies
    -l, --link             Link local dependencies [default]
    --list                 List all local dependencies regardless whether they are linked or not.
    -r, --recursive        Link recursively
    -f, --format [format]  output format
    --links                Output only symlinks (--format="%s")
    --files                Output only symlink targets (--format="%h") [default]
    --long                 Output the symlink to hardlink mapping (--format="%s -> %h")
    --absolute             Format output paths as absolute paths
    -q, --unique           Only unique lines of output

  Examples

    $ linklocal                 # link local deps in current dir
    $ linklocal link            # link local deps in current dir
    $ linklocal -r              # link local deps recursively
    $ linklocal unlink          # unlink only in current dir
    $ linklocal unlink -r       # unlink recursively

    $ linklocal list            # list all local deps, ignores link status
    $ linklocal list -r         # list all local deps recursively, ignoring link status

    $ linklocal -- mydir        # link local deps in mydir
    $ linklocal unlink -- mydir # unlink local deps in mydir

  Formats

    %s: relative path to symlink
    %S: absolute path to symlink
    %h: relative real path to symlink target
    %H: absolute real path to symlink target

    relative paths are relative to cwd

Linking

linklocal creates symlinks to any local dependencies it finds in your package.json.

# from test/banana
> linklocal
node_modules/apple -> ../apple

Linked 1 dependency
> ls -l node_modules
total 8
lrwxr-xr-x  1 timoxley  staff  11 20 Sep 01:39 apple -> ../../apple

Unlinking

You can unlink all local links using linklocal --unlink.

# from test/banana
> linklocal --unlink
node_modules/apple -> ../apple

Unlinked 1 dependency

> ls -l node_modules

>

Recursively Linking local dependencies in local dependencies

If your local dependencies might have local dependencies, you can use linklocal -r to recursively link all local dependencies:

bowl depends on banana banana depends on apple

With Recursion

apple gets linked into banana

node_modules/apple -> ../apple
node_modules/banana -> ../banana
../banana/node_modules/apple -> ../apple
node_modules/@nuts/almond -> ../almond

Linked 4 dependencies
Without Recursion

apple does not get linked into banana

# from test/bowl
> linklocal
node_modules/apple -> ../apple
node_modules/banana -> ../banana
node_modules/@nuts/almond -> ../almond

Linked 3 dependencies

Why

npm 2.0.0 supports specifying local dependencies in your package.json:

> npm install --save ../apple
> cat package.json
{
  "name": "bowl",
  "version": "1.0.0",
  "dependencies": {
    "apple": "file:../apple"
  }
}

npm install will copy (and npm install) the package into the target's node_module's hierarchy.

This is not an ideal workflow during development as any time you modify your local dependency, you must reinstall it in every location that depends on it. If you do not update all copies, you will have different versions of the same code, probably under the same version number.

Global npm link dependencies are also not ideal as packages clobber each other across projects.

By symlinking local dependencies while in development, changes can be instantly consumed by dependees, effects are limited to the current package and you can be more certain local dependees are using the latest changes.

Recommendations

linklocal does not install dependencies of linked dependencies. To have dependencies installed, use timoxley/bulk in a script like:

{
  "name": "my-app",
  "scripts": {
    "dev": "linklocal link -r && linklocal list -r | bulk -c 'npm install --production'",
    "prepublish": "if [[ $NODE_ENV != 'production' ]]; then npm run dev; fi"
  }
}

Caveats

  • linklocal does not install dependencies of linked dependencies, as such you typically end up installing dependencies of linked dependencies twice: once during npm install, then again after linklocal

See Also

License

MIT

Keywords

FAQs

Package last updated on 11 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc