npm-update-package 0.46.3 → 0.46.6
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/dist/package.json +3 -3
- package/dist/src/core/OutdatedPackageProcessor.js +3 -10
- package/dist/src/core/PackageUpdater.js +17 -0
- package/dist/src/core/index.js +1 -0
- package/dist/src/git/GitRepository.js +32 -11
- package/dist/src/github/pull-request/creator/PullRequestBodyCreator.js +1 -1
- package/dist/src/logger/createLogger.js +0 -1
- package/dist/src/main.js +9 -2
- package/dist/src/package-json/extractRepository.js +4 -11
- package/package.json +3 -3
- package/dist/src/package-json/parseRepositoryString.js +0 -20
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-update-package",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.6",
|
|
4
4
|
"description": "CLI tool for creating pull requests to update npm packages",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"badges": "jest-coverage-badges output docs",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"log4js": "6.4.3",
|
|
27
27
|
"mustache": "4.1.0",
|
|
28
28
|
"node-fetch": "2.6.7",
|
|
29
|
-
"npm-check-updates": "12.5.
|
|
29
|
+
"npm-check-updates": "12.5.4",
|
|
30
30
|
"parse-github-url": "1.0.2",
|
|
31
31
|
"semver": "7.3.5",
|
|
32
32
|
"sleep-promise": "9.1.0",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"husky": "7.0.4",
|
|
54
54
|
"jest": "27.4.7",
|
|
55
55
|
"jest-coverage-badges": "1.1.2",
|
|
56
|
-
"lint-staged": "12.3.
|
|
56
|
+
"lint-staged": "12.3.7",
|
|
57
57
|
"npm-run-all": "4.1.5",
|
|
58
58
|
"rimraf": "3.0.2",
|
|
59
59
|
"ts-jest": "27.1.3",
|
|
@@ -5,9 +5,8 @@ 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,
|
|
8
|
+
constructor({ git, packageManager, pullRequestCreator, branchFinder, logger, commitMessageCreator, pullRequestFinder, pullRequestCloser, packageUpdater }) {
|
|
9
9
|
this.git = git;
|
|
10
|
-
this.ncu = ncu;
|
|
11
10
|
this.packageManager = packageManager;
|
|
12
11
|
this.pullRequestCreator = pullRequestCreator;
|
|
13
12
|
this.branchFinder = branchFinder;
|
|
@@ -15,6 +14,7 @@ class OutdatedPackageProcessor {
|
|
|
15
14
|
this.commitMessageCreator = commitMessageCreator;
|
|
16
15
|
this.pullRequestFinder = pullRequestFinder;
|
|
17
16
|
this.pullRequestCloser = pullRequestCloser;
|
|
17
|
+
this.packageUpdater = packageUpdater;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Don't run in parallel because it includes file operations.
|
|
@@ -33,7 +33,7 @@ class OutdatedPackageProcessor {
|
|
|
33
33
|
this.logger.info(`${branchName} branch has created.`);
|
|
34
34
|
try {
|
|
35
35
|
try {
|
|
36
|
-
await this.
|
|
36
|
+
await this.packageUpdater.update(outdatedPackage);
|
|
37
37
|
}
|
|
38
38
|
catch (error) {
|
|
39
39
|
this.logger.error(error);
|
|
@@ -66,13 +66,6 @@ class OutdatedPackageProcessor {
|
|
|
66
66
|
this.logger.info(`${branchName} branch has removed.`);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
async updatePackage(outdatedPackage) {
|
|
70
|
-
const updatedPackages = await this.ncu.update(outdatedPackage);
|
|
71
|
-
if (updatedPackages.length !== 1) {
|
|
72
|
-
throw new Error(`Failed to update ${outdatedPackage.name}.`);
|
|
73
|
-
}
|
|
74
|
-
await this.packageManager.install();
|
|
75
|
-
}
|
|
76
69
|
async closeOldPullRequests(outdatedPackage) {
|
|
77
70
|
const pullRequests = this.pullRequestFinder.findByPackageName(outdatedPackage.name);
|
|
78
71
|
this.logger.debug(`pullRequests=${JSON.stringify(pullRequests)}`);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PackageUpdater = void 0;
|
|
4
|
+
class PackageUpdater {
|
|
5
|
+
constructor({ packageManager, ncu }) {
|
|
6
|
+
this.packageManager = packageManager;
|
|
7
|
+
this.ncu = ncu;
|
|
8
|
+
}
|
|
9
|
+
async update(outdatedPackage) {
|
|
10
|
+
const updatedPackages = await this.ncu.update(outdatedPackage);
|
|
11
|
+
if (updatedPackages.length !== 1) {
|
|
12
|
+
throw new Error(`Failed to update ${outdatedPackage.name}.`);
|
|
13
|
+
}
|
|
14
|
+
await this.packageManager.install();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.PackageUpdater = PackageUpdater;
|
package/dist/src/core/index.js
CHANGED
|
@@ -18,4 +18,5 @@ __exportStar(require("./FailedResult"), exports);
|
|
|
18
18
|
__exportStar(require("./OutdatedPackage"), exports);
|
|
19
19
|
__exportStar(require("./OutdatedPackageProcessor"), exports);
|
|
20
20
|
__exportStar(require("./OutdatedPackagesProcessor"), exports);
|
|
21
|
+
__exportStar(require("./PackageUpdater"), exports);
|
|
21
22
|
__exportStar(require("./SucceededResult"), exports);
|
|
@@ -6,27 +6,48 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.GitRepository = void 0;
|
|
7
7
|
const url_1 = require("url");
|
|
8
8
|
const parse_github_url_1 = __importDefault(require("parse-github-url"));
|
|
9
|
+
const HOST_GITHUB = 'github.com';
|
|
9
10
|
class GitRepository {
|
|
10
|
-
constructor({ url, owner, name }) {
|
|
11
|
+
constructor({ url, owner, name, isGitHub }) {
|
|
11
12
|
this.url = url;
|
|
12
13
|
this.owner = owner;
|
|
13
14
|
this.name = name;
|
|
15
|
+
this.isGitHub = isGitHub;
|
|
14
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Parses a repository string.
|
|
19
|
+
* @example Valid strings
|
|
20
|
+
* - `<owner>/<repo>`
|
|
21
|
+
* - `github:<owner>/<repo>`
|
|
22
|
+
* - `https://<host>/<owner>/<repo>`
|
|
23
|
+
* - `https://<host>/<owner>/<repo>.git`
|
|
24
|
+
* - `git://<host>/<owner>/<repo>`
|
|
25
|
+
* - `git://<host>/<owner>/<repo>.git`
|
|
26
|
+
* - `git+https://<host>/<owner>/<repo>`
|
|
27
|
+
* - `git+https://<host>/<owner>/<repo>.git`
|
|
28
|
+
* - `git+ssh://<host>/<owner>/<repo>`
|
|
29
|
+
* - `git+ssh://<host>/<owner>/<repo>.git`
|
|
30
|
+
* - `git@<host>:<owner>/<repo>`
|
|
31
|
+
* - `git@<host>:<owner>/<repo>.git`
|
|
32
|
+
*/
|
|
15
33
|
static of(repository) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
throw new Error(`Failed to parse repository. repository=${repository}`);
|
|
34
|
+
const result = (0, parse_github_url_1.default)(repository);
|
|
35
|
+
if (result === null) {
|
|
36
|
+
return undefined;
|
|
20
37
|
}
|
|
21
|
-
const {
|
|
22
|
-
if (
|
|
23
|
-
|
|
38
|
+
const { owner, name } = result;
|
|
39
|
+
if (owner === null || name === null) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const host = result.protocol === 'github:' ? HOST_GITHUB : result.host;
|
|
43
|
+
if (host === null || !host.includes('.')) {
|
|
44
|
+
return undefined;
|
|
24
45
|
}
|
|
25
|
-
const protocol = (_a = parsed.protocol) !== null && _a !== void 0 ? _a : 'https:';
|
|
26
46
|
return new GitRepository({
|
|
27
|
-
url: new url_1.URL(
|
|
47
|
+
url: new url_1.URL(`https://${host}/${owner}/${name}`),
|
|
28
48
|
owner,
|
|
29
|
-
name
|
|
49
|
+
name,
|
|
50
|
+
isGitHub: host === HOST_GITHUB
|
|
30
51
|
});
|
|
31
52
|
}
|
|
32
53
|
}
|
|
@@ -20,7 +20,7 @@ class PullRequestBodyCreator {
|
|
|
20
20
|
const outdatedPackagesTable = this.createOutdatedPackagesTable(outdatedPackage);
|
|
21
21
|
sections.push(`This PR updates these packages:\n\n${outdatedPackagesTable}`);
|
|
22
22
|
const gitRepo = await this.extractRepository(outdatedPackage);
|
|
23
|
-
if (gitRepo
|
|
23
|
+
if ((gitRepo === null || gitRepo === void 0 ? void 0 : gitRepo.isGitHub) === true) {
|
|
24
24
|
const releaseNotesSection = await this.createReleaseNotesSection({
|
|
25
25
|
outdatedPackage,
|
|
26
26
|
gitRepo
|
package/dist/src/main.js
CHANGED
|
@@ -30,6 +30,9 @@ const main = async ({ options, logger }) => {
|
|
|
30
30
|
const remoteUrl = await git.getRemoteUrl();
|
|
31
31
|
const gitRepo = git_1.GitRepository.of(remoteUrl);
|
|
32
32
|
logger.debug(`gitRepo=${JSON.stringify(gitRepo)}`);
|
|
33
|
+
if (gitRepo === undefined) {
|
|
34
|
+
throw new Error(`Failed to parse remote url. URL=${remoteUrl}`);
|
|
35
|
+
}
|
|
33
36
|
const github = (0, github_1.createGitHub)({
|
|
34
37
|
host: gitRepo.url.host,
|
|
35
38
|
token: options.githubToken
|
|
@@ -83,16 +86,20 @@ const main = async ({ options, logger }) => {
|
|
|
83
86
|
const commitMessageCreator = new git_1.CommitMessageCreator(options.commitMessage);
|
|
84
87
|
const pullRequestFinder = new github_1.PullRequestFinder(pullRequests);
|
|
85
88
|
const pullRequestCloser = new github_1.PullRequestCloser(github);
|
|
89
|
+
const packageUpdater = new core_1.PackageUpdater({
|
|
90
|
+
packageManager,
|
|
91
|
+
ncu
|
|
92
|
+
});
|
|
86
93
|
const outdatedPackageProcessor = new core_1.OutdatedPackageProcessor({
|
|
87
94
|
git,
|
|
88
|
-
ncu,
|
|
89
95
|
packageManager,
|
|
90
96
|
pullRequestCreator,
|
|
91
97
|
branchFinder,
|
|
92
98
|
logger,
|
|
93
99
|
commitMessageCreator,
|
|
94
100
|
pullRequestFinder,
|
|
95
|
-
pullRequestCloser
|
|
101
|
+
pullRequestCloser,
|
|
102
|
+
packageUpdater
|
|
96
103
|
});
|
|
97
104
|
const outdatedPackagesProcessor = new core_1.OutdatedPackagesProcessor({
|
|
98
105
|
outdatedPackageProcessor,
|
|
@@ -2,19 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extractRepository = void 0;
|
|
4
4
|
const git_1 = require("../git");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const extractRepository = (pkg) => {
|
|
6
|
+
const { repository } = pkg;
|
|
7
7
|
if (repository === undefined) {
|
|
8
8
|
return undefined;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (!isGitHub) {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
return git_1.GitRepository.of(`${owner}/${repo}`);
|
|
16
|
-
}
|
|
17
|
-
const { url } = repository;
|
|
18
|
-
return git_1.GitRepository.of(url.replace(/^git\+/, ''));
|
|
10
|
+
const repositoryString = typeof repository === 'string' ? repository : repository.url;
|
|
11
|
+
return git_1.GitRepository.of(repositoryString);
|
|
19
12
|
};
|
|
20
13
|
exports.extractRepository = extractRepository;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-update-package",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.6",
|
|
4
4
|
"description": "CLI tool for creating pull requests to update npm packages",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"badges": "jest-coverage-badges output docs",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"log4js": "6.4.3",
|
|
27
27
|
"mustache": "4.1.0",
|
|
28
28
|
"node-fetch": "2.6.7",
|
|
29
|
-
"npm-check-updates": "12.5.
|
|
29
|
+
"npm-check-updates": "12.5.4",
|
|
30
30
|
"parse-github-url": "1.0.2",
|
|
31
31
|
"semver": "7.3.5",
|
|
32
32
|
"sleep-promise": "9.1.0",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"husky": "7.0.4",
|
|
54
54
|
"jest": "27.4.7",
|
|
55
55
|
"jest-coverage-badges": "1.1.2",
|
|
56
|
-
"lint-staged": "12.3.
|
|
56
|
+
"lint-staged": "12.3.7",
|
|
57
57
|
"npm-run-all": "4.1.5",
|
|
58
58
|
"rimraf": "3.0.2",
|
|
59
59
|
"ts-jest": "27.1.3",
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseRepositoryString = void 0;
|
|
4
|
-
const parseRepositoryString = (repository) => {
|
|
5
|
-
const matched = repository.match(/^((.+):)?(.+)\/(.+)/);
|
|
6
|
-
if (matched === null) {
|
|
7
|
-
throw new Error(`Failed to parse repository. repository=${repository}`);
|
|
8
|
-
}
|
|
9
|
-
const [, , type, owner, repo] = matched;
|
|
10
|
-
/* istanbul ignore if: I can't write a test to reach here. */
|
|
11
|
-
if (owner === undefined || repo === undefined) {
|
|
12
|
-
throw new Error(`Failed to parse repository. repository=${repository}`);
|
|
13
|
-
}
|
|
14
|
-
return {
|
|
15
|
-
owner,
|
|
16
|
-
repo,
|
|
17
|
-
isGitHub: type === undefined || type === 'github'
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
exports.parseRepositoryString = parseRepositoryString;
|