@teambit/pnpm 1.0.1298 → 1.0.1299
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/dist/lockfile-deps-graph-converter.d.ts +19 -2
- package/dist/lockfile-deps-graph-converter.js +126 -41
- package/dist/lockfile-deps-graph-converter.js.map +1 -1
- package/dist/lockfile-deps-graph-converter.spec.js +157 -2
- package/dist/lockfile-deps-graph-converter.spec.js.map +1 -1
- package/dist/pnpm.package-manager.js +3 -1
- package/dist/pnpm.package-manager.js.map +1 -1
- package/dist/{preview-1793031377870.js → preview-1793039364231.js} +2 -2
- package/package.json +8 -8
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ProjectManifest } from '@pnpm/types';
|
|
2
2
|
import { type LockfileFileProjectSnapshot } from '@pnpm/lockfile.types';
|
|
3
|
-
import { DependenciesGraph } from '@teambit/objects';
|
|
3
|
+
import { DependenciesGraph, type PackageAttributes, type DependencyEdge } from '@teambit/objects';
|
|
4
4
|
import { type CalcDepsGraphOptions, type CalcDepsGraphForComponentOptions, type ComponentIdByPkgName } from '@teambit/dependency-resolver';
|
|
5
5
|
import { type BitLockfileFile } from './lynx';
|
|
6
6
|
/**
|
|
@@ -19,8 +19,25 @@ type ResolveFunction = (wantedDependency: {
|
|
|
19
19
|
resolution?: Record<string, unknown>;
|
|
20
20
|
}>;
|
|
21
21
|
export declare function init(): Promise<void>;
|
|
22
|
-
export
|
|
22
|
+
export interface LockfileToGraphCache {
|
|
23
|
+
edges: WeakMap<object, {
|
|
24
|
+
depPath: string;
|
|
25
|
+
edge: DependencyEdge | null;
|
|
26
|
+
}>;
|
|
27
|
+
packages: WeakMap<object, {
|
|
28
|
+
pkgId: string;
|
|
29
|
+
replacedPkgId: string;
|
|
30
|
+
graphPkg: PackageAttributes;
|
|
31
|
+
}>;
|
|
32
|
+
componentIdByPkgName?: ComponentIdByPkgName;
|
|
33
|
+
depsRequiringBuild?: string[];
|
|
34
|
+
contextKey?: string;
|
|
23
35
|
replaceFileVersion?: (s: string) => string;
|
|
36
|
+
}
|
|
37
|
+
export declare function createLockfileToGraphCache(): LockfileToGraphCache;
|
|
38
|
+
export declare function convertLockfileToGraph(lockfile: BitLockfileFile, { pkgName, componentRootDir, componentRelativeDir, componentIdByPkgName, replaceFileVersion, cache, }: Omit<CalcDepsGraphOptions & CalcDepsGraphForComponentOptions, 'rootDir' | 'components' | 'component'> & {
|
|
39
|
+
replaceFileVersion?: (s: string) => string;
|
|
40
|
+
cache?: LockfileToGraphCache;
|
|
24
41
|
}): DependenciesGraph;
|
|
25
42
|
export declare function createFileVersionReplacer(componentIdByPkgName: ComponentIdByPkgName): (s: string) => string;
|
|
26
43
|
/**
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.convertGraphToLockfile = convertGraphToLockfile;
|
|
7
7
|
exports.convertLockfileToGraph = convertLockfileToGraph;
|
|
8
8
|
exports.createFileVersionReplacer = createFileVersionReplacer;
|
|
9
|
+
exports.createLockfileToGraphCache = createLockfileToGraphCache;
|
|
9
10
|
exports.filterLockfileByImporters = filterLockfileByImporters;
|
|
10
11
|
exports.init = init;
|
|
11
12
|
function _path() {
|
|
@@ -156,12 +157,29 @@ function scrubOwnComponentFromLockfile(lockfile, pkgName) {
|
|
|
156
157
|
packages
|
|
157
158
|
});
|
|
158
159
|
}
|
|
160
|
+
function createLockfileToGraphCache() {
|
|
161
|
+
return {
|
|
162
|
+
edges: new WeakMap(),
|
|
163
|
+
packages: new WeakMap()
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function getCacheContextKey(componentIdByPkgName, depsRequiringBuild) {
|
|
167
|
+
let key = '';
|
|
168
|
+
for (const [pkgName, compId] of componentIdByPkgName.entries()) {
|
|
169
|
+
key += `${pkgName}:${compId.scope}/${compId.fullName}@${compId.version};`;
|
|
170
|
+
}
|
|
171
|
+
if (depsRequiringBuild?.length) {
|
|
172
|
+
key += `|build:${depsRequiringBuild.join(',')}`;
|
|
173
|
+
}
|
|
174
|
+
return key;
|
|
175
|
+
}
|
|
159
176
|
function convertLockfileToGraphFromCapsule(lockfile, {
|
|
160
177
|
pkgName,
|
|
161
178
|
componentRelativeDir,
|
|
162
179
|
componentIdByPkgName,
|
|
163
180
|
replaceFileVersion,
|
|
164
|
-
narrowToComponentImporter = false
|
|
181
|
+
narrowToComponentImporter = false,
|
|
182
|
+
cache
|
|
165
183
|
}) {
|
|
166
184
|
const narrowedLockfile = scrubOwnComponentFromLockfile(narrowToComponentImporter ? filterLockfileByImporters(lockfile, [componentRelativeDir]) : lockfile, pkgName);
|
|
167
185
|
const componentImporter = narrowedLockfile.importers[componentRelativeDir];
|
|
@@ -176,7 +194,8 @@ function convertLockfileToGraphFromCapsule(lockfile, {
|
|
|
176
194
|
return _convertLockfileToGraph(narrowedLockfile, {
|
|
177
195
|
componentIdByPkgName,
|
|
178
196
|
directDependencies,
|
|
179
|
-
replaceFileVersion
|
|
197
|
+
replaceFileVersion,
|
|
198
|
+
cache
|
|
180
199
|
});
|
|
181
200
|
}
|
|
182
201
|
function importerDepsToNeighbours(importerDependencies, lifecycle, optional) {
|
|
@@ -204,7 +223,8 @@ function convertLockfileToGraph(lockfile, {
|
|
|
204
223
|
componentRootDir,
|
|
205
224
|
componentRelativeDir,
|
|
206
225
|
componentIdByPkgName,
|
|
207
|
-
replaceFileVersion
|
|
226
|
+
replaceFileVersion,
|
|
227
|
+
cache
|
|
208
228
|
}) {
|
|
209
229
|
ensureInitialized();
|
|
210
230
|
if (componentRootDir == null || pkgName == null) {
|
|
@@ -212,7 +232,8 @@ function convertLockfileToGraph(lockfile, {
|
|
|
212
232
|
pkgName,
|
|
213
233
|
componentRelativeDir,
|
|
214
234
|
componentIdByPkgName,
|
|
215
|
-
replaceFileVersion
|
|
235
|
+
replaceFileVersion,
|
|
236
|
+
cache
|
|
216
237
|
});
|
|
217
238
|
}
|
|
218
239
|
const rootImporterDeps = lockfile.importers[componentRootDir]?.dependencies?.[pkgName];
|
|
@@ -222,7 +243,8 @@ function convertLockfileToGraph(lockfile, {
|
|
|
222
243
|
componentRelativeDir,
|
|
223
244
|
componentIdByPkgName,
|
|
224
245
|
replaceFileVersion,
|
|
225
|
-
narrowToComponentImporter: lockfile.importers?.[componentRootDir] != null
|
|
246
|
+
narrowToComponentImporter: lockfile.importers?.[componentRootDir] != null,
|
|
247
|
+
cache
|
|
226
248
|
});
|
|
227
249
|
}
|
|
228
250
|
const lockedFileVersion = rootImporterDeps.version;
|
|
@@ -234,7 +256,8 @@ function convertLockfileToGraph(lockfile, {
|
|
|
234
256
|
componentRelativeDir,
|
|
235
257
|
componentIdByPkgName,
|
|
236
258
|
replaceFileVersion,
|
|
237
|
-
narrowToComponentImporter: lockfile.importers?.[componentRootDir] != null
|
|
259
|
+
narrowToComponentImporter: lockfile.importers?.[componentRootDir] != null,
|
|
260
|
+
cache
|
|
238
261
|
});
|
|
239
262
|
}
|
|
240
263
|
const componentDevImporter = lockfile.importers[componentRelativeDir];
|
|
@@ -256,8 +279,10 @@ function convertLockfileToGraph(lockfile, {
|
|
|
256
279
|
});
|
|
257
280
|
}
|
|
258
281
|
}
|
|
259
|
-
|
|
260
|
-
|
|
282
|
+
const snapshots = _objectSpread({}, lockfile.snapshots);
|
|
283
|
+
const packages = _objectSpread({}, lockfile.packages);
|
|
284
|
+
delete snapshots[lockedPkgDepPath];
|
|
285
|
+
delete packages[dp.removeSuffix(lockedPkgDepPath)];
|
|
261
286
|
// Scrub back-edges from a circular workspace dep (another workspace
|
|
262
287
|
// component depending on the one we're processing). Otherwise the
|
|
263
288
|
// back-edge survives buildEdges but its target — the just-deleted
|
|
@@ -265,34 +290,76 @@ function convertLockfileToGraph(lockfile, {
|
|
|
265
290
|
// convertGraphToLockfile would later materialise that neighbour as an
|
|
266
291
|
// empty packages entry and ask the registry for the workspace
|
|
267
292
|
// snap-version, which may never have been published.
|
|
268
|
-
for (const snapshot of Object.
|
|
293
|
+
for (const [depPath, snapshot] of Object.entries(snapshots)) {
|
|
294
|
+
let snapshotCopied = false;
|
|
295
|
+
let currentSnapshot = snapshot;
|
|
269
296
|
for (const depType of ['dependencies', 'optionalDependencies']) {
|
|
270
|
-
const deps =
|
|
297
|
+
const deps = currentSnapshot[depType];
|
|
271
298
|
if (deps?.[pkgName] === lockedFileVersion) {
|
|
272
|
-
|
|
273
|
-
|
|
299
|
+
if (!snapshotCopied) {
|
|
300
|
+
currentSnapshot = _objectSpread({}, currentSnapshot);
|
|
301
|
+
snapshots[depPath] = currentSnapshot;
|
|
302
|
+
snapshotCopied = true;
|
|
303
|
+
}
|
|
304
|
+
const nextDeps = _objectSpread({}, deps);
|
|
305
|
+
delete nextDeps[pkgName];
|
|
306
|
+
if (Object.keys(nextDeps).length === 0) {
|
|
307
|
+
delete currentSnapshot[depType];
|
|
308
|
+
} else {
|
|
309
|
+
currentSnapshot[depType] = nextDeps;
|
|
310
|
+
}
|
|
274
311
|
}
|
|
275
312
|
}
|
|
276
313
|
}
|
|
277
|
-
return _convertLockfileToGraph(lockfile, {
|
|
314
|
+
return _convertLockfileToGraph(_objectSpread(_objectSpread({}, lockfile), {}, {
|
|
315
|
+
snapshots,
|
|
316
|
+
packages
|
|
317
|
+
}), {
|
|
278
318
|
componentIdByPkgName,
|
|
279
319
|
directDependencies,
|
|
280
|
-
replaceFileVersion
|
|
320
|
+
replaceFileVersion,
|
|
321
|
+
cache
|
|
281
322
|
});
|
|
282
323
|
}
|
|
283
324
|
function _convertLockfileToGraph(lockfile, {
|
|
284
325
|
componentIdByPkgName,
|
|
285
326
|
directDependencies,
|
|
286
|
-
replaceFileVersion
|
|
327
|
+
replaceFileVersion,
|
|
328
|
+
cache
|
|
287
329
|
}) {
|
|
330
|
+
let resolvedReplacer = replaceFileVersion;
|
|
331
|
+
if (cache) {
|
|
332
|
+
const depsRequiringBuild = lockfile.bit?.depsRequiringBuild;
|
|
333
|
+
let isContextChanged = replaceFileVersion != null && cache.replaceFileVersion != null && cache.replaceFileVersion !== replaceFileVersion;
|
|
334
|
+
if (cache.componentIdByPkgName !== componentIdByPkgName || cache.depsRequiringBuild !== depsRequiringBuild) {
|
|
335
|
+
const contextKey = getCacheContextKey(componentIdByPkgName, depsRequiringBuild);
|
|
336
|
+
if (cache.contextKey !== contextKey) {
|
|
337
|
+
isContextChanged = true;
|
|
338
|
+
cache.contextKey = contextKey;
|
|
339
|
+
}
|
|
340
|
+
cache.componentIdByPkgName = componentIdByPkgName;
|
|
341
|
+
cache.depsRequiringBuild = depsRequiringBuild;
|
|
342
|
+
}
|
|
343
|
+
if (isContextChanged) {
|
|
344
|
+
cache.edges = new WeakMap();
|
|
345
|
+
cache.packages = new WeakMap();
|
|
346
|
+
cache.replaceFileVersion = undefined;
|
|
347
|
+
}
|
|
348
|
+
resolvedReplacer ??= cache.replaceFileVersion ?? createFileVersionReplacer(componentIdByPkgName);
|
|
349
|
+
cache.replaceFileVersion = resolvedReplacer;
|
|
350
|
+
} else {
|
|
351
|
+
resolvedReplacer ??= createFileVersionReplacer(componentIdByPkgName);
|
|
352
|
+
}
|
|
288
353
|
const graph = new (_objects().DependenciesGraph)({
|
|
289
354
|
edges: buildEdges(lockfile, {
|
|
290
355
|
directDependencies,
|
|
291
|
-
replaceFileVersion
|
|
356
|
+
replaceFileVersion: resolvedReplacer,
|
|
357
|
+
edgesCache: cache?.edges
|
|
292
358
|
}),
|
|
293
359
|
packages: buildPackages(lockfile, {
|
|
294
360
|
componentIdByPkgName,
|
|
295
|
-
replaceFileVersion
|
|
361
|
+
replaceFileVersion: resolvedReplacer,
|
|
362
|
+
packagesCache: cache?.packages
|
|
296
363
|
}),
|
|
297
364
|
pnpmfileChecksum: lockfile.pnpmfileChecksum,
|
|
298
365
|
lockfileSettings: lockfile.settings,
|
|
@@ -303,28 +370,40 @@ function _convertLockfileToGraph(lockfile, {
|
|
|
303
370
|
}
|
|
304
371
|
function buildEdges(lockfile, {
|
|
305
372
|
directDependencies,
|
|
306
|
-
replaceFileVersion
|
|
373
|
+
replaceFileVersion,
|
|
374
|
+
edgesCache
|
|
307
375
|
}) {
|
|
308
376
|
const edges = [];
|
|
309
377
|
for (const [depPath, snapshot] of Object.entries(lockfile.snapshots ?? {})) {
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
378
|
+
const cached = edgesCache?.get(snapshot);
|
|
379
|
+
let edge;
|
|
380
|
+
if (cached && cached.depPath === depPath) {
|
|
381
|
+
edge = cached.edge;
|
|
382
|
+
} else {
|
|
383
|
+
const neighbours = extractDependenciesFromSnapshot(snapshot, replaceFileVersion);
|
|
384
|
+
const replacedDepPath = replaceFileVersion(depPath);
|
|
385
|
+
const candidate = {
|
|
386
|
+
id: replacedDepPath,
|
|
387
|
+
neighbours
|
|
320
388
|
};
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
389
|
+
const pkgId = dp.removeSuffix(replacedDepPath);
|
|
390
|
+
if (pkgId !== replacedDepPath) {
|
|
391
|
+
candidate.attr = {
|
|
392
|
+
pkgId
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
if (snapshot.transitivePeerDependencies) {
|
|
396
|
+
candidate.attr = _objectSpread(_objectSpread({}, candidate.attr), {}, {
|
|
397
|
+
transitivePeerDependencies: snapshot.transitivePeerDependencies
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
edge = candidate.neighbours.length > 0 || candidate.id !== pkgId ? candidate : null;
|
|
401
|
+
edgesCache?.set(snapshot, {
|
|
402
|
+
depPath,
|
|
403
|
+
edge
|
|
325
404
|
});
|
|
326
405
|
}
|
|
327
|
-
if (edge
|
|
406
|
+
if (edge) {
|
|
328
407
|
edges.push(edge);
|
|
329
408
|
}
|
|
330
409
|
}
|
|
@@ -363,12 +442,18 @@ function extractDependenciesFromSnapshot(snapshot, replaceFileVersion) {
|
|
|
363
442
|
}
|
|
364
443
|
function buildPackages(lockfile, {
|
|
365
444
|
componentIdByPkgName,
|
|
366
|
-
replaceFileVersion
|
|
445
|
+
replaceFileVersion,
|
|
446
|
+
packagesCache
|
|
367
447
|
}) {
|
|
368
448
|
const depsRequiringBuild = lockfile.bit?.depsRequiringBuild;
|
|
369
449
|
const depsRequiringBuildSet = depsRequiringBuild ? new Set(depsRequiringBuild) : undefined;
|
|
370
450
|
const packages = new Map();
|
|
371
451
|
for (const [pkgId, pkg] of Object.entries(lockfile.packages ?? {})) {
|
|
452
|
+
const cached = packagesCache?.get(pkg);
|
|
453
|
+
if (cached && cached.pkgId === pkgId) {
|
|
454
|
+
packages.set(cached.replacedPkgId, cached.graphPkg);
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
372
457
|
const graphPkg = (0, _lodash().pick)(pkg, ['bundledDependencies', 'cpu', 'deprecated', 'engines', 'hasBin', 'libc', 'name', 'os', 'peerDependencies', 'peerDependenciesMeta', 'resolution', 'version']);
|
|
373
458
|
if (graphPkg.resolution.type === 'directory') {
|
|
374
459
|
delete graphPkg.resolution;
|
|
@@ -385,6 +470,11 @@ function buildPackages(lockfile, {
|
|
|
385
470
|
if (depsRequiringBuildSet?.has(pkgId)) {
|
|
386
471
|
graphPkg.requiresBuild = true;
|
|
387
472
|
}
|
|
473
|
+
packagesCache?.set(pkg, {
|
|
474
|
+
pkgId,
|
|
475
|
+
replacedPkgId,
|
|
476
|
+
graphPkg
|
|
477
|
+
});
|
|
388
478
|
packages.set(replacedPkgId, graphPkg);
|
|
389
479
|
}
|
|
390
480
|
return packages;
|
|
@@ -451,16 +541,11 @@ function filterLockfileByImporters(lockfile, importerIds, importersOverride) {
|
|
|
451
541
|
}
|
|
452
542
|
const filteredPackages = {};
|
|
453
543
|
for (const pkgId of reachablePackages) {
|
|
454
|
-
filteredPackages[pkgId] =
|
|
544
|
+
filteredPackages[pkgId] = lockfile.packages[pkgId];
|
|
455
545
|
}
|
|
456
546
|
const filteredSnapshots = {};
|
|
457
547
|
for (const depPath of reachableSnapshots) {
|
|
458
|
-
|
|
459
|
-
filteredSnapshots[depPath] = _objectSpread(_objectSpread(_objectSpread({}, snapshot), snapshot.dependencies ? {
|
|
460
|
-
dependencies: _objectSpread({}, snapshot.dependencies)
|
|
461
|
-
} : {}), snapshot.optionalDependencies ? {
|
|
462
|
-
optionalDependencies: _objectSpread({}, snapshot.optionalDependencies)
|
|
463
|
-
} : {});
|
|
548
|
+
filteredSnapshots[depPath] = lockfile.snapshots[depPath];
|
|
464
549
|
}
|
|
465
550
|
const filteredImporters = {};
|
|
466
551
|
for (const importerId of importerIds) {
|