2019-04-05 15:55:41 -07:00
2019-04-05 15:49:59 -07:00
2019-04-04 13:01:52 -07:00
2019-04-04 13:01:52 -07:00
2019-04-04 13:01:52 -07:00
2019-04-04 13:01:52 -07:00
2019-04-04 13:01:52 -07:00
2019-04-05 15:49:59 -07:00
2019-04-05 15:55:41 -07:00
2019-04-05 15:49:59 -07:00

pkgcomp

Node package compare and change runner.

GitHub license npm Project Status

This tool will execute a command if the dependencies or lock files of your module have changed since the last time it was run. Any of the following will be considered a change:

  • If the dependencies or devDependencies in package.json change
  • If the dependencies or devDependencies in any of your workspaces change
    • Uses workspaces property in root package.json, works with Yarn workspaces
  • If one of the files in your checkFiles config's md5 hash changes

If the command exits with a non-zero exit code, pkgcomp will exit with the same exit code.

NOTE: Out of the box the script will do nothing, you have to provide a command to run, via the cmd config. See Configuration below.

Usage

Simply install the package and run it from the command line in your project. You can install it globally and run it that way, but installing locally is generally better.

yarn add -D pkgcomp
npx pkgcomp

NOTE: Out of the box the script will do nothing, you have to provide a command to run, via the cmd config. See Configuration below.

You can also set the command, and control how the script works, via the available command line arguments

In node

Alternatively, you can use the module in node by passing in a config object, some identifier to key changes on (name from package.json is what the CLI uses), and an options object to enable verbose mode or force the command to be run.

const pkgcomp = require('pkgcomp');
const config = { cmd: 'yarn install' }; // see Configuration below
const options = { verbose: false, force: false }; // see CLI Arguments below

// module returns a Promise
pkgcomp(config, 'my-package', options)
  .then((payload) => {
    console.log({ payload }); // checkFiles hashes, dependencies, and devDependencies
  })
  .catch(err => {
    // err has `exitCode` and `cmd` properties
    console.error(err);
    process.exit(err.exitCode);
  })

Configuration

Configuration is provided as JSON, and can be defined in any of the following (listed by precidence):

  • .config/pkgcomp.json
  • .pkgcomp.json
  • pkgcomp.json
  • In a pkgcomp key in your package.json

Config options

Name Default Description
checkFiles ['package-lock.json', 'yarn.lock'] Additional files to checksum and compare, files that are not included will be skipped
rootDir process.cwd() The root path to your project
dataDir <Home>/.local/share Directory where this module's data should be written to
cmd false Command to run when changes are found; false or an empty string means do nothing

Example configs

As a standalone file:

{
  "checkFiles": ["yarn.lock"],
  "cmd": "yarn install"
}

As a property in package.json:

{
  "name": "your-package",
  "version": "0.0.0",
  ...
  "pkgcomp": {
    "checkFiles": ["yarn.lock"],
    "cmd": "yarn install"
  }
}

CLI Arguments

Argument Default Description
--verbose false Shows more verbose output, like if the command is being skipped or a file in checkFiles does not exist
--force false Runs your command regardless of whether or not there were changes in the package
--cmd Specify the command to run when changes are found (ex. --cmd="yarn install")

License

MIT © w33ble

Description
No description provided
Readme 592 KiB
Languages
JavaScript 100%