Détail du package

link-parent-bin

nicojs8.6kISCobsolète3.0.0

readme

Mutation testing badge CI

Link parent bin

Link the bins of parent (dev) dependencies to the child packages in a multi-package lerna-like project. Stuff just works as expected.

NOTE: This package is no longer needed and thus deprecated. Since recent NPM releases, any parent directory's "node_modules/.bin" is automatically added to the PATH when using npm run.

About

Let's say your repo looks like this:

root/
  package.json
  packages/
    package-1/
      package.json
    package-2/
      package.json

Well... you're probably managing your devDependencies at root level only. For example: you have one mocha installed at root with npm i -D mocha.

Now if you add an npm script in package-1/package.json:

"scripts": {
    "test": "mocha"
}

And run:

$ npm run test

> package-1@0.0.1 test /package-1
> mocha

'mocha' is not recognized as an internal or external command

npm ERR!

...thats not so nice. You're basically forced to run all npm scripts from the root level. But after running link-parent-bin:

$ npm run test

> package-1@0.0.1 test /package-1
> mocha

  linked from parent...
      √ and it worked!

Getting started

Install the package in the root of your multiple packages repository.

npm i -D link-parent-bin

Add the following npm script in your root package.json:

"scripts": {
    "link-parent-bin": "link-parent-bin"
}

Run it with npm run link-parent-bin.

npm run link-parent-bin

[INFO] ParentBinLinker - Linking dependencies ["mocha"] under children ["package-1", "package-2"]

And your done.

Improve your workflow

Since you're probably not releasing your parent module anyway, it might be better to add the linking to the post-install step:

"scripts": {
    "postinstall": "link-parent-bin"
}

-or if you're using lerna

"scripts": {
    "postinstall": "lerna bootstrap && link-parent-bin"
}

This way, other developers don't have to run this script manually.

Command line options

$ node_modules/.bin/link-parent-bin --help

Usage: link-parent-bin [options]

Options:
  -V, --version                                 output the version number
  -c, --child-directory-root <child-directory>  The directory that hosts the child packages relative to the parent root. (default: "packages")
  -d, --link-dev-dependencies <true|false>      Enables linking of parents `devDependencies`. Defaults to: true (default: true)
  -s, --link-dependencies <true|false>          Enables linking of parents `dependencies`. Defaults to: false (default: false)
  -o, --link-local-dependencies <true|false>    Enables linking of parents `localDependencies`. Defaults to: false (default: false)
  -l, --log-level <debug|info|error|off>        Set the log level (default: "info")
  --filter <pattern>                            Specify a [minimatch](https://www.npmjs.com/package/minimatch) glob pattern to specify which child packages under the child packages directory should receive symlinks. (default: "*")
  -h, --help                                    display help for command

Use programmatically

const { ParentBinLinker } = require('link-parent-bin');
const linker = new ParentBinLinker({ childDirectoryRoot: 'packages', linkDevDependencies: true, linkDependencies: false, linkLocalDependencies: false });
linker.linkBinsToChildren()
    .then(() => console.log('done'))
    .catch(err => console.error('Error Linking packages', err));

Type declaration files are included for the TypeScript developers out there.

changelog

3.0.0 (2022-05-27)

Features

  • deprecate: Add note about deprecation (f3921c5)
  • node version: Update min version to 14 (6a52cd0)

BREAKING CHANGES

  • deprecate: This package is deprecated and should no longer be used. Recent NPM versions automatically add any parent's node_modules/.bin to the PATH when executing an npm run command, rendering this package no longer needed
  • node version: Node 10 or 12 are no longer supported officially.

2.0.0 (2020-10-28)

chore

  • general quality of life improvements (#25) (f78820c)
  • deps: update dependencies (6ae5ec8)

Features

BREAKING CHANGES

  • JS output files are now located in the dist directory. This only has an effect if you're requiring directly from it.
  • deps: Node 8 is no longer actively supported

1.0.2 (2019-07-09)

Features

  • log level: support log level off (#11) (f0cdec3)

1.0.1 (2019-07-02)

Bug Fixes

  • deps: update log4js and commander versions (4d6982b)

1.0.0 (2019-02-12)

0.3.0 (2019-01-27)

Features

  • windows shim link: Preserve shimlink if it already exists (a15e13e)

0.2.3 (2018-08-30)

0.2.2 (2018-08-30)

0.2.1 (2018-08-30)

Bug Fixes

  • deps: Update log4js and commander dependencies (#9) (44d3439)

0.2.0 (2018-04-18)

Features

  • pkg.bin: support for binaries defined as string rather than object (#6) (123c817)

0.1.3 (2017-08-11)

Features

  • link: Ignore EEXIST error (020a7e9)

0.1.2 (2017-06-15)

Features

  • local-dependencies: Support local dependencies (44731e8)

0.1.1 (2017-04-14)

0.1.0 (2017-04-13)