npm-update-package 0.54.0 → 0.55.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
@@ -26,6 +26,7 @@ CLI tool for creating pull requests to update npm packages
26
26
  - [ignorePackages](#ignorepackages)
27
27
  - [logLevel](#loglevel)
28
28
  - [packageManager](#packagemanager)
29
+ - [prBodyGithubHost](#prbodygithubhost)
29
30
  - [prBodyNotes](#prbodynotes)
30
31
  - [prTitle](#prtitle)
31
32
  - [reviewers](#reviewers)
@@ -34,7 +35,6 @@ CLI tool for creating pull requests to update npm packages
34
35
  - [Use token of GitHub Actions](#use-token-of-github-actions)
35
36
  - [Use token of GitHub App](#use-token-of-github-app)
36
37
  - [Use Personal access token](#use-personal-access-token)
37
- - [Use Yarn](#use-yarn)
38
38
  - [Flow](#flow)
39
39
  - [FAQ](#faq)
40
40
  - [What is the purpose of npm-update-package?](#what-is-the-purpose-of-npm-update-package)
@@ -271,6 +271,25 @@ npx npm-update-package \
271
271
  --package-manager yarn
272
272
  ```
273
273
 
274
+ ### prBodyGithubHost
275
+
276
+ GitHub host of pull request body.
277
+
278
+ |Name|Value|
279
+ |---|---|
280
+ |cli|`--pr-body-github-host`|
281
+ |type|string|
282
+ |required|false|
283
+ |default|`togithub.com`|
284
+
285
+ Example:
286
+
287
+ ```sh
288
+ npx npm-update-package \
289
+ --github-token $GITHUB_TOKEN \
290
+ --pr-body-github-host "github.example"
291
+ ```
292
+
274
293
  ### prBodyNotes
275
294
 
276
295
  Additional notes for Pull request body.
@@ -455,41 +474,6 @@ jobs:
455
474
 
456
475
  See working example on [example-pat](https://github.com/npm-update-package/example-pat).
457
476
 
458
- ### Use Yarn
459
-
460
- ```yaml
461
- name: npm-update-package
462
- on:
463
- schedule:
464
- - cron: '0 0 * * *'
465
- jobs:
466
- npm-update-package:
467
- runs-on: ubuntu-latest
468
- steps:
469
- - uses: actions/checkout@v2
470
- - uses: actions/setup-node@v2
471
- - name: Generate token
472
- id: generate_token
473
- uses: tibdex/github-app-token@v1
474
- with:
475
- app_id: ${{ secrets.APP_ID }}
476
- private_key: ${{ secrets.PRIVATE_KEY }}
477
- - run: |
478
- npx npm-update-package \
479
- --github-token $GITHUB_TOKEN \
480
- --git-user-name $GIT_USER_NAME \
481
- --git-user-email $GIT_USER_EMAIL \
482
- --package-manager yarn
483
- env:
484
- # TODO: Replace with your GitHub App's email
485
- GIT_USER_EMAIL: 97396142+npm-update-package[bot]@users.noreply.github.com
486
- # TODO: Replace with your GitHub App's user name
487
- GIT_USER_NAME: npm-update-package[bot]
488
- GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
489
- ```
490
-
491
- See working example on [example-yarn](https://github.com/npm-update-package/example-yarn).
492
-
493
477
  ## Flow
494
478
 
495
479
  The following shows the process flow of npm-update-package.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-update-package",
3
- "version": "0.54.0",
3
+ "version": "0.55.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",
@@ -20,11 +20,10 @@
20
20
  "fp-ts": "2.11.9",
21
21
  "http-status-codes": "2.2.0",
22
22
  "io-ts": "2.2.16",
23
- "lodash": "4.14.2",
24
23
  "log4js": "6.4.4",
25
24
  "mustache": "4.1.0",
26
25
  "node-fetch": "2.6.7",
27
- "npm-check-updates": "12.5.5",
26
+ "npm-check-updates": "12.5.7",
28
27
  "parse-github-url": "1.0.2",
29
28
  "semver": "7.3.5",
30
29
  "sleep-promise": "9.1.0",
@@ -34,13 +33,12 @@
34
33
  "@jest/types": "27.4.2",
35
34
  "@tsconfig/node12": "1.0.9",
36
35
  "@types/jest": "27.4.1",
37
- "@types/lodash": "4.14.181",
38
36
  "@types/mustache": "4.1.2",
39
37
  "@types/node": "12.20.47",
40
38
  "@types/node-fetch": "2.6.1",
41
39
  "@types/parse-github-url": "1.0.0",
42
40
  "@types/semver": "7.3.9",
43
- "@typescript-eslint/eslint-plugin": "5.17.0",
41
+ "@typescript-eslint/eslint-plugin": "5.18.0",
44
42
  "eslint": "8.12.0",
45
43
  "eslint-config-standard-with-typescript": "21.0.1",
46
44
  "eslint-plugin-import": "2.25.4",
@@ -1,7 +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
+ const number_1 = require("../number");
5
5
  class GitHub {
6
6
  constructor(octokit) {
7
7
  this.octokit = octokit;
@@ -59,7 +59,7 @@ class GitHub {
59
59
  }
60
60
  async fetchBranches({ owner, repo }) {
61
61
  const branches = [];
62
- for (const page of (0, lodash_1.range)(1, 11)) {
62
+ for (const page of (0, number_1.range)(1, 11)) {
63
63
  const { data } = await this.octokit.repos.listBranches({
64
64
  owner,
65
65
  repo,
@@ -83,7 +83,7 @@ class GitHub {
83
83
  }
84
84
  async fetchPullRequests({ owner, repo }) {
85
85
  const pullRequests = [];
86
- for (const page of (0, lodash_1.range)(1, 11)) {
86
+ for (const page of (0, number_1.range)(1, 11)) {
87
87
  const { data } = await this.octokit.pulls.list({
88
88
  owner,
89
89
  repo,
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GitHubUrlOptimizer = void 0;
4
+ const url_1 = require("url");
5
+ class GitHubUrlOptimizer {
6
+ constructor(options) {
7
+ this.options = options;
8
+ }
9
+ /**
10
+ * Convert URL to prevent linking to other repositories.
11
+ */
12
+ optimize(url) {
13
+ const newUrl = url instanceof url_1.URL ? url : new url_1.URL(url);
14
+ if (newUrl.host === 'github.com') {
15
+ newUrl.host = this.options.prBodyGithubHost;
16
+ }
17
+ return newUrl;
18
+ }
19
+ }
20
+ exports.GitHubUrlOptimizer = GitHubUrlOptimizer;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PackageDiffsSectionCreator = void 0;
4
+ class PackageDiffsSectionCreator {
5
+ constructor(gitHubUrlOptimizer) {
6
+ this.gitHubUrlOptimizer = gitHubUrlOptimizer;
7
+ }
8
+ create({ outdatedPackage, gitRepo }) {
9
+ const packageName = outdatedPackage.name;
10
+ const currentVersion = outdatedPackage.currentVersion.version;
11
+ const newVersion = outdatedPackage.newVersion.version;
12
+ const links = [];
13
+ if ((gitRepo === null || gitRepo === void 0 ? void 0 : gitRepo.isGitHub) === true) {
14
+ const url = `${gitRepo.url.toString()}/compare/v${currentVersion}...v${newVersion}`;
15
+ const optimizedUrl = this.gitHubUrlOptimizer.optimize(url).toString();
16
+ links.push(`- [GitHub](${optimizedUrl})`);
17
+ }
18
+ links.push(`- [npmfs](https://npmfs.com/compare/${packageName}/${currentVersion}/${newVersion})`);
19
+ links.push(`- [Package Diff](https://diff.intrinsic.com/${packageName}/${currentVersion}/${newVersion})`);
20
+ links.push(`- [Renovate Bot Package Diff](https://renovatebot.com/diffs/npm/${packageName}/${currentVersion}/${newVersion})`);
21
+ return `## Package diffs
22
+
23
+ ${links.join('\n')}`;
24
+ }
25
+ }
26
+ exports.PackageDiffsSectionCreator = PackageDiffsSectionCreator;
@@ -7,20 +7,20 @@ const createFooter_1 = require("./createFooter");
7
7
  const createMetadataSection_1 = require("./createMetadataSection");
8
8
  const createNotesSection_1 = require("./createNotesSection");
9
9
  const createOutdatedPackagesTable_1 = require("./createOutdatedPackagesTable");
10
- const createPackageDiffsSection_1 = require("./createPackageDiffsSection");
11
- const createReleaseNotesSection_1 = require("./createReleaseNotesSection");
12
10
  // TODO: Split into multiple classes and functions
13
11
  class PullRequestBodyCreator {
14
- constructor({ options, releasesFetcher }) {
12
+ constructor({ options, releasesFetcher, packageDiffsSectionCreator, releaseNotesSectionCreator }) {
15
13
  this.options = options;
16
14
  this.releasesFetcher = releasesFetcher;
15
+ this.packageDiffsSectionCreator = packageDiffsSectionCreator;
16
+ this.releaseNotesSectionCreator = releaseNotesSectionCreator;
17
17
  }
18
18
  async create(outdatedPackage) {
19
19
  const sections = [];
20
20
  const outdatedPackagesTable = (0, createOutdatedPackagesTable_1.createOutdatedPackagesTable)(outdatedPackage);
21
21
  sections.push(`This PR updates these packages:\n\n${outdatedPackagesTable}`);
22
22
  const gitRepo = await this.extractRepository(outdatedPackage);
23
- const diffSection = (0, createPackageDiffsSection_1.createPackageDiffsSection)({
23
+ const diffSection = this.packageDiffsSectionCreator.create({
24
24
  outdatedPackage,
25
25
  gitRepo
26
26
  });
@@ -33,7 +33,7 @@ class PullRequestBodyCreator {
33
33
  to: outdatedPackage.newVersion
34
34
  });
35
35
  if (releases.length > 0) {
36
- const releaseNotesSection = (0, createReleaseNotesSection_1.createReleaseNotesSection)(releases);
36
+ const releaseNotesSection = this.releaseNotesSectionCreator.create(releases);
37
37
  sections.push(releaseNotesSection);
38
38
  }
39
39
  }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReleaseNotesSectionCreator = void 0;
4
+ class ReleaseNotesSectionCreator {
5
+ constructor(gitHubUrlOptimizer) {
6
+ this.gitHubUrlOptimizer = gitHubUrlOptimizer;
7
+ }
8
+ create(releases) {
9
+ const items = releases.map(({ tag, url }) => {
10
+ const optimizedUrl = this.gitHubUrlOptimizer.optimize(url).toString();
11
+ return `- [${tag}](${optimizedUrl})`;
12
+ });
13
+ return `## Release notes
14
+
15
+ ${items.join('\n')}`;
16
+ }
17
+ }
18
+ exports.ReleaseNotesSectionCreator = ReleaseNotesSectionCreator;
@@ -14,6 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./GitHubUrlOptimizer"), exports);
18
+ __exportStar(require("./PackageDiffsSectionCreator"), exports);
17
19
  __exportStar(require("./PullRequestBodyCreator"), exports);
18
20
  __exportStar(require("./PullRequestCreator"), exports);
19
21
  __exportStar(require("./PullRequestTitleCreator"), exports);
22
+ __exportStar(require("./ReleaseNotesSectionCreator"), exports);
package/dist/src/main.js CHANGED
@@ -73,9 +73,14 @@ const main = async ({ options, logger }) => {
73
73
  options,
74
74
  packageManager
75
75
  });
76
+ const githubUrlOptimizer = new github_1.GitHubUrlOptimizer(options);
77
+ const packageDiffsSectionCreator = new github_1.PackageDiffsSectionCreator(githubUrlOptimizer);
78
+ const releaseNotesSectionCreator = new github_1.ReleaseNotesSectionCreator(githubUrlOptimizer);
76
79
  const pullRequestBodyCreator = new github_1.PullRequestBodyCreator({
77
80
  options,
78
- releasesFetcher
81
+ releasesFetcher,
82
+ packageDiffsSectionCreator,
83
+ releaseNotesSectionCreator
79
84
  });
80
85
  const pullRequestCreator = new github_1.PullRequestCreator({
81
86
  github,
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./range"), exports);
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.range = void 0;
4
+ // TODO: Add test
5
+ function* range(start, end) {
6
+ for (let i = start; i <= end; i++) {
7
+ yield i;
8
+ }
9
+ }
10
+ exports.range = range;
@@ -19,6 +19,7 @@ const Options = (0, io_ts_1.intersection)([
19
19
  (0, io_ts_1.literal)(logger_1.LogLevel.Debug),
20
20
  (0, io_ts_1.literal)(logger_1.LogLevel.Trace)
21
21
  ]),
22
+ prBodyGithubHost: io_ts_1.string,
22
23
  prTitle: io_ts_1.string
23
24
  }),
24
25
  (0, io_ts_1.partial)({
@@ -82,6 +82,13 @@ exports.cliOptions = [
82
82
  package_manager_1.PackageManagerName.Yarn
83
83
  ]
84
84
  },
85
+ {
86
+ name: 'pr-body-github-host',
87
+ description: 'GitHub host of pull request body',
88
+ type: OptionType_1.OptionType.String,
89
+ required: false,
90
+ default: 'togithub.com'
91
+ },
85
92
  {
86
93
  name: 'pr-body-notes',
87
94
  description: 'Additional notes for Pull request body',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-update-package",
3
- "version": "0.54.0",
3
+ "version": "0.55.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",
@@ -20,11 +20,10 @@
20
20
  "fp-ts": "2.11.9",
21
21
  "http-status-codes": "2.2.0",
22
22
  "io-ts": "2.2.16",
23
- "lodash": "4.14.2",
24
23
  "log4js": "6.4.4",
25
24
  "mustache": "4.1.0",
26
25
  "node-fetch": "2.6.7",
27
- "npm-check-updates": "12.5.5",
26
+ "npm-check-updates": "12.5.7",
28
27
  "parse-github-url": "1.0.2",
29
28
  "semver": "7.3.5",
30
29
  "sleep-promise": "9.1.0",
@@ -34,13 +33,12 @@
34
33
  "@jest/types": "27.4.2",
35
34
  "@tsconfig/node12": "1.0.9",
36
35
  "@types/jest": "27.4.1",
37
- "@types/lodash": "4.14.181",
38
36
  "@types/mustache": "4.1.2",
39
37
  "@types/node": "12.20.47",
40
38
  "@types/node-fetch": "2.6.1",
41
39
  "@types/parse-github-url": "1.0.0",
42
40
  "@types/semver": "7.3.9",
43
- "@typescript-eslint/eslint-plugin": "5.17.0",
41
+ "@typescript-eslint/eslint-plugin": "5.18.0",
44
42
  "eslint": "8.12.0",
45
43
  "eslint-config-standard-with-typescript": "21.0.1",
46
44
  "eslint-plugin-import": "2.25.4",
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createPackageDiffsSection = void 0;
4
- const optimizeGitHubUrl_1 = require("./optimizeGitHubUrl");
5
- const createPackageDiffsSection = ({ outdatedPackage, gitRepo }) => {
6
- const packageName = outdatedPackage.name;
7
- const currentVersion = outdatedPackage.currentVersion.version;
8
- const newVersion = outdatedPackage.newVersion.version;
9
- const links = [];
10
- if ((gitRepo === null || gitRepo === void 0 ? void 0 : gitRepo.isGitHub) === true) {
11
- const url = `${gitRepo.url.toString()}/compare/v${currentVersion}...v${newVersion}`;
12
- const optimizedUrl = (0, optimizeGitHubUrl_1.optimizeGitHubUrl)(url).toString();
13
- links.push(`- [GitHub](${optimizedUrl})`);
14
- }
15
- links.push(`- [npmfs](https://npmfs.com/compare/${packageName}/${currentVersion}/${newVersion})`);
16
- links.push(`- [Package Diff](https://diff.intrinsic.com/${packageName}/${currentVersion}/${newVersion})`);
17
- links.push(`- [Renovate Bot Package Diff](https://renovatebot.com/diffs/npm/${packageName}/${currentVersion}/${newVersion})`);
18
- return `## Package diffs
19
-
20
- ${links.join('\n')}`;
21
- };
22
- exports.createPackageDiffsSection = createPackageDiffsSection;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createReleaseNotesSection = void 0;
4
- const optimizeGitHubUrl_1 = require("./optimizeGitHubUrl");
5
- const createReleaseNotesSection = (releases) => {
6
- const items = releases.map(({ tag, url }) => {
7
- const optimizedUrl = (0, optimizeGitHubUrl_1.optimizeGitHubUrl)(url).toString();
8
- return `- [${tag}](${optimizedUrl})`;
9
- });
10
- return `## Release notes
11
-
12
- ${items.join('\n')}`;
13
- };
14
- exports.createReleaseNotesSection = createReleaseNotesSection;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.optimizeGitHubUrl = void 0;
4
- const url_1 = require("url");
5
- /**
6
- * Convert URL to prevent linking to other repositories.
7
- */
8
- const optimizeGitHubUrl = (url) => {
9
- const newUrl = url instanceof url_1.URL ? url : new url_1.URL(url);
10
- if (newUrl.host === 'github.com') {
11
- newUrl.host = 'togithub.com';
12
- }
13
- return newUrl;
14
- };
15
- exports.optimizeGitHubUrl = optimizeGitHubUrl;