npm-update-package 0.45.4 → 0.45.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-update-package",
3
- "version": "0.45.4",
3
+ "version": "0.45.7",
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",
25
- "npm-check-updates": "12.5.2",
26
+ "node-fetch": "2.6.7",
27
+ "npm-check-updates": "12.5.3",
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
43
  "@typescript-eslint/eslint-plugin": "5.14.0",
39
- "eslint": "8.10.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,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GitHub = void 0;
4
+ const lodash_1 = require("lodash");
4
5
  class GitHub {
5
6
  constructor(octokit) {
6
7
  this.octokit = octokit;
@@ -50,7 +51,7 @@ class GitHub {
50
51
  }
51
52
  async fetchBranches({ owner, repo }) {
52
53
  const branches = [];
53
- for (let page = 1;; page++) {
54
+ for (const page of (0, lodash_1.range)(1, 11)) {
54
55
  const { data } = await this.octokit.repos.listBranches({
55
56
  owner,
56
57
  repo,
@@ -74,7 +75,7 @@ class GitHub {
74
75
  }
75
76
  async fetchPullRequests({ owner, repo }) {
76
77
  const pullRequests = [];
77
- for (let page = 1;; page++) {
78
+ for (const page of (0, lodash_1.range)(1, 11)) {
78
79
  const { data } = await this.octokit.pulls.list({
79
80
  owner,
80
81
  repo,
@@ -88,22 +89,6 @@ class GitHub {
88
89
  }
89
90
  return pullRequests;
90
91
  }
91
- async fetchReleases({ owner, repo }) {
92
- const releases = [];
93
- for (let page = 1;; page++) {
94
- const { data } = await this.octokit.repos.listReleases({
95
- owner,
96
- repo,
97
- per_page: 100,
98
- page
99
- });
100
- if (data.length === 0) {
101
- break;
102
- }
103
- releases.push(...data);
104
- }
105
- return releases;
106
- }
107
92
  async fetchRepository({ owner, repo }) {
108
93
  const { data } = await this.octokit.repos.get({
109
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;
@@ -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) {
@@ -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.4",
3
+ "version": "0.45.7",
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",
25
- "npm-check-updates": "12.5.2",
26
+ "node-fetch": "2.6.7",
27
+ "npm-check-updates": "12.5.3",
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
43
  "@typescript-eslint/eslint-plugin": "5.14.0",
39
- "eslint": "8.10.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",