npm-update-package 0.8.0 → 0.9.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/dist/app.js +1 -1
- package/package.json +10 -6
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -23
- package/.github/FUNDING.yml +0 -2
- package/.github/renovate.json +0 -15
- package/.github/workflows/eslint.yml +0 -14
- package/.github/workflows/test.yml +0 -19
- package/.husky/pre-commit +0 -4
- package/.nvmrc +0 -1
- package/jest.config.ts +0 -11
- package/lint-staged.config.js +0 -4
- package/npm-update-package.code-workspace +0 -8
- package/src/app.ts +0 -5
- package/src/bin.ts +0 -20
- package/src/git/BranchNameCreator.test.ts +0 -17
- package/src/git/BranchNameCreator.ts +0 -19
- package/src/git/CommitMessageCreator.test.ts +0 -17
- package/src/git/CommitMessageCreator.ts +0 -19
- package/src/git/Committer.ts +0 -49
- package/src/git/Git.ts +0 -55
- package/src/git/GitRepository.test.ts +0 -61
- package/src/git/GitRepository.ts +0 -57
- package/src/git/index.ts +0 -5
- package/src/github/Branch.ts +0 -4
- package/src/github/GitHub.ts +0 -27
- package/src/github/PullRequest.ts +0 -3
- package/src/github/PullRequestBodyCreator.test.ts +0 -32
- package/src/github/PullRequestBodyCreator.ts +0 -26
- package/src/github/PullRequestCreator.ts +0 -65
- package/src/github/PullRequestTitleCreator.test.ts +0 -17
- package/src/github/PullRequestTitleCreator.ts +0 -19
- package/src/github/RemoteBranchExistenceChecker.ts +0 -15
- package/src/github/Repository.ts +0 -3
- package/src/github/createGitHub.ts +0 -18
- package/src/github/createOctokit.ts +0 -28
- package/src/github/index.ts +0 -9
- package/src/logger/LogLevel.ts +0 -8
- package/src/logger/Logger.ts +0 -1
- package/src/logger/createLogger.ts +0 -10
- package/src/logger/index.ts +0 -6
- package/src/main.ts +0 -128
- package/src/ncu/Ncu.ts +0 -43
- package/src/ncu/NcuOutdatedPackages.ts +0 -6
- package/src/ncu/NcuOutdatedPackagesConverter.ts +0 -25
- package/src/ncu/OutdatedPackage.ts +0 -9
- package/src/ncu/PackageVersion.test.ts +0 -25
- package/src/ncu/PackageVersion.ts +0 -40
- package/src/ncu/UpdateType.ts +0 -9
- package/src/ncu/index.ts +0 -7
- package/src/ncu/isNcuOutdatedPackages.ts +0 -6
- package/src/ncu/toUpdateType.test.ts +0 -21
- package/src/ncu/toUpdateType.ts +0 -18
- package/src/options/Options.ts +0 -30
- package/src/options/index.ts +0 -2
- package/src/options/initOptions.ts +0 -53
- package/src/package-json/Package.ts +0 -24
- package/src/package-json/PackageDependencies.ts +0 -10
- package/src/package-json/PackageJsonParser.ts +0 -19
- package/src/package-json/PackageJsonReader.ts +0 -27
- package/src/package-json/index.ts +0 -3
- package/src/package-manager/Npm.ts +0 -19
- package/src/package-manager/PackageManager.ts +0 -4
- package/src/package-manager/PackageManagerName.ts +0 -8
- package/src/package-manager/Yarn.ts +0 -19
- package/src/package-manager/createPackageManager.ts +0 -21
- package/src/package-manager/index.ts +0 -8
- package/src/processors/OutdatedPackageProcessor.ts +0 -109
- package/src/processors/OutdatedPackagesProcessor.ts +0 -32
- package/src/processors/Result.ts +0 -7
- package/src/processors/index.ts +0 -2
- package/src/terminal/Terminal.ts +0 -30
- package/src/terminal/index.ts +0 -1
- package/src/terminal/isExecaReturnValue.ts +0 -30
- package/tsconfig.base.json +0 -3
- package/tsconfig.build.json +0 -13
- package/tsconfig.json +0 -9
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import type { Logger } from '../logger'
|
|
3
|
-
import type { Package } from './Package'
|
|
4
|
-
import type { PackageJsonParser } from './PackageJsonParser'
|
|
5
|
-
|
|
6
|
-
// TODO: add test
|
|
7
|
-
export class PackageJsonReader {
|
|
8
|
-
private readonly packageJsonParser: PackageJsonParser
|
|
9
|
-
private readonly logger: Logger
|
|
10
|
-
|
|
11
|
-
constructor ({
|
|
12
|
-
packageJsonParser,
|
|
13
|
-
logger
|
|
14
|
-
}: {
|
|
15
|
-
packageJsonParser: PackageJsonParser
|
|
16
|
-
logger: Logger
|
|
17
|
-
}) {
|
|
18
|
-
this.packageJsonParser = packageJsonParser
|
|
19
|
-
this.logger = logger
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async read (filePath: string): Promise<Package> {
|
|
23
|
-
const json = await fs.promises.readFile(filePath, 'utf8')
|
|
24
|
-
this.logger.debug(`json=${json}`)
|
|
25
|
-
return this.packageJsonParser.parse(json)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Terminal } from '../terminal'
|
|
2
|
-
import type { PackageManager } from './PackageManager'
|
|
3
|
-
|
|
4
|
-
// TODO: add test
|
|
5
|
-
export class Npm implements PackageManager {
|
|
6
|
-
readonly packageFiles = [
|
|
7
|
-
'package.json',
|
|
8
|
-
'package-lock.json'
|
|
9
|
-
]
|
|
10
|
-
|
|
11
|
-
constructor (private readonly terminal: Terminal) {}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @see https://docs.npmjs.com/cli/v8/commands/npm-install
|
|
15
|
-
*/
|
|
16
|
-
async install (): Promise<void> {
|
|
17
|
-
await this.terminal.run('npm', 'install')
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export const PackageManagerName = {
|
|
2
|
-
Npm: 'npm',
|
|
3
|
-
Yarn: 'yarn'
|
|
4
|
-
} as const
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
6
|
-
export type PackageManagerName = typeof PackageManagerName[keyof typeof PackageManagerName]
|
|
7
|
-
const packageManagerNames = Object.values(PackageManagerName)
|
|
8
|
-
export const isPackageManagerName = (value: any): value is PackageManagerName => packageManagerNames.includes(value)
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Terminal } from '../terminal'
|
|
2
|
-
import type { PackageManager } from './PackageManager'
|
|
3
|
-
|
|
4
|
-
// TODO: add test
|
|
5
|
-
export class Yarn implements PackageManager {
|
|
6
|
-
readonly packageFiles = [
|
|
7
|
-
'package.json',
|
|
8
|
-
'yarn.lock'
|
|
9
|
-
]
|
|
10
|
-
|
|
11
|
-
constructor (private readonly terminal: Terminal) {}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @see https://classic.yarnpkg.com/en/docs/cli/install
|
|
15
|
-
*/
|
|
16
|
-
async install (): Promise<void> {
|
|
17
|
-
await this.terminal.run('yarn', 'install')
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Terminal } from '../terminal'
|
|
2
|
-
import { Npm } from './Npm'
|
|
3
|
-
import type { PackageManager } from './PackageManager'
|
|
4
|
-
import type { PackageManagerName } from './PackageManagerName'
|
|
5
|
-
import { Yarn } from './Yarn'
|
|
6
|
-
|
|
7
|
-
// TODO: add test
|
|
8
|
-
export const createPackageManager = ({
|
|
9
|
-
terminal,
|
|
10
|
-
packageManager
|
|
11
|
-
}: {
|
|
12
|
-
terminal: Terminal
|
|
13
|
-
packageManager: PackageManagerName
|
|
14
|
-
}): PackageManager => {
|
|
15
|
-
switch (packageManager) {
|
|
16
|
-
case 'npm':
|
|
17
|
-
return new Npm(terminal)
|
|
18
|
-
case 'yarn':
|
|
19
|
-
return new Yarn(terminal)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { createPackageManager } from './createPackageManager'
|
|
2
|
-
export { Npm } from './Npm'
|
|
3
|
-
export type { PackageManager } from './PackageManager'
|
|
4
|
-
export {
|
|
5
|
-
isPackageManagerName,
|
|
6
|
-
PackageManagerName
|
|
7
|
-
} from './PackageManagerName'
|
|
8
|
-
export { Yarn } from './Yarn'
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BranchNameCreator,
|
|
3
|
-
CommitMessageCreator,
|
|
4
|
-
Committer,
|
|
5
|
-
Git
|
|
6
|
-
} from '../git'
|
|
7
|
-
import type {
|
|
8
|
-
PullRequestCreator,
|
|
9
|
-
RemoteBranchExistenceChecker
|
|
10
|
-
} from '../github'
|
|
11
|
-
import type { Logger } from '../logger'
|
|
12
|
-
import type {
|
|
13
|
-
Ncu,
|
|
14
|
-
OutdatedPackage
|
|
15
|
-
} from '../ncu'
|
|
16
|
-
import type { PackageManager } from '../package-manager'
|
|
17
|
-
import type { Result } from './Result'
|
|
18
|
-
|
|
19
|
-
// TODO: add test
|
|
20
|
-
export class OutdatedPackageProcessor {
|
|
21
|
-
private readonly committer: Committer
|
|
22
|
-
private readonly git: Git
|
|
23
|
-
private readonly ncu: Ncu
|
|
24
|
-
private readonly packageManager: PackageManager
|
|
25
|
-
private readonly pullRequestCreator: PullRequestCreator
|
|
26
|
-
private readonly remoteBranchExistenceChecker: RemoteBranchExistenceChecker
|
|
27
|
-
private readonly logger: Logger
|
|
28
|
-
private readonly branchNameCreator: BranchNameCreator
|
|
29
|
-
private readonly commitMessageCreator: CommitMessageCreator
|
|
30
|
-
|
|
31
|
-
constructor ({
|
|
32
|
-
committer,
|
|
33
|
-
git,
|
|
34
|
-
ncu,
|
|
35
|
-
packageManager,
|
|
36
|
-
pullRequestCreator,
|
|
37
|
-
remoteBranchExistenceChecker,
|
|
38
|
-
logger,
|
|
39
|
-
branchNameCreator,
|
|
40
|
-
commitMessageCreator
|
|
41
|
-
}: {
|
|
42
|
-
committer: Committer
|
|
43
|
-
git: Git
|
|
44
|
-
ncu: Ncu
|
|
45
|
-
packageManager: PackageManager
|
|
46
|
-
pullRequestCreator: PullRequestCreator
|
|
47
|
-
remoteBranchExistenceChecker: RemoteBranchExistenceChecker
|
|
48
|
-
logger: Logger
|
|
49
|
-
branchNameCreator: BranchNameCreator
|
|
50
|
-
commitMessageCreator: CommitMessageCreator
|
|
51
|
-
}) {
|
|
52
|
-
this.committer = committer
|
|
53
|
-
this.git = git
|
|
54
|
-
this.ncu = ncu
|
|
55
|
-
this.packageManager = packageManager
|
|
56
|
-
this.pullRequestCreator = pullRequestCreator
|
|
57
|
-
this.remoteBranchExistenceChecker = remoteBranchExistenceChecker
|
|
58
|
-
this.logger = logger
|
|
59
|
-
this.branchNameCreator = branchNameCreator
|
|
60
|
-
this.commitMessageCreator = commitMessageCreator
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Don't run in parallel because it includes file operations.
|
|
65
|
-
*/
|
|
66
|
-
async process (outdatedPackage: OutdatedPackage): Promise<Result> {
|
|
67
|
-
const branchName = this.branchNameCreator.create(outdatedPackage)
|
|
68
|
-
this.logger.debug(`branchName=${branchName}`)
|
|
69
|
-
|
|
70
|
-
if (this.remoteBranchExistenceChecker.check(branchName)) {
|
|
71
|
-
this.logger.info(`Skip ${outdatedPackage.name} because ${branchName} branch already exists on remote.`)
|
|
72
|
-
return {
|
|
73
|
-
outdatedPackage,
|
|
74
|
-
skipped: true
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
await this.git.createBranch(branchName)
|
|
79
|
-
this.logger.info(`${branchName} branch has created.`)
|
|
80
|
-
|
|
81
|
-
const updatedPackages = await this.ncu.update(outdatedPackage)
|
|
82
|
-
|
|
83
|
-
if (updatedPackages.length !== 1) {
|
|
84
|
-
throw new Error(`Failed to update ${outdatedPackage.name}.`)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
await this.packageManager.install()
|
|
88
|
-
this.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`)
|
|
89
|
-
|
|
90
|
-
await this.git.add(...this.packageManager.packageFiles)
|
|
91
|
-
const message = this.commitMessageCreator.create(outdatedPackage)
|
|
92
|
-
this.logger.debug(`message=${message}`)
|
|
93
|
-
|
|
94
|
-
await this.committer.commit(message)
|
|
95
|
-
await this.git.push(branchName)
|
|
96
|
-
await this.pullRequestCreator.create({
|
|
97
|
-
outdatedPackage,
|
|
98
|
-
branchName
|
|
99
|
-
})
|
|
100
|
-
await this.git.checkout('-')
|
|
101
|
-
await this.git.removeBranch(branchName)
|
|
102
|
-
this.logger.info(`${branchName} branch has removed.`)
|
|
103
|
-
|
|
104
|
-
return {
|
|
105
|
-
outdatedPackage,
|
|
106
|
-
updated: true
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { Logger } from '../logger'
|
|
2
|
-
import type { OutdatedPackage } from '../ncu'
|
|
3
|
-
import type { OutdatedPackageProcessor } from './OutdatedPackageProcessor'
|
|
4
|
-
import type { Result } from './Result'
|
|
5
|
-
|
|
6
|
-
export class OutdatedPackagesProcessor {
|
|
7
|
-
private readonly outdatedPackageProcessor: OutdatedPackageProcessor
|
|
8
|
-
private readonly logger: Logger
|
|
9
|
-
|
|
10
|
-
constructor ({
|
|
11
|
-
outdatedPackageProcessor,
|
|
12
|
-
logger
|
|
13
|
-
}: {
|
|
14
|
-
outdatedPackageProcessor: OutdatedPackageProcessor
|
|
15
|
-
logger: Logger
|
|
16
|
-
}) {
|
|
17
|
-
this.outdatedPackageProcessor = outdatedPackageProcessor
|
|
18
|
-
this.logger = logger
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async process (outdatedPackages: OutdatedPackage[]): Promise<Result[]> {
|
|
22
|
-
const results: Result[] = []
|
|
23
|
-
|
|
24
|
-
for (const outdatedPackage of outdatedPackages) {
|
|
25
|
-
this.logger.debug(`outdatedPackage=${JSON.stringify(outdatedPackage)}`)
|
|
26
|
-
const result = await this.outdatedPackageProcessor.process(outdatedPackage)
|
|
27
|
-
results.push(result)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return results
|
|
31
|
-
}
|
|
32
|
-
}
|
package/src/processors/Result.ts
DELETED
package/src/processors/index.ts
DELETED
package/src/terminal/Terminal.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import execa from 'execa'
|
|
2
|
-
import type { ExecaReturnValue } from 'execa'
|
|
3
|
-
import { isExecaReturnValue } from './isExecaReturnValue'
|
|
4
|
-
|
|
5
|
-
// TODO: add test
|
|
6
|
-
export class Terminal {
|
|
7
|
-
async run (
|
|
8
|
-
command: string,
|
|
9
|
-
...args: string[]
|
|
10
|
-
): Promise<ExecaReturnValue<string>> {
|
|
11
|
-
return await execa(command, args)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async runWithErrorHandling (
|
|
15
|
-
command: string,
|
|
16
|
-
...args: string[]
|
|
17
|
-
): Promise<ExecaReturnValue<string>> {
|
|
18
|
-
try {
|
|
19
|
-
return await this.run(command, ...args)
|
|
20
|
-
} catch (e) {
|
|
21
|
-
const value: unknown = e instanceof Error ? JSON.parse(JSON.stringify(e)) : e
|
|
22
|
-
|
|
23
|
-
if (isExecaReturnValue(value)) {
|
|
24
|
-
return value
|
|
25
|
-
} else {
|
|
26
|
-
throw e
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
package/src/terminal/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Terminal } from './Terminal'
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { ExecaReturnValue } from 'execa'
|
|
2
|
-
import {
|
|
3
|
-
boolean,
|
|
4
|
-
intersection,
|
|
5
|
-
number,
|
|
6
|
-
partial,
|
|
7
|
-
string,
|
|
8
|
-
type
|
|
9
|
-
} from 'io-ts'
|
|
10
|
-
|
|
11
|
-
const ExecaReturnValueType = intersection([
|
|
12
|
-
type({
|
|
13
|
-
command: string,
|
|
14
|
-
escapedCommand: string,
|
|
15
|
-
exitCode: number,
|
|
16
|
-
failed: boolean,
|
|
17
|
-
timedOut: boolean,
|
|
18
|
-
killed: boolean,
|
|
19
|
-
isCanceled: boolean
|
|
20
|
-
}),
|
|
21
|
-
partial({
|
|
22
|
-
signal: string,
|
|
23
|
-
signalDescription: string
|
|
24
|
-
})
|
|
25
|
-
])
|
|
26
|
-
|
|
27
|
-
// TODO: add test
|
|
28
|
-
export const isExecaReturnValue = (value: unknown): value is ExecaReturnValue => {
|
|
29
|
-
return ExecaReturnValueType.is(value)
|
|
30
|
-
}
|
package/tsconfig.base.json
DELETED
package/tsconfig.build.json
DELETED