npm-update-package 0.20.0 → 0.22.1

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 CHANGED
@@ -14,20 +14,7 @@ npx npm-update-package --github-token $GITHUB_TOKEN
14
14
  ## Options
15
15
 
16
16
  You can customize behavior via command-line options.
17
- Template strings such as `--branch-name` can embed variables like `{{packageName}}`(HTML-escaped) or `{{{packageName}}}`(not HTML-escaped).
18
-
19
- ### `--branch-name`
20
-
21
- Branch name template
22
-
23
- - type: string
24
- - variables:
25
- - `currentVersion`
26
- - `newVersion`
27
- - `packageName`
28
- - `updateType`
29
- - required: false
30
- - default: `npm-update-package/{{{packageName}}}/v{{newVersion}}`
17
+ Template strings such as `--commit-message` can embed variables like `{{packageName}}`(HTML-escaped) or `{{{packageName}}}`(not HTML-escaped).
31
18
 
32
19
  ### `--commit-message`
33
20
 
@@ -73,40 +60,6 @@ Package manager of your project
73
60
  - required: false
74
61
  - default: `npm`
75
62
 
76
- ### `--pull-request-body`
77
-
78
- Pull request body template
79
-
80
- - type: string
81
- - variables:
82
- - `appName`
83
- - `appVersion`
84
- - `appWeb`
85
- - `currentVersion`
86
- - `newVersion`
87
- - `packageName`
88
- - `updateType`
89
- - required: false
90
- - default:
91
-
92
- ```
93
- This PR updates these packages:
94
-
95
- |package|type|current version|new version|
96
- |---|---|---|---|
97
- |[{{{packageName}}}](https://www.npmjs.com/package/{{{packageName}}})|{{updateType}}|\`{{currentVersion}}\`|\`{{newVersion}}\`|
98
-
99
- ---
100
- This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}
101
- ```
102
-
103
- ### `--pull-request-labels`
104
-
105
- Pull request labels
106
-
107
- - type: string array
108
- - required: false
109
-
110
63
  ### `--pull-request-title`
111
64
 
112
65
  Pull request title template
@@ -153,8 +106,6 @@ Actual working examples can be seen in these repositories.
153
106
 
154
107
  The following shows the process flow of npm-update-package:
155
108
 
156
- [![](http://www.plantuml.com/plantuml/svg/RKyxKiCm5EpVARPqYbmWRi9Gq4666GuWx4tiGPQ4z0JXzaIn70D38wsUzkrddzH4pPELAv1Jz3bWCgEJtGCLFcjlb3s2wTxCYQaL6OzexgozZM0YaSDM_RPmDz213iqNqqO0kbve4z4ulv7BQpnAjNcgueSgT8Y-Oqe-IcIWKG7-9Quye8HvvkILU8t6TGDu7fEcFodM102mkuyqjursdhs4uh6qQdyHGxOMaU-PIUjFCVtuAN6jDjzpxDe2dyDeYUQHPrtKbv2oabTOaEmlHvxiDm00)](http://www.plantuml.com/plantuml/uml/RKyxKiCm5EpVARPqYbmWRi9Gq4666GuWx4tiGPQ4z0JXzaIn70D38wsUzkrddzH4pPELAv1Jz3bWCgEJtGCLFcjlb3s2wTxCYQaL6OzexgozZM0YaSDM_RPmDz213iqNqqO0kbve4z4ulv7BQpnAjNcgueSgT8Y-Oqe-IcIWKG7-9Quye8HvvkILU8t6TGDu7fEcFodM102mkuyqjursdhs4uh6qQdyHGxOMaU-PIUjFCVtuAN6jDjzpxDe2dyDeYUQHPrtKbv2oabTOaEmlHvxiDm00)
157
-
158
109
  <!--
159
110
  ```plantuml
160
111
  @startuml
@@ -167,18 +118,23 @@ if (All packages are up-to-date) then (yes)
167
118
  else (no)
168
119
  endif
169
120
 
121
+ :Get remote branches;
122
+ :Get pull requests;
123
+
170
124
  group OutdatedPackagesProcessor
171
- repeat
125
+ while (Package exists) is (yes)
172
126
  group OutdatedPackageProcessor
173
127
  if (Remote branch exists) then (yes)
174
128
  else (no)
175
129
  :Create branch;
176
130
  :Update package;
177
131
  :Create pull request;
132
+ :Close old pull requests;
178
133
  :Remove branch;
179
134
  endif
180
135
  end group
181
- repeat while (Next package exists)
136
+ endwhile (no)
137
+
182
138
  end group
183
139
 
184
140
  end group
@@ -187,6 +143,8 @@ end
187
143
  ```
188
144
  -->
189
145
 
146
+ [![](http://www.plantuml.com/plantuml/svg/RL0vSiCm3EpnYYsbmX-m6cTIf8mdCta08y4M9n39yCZn-uYYJ4kPD3omm1uuXQXyJ9FGyg2hjybXKjhGyOaZR8g3YZp0gVvTNJbqHFg2va6abg0y8xb3j8VSsoAERD3yS6W9O3CGIs0qnhOq__I52hVdoKR6crUc7sVcKdL919u_4eUOrOgZvzN7UTKyUzjp2DRJrwY5qQm0-5lFSorqg0x-PRWJ03dGozPCPTadgIa0uFZeMTM9hjHUNTQuRQRRDkw2tH2nWM5b-9EweDdIvrPWMLwvIwYypf9_iKLtW7OzT9gFDCal)](http://www.plantuml.com/plantuml/uml/RL0vSiCm3EpnYYsbmX-m6cTIf8mdCta08y4M9n39yCZn-uYYJ4kPD3omm1uuXQXyJ9FGyg2hjybXKjhGyOaZR8g3YZp0gVvTNJbqHFg2va6abg0y8xb3j8VSsoAERD3yS6W9O3CGIs0qnhOq__I52hVdoKR6crUc7sVcKdL919u_4eUOrOgZvzN7UTKyUzjp2DRJrwY5qQm0-5lFSorqg0x-PRWJ03dGozPCPTadgIa0uFZeMTM9hjHUNTQuRQRRDkw2tH2nWM5b-9EweDdIvrPWMLwvIwYypf9_iKLtW7OzT9gFDCal)
147
+
190
148
  ## FAQ
191
149
 
192
150
  ### What is the purpose of npm-update-package?
package/dist/app.js CHANGED
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.app = void 0;
4
4
  exports.app = {
5
5
  name: 'npm-update-package',
6
- version: '0.20.0',
6
+ version: '0.22.1',
7
7
  web: 'https://github.com/npm-update-package/npm-update-package'
8
8
  };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createBranchName = void 0;
4
+ const mustache_1 = require("mustache");
5
+ const TEMPLATE = 'npm-update-package/{{{packageName}}}/v{{newVersion}}';
6
+ const createBranchName = (outdatedPackage) => {
7
+ const packageName = outdatedPackage.name;
8
+ const currentVersion = outdatedPackage.currentVersion.version;
9
+ const newVersion = outdatedPackage.newVersion.version;
10
+ const updateType = outdatedPackage.type;
11
+ return (0, mustache_1.render)(TEMPLATE, {
12
+ packageName,
13
+ currentVersion,
14
+ newVersion,
15
+ updateType
16
+ });
17
+ };
18
+ exports.createBranchName = createBranchName;
package/dist/git/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GitRepository = exports.Git = exports.CommitMessageCreator = exports.BranchNameCreator = void 0;
4
- var BranchNameCreator_1 = require("./BranchNameCreator");
5
- Object.defineProperty(exports, "BranchNameCreator", { enumerable: true, get: function () { return BranchNameCreator_1.BranchNameCreator; } });
3
+ exports.GitRepository = exports.Git = exports.CommitMessageCreator = exports.createBranchName = void 0;
4
+ var createBranchName_1 = require("./createBranchName");
5
+ Object.defineProperty(exports, "createBranchName", { enumerable: true, get: function () { return createBranchName_1.createBranchName; } });
6
6
  var CommitMessageCreator_1 = require("./CommitMessageCreator");
7
7
  Object.defineProperty(exports, "CommitMessageCreator", { enumerable: true, get: function () { return CommitMessageCreator_1.CommitMessageCreator; } });
8
8
  var Git_1 = require("./Git");
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -10,12 +10,30 @@ class GitHub {
10
10
  const { data } = await this.octokit.issues.addLabels(params);
11
11
  return data;
12
12
  }
13
+ async closePullRequest(params) {
14
+ await this.octokit.pulls.update({
15
+ ...params,
16
+ state: 'closed'
17
+ });
18
+ }
13
19
  async createPullRequest(params) {
14
20
  const { data } = await this.octokit.pulls.create(params);
15
21
  return data;
16
22
  }
23
+ // TODO: fetch all branches with page option
17
24
  async fetchBranches(params) {
18
- const { data } = await this.octokit.repos.listBranches(params);
25
+ const { data } = await this.octokit.repos.listBranches({
26
+ ...params,
27
+ per_page: 100
28
+ });
29
+ return data;
30
+ }
31
+ // TODO: fetch all pull requests with page option
32
+ async fetchPullRequests(params) {
33
+ const { data } = await this.octokit.pulls.list({
34
+ ...params,
35
+ per_page: 100
36
+ });
19
37
  return data;
20
38
  }
21
39
  async fetchRepository(params) {
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PullRequestCloser = void 0;
4
+ // TODO: Add test
5
+ class PullRequestCloser {
6
+ constructor(github) {
7
+ this.github = github;
8
+ }
9
+ async close(pullRequest) {
10
+ await this.github.closePullRequest({
11
+ owner: pullRequest.base.repo.owner.login,
12
+ repo: pullRequest.base.repo.name,
13
+ pull_number: pullRequest.number
14
+ });
15
+ }
16
+ }
17
+ exports.PullRequestCloser = PullRequestCloser;
@@ -1,20 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PullRequestCreator = void 0;
4
+ const createPullRequestBody_1 = require("./createPullRequestBody");
4
5
  class PullRequestCreator {
5
- constructor({ github, gitRepo, githubRepo, pullRequestTitleCreator, pullRequestBodyCreator, logger, labels }) {
6
+ constructor({ github, gitRepo, githubRepo, pullRequestTitleCreator, logger }) {
6
7
  this.github = github;
7
8
  this.gitRepo = gitRepo;
8
9
  this.githubRepo = githubRepo;
9
10
  this.pullRequestTitleCreator = pullRequestTitleCreator;
10
- this.pullRequestBodyCreator = pullRequestBodyCreator;
11
11
  this.logger = logger;
12
- this.labels = labels;
13
12
  }
14
13
  async create({ outdatedPackage, branchName }) {
15
14
  const title = this.pullRequestTitleCreator.create(outdatedPackage);
16
15
  this.logger.debug(`title=${title}`);
17
- const body = this.pullRequestBodyCreator.create(outdatedPackage);
16
+ const body = (0, createPullRequestBody_1.createPullRequestBody)(outdatedPackage);
18
17
  this.logger.debug(`body=${body}`);
19
18
  const pullRequest = await this.github.createPullRequest({
20
19
  owner: this.gitRepo.owner,
@@ -25,16 +24,13 @@ class PullRequestCreator {
25
24
  body
26
25
  });
27
26
  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
- }
37
- this.logger.info(`Pull request for ${outdatedPackage.name} has created. ${pullRequest.html_url}`);
27
+ await this.github.addLabels({
28
+ owner: this.gitRepo.owner,
29
+ repo: this.gitRepo.name,
30
+ issue_number: pullRequest.number,
31
+ labels: ['npm-update-package']
32
+ });
33
+ return pullRequest;
38
34
  }
39
35
  }
40
36
  exports.PullRequestCreator = PullRequestCreator;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PullRequestFinder = void 0;
4
+ const extractPullRequestMetadata_1 = require("./extractPullRequestMetadata");
5
+ const isPullRequestByNpmUpdatePackage_1 = require("./isPullRequestByNpmUpdatePackage");
6
+ // TODO: Add test
7
+ class PullRequestFinder {
8
+ constructor(pullRequests) {
9
+ this.pullRequests = pullRequests;
10
+ }
11
+ findByPackageName(packageName) {
12
+ return this.pullRequests
13
+ .filter(isPullRequestByNpmUpdatePackage_1.isPullRequestByNpmUpdatePackage)
14
+ .filter(({ body }) => {
15
+ if (body === null) {
16
+ return false;
17
+ }
18
+ const metadata = (0, extractPullRequestMetadata_1.extractPullRequestMetadata)(body);
19
+ if (metadata === undefined) {
20
+ return false;
21
+ }
22
+ return metadata.packages.some(({ name }) => name === packageName);
23
+ });
24
+ }
25
+ }
26
+ exports.PullRequestFinder = PullRequestFinder;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPullRequestMetadata = void 0;
4
+ const io_ts_1 = require("io-ts");
5
+ const ncu_1 = require("../ncu");
6
+ const PullRequestMetadata = (0, io_ts_1.type)({
7
+ version: io_ts_1.string,
8
+ packages: (0, io_ts_1.array)((0, io_ts_1.type)({
9
+ name: io_ts_1.string,
10
+ currentVersion: io_ts_1.string,
11
+ newVersion: io_ts_1.string,
12
+ type: (0, io_ts_1.union)([(0, io_ts_1.literal)(ncu_1.UpdateType.Major), (0, io_ts_1.literal)(ncu_1.UpdateType.Minor), (0, io_ts_1.literal)(ncu_1.UpdateType.Patch)])
13
+ }))
14
+ });
15
+ exports.isPullRequestMetadata = PullRequestMetadata.is;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPullRequestBody = void 0;
4
+ const mustache_1 = require("mustache");
5
+ const app_1 = require("../app");
6
+ const TEMPLATE = `This PR updates these packages:
7
+
8
+ |package|type|current version|new version|
9
+ |---|---|---|---|
10
+ |[{{{packageName}}}](https://www.npmjs.com/package/{{{packageName}}})|{{updateType}}|\`{{currentVersion}}\`|\`{{newVersion}}\`|
11
+
12
+ <details>
13
+ <summary>Metadata</summary>
14
+
15
+ **Don't remove or edit this section because it will be used by npm-update-package.**
16
+
17
+ <div id="npm-update-package-metadata">
18
+
19
+ \`\`\`json
20
+ {
21
+ "version": "{{appVersion}}",
22
+ "packages": [
23
+ {
24
+ "name": "{{{packageName}}}",
25
+ "type": "{{updateType}}",
26
+ "currentVersion": "{{currentVersion}}",
27
+ "newVersion": "{{newVersion}}"
28
+ }
29
+ ]
30
+ }
31
+ \`\`\`
32
+
33
+ </div>
34
+ </details>
35
+
36
+ ---
37
+ This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}`;
38
+ const createPullRequestBody = (outdatedPackage) => {
39
+ const appName = app_1.app.name;
40
+ const appVersion = app_1.app.version;
41
+ const appWeb = app_1.app.web;
42
+ const currentVersion = outdatedPackage.currentVersion.version;
43
+ const newVersion = outdatedPackage.newVersion.version;
44
+ const packageName = outdatedPackage.name;
45
+ const updateType = outdatedPackage.type;
46
+ return (0, mustache_1.render)(TEMPLATE, {
47
+ appName,
48
+ appVersion,
49
+ appWeb,
50
+ currentVersion,
51
+ newVersion,
52
+ packageName,
53
+ updateType
54
+ });
55
+ };
56
+ exports.createPullRequestBody = createPullRequestBody;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractPullRequestMetadata = void 0;
4
+ const PullRequestMetadata_1 = require("./PullRequestMetadata");
5
+ const extractPullRequestMetadata = (pullRequestBody) => {
6
+ const matched = pullRequestBody.match(/<div id="npm-update-package-metadata">\s*```json\s*([\s\S]+?)\s*```\s*<\/div>/);
7
+ const json = matched === null || matched === void 0 ? void 0 : matched[1];
8
+ if (json === undefined) {
9
+ return undefined;
10
+ }
11
+ const metadata = JSON.parse(json);
12
+ if (!(0, PullRequestMetadata_1.isPullRequestMetadata)(metadata)) {
13
+ return undefined;
14
+ }
15
+ return metadata;
16
+ };
17
+ exports.extractPullRequestMetadata = extractPullRequestMetadata;
@@ -1,14 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RemoteBranchExistenceChecker = exports.PullRequestTitleCreator = exports.PullRequestCreator = exports.PullRequestBodyCreator = exports.GitHub = exports.createGitHub = void 0;
3
+ exports.RemoteBranchExistenceChecker = exports.PullRequestTitleCreator = exports.PullRequestFinder = exports.PullRequestCreator = exports.PullRequestCloser = exports.GitHub = exports.createGitHub = void 0;
4
4
  var createGitHub_1 = require("./createGitHub");
5
5
  Object.defineProperty(exports, "createGitHub", { enumerable: true, get: function () { return createGitHub_1.createGitHub; } });
6
6
  var GitHub_1 = require("./GitHub");
7
7
  Object.defineProperty(exports, "GitHub", { enumerable: true, get: function () { return GitHub_1.GitHub; } });
8
- var PullRequestBodyCreator_1 = require("./PullRequestBodyCreator");
9
- Object.defineProperty(exports, "PullRequestBodyCreator", { enumerable: true, get: function () { return PullRequestBodyCreator_1.PullRequestBodyCreator; } });
8
+ var PullRequestCloser_1 = require("./PullRequestCloser");
9
+ Object.defineProperty(exports, "PullRequestCloser", { enumerable: true, get: function () { return PullRequestCloser_1.PullRequestCloser; } });
10
10
  var PullRequestCreator_1 = require("./PullRequestCreator");
11
11
  Object.defineProperty(exports, "PullRequestCreator", { enumerable: true, get: function () { return PullRequestCreator_1.PullRequestCreator; } });
12
+ var PullRequestFinder_1 = require("./PullRequestFinder");
13
+ Object.defineProperty(exports, "PullRequestFinder", { enumerable: true, get: function () { return PullRequestFinder_1.PullRequestFinder; } });
12
14
  var PullRequestTitleCreator_1 = require("./PullRequestTitleCreator");
13
15
  Object.defineProperty(exports, "PullRequestTitleCreator", { enumerable: true, get: function () { return PullRequestTitleCreator_1.PullRequestTitleCreator; } });
14
16
  var RemoteBranchExistenceChecker_1 = require("./RemoteBranchExistenceChecker");
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPullRequestByNpmUpdatePackage = void 0;
4
+ const isPullRequestByNpmUpdatePackage = (pullRequest) => {
5
+ return pullRequest.labels.some(({ name }) => name === 'npm-update-package');
6
+ };
7
+ exports.isPullRequestByNpmUpdatePackage = isPullRequestByNpmUpdatePackage;
package/dist/main.js CHANGED
@@ -50,24 +50,27 @@ const main = async ({ options, logger }) => {
50
50
  repo: gitRepo.name
51
51
  });
52
52
  logger.debug(`remoteBranches=${JSON.stringify(remoteBranches)}`);
53
+ const pullRequests = await github.fetchPullRequests({
54
+ owner: gitRepo.owner,
55
+ repo: gitRepo.name
56
+ });
57
+ logger.debug(`pullRequests=${JSON.stringify(pullRequests)}`);
53
58
  const remoteBranchExistenceChecker = github_1.RemoteBranchExistenceChecker.of(remoteBranches);
54
59
  const packageManager = (0, package_manager_1.createPackageManager)({
55
60
  terminal,
56
61
  packageManager: options.packageManager
57
62
  });
58
63
  const pullRequestTitleCreator = new github_1.PullRequestTitleCreator(options.pullRequestTitle);
59
- const pullRequestBodyCreator = new github_1.PullRequestBodyCreator(options.pullRequestBody);
60
64
  const pullRequestCreator = new github_1.PullRequestCreator({
61
65
  github,
62
66
  gitRepo,
63
67
  githubRepo,
64
68
  pullRequestTitleCreator,
65
- pullRequestBodyCreator,
66
- logger,
67
- labels: options.pullRequestLabels
69
+ logger
68
70
  });
69
- const branchNameCreator = new git_1.BranchNameCreator(options.branchName);
70
71
  const commitMessageCreator = new git_1.CommitMessageCreator(options.commitMessage);
72
+ const pullRequestFinder = new github_1.PullRequestFinder(pullRequests);
73
+ const pullRequestCloser = new github_1.PullRequestCloser(github);
71
74
  const outdatedPackageProcessor = new processors_1.OutdatedPackageProcessor({
72
75
  git,
73
76
  ncu,
@@ -75,8 +78,9 @@ const main = async ({ options, logger }) => {
75
78
  pullRequestCreator,
76
79
  remoteBranchExistenceChecker,
77
80
  logger,
78
- branchNameCreator,
79
- commitMessageCreator
81
+ commitMessageCreator,
82
+ pullRequestFinder,
83
+ pullRequestCloser
80
84
  });
81
85
  const outdatedPackagesProcessor = new processors_1.OutdatedPackagesProcessor({
82
86
  outdatedPackageProcessor,
@@ -4,18 +4,11 @@ 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.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
- ]);
7
+ const Options = (0, io_ts_1.type)({
8
+ commitMessage: io_ts_1.string,
9
+ githubToken: io_ts_1.string,
10
+ 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)]),
11
+ 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)]),
12
+ pullRequestTitle: io_ts_1.string
13
+ });
21
14
  exports.isOptions = Options.is;
@@ -5,13 +5,6 @@ const logger_1 = require("../logger");
5
5
  const package_manager_1 = require("../package-manager");
6
6
  const OptionType_1 = require("./OptionType");
7
7
  exports.cliOptions = [
8
- {
9
- name: 'branch-name',
10
- description: 'Branch name template',
11
- type: OptionType_1.OptionType.String,
12
- required: false,
13
- default: 'npm-update-package/{{{packageName}}}/v{{newVersion}}'
14
- },
15
8
  {
16
9
  name: 'commit-message',
17
10
  description: 'Commit message template',
@@ -49,26 +42,6 @@ exports.cliOptions = [
49
42
  ],
50
43
  default: package_manager_1.PackageManagerName.Npm
51
44
  },
52
- {
53
- name: 'pull-request-body',
54
- description: 'Pull request body template',
55
- type: OptionType_1.OptionType.String,
56
- required: false,
57
- default: `This PR updates these packages:
58
-
59
- |package|type|current version|new version|
60
- |---|---|---|---|
61
- |[{{{packageName}}}](https://www.npmjs.com/package/{{{packageName}}})|{{updateType}}|\`{{currentVersion}}\`|\`{{newVersion}}\`|
62
-
63
- ---
64
- This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}`
65
- },
66
- {
67
- name: 'pull-request-labels',
68
- description: 'Pull request labels',
69
- type: OptionType_1.OptionType.StringArray,
70
- required: false
71
- },
72
45
  {
73
46
  name: 'pull-request-title',
74
47
  description: 'Pull request title template',
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.PackageJsonReader = void 0;
4
- const file_1 = require("../file");
7
+ const fs_1 = __importDefault(require("fs"));
5
8
  // TODO: add test
6
9
  class PackageJsonReader {
7
10
  constructor({ packageJsonParser, logger }) {
@@ -9,7 +12,7 @@ class PackageJsonReader {
9
12
  this.logger = logger;
10
13
  }
11
14
  async read() {
12
- const json = await (0, file_1.readFile)('./package.json');
15
+ const json = await fs_1.default.promises.readFile('./package.json', 'utf8');
13
16
  this.logger.debug(`json=${json}`);
14
17
  return this.packageJsonParser.parse(json);
15
18
  }
@@ -2,23 +2,25 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OutdatedPackageProcessor = void 0;
4
4
  const Either_1 = require("fp-ts/lib/Either");
5
+ const git_1 = require("../git");
5
6
  // TODO: add test
6
7
  class OutdatedPackageProcessor {
7
- constructor({ git, ncu, packageManager, pullRequestCreator, remoteBranchExistenceChecker, logger, branchNameCreator, commitMessageCreator }) {
8
+ constructor({ git, ncu, packageManager, pullRequestCreator, remoteBranchExistenceChecker, logger, commitMessageCreator, pullRequestFinder, pullRequestCloser }) {
8
9
  this.git = git;
9
10
  this.ncu = ncu;
10
11
  this.packageManager = packageManager;
11
12
  this.pullRequestCreator = pullRequestCreator;
12
13
  this.remoteBranchExistenceChecker = remoteBranchExistenceChecker;
13
14
  this.logger = logger;
14
- this.branchNameCreator = branchNameCreator;
15
15
  this.commitMessageCreator = commitMessageCreator;
16
+ this.pullRequestFinder = pullRequestFinder;
17
+ this.pullRequestCloser = pullRequestCloser;
16
18
  }
17
19
  /**
18
20
  * Don't run in parallel because it includes file operations.
19
21
  */
20
22
  async process(outdatedPackage) {
21
- const branchName = this.branchNameCreator.create(outdatedPackage);
23
+ const branchName = (0, git_1.createBranchName)(outdatedPackage);
22
24
  this.logger.debug(`branchName=${branchName}`);
23
25
  if (this.remoteBranchExistenceChecker.check(branchName)) {
24
26
  this.logger.info(`Skip ${outdatedPackage.name} because ${branchName} branch already exists on remote.`);
@@ -50,10 +52,17 @@ class OutdatedPackageProcessor {
50
52
  this.logger.debug(`message=${message}`);
51
53
  await this.git.commit(message);
52
54
  await this.git.push(branchName);
53
- await this.pullRequestCreator.create({
55
+ const pullRequest = await this.pullRequestCreator.create({
54
56
  outdatedPackage,
55
57
  branchName
56
58
  });
59
+ this.logger.info(`Pull request for ${outdatedPackage.name} has created. ${pullRequest.html_url}`);
60
+ const pullRequests = this.pullRequestFinder.findByPackageName(outdatedPackage.name);
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
+ }));
57
66
  return (0, Either_1.right)({
58
67
  outdatedPackage,
59
68
  updated: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-update-package",
3
- "version": "0.20.0",
3
+ "version": "0.22.1",
4
4
  "description": "CLI tool for creating pull request to update npm packages",
5
5
  "scripts": {
6
6
  "build": "tsc --project tsconfig.build.json",
@@ -20,11 +20,11 @@
20
20
  "@octokit/rest": "18.12.0",
21
21
  "commander": "8.3.0",
22
22
  "execa": "5.1.1",
23
- "fp-ts": "2.11.5",
23
+ "fp-ts": "2.11.6",
24
24
  "io-ts": "2.2.16",
25
25
  "log4js": "6.3.0",
26
26
  "mustache": "4.1.0",
27
- "npm-check-updates": "12.0.5",
27
+ "npm-check-updates": "12.1.0",
28
28
  "parse-github-url": "1.0.2",
29
29
  "semver": "7.3.5",
30
30
  "type-guards": "0.15.0"
@@ -37,17 +37,17 @@
37
37
  "@types/node": "12.20.40",
38
38
  "@types/parse-github-url": "1.0.0",
39
39
  "@types/semver": "7.3.9",
40
- "@typescript-eslint/eslint-plugin": "5.8.1",
41
- "eslint": "8.5.0",
40
+ "@typescript-eslint/eslint-plugin": "5.9.0",
41
+ "eslint": "8.6.0",
42
42
  "eslint-config-standard-with-typescript": "21.0.1",
43
- "eslint-plugin-import": "2.25.3",
44
- "eslint-plugin-jest": "25.3.3",
43
+ "eslint-plugin-import": "2.25.4",
44
+ "eslint-plugin-jest": "25.3.4",
45
45
  "eslint-plugin-node": "11.1.0",
46
46
  "eslint-plugin-promise": "6.0.0",
47
47
  "eslint-plugin-tsdoc": "0.2.14",
48
48
  "husky": "7.0.4",
49
- "jest": "27.4.5",
50
- "lint-staged": "12.1.4",
49
+ "jest": "27.4.7",
50
+ "lint-staged": "12.1.7",
51
51
  "npm-run-all": "4.1.5",
52
52
  "rimraf": "3.0.2",
53
53
  "ts-jest": "27.1.2",
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readFile = void 0;
4
- var readFile_1 = require("./readFile");
5
- Object.defineProperty(exports, "readFile", { enumerable: true, get: function () { return readFile_1.readFile; } });
@@ -1,13 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.readFile = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- // TODO: add test
9
- const readFile = async (path) => {
10
- const data = await fs_1.default.promises.readFile(path, 'utf8');
11
- return data;
12
- };
13
- exports.readFile = readFile;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BranchNameCreator = void 0;
4
- const mustache_1 = require("mustache");
5
- class BranchNameCreator {
6
- constructor(template) {
7
- this.template = template;
8
- }
9
- create(outdatedPackage) {
10
- const packageName = outdatedPackage.name;
11
- const currentVersion = outdatedPackage.currentVersion.version;
12
- const newVersion = outdatedPackage.newVersion.version;
13
- const updateType = outdatedPackage.type;
14
- return (0, mustache_1.render)(this.template, {
15
- packageName,
16
- currentVersion,
17
- newVersion,
18
- updateType
19
- });
20
- }
21
- }
22
- exports.BranchNameCreator = BranchNameCreator;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PullRequestBodyCreator = void 0;
4
- const mustache_1 = require("mustache");
5
- const app_1 = require("../app");
6
- class PullRequestBodyCreator {
7
- constructor(template) {
8
- this.template = template;
9
- }
10
- create(outdatedPackage) {
11
- const appName = app_1.app.name;
12
- const appVersion = app_1.app.version;
13
- const appWeb = app_1.app.web;
14
- const currentVersion = outdatedPackage.currentVersion.version;
15
- const newVersion = outdatedPackage.newVersion.version;
16
- const packageName = outdatedPackage.name;
17
- const updateType = outdatedPackage.type;
18
- return (0, mustache_1.render)(this.template, {
19
- appName,
20
- appVersion,
21
- appWeb,
22
- currentVersion,
23
- newVersion,
24
- packageName,
25
- updateType
26
- });
27
- }
28
- }
29
- exports.PullRequestBodyCreator = PullRequestBodyCreator;