Skip to content

Commit

Permalink
feat(core): add support for config files
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMason committed Aug 22, 2020
1 parent 6cb3462 commit cfd5df3
Show file tree
Hide file tree
Showing 19 changed files with 336 additions and 184 deletions.
11 changes: 11 additions & 0 deletions .syncpackrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"options": {
"dev": true,
"indent": " ",
"semverRange": "",
"peer": true,
"prod": true,
"filter": "",
"source": []
}
}
170 changes: 92 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
# syncpack

> Manage multiple package.json files, such as in Lerna Monorepos and Yarn Workspaces
> Manage multiple package.json files, such as in Lerna Monorepos and Yarn/Pnpm Workspaces
[![NPM version](http://img.shields.io/npm/v/syncpack.svg?style=flat-square)](https://www.npmjs.com/package/syncpack) [![NPM downloads](http://img.shields.io/npm/dm/syncpack.svg?style=flat-square)](https://www.npmjs.com/package/syncpack) [![Build Status](http://img.shields.io/travis/JamieMason/syncpack/master.svg?style=flat-square)](https://travis-ci.org/JamieMason/syncpack) [![Maintainability](https://api.codeclimate.com/v1/badges/516439365fdd0e3c6526/maintainability)](https://codeclimate.com/github/JamieMason/syncpack/maintainability)
[![NPM version](http://img.shields.io/npm/v/syncpack.svg?style=flat-square)](https://www.npmjs.com/package/syncpack)
[![NPM downloads](http://img.shields.io/npm/dm/syncpack.svg?style=flat-square)](https://www.npmjs.com/package/syncpack)
[![Build Status](http://img.shields.io/travis/JamieMason/syncpack/master.svg?style=flat-square)](https://travis-ci.org/JamieMason/syncpack)
[![Maintainability](https://api.codeclimate.com/v1/badges/516439365fdd0e3c6526/maintainability)](https://codeclimate.com/github/JamieMason/syncpack/maintainability)

## Table of Contents

- [🌩 Installation](#-installation)
- [🕵🏾‍♀️ Resolving Packages](#♀️-resolving-packages)
- [📝 Commands](#-commands)
- [🙋🏿‍♀️ Getting Help](#♀️-getting-help)
- [👀 Other Projects](#-other-projects)
- [🤓 Author](#-author)
- [🌩 Installation](#-installation)
- [📝 Commands](#-commands)
- [fix-mismatches](#fix-mismatches)
- [format](#format)
- [list](#list)
- [list-mismatches](#list-mismatches)
- [set-semver-ranges](#set-semver-ranges)
- [🛠 Configuration File](#-configuration-file)
- [🕵🏾‍♀️ Resolving Packages](#️-resolving-packages)
- [🙋🏿‍♀️ Getting Help](#️-getting-help)
- [👀 Other Projects](#-other-projects)

## 🌩 Installation

npm install --global syncpack

## 🕵🏾‍♀️ Resolving Packages

package.json files are resolved in this order of precendence:

1. If `--source` [glob patterns](https://github.com/isaacs/node-glob#glob-primer) are provided, use those.
2. If using [Yarn Workspaces](https://yarnpkg.com/lang/en/docs/workspaces/), read `workspaces` from `./package.json`.
3. If using [Lerna](https://lerna.js.org/), read `packages` from `./lerna.json`.
4. Default to `'package.json'` and `'packages/*/package.json'`.

## 📝 Commands

### fix-mismatches

Ensure that multiple packages requiring the same dependency define the same version, so that every package requires eg. `[email protected]`, instead of a combination of `[email protected]`, `[email protected]`, and `[email protected]`.
Ensure that multiple packages requiring the same dependency define the same version, so that every package requires eg.
`[email protected]`, instead of a combination of `[email protected]`, `[email protected]`, and `[email protected]`.

<details>
<summary>Options</summary>
Expand Down Expand Up @@ -69,7 +69,9 @@ syncpack fix-mismatches --indent " "

### format

Organise package.json files according to a conventional format, where fields appear in a predictable order and nested fields are ordered alphabetically. Shorthand properties are used where available, such as the `"repository"` and `"bugs"` fields.
Organise package.json files according to a conventional format, where fields appear in a predictable order and nested
fields are ordered alphabetically. Shorthand properties are used where available, such as the `"repository"` and
`"bugs"` fields.

<details>
<summary>Options</summary>
Expand Down Expand Up @@ -170,7 +172,8 @@ syncpack list-mismatches --dev --peer

### set-semver-ranges

Ensure dependency versions used within `"dependencies"`, `"devDependencies"`, and `"peerDependencies"` follow a consistent format.
Ensure dependency versions used within `"dependencies"`, `"devDependencies"`, and `"peerDependencies"` follow a
consistent format.

<details>
<summary>Options</summary>
Expand Down Expand Up @@ -210,86 +213,97 @@ syncpack set-semver-ranges --indent " "

</details>

<details>
<summary>Supported Ranges</summary>

< <1.4.2
<= <=1.4.2
"" 1.4.2
~ ~1.4.2
^ ^1.4.2
>= >=1.4.2
> >1.4.2
* *

</details>

## 🙋🏿‍♀️ Getting Help

Get help with issues by creating a [Bug Report] or discuss ideas by opening a [Feature Request].
## 🛠 Configuration File

[bug report]: https://github.com/JamieMason/syncpack/issues/new?template=bug_report.md
Creating a configuration file is optional, syncpack will search up the directory tree in the following places:

[feature request]: https://github.com/JamieMason/syncpack/issues/new?template=feature_request.md
- a `syncpack` property in `package.json`
- a `.syncpackrc` file in JSON or YAML format
- a `.syncpackrc.json`, `.syncpackrc.yaml`, `.syncpackrc.yml`, `.syncpackrc.js`, or `.syncpackrc.cjs` file
- a `syncpack.config.js` or `syncpack.config.cjs` CommonJS module exporting an object

## 👀 Other Projects
### Default Configuration

If you find my Open Source projects useful, please share them ❤️

- [**eslint-formatter-git-log**](https://github.com/JamieMason/eslint-formatter-git-log)<br>ESLint Formatter featuring Git Author, Date, and Hash
- [**eslint-plugin-move-files**](https://github.com/JamieMason/eslint-plugin-move-files)<br>Move and rename files while keeping imports up to date
- [**eslint-plugin-prefer-arrow-functions**](https://github.com/JamieMason/eslint-plugin-prefer-arrow-functions)<br>Convert functions to arrow functions
- [**ImageOptim-CLI**](https://github.com/JamieMason/ImageOptim-CLI)<br>Automates ImageOptim, ImageAlpha, and JPEGmini for Mac to make batch optimisation of images part of your automated build process.
- [**Jasmine-Matchers**](https://github.com/JamieMason/Jasmine-Matchers)<br>Write Beautiful Specs with Custom Matchers
- [**karma-benchmark**](https://github.com/JamieMason/karma-benchmark)<br>Run Benchmark.js over multiple Browsers, with CI compatible output
- [**self-help**](https://github.com/JamieMason/self-help#readme)<br>Interactive Q&A Guides for Web and the Command Line

## 🤓 Author

<img src="https://www.gravatar.com/avatar/acdf106ce071806278438d8c354adec8?s=100" align="left">

I'm [Jamie Mason] from [Leeds] in England, I began Web Design and Development in 1999 and have been Contracting and offering Consultancy as Fold Left Ltd since 2012. Who I've worked with includes [Sky Sports], [Sky Bet], [Sky Poker], The [Premier League], [William Hill], [Shell], [Betfair], and Football Clubs including [Leeds United], [Spurs], [West Ham], [Arsenal], and more.

<div align="center">
```json
{
"dev": true,
"filter": ".",
"indent": " ",
"peer": true,
"prod": true,
"semverRange": "",
"source": ["package.json", "packages/*/package.json"]
}
```

[![Follow JamieMason on GitHub][github badge]][github]      [![Follow fold_left on Twitter][twitter badge]][twitter]
### `dev`, `peer`, and `prod`

</div>
Whether to search within `devDependencies`, `peerDependencies`, and `dependencies` respectively. All of these locations
are searched by default but they can be disabled individually in your config file. If any are set via the command line
options `--dev`, `--peer`, or `--prod` then only the options you provide will be searched.

<!-- images -->
### `filter`

[github badge]: https://img.shields.io/github/followers/JamieMason.svg?style=social&label=Follow
A string which will be passed to `new RegExp()` to match against package names that should be included.

[twitter badge]: https://img.shields.io/twitter/follow/fold_left.svg?style=social&label=Follow
### `indent`

<!-- links -->
The character(s) to be used to indent your package.json files when writing to disk.

[arsenal]: https://www.arsenal.com
### `semverRange`

[betfair]: https://www.betfair.com
Defaulted to `""` to ensure that exact dependency versions are used instead of loose ranges, but this can be overridden
in your config file or via the `--semver-range` command line option.

[github]: https://github.com/JamieMason
#### Supported Ranges

[jamie mason]: https://www.linkedin.com/in/jamiemasonleeds
```
< <1.4.2
<= <=1.4.2
"" 1.4.2
~ ~1.4.2
^ ^1.4.2
>= >=1.4.2
> >1.4.2
* *
```

[leeds united]: https://www.leedsunited.com/
### `source`

[leeds]: https://www.instagram.com/visitleeds
Defaults to `["package.json", "packages/*/package.json"]` to match most Projects using Lerna or Yarn Workspaces, but
this can be overridden in your config file or via multiple `--source` command line options. Supports any patterns
supported by [glob](https://github.com/isaacs/node-glob).

[premier league]: https://www.premierleague.com
## 🕵🏾‍♀️ Resolving Packages

[shell]: https://www.shell.com
package.json files are resolved in this order of precendence:

[sky bet]: https://www.skybet.com
1. If `--source` [glob patterns](https://github.com/isaacs/node-glob#glob-primer) are provided, use those.
2. If using [Yarn Workspaces](https://yarnpkg.com/lang/en/docs/workspaces/), read `workspaces` from `./package.json`.
3. If using [Lerna](https://lerna.js.org/), read `packages` from `./lerna.json`.
4. If using [Pnpm](https://pnpm.js.org/), read `packages` from `./pnpm-workspace.yaml`.
5. Default to `'package.json'` and `'packages/*/package.json'`.

[sky poker]: https://www.skypoker.com
## 🙋🏿‍♀️ Getting Help

[sky sports]: https://www.skysports.com
Get help with issues by creating a [Bug Report] or discuss ideas by opening a [Feature Request].

[spurs]: https://www.tottenhamhotspur.com
[bug report]: https://github.com/JamieMason/syncpack/issues/new?template=bug_report.md
[feature request]: https://github.com/JamieMason/syncpack/issues/new?template=feature_request.md

[twitter]: https://twitter.com/fold_left
## 👀 Other Projects

[west ham]: https://www.whufc.com
If you find my Open Source projects useful, please share them ❤️

[william hill]: https://www.williamhill.com
- [**eslint-formatter-git-log**](https://github.com/JamieMason/eslint-formatter-git-log)<br>ESLint Formatter featuring
Git Author, Date, and Hash
- [**eslint-plugin-move-files**](https://github.com/JamieMason/eslint-plugin-move-files)<br>Move and rename files while
keeping imports up to date
- [**eslint-plugin-prefer-arrow-functions**](https://github.com/JamieMason/eslint-plugin-prefer-arrow-functions)<br>Convert
functions to arrow functions
- [**ImageOptim-CLI**](https://github.com/JamieMason/ImageOptim-CLI)<br>Automates ImageOptim, ImageAlpha, and JPEGmini
for Mac to make batch optimisation of images part of your automated build process.
- [**Jasmine-Matchers**](https://github.com/JamieMason/Jasmine-Matchers)<br>Write Beautiful Specs with Custom Matchers
- [**karma-benchmark**](https://github.com/JamieMason/karma-benchmark)<br>Run Benchmark.js over multiple Browsers, with
CI compatible output
- [**self-help**](https://github.com/JamieMason/self-help#readme)<br>Interactive Q&A Guides for Web and the Command Line
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"@manypkg/get-packages": "1.1.0",
"chalk": "4.1.0",
"commander": "6.0.0",
"cosmiconfig": "7.0.0",
"expect-more": "0.8.0",
"fs-extra": "9.0.1",
"glob": "7.1.6",
"semver": "7.3.2"
Expand Down
19 changes: 11 additions & 8 deletions src/bin-fix-mismatches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import chalk from 'chalk';
import { fixMismatchesToDisk } from './commands/fix-mismatches';
import { option } from './constants';
import { getConfig } from './lib/get-config';
import program = require('commander');

program.description(
Expand Down Expand Up @@ -54,11 +55,13 @@ program
.option(...option.indent)
.parse(process.argv);

fixMismatchesToDisk({
dev: Boolean(program.dev),
filter: new RegExp(program.filter ? program.filter : '.'),
indent: program.indent ? program.indent : ' ',
peer: Boolean(program.peer),
prod: Boolean(program.prod),
sources: Array.isArray(program.source) ? program.source : [],
});
fixMismatchesToDisk(
getConfig({
dev: program.dev,
filter: program.filter,
indent: program.indent,
peer: program.peer,
prod: program.prod,
source: program.source,
}),
);
11 changes: 7 additions & 4 deletions src/bin-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import chalk from 'chalk';
import { formatToDisk } from './commands/format';
import { option } from './constants';
import { getConfig } from './lib/get-config';
import program = require('commander');

program.description(
Expand Down Expand Up @@ -45,7 +46,9 @@ program
.option(...option.indent)
.parse(process.argv);

formatToDisk({
indent: program.indent ? program.indent : ' ',
sources: Array.isArray(program.source) ? program.source : [],
});
formatToDisk(
getConfig({
indent: program.indent,
source: program.source,
}),
);
17 changes: 10 additions & 7 deletions src/bin-list-mismatches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import chalk from 'chalk';
import { listMismatchesFromDisk } from './commands/list-mismatches';
import { option } from './constants';
import { getConfig } from './lib/get-config';
import program = require('commander');

program.description(
Expand Down Expand Up @@ -50,10 +51,12 @@ program
.option(...option.filter)
.parse(process.argv);

listMismatchesFromDisk({
dev: Boolean(program.dev),
filter: new RegExp(program.filter ? program.filter : '.'),
peer: Boolean(program.peer),
prod: Boolean(program.prod),
sources: Array.isArray(program.source) ? program.source : [],
});
listMismatchesFromDisk(
getConfig({
dev: program.dev,
filter: program.filter,
peer: program.peer,
prod: program.prod,
source: program.source,
}),
);
17 changes: 10 additions & 7 deletions src/bin-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import chalk from 'chalk';
import { listFromDisk } from './commands/list';
import { option } from './constants';
import { getConfig } from './lib/get-config';
import program = require('commander');

program.description(' List all dependencies required by your packages.');
Expand Down Expand Up @@ -46,10 +47,12 @@ program
.option(...option.filter)
.parse(process.argv);

listFromDisk({
dev: Boolean(program.dev),
filter: new RegExp(program.filter ? program.filter : '.'),
peer: Boolean(program.peer),
prod: Boolean(program.prod),
sources: Array.isArray(program.source) ? program.source : [],
});
listFromDisk(
getConfig({
dev: program.dev,
filter: program.filter,
peer: program.peer,
prod: program.prod,
source: program.source,
}),
);
21 changes: 12 additions & 9 deletions src/bin-set-semver-ranges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import chalk from 'chalk';
import { setSemverRangesToDisk } from './commands/set-semver-ranges';
import { option } from './constants';
import { getConfig } from './lib/get-config';
import program = require('commander');

program.description(
Expand Down Expand Up @@ -66,12 +67,14 @@ program
.option(...option.semverRange)
.parse(process.argv);

setSemverRangesToDisk({
dev: Boolean(program.dev),
filter: new RegExp(program.filter ? program.filter : '.'),
indent: program.indent ? program.indent : ' ',
peer: Boolean(program.peer),
prod: Boolean(program.prod),
semverRange: program.semverRange ? program.semverRange : '',
sources: Array.isArray(program.source) ? program.source : [],
});
setSemverRangesToDisk(
getConfig({
dev: program.dev,
filter: program.filter,
indent: program.indent,
peer: program.peer,
prod: program.prod,
semverRange: program.semverRange,
source: program.source,
}),
);
Loading

0 comments on commit cfd5df3

Please sign in to comment.