npm-update-package 0.42.0 → 0.43.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 +7 -0
- package/dist/package.json +3 -3
- package/dist/src/core/OutdatedPackageProcessor.js +28 -12
- package/dist/src/git/Git.js +0 -11
- package/dist/src/github/errors/NotFoundError.js +0 -1
- package/dist/src/github/pull-request/closer/PullRequestCloser.js +6 -4
- package/dist/src/main.js +2 -1
- package/dist/src/options/Options.js +1 -0
- package/dist/src/options/cliOptions.js +6 -0
- package/package.json +3 -3
package/README.md
CHANGED
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-update-package",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.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",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"fp-ts": "2.11.8",
|
|
21
21
|
"http-status-codes": "2.2.0",
|
|
22
22
|
"io-ts": "2.2.16",
|
|
23
|
-
"log4js": "6.4.
|
|
23
|
+
"log4js": "6.4.2",
|
|
24
24
|
"mustache": "4.1.0",
|
|
25
25
|
"npm-check-updates": "12.5.0",
|
|
26
26
|
"parse-github-url": "1.0.2",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"npm-run-all": "4.1.5",
|
|
50
50
|
"rimraf": "3.0.2",
|
|
51
51
|
"ts-jest": "27.1.3",
|
|
52
|
-
"ts-node": "10.
|
|
52
|
+
"ts-node": "10.6.0",
|
|
53
53
|
"typescript": "4.5.5",
|
|
54
54
|
"utility-types": "3.10.0"
|
|
55
55
|
},
|
|
@@ -5,7 +5,7 @@ const Either_1 = require("fp-ts/lib/Either");
|
|
|
5
5
|
const git_1 = require("../git");
|
|
6
6
|
// TODO: add test
|
|
7
7
|
class OutdatedPackageProcessor {
|
|
8
|
-
constructor({ git, ncu, packageManager, pullRequestCreator, branchFinder, logger, commitMessageCreator, pullRequestFinder, pullRequestCloser }) {
|
|
8
|
+
constructor({ git, ncu, packageManager, pullRequestCreator, branchFinder, logger, commitMessageCreator, pullRequestFinder, pullRequestCloser, options }) {
|
|
9
9
|
this.git = git;
|
|
10
10
|
this.ncu = ncu;
|
|
11
11
|
this.packageManager = packageManager;
|
|
@@ -15,11 +15,21 @@ class OutdatedPackageProcessor {
|
|
|
15
15
|
this.commitMessageCreator = commitMessageCreator;
|
|
16
16
|
this.pullRequestFinder = pullRequestFinder;
|
|
17
17
|
this.pullRequestCloser = pullRequestCloser;
|
|
18
|
+
this.options = options;
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
21
|
* Don't run in parallel because it includes file operations.
|
|
21
22
|
*/
|
|
22
23
|
async process(outdatedPackage) {
|
|
24
|
+
var _a;
|
|
25
|
+
const ignoredPackages = (_a = this.options.ignorePackages) !== null && _a !== void 0 ? _a : [];
|
|
26
|
+
if (ignoredPackages.includes(outdatedPackage.name)) {
|
|
27
|
+
this.logger.info(`Skip ${outdatedPackage.name} because ignorePackages contains it.`);
|
|
28
|
+
return (0, Either_1.right)({
|
|
29
|
+
outdatedPackage,
|
|
30
|
+
skipped: true
|
|
31
|
+
});
|
|
32
|
+
}
|
|
23
33
|
const branchName = (0, git_1.createBranchName)(outdatedPackage);
|
|
24
34
|
this.logger.debug(`branchName=${branchName}`);
|
|
25
35
|
if (this.branchFinder.findByName(branchName) !== undefined) {
|
|
@@ -33,11 +43,7 @@ class OutdatedPackageProcessor {
|
|
|
33
43
|
this.logger.info(`${branchName} branch has created.`);
|
|
34
44
|
try {
|
|
35
45
|
try {
|
|
36
|
-
|
|
37
|
-
if (updatedPackages.length !== 1) {
|
|
38
|
-
throw new Error(`Failed to update ${outdatedPackage.name}.`);
|
|
39
|
-
}
|
|
40
|
-
await this.packageManager.install();
|
|
46
|
+
await this.updatePackage(outdatedPackage);
|
|
41
47
|
}
|
|
42
48
|
catch (error) {
|
|
43
49
|
this.logger.error(error);
|
|
@@ -57,12 +63,7 @@ class OutdatedPackageProcessor {
|
|
|
57
63
|
branchName
|
|
58
64
|
});
|
|
59
65
|
this.logger.info(`Pull request for ${outdatedPackage.name} has created. ${pullRequest.html_url}`);
|
|
60
|
-
|
|
61
|
-
this.logger.debug(`pullRequests=${JSON.stringify(pullRequests)}`);
|
|
62
|
-
await Promise.all(pullRequests.map(async (pullRequest) => {
|
|
63
|
-
await this.pullRequestCloser.close(pullRequest);
|
|
64
|
-
this.logger.info(`Pull request for ${outdatedPackage.name} has closed. ${pullRequest.html_url}`);
|
|
65
|
-
}));
|
|
66
|
+
await this.closeOldPullRequests(outdatedPackage);
|
|
66
67
|
return (0, Either_1.right)({
|
|
67
68
|
outdatedPackage,
|
|
68
69
|
created: true
|
|
@@ -75,5 +76,20 @@ class OutdatedPackageProcessor {
|
|
|
75
76
|
this.logger.info(`${branchName} branch has removed.`);
|
|
76
77
|
}
|
|
77
78
|
}
|
|
79
|
+
async updatePackage(outdatedPackage) {
|
|
80
|
+
const updatedPackages = await this.ncu.update(outdatedPackage);
|
|
81
|
+
if (updatedPackages.length !== 1) {
|
|
82
|
+
throw new Error(`Failed to update ${outdatedPackage.name}.`);
|
|
83
|
+
}
|
|
84
|
+
await this.packageManager.install();
|
|
85
|
+
}
|
|
86
|
+
async closeOldPullRequests(outdatedPackage) {
|
|
87
|
+
const pullRequests = this.pullRequestFinder.findByPackageName(outdatedPackage.name);
|
|
88
|
+
this.logger.debug(`pullRequests=${JSON.stringify(pullRequests)}`);
|
|
89
|
+
await Promise.all(pullRequests.map(async (pullRequest) => {
|
|
90
|
+
await this.pullRequestCloser.close(pullRequest);
|
|
91
|
+
this.logger.info(`Pull request for ${outdatedPackage.name} has closed. ${pullRequest.html_url}`);
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
78
94
|
}
|
|
79
95
|
exports.OutdatedPackageProcessor = OutdatedPackageProcessor;
|
package/dist/src/git/Git.js
CHANGED
|
@@ -16,14 +16,6 @@ class Git {
|
|
|
16
16
|
async createBranch(branchName) {
|
|
17
17
|
await this.terminal.run('git', 'checkout', '-b', branchName);
|
|
18
18
|
}
|
|
19
|
-
async getConfig(key) {
|
|
20
|
-
const { stdout } = await this.terminal.run('git', 'config', key);
|
|
21
|
-
return stdout.trim();
|
|
22
|
-
}
|
|
23
|
-
async getCurrentBranch() {
|
|
24
|
-
const { stdout } = await this.terminal.run('git', 'rev-parse', '--abbrev-ref', 'HEAD');
|
|
25
|
-
return stdout.trim();
|
|
26
|
-
}
|
|
27
19
|
async getRemoteUrl() {
|
|
28
20
|
const { stdout } = await this.terminal.run('git', 'remote', 'get-url', '--push', 'origin');
|
|
29
21
|
return stdout.trim();
|
|
@@ -41,9 +33,6 @@ class Git {
|
|
|
41
33
|
async restore(...files) {
|
|
42
34
|
await this.terminal.run('git', 'checkout', ...files);
|
|
43
35
|
}
|
|
44
|
-
async setConfig(key, value) {
|
|
45
|
-
await this.terminal.run('git', 'config', key, value);
|
|
46
|
-
}
|
|
47
36
|
async switch(branchName) {
|
|
48
37
|
await this.terminal.run('git', 'checkout', branchName);
|
|
49
38
|
}
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isNotFoundError = void 0;
|
|
4
4
|
const request_error_1 = require("@octokit/request-error");
|
|
5
5
|
const http_status_codes_1 = require("http-status-codes");
|
|
6
|
-
// TODO: Add test
|
|
7
6
|
const isNotFoundError = (value) => {
|
|
8
7
|
return value instanceof request_error_1.RequestError && value.status === http_status_codes_1.StatusCodes.NOT_FOUND;
|
|
9
8
|
};
|
|
@@ -6,14 +6,16 @@ class PullRequestCloser {
|
|
|
6
6
|
this.github = github;
|
|
7
7
|
}
|
|
8
8
|
async close(pullRequest) {
|
|
9
|
+
const owner = pullRequest.base.repo.owner.login;
|
|
10
|
+
const repo = pullRequest.base.repo.name;
|
|
9
11
|
await this.github.closePullRequest({
|
|
10
|
-
owner
|
|
11
|
-
repo
|
|
12
|
+
owner,
|
|
13
|
+
repo,
|
|
12
14
|
pullNumber: pullRequest.number
|
|
13
15
|
});
|
|
14
16
|
await this.github.deleteBranch({
|
|
15
|
-
owner
|
|
16
|
-
repo
|
|
17
|
+
owner,
|
|
18
|
+
repo,
|
|
17
19
|
branch: pullRequest.head.ref
|
|
18
20
|
});
|
|
19
21
|
}
|
package/dist/src/main.js
CHANGED
|
@@ -89,7 +89,8 @@ const main = async ({ options, logger }) => {
|
|
|
89
89
|
logger,
|
|
90
90
|
commitMessageCreator,
|
|
91
91
|
pullRequestFinder,
|
|
92
|
-
pullRequestCloser
|
|
92
|
+
pullRequestCloser,
|
|
93
|
+
options
|
|
93
94
|
});
|
|
94
95
|
const outdatedPackagesProcessor = new core_1.OutdatedPackagesProcessor({
|
|
95
96
|
outdatedPackageProcessor,
|
|
@@ -18,6 +18,12 @@ exports.cliOptions = [
|
|
|
18
18
|
type: OptionType_1.OptionType.String,
|
|
19
19
|
required: true
|
|
20
20
|
},
|
|
21
|
+
{
|
|
22
|
+
name: 'ignore-packages',
|
|
23
|
+
description: 'Package names to ignore',
|
|
24
|
+
type: OptionType_1.OptionType.StringArray,
|
|
25
|
+
required: false
|
|
26
|
+
},
|
|
21
27
|
{
|
|
22
28
|
name: 'log-level',
|
|
23
29
|
description: 'Log level to show',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-update-package",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.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",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"fp-ts": "2.11.8",
|
|
21
21
|
"http-status-codes": "2.2.0",
|
|
22
22
|
"io-ts": "2.2.16",
|
|
23
|
-
"log4js": "6.4.
|
|
23
|
+
"log4js": "6.4.2",
|
|
24
24
|
"mustache": "4.1.0",
|
|
25
25
|
"npm-check-updates": "12.5.0",
|
|
26
26
|
"parse-github-url": "1.0.2",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"npm-run-all": "4.1.5",
|
|
50
50
|
"rimraf": "3.0.2",
|
|
51
51
|
"ts-jest": "27.1.3",
|
|
52
|
-
"ts-node": "10.
|
|
52
|
+
"ts-node": "10.6.0",
|
|
53
53
|
"typescript": "4.5.5",
|
|
54
54
|
"utility-types": "3.10.0"
|
|
55
55
|
},
|