npm-update-package 0.45.3 → 0.45.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/README.md CHANGED
@@ -294,6 +294,6 @@ end
294
294
 
295
295
  npm-update-package can be used in environments where Renovate cannot be used for some reason.
296
296
 
297
- ### Conflicts have occurred in the pull request. What should I do?
297
+ ### What should I do if conflicts occurred in the pull request?
298
298
 
299
- If conflicts have occurred in the pull request, close it and run npm-update-package again.
299
+ If you have difficulty resolving it manually, close the pull request and run npm-update-package again.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-update-package",
3
- "version": "0.45.3",
3
+ "version": "0.45.6",
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,23 +20,28 @@
20
20
  "fp-ts": "2.11.8",
21
21
  "http-status-codes": "2.2.0",
22
22
  "io-ts": "2.2.16",
23
+ "lodash": "4.14.2",
23
24
  "log4js": "6.4.2",
24
25
  "mustache": "4.1.0",
26
+ "node-fetch": "2.6.7",
25
27
  "npm-check-updates": "12.5.2",
26
28
  "parse-github-url": "1.0.2",
27
29
  "semver": "7.3.5",
30
+ "sleep-promise": "9.1.0",
28
31
  "type-guards": "0.15.0"
29
32
  },
30
33
  "devDependencies": {
31
34
  "@jest/types": "27.4.2",
32
35
  "@tsconfig/node12": "1.0.9",
33
36
  "@types/jest": "27.4.0",
37
+ "@types/lodash": "4.14.179",
34
38
  "@types/mustache": "4.1.2",
35
39
  "@types/node": "12.20.40",
40
+ "@types/node-fetch": "2.6.1",
36
41
  "@types/parse-github-url": "1.0.0",
37
42
  "@types/semver": "7.3.9",
38
- "@typescript-eslint/eslint-plugin": "5.13.0",
39
- "eslint": "8.10.0",
43
+ "@typescript-eslint/eslint-plugin": "5.14.0",
44
+ "eslint": "8.11.0",
40
45
  "eslint-config-standard-with-typescript": "21.0.1",
41
46
  "eslint-plugin-import": "2.25.4",
42
47
  "eslint-plugin-jest": "26.1.1",
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GitHub = void 0;
4
- // TODO: add test
4
+ const lodash_1 = require("lodash");
5
5
  class GitHub {
6
6
  constructor(octokit) {
7
7
  this.octokit = octokit;
@@ -51,7 +51,7 @@ class GitHub {
51
51
  }
52
52
  async fetchBranches({ owner, repo }) {
53
53
  const branches = [];
54
- for (let page = 1;; page++) {
54
+ for (const page of (0, lodash_1.range)(1, 11)) {
55
55
  const { data } = await this.octokit.repos.listBranches({
56
56
  owner,
57
57
  repo,
@@ -75,7 +75,7 @@ class GitHub {
75
75
  }
76
76
  async fetchPullRequests({ owner, repo }) {
77
77
  const pullRequests = [];
78
- for (let page = 1;; page++) {
78
+ for (const page of (0, lodash_1.range)(1, 11)) {
79
79
  const { data } = await this.octokit.pulls.list({
80
80
  owner,
81
81
  repo,
@@ -89,22 +89,6 @@ class GitHub {
89
89
  }
90
90
  return pullRequests;
91
91
  }
92
- async fetchReleases({ owner, repo }) {
93
- const releases = [];
94
- for (let page = 1;; page++) {
95
- const { data } = await this.octokit.repos.listReleases({
96
- owner,
97
- repo,
98
- per_page: 100,
99
- page
100
- });
101
- if (data.length === 0) {
102
- break;
103
- }
104
- releases.push(...data);
105
- }
106
- return releases;
107
- }
108
92
  async fetchRepository({ owner, repo }) {
109
93
  const { data } = await this.octokit.repos.get({
110
94
  owner,
@@ -67,13 +67,14 @@ ${this.options.prBodyNotes}`;
67
67
  async createReleaseNotesSection({ outdatedPackage, gitRepo }) {
68
68
  const releases = await this.releasesFetcher.fetch({
69
69
  gitRepo,
70
+ packageName: outdatedPackage.name,
70
71
  from: outdatedPackage.currentVersion,
71
72
  to: outdatedPackage.newVersion
72
73
  });
73
74
  if (releases.length === 0) {
74
75
  return undefined;
75
76
  }
76
- const items = releases.map(release => `- [${release.tag_name}](${release.html_url})`);
77
+ const items = releases.map(({ tag, url }) => `- [${tag}](${url})`);
77
78
  return `## Release notes
78
79
 
79
80
  ${items.join('\n')}`;
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PullRequestFinder = void 0;
4
4
  const metadata_1 = require("../metadata");
5
5
  const isPullRequestByNpmUpdatePackage_1 = require("./isPullRequestByNpmUpdatePackage");
6
- // TODO: Add test
7
6
  class PullRequestFinder {
8
7
  constructor(pullRequests) {
9
8
  this.pullRequests = pullRequests;
@@ -4,7 +4,11 @@ exports.extractPullRequestMetadata = void 0;
4
4
  const PullRequestMetadata_1 = require("./PullRequestMetadata");
5
5
  const extractPullRequestMetadata = (pullRequestBody) => {
6
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];
7
+ if (matched === null) {
8
+ return undefined;
9
+ }
10
+ const json = matched[1];
11
+ /* istanbul ignore if: I can't write a test to reach here. */
8
12
  if (json === undefined) {
9
13
  return undefined;
10
14
  }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,20 +1,58 @@
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.ReleasesFetcher = void 0;
7
+ const node_fetch_1 = __importDefault(require("node-fetch"));
4
8
  const semver_1 = require("semver");
9
+ const sleep_promise_1 = __importDefault(require("sleep-promise"));
10
+ const type_guards_1 = require("type-guards");
5
11
  class ReleasesFetcher {
6
- constructor(github) {
7
- this.github = github;
12
+ constructor({ packageManager }) {
13
+ this.packageManager = packageManager;
8
14
  }
9
- async fetch({ gitRepo, from, to }) {
10
- const releases = await this.github.fetchReleases({
11
- owner: gitRepo.owner,
12
- repo: gitRepo.name
15
+ async fetch({ gitRepo, packageName, from, to }) {
16
+ const versions = await this.getVersions({
17
+ packageName,
18
+ from,
19
+ to
13
20
  });
14
- return releases.filter(({ tag_name: version }) => {
15
- // TODO: Move these to SemVer
16
- return (0, semver_1.valid)(version) !== null && (0, semver_1.gte)(version, from.version) && (0, semver_1.lte)(version, to.version);
21
+ const tags = versions.map(version => `v${version}`);
22
+ return await this.fetchReleasesByTags({
23
+ gitRepo,
24
+ tags
17
25
  });
18
26
  }
27
+ async fetchReleaseByTag({ gitRepo, tag }) {
28
+ const url = `${gitRepo.url.toString()}/releases/tag/${tag}`;
29
+ const resp = await (0, node_fetch_1.default)(url);
30
+ if (resp.ok) {
31
+ return {
32
+ tag,
33
+ url
34
+ };
35
+ }
36
+ }
37
+ async fetchReleasesByTags({ gitRepo, tags }) {
38
+ const releases = await Promise.all(tags.map(async (tag, i) => {
39
+ if (i > 0) {
40
+ // NOTE: Sleeps for 1 second between fetches.
41
+ await (0, sleep_promise_1.default)(1000);
42
+ }
43
+ return await this.fetchReleaseByTag({
44
+ gitRepo,
45
+ tag
46
+ });
47
+ }));
48
+ return releases.filter(type_guards_1.isNotUndefined);
49
+ }
50
+ async getVersions({ packageName, from, to }) {
51
+ const versions = await this.packageManager.getVersions(packageName);
52
+ // TODO: Move these to SemVer
53
+ return versions.filter(version => (0, semver_1.valid)(version))
54
+ .filter(version => (0, semver_1.gte)(version, from.version))
55
+ .filter(version => (0, semver_1.lte)(version, to.version));
56
+ }
19
57
  }
20
58
  exports.ReleasesFetcher = ReleasesFetcher;
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./fetcher"), exports);
18
+ __exportStar(require("./Release"), exports);
package/dist/src/main.js CHANGED
@@ -65,10 +65,7 @@ const main = async ({ options, logger }) => {
65
65
  packageManager: options.packageManager
66
66
  });
67
67
  const pullRequestTitleCreator = new github_1.PullRequestTitleCreator(options.prTitle);
68
- const githubWithoutToken = (0, github_1.createGitHub)({
69
- host: 'github.com'
70
- });
71
- const releasesFetcher = new github_1.ReleasesFetcher(githubWithoutToken);
68
+ const releasesFetcher = new github_1.ReleasesFetcher({ packageManager });
72
69
  const pullRequestBodyCreator = new github_1.PullRequestBodyCreator({
73
70
  options,
74
71
  releasesFetcher
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toCommanderOption = void 0;
4
4
  const commander_1 = require("commander");
5
5
  const OptionType_1 = require("./OptionType");
6
- // TODO: add test
7
6
  const toCommanderOption = (cliOption) => {
8
7
  const argument = createArgumentString(cliOption);
9
8
  const option = new commander_1.Option(`--${cliOption.name} ${argument}`, cliOption.description);
@@ -17,10 +16,8 @@ const toCommanderOption = (cliOption) => {
17
16
  };
18
17
  exports.toCommanderOption = toCommanderOption;
19
18
  const createArgumentString = (cliOption) => {
20
- const prefix = cliOption.required ? '<' : '[';
21
- const suffix = cliOption.required ? '>' : ']';
22
19
  const name = createArgumentNameString(cliOption.type);
23
- return `${prefix}${name}${suffix}`;
20
+ return cliOption.required ? `<${name}>` : `[${name}]`;
24
21
  };
25
22
  const createArgumentNameString = (optionType) => {
26
23
  switch (optionType) {
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parsePackageJson = void 0;
4
4
  const PackageMetadata_1 = require("./PackageMetadata");
5
- // TODO: add test
6
5
  const parsePackageJson = (json) => {
7
6
  const parsed = JSON.parse(json);
8
7
  if ((0, PackageMetadata_1.isPackageMetadata)(parsed)) {
@@ -1,12 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Npm = void 0;
4
+ const Versions_1 = require("./Versions");
4
5
  class Npm {
5
6
  constructor(terminal) {
6
7
  this.terminal = terminal;
7
8
  this.packageFile = 'package.json';
8
9
  this.lockFile = 'package-lock.json';
9
10
  }
11
+ async getVersions(packageName) {
12
+ const { stdout } = await this.terminal.run('npm', 'info', packageName, 'versions', '--json');
13
+ const versions = JSON.parse(stdout);
14
+ if (!(0, Versions_1.isVersions)(versions)) {
15
+ throw new Error(`Failed to parse versions. versions=${JSON.stringify(versions)}`);
16
+ }
17
+ return versions;
18
+ }
10
19
  /**
11
20
  * @see https://docs.npmjs.com/cli/v8/commands/npm-install
12
21
  */
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isVersions = exports.Versions = void 0;
4
+ const io_ts_1 = require("io-ts");
5
+ exports.Versions = (0, io_ts_1.array)(io_ts_1.string);
6
+ exports.isVersions = exports.Versions.is;
@@ -1,12 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Yarn = void 0;
4
+ const Versions_1 = require("./Versions");
4
5
  class Yarn {
5
6
  constructor(terminal) {
6
7
  this.terminal = terminal;
7
8
  this.packageFile = 'package.json';
8
9
  this.lockFile = 'yarn.lock';
9
10
  }
11
+ async getVersions(packageName) {
12
+ const { stdout } = await this.terminal.run('yarn', 'info', packageName, 'versions', '--json');
13
+ const versions = JSON.parse(stdout);
14
+ if (!(0, Versions_1.isVersions)(versions)) {
15
+ throw new Error(`Failed to parse versions. versions=${JSON.stringify(versions)}`);
16
+ }
17
+ return versions;
18
+ }
10
19
  /**
11
20
  * @see https://classic.yarnpkg.com/en/docs/cli/install
12
21
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-update-package",
3
- "version": "0.45.3",
3
+ "version": "0.45.6",
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,23 +20,28 @@
20
20
  "fp-ts": "2.11.8",
21
21
  "http-status-codes": "2.2.0",
22
22
  "io-ts": "2.2.16",
23
+ "lodash": "4.14.2",
23
24
  "log4js": "6.4.2",
24
25
  "mustache": "4.1.0",
26
+ "node-fetch": "2.6.7",
25
27
  "npm-check-updates": "12.5.2",
26
28
  "parse-github-url": "1.0.2",
27
29
  "semver": "7.3.5",
30
+ "sleep-promise": "9.1.0",
28
31
  "type-guards": "0.15.0"
29
32
  },
30
33
  "devDependencies": {
31
34
  "@jest/types": "27.4.2",
32
35
  "@tsconfig/node12": "1.0.9",
33
36
  "@types/jest": "27.4.0",
37
+ "@types/lodash": "4.14.179",
34
38
  "@types/mustache": "4.1.2",
35
39
  "@types/node": "12.20.40",
40
+ "@types/node-fetch": "2.6.1",
36
41
  "@types/parse-github-url": "1.0.0",
37
42
  "@types/semver": "7.3.9",
38
- "@typescript-eslint/eslint-plugin": "5.13.0",
39
- "eslint": "8.10.0",
43
+ "@typescript-eslint/eslint-plugin": "5.14.0",
44
+ "eslint": "8.11.0",
40
45
  "eslint-config-standard-with-typescript": "21.0.1",
41
46
  "eslint-plugin-import": "2.25.4",
42
47
  "eslint-plugin-jest": "26.1.1",