Skip to content

Commit a5a45dd

Browse files
maraisrJamieMason
authored andcommitted
feat(cli): add support for yarn workspaces
Closes #20 Closes #22
1 parent 1d72956 commit a5a45dd

10 files changed

Lines changed: 222 additions & 54 deletions

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CHANGELOG.md
2+
DEPENDENCIES.md

README.md

Lines changed: 69 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# syncpack
22

3-
> Manage multiple package.json files, such as in Lerna Monorepos
3+
> Manage multiple package.json files, such as in Lerna Monorepos and Yarn
4+
> Workspaces
45
56
[![NPM version](http://img.shields.io/npm/v/syncpack.svg?style=flat-square)](https://www.npmjs.com/package/syncpack)
67
[![NPM downloads](http://img.shields.io/npm/dm/syncpack.svg?style=flat-square)](https://www.npmjs.com/package/syncpack)
@@ -14,21 +15,34 @@
1415
[![Follow JamieMason on GitHub](https://img.shields.io/github/followers/JamieMason.svg?style=social&label=Follow)](https://github.com/JamieMason)
1516
[![Follow fold_left on Twitter](https://img.shields.io/twitter/follow/fold_left.svg?style=social&label=Follow)](https://twitter.com/fold_left)
1617

17-
## :cloud: Installation
18+
## ☁️ Installation
1819

1920
```
2021
npm install --global syncpack
2122
```
2223

23-
## :memo: Commands
24+
## 🕵🏾‍♀️ Resolving Packages
25+
26+
package.json files are resolved in this order of precendence:
27+
28+
1. If `--source`
29+
[glob patterns](https://github.com/isaacs/node-glob#glob-primer) are
30+
provided, use those.
31+
1. If using [Yarn Workspaces](https://yarnpkg.com/lang/en/docs/workspaces/),
32+
read `workspaces` from `./package.json`.
33+
1. If using [Lerna](https://lerna.js.org/), read `packages` from `./lerna.json`.
34+
1. Default to `'package.json'` and `'packages/*/package.json'`.
35+
36+
## 📝 Commands
2437

2538
### fix-mismatches
2639

2740
Ensure that multiple packages requiring the same dependency define the same
2841
version, so that every package requires eg. `react@16.4.2`, instead of a
2942
combination of `react@16.4.2`, `react@0.15.9`, and `react@16.0.0`.
3043

31-
#### Options
44+
<details>
45+
<summary>Options</summary>
3246

3347
```
3448
-s, --source [pattern] glob pattern for package.json files to read from
@@ -39,10 +53,13 @@ combination of `react@16.4.2`, `react@0.15.9`, and `react@16.0.0`.
3953
-h, --help output usage information
4054
```
4155

42-
#### Examples
56+
</details>
57+
58+
<details>
59+
<summary>Examples</summary>
4360

4461
```bash
45-
# uses packages defined in lerna.json by default
62+
# uses defaults for resolving packages
4663
syncpack fix-mismatches
4764
# uses packages defined by --source when provided
4865
syncpack fix-mismatches --source "apps/*/package.json"
@@ -58,25 +75,31 @@ syncpack fix-mismatches --dev --peer
5875
syncpack fix-mismatches --indent " "
5976
```
6077

78+
</details>
79+
6180
### format
6281

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

68-
#### Options
87+
<details>
88+
<summary>Options</summary>
6989

7090
```
7191
-s, --source [pattern] glob pattern for package.json files to read from
7292
-i, --indent [value] override indentation. defaults to " "
7393
-h, --help output usage information
7494
```
7595

76-
#### Examples
96+
</details>
97+
98+
<details>
99+
<summary>Examples</summary>
77100

78101
```bash
79-
# uses packages defined in lerna.json by default
102+
# uses defaults for resolving packages
80103
syncpack format
81104
# uses packages defined by --source when provided
82105
syncpack format --source "apps/*/package.json"
@@ -86,11 +109,14 @@ syncpack format --source "apps/*/package.json" --source "core/*/package.json"
86109
syncpack format --indent " "
87110
```
88111

112+
</details>
113+
89114
### list
90115

91116
List all dependencies required by your packages.
92117

93-
#### Options
118+
<details>
119+
<summary>Options</summary>
94120

95121
```
96122
-s, --source [pattern] glob pattern for package.json files to read from
@@ -100,10 +126,13 @@ List all dependencies required by your packages.
100126
-h, --help output usage information
101127
```
102128

103-
#### Examples
129+
</details>
130+
131+
<details>
132+
<summary>Examples</summary>
104133

105134
```bash
106-
# uses packages defined in lerna.json by default
135+
# uses defaults for resolving packages
107136
syncpack list
108137
# uses packages defined by --source when provided
109138
syncpack list --source "apps/*/package.json"
@@ -115,12 +144,15 @@ syncpack list --dev
115144
syncpack list --dev --peer
116145
```
117146

147+
</details>
148+
118149
### list-mismatches
119150

120151
List dependencies which are required by multiple packages, where the version is
121152
not the same across every package.
122153

123-
#### Options
154+
<details>
155+
<summary>Options</summary>
124156

125157
```
126158
-s, --source [pattern] glob pattern for package.json files to read from
@@ -130,10 +162,13 @@ not the same across every package.
130162
-h, --help output usage information
131163
```
132164

133-
#### Examples
165+
</details>
166+
167+
<details>
168+
<summary>Examples</summary>
134169

135170
```bash
136-
# uses packages defined in lerna.json by default
171+
# uses defaults for resolving packages
137172
syncpack list-mismatches
138173
# uses packages defined by --source when provided
139174
syncpack list-mismatches --source "apps/*/package.json"
@@ -145,12 +180,15 @@ syncpack list-mismatches --dev
145180
syncpack list-mismatches --dev --peer
146181
```
147182

183+
</details>
184+
148185
### set-semver-ranges
149186

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

153-
#### Options
190+
<details>
191+
<summary>Options</summary>
154192

155193
```
156194
-r, --semver-range <range> <, <=, "", ~, ^, >=, >, or *. defaults to ""
@@ -162,10 +200,13 @@ and `"peerDependencies"` follow a consistent format.
162200
-h, --help output usage information
163201
```
164202

165-
#### Examples
203+
</details>
204+
205+
<details>
206+
<summary>Examples</summary>
166207

167208
```bash
168-
# uses packages defined in lerna.json by default
209+
# uses defaults for resolving packages
169210
syncpack set-semver-ranges
170211
# uses packages defined by --source when provided
171212
syncpack set-semver-ranges --source "apps/*/package.json"
@@ -181,7 +222,10 @@ syncpack set-semver-ranges --dev --peer --semver-range ~
181222
syncpack set-semver-ranges --indent " "
182223
```
183224

184-
#### Supported Ranges
225+
</details>
226+
227+
<details>
228+
<summary>Supported Ranges</summary>
185229

186230
```
187231
< <1.4.2
@@ -194,9 +238,11 @@ syncpack set-semver-ranges --indent " "
194238
* *
195239
```
196240

197-
## :raising_hand: Get Help
241+
</details>
242+
243+
## 🙋 Get Help
198244

199-
There are few ways to get help:
245+
There are a few ways to get help:
200246

201-
1. For bug reports and feature requests, open issues :bug:
202-
1. For direct and quick help, you can use Gitter :rocket:
247+
1. For bug reports and feature requests, open issues 🐛
248+
1. For direct and quick help, you can use Gitter 🚀

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "syncpack",
3-
"description": "Manage multiple package.json files, such as in Lerna Monorepos",
3+
"description": "Manage multiple package.json files, such as in Lerna Monorepos and Yarn Workspaces",
44
"version": "4.4.2",
55
"author": "Jamie Mason <jamie@foldleft.io> (https://github.com/JamieMason)",
66
"bin": {
@@ -16,6 +16,7 @@
1616
"Alex Hayton (https://github.com/AlexHayton)",
1717
"Jamie Mason (https://github.com/JamieMason)",
1818
"Luis Vieira (https://github.com/luisvieiragmr)",
19+
"Marais Rossouw (https://github.com/maraisr)",
1920
"Matt Sprague (https://github.com/uforic)"
2021
],
2122
"dependencies": {

src/bin-fix-mismatches.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ program.description(
1717
program.on('--help', () => {
1818
console.log('');
1919
console.log(`Examples:
20-
${chalk.grey('# uses packages defined in lerna.json by default')}
20+
${chalk.grey('# uses defaults for resolving packages')}
2121
syncpack fix-mismatches
2222
${chalk.grey('# uses packages defined by --source when provided')}
2323
syncpack fix-mismatches --source ${chalk.yellow('"apps/*/package.json"')}
@@ -36,11 +36,28 @@ program.on('--help', () => {
3636
${chalk.grey('# indent package.json with 4 spaces instead of 2')}
3737
syncpack fix-mismatches --indent ${chalk.yellow('" "')}
3838
`);
39+
console.log(`Resolving Packages:
40+
1. If ${chalk.yellow(`--source`)} globs are provided, use those.
41+
2. If using Yarn Workspaces, read ${chalk.yellow(
42+
`workspaces`
43+
)} from ${chalk.yellow(`package.json`)}.
44+
3. If using Lerna, read ${chalk.yellow(`packages`)} from ${chalk.yellow(
45+
`lerna.json`
46+
)}.
47+
4. Default to ${chalk.yellow(`"package.json"`)} and ${chalk.yellow(
48+
`"packages/*/package.json"`
49+
)}.
50+
`);
3951
console.log(`Reference:
40-
lerna.json
41-
${chalk.blue.underline('https://github.com/lerna/lerna#lernajson')}
42-
globs
43-
${chalk.blue.underline('https://github.com/isaacs/node-glob#glob-primer')}`);
52+
globs ${chalk.blue.underline(
53+
'https://github.com/isaacs/node-glob#glob-primer'
54+
)}
55+
lerna.json ${chalk.blue.underline(
56+
'https://github.com/lerna/lerna#lernajson'
57+
)}
58+
Yarn Workspaces ${chalk.blue.underline(
59+
'https://yarnpkg.com/lang/en/docs/workspaces'
60+
)}`);
4461
});
4562

4663
run(program);

src/bin-format.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ program.description(
1515
program.on('--help', () => {
1616
console.log('');
1717
console.log(`Examples:
18-
${chalk.grey('# uses packages defined in lerna.json by default')}
18+
${chalk.grey('# uses defaults for resolving packages')}
1919
syncpack format
2020
${chalk.grey('# uses packages defined by --source when provided')}
2121
syncpack format --source ${chalk.yellow('"apps/*/package.json"')}
@@ -26,11 +26,28 @@ program.on('--help', () => {
2626
${chalk.grey('# indent package.json with 4 spaces instead of 2')}
2727
syncpack format --indent ${chalk.yellow('" "')}
2828
`);
29+
console.log(`Resolving Packages:
30+
1. If ${chalk.yellow(`--source`)} globs are provided, use those.
31+
2. If using Yarn Workspaces, read ${chalk.yellow(
32+
`workspaces`
33+
)} from ${chalk.yellow(`package.json`)}.
34+
3. If using Lerna, read ${chalk.yellow(`packages`)} from ${chalk.yellow(
35+
`lerna.json`
36+
)}.
37+
4. Default to ${chalk.yellow(`"package.json"`)} and ${chalk.yellow(
38+
`"packages/*/package.json"`
39+
)}.
40+
`);
2941
console.log(`Reference:
30-
lerna.json
31-
${chalk.blue.underline('https://github.com/lerna/lerna#lernajson')}
32-
globs
33-
${chalk.blue.underline('https://github.com/isaacs/node-glob#glob-primer')}`);
42+
globs ${chalk.blue.underline(
43+
'https://github.com/isaacs/node-glob#glob-primer'
44+
)}
45+
lerna.json ${chalk.blue.underline(
46+
'https://github.com/lerna/lerna#lernajson'
47+
)}
48+
Yarn Workspaces ${chalk.blue.underline(
49+
'https://yarnpkg.com/lang/en/docs/workspaces'
50+
)}`);
3451
});
3552

3653
run(program);

src/bin-list-mismatches.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ program.description(
1313
program.on('--help', () => {
1414
console.log('');
1515
console.log(`Examples:
16-
${chalk.grey('# uses packages defined in lerna.json by default')}
16+
${chalk.grey('# uses defaults for resolving packages')}
1717
syncpack list-mismatches
1818
${chalk.grey('# uses packages defined by --source when provided')}
1919
syncpack list-mismatches --source ${chalk.yellow('"apps/*/package.json"')}
@@ -30,11 +30,28 @@ program.on('--help', () => {
3030
${chalk.grey('# only list "devDependencies" and "peerDependencies"')}
3131
syncpack list-mismatches --dev --peer
3232
`);
33+
console.log(`Resolving Packages:
34+
1. If ${chalk.yellow(`--source`)} globs are provided, use those.
35+
2. If using Yarn Workspaces, read ${chalk.yellow(
36+
`workspaces`
37+
)} from ${chalk.yellow(`package.json`)}.
38+
3. If using Lerna, read ${chalk.yellow(`packages`)} from ${chalk.yellow(
39+
`lerna.json`
40+
)}.
41+
4. Default to ${chalk.yellow(`"package.json"`)} and ${chalk.yellow(
42+
`"packages/*/package.json"`
43+
)}.
44+
`);
3345
console.log(`Reference:
34-
lerna.json
35-
${chalk.blue.underline('https://github.com/lerna/lerna#lernajson')}
36-
globs
37-
${chalk.blue.underline('https://github.com/isaacs/node-glob#glob-primer')}`);
46+
globs ${chalk.blue.underline(
47+
'https://github.com/isaacs/node-glob#glob-primer'
48+
)}
49+
lerna.json ${chalk.blue.underline(
50+
'https://github.com/lerna/lerna#lernajson'
51+
)}
52+
Yarn Workspaces ${chalk.blue.underline(
53+
'https://yarnpkg.com/lang/en/docs/workspaces'
54+
)}`);
3855
});
3956

4057
run(program);

0 commit comments

Comments
 (0)