thin-install
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

thin-install

For large projects it can be a pain to install the entire project if you only need a subset of dependencies to accomplish a specific task like running tests or tooling.

Install

Local

npm install thin-install

Global

npm install -g thin-install

Setup

Add a subsets entry to your package.json. Each entry maps the subset name to an array of dependency names.

{
  "name": "foo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "a": "1.0.0",
    "b": "2.2.2",
    "c": "3.3.3",
    "d": "4.4.4"
  },
  "subsets": {
    "test": [
      "a",
      "b"
    ],
    "analysis": [
      "c"
    ],
    "build": [
      "a",
      "d"
    ]
  }
}

Run

CLI

Available options

  • --srcDir The directory where the source package.json file lives. The current running directly will be used if not provided.
  • --subset Install a single subset of dependencies.
  • --subsets Install multiple subsets of dependencies. Separate subset names with a space!
  • --workingDir Install the subset of dependencies into a directory other than where the source package.json file is.
  • --installCommand Use a custom install command. Useful if using Yarn or another package manager.
  • --timeout Set the amount of time (in milliseconds) that can be spent installing dependencies. Default is 300000ms
  • --force thin-install performs file operations. If something happens during the process files can be irreparably changed. By default we will only write to Git protected folders. Use this option to override that protection if you know what you are doing or are using another version control system.

Examples below are using the package.json defined above. You must provide exactly one of the subset or the subsets options.

Install in current directory

Install a subset into the current directory. (installs dependency c) npx thin-install --subset analysis

Use package.json in different directory

Use the srcDir to point to the directory where the package.json resides. (installs dependencies a and d) npx thin-install --srcDir test-dir --subset build

Single Subset

To install just a single subset of dependencies use the subset option. (installs dependencies a and b) npx thin-install --subset test

Multiple Subsets

To install multiple subsets use the subsets directory and a space separated list of subsets to install. (installs dependencies a, c, and d) npx thin-install --subsets analysis build

Install to different directory

The workingDir option allows you to install the subsets into a directory other than where the source package.json lives. npx thin-install --subset test --workingDir other-dir

Custom install command

If you are using a different tool to install node packages such as Yarn, you can provide that with the installCommand option. Default is npm install. (installs dependencies a, b, and d) npx thin-install --subsets build test --workingDir other-dir

Change install timeout

By default thin-install will timeout the installation process after a set time in milliseconds. This can be extended with the timeout option. (installs a, b, and c) npx thin-install --subsets analysis test --timeout 400000

Skip Git Check

By default, thin-install will not write the subset package.json file to a directory that is not protected by Git. Use force to override this check.

npx thin-install --subsets analysis build --force

Code

JavaScript

const ThinInstaller = require("thin-install").ThinInstaller;
const ThinInstallConfig = require("thin-install").ThinInstallConfig;

(async () => {
  const sourceDir = "";
  const force = false;
  const installCommand = "yarn";
  const subset = "foo";
  const subsets = undefined;
  const workingDir = "some-dir";
  const timeout = Number.MAX_SAFE_INTEGER;
  const config: ThinInstallConfig = {
    sourceDir,
    force,
    installCommand,
    subset,
    subsets,
    workingDir,
    timeout,
  };

  await new ThinInstaller(config).run();
})();

TypeScript

import { ThinInstaller, ThinInstallConfig } from "thin-install";

(async () => {
  const sourceDir = "";
  const force = false;
  const installCommand = "yarn";
  const subset = undefined;
  const subsets = ["foo", "bar"];
  const workingDir = "some-dir";
  const timeout = Number.MAX_SAFE_INTEGER;
  const config: ThinInstallConfig = {
    sourceDir,
    force,
    installCommand,
    subset,
    subsets,
    workingDir,
    timeout,
  };

  await new ThinInstaller(config).run();
})();

Contribute

Code

You can get all source code by running.

  • git clone https://MikeWestbrook@dev.azure.com/MikeWestbrook/MikesNodeModules/_git/thin-install

Install

Install dependencies

  • npm install

Build

Build once

  • npm run tsc

Build on saved changes

  • npm run watch

Test

Single Run

npm test

Test on Save

npm run test:watch

Debug Test

Run the Test task in VSCode

Debug

  • In VSCode, use the Run launch config. You can change inputs in the launch.json file.

Readme

Keywords

none

Package Sidebar

Install

npm i thin-install

Weekly Downloads

1,144

Version

2.0.2

License

MIT

Unpacked Size

23.9 kB

Total Files

7

Last publish

Collaborators

  • albinopython