nx 19.2.0-canary.20240525-af463c4 → 19.2.0-canary.20240528-7f11a1d
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/package.json +12 -12
- package/src/command-line/init/implementation/add-nx-to-monorepo.js +8 -0
- package/src/command-line/init/implementation/add-nx-to-nest.js +4 -0
- package/src/command-line/init/implementation/add-nx-to-npm-repo.js +4 -0
- package/src/command-line/init/implementation/angular/index.js +4 -0
- package/src/command-line/init/init-v2.js +4 -0
- package/src/command-line/show/project.js +7 -1
- package/src/command-line/yargs-utils/shared-options.js +9 -1
- package/src/core/graph/main.js +1 -1
- package/src/core/graph/styles.css +1 -1
- package/src/daemon/server/server.js +1 -0
- package/src/plugins/js/index.js +6 -2
- package/src/plugins/js/lock-file/pnpm-parser.js +220 -89
- package/src/plugins/js/lock-file/utils/pnpm-normalizer.d.ts +7 -25
- package/src/plugins/js/lock-file/utils/pnpm-normalizer.js +567 -287
- package/src/plugins/js/project-graph/affected/lock-file-changes.js +1 -0
- package/src/plugins/package-json-workspaces/create-nodes.js +1 -0
- package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.js +1 -0
- package/src/tasks-runner/create-task-graph.d.ts +3 -3
- package/src/tasks-runner/create-task-graph.js +5 -5
- package/src/tasks-runner/run-command.js +3 -4
- package/src/tasks-runner/utils.d.ts +1 -2
- package/src/tasks-runner/utils.js +4 -8
- package/src/utils/package-json.d.ts +2 -1
- package/src/utils/package-json.js +11 -1
- package/src/utils/params.d.ts +1 -1
- package/src/utils/params.js +5 -4
@@ -4,14 +4,29 @@
|
|
4
4
|
* It will convert inline specifiers to the separate specifiers format and ensure importers are present.
|
5
5
|
*/
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
7
|
-
exports.stringifyToPnpmYaml = exports.parseAndNormalizePnpmLockfile = exports.loadPnpmHoistedDepsDefinition = exports.
|
7
|
+
exports.stringifyToPnpmYaml = exports.parseAndNormalizePnpmLockfile = exports.loadPnpmHoistedDepsDefinition = exports.usesLeadingDash = exports.isV5Syntax = void 0;
|
8
8
|
const fs_1 = require("fs");
|
9
|
-
const workspace_root_1 = require("../../../../utils/workspace-root");
|
10
9
|
const semver_1 = require("semver");
|
11
|
-
|
12
|
-
|
10
|
+
const workspace_root_1 = require("../../../../utils/workspace-root");
|
11
|
+
const file_hasher_1 = require("../../../../hasher/file-hasher");
|
12
|
+
function isV5Syntax(data) {
|
13
|
+
if (+data.lockfileVersion.toString() >= 6) {
|
14
|
+
return false;
|
15
|
+
}
|
16
|
+
else {
|
17
|
+
return true;
|
18
|
+
}
|
13
19
|
}
|
14
|
-
exports.
|
20
|
+
exports.isV5Syntax = isV5Syntax;
|
21
|
+
function usesLeadingDash(data) {
|
22
|
+
if (+data.lockfileVersion.toString() >= 9) {
|
23
|
+
false;
|
24
|
+
}
|
25
|
+
else {
|
26
|
+
return true;
|
27
|
+
}
|
28
|
+
}
|
29
|
+
exports.usesLeadingDash = usesLeadingDash;
|
15
30
|
function loadPnpmHoistedDepsDefinition() {
|
16
31
|
const fullPath = `${workspace_root_1.workspaceRoot}/node_modules/.modules.yaml`;
|
17
32
|
if ((0, fs_1.existsSync)(fullPath)) {
|
@@ -24,33 +39,157 @@ function loadPnpmHoistedDepsDefinition() {
|
|
24
39
|
}
|
25
40
|
}
|
26
41
|
exports.loadPnpmHoistedDepsDefinition = loadPnpmHoistedDepsDefinition;
|
27
|
-
/*************************************************************************
|
28
|
-
* THE FOLLOWING CODE IS COPIED & simplified FROM @pnpm/lockfile-file for convenience
|
29
|
-
*************************************************************************/
|
30
42
|
/**
|
31
43
|
* Parsing and mapping logic from pnpm lockfile `read` function
|
32
|
-
* https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/lockfile/lockfile-file/src/read.ts#L91
|
33
44
|
*/
|
34
45
|
function parseAndNormalizePnpmLockfile(content) {
|
35
46
|
const { load } = require('@zkochan/js-yaml');
|
36
|
-
|
37
|
-
return revertFromInlineSpecifiersFormatIfNecessary(convertFromLockfileFileMutable(lockFileData));
|
47
|
+
return convertToLockfileObject(load(content));
|
38
48
|
}
|
39
49
|
exports.parseAndNormalizePnpmLockfile = parseAndNormalizePnpmLockfile;
|
50
|
+
// https://github.com/pnpm/pnpm/blob/50e37072f42bcca6d393a74bed29f7f0e029805d/lockfile/lockfile-file/src/write.ts#L22
|
51
|
+
const LOCKFILE_YAML_FORMAT = {
|
52
|
+
blankLines: true,
|
53
|
+
lineWidth: -1, // This is setting line width to never wrap
|
54
|
+
noCompatMode: true,
|
55
|
+
noRefs: true,
|
56
|
+
sortKeys: false,
|
57
|
+
};
|
58
|
+
const LOCKFILE_YAML_PRE9_FORMAT = {
|
59
|
+
...LOCKFILE_YAML_FORMAT,
|
60
|
+
lineWidth: 1000,
|
61
|
+
};
|
62
|
+
/**
|
63
|
+
* Mapping and writing logic from pnpm lockfile `write` function
|
64
|
+
*/
|
65
|
+
function stringifyToPnpmYaml(lockfile) {
|
66
|
+
const { dump } = require('@zkochan/js-yaml');
|
67
|
+
const lockfileVersion = +lockfile.lockfileVersion;
|
68
|
+
if (lockfileVersion >= 9) {
|
69
|
+
const adaptedLockfile = convertToLockfileFile(lockfile, {
|
70
|
+
forceSharedFormat: true,
|
71
|
+
});
|
72
|
+
return dump(sortLockfileKeys(adaptedLockfile), LOCKFILE_YAML_FORMAT);
|
73
|
+
}
|
74
|
+
else {
|
75
|
+
// https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/lockfile/lockfile-file/src/write.ts#L77
|
76
|
+
const adaptedLockfile = lockfileVersion >= 6
|
77
|
+
? convertToInlineSpecifiersFormat(lockfile)
|
78
|
+
: lockfile;
|
79
|
+
return dump(sortLockfileKeys(normalizeLockfileV6(adaptedLockfile, lockfileVersion >= 6)), LOCKFILE_YAML_PRE9_FORMAT);
|
80
|
+
}
|
81
|
+
}
|
82
|
+
exports.stringifyToPnpmYaml = stringifyToPnpmYaml;
|
40
83
|
/**
|
41
|
-
*
|
42
|
-
* https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/lockfile/lockfile-file/src/read.ts#L234
|
84
|
+
* The following code was copied over from pnpm source code and modified to work in this context.
|
43
85
|
*/
|
86
|
+
// https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/lockfile/lockfile-file/src/experiments/inlineSpecifiersLockfileConverters.ts#L17
|
87
|
+
function convertToInlineSpecifiersFormat(lockfile) {
|
88
|
+
let importers = lockfile.importers;
|
89
|
+
let packages = lockfile.packages;
|
90
|
+
importers = Object.fromEntries(Object.entries(lockfile.importers ?? {}).map(([importerId, pkgSnapshot]) => {
|
91
|
+
const newSnapshot = { ...pkgSnapshot };
|
92
|
+
if (newSnapshot.dependencies != null) {
|
93
|
+
newSnapshot.dependencies = mapValues(newSnapshot.dependencies, convertOldRefToNewRef);
|
94
|
+
}
|
95
|
+
if (newSnapshot.optionalDependencies != null) {
|
96
|
+
newSnapshot.optionalDependencies = mapValues(newSnapshot.optionalDependencies, convertOldRefToNewRef);
|
97
|
+
}
|
98
|
+
if (newSnapshot.devDependencies != null) {
|
99
|
+
newSnapshot.devDependencies = mapValues(newSnapshot.devDependencies, convertOldRefToNewRef);
|
100
|
+
}
|
101
|
+
return [importerId, newSnapshot];
|
102
|
+
}));
|
103
|
+
packages = Object.fromEntries(Object.entries(lockfile.packages ?? {}).map(([depPath, pkgSnapshot]) => {
|
104
|
+
const newSnapshot = { ...pkgSnapshot };
|
105
|
+
if (newSnapshot.dependencies != null) {
|
106
|
+
newSnapshot.dependencies = mapValues(newSnapshot.dependencies, convertOldRefToNewRef);
|
107
|
+
}
|
108
|
+
if (newSnapshot.optionalDependencies != null) {
|
109
|
+
newSnapshot.optionalDependencies = mapValues(newSnapshot.optionalDependencies, convertOldRefToNewRef);
|
110
|
+
}
|
111
|
+
return [convertOldDepPathToNewDepPath(depPath), newSnapshot];
|
112
|
+
}));
|
113
|
+
const newLockfile = {
|
114
|
+
...lockfile,
|
115
|
+
packages,
|
116
|
+
lockfileVersion: lockfile.lockfileVersion.toString(),
|
117
|
+
importers: mapValues(importers, convertProjectSnapshotToInlineSpecifiersFormat),
|
118
|
+
};
|
119
|
+
if (newLockfile.time) {
|
120
|
+
newLockfile.time = Object.fromEntries(Object.entries(newLockfile.time).map(([depPath, time]) => [
|
121
|
+
convertOldDepPathToNewDepPath(depPath),
|
122
|
+
time,
|
123
|
+
]));
|
124
|
+
}
|
125
|
+
return newLockfile;
|
126
|
+
}
|
127
|
+
// https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/lockfile/lockfile-file/src/experiments/inlineSpecifiersLockfileConverters.ts#L72
|
128
|
+
function convertOldDepPathToNewDepPath(oldDepPath) {
|
129
|
+
const parsedDepPath = dpParse(oldDepPath);
|
130
|
+
if (!parsedDepPath.name || !parsedDepPath.version)
|
131
|
+
return oldDepPath;
|
132
|
+
let newDepPath = `/${parsedDepPath.name}@${parsedDepPath.version}`;
|
133
|
+
if (parsedDepPath.peersSuffix) {
|
134
|
+
if (parsedDepPath.peersSuffix.startsWith('(')) {
|
135
|
+
newDepPath += parsedDepPath.peersSuffix;
|
136
|
+
}
|
137
|
+
else {
|
138
|
+
newDepPath += `_${parsedDepPath.peersSuffix}`;
|
139
|
+
}
|
140
|
+
}
|
141
|
+
if (parsedDepPath.host) {
|
142
|
+
newDepPath = `${parsedDepPath.host}${newDepPath}`;
|
143
|
+
}
|
144
|
+
return newDepPath;
|
145
|
+
}
|
146
|
+
// https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/lockfile/lockfile-file/src/experiments/inlineSpecifiersLockfileConverters.ts#L89
|
147
|
+
function convertOldRefToNewRef(oldRef) {
|
148
|
+
if (oldRef.startsWith('link:') || oldRef.startsWith('file:')) {
|
149
|
+
return oldRef;
|
150
|
+
}
|
151
|
+
if (oldRef.includes('/')) {
|
152
|
+
return convertOldDepPathToNewDepPath(oldRef);
|
153
|
+
}
|
154
|
+
return oldRef;
|
155
|
+
}
|
156
|
+
// https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/lockfile/lockfile-file/src/experiments/inlineSpecifiersLockfileConverters.ts#L179
|
157
|
+
function convertProjectSnapshotToInlineSpecifiersFormat(projectSnapshot) {
|
158
|
+
const { specifiers, ...rest } = projectSnapshot;
|
159
|
+
const convertBlock = (block) => block != null
|
160
|
+
? convertResolvedDependenciesToInlineSpecifiersFormat(block, {
|
161
|
+
specifiers,
|
162
|
+
})
|
163
|
+
: block;
|
164
|
+
return {
|
165
|
+
...rest,
|
166
|
+
dependencies: convertBlock(projectSnapshot.dependencies),
|
167
|
+
optionalDependencies: convertBlock(projectSnapshot.optionalDependencies),
|
168
|
+
devDependencies: convertBlock(projectSnapshot.devDependencies),
|
169
|
+
};
|
170
|
+
}
|
171
|
+
// https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/lockfile/lockfile-file/src/experiments/inlineSpecifiersLockfileConverters.ts#L195
|
172
|
+
function convertResolvedDependenciesToInlineSpecifiersFormat(resolvedDependencies, { specifiers }) {
|
173
|
+
return mapValues(resolvedDependencies, (version, depName) => ({
|
174
|
+
specifier: specifiers[depName],
|
175
|
+
version,
|
176
|
+
}));
|
177
|
+
}
|
178
|
+
// https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/packages/types/src/misc.ts#L6
|
179
|
+
const DEPENDENCIES_FIELDS = [
|
180
|
+
'optionalDependencies',
|
181
|
+
'dependencies',
|
182
|
+
'devDependencies',
|
183
|
+
];
|
184
|
+
// https://github.com/pnpm/pnpm/blob/cca56c0c6c956d036883003092ca1d11bbb700f6/lockfile/lockfile-file/src/lockfileFormatConverters.ts#L169
|
44
185
|
function convertFromLockfileFileMutable(lockfileFile) {
|
45
186
|
if (typeof lockfileFile?.['importers'] === 'undefined') {
|
46
187
|
lockfileFile.importers = {
|
47
188
|
'.': {
|
48
|
-
specifiers: lockfileFile['specifiers'] ?? {},
|
49
189
|
dependenciesMeta: lockfileFile['dependenciesMeta'],
|
50
190
|
publishDirectory: lockfileFile['publishDirectory'],
|
51
191
|
},
|
52
192
|
};
|
53
|
-
delete lockfileFile.specifiers;
|
54
193
|
for (const depType of DEPENDENCIES_FIELDS) {
|
55
194
|
if (lockfileFile[depType] != null) {
|
56
195
|
lockfileFile.importers['.'][depType] = lockfileFile[depType];
|
@@ -58,31 +197,208 @@ function convertFromLockfileFileMutable(lockfileFile) {
|
|
58
197
|
}
|
59
198
|
}
|
60
199
|
}
|
200
|
+
else if (isV5Syntax(lockfileFile)) {
|
201
|
+
// remap the importers from v5 to the new format
|
202
|
+
for (const depType of DEPENDENCIES_FIELDS) {
|
203
|
+
if (lockfileFile.importers['.'][depType]) {
|
204
|
+
for (const [depName, version] of Object.entries(lockfileFile.importers['.'][depType])) {
|
205
|
+
lockfileFile.importers['.'][depType][depName] = {
|
206
|
+
version,
|
207
|
+
specifier: (lockfileFile['specifiers'] ||
|
208
|
+
lockfileFile.importers['.']['specifiers'])[depName],
|
209
|
+
};
|
210
|
+
}
|
211
|
+
}
|
212
|
+
}
|
213
|
+
}
|
61
214
|
return lockfileFile;
|
62
215
|
}
|
63
|
-
// https://github.com/pnpm/pnpm/blob/
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
216
|
+
// https://github.com/pnpm/pnpm/blob/cca56c0c6c956d036883003092ca1d11bbb700f6/lockfile/lockfile-file/src/lockfileFormatConverters.ts#L187
|
217
|
+
function convertToLockfileObject(lockfile) {
|
218
|
+
if (lockfile.snapshots) {
|
219
|
+
return convertLockfileV9ToLockfileObject(lockfile);
|
220
|
+
}
|
221
|
+
convertPkgIds(lockfile);
|
222
|
+
const { importers, ...rest } = convertFromLockfileFileMutable(lockfile);
|
223
|
+
const newLockfile = {
|
224
|
+
...rest,
|
225
|
+
importers: mapValues(importers ?? {}, revertProjectSnapshot),
|
226
|
+
};
|
227
|
+
return newLockfile;
|
228
|
+
}
|
229
|
+
// https://github.com/pnpm/pnpm/blob/cca56c0c6c956d036883003092ca1d11bbb700f6/lockfile/lockfile-file/src/lockfileFormatConverters.ts#L201
|
230
|
+
function convertPkgIds(lockfile) {
|
231
|
+
const oldIdToNewId = {};
|
232
|
+
if (lockfile.packages == null || isEmpty(lockfile.packages))
|
233
|
+
return;
|
234
|
+
for (const [pkgId, pkg] of Object.entries(lockfile.packages ?? {})) {
|
235
|
+
if (pkg.name) {
|
236
|
+
const { id, peersSuffix } = parseDepPath(pkgId);
|
237
|
+
let newId = `${pkg.name}@`;
|
238
|
+
if ('tarball' in pkg.resolution) {
|
239
|
+
newId += pkg.resolution.tarball;
|
240
|
+
if (pkg.resolution.path) {
|
241
|
+
newId += `#path:${pkg.resolution.path}`;
|
242
|
+
}
|
243
|
+
}
|
244
|
+
else if ('repo' in pkg.resolution) {
|
245
|
+
newId += createGitHostedPkgId(pkg.resolution);
|
246
|
+
}
|
247
|
+
else if ('directory' in pkg.resolution) {
|
248
|
+
newId += id;
|
249
|
+
}
|
250
|
+
else {
|
251
|
+
continue;
|
252
|
+
}
|
253
|
+
oldIdToNewId[pkgId] = `${newId}${peersSuffix}`;
|
254
|
+
if (id !== pkgId) {
|
255
|
+
oldIdToNewId[id] = newId;
|
256
|
+
}
|
257
|
+
}
|
258
|
+
else {
|
259
|
+
const { id, peersSuffix } = parseDepPath(pkgId);
|
260
|
+
const newId = id.substring(1);
|
261
|
+
oldIdToNewId[pkgId] = `${newId}${peersSuffix}`;
|
262
|
+
if (id !== pkgId) {
|
263
|
+
oldIdToNewId[id] = newId;
|
264
|
+
}
|
265
|
+
}
|
266
|
+
}
|
267
|
+
const newLockfilePackages = {};
|
268
|
+
for (const [pkgId, pkg] of Object.entries(lockfile.packages ?? {})) {
|
269
|
+
if (oldIdToNewId[pkgId]) {
|
270
|
+
if (pkg.id) {
|
271
|
+
pkg.id = oldIdToNewId[pkg.id];
|
272
|
+
}
|
273
|
+
newLockfilePackages[oldIdToNewId[pkgId]] = pkg;
|
274
|
+
}
|
275
|
+
else {
|
276
|
+
newLockfilePackages[pkgId] = pkg;
|
277
|
+
}
|
278
|
+
for (const depType of ['dependencies', 'optionalDependencies']) {
|
279
|
+
for (const [alias, depPath] of Object.entries(pkg[depType] ?? {})) {
|
280
|
+
if (oldIdToNewId[depPath]) {
|
281
|
+
if (oldIdToNewId[depPath].startsWith(`${alias}@`)) {
|
282
|
+
pkg[depType][alias] = oldIdToNewId[depPath].substring(alias.length + 1);
|
283
|
+
}
|
284
|
+
else {
|
285
|
+
pkg[depType][alias] = oldIdToNewId[depPath];
|
286
|
+
}
|
287
|
+
}
|
288
|
+
}
|
289
|
+
}
|
290
|
+
}
|
291
|
+
lockfile.packages = newLockfilePackages;
|
292
|
+
if ((lockfile.dependencies != null ||
|
293
|
+
lockfile.devDependencies != null ||
|
294
|
+
lockfile.optionalDependencies != null) &&
|
295
|
+
!lockfile.importers?.['.']) {
|
296
|
+
lockfile.importers = lockfile.importers ?? {};
|
297
|
+
lockfile.importers['.'] = {
|
298
|
+
dependencies: lockfile.dependencies,
|
299
|
+
devDependencies: lockfile.devDependencies,
|
300
|
+
optionalDependencies: lockfile.optionalDependencies,
|
301
|
+
};
|
302
|
+
delete lockfile.dependencies;
|
303
|
+
delete lockfile.devDependencies;
|
304
|
+
delete lockfile.optionalDependencies;
|
305
|
+
}
|
306
|
+
for (const importer of Object.values(lockfile.importers ?? {})) {
|
307
|
+
for (const depType of [
|
308
|
+
'dependencies',
|
309
|
+
'optionalDependencies',
|
310
|
+
'devDependencies',
|
311
|
+
]) {
|
312
|
+
for (const [alias, { version }] of Object.entries(importer[depType] ?? {})) {
|
313
|
+
if (oldIdToNewId[version]) {
|
314
|
+
if (oldIdToNewId[version].startsWith(`${alias}@`)) {
|
315
|
+
importer[depType][alias].version = oldIdToNewId[version].substring(alias.length + 1);
|
316
|
+
}
|
317
|
+
else {
|
318
|
+
importer[depType][alias].version = oldIdToNewId[version];
|
319
|
+
}
|
320
|
+
}
|
321
|
+
}
|
322
|
+
}
|
323
|
+
}
|
324
|
+
for (const depType of [
|
325
|
+
'dependencies',
|
326
|
+
'optionalDependencies',
|
327
|
+
'devDependencies',
|
328
|
+
]) {
|
329
|
+
for (const [alias, { version }] of Object.entries(lockfile[depType] ?? {})) {
|
330
|
+
if (oldIdToNewId[version]) {
|
331
|
+
lockfile[depType][alias].version = oldIdToNewId[version];
|
332
|
+
}
|
333
|
+
}
|
334
|
+
}
|
335
|
+
}
|
336
|
+
// https://github.com/pnpm/pnpm/blob/cca56c0c6c956d036883003092ca1d11bbb700f6/lockfile/lockfile-file/src/lockfileFormatConverters.ts#L289
|
337
|
+
function convertLockfileV9ToLockfileObject(lockfile) {
|
338
|
+
const { importers, ...rest } = convertFromLockfileFileMutable(lockfile);
|
339
|
+
const packages = {};
|
340
|
+
for (const [depPath, pkg] of Object.entries(lockfile.snapshots ?? {})) {
|
341
|
+
const pkgId = removePeersSuffix(depPath);
|
342
|
+
packages[depPath] = Object.assign(pkg, lockfile.packages?.[pkgId]);
|
343
|
+
}
|
344
|
+
return {
|
345
|
+
...omit(['snapshots'], rest),
|
346
|
+
packages,
|
347
|
+
importers: mapValues(importers ?? {}, revertProjectSnapshot),
|
348
|
+
};
|
349
|
+
}
|
350
|
+
// https://github.com/pnpm/pnpm/blob/cca56c0c6c956d036883003092ca1d11bbb700f6/lockfile/lockfile-file/src/lockfileFormatConverters.ts#L331
|
351
|
+
function revertProjectSnapshot(from) {
|
352
|
+
const specifiers = {};
|
353
|
+
function moveSpecifiers(from) {
|
354
|
+
const resolvedDependencies = {};
|
355
|
+
for (const [depName, { specifier, version }] of Object.entries(from)) {
|
356
|
+
const existingValue = specifiers[depName];
|
357
|
+
if (existingValue != null && existingValue !== specifier) {
|
358
|
+
throw new Error(`Project snapshot lists the same dependency more than once with conflicting versions: ${depName}`);
|
359
|
+
}
|
360
|
+
specifiers[depName] = specifier;
|
361
|
+
resolvedDependencies[depName] = version;
|
362
|
+
}
|
363
|
+
return resolvedDependencies;
|
364
|
+
}
|
365
|
+
const dependencies = from.dependencies == null
|
366
|
+
? from.dependencies
|
367
|
+
: moveSpecifiers(from.dependencies);
|
368
|
+
const devDependencies = from.devDependencies == null
|
369
|
+
? from.devDependencies
|
370
|
+
: moveSpecifiers(from.devDependencies);
|
371
|
+
const optionalDependencies = from.optionalDependencies == null
|
372
|
+
? from.optionalDependencies
|
373
|
+
: moveSpecifiers(from.optionalDependencies);
|
374
|
+
return {
|
375
|
+
...from,
|
376
|
+
specifiers,
|
377
|
+
dependencies,
|
378
|
+
devDependencies,
|
379
|
+
optionalDependencies,
|
380
|
+
};
|
381
|
+
}
|
382
|
+
// https://github.com/pnpm/pnpm/blob/cca56c0c6c956d036883003092ca1d11bbb700f6/lockfile/lockfile-file/src/lockfileFormatConverters.ts#L367
|
383
|
+
function mapValues(obj, mapper) {
|
384
|
+
const result = {};
|
385
|
+
for (const [key, value] of Object.entries(obj)) {
|
386
|
+
result[key] = mapper(value, key);
|
387
|
+
}
|
388
|
+
return result;
|
389
|
+
}
|
390
|
+
// https://github.com/pnpm/pnpm/blob/cca56c0c6c956d036883003092ca1d11bbb700f6/resolving/git-resolver/src/createGitHostedPkgId.ts#L1
|
391
|
+
function createGitHostedPkgId({ repo, commit, path, }) {
|
392
|
+
let id = `${repo.includes('://') ? '' : 'https://'}${repo}#${commit}`;
|
393
|
+
if (!id.startsWith('git+'))
|
394
|
+
id = `git+${id}`;
|
395
|
+
if (path) {
|
396
|
+
id += `&path:${path}`;
|
397
|
+
}
|
398
|
+
return id;
|
82
399
|
}
|
83
|
-
exports.stringifyToPnpmYaml = stringifyToPnpmYaml;
|
84
400
|
// https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/lockfile/lockfile-file/src/write.ts#L106
|
85
|
-
function
|
401
|
+
function normalizeLockfileV6(lockfile, isLockfileV6) {
|
86
402
|
let lockfileToSave;
|
87
403
|
if (Object.keys(lockfile.importers).length === 1 && lockfile.importers['.']) {
|
88
404
|
lockfileToSave = {
|
@@ -126,6 +442,13 @@ function normalizeLockfile(lockfile, isLockfileV6) {
|
|
126
442
|
delete lockfileToSave.packages;
|
127
443
|
}
|
128
444
|
}
|
445
|
+
if (lockfileToSave.packages) {
|
446
|
+
const newPackages = {};
|
447
|
+
for (const [depPath, pkgSnapshot] of Object.entries(lockfileToSave.packages)) {
|
448
|
+
const newDepPath = depPath.replace(/\/$/, '');
|
449
|
+
newPackages[newDepPath] = pkgSnapshot;
|
450
|
+
}
|
451
|
+
}
|
129
452
|
if (lockfileToSave.time) {
|
130
453
|
lockfileToSave.time = (isLockfileV6 ? pruneTimeInLockfileV6 : pruneTime)(lockfileToSave.time, lockfile.importers);
|
131
454
|
}
|
@@ -136,18 +459,18 @@ function normalizeLockfile(lockfile, isLockfileV6) {
|
|
136
459
|
isEmpty(lockfileToSave.patchedDependencies)) {
|
137
460
|
delete lockfileToSave.patchedDependencies;
|
138
461
|
}
|
139
|
-
if (lockfileToSave
|
140
|
-
if (isEmpty(lockfileToSave
|
141
|
-
delete lockfileToSave
|
462
|
+
if (lockfileToSave['neverBuiltDependencies'] != null) {
|
463
|
+
if (isEmpty(lockfileToSave['neverBuiltDependencies'])) {
|
464
|
+
delete lockfileToSave['neverBuiltDependencies'];
|
142
465
|
}
|
143
466
|
else {
|
144
|
-
lockfileToSave
|
145
|
-
lockfileToSave
|
467
|
+
lockfileToSave['neverBuiltDependencies'] =
|
468
|
+
lockfileToSave['neverBuiltDependencies'].sort();
|
146
469
|
}
|
147
470
|
}
|
148
|
-
if (lockfileToSave
|
149
|
-
lockfileToSave
|
150
|
-
lockfileToSave
|
471
|
+
if (lockfileToSave['onlyBuiltDependencies'] != null) {
|
472
|
+
lockfileToSave['onlyBuiltDependencies'] =
|
473
|
+
lockfileToSave['onlyBuiltDependencies'].sort();
|
151
474
|
}
|
152
475
|
if (!lockfileToSave.packageExtensionsChecksum) {
|
153
476
|
delete lockfileToSave.packageExtensionsChecksum;
|
@@ -216,268 +539,146 @@ function pruneTime(time, importers) {
|
|
216
539
|
}
|
217
540
|
return pickBy((depPath) => rootDepPaths.has(depPath), time);
|
218
541
|
}
|
219
|
-
// https://github.com/pnpm/pnpm/blob/
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
const INLINE_SPECIFIERS_FORMAT_LOCKFILE_VERSION_SUFFIX = '-inlineSpecifiers';
|
249
|
-
// https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/lockfile/lockfile-file/src/experiments/inlineSpecifiersLockfileConverters.ts#L10
|
250
|
-
function isExperimentalInlineSpecifiersFormat(lockfile) {
|
251
|
-
const { lockfileVersion } = lockfile;
|
252
|
-
return (lockfileVersion.toString().startsWith('6.') ||
|
253
|
-
(typeof lockfileVersion === 'string' &&
|
254
|
-
lockfileVersion.endsWith(INLINE_SPECIFIERS_FORMAT_LOCKFILE_VERSION_SUFFIX)));
|
255
|
-
}
|
256
|
-
// https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/lockfile/lockfile-file/src/experiments/inlineSpecifiersLockfileConverters.ts#L17
|
257
|
-
function convertToInlineSpecifiersFormat(lockfile) {
|
258
|
-
let importers = lockfile.importers;
|
259
|
-
let packages = lockfile.packages;
|
260
|
-
if (isV6Lockfile(lockfile)) {
|
261
|
-
importers = Object.fromEntries(Object.entries(lockfile.importers ?? {}).map(([importerId, pkgSnapshot]) => {
|
262
|
-
const newSnapshot = { ...pkgSnapshot };
|
263
|
-
if (newSnapshot.dependencies != null) {
|
264
|
-
newSnapshot.dependencies = mapValues(newSnapshot.dependencies, convertOldRefToNewRef);
|
265
|
-
}
|
266
|
-
if (newSnapshot.optionalDependencies != null) {
|
267
|
-
newSnapshot.optionalDependencies = mapValues(newSnapshot.optionalDependencies, convertOldRefToNewRef);
|
268
|
-
}
|
269
|
-
if (newSnapshot.devDependencies != null) {
|
270
|
-
newSnapshot.devDependencies = mapValues(newSnapshot.devDependencies, convertOldRefToNewRef);
|
271
|
-
}
|
272
|
-
return [importerId, newSnapshot];
|
273
|
-
}));
|
274
|
-
packages = Object.fromEntries(Object.entries(lockfile.packages ?? {}).map(([depPath, pkgSnapshot]) => {
|
275
|
-
const newSnapshot = { ...pkgSnapshot };
|
276
|
-
if (newSnapshot.dependencies != null) {
|
277
|
-
newSnapshot.dependencies = mapValues(newSnapshot.dependencies, convertOldRefToNewRef);
|
278
|
-
}
|
279
|
-
if (newSnapshot.optionalDependencies != null) {
|
280
|
-
newSnapshot.optionalDependencies = mapValues(newSnapshot.optionalDependencies, convertOldRefToNewRef);
|
281
|
-
}
|
282
|
-
return [convertOldDepPathToNewDepPath(depPath), newSnapshot];
|
283
|
-
}));
|
542
|
+
// https://github.com/pnpm/pnpm/blob/34bc8f48e10dc5a7d54eaa657638f8ccfb406aa4/lockfile/lockfile-file/src/lockfileFormatConverters.ts#L29
|
543
|
+
function convertToLockfileFile(lockfile, opts) {
|
544
|
+
const packages = {};
|
545
|
+
const snapshots = {};
|
546
|
+
for (const [depPath, pkg] of Object.entries(lockfile.packages ?? {})) {
|
547
|
+
snapshots[depPath] = pick([
|
548
|
+
'dependencies',
|
549
|
+
'optionalDependencies',
|
550
|
+
'transitivePeerDependencies',
|
551
|
+
'optional',
|
552
|
+
'id',
|
553
|
+
], pkg);
|
554
|
+
const pkgId = removePeersSuffix(depPath);
|
555
|
+
if (!packages[pkgId]) {
|
556
|
+
packages[pkgId] = pick([
|
557
|
+
'resolution',
|
558
|
+
'bundledDependencies',
|
559
|
+
'cpu',
|
560
|
+
'deprecated',
|
561
|
+
'engines',
|
562
|
+
'hasBin',
|
563
|
+
'libc',
|
564
|
+
'name',
|
565
|
+
'os',
|
566
|
+
'peerDependencies',
|
567
|
+
'peerDependenciesMeta',
|
568
|
+
'version',
|
569
|
+
], pkg);
|
570
|
+
}
|
284
571
|
}
|
285
572
|
const newLockfile = {
|
286
573
|
...lockfile,
|
574
|
+
snapshots,
|
287
575
|
packages,
|
288
|
-
lockfileVersion:
|
289
|
-
|
290
|
-
: lockfile.lockfileVersion
|
291
|
-
.toString()
|
292
|
-
.endsWith(INLINE_SPECIFIERS_FORMAT_LOCKFILE_VERSION_SUFFIX)
|
293
|
-
? lockfile.lockfileVersion.toString()
|
294
|
-
: `${lockfile.lockfileVersion}${INLINE_SPECIFIERS_FORMAT_LOCKFILE_VERSION_SUFFIX}`,
|
295
|
-
importers: mapValues(importers, convertProjectSnapshotToInlineSpecifiersFormat),
|
576
|
+
lockfileVersion: lockfile.lockfileVersion.toString(),
|
577
|
+
importers: mapValues(lockfile.importers, convertProjectSnapshotToInlineSpecifiersFormat),
|
296
578
|
};
|
297
|
-
|
298
|
-
newLockfile.time = Object.fromEntries(Object.entries(newLockfile.time).map(([depPath, time]) => [
|
299
|
-
convertOldDepPathToNewDepPath(depPath),
|
300
|
-
time,
|
301
|
-
]));
|
302
|
-
}
|
303
|
-
return newLockfile;
|
579
|
+
return normalizeLockfile(newLockfile, opts);
|
304
580
|
}
|
305
|
-
// https://github.com/pnpm/pnpm/blob/
|
306
|
-
function
|
307
|
-
|
308
|
-
if (!
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
581
|
+
// https://github.com/pnpm/pnpm/blob/34bc8f48e10dc5a7d54eaa657638f8ccfb406aa4/lockfile/lockfile-file/src/lockfileFormatConverters.ts#L68
|
582
|
+
function normalizeLockfile(lockfile, opts) {
|
583
|
+
let lockfileToSave;
|
584
|
+
if (!opts.forceSharedFormat &&
|
585
|
+
equals(Object.keys(lockfile.importers ?? {}), ['.'])) {
|
586
|
+
lockfileToSave = {
|
587
|
+
...lockfile,
|
588
|
+
...lockfile.importers?.['.'],
|
589
|
+
};
|
590
|
+
delete lockfileToSave.importers;
|
591
|
+
for (const depType of DEPENDENCIES_FIELDS) {
|
592
|
+
if (isEmpty(lockfileToSave[depType])) {
|
593
|
+
delete lockfileToSave[depType];
|
594
|
+
}
|
314
595
|
}
|
315
|
-
|
316
|
-
|
596
|
+
if (isEmpty(lockfileToSave.packages) || lockfileToSave.packages == null) {
|
597
|
+
delete lockfileToSave.packages;
|
598
|
+
}
|
599
|
+
if (isEmpty(lockfileToSave.snapshots) ||
|
600
|
+
lockfileToSave.snapshots == null) {
|
601
|
+
delete lockfileToSave.snapshots;
|
317
602
|
}
|
318
603
|
}
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
}
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
throw new Error(`Unable to revert lockfile from inline specifiers format. Invalid version parsed: ${originalVersionStr}`);
|
347
|
-
}
|
348
|
-
let revertedImporters = mapValues(importers, revertProjectSnapshot);
|
349
|
-
let packages = lockfile.packages;
|
350
|
-
if (originalVersionStr.startsWith('6.')) {
|
351
|
-
revertedImporters = Object.fromEntries(Object.entries(revertedImporters ?? {}).map(([importerId, pkgSnapshot]) => {
|
352
|
-
const newSnapshot = { ...pkgSnapshot };
|
353
|
-
if (newSnapshot.dependencies != null) {
|
354
|
-
newSnapshot.dependencies = mapValues(newSnapshot.dependencies, convertNewRefToOldRef);
|
355
|
-
}
|
356
|
-
if (newSnapshot.optionalDependencies != null) {
|
357
|
-
newSnapshot.optionalDependencies = mapValues(newSnapshot.optionalDependencies, convertNewRefToOldRef);
|
358
|
-
}
|
359
|
-
if (newSnapshot.devDependencies != null) {
|
360
|
-
newSnapshot.devDependencies = mapValues(newSnapshot.devDependencies, convertNewRefToOldRef);
|
361
|
-
}
|
362
|
-
return [importerId, newSnapshot];
|
363
|
-
}));
|
364
|
-
packages = Object.fromEntries(Object.entries(lockfile.packages ?? {}).map(([depPath, pkgSnapshot]) => {
|
365
|
-
const newSnapshot = { ...pkgSnapshot };
|
366
|
-
if (newSnapshot.dependencies != null) {
|
367
|
-
newSnapshot.dependencies = mapValues(newSnapshot.dependencies, convertNewRefToOldRef);
|
368
|
-
}
|
369
|
-
if (newSnapshot.optionalDependencies != null) {
|
370
|
-
newSnapshot.optionalDependencies = mapValues(newSnapshot.optionalDependencies, convertNewRefToOldRef);
|
371
|
-
}
|
372
|
-
return [convertNewDepPathToOldDepPath(depPath), newSnapshot];
|
373
|
-
}));
|
604
|
+
else {
|
605
|
+
lockfileToSave = {
|
606
|
+
...lockfile,
|
607
|
+
importers: mapValues(lockfile.importers ?? {}, (importer) => {
|
608
|
+
const normalizedImporter = {};
|
609
|
+
if (importer.dependenciesMeta != null &&
|
610
|
+
!isEmpty(importer.dependenciesMeta)) {
|
611
|
+
normalizedImporter.dependenciesMeta = importer.dependenciesMeta;
|
612
|
+
}
|
613
|
+
for (const depType of DEPENDENCIES_FIELDS) {
|
614
|
+
if (!isEmpty(importer[depType] ?? {})) {
|
615
|
+
normalizedImporter[depType] = importer[depType];
|
616
|
+
}
|
617
|
+
}
|
618
|
+
if (importer.publishDirectory) {
|
619
|
+
normalizedImporter.publishDirectory = importer.publishDirectory;
|
620
|
+
}
|
621
|
+
return normalizedImporter;
|
622
|
+
}),
|
623
|
+
};
|
624
|
+
if (isEmpty(lockfileToSave.packages) || lockfileToSave.packages == null) {
|
625
|
+
delete lockfileToSave.packages;
|
626
|
+
}
|
627
|
+
if (isEmpty(lockfileToSave.snapshots) ||
|
628
|
+
lockfileToSave.snapshots == null) {
|
629
|
+
delete lockfileToSave.snapshots;
|
630
|
+
}
|
374
631
|
}
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
importers: revertedImporters,
|
382
|
-
};
|
383
|
-
if (originalVersionStr.startsWith('6.') && newLockfile.time) {
|
384
|
-
newLockfile.time = Object.fromEntries(Object.entries(newLockfile.time).map(([depPath, time]) => [
|
385
|
-
convertNewDepPathToOldDepPath(depPath),
|
386
|
-
time,
|
387
|
-
]));
|
632
|
+
// This code only handles v9 format
|
633
|
+
// if (lockfileToSave.time) {
|
634
|
+
// lockfileToSave.time = pruneTimeInLockfileV6(lockfileToSave.time, lockfile.importers ?? {})
|
635
|
+
// }
|
636
|
+
if (lockfileToSave.overrides != null && isEmpty(lockfileToSave.overrides)) {
|
637
|
+
delete lockfileToSave.overrides;
|
388
638
|
}
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
function convertNewDepPathToOldDepPath(oldDepPath) {
|
393
|
-
if (!oldDepPath.includes('@', 2))
|
394
|
-
return oldDepPath;
|
395
|
-
const index = oldDepPath.indexOf('@', oldDepPath.indexOf('/@') + 2);
|
396
|
-
if (oldDepPath.includes('(') && index > oldDepPath.indexOf('('))
|
397
|
-
return oldDepPath;
|
398
|
-
return `${oldDepPath.substring(0, index)}/${oldDepPath.substring(index + 1)}`;
|
399
|
-
}
|
400
|
-
// https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/lockfile/lockfile-file/src/experiments/inlineSpecifiersLockfileConverters.ts#L169
|
401
|
-
function convertNewRefToOldRef(oldRef) {
|
402
|
-
if (oldRef.startsWith('link:') || oldRef.startsWith('file:')) {
|
403
|
-
return oldRef;
|
639
|
+
if (lockfileToSave.patchedDependencies != null &&
|
640
|
+
isEmpty(lockfileToSave.patchedDependencies)) {
|
641
|
+
delete lockfileToSave.patchedDependencies;
|
404
642
|
}
|
405
|
-
if (
|
406
|
-
|
643
|
+
if (!lockfileToSave.packageExtensionsChecksum) {
|
644
|
+
delete lockfileToSave.packageExtensionsChecksum;
|
407
645
|
}
|
408
|
-
|
409
|
-
|
410
|
-
// https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/lockfile/lockfile-file/src/experiments/inlineSpecifiersLockfileConverters.ts#L179
|
411
|
-
function convertProjectSnapshotToInlineSpecifiersFormat(projectSnapshot) {
|
412
|
-
const { specifiers, ...rest } = projectSnapshot;
|
413
|
-
const convertBlock = (block) => block != null
|
414
|
-
? convertResolvedDependenciesToInlineSpecifiersFormat(block, {
|
415
|
-
specifiers,
|
416
|
-
})
|
417
|
-
: block;
|
418
|
-
return {
|
419
|
-
...rest,
|
420
|
-
dependencies: convertBlock(projectSnapshot.dependencies),
|
421
|
-
optionalDependencies: convertBlock(projectSnapshot.optionalDependencies),
|
422
|
-
devDependencies: convertBlock(projectSnapshot.devDependencies),
|
423
|
-
};
|
424
|
-
}
|
425
|
-
// https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/lockfile/lockfile-file/src/experiments/inlineSpecifiersLockfileConverters.ts#L195
|
426
|
-
function convertResolvedDependenciesToInlineSpecifiersFormat(resolvedDependencies, { specifiers }) {
|
427
|
-
return mapValues(resolvedDependencies, (version, depName) => ({
|
428
|
-
specifier: specifiers[depName],
|
429
|
-
version,
|
430
|
-
}));
|
431
|
-
}
|
432
|
-
// https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/lockfile/lockfile-file/src/experiments/inlineSpecifiersLockfileConverters.ts#L205
|
433
|
-
function revertProjectSnapshot(from) {
|
434
|
-
const specifiers = {};
|
435
|
-
function moveSpecifiers(from) {
|
436
|
-
const resolvedDependencies = {};
|
437
|
-
for (const [depName, { specifier, version }] of Object.entries(from)) {
|
438
|
-
const existingValue = specifiers[depName];
|
439
|
-
if (existingValue != null && existingValue !== specifier) {
|
440
|
-
throw new Error(`Project snapshot lists the same dependency more than once with conflicting versions: ${depName}`);
|
441
|
-
}
|
442
|
-
specifiers[depName] = specifier;
|
443
|
-
resolvedDependencies[depName] = version;
|
444
|
-
}
|
445
|
-
return resolvedDependencies;
|
646
|
+
if (!lockfileToSave.ignoredOptionalDependencies?.length) {
|
647
|
+
delete lockfileToSave.ignoredOptionalDependencies;
|
446
648
|
}
|
447
|
-
|
448
|
-
|
449
|
-
: null;
|
450
|
-
const devDependencies = from.devDependencies
|
451
|
-
? moveSpecifiers(from.devDependencies)
|
452
|
-
: null;
|
453
|
-
const optionalDependencies = from.optionalDependencies
|
454
|
-
? moveSpecifiers(from.optionalDependencies)
|
455
|
-
: null;
|
456
|
-
return {
|
457
|
-
...from,
|
458
|
-
specifiers,
|
459
|
-
dependencies,
|
460
|
-
devDependencies,
|
461
|
-
optionalDependencies,
|
462
|
-
};
|
463
|
-
}
|
464
|
-
// https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/lockfile/lockfile-file/src/experiments/inlineSpecifiersLockfileConverters.ts#L241
|
465
|
-
function mapValues(obj, mapper) {
|
466
|
-
const result = {};
|
467
|
-
for (const [key, value] of Object.entries(obj)) {
|
468
|
-
result[key] = mapper(value, key);
|
649
|
+
if (!lockfileToSave.pnpmfileChecksum) {
|
650
|
+
delete lockfileToSave.pnpmfileChecksum;
|
469
651
|
}
|
470
|
-
return
|
652
|
+
return lockfileToSave;
|
471
653
|
}
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
'
|
654
|
+
const ROOT_KEYS = [
|
655
|
+
'lockfileVersion',
|
656
|
+
'neverBuiltDependencies',
|
657
|
+
'onlyBuiltDependencies',
|
658
|
+
'settings',
|
659
|
+
'overrides',
|
660
|
+
'packageExtensionsChecksum',
|
661
|
+
'pnpmfileChecksum',
|
662
|
+
'patchedDependencies',
|
663
|
+
'specifiers',
|
478
664
|
'dependencies',
|
665
|
+
'optionalDependencies',
|
479
666
|
'devDependencies',
|
667
|
+
'dependenciesMeta',
|
668
|
+
'importers',
|
669
|
+
'packages',
|
480
670
|
];
|
671
|
+
const ROOT_KEYS_ORDER = Object.fromEntries(ROOT_KEYS.map((key, index) => [key, index]));
|
672
|
+
// https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/lockfile/lockfile-file/src/sortLockfileKeys.ts#L60
|
673
|
+
// TODO(meeroslav): pnpm has not a more sophisticated implementation for this function. check if this becomes a bottleneck
|
674
|
+
function sortLockfileKeys(lockfile) {
|
675
|
+
let sortedLockfile = {};
|
676
|
+
const sortedKeys = Object.keys(lockfile).sort((a, b) => ROOT_KEYS_ORDER[a] - ROOT_KEYS_ORDER[b]);
|
677
|
+
for (const key of sortedKeys) {
|
678
|
+
sortedLockfile[key] = lockfile[key];
|
679
|
+
}
|
680
|
+
return sortedLockfile;
|
681
|
+
}
|
481
682
|
/*************************************************************************
|
482
683
|
* THE FOLLOWING CODE IS COPIED FROM @pnpm/dependency-path for convenience
|
483
684
|
*************************************************************************/
|
@@ -485,6 +686,46 @@ const DEPENDENCIES_FIELDS = [
|
|
485
686
|
function isAbsolute(dependencyPath) {
|
486
687
|
return dependencyPath[0] !== '/';
|
487
688
|
}
|
689
|
+
// https://github.com/pnpm/pnpm/blob/cca56c0c6c956d036883003092ca1d11bbb700f6/packages/dependency-path/src/index.ts#L9
|
690
|
+
function indexOfPeersSuffix(depPath) {
|
691
|
+
if (!depPath.endsWith(')'))
|
692
|
+
return -1;
|
693
|
+
let open = 1;
|
694
|
+
for (let i = depPath.length - 2; i >= 0; i--) {
|
695
|
+
if (depPath[i] === '(') {
|
696
|
+
open--;
|
697
|
+
}
|
698
|
+
else if (depPath[i] === ')') {
|
699
|
+
open++;
|
700
|
+
}
|
701
|
+
else if (!open) {
|
702
|
+
return i + 1;
|
703
|
+
}
|
704
|
+
}
|
705
|
+
return -1;
|
706
|
+
}
|
707
|
+
// https://github.com/pnpm/pnpm/blob/cca56c0c6c956d036883003092ca1d11bbb700f6/packages/dependency-path/src/index.ts#L29
|
708
|
+
function parseDepPath(relDepPath) {
|
709
|
+
const sepIndex = indexOfPeersSuffix(relDepPath);
|
710
|
+
if (sepIndex !== -1) {
|
711
|
+
return {
|
712
|
+
id: relDepPath.substring(0, sepIndex),
|
713
|
+
peersSuffix: relDepPath.substring(sepIndex),
|
714
|
+
};
|
715
|
+
}
|
716
|
+
return {
|
717
|
+
id: relDepPath,
|
718
|
+
peersSuffix: '',
|
719
|
+
};
|
720
|
+
}
|
721
|
+
// https://github.com/pnpm/pnpm/blob/cca56c0c6c956d036883003092ca1d11bbb700f6/packages/dependency-path/src/index.ts#L43
|
722
|
+
function removePeersSuffix(relDepPath) {
|
723
|
+
const sepIndex = indexOfPeersSuffix(relDepPath);
|
724
|
+
if (sepIndex !== -1) {
|
725
|
+
return relDepPath.substring(0, sepIndex);
|
726
|
+
}
|
727
|
+
return relDepPath;
|
728
|
+
}
|
488
729
|
// https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/packages/dependency-path/src/index.ts#L80
|
489
730
|
function dpRefToRelative(reference, pkgName) {
|
490
731
|
if (reference.startsWith('link:')) {
|
@@ -559,6 +800,18 @@ function dpParse(dependencyPath) {
|
|
559
800
|
/********************************************************************************
|
560
801
|
* THE FOLLOWING CODE IS COPIED AND SIMPLIFIED FROM @pnpm/ramda for convenience
|
561
802
|
*******************************************************************************/
|
803
|
+
// https://github.com/pnpm/ramda/blob/50c6b57110b2f3631ed8633141f12012b7768d85/source/pick.js#L22
|
804
|
+
function pick(names, obj) {
|
805
|
+
var result = {};
|
806
|
+
var idx = 0;
|
807
|
+
while (idx < names.length) {
|
808
|
+
if (names[idx] in obj) {
|
809
|
+
result[names[idx]] = obj[names[idx]];
|
810
|
+
}
|
811
|
+
idx += 1;
|
812
|
+
}
|
813
|
+
return result;
|
814
|
+
}
|
562
815
|
// https://github.com/pnpm/ramda/blob/50c6b57110b2f3631ed8633141f12012b7768d85/source/pickBy.js#L24
|
563
816
|
function pickBy(test, obj) {
|
564
817
|
let result = {};
|
@@ -573,3 +826,30 @@ function pickBy(test, obj) {
|
|
573
826
|
function isEmpty(obj) {
|
574
827
|
return obj != null && Object.keys(obj).length === 0;
|
575
828
|
}
|
829
|
+
// https://github.com/pnpm/ramda/blob/50c6b57110b2f3631ed8633141f12012b7768d85/source/omit.js#L19
|
830
|
+
function omit(names, obj) {
|
831
|
+
let result = {};
|
832
|
+
let index = {};
|
833
|
+
let idx = 0;
|
834
|
+
const len = names.length;
|
835
|
+
while (idx < len) {
|
836
|
+
index[names[idx]] = 1;
|
837
|
+
idx += 1;
|
838
|
+
}
|
839
|
+
for (var prop in obj) {
|
840
|
+
if (!index.hasOwnProperty(prop)) {
|
841
|
+
result[prop] = obj[prop];
|
842
|
+
}
|
843
|
+
}
|
844
|
+
return result;
|
845
|
+
}
|
846
|
+
// This is a simplified internal implementation of the `equals` to replace complex function from Ramda
|
847
|
+
function equals(a, b) {
|
848
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
849
|
+
return a.length === b.length && a.every((v, i) => v === b[i]);
|
850
|
+
}
|
851
|
+
if (typeof a === 'object' && typeof b === 'object') {
|
852
|
+
return (0, file_hasher_1.hashObject)(a) === (0, file_hasher_1.hashObject)(b);
|
853
|
+
}
|
854
|
+
return a === b;
|
855
|
+
}
|