npm-update-package 0.1.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/.eslintignore +3 -0
- package/.eslintrc.js +23 -0
- package/.github/renovate.json +15 -0
- package/.github/workflows/eslint.yml +14 -0
- package/.github/workflows/test.yml +19 -0
- package/.husky/pre-commit +4 -0
- package/.nvmrc +1 -0
- package/LICENSE +22 -0
- package/README.md +43 -0
- package/dist/app.js +8 -0
- package/dist/bin.js +18 -0
- package/dist/enums/LogLevel.js +10 -0
- package/dist/enums/PackageManagerName.js +10 -0
- package/dist/enums/UpdateType.js +11 -0
- package/dist/enums/index.js +12 -0
- package/dist/git/Committer.js +31 -0
- package/dist/git/Git.js +48 -0
- package/dist/git/GitRepository.js +41 -0
- package/dist/git/index.js +7 -0
- package/dist/github/Branch.js +2 -0
- package/dist/github/GitHub.js +22 -0
- package/dist/github/PullRequest.js +2 -0
- package/dist/github/PullRequestCreator.js +31 -0
- package/dist/github/RemoteBranchExistenceChecker.js +17 -0
- package/dist/github/Repository.js +2 -0
- package/dist/github/createGitHub.js +14 -0
- package/dist/github/createOctokit.js +24 -0
- package/dist/github/createPullRequestBody.js +19 -0
- package/dist/github/createPullRequestTitle.js +10 -0
- package/dist/github/index.js +11 -0
- package/dist/logger/Logger.js +2 -0
- package/dist/logger/createLogger.js +11 -0
- package/dist/logger/index.js +5 -0
- package/dist/main.js +83 -0
- package/dist/ncu/Ncu.js +38 -0
- package/dist/ncu/NcuOutdatedPackages.js +2 -0
- package/dist/ncu/NcuOutdatedPackagesConverter.js +26 -0
- package/dist/ncu/index.js +5 -0
- package/dist/ncu/isNcuOutdatedPackages.js +8 -0
- package/dist/ncu/toUpdateType.js +17 -0
- package/dist/options/Options.js +16 -0
- package/dist/options/index.js +5 -0
- package/dist/options/initOptions.js +27 -0
- package/dist/outdated-package-processor/OutdatedPackageProcessor.js +56 -0
- package/dist/outdated-package-processor/createBranchName.js +9 -0
- package/dist/outdated-package-processor/createCommitMessage.js +10 -0
- package/dist/outdated-package-processor/index.js +5 -0
- package/dist/outdated-packages-processor/OutdatedPackagesProcessor.js +19 -0
- package/dist/outdated-packages-processor/index.js +5 -0
- package/dist/package-manager/Npm.js +20 -0
- package/dist/package-manager/PackageManager.js +2 -0
- package/dist/package-manager/Yarn.js +20 -0
- package/dist/package-manager/createPackageManager.js +15 -0
- package/dist/package-manager/index.js +9 -0
- package/dist/read-package-json/Package.js +18 -0
- package/dist/read-package-json/PackageDependencies.js +6 -0
- package/dist/read-package-json/index.js +5 -0
- package/dist/read-package-json/parsePackageJson.js +15 -0
- package/dist/read-package-json/readFile.js +12 -0
- package/dist/read-package-json/readPackageJson.js +11 -0
- package/dist/terminal/Terminal.js +29 -0
- package/dist/terminal/index.js +5 -0
- package/dist/terminal/isExecaReturnValue.js +24 -0
- package/dist/types/OutdatedPackage.js +2 -0
- package/dist/types/Result.js +2 -0
- package/dist/types/index.js +2 -0
- package/dist/values/PackageVersion.js +25 -0
- package/dist/values/index.js +5 -0
- package/jest.config.ts +11 -0
- package/lint-staged.config.js +4 -0
- package/package.json +59 -0
- package/src/app.ts +5 -0
- package/src/bin.ts +19 -0
- package/src/enums/LogLevel.ts +8 -0
- package/src/enums/PackageManagerName.ts +8 -0
- package/src/enums/UpdateType.ts +9 -0
- package/src/enums/index.ts +12 -0
- package/src/git/Committer.ts +49 -0
- package/src/git/Git.ts +55 -0
- package/src/git/GitRepository.test.ts +61 -0
- package/src/git/GitRepository.ts +57 -0
- package/src/git/index.ts +3 -0
- package/src/github/Branch.ts +4 -0
- package/src/github/GitHub.ts +27 -0
- package/src/github/PullRequest.ts +3 -0
- package/src/github/PullRequestCreator.ts +57 -0
- package/src/github/RemoteBranchExistenceChecker.ts +15 -0
- package/src/github/Repository.ts +3 -0
- package/src/github/createGitHub.ts +18 -0
- package/src/github/createOctokit.ts +28 -0
- package/src/github/createPullRequestBody.test.ts +62 -0
- package/src/github/createPullRequestBody.ts +17 -0
- package/src/github/createPullRequestTitle.test.ts +43 -0
- package/src/github/createPullRequestTitle.ts +8 -0
- package/src/github/index.ts +7 -0
- package/src/logger/Logger.ts +1 -0
- package/src/logger/createLogger.ts +10 -0
- package/src/logger/index.ts +2 -0
- package/src/main.ts +105 -0
- package/src/ncu/Ncu.ts +41 -0
- package/src/ncu/NcuOutdatedPackages.ts +6 -0
- package/src/ncu/NcuOutdatedPackagesConverter.ts +25 -0
- package/src/ncu/index.ts +1 -0
- package/src/ncu/isNcuOutdatedPackages.ts +6 -0
- package/src/ncu/toUpdateType.test.ts +21 -0
- package/src/ncu/toUpdateType.ts +18 -0
- package/src/options/Options.ts +24 -0
- package/src/options/index.ts +2 -0
- package/src/options/initOptions.ts +34 -0
- package/src/outdated-package-processor/OutdatedPackageProcessor.ts +101 -0
- package/src/outdated-package-processor/createBranchName.test.ts +14 -0
- package/src/outdated-package-processor/createBranchName.ts +7 -0
- package/src/outdated-package-processor/createCommitMessage.test.ts +43 -0
- package/src/outdated-package-processor/createCommitMessage.ts +8 -0
- package/src/outdated-package-processor/index.ts +1 -0
- package/src/outdated-packages-processor/OutdatedPackagesProcessor.ts +34 -0
- package/src/outdated-packages-processor/index.ts +1 -0
- package/src/package-manager/Npm.ts +19 -0
- package/src/package-manager/PackageManager.ts +4 -0
- package/src/package-manager/Yarn.ts +19 -0
- package/src/package-manager/createPackageManager.ts +21 -0
- package/src/package-manager/index.ts +4 -0
- package/src/read-package-json/Package.ts +24 -0
- package/src/read-package-json/PackageDependencies.ts +10 -0
- package/src/read-package-json/index.ts +2 -0
- package/src/read-package-json/parsePackageJson.ts +13 -0
- package/src/read-package-json/readFile.ts +6 -0
- package/src/read-package-json/readPackageJson.ts +9 -0
- package/src/terminal/Terminal.ts +30 -0
- package/src/terminal/index.ts +1 -0
- package/src/terminal/isExecaReturnValue.ts +30 -0
- package/src/types/OutdatedPackage.ts +9 -0
- package/src/types/Result.ts +7 -0
- package/src/types/index.ts +2 -0
- package/src/values/PackageVersion.test.ts +25 -0
- package/src/values/PackageVersion.ts +40 -0
- package/src/values/index.ts +1 -0
- package/tsconfig.base.json +3 -0
- package/tsconfig.build.json +13 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Terminal } from './Terminal'
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { PackageVersion } from './PackageVersion'
|
|
2
|
+
|
|
3
|
+
describe('PackageVersion', () => {
|
|
4
|
+
describe('of', () => {
|
|
5
|
+
describe('if version is valid', () => {
|
|
6
|
+
const version = '^1.2.3'
|
|
7
|
+
|
|
8
|
+
it('returns new PackageVersion instance', () => {
|
|
9
|
+
const packageVersion = PackageVersion.of(version)
|
|
10
|
+
expect(packageVersion.version).toBe('1.2.3')
|
|
11
|
+
expect(packageVersion.major).toBe(1)
|
|
12
|
+
expect(packageVersion.minor).toBe(2)
|
|
13
|
+
expect(packageVersion.patch).toBe(3)
|
|
14
|
+
})
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
describe('if version is invalid', () => {
|
|
18
|
+
const version = ''
|
|
19
|
+
|
|
20
|
+
it('throws error', () => {
|
|
21
|
+
expect(() => PackageVersion.of(version)).toThrow(Error)
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
})
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { coerce } from 'semver'
|
|
2
|
+
|
|
3
|
+
export class PackageVersion {
|
|
4
|
+
readonly version: string
|
|
5
|
+
readonly major: number
|
|
6
|
+
readonly minor: number
|
|
7
|
+
readonly patch: number
|
|
8
|
+
|
|
9
|
+
private constructor ({
|
|
10
|
+
version,
|
|
11
|
+
major,
|
|
12
|
+
minor,
|
|
13
|
+
patch
|
|
14
|
+
}: {
|
|
15
|
+
version: string
|
|
16
|
+
major: number
|
|
17
|
+
minor: number
|
|
18
|
+
patch: number
|
|
19
|
+
}) {
|
|
20
|
+
this.version = version
|
|
21
|
+
this.major = major
|
|
22
|
+
this.minor = minor
|
|
23
|
+
this.patch = patch
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static of (version: string): PackageVersion {
|
|
27
|
+
const semver = coerce(version)
|
|
28
|
+
|
|
29
|
+
if (semver === null) {
|
|
30
|
+
throw new Error(`Failed to parse package version. version=${version}`)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return new PackageVersion({
|
|
34
|
+
version: semver.version,
|
|
35
|
+
major: semver.major,
|
|
36
|
+
minor: semver.minor,
|
|
37
|
+
patch: semver.patch
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PackageVersion } from './PackageVersion'
|