npm-update-package 0.45.5 → 0.45.8

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
@@ -18,86 +18,174 @@ Some options can embed variables like `{{packageName}}`(HTML-escaped) or `{{{pac
18
18
 
19
19
  ### `--commit-message`
20
20
 
21
- Commit message template
22
-
23
- - type: string
24
- - required: false
25
- - variables
26
- - `currentVersion`: current package version
27
- - `newVersion`: new package version
28
- - `packageName`: package name
29
- - `level`: semver level (major/minor/patch)
30
- - `dependencyType`: dependency type (dependencies/devDependencies/peerDependencies/optionalDependencies)
31
- - default: `chore(deps): {{{level}}} update {{{packageName}}} to v{{{newVersion}}}`
21
+ Commit message template.
22
+
23
+ |Name|Value|
24
+ |---|---|
25
+ |type|string|
26
+ |required|false|
27
+ |default|`chore(deps): {{{level}}} update {{{packageName}}} to v{{{newVersion}}}`|
28
+
29
+ #### Available variables
30
+
31
+ |Variable|Description|
32
+ |---|---|
33
+ |`currentVersion`|Current package version|
34
+ |`newVersion`|New package version|
35
+ |`packageName`|Package name|
36
+ |`level`|Semver level (`major`/`minor`/`patch`)|
37
+ |`dependencyType`|Dependency type (`dependencies`/`devDependencies`/`peerDependencies`/`optionalDependencies`)|
38
+
39
+ #### Example
40
+
41
+ ```sh
42
+ npx npm-update-package \
43
+ --github-token $GITHUB_TOKEN \
44
+ --commit-message "chore(deps): {{{level}}} update {{{packageName}}} to v{{{newVersion}}}"
45
+ ```
32
46
 
33
47
  ### `--github-token`
34
48
 
35
- [GitHub token](#github-token)
49
+ [GitHub token](#github-token).
36
50
 
37
- - type: string
38
- - required: true
51
+ |Name|Value|
52
+ |---|---|
53
+ |type|string|
54
+ |required|true|
39
55
 
40
56
  ### `--ignore-packages`
41
57
 
42
- Package names to ignore
58
+ Package names to ignore.
59
+
60
+ |Name|Value|
61
+ |---|---|
62
+ |type|string[]|
63
+ |required|false|
43
64
 
44
- - type: string[]
45
- - required: false
65
+ #### Example
66
+
67
+ ```sh
68
+ npx npm-update-package \
69
+ --github-token $GITHUB_TOKEN \
70
+ --ignore-packages @types/jest jest
71
+ ```
46
72
 
47
73
  ### `--log-level`
48
74
 
49
- Log level to show
75
+ Log level to show.
76
+
77
+ |Name|Value|
78
+ |---|---|
79
+ |type|string|
80
+ |required|false|
81
+ |default|`info`|
82
+
83
+ #### Allowed values
50
84
 
51
- - type: string
52
- - required: false
53
- - allowed values
54
- - `off`: Do not output any logs.
55
- - `fatal`: Output fatal logs.
56
- - `error`: Output fatal/error logs.
57
- - `warn`: Output fatal/error/warn logs.
58
- - `info`: Output fatal/error/warn/info logs.
59
- - `debug`: Output fatal/error/warn/info/debug logs.
60
- - `trace`: Output fatal/error/warn/info/debug/trace logs.
61
- - default: `info`
85
+ |Value|Description|
86
+ |---|---|
87
+ |`off`|Do not output any logs.|
88
+ |`fatal`|Output fatal logs.|
89
+ |`error`|Output fatal/error logs.|
90
+ |`warn`|Output fatal/error/warn logs.|
91
+ |`info`|Output fatal/error/warn/info logs.|
92
+ |`debug`|Output fatal/error/warn/info/debug logs.|
93
+ |`trace`|Output fatal/error/warn/info/debug/trace logs.|
94
+
95
+ #### Example
96
+
97
+ ```sh
98
+ npx npm-update-package \
99
+ --github-token $GITHUB_TOKEN \
100
+ --log-level info
101
+ ```
62
102
 
63
103
  ### `--package-manager`
64
104
 
65
- Package manager of your project
105
+ Package manager of your project.
106
+
107
+ |Name|Value|
108
+ |---|---|
109
+ |type|string|
110
+ |required|false|
111
+ |default|`npm`|
112
+
113
+ #### Allowed values
66
114
 
67
- - type: string
68
- - required: false
69
- - allowed values
70
- - `npm`: npm
71
- - `yarn`: Yarn
72
- - default: `npm`
115
+ |Value|Description|
116
+ |---|---|
117
+ |`npm`|npm|
118
+ |`yarn`|Yarn|
119
+
120
+ #### Example
121
+
122
+ ```sh
123
+ npx npm-update-package \
124
+ --github-token $GITHUB_TOKEN \
125
+ --package-manager npm
126
+ ```
73
127
 
74
128
  ### `--pr-body-notes`
75
129
 
76
- Additional notes for Pull request body
130
+ Additional notes for Pull request body.
131
+
132
+ |Name|Value|
133
+ |---|---|
134
+ |type|string|
135
+ |required|false|
77
136
 
78
- - type: string
79
- - required: false
137
+ #### Example
138
+
139
+ ```sh
140
+ npx npm-update-package \
141
+ --github-token $GITHUB_TOKEN \
142
+ --pr-body-notes "**:warning: Please see diff and release notes before merging.**"
143
+ ```
80
144
 
81
145
  ### `--pr-title`
82
146
 
83
- Pull request title template
147
+ Pull request title template.
148
+
149
+ |Name|Value|
150
+ |---|---|
151
+ |type|string|
152
+ |required|false|
153
+ |default|`chore(deps): {{{level}}} update {{{packageName}}} to v{{{newVersion}}}`|
84
154
 
85
- - type: string
86
- - required: false
87
- - variables
88
- - `currentVersion`: current package version
89
- - `newVersion`: new package version
90
- - `packageName`: package name
91
- - `level`: semver level (major/minor/patch)
92
- - `dependencyType`: dependency type (dependencies/devDependencies/peerDependencies/optionalDependencies)
93
- - default: `chore(deps): {{{level}}} update {{{packageName}}} to v{{{newVersion}}}`
155
+ #### Available variables
156
+
157
+ |Variable|Description|
158
+ |---|---|
159
+ |`currentVersion`|Current package version|
160
+ |`newVersion`|New package version|
161
+ |`packageName`|Package name|
162
+ |`level`|Semver level (`major`/`minor`/`patch`)|
163
+ |`dependencyType`|Dependency type (`dependencies`/`devDependencies`/`peerDependencies`/`optionalDependencies`)|
164
+
165
+ #### Example
166
+
167
+ ```sh
168
+ npx npm-update-package \
169
+ --github-token $GITHUB_TOKEN \
170
+ --pr-title "chore(deps): {{{level}}} update {{{packageName}}} to v{{{newVersion}}}"
171
+ ```
94
172
 
95
173
  ### `--reviewers`
96
174
 
97
- User names to request reviews
175
+ User names to request reviews.
98
176
 
99
- - type: string[]
100
- - required: false
177
+ |Name|Value|
178
+ |---|---|
179
+ |type|string[]|
180
+ |required|false|
181
+
182
+ #### Example
183
+
184
+ ```sh
185
+ npx npm-update-package \
186
+ --github-token $GITHUB_TOKEN \
187
+ --reviewers npm-update-package npm-update-package-bot
188
+ ```
101
189
 
102
190
  ## GitHub token
103
191
 
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-update-package",
3
- "version": "0.45.5",
3
+ "version": "0.45.8",
4
4
  "description": "CLI tool for creating pull requests to update npm packages",
5
5
  "scripts": {
6
6
  "build": "tsc --project tsconfig.build.json",
@@ -23,9 +23,11 @@
23
23
  "lodash": "4.14.2",
24
24
  "log4js": "6.4.2",
25
25
  "mustache": "4.1.0",
26
- "npm-check-updates": "12.5.2",
26
+ "node-fetch": "2.6.7",
27
+ "npm-check-updates": "12.5.3",
27
28
  "parse-github-url": "1.0.2",
28
29
  "semver": "7.3.5",
30
+ "sleep-promise": "9.1.0",
29
31
  "type-guards": "0.15.0"
30
32
  },
31
33
  "devDependencies": {
@@ -35,10 +37,11 @@
35
37
  "@types/lodash": "4.14.179",
36
38
  "@types/mustache": "4.1.2",
37
39
  "@types/node": "12.20.40",
40
+ "@types/node-fetch": "2.6.1",
38
41
  "@types/parse-github-url": "1.0.0",
39
42
  "@types/semver": "7.3.9",
40
43
  "@typescript-eslint/eslint-plugin": "5.14.0",
41
- "eslint": "8.10.0",
44
+ "eslint": "8.11.0",
42
45
  "eslint-config-standard-with-typescript": "21.0.1",
43
46
  "eslint-plugin-import": "2.25.4",
44
47
  "eslint-plugin-jest": "26.1.1",
@@ -89,22 +89,6 @@ class GitHub {
89
89
  }
90
90
  return pullRequests;
91
91
  }
92
- async fetchReleases({ owner, repo }) {
93
- const releases = [];
94
- for (const page of (0, lodash_1.range)(1, 11)) {
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')}`;
@@ -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
@@ -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.5",
3
+ "version": "0.45.8",
4
4
  "description": "CLI tool for creating pull requests to update npm packages",
5
5
  "scripts": {
6
6
  "build": "tsc --project tsconfig.build.json",
@@ -23,9 +23,11 @@
23
23
  "lodash": "4.14.2",
24
24
  "log4js": "6.4.2",
25
25
  "mustache": "4.1.0",
26
- "npm-check-updates": "12.5.2",
26
+ "node-fetch": "2.6.7",
27
+ "npm-check-updates": "12.5.3",
27
28
  "parse-github-url": "1.0.2",
28
29
  "semver": "7.3.5",
30
+ "sleep-promise": "9.1.0",
29
31
  "type-guards": "0.15.0"
30
32
  },
31
33
  "devDependencies": {
@@ -35,10 +37,11 @@
35
37
  "@types/lodash": "4.14.179",
36
38
  "@types/mustache": "4.1.2",
37
39
  "@types/node": "12.20.40",
40
+ "@types/node-fetch": "2.6.1",
38
41
  "@types/parse-github-url": "1.0.0",
39
42
  "@types/semver": "7.3.9",
40
43
  "@typescript-eslint/eslint-plugin": "5.14.0",
41
- "eslint": "8.10.0",
44
+ "eslint": "8.11.0",
42
45
  "eslint-config-standard-with-typescript": "21.0.1",
43
46
  "eslint-plugin-import": "2.25.4",
44
47
  "eslint-plugin-jest": "26.1.1",