npm-update-package 0.57.0 → 0.58.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -9
- package/dist/package.json +5 -5
- package/dist/src/core/Create.js +62 -0
- package/dist/src/core/OutdatedPackageProcessor.js +0 -74
- package/dist/src/core/OutdatedPackageProcessorCreator.js +47 -0
- package/dist/src/core/OutdatedPullRequestStrategy.js +11 -0
- package/dist/src/core/Recreate.js +67 -0
- package/dist/src/core/Skip.js +72 -0
- package/dist/src/core/index.js +2 -0
- package/dist/src/git/GitTransaction.js +33 -0
- package/dist/src/git/index.js +1 -0
- package/dist/src/main.js +2 -1
- package/dist/src/options/Options.js +6 -0
- package/dist/src/options/cliOptions.js +13 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ CLI tool for creating pull requests to update npm packages
|
|
|
26
26
|
- [githubToken](#githubtoken)
|
|
27
27
|
- [ignorePackages](#ignorepackages)
|
|
28
28
|
- [logLevel](#loglevel)
|
|
29
|
+
- [outdatedPrStrategy](#outdatedprstrategy)
|
|
29
30
|
- [packageManager](#packagemanager)
|
|
30
31
|
- [prBodyGithubHost](#prbodygithubhost)
|
|
31
32
|
- [prBodyNotes](#prbodynotes)
|
|
@@ -76,6 +77,7 @@ User names to assign to pull request.
|
|
|
76
77
|
|cli|`--assignees`|
|
|
77
78
|
|type|string[]|
|
|
78
79
|
|required|false|
|
|
80
|
+
|added version|v0.46.0|
|
|
79
81
|
|
|
80
82
|
Example:
|
|
81
83
|
|
|
@@ -94,6 +96,7 @@ How many members to be assigned to assignees.
|
|
|
94
96
|
|cli|`--assignees-sample-size`|
|
|
95
97
|
|type|number|
|
|
96
98
|
|required|false|
|
|
99
|
+
|added version|v0.56.0|
|
|
97
100
|
|
|
98
101
|
Example:
|
|
99
102
|
|
|
@@ -114,6 +117,7 @@ Commit message template.
|
|
|
114
117
|
|type|string|
|
|
115
118
|
|required|false|
|
|
116
119
|
|default|`chore(deps): {{{level}}} update {{{packageName}}} to v{{{newVersion}}}`|
|
|
120
|
+
|added version|v0.5.0|
|
|
117
121
|
|
|
118
122
|
Available variables:
|
|
119
123
|
|
|
@@ -143,6 +147,7 @@ Whether to fetch release notes.
|
|
|
143
147
|
|type|boolean|
|
|
144
148
|
|required|false|
|
|
145
149
|
|default|`true`|
|
|
150
|
+
|added version|v0.51.0|
|
|
146
151
|
|
|
147
152
|
Example:
|
|
148
153
|
|
|
@@ -162,6 +167,7 @@ Sleep time between fetching (ms).
|
|
|
162
167
|
|type|number|
|
|
163
168
|
|required|false|
|
|
164
169
|
|default|`1000`|
|
|
170
|
+
|added version|v0.50.0|
|
|
165
171
|
|
|
166
172
|
Example:
|
|
167
173
|
|
|
@@ -180,6 +186,7 @@ Git user email.
|
|
|
180
186
|
|cli|`--git-user-email`|
|
|
181
187
|
|type|string|
|
|
182
188
|
|required|false|
|
|
189
|
+
|added version|v0.53.0|
|
|
183
190
|
|
|
184
191
|
Example:
|
|
185
192
|
|
|
@@ -198,6 +205,7 @@ Git user name.
|
|
|
198
205
|
|cli|`--git-user-name`|
|
|
199
206
|
|type|string|
|
|
200
207
|
|required|false|
|
|
208
|
+
|added version|v0.53.0|
|
|
201
209
|
|
|
202
210
|
Example:
|
|
203
211
|
|
|
@@ -216,6 +224,7 @@ npx npm-update-package \
|
|
|
216
224
|
|cli|`--github-token`|
|
|
217
225
|
|type|string|
|
|
218
226
|
|required|true|
|
|
227
|
+
|added version|v0.1.0|
|
|
219
228
|
|
|
220
229
|
### ignorePackages
|
|
221
230
|
|
|
@@ -226,6 +235,7 @@ Package names to ignore.
|
|
|
226
235
|
|cli|`--ignore-packages`|
|
|
227
236
|
|type|string[]|
|
|
228
237
|
|required|false|
|
|
238
|
+
|added version|v0.43.0|
|
|
229
239
|
|
|
230
240
|
Example:
|
|
231
241
|
|
|
@@ -245,6 +255,7 @@ Log level to show.
|
|
|
245
255
|
|type|string|
|
|
246
256
|
|required|false|
|
|
247
257
|
|default|`info`|
|
|
258
|
+
|added version|v0.1.0|
|
|
248
259
|
|
|
249
260
|
Allowed values:
|
|
250
261
|
|
|
@@ -266,6 +277,34 @@ npx npm-update-package \
|
|
|
266
277
|
--log-level debug
|
|
267
278
|
```
|
|
268
279
|
|
|
280
|
+
### outdatedPrStrategy
|
|
281
|
+
|
|
282
|
+
What to do when outdated pull requests exist.
|
|
283
|
+
|
|
284
|
+
|Name|Value|
|
|
285
|
+
|---|---|
|
|
286
|
+
|cli|`--outdated-pr-strategy`|
|
|
287
|
+
|type|string|
|
|
288
|
+
|required|false|
|
|
289
|
+
|default|`recreate`|
|
|
290
|
+
|added version|v0.58.0|
|
|
291
|
+
|
|
292
|
+
Allowed values:
|
|
293
|
+
|
|
294
|
+
|Value|Description|
|
|
295
|
+
|---|---|
|
|
296
|
+
|`create`|Create new pull request.|
|
|
297
|
+
|`recreate`|Close old pull requests and create new pull request.|
|
|
298
|
+
|`skip`|Skip creating pull request.|
|
|
299
|
+
|
|
300
|
+
Example:
|
|
301
|
+
|
|
302
|
+
```sh
|
|
303
|
+
npx npm-update-package \
|
|
304
|
+
--github-token $GITHUB_TOKEN \
|
|
305
|
+
--outdated-pr-strategy create
|
|
306
|
+
```
|
|
307
|
+
|
|
269
308
|
### packageManager
|
|
270
309
|
|
|
271
310
|
Package manager of your project.
|
|
@@ -276,6 +315,7 @@ Since npm-update-package automatically determines which package manager to use,
|
|
|
276
315
|
|cli|`--package-manager`|
|
|
277
316
|
|type|string|
|
|
278
317
|
|required|false|
|
|
318
|
+
|added version|v0.1.0|
|
|
279
319
|
|
|
280
320
|
Allowed values:
|
|
281
321
|
|
|
@@ -302,6 +342,7 @@ GitHub host of pull request body.
|
|
|
302
342
|
|type|string|
|
|
303
343
|
|required|false|
|
|
304
344
|
|default|`togithub.com`|
|
|
345
|
+
|added version|v0.55.0|
|
|
305
346
|
|
|
306
347
|
Example:
|
|
307
348
|
|
|
@@ -320,6 +361,7 @@ Additional notes for Pull request body.
|
|
|
320
361
|
|cli|`--pr-body-notes`|
|
|
321
362
|
|type|string|
|
|
322
363
|
|required|false|
|
|
364
|
+
|added version|v0.45.0|
|
|
323
365
|
|
|
324
366
|
Example:
|
|
325
367
|
|
|
@@ -339,6 +381,7 @@ Pull request title template.
|
|
|
339
381
|
|type|string|
|
|
340
382
|
|required|false|
|
|
341
383
|
|default|`chore(deps): {{{level}}} update {{{packageName}}} to v{{{newVersion}}}`|
|
|
384
|
+
|added version|v0.44.0|
|
|
342
385
|
|
|
343
386
|
Available variables:
|
|
344
387
|
|
|
@@ -367,6 +410,7 @@ User names to request reviews.
|
|
|
367
410
|
|cli|`--reviewers`|
|
|
368
411
|
|type|string[]|
|
|
369
412
|
|required|false|
|
|
413
|
+
|added version|v0.26.0|
|
|
370
414
|
|
|
371
415
|
Example:
|
|
372
416
|
|
|
@@ -385,6 +429,7 @@ How many members to be assigned to reviewers.
|
|
|
385
429
|
|cli|`--reviewers-sample-size`|
|
|
386
430
|
|type|number|
|
|
387
431
|
|required|false|
|
|
432
|
+
|added version|v0.57.0|
|
|
388
433
|
|
|
389
434
|
Example:
|
|
390
435
|
|
|
@@ -522,6 +567,8 @@ The following shows the process flow of npm-update-package.
|
|
|
522
567
|
```plantuml
|
|
523
568
|
@startuml
|
|
524
569
|
start
|
|
570
|
+
group bin
|
|
571
|
+
:Initialize options;
|
|
525
572
|
group main
|
|
526
573
|
:Get outdated packages;
|
|
527
574
|
|
|
@@ -538,29 +585,48 @@ if (Label does not exist) then (yes)
|
|
|
538
585
|
else (no)
|
|
539
586
|
endif
|
|
540
587
|
|
|
588
|
+
:Initialize Git config;
|
|
541
589
|
group OutdatedPackagesProcessor
|
|
590
|
+
|
|
542
591
|
while (Package exists) is (yes)
|
|
543
592
|
group OutdatedPackageProcessor
|
|
544
593
|
if (Remote branch does not exist) then (yes)
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
594
|
+
switch (outdatedPrStrategy)
|
|
595
|
+
case (create)
|
|
596
|
+
:Create branch;
|
|
597
|
+
:Update package;
|
|
598
|
+
:Create pull request;
|
|
599
|
+
:Remove branch;
|
|
600
|
+
case (recreate)
|
|
601
|
+
:Create branch;
|
|
602
|
+
:Update package;
|
|
603
|
+
:Create pull request;
|
|
604
|
+
:Close old pull requests;
|
|
605
|
+
:Remove branch;
|
|
606
|
+
case (skip)
|
|
607
|
+
if (Outdated pull requests don't exist) then (yes)
|
|
608
|
+
:Create branch;
|
|
609
|
+
:Update package;
|
|
610
|
+
:Create pull request;
|
|
611
|
+
:Remove branch;
|
|
612
|
+
else (no)
|
|
613
|
+
endif
|
|
614
|
+
endswitch
|
|
550
615
|
else (no)
|
|
551
616
|
endif
|
|
552
617
|
end group
|
|
553
618
|
endwhile (no)
|
|
554
619
|
|
|
555
|
-
end group
|
|
556
|
-
|
|
557
|
-
end group
|
|
620
|
+
end group /' OutdatedPackagesProcessor '/
|
|
621
|
+
:Show results;
|
|
622
|
+
end group /' main '/
|
|
623
|
+
end group /' bin '/
|
|
558
624
|
end
|
|
559
625
|
@enduml
|
|
560
626
|
```
|
|
561
627
|
-->
|
|
562
628
|
|
|
563
|
-
[](http://www.plantuml.com/plantuml/uml/hLF1RjGm4BtxAzvjiuUgzzrBKIKg92GgAZx0cynkh3gUO4zOojUJQUo0WS25IsBFUvddzpovIsAZJ8CthmjpYJoDEBbW3k-24sUz-qRWKHo7TCpmO1L_805FqbcX3gDjd-s5PefnPpHll5zBi94mZJV2DyhTGteAQ5uexGr0eJFa4w49l3VppfsDERmbQNj46bW8fsX3ssllN1ydxsVmyqH9Yk9xUoAFZYaXi82-kYI_I1tk8raXUAKUVrEj73yuGSlXx2x5z8TizJ7RUepSKaeSZRdspXEQZ2pQQG-NLka_jlZH0L0B7t-s-tShGBewZQBXqZC-IPmNbvS5RwswQryTBvKIG54ubkgdKJkK-phMv2hi5TEZVgaQPS58MHB_NVFUSoAmxoeu_VjCwTcD9GBDkLn3tGSTXzrMsjjEDhrikza-Bx0EPTulevbNovsRcfKP-bx6JCSvJwGop0e0jxljCSRkrXoUUhuYKfgy1bj_gN-zakhgQIsQk_an3Vux)
|
|
564
630
|
|
|
565
631
|
## FAQ
|
|
566
632
|
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-update-package",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.58.2",
|
|
4
4
|
"description": "CLI tool for creating pull requests to update npm packages",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc --project tsconfig.build.json",
|
|
@@ -40,14 +40,14 @@
|
|
|
40
40
|
"@types/node-fetch": "2.6.1",
|
|
41
41
|
"@types/parse-github-url": "1.0.0",
|
|
42
42
|
"@types/semver": "7.3.9",
|
|
43
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
44
|
-
"eslint": "8.
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "5.19.0",
|
|
44
|
+
"eslint": "8.13.0",
|
|
45
45
|
"eslint-config-standard-with-typescript": "21.0.1",
|
|
46
46
|
"eslint-plugin-import": "2.26.0",
|
|
47
|
-
"eslint-plugin-jest": "26.1.
|
|
47
|
+
"eslint-plugin-jest": "26.1.4",
|
|
48
48
|
"eslint-plugin-node": "11.1.0",
|
|
49
49
|
"eslint-plugin-promise": "6.0.0",
|
|
50
|
-
"eslint-plugin-tsdoc": "0.2.
|
|
50
|
+
"eslint-plugin-tsdoc": "0.2.16",
|
|
51
51
|
"husky": "7.0.4",
|
|
52
52
|
"jest": "27.4.7",
|
|
53
53
|
"lint-staged": "12.3.7",
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Create = void 0;
|
|
4
|
+
const Either_1 = require("fp-ts/lib/Either");
|
|
5
|
+
const git_1 = require("../git");
|
|
6
|
+
const logger_1 = require("../logger");
|
|
7
|
+
// TODO: Add test
|
|
8
|
+
class Create {
|
|
9
|
+
constructor({ git, packageManager, pullRequestCreator, branchFinder, commitMessageCreator, packageUpdater }) {
|
|
10
|
+
this.git = git;
|
|
11
|
+
this.packageManager = packageManager;
|
|
12
|
+
this.pullRequestCreator = pullRequestCreator;
|
|
13
|
+
this.branchFinder = branchFinder;
|
|
14
|
+
this.commitMessageCreator = commitMessageCreator;
|
|
15
|
+
this.packageUpdater = packageUpdater;
|
|
16
|
+
}
|
|
17
|
+
async process(outdatedPackage) {
|
|
18
|
+
const branchName = (0, git_1.createBranchName)(outdatedPackage);
|
|
19
|
+
logger_1.logger.trace(`branchName=${branchName}`);
|
|
20
|
+
if (this.branchFinder.findByName(branchName) !== undefined) {
|
|
21
|
+
logger_1.logger.info(`Skip ${outdatedPackage.name} because ${branchName} branch already exists on remote.`);
|
|
22
|
+
return (0, Either_1.right)({
|
|
23
|
+
outdatedPackage,
|
|
24
|
+
skipped: true
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
const transaction = new git_1.GitTransaction({
|
|
28
|
+
git: this.git,
|
|
29
|
+
branchName,
|
|
30
|
+
files: [this.packageManager.packageFile, this.packageManager.lockFile]
|
|
31
|
+
});
|
|
32
|
+
return await transaction.run(async ({ git, branchName }) => {
|
|
33
|
+
try {
|
|
34
|
+
await this.packageUpdater.update(outdatedPackage);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
logger_1.logger.error(error);
|
|
38
|
+
return (0, Either_1.left)({
|
|
39
|
+
outdatedPackage,
|
|
40
|
+
error
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
logger_1.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`);
|
|
44
|
+
await git.add(this.packageManager.packageFile, this.packageManager.lockFile);
|
|
45
|
+
const message = this.commitMessageCreator.create(outdatedPackage);
|
|
46
|
+
logger_1.logger.trace(`message=${message}`);
|
|
47
|
+
await git.commit(message);
|
|
48
|
+
await git.push(branchName);
|
|
49
|
+
const pullRequest = await this.pullRequestCreator.create({
|
|
50
|
+
outdatedPackage,
|
|
51
|
+
branchName
|
|
52
|
+
});
|
|
53
|
+
logger_1.logger.trace(`pullRequest=${JSON.stringify(pullRequest)}`);
|
|
54
|
+
logger_1.logger.info(`Pull request for ${outdatedPackage.name} has created. ${pullRequest.html_url}`);
|
|
55
|
+
return (0, Either_1.right)({
|
|
56
|
+
outdatedPackage,
|
|
57
|
+
created: true
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.Create = Create;
|
|
@@ -1,76 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OutdatedPackageProcessor = void 0;
|
|
4
|
-
const Either_1 = require("fp-ts/lib/Either");
|
|
5
|
-
const git_1 = require("../git");
|
|
6
|
-
const logger_1 = require("../logger");
|
|
7
|
-
// TODO: Add test
|
|
8
|
-
// TODO: Split into multiple classes and functions
|
|
9
|
-
class OutdatedPackageProcessor {
|
|
10
|
-
constructor({ git, packageManager, pullRequestCreator, branchFinder, commitMessageCreator, pullRequestFinder, pullRequestsCloser, packageUpdater }) {
|
|
11
|
-
this.git = git;
|
|
12
|
-
this.packageManager = packageManager;
|
|
13
|
-
this.pullRequestCreator = pullRequestCreator;
|
|
14
|
-
this.branchFinder = branchFinder;
|
|
15
|
-
this.commitMessageCreator = commitMessageCreator;
|
|
16
|
-
this.pullRequestFinder = pullRequestFinder;
|
|
17
|
-
this.pullRequestsCloser = pullRequestsCloser;
|
|
18
|
-
this.packageUpdater = packageUpdater;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Don't run in parallel because it includes file operations.
|
|
22
|
-
*/
|
|
23
|
-
async process(outdatedPackage) {
|
|
24
|
-
const branchName = (0, git_1.createBranchName)(outdatedPackage);
|
|
25
|
-
logger_1.logger.debug(`branchName=${branchName}`);
|
|
26
|
-
if (this.branchFinder.findByName(branchName) !== undefined) {
|
|
27
|
-
logger_1.logger.info(`Skip ${outdatedPackage.name} because ${branchName} branch already exists on remote.`);
|
|
28
|
-
return (0, Either_1.right)({
|
|
29
|
-
outdatedPackage,
|
|
30
|
-
skipped: true
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
await this.git.createBranch(branchName);
|
|
34
|
-
logger_1.logger.info(`${branchName} branch has created.`);
|
|
35
|
-
try {
|
|
36
|
-
try {
|
|
37
|
-
await this.packageUpdater.update(outdatedPackage);
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
logger_1.logger.error(error);
|
|
41
|
-
return (0, Either_1.left)({
|
|
42
|
-
outdatedPackage,
|
|
43
|
-
error
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
logger_1.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`);
|
|
47
|
-
await this.git.add(this.packageManager.packageFile, this.packageManager.lockFile);
|
|
48
|
-
const message = this.commitMessageCreator.create(outdatedPackage);
|
|
49
|
-
logger_1.logger.debug(`message=${message}`);
|
|
50
|
-
await this.git.commit(message);
|
|
51
|
-
await this.git.push(branchName);
|
|
52
|
-
const pullRequest = await this.pullRequestCreator.create({
|
|
53
|
-
outdatedPackage,
|
|
54
|
-
branchName
|
|
55
|
-
});
|
|
56
|
-
logger_1.logger.info(`Pull request for ${outdatedPackage.name} has created. ${pullRequest.html_url}`);
|
|
57
|
-
await this.closeOldPullRequests(outdatedPackage);
|
|
58
|
-
return (0, Either_1.right)({
|
|
59
|
-
outdatedPackage,
|
|
60
|
-
created: true
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
finally {
|
|
64
|
-
await this.git.restore(this.packageManager.packageFile, this.packageManager.lockFile);
|
|
65
|
-
await this.git.switch('-');
|
|
66
|
-
await this.git.removeBranch(branchName);
|
|
67
|
-
logger_1.logger.info(`${branchName} branch has removed.`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
async closeOldPullRequests(outdatedPackage) {
|
|
71
|
-
const pullRequests = this.pullRequestFinder.findByPackageName(outdatedPackage.name);
|
|
72
|
-
logger_1.logger.debug(`pullRequests=${JSON.stringify(pullRequests)}`);
|
|
73
|
-
await this.pullRequestsCloser.close(pullRequests);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.OutdatedPackageProcessor = OutdatedPackageProcessor;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OutdatedPackageProcessorCreator = void 0;
|
|
4
|
+
const Create_1 = require("./Create");
|
|
5
|
+
const OutdatedPullRequestStrategy_1 = require("./OutdatedPullRequestStrategy");
|
|
6
|
+
const Recreate_1 = require("./Recreate");
|
|
7
|
+
const Skip_1 = require("./Skip");
|
|
8
|
+
class OutdatedPackageProcessorCreator {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
create({ git, packageManager, pullRequestCreator, branchFinder, commitMessageCreator, pullRequestFinder, pullRequestsCloser, packageUpdater }) {
|
|
13
|
+
switch (this.options.outdatedPrStrategy) {
|
|
14
|
+
case OutdatedPullRequestStrategy_1.OutdatedPullRequestStrategy.Create:
|
|
15
|
+
return new Create_1.Create({
|
|
16
|
+
git,
|
|
17
|
+
packageManager,
|
|
18
|
+
pullRequestCreator,
|
|
19
|
+
branchFinder,
|
|
20
|
+
commitMessageCreator,
|
|
21
|
+
packageUpdater
|
|
22
|
+
});
|
|
23
|
+
case OutdatedPullRequestStrategy_1.OutdatedPullRequestStrategy.Recreate:
|
|
24
|
+
return new Recreate_1.Recreate({
|
|
25
|
+
git,
|
|
26
|
+
packageManager,
|
|
27
|
+
pullRequestCreator,
|
|
28
|
+
branchFinder,
|
|
29
|
+
commitMessageCreator,
|
|
30
|
+
pullRequestFinder,
|
|
31
|
+
pullRequestsCloser,
|
|
32
|
+
packageUpdater
|
|
33
|
+
});
|
|
34
|
+
case OutdatedPullRequestStrategy_1.OutdatedPullRequestStrategy.Skip:
|
|
35
|
+
return new Skip_1.Skip({
|
|
36
|
+
git,
|
|
37
|
+
packageManager,
|
|
38
|
+
pullRequestCreator,
|
|
39
|
+
branchFinder,
|
|
40
|
+
commitMessageCreator,
|
|
41
|
+
pullRequestFinder,
|
|
42
|
+
packageUpdater
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.OutdatedPackageProcessorCreator = OutdatedPackageProcessorCreator;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isOutdatedPullRequestStrategy = exports.OutdatedPullRequestStrategy = void 0;
|
|
4
|
+
exports.OutdatedPullRequestStrategy = {
|
|
5
|
+
Create: 'create',
|
|
6
|
+
Recreate: 'recreate',
|
|
7
|
+
Skip: 'skip'
|
|
8
|
+
};
|
|
9
|
+
const outdatedPullRequestStrategies = Object.values(exports.OutdatedPullRequestStrategy);
|
|
10
|
+
const isOutdatedPullRequestStrategy = (value) => outdatedPullRequestStrategies.includes(value);
|
|
11
|
+
exports.isOutdatedPullRequestStrategy = isOutdatedPullRequestStrategy;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Recreate = void 0;
|
|
4
|
+
const Either_1 = require("fp-ts/lib/Either");
|
|
5
|
+
const git_1 = require("../git");
|
|
6
|
+
const logger_1 = require("../logger");
|
|
7
|
+
// TODO: Add test
|
|
8
|
+
class Recreate {
|
|
9
|
+
constructor({ git, packageManager, pullRequestCreator, branchFinder, commitMessageCreator, packageUpdater, pullRequestFinder, pullRequestsCloser }) {
|
|
10
|
+
this.git = git;
|
|
11
|
+
this.packageManager = packageManager;
|
|
12
|
+
this.pullRequestCreator = pullRequestCreator;
|
|
13
|
+
this.branchFinder = branchFinder;
|
|
14
|
+
this.commitMessageCreator = commitMessageCreator;
|
|
15
|
+
this.packageUpdater = packageUpdater;
|
|
16
|
+
this.pullRequestFinder = pullRequestFinder;
|
|
17
|
+
this.pullRequestsCloser = pullRequestsCloser;
|
|
18
|
+
}
|
|
19
|
+
async process(outdatedPackage) {
|
|
20
|
+
const branchName = (0, git_1.createBranchName)(outdatedPackage);
|
|
21
|
+
logger_1.logger.trace(`branchName=${branchName}`);
|
|
22
|
+
if (this.branchFinder.findByName(branchName) !== undefined) {
|
|
23
|
+
logger_1.logger.info(`Skip ${outdatedPackage.name} because ${branchName} branch already exists on remote.`);
|
|
24
|
+
return (0, Either_1.right)({
|
|
25
|
+
outdatedPackage,
|
|
26
|
+
skipped: true
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const transaction = new git_1.GitTransaction({
|
|
30
|
+
git: this.git,
|
|
31
|
+
branchName,
|
|
32
|
+
files: [this.packageManager.packageFile, this.packageManager.lockFile]
|
|
33
|
+
});
|
|
34
|
+
return await transaction.run(async ({ git, branchName }) => {
|
|
35
|
+
try {
|
|
36
|
+
await this.packageUpdater.update(outdatedPackage);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
logger_1.logger.error(error);
|
|
40
|
+
return (0, Either_1.left)({
|
|
41
|
+
outdatedPackage,
|
|
42
|
+
error
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
logger_1.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`);
|
|
46
|
+
await git.add(this.packageManager.packageFile, this.packageManager.lockFile);
|
|
47
|
+
const message = this.commitMessageCreator.create(outdatedPackage);
|
|
48
|
+
logger_1.logger.trace(`message=${message}`);
|
|
49
|
+
await git.commit(message);
|
|
50
|
+
await git.push(branchName);
|
|
51
|
+
const pullRequest = await this.pullRequestCreator.create({
|
|
52
|
+
outdatedPackage,
|
|
53
|
+
branchName
|
|
54
|
+
});
|
|
55
|
+
logger_1.logger.trace(`pullRequest=${JSON.stringify(pullRequest)}`);
|
|
56
|
+
logger_1.logger.info(`Pull request for ${outdatedPackage.name} has created. ${pullRequest.html_url}`);
|
|
57
|
+
const pullRequests = this.pullRequestFinder.findByPackageName(outdatedPackage.name);
|
|
58
|
+
logger_1.logger.trace(`pullRequests=${JSON.stringify(pullRequests)}`);
|
|
59
|
+
await this.pullRequestsCloser.close(pullRequests);
|
|
60
|
+
return (0, Either_1.right)({
|
|
61
|
+
outdatedPackage,
|
|
62
|
+
created: true
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.Recreate = Recreate;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Skip = void 0;
|
|
4
|
+
const Either_1 = require("fp-ts/lib/Either");
|
|
5
|
+
const git_1 = require("../git");
|
|
6
|
+
const logger_1 = require("../logger");
|
|
7
|
+
// TODO: Add test
|
|
8
|
+
class Skip {
|
|
9
|
+
constructor({ git, packageManager, pullRequestCreator, branchFinder, commitMessageCreator, packageUpdater, pullRequestFinder }) {
|
|
10
|
+
this.git = git;
|
|
11
|
+
this.packageManager = packageManager;
|
|
12
|
+
this.pullRequestCreator = pullRequestCreator;
|
|
13
|
+
this.branchFinder = branchFinder;
|
|
14
|
+
this.commitMessageCreator = commitMessageCreator;
|
|
15
|
+
this.packageUpdater = packageUpdater;
|
|
16
|
+
this.pullRequestFinder = pullRequestFinder;
|
|
17
|
+
}
|
|
18
|
+
async process(outdatedPackage) {
|
|
19
|
+
const branchName = (0, git_1.createBranchName)(outdatedPackage);
|
|
20
|
+
logger_1.logger.trace(`branchName=${branchName}`);
|
|
21
|
+
if (this.branchFinder.findByName(branchName) !== undefined) {
|
|
22
|
+
logger_1.logger.info(`Skip ${outdatedPackage.name} because ${branchName} branch already exists on remote.`);
|
|
23
|
+
return (0, Either_1.right)({
|
|
24
|
+
outdatedPackage,
|
|
25
|
+
skipped: true
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const pullRequests = this.pullRequestFinder.findByPackageName(outdatedPackage.name);
|
|
29
|
+
logger_1.logger.trace(`pullRequests=${JSON.stringify(pullRequests)}`);
|
|
30
|
+
if (pullRequests.length > 0) {
|
|
31
|
+
logger_1.logger.info(`Skip ${outdatedPackage.name} because outdated pull requests exist.`);
|
|
32
|
+
return (0, Either_1.right)({
|
|
33
|
+
outdatedPackage,
|
|
34
|
+
skipped: true
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const transaction = new git_1.GitTransaction({
|
|
38
|
+
git: this.git,
|
|
39
|
+
branchName,
|
|
40
|
+
files: [this.packageManager.packageFile, this.packageManager.lockFile]
|
|
41
|
+
});
|
|
42
|
+
return await transaction.run(async ({ git, branchName }) => {
|
|
43
|
+
try {
|
|
44
|
+
await this.packageUpdater.update(outdatedPackage);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
logger_1.logger.error(error);
|
|
48
|
+
return (0, Either_1.left)({
|
|
49
|
+
outdatedPackage,
|
|
50
|
+
error
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
logger_1.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`);
|
|
54
|
+
await git.add(this.packageManager.packageFile, this.packageManager.lockFile);
|
|
55
|
+
const message = this.commitMessageCreator.create(outdatedPackage);
|
|
56
|
+
logger_1.logger.trace(`message=${message}`);
|
|
57
|
+
await git.commit(message);
|
|
58
|
+
await git.push(branchName);
|
|
59
|
+
const pullRequest = await this.pullRequestCreator.create({
|
|
60
|
+
outdatedPackage,
|
|
61
|
+
branchName
|
|
62
|
+
});
|
|
63
|
+
logger_1.logger.trace(`pullRequest=${JSON.stringify(pullRequest)}`);
|
|
64
|
+
logger_1.logger.info(`Pull request for ${outdatedPackage.name} has created. ${pullRequest.html_url}`);
|
|
65
|
+
return (0, Either_1.right)({
|
|
66
|
+
outdatedPackage,
|
|
67
|
+
created: true
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.Skip = Skip;
|
package/dist/src/core/index.js
CHANGED
|
@@ -17,6 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./FailedResult"), exports);
|
|
18
18
|
__exportStar(require("./OutdatedPackage"), exports);
|
|
19
19
|
__exportStar(require("./OutdatedPackageProcessor"), exports);
|
|
20
|
+
__exportStar(require("./OutdatedPackageProcessorCreator"), exports);
|
|
20
21
|
__exportStar(require("./OutdatedPackagesProcessor"), exports);
|
|
22
|
+
__exportStar(require("./OutdatedPullRequestStrategy"), exports);
|
|
21
23
|
__exportStar(require("./PackageUpdater"), exports);
|
|
22
24
|
__exportStar(require("./SucceededResult"), exports);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GitTransaction = void 0;
|
|
4
|
+
const logger_1 = require("../logger");
|
|
5
|
+
// TODO: Add test
|
|
6
|
+
class GitTransaction {
|
|
7
|
+
constructor({ git, branchName, files }) {
|
|
8
|
+
this.git = git;
|
|
9
|
+
this.branchName = branchName;
|
|
10
|
+
this.files = files;
|
|
11
|
+
}
|
|
12
|
+
async run(operation) {
|
|
13
|
+
await this.git.createBranch(this.branchName);
|
|
14
|
+
logger_1.logger.info(`${this.branchName} branch has created.`);
|
|
15
|
+
try {
|
|
16
|
+
return await operation({
|
|
17
|
+
git: this.git,
|
|
18
|
+
branchName: this.branchName,
|
|
19
|
+
files: this.files
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
finally {
|
|
23
|
+
await this.rollback();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async rollback() {
|
|
27
|
+
await this.git.restore(...this.files);
|
|
28
|
+
await this.git.switch('-');
|
|
29
|
+
await this.git.removeBranch(this.branchName);
|
|
30
|
+
logger_1.logger.info(`${this.branchName} branch has removed.`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.GitTransaction = GitTransaction;
|
package/dist/src/git/index.js
CHANGED
package/dist/src/main.js
CHANGED
|
@@ -102,7 +102,8 @@ const main = async (options) => {
|
|
|
102
102
|
packageManager,
|
|
103
103
|
ncu
|
|
104
104
|
});
|
|
105
|
-
const
|
|
105
|
+
const outdatedPackageProcessorCreator = new core_1.OutdatedPackageProcessorCreator(options);
|
|
106
|
+
const outdatedPackageProcessor = outdatedPackageProcessorCreator.create({
|
|
106
107
|
git,
|
|
107
108
|
packageManager,
|
|
108
109
|
pullRequestCreator,
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isOptions = void 0;
|
|
4
4
|
const io_ts_1 = require("io-ts");
|
|
5
|
+
const core_1 = require("../core");
|
|
5
6
|
const logger_1 = require("../logger");
|
|
6
7
|
const package_manager_1 = require("../package-manager");
|
|
7
8
|
const Options = (0, io_ts_1.intersection)([
|
|
@@ -19,6 +20,11 @@ const Options = (0, io_ts_1.intersection)([
|
|
|
19
20
|
(0, io_ts_1.literal)(logger_1.LogLevel.Debug),
|
|
20
21
|
(0, io_ts_1.literal)(logger_1.LogLevel.Trace)
|
|
21
22
|
]),
|
|
23
|
+
outdatedPrStrategy: (0, io_ts_1.union)([
|
|
24
|
+
(0, io_ts_1.literal)(core_1.OutdatedPullRequestStrategy.Create),
|
|
25
|
+
(0, io_ts_1.literal)(core_1.OutdatedPullRequestStrategy.Recreate),
|
|
26
|
+
(0, io_ts_1.literal)(core_1.OutdatedPullRequestStrategy.Skip)
|
|
27
|
+
]),
|
|
22
28
|
prBodyGithubHost: io_ts_1.string,
|
|
23
29
|
prTitle: io_ts_1.string
|
|
24
30
|
}),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cliOptions = void 0;
|
|
4
|
+
const core_1 = require("../core");
|
|
4
5
|
const logger_1 = require("../logger");
|
|
5
6
|
const package_manager_1 = require("../package-manager");
|
|
6
7
|
const OptionType_1 = require("./OptionType");
|
|
@@ -78,6 +79,18 @@ exports.cliOptions = [
|
|
|
78
79
|
],
|
|
79
80
|
default: logger_1.LogLevel.Info
|
|
80
81
|
},
|
|
82
|
+
{
|
|
83
|
+
name: 'outdated-pr-strategy',
|
|
84
|
+
description: 'What to do when outdated pull requests exist',
|
|
85
|
+
type: OptionType_1.OptionType.String,
|
|
86
|
+
required: false,
|
|
87
|
+
choices: [
|
|
88
|
+
core_1.OutdatedPullRequestStrategy.Create,
|
|
89
|
+
core_1.OutdatedPullRequestStrategy.Recreate,
|
|
90
|
+
core_1.OutdatedPullRequestStrategy.Skip
|
|
91
|
+
],
|
|
92
|
+
default: core_1.OutdatedPullRequestStrategy.Recreate
|
|
93
|
+
},
|
|
81
94
|
{
|
|
82
95
|
name: 'package-manager',
|
|
83
96
|
description: 'Package manager of your project',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-update-package",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.58.2",
|
|
4
4
|
"description": "CLI tool for creating pull requests to update npm packages",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc --project tsconfig.build.json",
|
|
@@ -40,14 +40,14 @@
|
|
|
40
40
|
"@types/node-fetch": "2.6.1",
|
|
41
41
|
"@types/parse-github-url": "1.0.0",
|
|
42
42
|
"@types/semver": "7.3.9",
|
|
43
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
44
|
-
"eslint": "8.
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "5.19.0",
|
|
44
|
+
"eslint": "8.13.0",
|
|
45
45
|
"eslint-config-standard-with-typescript": "21.0.1",
|
|
46
46
|
"eslint-plugin-import": "2.26.0",
|
|
47
|
-
"eslint-plugin-jest": "26.1.
|
|
47
|
+
"eslint-plugin-jest": "26.1.4",
|
|
48
48
|
"eslint-plugin-node": "11.1.0",
|
|
49
49
|
"eslint-plugin-promise": "6.0.0",
|
|
50
|
-
"eslint-plugin-tsdoc": "0.2.
|
|
50
|
+
"eslint-plugin-tsdoc": "0.2.16",
|
|
51
51
|
"husky": "7.0.4",
|
|
52
52
|
"jest": "27.4.7",
|
|
53
53
|
"lint-staged": "12.3.7",
|