npm-update-package 0.42.0 → 0.43.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 CHANGED
@@ -37,6 +37,13 @@ Commit message template
37
37
  - type: string
38
38
  - required: true
39
39
 
40
+ ### `--ignore-packages`
41
+
42
+ Package names to ignore
43
+
44
+ - type: string[]
45
+ - required: false
46
+
40
47
  ### `--log-level`
41
48
 
42
49
  Log level to show
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-update-package",
3
- "version": "0.42.0",
3
+ "version": "0.43.0",
4
4
  "description": "CLI tool for creating pull requests to update npm packages",
5
5
  "scripts": {
6
6
  "build": "tsc --project tsconfig.build.json",
@@ -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
- const updatedPackages = await this.ncu.update(outdatedPackage);
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
- 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
- }));
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;
@@ -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
  }
@@ -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: pullRequest.base.repo.owner.login,
11
- repo: pullRequest.base.repo.name,
12
+ owner,
13
+ repo,
12
14
  pullNumber: pullRequest.number
13
15
  });
14
16
  await this.github.deleteBranch({
15
- owner: pullRequest.base.repo.owner.login,
16
- repo: pullRequest.base.repo.name,
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,
@@ -24,6 +24,7 @@ const Options = (0, io_ts_1.intersection)([
24
24
  pullRequestTitle: io_ts_1.string
25
25
  }),
26
26
  (0, io_ts_1.partial)({
27
+ ignorePackages: (0, io_ts_1.array)(io_ts_1.string),
27
28
  reviewers: (0, io_ts_1.array)(io_ts_1.string)
28
29
  })
29
30
  ]);
@@ -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.42.0",
3
+ "version": "0.43.0",
4
4
  "description": "CLI tool for creating pull requests to update npm packages",
5
5
  "scripts": {
6
6
  "build": "tsc --project tsconfig.build.json",