This repository was archived by the owner on Apr 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlockfile.ts
More file actions
160 lines (137 loc) · 4.27 KB
/
Copy pathlockfile.ts
File metadata and controls
160 lines (137 loc) · 4.27 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import type { LockFile } from "renovate/dist/modules/manager/npm/extract/types";
import type { PackageDependency } from "renovate/dist/modules/manager/types";
import { logger } from "./logger";
const knownYarnLockfileVersions = [1, 2, 8];
export function isYarnLockFile(lockfile: LockFile): boolean {
if (lockfile.lockedVersions == null) {
return false;
}
const keys = Object.keys(lockfile.lockedVersions);
/*
Passing the wrong type of lockfile (i.e. an NPM lockfile) will result in a `LockFile` of the form:
{
yarnLock: {
isYarn1: true,
lockfileVersion: undefined,
lockedVersions: {
'name@unknown': undefined,
'version@unknown': undefined,
'lockfileVersion@unknown': undefined,
'requires@unknown': undefined,
'packages@unknown': undefined,
'dependencies@unknown': undefined
}
}
}
PNPM also presents a similar option, so we can look for the presence of `packages@unknown` as it's common across both
*/
return !keys.includes("packages@unknown");
}
export async function parseYarnLockfileEntry(
isYarn1: boolean | undefined,
lockfileVersion: number | undefined,
key: string,
value: string,
): Promise<PackageDependency<Record<string, any>>> {
if (isYarn1 !== undefined && isYarn1) {
const lockedVersion = value;
const parts = key.split("@");
let depName = parts[0];
let version = parts[1];
// if we've got a scoped package
if (parts.length === 3) {
depName += `@${parts[1]}`;
version = parts[2];
}
// intermediate variable to allow adding `depTypes` which isn't explicitly defined in the type, but seems to be returned in several places
const dep = {
depName,
packageName: depName,
datasource: "npm",
depTypes: [
"lockfile",
// in the case that we have multiple lockfile entries found for a given dependency, we need to add a separate `depType` metadata, which works around the way that dmd.tanna.dev deduplicates entries
`lockfile-yarn-pinning-${version}`,
],
currentValue: version,
lockedVersion,
fixedVersion: lockedVersion,
currentVersion: lockedVersion,
};
return dep;
}
if (
lockfileVersion === undefined ||
!knownYarnLockfileVersions.includes(lockfileVersion)
) {
logger.warn(
`WARN: Using Yarn Lockfile version ${JSON.stringify(lockfileVersion)}, which renovate-graph may not be able to handle correctly`,
);
}
const lockedVersion = value;
const parts = key.split("@");
let depName = parts[0];
let version = parts[1];
// if we've got a scoped package
if (parts.length === 3) {
depName += `@${parts[1]}`;
version = parts[2];
}
// intermediate variable to allow adding `depTypes` which isn't explicitly defined in the type, but seems to be returned in several places
const dep = {
depName,
packageName: depName,
datasource: "npm",
depTypes: [
"lockfile",
// in the case that we have multiple lockfile entries found for a given dependency, we need to add a separate `depType` metadata, which works around the way that dmd.tanna.dev deduplicates entries
`lockfile-yarn-pinning-${version}`,
],
currentValue: version,
lockedVersion,
fixedVersion: lockedVersion,
currentVersion: lockedVersion,
};
return dep;
}
export async function parseNPMLockfileEntry(
_lockfileVersion: number | undefined,
key: string,
value: string,
): Promise<PackageDependency<Record<string, any>>> {
const depName = key;
const version = value;
// intermediate variable to allow adding `depTypes` which isn't explicitly defined in the type, but seems to be returned in several places
const dep = {
depName,
packageName: depName,
datasource: "npm",
depTypes: ["lockfile"],
currentValue: version,
version,
fixedVersion: version,
currentVersion: version,
};
return dep;
}
export async function parsePNPMLockfileEntry(
_lockfileVersion: number | undefined,
key: string,
value: string,
depType: string,
): Promise<PackageDependency<Record<string, any>>> {
const depName = key;
const version = value;
// intermediate variable to allow adding `depTypes` which isn't explicitly defined in the type, but seems to be returned in several places
const dep = {
depName,
packageName: depName,
datasource: "npm",
depTypes: [depType, "lockfile"],
currentValue: version,
version,
fixedVersion: version,
currentVersion: version,
};
return dep;
}