npm-update-package 0.16.2 → 0.18.0
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 +78 -29
- package/dist/app.js +1 -1
- package/dist/github/GitHub.js +4 -0
- package/dist/github/Label.js +2 -0
- package/dist/github/PullRequestCreator.js +11 -1
- package/dist/main.js +2 -1
- package/dist/ncu/NcuResultConverter.js +23 -12
- package/dist/options/Options.js +14 -9
- package/dist/options/cliOptions.js +6 -0
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -11,35 +11,6 @@ CLI tool for creating pull request to update npm packages
|
|
|
11
11
|
npx npm-update-package --github-token $GITHUB_TOKEN
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
## Examples
|
|
15
|
-
|
|
16
|
-
Example of running npm-update-package on GitHub Actions at 0:00 (UTC) every day:
|
|
17
|
-
|
|
18
|
-
```yaml
|
|
19
|
-
name: npm-update-package
|
|
20
|
-
on:
|
|
21
|
-
schedule:
|
|
22
|
-
- cron: '0 0 * * *'
|
|
23
|
-
jobs:
|
|
24
|
-
npm-update-package:
|
|
25
|
-
runs-on: ubuntu-latest
|
|
26
|
-
steps:
|
|
27
|
-
- uses: actions/checkout@v2
|
|
28
|
-
- uses: actions/setup-node@v2
|
|
29
|
-
- run: |
|
|
30
|
-
git config user.name $GIT_USER_NAME
|
|
31
|
-
git config user.email $GIT_USER_EMAIL
|
|
32
|
-
npx npm-update-package --github-token $GITHUB_TOKEN
|
|
33
|
-
env:
|
|
34
|
-
GIT_USER_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com
|
|
35
|
-
GIT_USER_NAME: github-actions[bot]
|
|
36
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
Actual working examples can be seen in these repositories.
|
|
40
|
-
|
|
41
|
-
- [npm-update-package/example-npm](https://github.com/npm-update-package/example-npm)
|
|
42
|
-
|
|
43
14
|
## Options
|
|
44
15
|
|
|
45
16
|
You can customize behavior via command-line options.
|
|
@@ -129,6 +100,13 @@ This PR updates these packages:
|
|
|
129
100
|
This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}
|
|
130
101
|
```
|
|
131
102
|
|
|
103
|
+
### `--pull-request-labels`
|
|
104
|
+
|
|
105
|
+
Pull request labels
|
|
106
|
+
|
|
107
|
+
- type: string array
|
|
108
|
+
- required: false
|
|
109
|
+
|
|
132
110
|
### `--pull-request-title`
|
|
133
111
|
|
|
134
112
|
Pull request title template
|
|
@@ -142,8 +120,79 @@ Pull request title template
|
|
|
142
120
|
- required: false
|
|
143
121
|
- default: `chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}`
|
|
144
122
|
|
|
123
|
+
## Examples
|
|
124
|
+
|
|
125
|
+
Example of running npm-update-package on GitHub Actions at 0:00 (UTC) every day:
|
|
126
|
+
|
|
127
|
+
```yaml
|
|
128
|
+
name: npm-update-package
|
|
129
|
+
on:
|
|
130
|
+
schedule:
|
|
131
|
+
- cron: '0 0 * * *'
|
|
132
|
+
jobs:
|
|
133
|
+
npm-update-package:
|
|
134
|
+
runs-on: ubuntu-latest
|
|
135
|
+
steps:
|
|
136
|
+
- uses: actions/checkout@v2
|
|
137
|
+
- uses: actions/setup-node@v2
|
|
138
|
+
- run: |
|
|
139
|
+
git config user.name $GIT_USER_NAME
|
|
140
|
+
git config user.email $GIT_USER_EMAIL
|
|
141
|
+
npx npm-update-package --github-token $GITHUB_TOKEN
|
|
142
|
+
env:
|
|
143
|
+
GIT_USER_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com
|
|
144
|
+
GIT_USER_NAME: github-actions[bot]
|
|
145
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Actual working examples can be seen in these repositories.
|
|
149
|
+
|
|
150
|
+
- [npm-update-package/example-npm](https://github.com/npm-update-package/example-npm)
|
|
151
|
+
|
|
152
|
+
## Flow
|
|
153
|
+
|
|
154
|
+
The following shows the process flow of npm-update-package:
|
|
155
|
+
|
|
156
|
+
[](http://www.plantuml.com/plantuml/uml/RKyxKiCm5EpVARPqYbmWRi9Gq4666GuWx4tiGPQ4z0JXzaIn70D38wsUzkrddzH4pPELAv1Jz3bWCgEJtGCLFcjlb3s2wTxCYQaL6OzexgozZM0YaSDM_RPmDz213iqNqqO0kbve4z4ulv7BQpnAjNcgueSgT8Y-Oqe-IcIWKG7-9Quye8HvvkILU8t6TGDu7fEcFodM102mkuyqjursdhs4uh6qQdyHGxOMaU-PIUjFCVtuAN6jDjzpxDe2dyDeYUQHPrtKbv2oabTOaEmlHvxiDm00)
|
|
157
|
+
|
|
158
|
+
<!--
|
|
159
|
+
```plantuml
|
|
160
|
+
@startuml
|
|
161
|
+
start
|
|
162
|
+
group main
|
|
163
|
+
:Get outdated packages;
|
|
164
|
+
|
|
165
|
+
if (All packages are up-to-date) then (yes)
|
|
166
|
+
end
|
|
167
|
+
else (no)
|
|
168
|
+
endif
|
|
169
|
+
|
|
170
|
+
group OutdatedPackagesProcessor
|
|
171
|
+
repeat
|
|
172
|
+
group OutdatedPackageProcessor
|
|
173
|
+
if (Remote branch exists) then (yes)
|
|
174
|
+
else (no)
|
|
175
|
+
:Create branch;
|
|
176
|
+
:Update package;
|
|
177
|
+
:Create pull request;
|
|
178
|
+
:Remove branch;
|
|
179
|
+
endif
|
|
180
|
+
end group
|
|
181
|
+
repeat while (Next package exists)
|
|
182
|
+
end group
|
|
183
|
+
|
|
184
|
+
end group
|
|
185
|
+
end
|
|
186
|
+
@enduml
|
|
187
|
+
```
|
|
188
|
+
-->
|
|
189
|
+
|
|
145
190
|
## FAQ
|
|
146
191
|
|
|
192
|
+
### What is the purpose of npm-update-package?
|
|
193
|
+
|
|
194
|
+
npm-update-package can be used in environments where Renovate cannot be used for some reason.
|
|
195
|
+
|
|
147
196
|
### Conflicts have occurred in PR. What should I do?
|
|
148
197
|
|
|
149
198
|
If conflicts have occurred in PR, close it and run npm-update-package again.
|
package/dist/app.js
CHANGED
package/dist/github/GitHub.js
CHANGED
|
@@ -6,6 +6,10 @@ class GitHub {
|
|
|
6
6
|
constructor(octokit) {
|
|
7
7
|
this.octokit = octokit;
|
|
8
8
|
}
|
|
9
|
+
async addLabels(params) {
|
|
10
|
+
const { data } = await this.octokit.issues.addLabels(params);
|
|
11
|
+
return data;
|
|
12
|
+
}
|
|
9
13
|
async createPullRequest(params) {
|
|
10
14
|
const { data } = await this.octokit.pulls.create(params);
|
|
11
15
|
return data;
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PullRequestCreator = void 0;
|
|
4
4
|
class PullRequestCreator {
|
|
5
|
-
constructor({ github, gitRepo, githubRepo, pullRequestTitleCreator, pullRequestBodyCreator, logger }) {
|
|
5
|
+
constructor({ github, gitRepo, githubRepo, pullRequestTitleCreator, pullRequestBodyCreator, logger, labels }) {
|
|
6
6
|
this.github = github;
|
|
7
7
|
this.gitRepo = gitRepo;
|
|
8
8
|
this.githubRepo = githubRepo;
|
|
9
9
|
this.pullRequestTitleCreator = pullRequestTitleCreator;
|
|
10
10
|
this.pullRequestBodyCreator = pullRequestBodyCreator;
|
|
11
11
|
this.logger = logger;
|
|
12
|
+
this.labels = labels;
|
|
12
13
|
}
|
|
13
14
|
async create({ outdatedPackage, branchName }) {
|
|
14
15
|
const title = this.pullRequestTitleCreator.create(outdatedPackage);
|
|
@@ -24,6 +25,15 @@ class PullRequestCreator {
|
|
|
24
25
|
body
|
|
25
26
|
});
|
|
26
27
|
this.logger.debug(`pullRequest=${JSON.stringify(pullRequest)}`);
|
|
28
|
+
if (this.labels !== undefined) {
|
|
29
|
+
const labels = await this.github.addLabels({
|
|
30
|
+
owner: this.gitRepo.owner,
|
|
31
|
+
repo: this.gitRepo.name,
|
|
32
|
+
issue_number: pullRequest.number,
|
|
33
|
+
labels: this.labels
|
|
34
|
+
});
|
|
35
|
+
this.logger.debug(`labels=${JSON.stringify(labels)}`);
|
|
36
|
+
}
|
|
27
37
|
this.logger.info(`Pull request for ${outdatedPackage.name} has created. ${pullRequest.html_url}`);
|
|
28
38
|
}
|
|
29
39
|
}
|
package/dist/main.js
CHANGED
|
@@ -59,7 +59,8 @@ const main = async ({ options, logger }) => {
|
|
|
59
59
|
githubRepo,
|
|
60
60
|
pullRequestTitleCreator,
|
|
61
61
|
pullRequestBodyCreator,
|
|
62
|
-
logger
|
|
62
|
+
logger,
|
|
63
|
+
labels: options.pullRequestLabels
|
|
63
64
|
});
|
|
64
65
|
const branchNameCreator = new git_1.BranchNameCreator(options.branchName);
|
|
65
66
|
const commitMessageCreator = new git_1.CommitMessageCreator(options.commitMessage);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NcuResultConverter = void 0;
|
|
4
|
+
const type_guards_1 = require("type-guards");
|
|
4
5
|
const PackageVersion_1 = require("./PackageVersion");
|
|
5
6
|
const toUpdateType_1 = require("./toUpdateType");
|
|
6
7
|
// TODO: add test
|
|
@@ -9,18 +10,28 @@ class NcuResultConverter {
|
|
|
9
10
|
this.currentDependencies = currentDependencies;
|
|
10
11
|
}
|
|
11
12
|
toOutdatedPackages(result) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
name,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
newVersion
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
const resultEntries = Object.entries(result);
|
|
14
|
+
const outdatedPackages = resultEntries
|
|
15
|
+
.map(([name, newVersionString]) => {
|
|
16
|
+
const currentVersionString = this.currentDependencies[name];
|
|
17
|
+
if (currentVersionString === undefined) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const currentVersion = PackageVersion_1.PackageVersion.of(currentVersionString);
|
|
21
|
+
const newVersion = PackageVersion_1.PackageVersion.of(newVersionString);
|
|
22
|
+
const type = (0, toUpdateType_1.toUpdateType)(currentVersion, newVersion);
|
|
23
|
+
return {
|
|
24
|
+
name,
|
|
25
|
+
currentVersion,
|
|
26
|
+
newVersion,
|
|
27
|
+
type
|
|
28
|
+
};
|
|
29
|
+
})
|
|
30
|
+
.filter(type_guards_1.isNotUndefined);
|
|
31
|
+
if (resultEntries.length !== outdatedPackages.length) {
|
|
32
|
+
throw new Error('Failed to convert to outdatedPackages from NcuResult.');
|
|
33
|
+
}
|
|
34
|
+
return outdatedPackages;
|
|
24
35
|
}
|
|
25
36
|
}
|
|
26
37
|
exports.NcuResultConverter = NcuResultConverter;
|
package/dist/options/Options.js
CHANGED
|
@@ -4,13 +4,18 @@ exports.isOptions = void 0;
|
|
|
4
4
|
const io_ts_1 = require("io-ts");
|
|
5
5
|
const logger_1 = require("../logger");
|
|
6
6
|
const package_manager_1 = require("../package-manager");
|
|
7
|
-
const Options = (0, io_ts_1.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
const Options = (0, io_ts_1.intersection)([
|
|
8
|
+
(0, io_ts_1.type)({
|
|
9
|
+
branchName: io_ts_1.string,
|
|
10
|
+
commitMessage: io_ts_1.string,
|
|
11
|
+
githubToken: io_ts_1.string,
|
|
12
|
+
logLevel: (0, io_ts_1.union)([(0, io_ts_1.literal)(logger_1.LogLevel.Off), (0, io_ts_1.literal)(logger_1.LogLevel.Error), (0, io_ts_1.literal)(logger_1.LogLevel.Info), (0, io_ts_1.literal)(logger_1.LogLevel.Debug)]),
|
|
13
|
+
packageManager: (0, io_ts_1.union)([(0, io_ts_1.literal)(package_manager_1.PackageManagerName.Npm), (0, io_ts_1.literal)(package_manager_1.PackageManagerName.Yarn)]),
|
|
14
|
+
pullRequestBody: io_ts_1.string,
|
|
15
|
+
pullRequestTitle: io_ts_1.string
|
|
16
|
+
}),
|
|
17
|
+
(0, io_ts_1.partial)({
|
|
18
|
+
pullRequestLabels: (0, io_ts_1.array)(io_ts_1.string)
|
|
19
|
+
})
|
|
20
|
+
]);
|
|
16
21
|
exports.isOptions = Options.is;
|
|
@@ -63,6 +63,12 @@ exports.cliOptions = [
|
|
|
63
63
|
---
|
|
64
64
|
This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}`
|
|
65
65
|
},
|
|
66
|
+
{
|
|
67
|
+
name: 'pull-request-labels',
|
|
68
|
+
description: 'Pull request labels',
|
|
69
|
+
type: OptionType_1.OptionType.StringArray,
|
|
70
|
+
required: false
|
|
71
|
+
},
|
|
66
72
|
{
|
|
67
73
|
name: 'pull-request-title',
|
|
68
74
|
description: 'Pull request title template',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-update-package",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "CLI tool for creating pull request to update npm packages",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc --project tsconfig.build.json",
|
|
@@ -26,21 +26,22 @@
|
|
|
26
26
|
"mustache": "4.1.0",
|
|
27
27
|
"npm-check-updates": "12.0.5",
|
|
28
28
|
"parse-github-url": "1.0.2",
|
|
29
|
-
"semver": "7.3.5"
|
|
29
|
+
"semver": "7.3.5",
|
|
30
|
+
"type-guards": "0.15.0"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@jest/types": "27.0.6",
|
|
33
|
-
"@tsconfig/
|
|
34
|
+
"@tsconfig/node14": "1.0.1",
|
|
34
35
|
"@types/jest": "27.0.3",
|
|
35
36
|
"@types/mustache": "4.1.2",
|
|
36
|
-
"@types/node": "
|
|
37
|
+
"@types/node": "14.18.3",
|
|
37
38
|
"@types/parse-github-url": "1.0.0",
|
|
38
39
|
"@types/semver": "7.3.9",
|
|
39
|
-
"@typescript-eslint/eslint-plugin": "5.8.
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "5.8.1",
|
|
40
41
|
"eslint": "8.5.0",
|
|
41
42
|
"eslint-config-standard-with-typescript": "21.0.1",
|
|
42
43
|
"eslint-plugin-import": "2.25.3",
|
|
43
|
-
"eslint-plugin-jest": "25.3.
|
|
44
|
+
"eslint-plugin-jest": "25.3.2",
|
|
44
45
|
"eslint-plugin-node": "11.1.0",
|
|
45
46
|
"eslint-plugin-promise": "6.0.0",
|
|
46
47
|
"eslint-plugin-tsdoc": "0.2.14",
|