-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlockfileTypes.ts
113 lines (91 loc) · 2.44 KB
/
lockfileTypes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import * as path from 'path'
/**
* Supported lockfile types
*/
export enum LockfileType {
GEMFILE_LOCK = 'gemfile-lock',
YARN_LOCK = 'yarn-lock',
PACKAGE_LOCK = 'package-lock',
COMPOSER_LOCK = 'composer-lock',
CARGO_LOCK = 'cargo-lock',
POETRY_LOCK = 'poetry-lock',
PIPFILE_LOCK = 'pipfile-lock',
GRADLE_LOCK = 'gradle-lock',
SBT_LOCK = 'sbt-lock',
MAVEN_LOCK = 'maven-lock',
NUGET_LOCK = 'nuget-lock',
PODFILE_LOCK = 'podfile-lock',
COCOAPODS_LOCK = 'cocoapods-lock',
MIX_LOCK = 'mix-lock',
CARTHAGE_RESOLVED = 'carthage-resolved',
SWIFT_RESOLVED = 'swift-resolved',
GO_SUM = 'go-sum',
GO_MOD = 'go-mod',
PNPM_LOCK = 'pnpm-lock',
}
/**
* Detect the lockfile type based on the file path
* @param filePath Path to the lockfile
* @returns The detected lockfile type or undefined if not detected
*/
export function detectLockfileType(filePath: string): LockfileType | undefined {
const fileName = path.basename(filePath).toLowerCase()
if (fileName === 'gemfile.lock') {
return LockfileType.GEMFILE_LOCK
}
if (fileName === 'yarn.lock') {
return LockfileType.YARN_LOCK
}
if (fileName === 'package-lock.json') {
return LockfileType.PACKAGE_LOCK
}
if (fileName === 'composer.lock') {
return LockfileType.COMPOSER_LOCK
}
if (fileName === 'cargo.lock') {
return LockfileType.CARGO_LOCK
}
if (fileName === 'poetry.lock') {
return LockfileType.POETRY_LOCK
}
if (fileName === 'pipfile.lock') {
return LockfileType.PIPFILE_LOCK
}
if (fileName.endsWith('.gradle.lockfile')) {
return LockfileType.GRADLE_LOCK
}
if (fileName === 'build.sbt.lock') {
return LockfileType.SBT_LOCK
}
if (fileName === 'pom.xml.lock') {
return LockfileType.MAVEN_LOCK
}
if (fileName === 'packages.lock.json') {
return LockfileType.NUGET_LOCK
}
if (fileName === 'podfile.lock') {
return LockfileType.PODFILE_LOCK
}
if (fileName === 'cocoapods.lock') {
return LockfileType.COCOAPODS_LOCK
}
if (fileName === 'mix.lock') {
return LockfileType.MIX_LOCK
}
if (fileName === 'cartfile.resolved') {
return LockfileType.CARTHAGE_RESOLVED
}
if (fileName === 'package.resolved') {
return LockfileType.SWIFT_RESOLVED
}
if (fileName === 'go.sum') {
return LockfileType.GO_SUM
}
if (fileName === 'go.mod') {
return LockfileType.GO_MOD
}
if (fileName === 'pnpm-lock.yaml') {
return LockfileType.PNPM_LOCK
}
return undefined
}