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.
Files changed (140) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc.js +23 -0
  3. package/.github/renovate.json +15 -0
  4. package/.github/workflows/eslint.yml +14 -0
  5. package/.github/workflows/test.yml +19 -0
  6. package/.husky/pre-commit +4 -0
  7. package/.nvmrc +1 -0
  8. package/LICENSE +22 -0
  9. package/README.md +43 -0
  10. package/dist/app.js +8 -0
  11. package/dist/bin.js +18 -0
  12. package/dist/enums/LogLevel.js +10 -0
  13. package/dist/enums/PackageManagerName.js +10 -0
  14. package/dist/enums/UpdateType.js +11 -0
  15. package/dist/enums/index.js +12 -0
  16. package/dist/git/Committer.js +31 -0
  17. package/dist/git/Git.js +48 -0
  18. package/dist/git/GitRepository.js +41 -0
  19. package/dist/git/index.js +7 -0
  20. package/dist/github/Branch.js +2 -0
  21. package/dist/github/GitHub.js +22 -0
  22. package/dist/github/PullRequest.js +2 -0
  23. package/dist/github/PullRequestCreator.js +31 -0
  24. package/dist/github/RemoteBranchExistenceChecker.js +17 -0
  25. package/dist/github/Repository.js +2 -0
  26. package/dist/github/createGitHub.js +14 -0
  27. package/dist/github/createOctokit.js +24 -0
  28. package/dist/github/createPullRequestBody.js +19 -0
  29. package/dist/github/createPullRequestTitle.js +10 -0
  30. package/dist/github/index.js +11 -0
  31. package/dist/logger/Logger.js +2 -0
  32. package/dist/logger/createLogger.js +11 -0
  33. package/dist/logger/index.js +5 -0
  34. package/dist/main.js +83 -0
  35. package/dist/ncu/Ncu.js +38 -0
  36. package/dist/ncu/NcuOutdatedPackages.js +2 -0
  37. package/dist/ncu/NcuOutdatedPackagesConverter.js +26 -0
  38. package/dist/ncu/index.js +5 -0
  39. package/dist/ncu/isNcuOutdatedPackages.js +8 -0
  40. package/dist/ncu/toUpdateType.js +17 -0
  41. package/dist/options/Options.js +16 -0
  42. package/dist/options/index.js +5 -0
  43. package/dist/options/initOptions.js +27 -0
  44. package/dist/outdated-package-processor/OutdatedPackageProcessor.js +56 -0
  45. package/dist/outdated-package-processor/createBranchName.js +9 -0
  46. package/dist/outdated-package-processor/createCommitMessage.js +10 -0
  47. package/dist/outdated-package-processor/index.js +5 -0
  48. package/dist/outdated-packages-processor/OutdatedPackagesProcessor.js +19 -0
  49. package/dist/outdated-packages-processor/index.js +5 -0
  50. package/dist/package-manager/Npm.js +20 -0
  51. package/dist/package-manager/PackageManager.js +2 -0
  52. package/dist/package-manager/Yarn.js +20 -0
  53. package/dist/package-manager/createPackageManager.js +15 -0
  54. package/dist/package-manager/index.js +9 -0
  55. package/dist/read-package-json/Package.js +18 -0
  56. package/dist/read-package-json/PackageDependencies.js +6 -0
  57. package/dist/read-package-json/index.js +5 -0
  58. package/dist/read-package-json/parsePackageJson.js +15 -0
  59. package/dist/read-package-json/readFile.js +12 -0
  60. package/dist/read-package-json/readPackageJson.js +11 -0
  61. package/dist/terminal/Terminal.js +29 -0
  62. package/dist/terminal/index.js +5 -0
  63. package/dist/terminal/isExecaReturnValue.js +24 -0
  64. package/dist/types/OutdatedPackage.js +2 -0
  65. package/dist/types/Result.js +2 -0
  66. package/dist/types/index.js +2 -0
  67. package/dist/values/PackageVersion.js +25 -0
  68. package/dist/values/index.js +5 -0
  69. package/jest.config.ts +11 -0
  70. package/lint-staged.config.js +4 -0
  71. package/package.json +59 -0
  72. package/src/app.ts +5 -0
  73. package/src/bin.ts +19 -0
  74. package/src/enums/LogLevel.ts +8 -0
  75. package/src/enums/PackageManagerName.ts +8 -0
  76. package/src/enums/UpdateType.ts +9 -0
  77. package/src/enums/index.ts +12 -0
  78. package/src/git/Committer.ts +49 -0
  79. package/src/git/Git.ts +55 -0
  80. package/src/git/GitRepository.test.ts +61 -0
  81. package/src/git/GitRepository.ts +57 -0
  82. package/src/git/index.ts +3 -0
  83. package/src/github/Branch.ts +4 -0
  84. package/src/github/GitHub.ts +27 -0
  85. package/src/github/PullRequest.ts +3 -0
  86. package/src/github/PullRequestCreator.ts +57 -0
  87. package/src/github/RemoteBranchExistenceChecker.ts +15 -0
  88. package/src/github/Repository.ts +3 -0
  89. package/src/github/createGitHub.ts +18 -0
  90. package/src/github/createOctokit.ts +28 -0
  91. package/src/github/createPullRequestBody.test.ts +62 -0
  92. package/src/github/createPullRequestBody.ts +17 -0
  93. package/src/github/createPullRequestTitle.test.ts +43 -0
  94. package/src/github/createPullRequestTitle.ts +8 -0
  95. package/src/github/index.ts +7 -0
  96. package/src/logger/Logger.ts +1 -0
  97. package/src/logger/createLogger.ts +10 -0
  98. package/src/logger/index.ts +2 -0
  99. package/src/main.ts +105 -0
  100. package/src/ncu/Ncu.ts +41 -0
  101. package/src/ncu/NcuOutdatedPackages.ts +6 -0
  102. package/src/ncu/NcuOutdatedPackagesConverter.ts +25 -0
  103. package/src/ncu/index.ts +1 -0
  104. package/src/ncu/isNcuOutdatedPackages.ts +6 -0
  105. package/src/ncu/toUpdateType.test.ts +21 -0
  106. package/src/ncu/toUpdateType.ts +18 -0
  107. package/src/options/Options.ts +24 -0
  108. package/src/options/index.ts +2 -0
  109. package/src/options/initOptions.ts +34 -0
  110. package/src/outdated-package-processor/OutdatedPackageProcessor.ts +101 -0
  111. package/src/outdated-package-processor/createBranchName.test.ts +14 -0
  112. package/src/outdated-package-processor/createBranchName.ts +7 -0
  113. package/src/outdated-package-processor/createCommitMessage.test.ts +43 -0
  114. package/src/outdated-package-processor/createCommitMessage.ts +8 -0
  115. package/src/outdated-package-processor/index.ts +1 -0
  116. package/src/outdated-packages-processor/OutdatedPackagesProcessor.ts +34 -0
  117. package/src/outdated-packages-processor/index.ts +1 -0
  118. package/src/package-manager/Npm.ts +19 -0
  119. package/src/package-manager/PackageManager.ts +4 -0
  120. package/src/package-manager/Yarn.ts +19 -0
  121. package/src/package-manager/createPackageManager.ts +21 -0
  122. package/src/package-manager/index.ts +4 -0
  123. package/src/read-package-json/Package.ts +24 -0
  124. package/src/read-package-json/PackageDependencies.ts +10 -0
  125. package/src/read-package-json/index.ts +2 -0
  126. package/src/read-package-json/parsePackageJson.ts +13 -0
  127. package/src/read-package-json/readFile.ts +6 -0
  128. package/src/read-package-json/readPackageJson.ts +9 -0
  129. package/src/terminal/Terminal.ts +30 -0
  130. package/src/terminal/index.ts +1 -0
  131. package/src/terminal/isExecaReturnValue.ts +30 -0
  132. package/src/types/OutdatedPackage.ts +9 -0
  133. package/src/types/Result.ts +7 -0
  134. package/src/types/index.ts +2 -0
  135. package/src/values/PackageVersion.test.ts +25 -0
  136. package/src/values/PackageVersion.ts +40 -0
  137. package/src/values/index.ts +1 -0
  138. package/tsconfig.base.json +3 -0
  139. package/tsconfig.build.json +13 -0
  140. 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,9 @@
1
+ import type { UpdateType } from '../enums/UpdateType'
2
+ import type { PackageVersion } from '../values'
3
+
4
+ export interface OutdatedPackage {
5
+ name: string
6
+ currentVersion: PackageVersion
7
+ newVersion: PackageVersion
8
+ type: UpdateType
9
+ }
@@ -0,0 +1,7 @@
1
+ import type { OutdatedPackage } from './OutdatedPackage'
2
+
3
+ export interface Result {
4
+ outdatedPackage: OutdatedPackage
5
+ updated?: boolean
6
+ skipped?: boolean
7
+ }
@@ -0,0 +1,2 @@
1
+ export type { OutdatedPackage } from './OutdatedPackage'
2
+ export type { Result } from './Result'
@@ -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'
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "@tsconfig/node12/tsconfig.json"
3
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "./tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "rootDir": "src"
6
+ },
7
+ "include": [
8
+ "src/**/*.ts"
9
+ ],
10
+ "exclude": [
11
+ "**/*.test.ts"
12
+ ]
13
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "types": [
5
+ "node",
6
+ "jest"
7
+ ]
8
+ }
9
+ }