npm-update-package 0.52.1 → 0.54.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
@@ -13,11 +13,15 @@ CLI tool for creating pull requests to update npm packages
13
13
  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
14
14
 
15
15
  - [Usage](#usage)
16
+ - [Requirements](#requirements)
17
+ - [Supported platforms](#supported-platforms)
16
18
  - [Options](#options)
17
19
  - [assignees](#assignees)
18
20
  - [commitMessage](#commitmessage)
19
21
  - [fetchReleaseNotes](#fetchreleasenotes)
20
22
  - [fetchSleepTime](#fetchsleeptime)
23
+ - [gitUserEmail](#gituseremail)
24
+ - [gitUserName](#gitusername)
21
25
  - [githubToken](#githubtoken)
22
26
  - [ignorePackages](#ignorepackages)
23
27
  - [logLevel](#loglevel)
@@ -45,6 +49,17 @@ CLI tool for creating pull requests to update npm packages
45
49
  npx npm-update-package --github-token $GITHUB_TOKEN
46
50
  ```
47
51
 
52
+ ## Requirements
53
+
54
+ - Git
55
+ - Node.js
56
+ - npm or Yarn
57
+
58
+ ## Supported platforms
59
+
60
+ - GitHub
61
+ - GitHub Enterprise
62
+
48
63
  ## Options
49
64
 
50
65
  You can customize behavior via CLI options.
@@ -135,6 +150,42 @@ npx npm-update-package \
135
150
  --fetch-sleep-time 2000
136
151
  ```
137
152
 
153
+ ### gitUserEmail
154
+
155
+ Git user email.
156
+
157
+ |Name|Value|
158
+ |---|---|
159
+ |cli|`--git-user-email`|
160
+ |type|string|
161
+ |required|false|
162
+
163
+ Example:
164
+
165
+ ```sh
166
+ npx npm-update-package \
167
+ --github-token $GITHUB_TOKEN \
168
+ --git-user-email octocat@example.com
169
+ ```
170
+
171
+ ### gitUserName
172
+
173
+ Git user name.
174
+
175
+ |Name|Value|
176
+ |---|---|
177
+ |cli|`--git-user-name`|
178
+ |type|string|
179
+ |required|false|
180
+
181
+ Example:
182
+
183
+ ```sh
184
+ npx npm-update-package \
185
+ --github-token $GITHUB_TOKEN \
186
+ --git-user-name octocat
187
+ ```
188
+
138
189
  ### githubToken
139
190
 
140
191
  [GitHub token](#github-token).
@@ -196,14 +247,14 @@ npx npm-update-package \
196
247
 
197
248
  ### packageManager
198
249
 
199
- Package manager of your project.
250
+ Package manager of your project.
251
+ Since npm-update-package automatically determines which package manager to use, it is usually not necessary to specify this option.
200
252
 
201
253
  |Name|Value|
202
254
  |---|---|
203
255
  |cli|`--package-manager`|
204
256
  |type|string|
205
257
  |required|false|
206
- |default|`npm`|
207
258
 
208
259
  Allowed values:
209
260
 
@@ -330,9 +381,10 @@ jobs:
330
381
  - uses: actions/checkout@v2
331
382
  - uses: actions/setup-node@v2
332
383
  - run: |
333
- git config user.name $GIT_USER_NAME
334
- git config user.email $GIT_USER_EMAIL
335
- npx npm-update-package --github-token $GITHUB_TOKEN
384
+ npx npm-update-package \
385
+ --github-token $GITHUB_TOKEN \
386
+ --git-user-name $GIT_USER_NAME \
387
+ --git-user-email $GIT_USER_EMAIL
336
388
  env:
337
389
  GIT_USER_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com
338
390
  GIT_USER_NAME: github-actions[bot]
@@ -361,9 +413,10 @@ jobs:
361
413
  app_id: ${{ secrets.APP_ID }}
362
414
  private_key: ${{ secrets.PRIVATE_KEY }}
363
415
  - run: |
364
- git config user.name $GIT_USER_NAME
365
- git config user.email $GIT_USER_EMAIL
366
- npx npm-update-package --github-token $GITHUB_TOKEN
416
+ npx npm-update-package \
417
+ --github-token $GITHUB_TOKEN \
418
+ --git-user-name $GIT_USER_NAME \
419
+ --git-user-email $GIT_USER_EMAIL
367
420
  env:
368
421
  # TODO: Replace with your GitHub App's email
369
422
  GIT_USER_EMAIL: 97396142+npm-update-package[bot]@users.noreply.github.com
@@ -388,9 +441,10 @@ jobs:
388
441
  - uses: actions/checkout@v2
389
442
  - uses: actions/setup-node@v2
390
443
  - run: |
391
- git config user.name $GIT_USER_NAME
392
- git config user.email $GIT_USER_EMAIL
393
- npx npm-update-package --github-token $GITHUB_TOKEN
444
+ npx npm-update-package \
445
+ --github-token $GITHUB_TOKEN \
446
+ --git-user-name $GIT_USER_NAME \
447
+ --git-user-email $GIT_USER_EMAIL
394
448
  env:
395
449
  # TODO: Replace with your email
396
450
  GIT_USER_EMAIL: 97961304+npm-update-package-bot@users.noreply.github.com
@@ -421,9 +475,11 @@ jobs:
421
475
  app_id: ${{ secrets.APP_ID }}
422
476
  private_key: ${{ secrets.PRIVATE_KEY }}
423
477
  - run: |
424
- git config user.name $GIT_USER_NAME
425
- git config user.email $GIT_USER_EMAIL
426
- npx npm-update-package --github-token $GITHUB_TOKEN --package-manager yarn
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
427
483
  env:
428
484
  # TODO: Replace with your GitHub App's email
429
485
  GIT_USER_EMAIL: 97396142+npm-update-package[bot]@users.noreply.github.com
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-update-package",
3
- "version": "0.52.1",
3
+ "version": "0.54.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",
@@ -15,7 +15,7 @@
15
15
  "bin": "dist/src/bin.js",
16
16
  "dependencies": {
17
17
  "@octokit/rest": "18.12.0",
18
- "commander": "8.3.0",
18
+ "commander": "9.1.0",
19
19
  "execa": "5.1.1",
20
20
  "fp-ts": "2.11.9",
21
21
  "http-status-codes": "2.2.0",
@@ -24,7 +24,7 @@
24
24
  "log4js": "6.4.4",
25
25
  "mustache": "4.1.0",
26
26
  "node-fetch": "2.6.7",
27
- "npm-check-updates": "12.5.4",
27
+ "npm-check-updates": "12.5.5",
28
28
  "parse-github-url": "1.0.2",
29
29
  "semver": "7.3.5",
30
30
  "sleep-promise": "9.1.0",
@@ -33,14 +33,14 @@
33
33
  "devDependencies": {
34
34
  "@jest/types": "27.4.2",
35
35
  "@tsconfig/node12": "1.0.9",
36
- "@types/jest": "27.4.0",
37
- "@types/lodash": "4.14.180",
36
+ "@types/jest": "27.4.1",
37
+ "@types/lodash": "4.14.181",
38
38
  "@types/mustache": "4.1.2",
39
- "@types/node": "12.20.40",
39
+ "@types/node": "12.20.47",
40
40
  "@types/node-fetch": "2.6.1",
41
41
  "@types/parse-github-url": "1.0.0",
42
42
  "@types/semver": "7.3.9",
43
- "@typescript-eslint/eslint-plugin": "5.16.0",
43
+ "@typescript-eslint/eslint-plugin": "5.17.0",
44
44
  "eslint": "8.12.0",
45
45
  "eslint-config-standard-with-typescript": "21.0.1",
46
46
  "eslint-plugin-import": "2.25.4",
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.canReadWrite = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ // TODO: Add test
9
+ const canReadWrite = async (path) => {
10
+ try {
11
+ await fs_1.default.promises.access(path, fs_1.default.constants.R_OK | fs_1.default.constants.W_OK);
12
+ }
13
+ catch {
14
+ return false;
15
+ }
16
+ return true;
17
+ };
18
+ exports.canReadWrite = canReadWrite;
@@ -14,4 +14,5 @@ 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("./canReadWrite"), exports);
17
18
  __exportStar(require("./readFile"), exports);
@@ -27,6 +27,9 @@ class Git {
27
27
  async restore(...files) {
28
28
  await this.terminal.run('git', 'checkout', ...files);
29
29
  }
30
+ async setConfig(key, value) {
31
+ await this.terminal.run('git', 'config', key, value);
32
+ }
30
33
  async switch(branchName) {
31
34
  await this.terminal.run('git', 'checkout', branchName);
32
35
  }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GitConfigInitializer = void 0;
4
+ class GitConfigInitializer {
5
+ constructor({ options, git }) {
6
+ this.options = options;
7
+ this.git = git;
8
+ }
9
+ async initialize() {
10
+ if (this.options.gitUserName !== undefined) {
11
+ await this.git.setConfig('user.name', this.options.gitUserName);
12
+ }
13
+ if (this.options.gitUserEmail !== undefined) {
14
+ await this.git.setConfig('user.email', this.options.gitUserEmail);
15
+ }
16
+ }
17
+ }
18
+ exports.GitConfigInitializer = GitConfigInitializer;
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./CommitMessageCreator"), exports);
18
18
  __exportStar(require("./createBranchName"), exports);
19
19
  __exportStar(require("./Git"), exports);
20
+ __exportStar(require("./GitConfigInitializer"), exports);
20
21
  __exportStar(require("./GitRepository"), exports);
package/dist/src/main.js CHANGED
@@ -63,10 +63,11 @@ const main = async ({ options, logger }) => {
63
63
  color: 'A00F21'
64
64
  });
65
65
  const branchFinder = new github_1.BranchFinder(branches);
66
- const packageManager = (0, package_manager_1.createPackageManager)({
67
- terminal,
68
- packageManager: options.packageManager
66
+ const packageManagerCreator = new package_manager_1.PackageManagerCreator({
67
+ options,
68
+ logger
69
69
  });
70
+ const packageManager = await packageManagerCreator.create(terminal);
70
71
  const pullRequestTitleCreator = new github_1.PullRequestTitleCreator(options.prTitle);
71
72
  const releasesFetcher = new github_1.ReleasesFetcher({
72
73
  options,
@@ -108,6 +109,11 @@ const main = async ({ options, logger }) => {
108
109
  pullRequestsCloser,
109
110
  packageUpdater
110
111
  });
112
+ const gitConfigInitializer = new git_1.GitConfigInitializer({
113
+ options,
114
+ git
115
+ });
116
+ await gitConfigInitializer.initialize();
111
117
  const outdatedPackagesProcessor = new core_1.OutdatedPackagesProcessor({
112
118
  outdatedPackageProcessor,
113
119
  logger
@@ -15,12 +15,14 @@ class Ncu {
15
15
  }
16
16
  async check() {
17
17
  return await this.run({
18
+ packageManager: this.options.packageManager,
18
19
  jsonUpgraded: true,
19
20
  reject: this.options.ignorePackages
20
21
  });
21
22
  }
22
23
  async update(outdatedPackage) {
23
24
  return await this.run({
25
+ packageManager: this.options.packageManager,
24
26
  jsonUpgraded: true,
25
27
  filter: outdatedPackage.name,
26
28
  upgrade: true
@@ -19,15 +19,17 @@ 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
- packageManager: (0, io_ts_1.union)([
23
- (0, io_ts_1.literal)(package_manager_1.PackageManagerName.Npm),
24
- (0, io_ts_1.literal)(package_manager_1.PackageManagerName.Yarn)
25
- ]),
26
22
  prTitle: io_ts_1.string
27
23
  }),
28
24
  (0, io_ts_1.partial)({
29
25
  assignees: (0, io_ts_1.array)(io_ts_1.string),
26
+ gitUserEmail: io_ts_1.string,
27
+ gitUserName: io_ts_1.string,
30
28
  ignorePackages: (0, io_ts_1.array)(io_ts_1.string),
29
+ packageManager: (0, io_ts_1.union)([
30
+ (0, io_ts_1.literal)(package_manager_1.PackageManagerName.Npm),
31
+ (0, io_ts_1.literal)(package_manager_1.PackageManagerName.Yarn)
32
+ ]),
31
33
  prBodyNotes: io_ts_1.string,
32
34
  reviewers: (0, io_ts_1.array)(io_ts_1.string)
33
35
  })
@@ -32,6 +32,18 @@ exports.cliOptions = [
32
32
  required: false,
33
33
  default: 1000
34
34
  },
35
+ {
36
+ name: 'git-user-email',
37
+ description: 'Git user email',
38
+ type: OptionType_1.OptionType.String,
39
+ required: false
40
+ },
41
+ {
42
+ name: 'git-user-name',
43
+ description: 'Git user name',
44
+ type: OptionType_1.OptionType.String,
45
+ required: false
46
+ },
35
47
  {
36
48
  name: 'github-token',
37
49
  description: 'GitHub token',
@@ -68,8 +80,7 @@ exports.cliOptions = [
68
80
  choices: [
69
81
  package_manager_1.PackageManagerName.Npm,
70
82
  package_manager_1.PackageManagerName.Yarn
71
- ],
72
- default: package_manager_1.PackageManagerName.Npm
83
+ ]
73
84
  },
74
85
  {
75
86
  name: 'pr-body-notes',
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PackageManagerCreator = void 0;
4
+ const detectPackageManager_1 = require("./detectPackageManager");
5
+ const Npm_1 = require("./Npm");
6
+ const PackageManagerName_1 = require("./PackageManagerName");
7
+ const Yarn_1 = require("./Yarn");
8
+ class PackageManagerCreator {
9
+ constructor({ options, logger }) {
10
+ this.options = options;
11
+ this.logger = logger;
12
+ }
13
+ async create(terminal) {
14
+ const packageManagerName = await this.getPackageManagerName();
15
+ this.logger.trace(`packageManagerName=${packageManagerName}`);
16
+ switch (packageManagerName) {
17
+ case PackageManagerName_1.PackageManagerName.Npm:
18
+ this.logger.info('Use npm as package manager');
19
+ return new Npm_1.Npm(terminal);
20
+ case PackageManagerName_1.PackageManagerName.Yarn:
21
+ this.logger.info('Use Yarn as package manager');
22
+ return new Yarn_1.Yarn(terminal);
23
+ }
24
+ }
25
+ async getPackageManagerName() {
26
+ if (this.options.packageManager !== undefined) {
27
+ return this.options.packageManager;
28
+ }
29
+ this.logger.info('Try to detect package manager from lock file.');
30
+ return await (0, detectPackageManager_1.detectPackageManager)();
31
+ }
32
+ }
33
+ exports.PackageManagerCreator = PackageManagerCreator;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectPackageManager = void 0;
4
+ const file_1 = require("../file");
5
+ const PackageManagerName_1 = require("./PackageManagerName");
6
+ const detectPackageManager = async () => {
7
+ if (await (0, file_1.canReadWrite)('package-lock.json')) {
8
+ return PackageManagerName_1.PackageManagerName.Npm;
9
+ }
10
+ if (await (0, file_1.canReadWrite)('yarn.lock')) {
11
+ return PackageManagerName_1.PackageManagerName.Yarn;
12
+ }
13
+ throw new Error('No lock file exists.');
14
+ };
15
+ exports.detectPackageManager = detectPackageManager;
@@ -14,8 +14,8 @@ 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("./createPackageManager"), exports);
18
17
  __exportStar(require("./Npm"), exports);
19
18
  __exportStar(require("./PackageManager"), exports);
19
+ __exportStar(require("./PackageManagerCreator"), exports);
20
20
  __exportStar(require("./PackageManagerName"), exports);
21
21
  __exportStar(require("./Yarn"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-update-package",
3
- "version": "0.52.1",
3
+ "version": "0.54.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",
@@ -15,7 +15,7 @@
15
15
  "bin": "dist/src/bin.js",
16
16
  "dependencies": {
17
17
  "@octokit/rest": "18.12.0",
18
- "commander": "8.3.0",
18
+ "commander": "9.1.0",
19
19
  "execa": "5.1.1",
20
20
  "fp-ts": "2.11.9",
21
21
  "http-status-codes": "2.2.0",
@@ -24,7 +24,7 @@
24
24
  "log4js": "6.4.4",
25
25
  "mustache": "4.1.0",
26
26
  "node-fetch": "2.6.7",
27
- "npm-check-updates": "12.5.4",
27
+ "npm-check-updates": "12.5.5",
28
28
  "parse-github-url": "1.0.2",
29
29
  "semver": "7.3.5",
30
30
  "sleep-promise": "9.1.0",
@@ -33,14 +33,14 @@
33
33
  "devDependencies": {
34
34
  "@jest/types": "27.4.2",
35
35
  "@tsconfig/node12": "1.0.9",
36
- "@types/jest": "27.4.0",
37
- "@types/lodash": "4.14.180",
36
+ "@types/jest": "27.4.1",
37
+ "@types/lodash": "4.14.181",
38
38
  "@types/mustache": "4.1.2",
39
- "@types/node": "12.20.40",
39
+ "@types/node": "12.20.47",
40
40
  "@types/node-fetch": "2.6.1",
41
41
  "@types/parse-github-url": "1.0.0",
42
42
  "@types/semver": "7.3.9",
43
- "@typescript-eslint/eslint-plugin": "5.16.0",
43
+ "@typescript-eslint/eslint-plugin": "5.17.0",
44
44
  "eslint": "8.12.0",
45
45
  "eslint-config-standard-with-typescript": "21.0.1",
46
46
  "eslint-plugin-import": "2.25.4",
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createPackageManager = void 0;
4
- const Npm_1 = require("./Npm");
5
- const PackageManagerName_1 = require("./PackageManagerName");
6
- const Yarn_1 = require("./Yarn");
7
- const createPackageManager = ({ terminal, packageManager }) => {
8
- switch (packageManager) {
9
- case PackageManagerName_1.PackageManagerName.Npm:
10
- return new Npm_1.Npm(terminal);
11
- case PackageManagerName_1.PackageManagerName.Yarn:
12
- return new Yarn_1.Yarn(terminal);
13
- }
14
- };
15
- exports.createPackageManager = createPackageManager;