npm-update-package 0.9.1 → 0.11.2
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 +34 -34
- package/dist/app.js +1 -1
- package/dist/bin.js +6 -4
- package/dist/git/Git.js +7 -4
- package/dist/git/index.js +1 -3
- package/dist/logger/LogLevel.js +3 -2
- package/dist/main.js +14 -11
- package/dist/ncu/Ncu.js +6 -6
- package/dist/ncu/NcuResult.js +6 -0
- package/dist/ncu/{NcuOutdatedPackagesConverter.js → NcuResultConverter.js} +5 -5
- package/dist/options/Options.js +9 -15
- package/dist/options/initOptions.js +1 -2
- package/dist/package-manager/Npm.js +4 -6
- package/dist/package-manager/Yarn.js +2 -4
- package/dist/{ncu/NcuOutdatedPackages.js → processors/FailedResult.js} +0 -0
- package/dist/processors/OutdatedPackageProcessor.js +39 -25
- package/dist/processors/{Result.js → SucceededResult.js} +0 -0
- package/dist/terminal/Terminal.js +0 -15
- package/package.json +7 -6
- package/dist/git/Committer.js +0 -31
- package/dist/ncu/isNcuOutdatedPackages.js +0 -8
- package/dist/terminal/isExecaReturnValue.js +0 -24
package/README.md
CHANGED
|
@@ -9,31 +9,44 @@ CLI tool for creating pull request to update npm packages
|
|
|
9
9
|
|
|
10
10
|
This package is currently under development, so the major version is 0 yet.
|
|
11
11
|
|
|
12
|
-
##
|
|
12
|
+
## Requirements
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
- Git v2.23.0 or higher
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
npm i -g npm-update-package
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
If you are using Yarn:
|
|
16
|
+
## Usage
|
|
21
17
|
|
|
22
18
|
```sh
|
|
23
|
-
|
|
19
|
+
npx npm-update-package --github-token $GITHUB_TOKEN
|
|
24
20
|
```
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
## Examples
|
|
23
|
+
|
|
24
|
+
Example of running npm-update-package on GitHub Actions at 0:00 (UTC) every day:
|
|
25
|
+
|
|
26
|
+
```yaml
|
|
27
|
+
name: npm-update-package
|
|
28
|
+
on:
|
|
29
|
+
schedule:
|
|
30
|
+
- cron: '0 0 * * *'
|
|
31
|
+
jobs:
|
|
32
|
+
npm-update-package:
|
|
33
|
+
runs-on: ubuntu-latest
|
|
34
|
+
steps:
|
|
35
|
+
- uses: actions/checkout@v2
|
|
36
|
+
- uses: actions/setup-node@v2
|
|
37
|
+
- run: |
|
|
38
|
+
git config user.name $GIT_USER_NAME
|
|
39
|
+
git config user.email $GIT_USER_EMAIL
|
|
40
|
+
npx npm-update-package --github-token $GITHUB_TOKEN
|
|
41
|
+
env:
|
|
42
|
+
GIT_USER_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com
|
|
43
|
+
GIT_USER_NAME: github-actions[bot]
|
|
44
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
30
45
|
```
|
|
31
46
|
|
|
32
|
-
|
|
47
|
+
Actual working examples can be seen in these repositories.
|
|
33
48
|
|
|
34
|
-
|
|
35
|
-
npm-update-package --github-token $GITHUB_TOKEN
|
|
36
|
-
```
|
|
49
|
+
- [npm-update-package/example-npm](https://github.com/npm-update-package/example-npm)
|
|
37
50
|
|
|
38
51
|
## Options
|
|
39
52
|
|
|
@@ -45,7 +58,7 @@ Template strings such as `--branch-name` can embed variables like `{{packageName
|
|
|
45
58
|
Branch name template
|
|
46
59
|
|
|
47
60
|
- value: template string
|
|
48
|
-
-
|
|
61
|
+
- variables:
|
|
49
62
|
- `currentVersion`
|
|
50
63
|
- `newVersion`
|
|
51
64
|
- `packageName`
|
|
@@ -58,7 +71,7 @@ Branch name template
|
|
|
58
71
|
Commit message template
|
|
59
72
|
|
|
60
73
|
- value: template string
|
|
61
|
-
-
|
|
74
|
+
- variables:
|
|
62
75
|
- `currentVersion`
|
|
63
76
|
- `newVersion`
|
|
64
77
|
- `packageName`
|
|
@@ -66,20 +79,6 @@ Commit message template
|
|
|
66
79
|
- required: false
|
|
67
80
|
- default: `chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}`
|
|
68
81
|
|
|
69
|
-
### `--git-user-email`
|
|
70
|
-
|
|
71
|
-
User email of commit
|
|
72
|
-
|
|
73
|
-
- value: string
|
|
74
|
-
- required: false
|
|
75
|
-
|
|
76
|
-
### `--git-user-name`
|
|
77
|
-
|
|
78
|
-
User name of commit
|
|
79
|
-
|
|
80
|
-
- value: string
|
|
81
|
-
- required: false
|
|
82
|
-
|
|
83
82
|
### `--github-token`
|
|
84
83
|
|
|
85
84
|
GitHub token
|
|
@@ -92,6 +91,7 @@ GitHub token
|
|
|
92
91
|
Log level to show
|
|
93
92
|
|
|
94
93
|
- value: string
|
|
94
|
+
- `error`
|
|
95
95
|
- `info`
|
|
96
96
|
- `debug`
|
|
97
97
|
- required: false
|
|
@@ -112,7 +112,7 @@ Package manager of your project
|
|
|
112
112
|
Pull request body template
|
|
113
113
|
|
|
114
114
|
- value: template string
|
|
115
|
-
-
|
|
115
|
+
- variables:
|
|
116
116
|
- `appName`
|
|
117
117
|
- `appVersion`
|
|
118
118
|
- `appWeb`
|
|
@@ -139,7 +139,7 @@ This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}
|
|
|
139
139
|
Pull request title template
|
|
140
140
|
|
|
141
141
|
- value: template string
|
|
142
|
-
-
|
|
142
|
+
- variables:
|
|
143
143
|
- `currentVersion`
|
|
144
144
|
- `newVersion`
|
|
145
145
|
- `packageName`
|
package/dist/app.js
CHANGED
package/dist/bin.js
CHANGED
|
@@ -12,8 +12,10 @@ logger.info(`Start ${app_1.app.name} v${app_1.app.version}`);
|
|
|
12
12
|
options,
|
|
13
13
|
logger
|
|
14
14
|
})
|
|
15
|
-
.then(() =>
|
|
16
|
-
.
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
.then(() => {
|
|
16
|
+
logger.info(`End ${app_1.app.name} v${app_1.app.version}`);
|
|
17
|
+
})
|
|
18
|
+
.catch((error) => {
|
|
19
|
+
logger.fatal(error);
|
|
20
|
+
throw error;
|
|
19
21
|
});
|
package/dist/git/Git.js
CHANGED
|
@@ -10,14 +10,11 @@ class Git {
|
|
|
10
10
|
async add(...files) {
|
|
11
11
|
await this.terminal.run('git', 'add', ...files);
|
|
12
12
|
}
|
|
13
|
-
async checkout(branchName) {
|
|
14
|
-
await this.terminal.run('git', 'checkout', branchName);
|
|
15
|
-
}
|
|
16
13
|
async commit(message) {
|
|
17
14
|
await this.terminal.run('git', 'commit', '--message', message);
|
|
18
15
|
}
|
|
19
16
|
async createBranch(branchName) {
|
|
20
|
-
await this.terminal.run('git', '
|
|
17
|
+
await this.terminal.run('git', 'switch', '-c', branchName);
|
|
21
18
|
}
|
|
22
19
|
async getConfig(key) {
|
|
23
20
|
const { stdout } = await this.terminal.run('git', 'config', key);
|
|
@@ -41,8 +38,14 @@ class Git {
|
|
|
41
38
|
async removeBranch(branchName) {
|
|
42
39
|
await this.terminal.run('git', 'branch', '-D', branchName);
|
|
43
40
|
}
|
|
41
|
+
async restore(...files) {
|
|
42
|
+
await this.terminal.run('git', 'restore', '--worktree', '--staged', ...files);
|
|
43
|
+
}
|
|
44
44
|
async setConfig(key, value) {
|
|
45
45
|
await this.terminal.run('git', 'config', key, value);
|
|
46
46
|
}
|
|
47
|
+
async switch(branchName) {
|
|
48
|
+
await this.terminal.run('git', 'switch', branchName);
|
|
49
|
+
}
|
|
47
50
|
}
|
|
48
51
|
exports.Git = Git;
|
package/dist/git/index.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Git = exports.
|
|
3
|
+
exports.Git = exports.CommitMessageCreator = exports.BranchNameCreator = void 0;
|
|
4
4
|
var BranchNameCreator_1 = require("./BranchNameCreator");
|
|
5
5
|
Object.defineProperty(exports, "BranchNameCreator", { enumerable: true, get: function () { return BranchNameCreator_1.BranchNameCreator; } });
|
|
6
6
|
var CommitMessageCreator_1 = require("./CommitMessageCreator");
|
|
7
7
|
Object.defineProperty(exports, "CommitMessageCreator", { enumerable: true, get: function () { return CommitMessageCreator_1.CommitMessageCreator; } });
|
|
8
|
-
var Committer_1 = require("./Committer");
|
|
9
|
-
Object.defineProperty(exports, "Committer", { enumerable: true, get: function () { return Committer_1.Committer; } });
|
|
10
8
|
var Git_1 = require("./Git");
|
|
11
9
|
Object.defineProperty(exports, "Git", { enumerable: true, get: function () { return Git_1.Git; } });
|
package/dist/logger/LogLevel.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isLogLevel = exports.LogLevel = void 0;
|
|
4
4
|
exports.LogLevel = {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Debug: 'debug',
|
|
6
|
+
Error: 'error',
|
|
7
|
+
Info: 'info'
|
|
7
8
|
};
|
|
8
9
|
const logLevels = Object.values(exports.LogLevel);
|
|
9
10
|
const isLogLevel = (value) => logLevels.includes(value);
|
package/dist/main.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.main = void 0;
|
|
4
|
+
const Either_1 = require("fp-ts/lib/Either");
|
|
4
5
|
const git_1 = require("./git");
|
|
5
6
|
const github_1 = require("./github");
|
|
6
7
|
const ncu_1 = require("./ncu");
|
|
@@ -43,13 +44,6 @@ const main = async ({ options, logger }) => {
|
|
|
43
44
|
});
|
|
44
45
|
logger.debug(`remoteBranches=${JSON.stringify(remoteBranches)}`);
|
|
45
46
|
const remoteBranchExistenceChecker = github_1.RemoteBranchExistenceChecker.of(remoteBranches);
|
|
46
|
-
const committer = new git_1.Committer({
|
|
47
|
-
git,
|
|
48
|
-
user: {
|
|
49
|
-
name: options.gitUserName,
|
|
50
|
-
email: options.gitUserEmail
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
47
|
const packageManager = (0, package_manager_1.createPackageManager)({
|
|
54
48
|
terminal,
|
|
55
49
|
packageManager: options.packageManager
|
|
@@ -67,7 +61,6 @@ const main = async ({ options, logger }) => {
|
|
|
67
61
|
const branchNameCreator = new git_1.BranchNameCreator(options.branchName);
|
|
68
62
|
const commitMessageCreator = new git_1.CommitMessageCreator(options.commitMessage);
|
|
69
63
|
const outdatedPackageProcessor = new processors_1.OutdatedPackageProcessor({
|
|
70
|
-
committer,
|
|
71
64
|
git,
|
|
72
65
|
ncu,
|
|
73
66
|
packageManager,
|
|
@@ -83,14 +76,24 @@ const main = async ({ options, logger }) => {
|
|
|
83
76
|
});
|
|
84
77
|
const results = await outdatedPackagesProcessor.process(outdatedPackages);
|
|
85
78
|
logger.debug(`results=${JSON.stringify(results)}`);
|
|
86
|
-
const
|
|
79
|
+
const succeededResults = results.filter(Either_1.isRight).map(({ right }) => right);
|
|
80
|
+
logger.debug(`succeededResults=${JSON.stringify(succeededResults)}`);
|
|
81
|
+
const updatedPackages = succeededResults
|
|
87
82
|
.filter(({ updated }) => updated)
|
|
88
83
|
.map(({ outdatedPackage }) => outdatedPackage);
|
|
89
84
|
logger.debug(`updatedPackages=${JSON.stringify(updatedPackages)}`);
|
|
90
|
-
const skippedPackages =
|
|
85
|
+
const skippedPackages = succeededResults
|
|
91
86
|
.filter(({ skipped }) => skipped)
|
|
92
87
|
.map(({ outdatedPackage }) => outdatedPackage);
|
|
93
88
|
logger.debug(`skippedPackages=${JSON.stringify(skippedPackages)}`);
|
|
94
|
-
|
|
89
|
+
const failedResults = results.filter(Either_1.isLeft).map(({ left }) => left);
|
|
90
|
+
logger.debug(`failedResults=${JSON.stringify(failedResults)}`);
|
|
91
|
+
const failedPackages = failedResults.map(({ outdatedPackage }) => outdatedPackage);
|
|
92
|
+
logger.debug(`failedPackages=${JSON.stringify(failedPackages)}`);
|
|
93
|
+
// TODO: show as table
|
|
94
|
+
logger.info(`Processed ${succeededResults.length + failedPackages.length} packages:
|
|
95
|
+
- ${updatedPackages.length} packages has updated: ${updatedPackages.map(({ name }) => name).join(',')}
|
|
96
|
+
- ${skippedPackages.length} packages has skipped: ${skippedPackages.map(({ name }) => name).join(',')}
|
|
97
|
+
- ${failedPackages.length} packages has failed: ${failedPackages.map(({ name }) => name).join(',')}`);
|
|
95
98
|
};
|
|
96
99
|
exports.main = main;
|
package/dist/ncu/Ncu.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Ncu = void 0;
|
|
4
4
|
const npm_check_updates_1 = require("npm-check-updates");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const NcuResult_1 = require("./NcuResult");
|
|
6
|
+
const NcuResultConverter_1 = require("./NcuResultConverter");
|
|
7
7
|
// TODO: add test
|
|
8
8
|
class Ncu {
|
|
9
9
|
constructor(packageJsonReader) {
|
|
@@ -30,11 +30,11 @@ class Ncu {
|
|
|
30
30
|
...pkg.optionalDependencies
|
|
31
31
|
};
|
|
32
32
|
const result = await (0, npm_check_updates_1.run)(options);
|
|
33
|
-
if (!(0,
|
|
34
|
-
throw new Error('result is not
|
|
33
|
+
if (!(0, NcuResult_1.isNcuResult)(result)) {
|
|
34
|
+
throw new Error('result is not NcuResult');
|
|
35
35
|
}
|
|
36
|
-
const
|
|
37
|
-
return
|
|
36
|
+
const ncuResultConverter = new NcuResultConverter_1.NcuResultConverter(currentDependencies);
|
|
37
|
+
return ncuResultConverter.toOutdatedPackages(result);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
exports.Ncu = Ncu;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNcuResult = exports.NcuResult = void 0;
|
|
4
|
+
const io_ts_1 = require("io-ts");
|
|
5
|
+
exports.NcuResult = (0, io_ts_1.record)(io_ts_1.string, io_ts_1.string);
|
|
6
|
+
exports.isNcuResult = exports.NcuResult.is;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.NcuResultConverter = void 0;
|
|
4
4
|
const PackageVersion_1 = require("./PackageVersion");
|
|
5
5
|
const toUpdateType_1 = require("./toUpdateType");
|
|
6
6
|
// TODO: add test
|
|
7
|
-
class
|
|
7
|
+
class NcuResultConverter {
|
|
8
8
|
constructor(currentDependencies) {
|
|
9
9
|
this.currentDependencies = currentDependencies;
|
|
10
10
|
}
|
|
11
|
-
toOutdatedPackages(
|
|
12
|
-
return Object.entries(
|
|
11
|
+
toOutdatedPackages(result) {
|
|
12
|
+
return Object.entries(result)
|
|
13
13
|
.map(([name, newVersion]) => ({
|
|
14
14
|
name,
|
|
15
15
|
currentVersion: PackageVersion_1.PackageVersion.of(this.currentDependencies[name]),
|
|
@@ -23,4 +23,4 @@ class NcuOutdatedPackagesConverter {
|
|
|
23
23
|
}));
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
exports.
|
|
26
|
+
exports.NcuResultConverter = NcuResultConverter;
|
package/dist/options/Options.js
CHANGED
|
@@ -4,19 +4,13 @@ exports.isOptions = void 0;
|
|
|
4
4
|
const io_ts_1 = require("io-ts");
|
|
5
5
|
const logger_1 = require("../logger");
|
|
6
6
|
const package_manager_1 = require("../package-manager");
|
|
7
|
-
const Options = (0, io_ts_1.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}),
|
|
17
|
-
(0, io_ts_1.partial)({
|
|
18
|
-
gitUserEmail: io_ts_1.string,
|
|
19
|
-
gitUserName: io_ts_1.string
|
|
20
|
-
})
|
|
21
|
-
]);
|
|
7
|
+
const Options = (0, io_ts_1.type)({
|
|
8
|
+
branchName: io_ts_1.string,
|
|
9
|
+
commitMessage: io_ts_1.string,
|
|
10
|
+
githubToken: io_ts_1.string,
|
|
11
|
+
logLevel: (0, io_ts_1.union)([(0, io_ts_1.literal)(logger_1.LogLevel.Error), (0, io_ts_1.literal)(logger_1.LogLevel.Info), (0, io_ts_1.literal)(logger_1.LogLevel.Debug)]),
|
|
12
|
+
packageManager: (0, io_ts_1.union)([(0, io_ts_1.literal)(package_manager_1.PackageManagerName.Npm), (0, io_ts_1.literal)(package_manager_1.PackageManagerName.Yarn)]),
|
|
13
|
+
pullRequestBody: io_ts_1.string,
|
|
14
|
+
pullRequestTitle: io_ts_1.string
|
|
15
|
+
});
|
|
22
16
|
exports.isOptions = Options.is;
|
|
@@ -12,11 +12,10 @@ const initOptions = () => {
|
|
|
12
12
|
.version(app_1.app.version)
|
|
13
13
|
.option('--branch-name <value>', 'Branch name template', 'npm-update-package/{{{packageName}}}/v{{newVersion}}')
|
|
14
14
|
.option('--commit-message <value>', 'Commit message template', 'chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}')
|
|
15
|
-
.option('--git-user-email <value>', 'User email of commit')
|
|
16
|
-
.option('--git-user-name <value>', 'User name of commit')
|
|
17
15
|
.requiredOption('--github-token <value>', 'GitHub token')
|
|
18
16
|
.addOption(new commander_1.Option('--log-level <value>', 'Log level to show')
|
|
19
17
|
.choices([
|
|
18
|
+
logger_1.LogLevel.Error,
|
|
20
19
|
logger_1.LogLevel.Info,
|
|
21
20
|
logger_1.LogLevel.Debug
|
|
22
21
|
])
|
|
@@ -5,14 +5,12 @@ exports.Npm = void 0;
|
|
|
5
5
|
class Npm {
|
|
6
6
|
constructor(terminal) {
|
|
7
7
|
this.terminal = terminal;
|
|
8
|
-
this.
|
|
9
|
-
|
|
10
|
-
'package-lock.json'
|
|
11
|
-
];
|
|
8
|
+
this.packageFile = 'package.json';
|
|
9
|
+
this.lockFile = 'package-lock.json';
|
|
12
10
|
}
|
|
13
11
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
* @see https://docs.npmjs.com/cli/v8/commands/npm-install
|
|
13
|
+
*/
|
|
16
14
|
async install() {
|
|
17
15
|
await this.terminal.run('npm', 'install');
|
|
18
16
|
}
|
|
@@ -5,10 +5,8 @@ exports.Yarn = void 0;
|
|
|
5
5
|
class Yarn {
|
|
6
6
|
constructor(terminal) {
|
|
7
7
|
this.terminal = terminal;
|
|
8
|
-
this.
|
|
9
|
-
|
|
10
|
-
'yarn.lock'
|
|
11
|
-
];
|
|
8
|
+
this.packageFile = 'package.json';
|
|
9
|
+
this.lockFile = 'yarn.lock';
|
|
12
10
|
}
|
|
13
11
|
/**
|
|
14
12
|
* @see https://classic.yarnpkg.com/en/docs/cli/install
|
|
File without changes
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OutdatedPackageProcessor = void 0;
|
|
4
|
+
const Either_1 = require("fp-ts/lib/Either");
|
|
4
5
|
// TODO: add test
|
|
5
6
|
class OutdatedPackageProcessor {
|
|
6
|
-
constructor({
|
|
7
|
-
this.committer = committer;
|
|
7
|
+
constructor({ git, ncu, packageManager, pullRequestCreator, remoteBranchExistenceChecker, logger, branchNameCreator, commitMessageCreator }) {
|
|
8
8
|
this.git = git;
|
|
9
9
|
this.ncu = ncu;
|
|
10
10
|
this.packageManager = packageManager;
|
|
@@ -22,35 +22,49 @@ class OutdatedPackageProcessor {
|
|
|
22
22
|
this.logger.debug(`branchName=${branchName}`);
|
|
23
23
|
if (this.remoteBranchExistenceChecker.check(branchName)) {
|
|
24
24
|
this.logger.info(`Skip ${outdatedPackage.name} because ${branchName} branch already exists on remote.`);
|
|
25
|
-
return {
|
|
25
|
+
return (0, Either_1.right)({
|
|
26
26
|
outdatedPackage,
|
|
27
27
|
skipped: true
|
|
28
|
-
};
|
|
28
|
+
});
|
|
29
29
|
}
|
|
30
30
|
await this.git.createBranch(branchName);
|
|
31
31
|
this.logger.info(`${branchName} branch has created.`);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
try {
|
|
33
|
+
try {
|
|
34
|
+
const updatedPackages = await this.ncu.update(outdatedPackage);
|
|
35
|
+
if (updatedPackages.length !== 1) {
|
|
36
|
+
throw new Error(`Failed to update ${outdatedPackage.name}.`);
|
|
37
|
+
}
|
|
38
|
+
await this.packageManager.install();
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
this.logger.error(error);
|
|
42
|
+
return (0, Either_1.left)({
|
|
43
|
+
outdatedPackage,
|
|
44
|
+
error
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
this.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`);
|
|
48
|
+
await this.git.add(this.packageManager.packageFile, this.packageManager.lockFile);
|
|
49
|
+
const message = this.commitMessageCreator.create(outdatedPackage);
|
|
50
|
+
this.logger.debug(`message=${message}`);
|
|
51
|
+
await this.git.commit(message);
|
|
52
|
+
await this.git.push(branchName);
|
|
53
|
+
await this.pullRequestCreator.create({
|
|
54
|
+
outdatedPackage,
|
|
55
|
+
branchName
|
|
56
|
+
});
|
|
57
|
+
return (0, Either_1.right)({
|
|
58
|
+
outdatedPackage,
|
|
59
|
+
updated: true
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
await this.git.restore(this.packageManager.packageFile, this.packageManager.lockFile);
|
|
64
|
+
await this.git.switch('-');
|
|
65
|
+
await this.git.removeBranch(branchName);
|
|
66
|
+
this.logger.info(`${branchName} branch has removed.`);
|
|
35
67
|
}
|
|
36
|
-
await this.packageManager.install();
|
|
37
|
-
this.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`);
|
|
38
|
-
await this.git.add(...this.packageManager.packageFiles);
|
|
39
|
-
const message = this.commitMessageCreator.create(outdatedPackage);
|
|
40
|
-
this.logger.debug(`message=${message}`);
|
|
41
|
-
await this.committer.commit(message);
|
|
42
|
-
await this.git.push(branchName);
|
|
43
|
-
await this.pullRequestCreator.create({
|
|
44
|
-
outdatedPackage,
|
|
45
|
-
branchName
|
|
46
|
-
});
|
|
47
|
-
await this.git.checkout('-');
|
|
48
|
-
await this.git.removeBranch(branchName);
|
|
49
|
-
this.logger.info(`${branchName} branch has removed.`);
|
|
50
|
-
return {
|
|
51
|
-
outdatedPackage,
|
|
52
|
-
updated: true
|
|
53
|
-
};
|
|
54
68
|
}
|
|
55
69
|
}
|
|
56
70
|
exports.OutdatedPackageProcessor = OutdatedPackageProcessor;
|
|
File without changes
|
|
@@ -5,25 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Terminal = void 0;
|
|
7
7
|
const execa_1 = __importDefault(require("execa"));
|
|
8
|
-
const isExecaReturnValue_1 = require("./isExecaReturnValue");
|
|
9
8
|
// TODO: add test
|
|
10
9
|
class Terminal {
|
|
11
10
|
async run(command, ...args) {
|
|
12
11
|
return await (0, execa_1.default)(command, args);
|
|
13
12
|
}
|
|
14
|
-
async runWithErrorHandling(command, ...args) {
|
|
15
|
-
try {
|
|
16
|
-
return await this.run(command, ...args);
|
|
17
|
-
}
|
|
18
|
-
catch (e) {
|
|
19
|
-
const value = e instanceof Error ? JSON.parse(JSON.stringify(e)) : e;
|
|
20
|
-
if ((0, isExecaReturnValue_1.isExecaReturnValue)(value)) {
|
|
21
|
-
return value;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
throw e;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
13
|
}
|
|
29
14
|
exports.Terminal = Terminal;
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-update-package",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"description": "CLI tool for creating pull request to update npm packages",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc --project tsconfig.build.json",
|
|
7
7
|
"clean": "rimraf dist",
|
|
8
8
|
"lint": "eslint '**/*.{js,ts}'",
|
|
9
|
+
"prebuild": "npm run clean",
|
|
9
10
|
"prepare": "husky install",
|
|
10
|
-
"prepublish": "npm-run-all
|
|
11
|
+
"prepublish": "npm-run-all lint test build",
|
|
11
12
|
"start": "ts-node src/bin.ts",
|
|
12
13
|
"test": "jest --passWithNoTests"
|
|
13
14
|
},
|
|
@@ -23,7 +24,7 @@
|
|
|
23
24
|
"io-ts": "2.2.16",
|
|
24
25
|
"log4js": "6.3.0",
|
|
25
26
|
"mustache": "4.1.0",
|
|
26
|
-
"npm-check-updates": "12.0.
|
|
27
|
+
"npm-check-updates": "12.0.3",
|
|
27
28
|
"parse-github-url": "1.0.2",
|
|
28
29
|
"semver": "7.3.5"
|
|
29
30
|
},
|
|
@@ -36,19 +37,19 @@
|
|
|
36
37
|
"@types/parse-github-url": "1.0.0",
|
|
37
38
|
"@types/semver": "7.3.9",
|
|
38
39
|
"@typescript-eslint/eslint-plugin": "5.5.0",
|
|
39
|
-
"eslint": "8.
|
|
40
|
+
"eslint": "8.4.1",
|
|
40
41
|
"eslint-config-standard-with-typescript": "21.0.1",
|
|
41
42
|
"eslint-plugin-import": "2.25.3",
|
|
42
43
|
"eslint-plugin-jest": "25.3.0",
|
|
43
44
|
"eslint-plugin-node": "11.1.0",
|
|
44
|
-
"eslint-plugin-promise": "5.
|
|
45
|
+
"eslint-plugin-promise": "5.2.0",
|
|
45
46
|
"eslint-plugin-tsdoc": "0.2.14",
|
|
46
47
|
"husky": "7.0.4",
|
|
47
48
|
"jest": "27.0.6",
|
|
48
49
|
"lint-staged": "12.1.2",
|
|
49
50
|
"npm-run-all": "4.1.5",
|
|
50
51
|
"rimraf": "3.0.2",
|
|
51
|
-
"ts-jest": "27.0
|
|
52
|
+
"ts-jest": "27.1.0",
|
|
52
53
|
"ts-node": "10.4.0",
|
|
53
54
|
"typescript": "4.4.4",
|
|
54
55
|
"utility-types": "3.10.0"
|
package/dist/git/Committer.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Committer = void 0;
|
|
4
|
-
// TODO: add test
|
|
5
|
-
class Committer {
|
|
6
|
-
constructor({ git, user }) {
|
|
7
|
-
this.git = git;
|
|
8
|
-
this.user = user;
|
|
9
|
-
}
|
|
10
|
-
async commit(message) {
|
|
11
|
-
var _a, _b;
|
|
12
|
-
let name;
|
|
13
|
-
if (((_a = this.user) === null || _a === void 0 ? void 0 : _a.name) !== undefined) {
|
|
14
|
-
name = await this.git.getConfig('user.name');
|
|
15
|
-
await this.git.setConfig('user.name', this.user.name);
|
|
16
|
-
}
|
|
17
|
-
let email;
|
|
18
|
-
if (((_b = this.user) === null || _b === void 0 ? void 0 : _b.email) !== undefined) {
|
|
19
|
-
email = await this.git.getConfig('user.email');
|
|
20
|
-
await this.git.setConfig('user.email', this.user.email);
|
|
21
|
-
}
|
|
22
|
-
await this.git.commit(message);
|
|
23
|
-
if (name !== undefined) {
|
|
24
|
-
await this.git.setConfig('user.name', name);
|
|
25
|
-
}
|
|
26
|
-
if (email !== undefined) {
|
|
27
|
-
await this.git.setConfig('user.email', email);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
exports.Committer = Committer;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNcuOutdatedPackages = void 0;
|
|
4
|
-
// TODO: add test
|
|
5
|
-
const isNcuOutdatedPackages = (value) => {
|
|
6
|
-
return typeof value === 'object' && value !== null && Object.values(value).every(value => typeof value === 'string');
|
|
7
|
-
};
|
|
8
|
-
exports.isNcuOutdatedPackages = isNcuOutdatedPackages;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isExecaReturnValue = void 0;
|
|
4
|
-
const io_ts_1 = require("io-ts");
|
|
5
|
-
const ExecaReturnValueType = (0, io_ts_1.intersection)([
|
|
6
|
-
(0, io_ts_1.type)({
|
|
7
|
-
command: io_ts_1.string,
|
|
8
|
-
escapedCommand: io_ts_1.string,
|
|
9
|
-
exitCode: io_ts_1.number,
|
|
10
|
-
failed: io_ts_1.boolean,
|
|
11
|
-
timedOut: io_ts_1.boolean,
|
|
12
|
-
killed: io_ts_1.boolean,
|
|
13
|
-
isCanceled: io_ts_1.boolean
|
|
14
|
-
}),
|
|
15
|
-
(0, io_ts_1.partial)({
|
|
16
|
-
signal: io_ts_1.string,
|
|
17
|
-
signalDescription: io_ts_1.string
|
|
18
|
-
})
|
|
19
|
-
]);
|
|
20
|
-
// TODO: add test
|
|
21
|
-
const isExecaReturnValue = (value) => {
|
|
22
|
-
return ExecaReturnValueType.is(value);
|
|
23
|
-
};
|
|
24
|
-
exports.isExecaReturnValue = isExecaReturnValue;
|