util.merge-packages
TypeScript icon, indicating that this package has built-in type declarations

0.0.19 • Public • Published

util.merge-packages

Merges the contents of two package.json files

build analysis code style: prettier testing NPM

It attempts to combine two separate package.json files into one, respecting as much existing content as possible including already existing dependencies and package.json formatting.

Installation

This module uses yarn to manage dependencies and run scripts for development.

To install as an application dependency:

$ yarn add --dev util.merge-packages

To install globally (for the CLI):

$ yarn global add util.merge-packages

To build the app and run all tests:

$ yarn run all

Usage

 
import {merge} from 'util.mergePackages';
 
let dst = fs.readFileSync('package.a.json');
let src = fs.readFileSync('package.b.json');
 
// Create a new `package.json` as a string
console.log(merge(dst, src));

It allows you to do things like define scripts or dependencies that you would like to include as part of a larger project.

Merging:

{
    "name": "my-package",
    "dependencies": {
        "babel": "^5.2.2",
        "lodash": "^3.2.5"
    }
}
{
    "dependencies": {
        "babel": "^5.4.1",
        "eslint": "^0.22.1"
    }
}

results in:

{
    "name": "my-package",
    "dependencies": {
        "babel": "^5.4.1",
        "lodash": "^3.2.5",
        "eslint": "^0.22.1"
    }
}

CLI

The tool installs a command line version of this library to a program named pkgmerge. It uses the following options:

pkgmerge --out={filename}|./out.json --f1={file1.json} --f2={file2.json}

This will take file2.json (f2), merge it into file1.json (f1) and save the output to the filename given in the --out parameter.

This module was inspired by the existing module @ https://github.com/izaakschroeder/package-merge. This module uses Typescript, creates typings, uses the ava test runner, and adds it to the Travis CI/CD process.

Dependents (1)

Package Sidebar

Install

npm i util.merge-packages

Weekly Downloads

3

Version

0.0.19

License

MIT

Unpacked Size

14.1 kB

Total Files

8

Last publish

Collaborators

  • jmquigley