• Stars
    star
    106
  • Rank 325,871 (Top 7 %)
  • Language
    TypeScript
  • Created over 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Installs npm/yarn packages locally without symlink. Exactly the same as your production installation, no compromises.

Mutation testing badge CI

Install local

Installs npm/yarn packages locally without symlink, also in npm 5. Exactly the same as your production installation, no compromises.

Getting started

Install with

npm install -g install-local

or for occasional use, without installation

$ npx install-local

You can use install-local from command line or programmatically.

Command line:

Usage: 
$ install-local                                       # 1
$ install-local [options] <directory>[ <directory>]   # 2
$ install-local --target-siblings                     # 3

Installs a package from the filesystem into the current directory.

Options:

  • -h, --help: Output this help
  • -S, --save: Saved packages will appear in your package.json under "localDependencies"
  • -T, --target-siblings: Instead of installing into this package, this package gets installed into sibling packages which depend on this package by putting it in the "localDependencies". Useful in a lerna style monorepo.

Examples:

  • install-local Install the "localDependencies" of your current package
  • install-local .. Install the package located in the parent folder into the current directory.
  • install-local --save ../sibling ../sibling2 Install the packages in 2 sibling directories into the current directory.
  • install-local --help Print this help

See Programmatically to see how use install-local from node.

Why?

Why installing packages locally? There are a number of use cases.

  1. You want to test if the installation of your package results in expected behavior (test your .npmignore file, etc)
  2. You want to install a package locally in a lernajs-style monorepo
  3. You just want to test a fork of a dependency, after building it locally.

What's wrong with npm-link?

Well... nothing is wrong with npm link. It's just not covering all use cases.

For example, if your using typescript and you npm link a dependency from a parent directory, you might end up with infinite ts source files, resulting in an out-of-memory error:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

An other reason is with npm link your not testing if your package actually installs correctly. You might have files in there that will not be there after installation.

Can't i use npm i file:?

You could use npm install file:.. versions of npm prior to version 5. It installed the package locally. Since version 5, the functionality changed to npm link instead. More info here: npm/npm#15900

How to guarantee a production-like install

To guarantee the production-like installation of your dependency, install-local uses npm pack and npm install <tarball file> under the hood. This is as close as production-like as it gets.

Programmatically

Typings are included for all your TypeScript programmers out there

const { cli, execute, Options, progress, LocalInstaller} = require('install-local');

Use the CLI programmatically

Execute the cli functions with the cli function. It returns a promise:

cli(['node', 'install-local', '--save', '../sibling-dependency', '../sibling-dependency2'])
    .then(() => console.log('done'))
    .catch(err => console.error('err'));

Or a slightly cleaner api:

execute({ 
    validate: () => true, 
    dependencies: ['../sibling-dependency', '../sibling-dependency2'], 
    save: true, 
    targetSiblings: false 
})

Install dependencies locally

Use the LocalInstaller to install local dependencies into multiple directories.

For example:

const localInstaller = new LocalInstaller({
   /*1*/ '.': ['../sibling1', '../sibling2'],
   /*2*/ '../dependant': ['.']
});
progress(localInstaller);
localInstaller.install()
    .then(() => console.log('done'))
    .catch(err => console.error(err));
  1. This will install packages located in the directories "sibling1" and "sibling2" next to the current working directory into the package located in the current working directory ('.')
  2. This will install the package located in the current working directory ('.') into the package located in the "dependant" directory located next to the current working directory.

Construct the LocalInstall by using an object. The properties of this object are the relative package locations to install into. The array values are the packages to be installed. Use the install() method to install, returns a promise.

If you want the progress reporting like the CLI has: use progress(localInstaller);

Passing npm env variables

In some cases it might be useful to control the env variables for npm. For example when you want npm to rebuild native node modules against Electron headers. You can do it by passing options to LocalInstaller's constructor.

const localInstaller = new LocalInstaller(
   { '.': ['../sibling'] },
   { npmEnv: { envVar: 'envValue' } }
);

Because the value provided for npmEnv will override the environment of the npm execution, you may want to extend the existing environment so that required values such as PATH are preserved:

const localInstaller = new LocalInstaller(
   { '.': ['../sibling'] },
   { npmEnv: Object.assign({}, process.env, { envVar: 'envValue' }) }
);

More Repositories

1

typed-inject

Type safe dependency injection for TypeScript
TypeScript
439
star
2

typed-html

TypeSafe HTML templates using TypeScript. No need to learn a template library.
TypeScript
336
star
3

node-link-parent-bin

A tool to link the bins of the your npm dependencies to child packages in a node multi-package repository
TypeScript
43
star
4

html2commonmark

Converts HTML to markdown using commonmark.js. Compliant with the commmonmark markdown specification.
TypeScript
17
star
5

proposal-comments-as-types

ECMAScript proposal for comment syntax that is does stuff - Stage 0
12
star
6

node-surrial

Serialize anything. Pretty surreal!
TypeScript
8
star
7

lit-xml

🔥 Burning your XML documents to the ground? Yes please. In the mean time, let's use lit-xml.
TypeScript
6
star
8

typescript-eslint-prettier-starter

A starter project which integrates typescript, eslint and prettier
3
star
9

typescript-tips-and-tricks

Top 10 tips and tricks for TypeScript
HTML
2
star
10

poc-finch-tls

A proof of concept to use Finagle Finch with TLS
Scala
2
star
11

mutation-switch-instrumenter

👽 An example implementation for mutation switching in JavaScript and TypeScript.
TypeScript
2
star
12

angular-examples-nov-2021-2

Samples from angular course
TypeScript
1
star
13

reproduce-conemu-child-process-environment-bug

Reproduce a ConEmu only bug
JavaScript
1
star
14

spring-boot-github-api

Demo application to show of spring boot with angularjs
Java
1
star
15

angular-stryker-example

An example project on how to use Stryker, the mutation testing framework, in an Angular (CLI) project
JavaScript
1
star
16

mediummark-editor

A text editor in the browser which let you easily switch between markdown and the medium WYSIWYG editor
JavaScript
1
star
17

testbash-mutation-testing-presentation

Presentation for TestBash 2018
CSS
1
star
18

angular2-music-browser

An music browser written with angular2 alpha
JavaScript
1
star