npm-update-package 0.31.3 → 0.31.4

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 (105) hide show
  1. package/dist/package.json +4 -4
  2. package/package.json +4 -4
  3. package/.eslintignore +0 -3
  4. package/.eslintrc.js +0 -23
  5. package/.github/renovate.json +0 -15
  6. package/.github/workflows/eslint.yml +0 -14
  7. package/.github/workflows/test.yml +0 -20
  8. package/.husky/pre-commit +0 -4
  9. package/.nvmrc +0 -1
  10. package/jest.config.ts +0 -12
  11. package/lint-staged.config.js +0 -4
  12. package/npm-update-package.code-workspace +0 -10
  13. package/src/bin.ts +0 -22
  14. package/src/core/FailedResult.ts +0 -6
  15. package/src/core/OutdatedPackage.ts +0 -11
  16. package/src/core/OutdatedPackageProcessor.ts +0 -136
  17. package/src/core/OutdatedPackagesProcessor.ts +0 -35
  18. package/src/core/SucceededResult.ts +0 -7
  19. package/src/core/index.ts +0 -5
  20. package/src/file/index.ts +0 -1
  21. package/src/file/readFile.ts +0 -6
  22. package/src/git/CommitMessageCreator.test.ts +0 -17
  23. package/src/git/CommitMessageCreator.ts +0 -19
  24. package/src/git/Git.ts +0 -59
  25. package/src/git/GitRepository.test.ts +0 -82
  26. package/src/git/GitRepository.ts +0 -57
  27. package/src/git/createBranchName.test.ts +0 -14
  28. package/src/git/createBranchName.ts +0 -7
  29. package/src/git/index.ts +0 -4
  30. package/src/github/GitHub.ts +0 -198
  31. package/src/github/branch/finder/BranchFinder.test.ts +0 -21
  32. package/src/github/branch/finder/BranchFinder.ts +0 -9
  33. package/src/github/branch/finder/index.ts +0 -1
  34. package/src/github/branch/index.ts +0 -1
  35. package/src/github/createGitHub.test.ts +0 -16
  36. package/src/github/createGitHub.ts +0 -17
  37. package/src/github/createOctokit.test.ts +0 -27
  38. package/src/github/createOctokit.ts +0 -27
  39. package/src/github/errors/NotFoundError.ts +0 -11
  40. package/src/github/errors/index.ts +0 -1
  41. package/src/github/index.ts +0 -5
  42. package/src/github/label/creator/LabelCreator.ts +0 -71
  43. package/src/github/label/creator/index.ts +0 -1
  44. package/src/github/label/index.ts +0 -1
  45. package/src/github/pull-request/closer/PullRequestCloser.test.ts +0 -53
  46. package/src/github/pull-request/closer/PullRequestCloser.ts +0 -21
  47. package/src/github/pull-request/closer/index.ts +0 -1
  48. package/src/github/pull-request/creator/PullRequestCreator.test.ts +0 -98
  49. package/src/github/pull-request/creator/PullRequestCreator.ts +0 -84
  50. package/src/github/pull-request/creator/PullRequestTitleCreator.test.ts +0 -17
  51. package/src/github/pull-request/creator/PullRequestTitleCreator.ts +0 -19
  52. package/src/github/pull-request/creator/createPullRequestBody.test.ts +0 -47
  53. package/src/github/pull-request/creator/createPullRequestBody.ts +0 -35
  54. package/src/github/pull-request/creator/index.ts +0 -2
  55. package/src/github/pull-request/finder/PullRequestFinder.ts +0 -27
  56. package/src/github/pull-request/finder/index.ts +0 -1
  57. package/src/github/pull-request/finder/isPullRequestByNpmUpdatePackage.test.ts +0 -24
  58. package/src/github/pull-request/finder/isPullRequestByNpmUpdatePackage.ts +0 -5
  59. package/src/github/pull-request/index.ts +0 -3
  60. package/src/github/pull-request/metadata/PullRequestMetadata.ts +0 -22
  61. package/src/github/pull-request/metadata/createPullRequestMetadata.test.ts +0 -31
  62. package/src/github/pull-request/metadata/createPullRequestMetadata.ts +0 -21
  63. package/src/github/pull-request/metadata/extractPullRequestMetadata.test.ts +0 -53
  64. package/src/github/pull-request/metadata/extractPullRequestMetadata.ts +0 -21
  65. package/src/github/pull-request/metadata/index.ts +0 -3
  66. package/src/json/index.ts +0 -1
  67. package/src/json/toJSON.test.ts +0 -65
  68. package/src/json/toJSON.ts +0 -13
  69. package/src/logger/LogLevel.ts +0 -13
  70. package/src/logger/Logger.ts +0 -1
  71. package/src/logger/createLogger.ts +0 -10
  72. package/src/logger/index.ts +0 -3
  73. package/src/main.ts +0 -149
  74. package/src/ncu/Ncu.ts +0 -84
  75. package/src/ncu/NcuResult.ts +0 -10
  76. package/src/ncu/index.ts +0 -1
  77. package/src/options/CLIOption.ts +0 -19
  78. package/src/options/OptionType.ts +0 -8
  79. package/src/options/Options.ts +0 -40
  80. package/src/options/cliOptions.ts +0 -60
  81. package/src/options/index.ts +0 -2
  82. package/src/options/initOptions.ts +0 -24
  83. package/src/options/toCommanderOption.ts +0 -35
  84. package/src/package-json/PackageMetadata.ts +0 -24
  85. package/src/package-json/PackageMetadataDependencies.ts +0 -10
  86. package/src/package-json/index.ts +0 -2
  87. package/src/package-json/parsePackageJson.ts +0 -15
  88. package/src/package-manager/Npm.ts +0 -17
  89. package/src/package-manager/PackageManager.ts +0 -5
  90. package/src/package-manager/PackageManagerName.ts +0 -8
  91. package/src/package-manager/Yarn.ts +0 -17
  92. package/src/package-manager/createPackageManager.test.ts +0 -27
  93. package/src/package-manager/createPackageManager.ts +0 -20
  94. package/src/package-manager/index.ts +0 -5
  95. package/src/semver/SemVer.test.ts +0 -17
  96. package/src/semver/SemVer.ts +0 -40
  97. package/src/semver/SemVerLevel.ts +0 -9
  98. package/src/semver/compareSemVers.test.ts +0 -21
  99. package/src/semver/compareSemVers.ts +0 -16
  100. package/src/semver/index.ts +0 -3
  101. package/src/terminal/Terminal.ts +0 -12
  102. package/src/terminal/index.ts +0 -1
  103. package/tsconfig.base.json +0 -7
  104. package/tsconfig.build.json +0 -12
  105. package/tsconfig.json +0 -9
package/src/main.ts DELETED
@@ -1,149 +0,0 @@
1
- import {
2
- isLeft,
3
- isRight
4
- } from 'fp-ts/lib/Either'
5
- import {
6
- OutdatedPackageProcessor,
7
- OutdatedPackagesProcessor
8
- } from './core'
9
- import {
10
- CommitMessageCreator,
11
- Git
12
- } from './git'
13
- import {
14
- BranchFinder,
15
- createGitHub,
16
- LabelCreator,
17
- PullRequestCloser,
18
- PullRequestCreator,
19
- PullRequestFinder,
20
- PullRequestTitleCreator
21
- } from './github'
22
- import type { Logger } from './logger'
23
- import { Ncu } from './ncu'
24
- import type { Options } from './options'
25
- import { createPackageManager } from './package-manager'
26
- import { Terminal } from './terminal'
27
-
28
- // TODO: add test
29
- export const main = async ({
30
- options,
31
- logger
32
- }: {
33
- options: Options
34
- logger: Logger
35
- }): Promise<void> => {
36
- logger.debug(`options=${JSON.stringify({
37
- ...options,
38
- githubToken: options.githubToken !== '' ? '***' : ''
39
- })}`)
40
-
41
- const ncu = new Ncu(logger)
42
- const outdatedPackages = await ncu.check()
43
- logger.debug(`outdatedPackages=${JSON.stringify(outdatedPackages)}`)
44
-
45
- if (outdatedPackages.length === 0) {
46
- logger.info('All packages are up-to-date.')
47
- return
48
- }
49
-
50
- logger.info(`There are ${outdatedPackages.length} outdated packages.`)
51
-
52
- const terminal = new Terminal()
53
- const git = new Git(terminal)
54
- const gitRepo = await git.getRepository()
55
- logger.debug(`gitRepo=${JSON.stringify(gitRepo)}`)
56
-
57
- const github = createGitHub({
58
- repository: gitRepo,
59
- token: options.githubToken
60
- })
61
- const githubRepo = await github.fetchRepository({
62
- owner: gitRepo.owner,
63
- repo: gitRepo.name
64
- })
65
- logger.debug(`githubRepo=${JSON.stringify(githubRepo)}`)
66
-
67
- const branches = await github.fetchBranches({
68
- owner: gitRepo.owner,
69
- repo: gitRepo.name
70
- })
71
- logger.debug(`branches=${JSON.stringify(branches)}`)
72
-
73
- const pullRequests = await github.fetchPullRequests({
74
- owner: gitRepo.owner,
75
- repo: gitRepo.name
76
- })
77
- logger.debug(`pullRequests=${JSON.stringify(pullRequests)}`)
78
-
79
- const labelCreator = new LabelCreator({
80
- github,
81
- gitRepo,
82
- logger
83
- })
84
- await labelCreator.create({
85
- name: 'npm-update-package',
86
- description: 'Created by npm-update-package',
87
- color: 'A00F21'
88
- })
89
-
90
- const branchFinder = new BranchFinder(branches)
91
- const packageManager = createPackageManager({
92
- terminal,
93
- packageManager: options.packageManager
94
- })
95
- const pullRequestTitleCreator = new PullRequestTitleCreator(options.pullRequestTitle)
96
- const pullRequestCreator = new PullRequestCreator({
97
- github,
98
- gitRepo,
99
- githubRepo,
100
- pullRequestTitleCreator,
101
- logger,
102
- reviewers: options.reviewers
103
- })
104
- const commitMessageCreator = new CommitMessageCreator(options.commitMessage)
105
- const pullRequestFinder = new PullRequestFinder(pullRequests)
106
- const pullRequestCloser = new PullRequestCloser(github)
107
- const outdatedPackageProcessor = new OutdatedPackageProcessor({
108
- git,
109
- ncu,
110
- packageManager,
111
- pullRequestCreator,
112
- branchFinder,
113
- logger,
114
- commitMessageCreator,
115
- pullRequestFinder,
116
- pullRequestCloser
117
- })
118
- const outdatedPackagesProcessor = new OutdatedPackagesProcessor({
119
- outdatedPackageProcessor,
120
- logger
121
- })
122
- const results = await outdatedPackagesProcessor.process(outdatedPackages)
123
- logger.debug(`results=${JSON.stringify(results)}`)
124
-
125
- const succeededResults = results.filter(isRight).map(({ right }) => right)
126
- logger.debug(`succeededResults=${JSON.stringify(succeededResults)}`)
127
-
128
- const createdPackages = succeededResults
129
- .filter(({ created }) => created)
130
- .map(({ outdatedPackage }) => outdatedPackage)
131
- logger.debug(`createdPackages=${JSON.stringify(createdPackages)}`)
132
-
133
- const skippedPackages = succeededResults
134
- .filter(({ skipped }) => skipped)
135
- .map(({ outdatedPackage }) => outdatedPackage)
136
- logger.debug(`skippedPackages=${JSON.stringify(skippedPackages)}`)
137
-
138
- const failedResults = results.filter(isLeft).map(({ left }) => left)
139
- logger.debug(`failedResults=${JSON.stringify(failedResults)}`)
140
-
141
- const failedPackages = failedResults.map(({ outdatedPackage }) => outdatedPackage)
142
- logger.debug(`failedPackages=${JSON.stringify(failedPackages)}`)
143
-
144
- // TODO: show as table
145
- logger.info(`Processed ${succeededResults.length + failedPackages.length} packages:
146
- - ${createdPackages.length} packages: created (${createdPackages.map(({ name }) => name).join(',')})
147
- - ${skippedPackages.length} packages: skipped: (${skippedPackages.map(({ name }) => name).join(',')})
148
- - ${failedPackages.length} packages: failed: (${failedPackages.map(({ name }) => name).join(',')})`)
149
- }
package/src/ncu/Ncu.ts DELETED
@@ -1,84 +0,0 @@
1
- import { run } from 'npm-check-updates'
2
- import type { RunOptions } from 'npm-check-updates/build/src/types'
3
- import { isNotUndefined } from 'type-guards'
4
- import type { OutdatedPackage } from '../core'
5
- import { readFile } from '../file'
6
- import type { Logger } from '../logger'
7
- import { parsePackageJson } from '../package-json'
8
- import {
9
- compareSemVers,
10
- SemVer
11
- } from '../semver'
12
- import { isNcuResult } from './NcuResult'
13
-
14
- // TODO: add test
15
- export class Ncu {
16
- constructor (private readonly logger: Logger) {}
17
-
18
- async check (): Promise<OutdatedPackage[]> {
19
- return await this.run({
20
- jsonUpgraded: true
21
- })
22
- }
23
-
24
- async update (outdatedPackage: OutdatedPackage): Promise<OutdatedPackage[]> {
25
- return await this.run({
26
- jsonUpgraded: true,
27
- filter: outdatedPackage.name,
28
- upgrade: true
29
- })
30
- }
31
-
32
- private async run (options: RunOptions): Promise<OutdatedPackage[]> {
33
- // Read package.json before running ncu
34
- const json = await readFile('./package.json')
35
- const pkg = parsePackageJson(json)
36
- this.logger.debug(`pkg=${JSON.stringify(pkg)}`)
37
-
38
- const result = await run(options)
39
- this.logger.debug(`result=${JSON.stringify(result)}`)
40
-
41
- if (!isNcuResult(result)) {
42
- throw new Error('Failed to running ncu.')
43
- }
44
-
45
- const currentDependencies = {
46
- ...pkg.dependencies,
47
- ...pkg.devDependencies,
48
- ...pkg.peerDependencies,
49
- ...pkg.optionalDependencies
50
- }
51
- const resultEntries = Object.entries(result)
52
- const outdatedPackages: OutdatedPackage[] = resultEntries
53
- .map(([name, newVersionString]) => {
54
- const currentVersionString = currentDependencies[name]
55
-
56
- if (currentVersionString === undefined) {
57
- return undefined
58
- }
59
-
60
- const currentVersion = SemVer.of(currentVersionString)
61
- const newVersion = SemVer.of(newVersionString)
62
- const level = compareSemVers(currentVersion, newVersion)
63
-
64
- if (level === undefined) {
65
- return undefined
66
- }
67
-
68
- const outdatedPackage: OutdatedPackage = {
69
- name,
70
- currentVersion,
71
- newVersion,
72
- level
73
- }
74
- return outdatedPackage
75
- })
76
- .filter(isNotUndefined)
77
-
78
- if (resultEntries.length !== outdatedPackages.length) {
79
- throw new Error('Failed to running ncu.')
80
- }
81
-
82
- return outdatedPackages
83
- }
84
- }
@@ -1,10 +0,0 @@
1
- import {
2
- record,
3
- string,
4
- type TypeOf
5
- } from 'io-ts'
6
-
7
- export const NcuResult = record(string, string)
8
- // eslint-disable-next-line @typescript-eslint/no-redeclare
9
- export type NcuResult = TypeOf<typeof NcuResult>
10
- export const isNcuResult = NcuResult.is
package/src/ncu/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './Ncu'
@@ -1,19 +0,0 @@
1
- import type { OptionType } from './OptionType'
2
-
3
- interface OptionBase {
4
- name: string
5
- description: string
6
- type: OptionType
7
- choices?: string[]
8
- }
9
-
10
- interface RequiredOption extends OptionBase {
11
- required: true
12
- }
13
-
14
- interface OptionalOption extends OptionBase {
15
- required: false
16
- default?: string
17
- }
18
-
19
- export type CLIOption = RequiredOption | OptionalOption
@@ -1,8 +0,0 @@
1
- export const OptionType = {
2
- String: 'string',
3
- StringArray: 'string[]'
4
- } as const
5
- // eslint-disable-next-line @typescript-eslint/no-redeclare
6
- export type OptionType = typeof OptionType[keyof typeof OptionType]
7
- const optionTypes = Object.values(OptionType)
8
- export const isOptionType = (value: any): value is OptionType => optionTypes.includes(value)
@@ -1,40 +0,0 @@
1
- import {
2
- array,
3
- intersection,
4
- literal,
5
- partial,
6
- string,
7
- type,
8
- union,
9
- type TypeOf
10
- } from 'io-ts'
11
- import { LogLevel } from '../logger'
12
- import { PackageManagerName } from '../package-manager'
13
-
14
- const Options = intersection([
15
- type({
16
- commitMessage: string,
17
- githubToken: string,
18
- logLevel: union([
19
- literal(LogLevel.Off),
20
- literal(LogLevel.Fatal),
21
- literal(LogLevel.Error),
22
- literal(LogLevel.Warn),
23
- literal(LogLevel.Info),
24
- literal(LogLevel.Debug),
25
- literal(LogLevel.Trace)
26
- ]),
27
- packageManager: union([
28
- literal(PackageManagerName.Npm),
29
- literal(PackageManagerName.Yarn)
30
- ]),
31
- pullRequestTitle: string
32
- }),
33
- partial({
34
- reviewers: array(string)
35
- })
36
- ])
37
-
38
- // eslint-disable-next-line @typescript-eslint/no-redeclare
39
- export type Options = TypeOf<typeof Options>
40
- export const isOptions = Options.is
@@ -1,60 +0,0 @@
1
- import { LogLevel } from '../logger'
2
- import { PackageManagerName } from '../package-manager'
3
- import type { CLIOption } from './CLIOption'
4
- import { OptionType } from './OptionType'
5
-
6
- export const cliOptions: CLIOption[] = [
7
- {
8
- name: 'commit-message',
9
- description: 'Commit message template',
10
- type: OptionType.String,
11
- required: false,
12
- default: 'chore(deps): {{level}} update {{{packageName}}} to v{{newVersion}}'
13
- },
14
- {
15
- name: 'github-token',
16
- description: 'GitHub token',
17
- type: OptionType.String,
18
- required: true
19
- },
20
- {
21
- name: 'log-level',
22
- description: 'Log level to show',
23
- type: OptionType.String,
24
- required: false,
25
- choices: [
26
- LogLevel.Off,
27
- LogLevel.Fatal,
28
- LogLevel.Error,
29
- LogLevel.Warn,
30
- LogLevel.Info,
31
- LogLevel.Debug,
32
- LogLevel.Trace
33
- ],
34
- default: LogLevel.Info
35
- },
36
- {
37
- name: 'package-manager',
38
- description: 'Package manager of your project',
39
- type: OptionType.String,
40
- required: false,
41
- choices: [
42
- PackageManagerName.Npm,
43
- PackageManagerName.Yarn
44
- ],
45
- default: PackageManagerName.Npm
46
- },
47
- {
48
- name: 'pull-request-title',
49
- description: 'Pull request title template',
50
- type: OptionType.String,
51
- required: false,
52
- default: 'chore(deps): {{level}} update {{{packageName}}} to v{{newVersion}}'
53
- },
54
- {
55
- name: 'reviewers',
56
- description: 'User names to request reviews',
57
- type: OptionType.StringArray,
58
- required: false
59
- }
60
- ]
@@ -1,2 +0,0 @@
1
- export * from './initOptions'
2
- export * from './Options'
@@ -1,24 +0,0 @@
1
- import { program } from 'commander'
2
- import pkg from '../../package.json'
3
- import { cliOptions } from './cliOptions'
4
- import {
5
- isOptions,
6
- type Options
7
- } from './Options'
8
- import { toCommanderOption } from './toCommanderOption'
9
-
10
- // TODO: add test
11
- export const initOptions = (): Options => {
12
- program.version(pkg.version)
13
- cliOptions
14
- .map(toCommanderOption)
15
- .forEach(option => program.addOption(option))
16
- program.parse(process.argv)
17
- const options = program.opts()
18
-
19
- if (!isOptions(options)) {
20
- throw new Error(`Failed to parse command-line options. options=${JSON.stringify(options)}`)
21
- }
22
-
23
- return options
24
- }
@@ -1,35 +0,0 @@
1
- import { Option } from 'commander'
2
- import type { CLIOption } from './CLIOption'
3
- import { OptionType } from './OptionType'
4
-
5
- // TODO: add test
6
- export const toCommanderOption = (cliOption: CLIOption): Option => {
7
- const argument = createArgumentString(cliOption)
8
- const option = new Option(`--${cliOption.name} ${argument}`, cliOption.description)
9
-
10
- if (cliOption.choices !== undefined) {
11
- option.choices(cliOption.choices)
12
- }
13
-
14
- if (!cliOption.required && cliOption.default !== undefined) {
15
- option.default(cliOption.default)
16
- }
17
-
18
- return option
19
- }
20
-
21
- const createArgumentString = (cliOption: CLIOption): string => {
22
- const prefix = cliOption.required ? '<' : '['
23
- const suffix = cliOption.required ? '>' : ']'
24
- const name = createArgumentNameString(cliOption.type)
25
- return `${prefix}${name}${suffix}`
26
- }
27
-
28
- const createArgumentNameString = (optionType: OptionType): string => {
29
- switch (optionType) {
30
- case OptionType.String:
31
- return 'value'
32
- case OptionType.StringArray:
33
- return 'values...'
34
- }
35
- }
@@ -1,24 +0,0 @@
1
- import {
2
- intersection,
3
- partial,
4
- string,
5
- type,
6
- type TypeOf
7
- } from 'io-ts'
8
- import { PackageMetadataDependencies } from './PackageMetadataDependencies'
9
-
10
- const PackageMetadata = intersection([
11
- type({
12
- name: string,
13
- version: string
14
- }),
15
- partial({
16
- dependencies: PackageMetadataDependencies,
17
- devDependencies: PackageMetadataDependencies,
18
- peerDependencies: PackageMetadataDependencies,
19
- optionalDependencies: PackageMetadataDependencies
20
- })
21
- ])
22
- // eslint-disable-next-line @typescript-eslint/no-redeclare
23
- export type PackageMetadata = TypeOf<typeof PackageMetadata>
24
- export const isPackageMetadata = PackageMetadata.is
@@ -1,10 +0,0 @@
1
- import {
2
- record,
3
- string,
4
- type TypeOf
5
- } from 'io-ts'
6
-
7
- export const PackageMetadataDependencies = record(string, string)
8
- // eslint-disable-next-line @typescript-eslint/no-redeclare
9
- export type PackageMetadataDependencies = TypeOf<typeof PackageMetadataDependencies>
10
- export const isPackageMetadataDependencies = PackageMetadataDependencies.is
@@ -1,2 +0,0 @@
1
- export * from './PackageMetadata'
2
- export * from './parsePackageJson'
@@ -1,15 +0,0 @@
1
- import {
2
- isPackageMetadata,
3
- type PackageMetadata
4
- } from './PackageMetadata'
5
-
6
- // TODO: add test
7
- export const parsePackageJson = (json: string): PackageMetadata => {
8
- const parsed: unknown = JSON.parse(json)
9
-
10
- if (isPackageMetadata(parsed)) {
11
- return parsed
12
- } else {
13
- throw new Error(`Failed to parse package.json. json=${json}`)
14
- }
15
- }
@@ -1,17 +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 packageFile = 'package.json'
7
- readonly lockFile = 'package-lock.json'
8
-
9
- constructor (private readonly terminal: Terminal) {}
10
-
11
- /**
12
- * @see https://docs.npmjs.com/cli/v8/commands/npm-install
13
- */
14
- async install (): Promise<void> {
15
- await this.terminal.run('npm', 'install')
16
- }
17
- }
@@ -1,5 +0,0 @@
1
- export interface PackageManager {
2
- packageFile: string
3
- lockFile: string
4
- install: () => Promise<void>
5
- }
@@ -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,17 +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 packageFile = 'package.json'
7
- readonly lockFile = 'yarn.lock'
8
-
9
- constructor (private readonly terminal: Terminal) {}
10
-
11
- /**
12
- * @see https://classic.yarnpkg.com/en/docs/cli/install
13
- */
14
- async install (): Promise<void> {
15
- await this.terminal.run('yarn', 'install')
16
- }
17
- }
@@ -1,27 +0,0 @@
1
- import { Terminal } from '../terminal'
2
- import { createPackageManager } from './createPackageManager'
3
- import { Npm } from './Npm'
4
- import { PackageManagerName } from './PackageManagerName'
5
- import { Yarn } from './Yarn'
6
-
7
- describe('createPackageManager', () => {
8
- const terminal = new Terminal()
9
-
10
- it(`returns new Npm instance if packageManager is ${PackageManagerName.Npm}`, () => {
11
- const packageManager = createPackageManager({
12
- terminal,
13
- packageManager: PackageManagerName.Npm
14
- })
15
-
16
- expect(packageManager).toBeInstanceOf(Npm)
17
- })
18
-
19
- it(`returns new Yarn instance if packageManager is ${PackageManagerName.Yarn}`, () => {
20
- const packageManager = createPackageManager({
21
- terminal,
22
- packageManager: PackageManagerName.Yarn
23
- })
24
-
25
- expect(packageManager).toBeInstanceOf(Yarn)
26
- })
27
- })
@@ -1,20 +0,0 @@
1
- import type { Terminal } from '../terminal'
2
- import { Npm } from './Npm'
3
- import type { PackageManager } from './PackageManager'
4
- import { PackageManagerName } from './PackageManagerName'
5
- import { Yarn } from './Yarn'
6
-
7
- export const createPackageManager = ({
8
- terminal,
9
- packageManager
10
- }: {
11
- terminal: Terminal
12
- packageManager: PackageManagerName
13
- }): PackageManager => {
14
- switch (packageManager) {
15
- case PackageManagerName.Npm:
16
- return new Npm(terminal)
17
- case PackageManagerName.Yarn:
18
- return new Yarn(terminal)
19
- }
20
- }
@@ -1,5 +0,0 @@
1
- export * from './createPackageManager'
2
- export * from './Npm'
3
- export * from './PackageManager'
4
- export * from './PackageManagerName'
5
- export * from './Yarn'
@@ -1,17 +0,0 @@
1
- import { SemVer } from './SemVer'
2
-
3
- describe('SemVer', () => {
4
- describe('of', () => {
5
- it('returns new SemVer instance if version is valid', () => {
6
- const semver = SemVer.of('^1.2.3')
7
- expect(semver.version).toBe('1.2.3')
8
- expect(semver.major).toBe(1)
9
- expect(semver.minor).toBe(2)
10
- expect(semver.patch).toBe(3)
11
- })
12
-
13
- it('throws error if version is invalid', () => {
14
- expect(() => SemVer.of('')).toThrow(Error)
15
- })
16
- })
17
- })
@@ -1,40 +0,0 @@
1
- import { coerce } from 'semver'
2
-
3
- export class SemVer {
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): SemVer {
27
- const semver = coerce(version)
28
-
29
- if (semver === null) {
30
- throw new Error(`Failed to parse version. version=${version}`)
31
- }
32
-
33
- return new SemVer({
34
- version: semver.version,
35
- major: semver.major,
36
- minor: semver.minor,
37
- patch: semver.patch
38
- })
39
- }
40
- }
@@ -1,9 +0,0 @@
1
- export const SemVerLevel = {
2
- Major: 'major',
3
- Minor: 'minor',
4
- Patch: 'patch'
5
- } as const
6
- // eslint-disable-next-line @typescript-eslint/no-redeclare
7
- export type SemVerLevel = typeof SemVerLevel[keyof typeof SemVerLevel]
8
- const semVerLevels = Object.values(SemVerLevel)
9
- export const isSemVerLevel = (value: any): value is SemVerLevel => semVerLevels.includes(value)