@vltpkg/graph 0.0.0-3 → 0.0.0-31
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/README.md +148 -12
- package/dist/esm/actual/load.d.ts +49 -3
- package/dist/esm/actual/load.d.ts.map +1 -1
- package/dist/esm/actual/load.js +124 -73
- package/dist/esm/actual/load.js.map +1 -1
- package/dist/esm/browser.d.ts +8 -4
- package/dist/esm/browser.d.ts.map +1 -1
- package/dist/esm/browser.js +6 -2
- package/dist/esm/browser.js.map +1 -1
- package/dist/esm/build.d.ts +29 -0
- package/dist/esm/build.d.ts.map +1 -0
- package/dist/esm/build.js +79 -0
- package/dist/esm/build.js.map +1 -0
- package/dist/esm/dependencies.d.ts +14 -5
- package/dist/esm/dependencies.d.ts.map +1 -1
- package/dist/esm/dependencies.js +67 -2
- package/dist/esm/dependencies.js.map +1 -1
- package/dist/esm/diff.d.ts +67 -0
- package/dist/esm/diff.d.ts.map +1 -1
- package/dist/esm/diff.js +25 -0
- package/dist/esm/diff.js.map +1 -1
- package/dist/esm/edge.d.ts +8 -3
- package/dist/esm/edge.d.ts.map +1 -1
- package/dist/esm/edge.js +9 -1
- package/dist/esm/edge.js.map +1 -1
- package/dist/esm/graph.d.ts +22 -12
- package/dist/esm/graph.d.ts.map +1 -1
- package/dist/esm/graph.js +122 -23
- package/dist/esm/graph.js.map +1 -1
- package/dist/esm/ideal/add-nodes.d.ts +17 -2
- package/dist/esm/ideal/add-nodes.d.ts.map +1 -1
- package/dist/esm/ideal/add-nodes.js +15 -4
- package/dist/esm/ideal/add-nodes.js.map +1 -1
- package/dist/esm/ideal/append-nodes.d.ts +11 -1
- package/dist/esm/ideal/append-nodes.d.ts.map +1 -1
- package/dist/esm/ideal/append-nodes.js +176 -31
- package/dist/esm/ideal/append-nodes.js.map +1 -1
- package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts.map +1 -1
- package/dist/esm/ideal/build-ideal-from-starting-graph.js +9 -5
- package/dist/esm/ideal/build-ideal-from-starting-graph.js.map +1 -1
- package/dist/esm/ideal/build.d.ts +9 -0
- package/dist/esm/ideal/build.d.ts.map +1 -1
- package/dist/esm/ideal/build.js +4 -1
- package/dist/esm/ideal/build.js.map +1 -1
- package/dist/esm/ideal/get-importer-specs.d.ts +3 -2
- package/dist/esm/ideal/get-importer-specs.d.ts.map +1 -1
- package/dist/esm/ideal/get-importer-specs.js +7 -5
- package/dist/esm/ideal/get-importer-specs.js.map +1 -1
- package/dist/esm/index.d.ts +8 -4
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +4 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/install.d.ts +11 -5
- package/dist/esm/install.d.ts.map +1 -1
- package/dist/esm/install.js +167 -23
- package/dist/esm/install.js.map +1 -1
- package/dist/esm/lockfile/load-edges.d.ts +8 -1
- package/dist/esm/lockfile/load-edges.d.ts.map +1 -1
- package/dist/esm/lockfile/load-edges.js +79 -15
- package/dist/esm/lockfile/load-edges.js.map +1 -1
- package/dist/esm/lockfile/load-nodes.d.ts +3 -2
- package/dist/esm/lockfile/load-nodes.d.ts.map +1 -1
- package/dist/esm/lockfile/load-nodes.js +69 -12
- package/dist/esm/lockfile/load-nodes.js.map +1 -1
- package/dist/esm/lockfile/load.d.ts +18 -5
- package/dist/esm/lockfile/load.d.ts.map +1 -1
- package/dist/esm/lockfile/load.js +53 -22
- package/dist/esm/lockfile/load.js.map +1 -1
- package/dist/esm/lockfile/save.d.ts +12 -3
- package/dist/esm/lockfile/save.d.ts.map +1 -1
- package/dist/esm/lockfile/save.js +45 -16
- package/dist/esm/lockfile/save.js.map +1 -1
- package/dist/esm/lockfile/types.d.ts +33 -4
- package/dist/esm/lockfile/types.d.ts.map +1 -1
- package/dist/esm/lockfile/types.js +31 -0
- package/dist/esm/lockfile/types.js.map +1 -1
- package/dist/esm/modifiers.d.ts +189 -0
- package/dist/esm/modifiers.d.ts.map +1 -0
- package/dist/esm/modifiers.js +330 -0
- package/dist/esm/modifiers.js.map +1 -0
- package/dist/esm/node.d.ts +73 -6
- package/dist/esm/node.d.ts.map +1 -1
- package/dist/esm/node.js +94 -2
- package/dist/esm/node.js.map +1 -1
- package/dist/esm/reify/add-edge.d.ts +1 -1
- package/dist/esm/reify/add-edge.d.ts.map +1 -1
- package/dist/esm/reify/add-edge.js +36 -14
- package/dist/esm/reify/add-edge.js.map +1 -1
- package/dist/esm/reify/add-nodes.d.ts.map +1 -1
- package/dist/esm/reify/add-nodes.js +4 -27
- package/dist/esm/reify/add-nodes.js.map +1 -1
- package/dist/esm/reify/bin-paths.d.ts +1 -1
- package/dist/esm/reify/bin-paths.d.ts.map +1 -1
- package/dist/esm/reify/bin-paths.js.map +1 -1
- package/dist/esm/reify/build.d.ts +10 -1
- package/dist/esm/reify/build.d.ts.map +1 -1
- package/dist/esm/reify/build.js +36 -7
- package/dist/esm/reify/build.js.map +1 -1
- package/dist/esm/reify/calculate-save-value.d.ts +3 -0
- package/dist/esm/reify/calculate-save-value.d.ts.map +1 -0
- package/dist/esm/reify/calculate-save-value.js +45 -0
- package/dist/esm/reify/calculate-save-value.js.map +1 -0
- package/dist/esm/reify/check-needed-build.d.ts +25 -0
- package/dist/esm/reify/check-needed-build.d.ts.map +1 -0
- package/dist/esm/reify/check-needed-build.js +50 -0
- package/dist/esm/reify/check-needed-build.js.map +1 -0
- package/dist/esm/reify/delete-edge.js +1 -1
- package/dist/esm/reify/delete-edge.js.map +1 -1
- package/dist/esm/reify/delete-nodes.d.ts.map +1 -1
- package/dist/esm/reify/delete-nodes.js +4 -0
- package/dist/esm/reify/delete-nodes.js.map +1 -1
- package/dist/esm/reify/extract-node.d.ts +24 -0
- package/dist/esm/reify/extract-node.d.ts.map +1 -0
- package/dist/esm/reify/extract-node.js +76 -0
- package/dist/esm/reify/extract-node.js.map +1 -0
- package/dist/esm/reify/index.d.ts +18 -1
- package/dist/esm/reify/index.d.ts.map +1 -1
- package/dist/esm/reify/index.js +78 -13
- package/dist/esm/reify/index.js.map +1 -1
- package/dist/esm/reify/internal-hoist.d.ts +9 -0
- package/dist/esm/reify/internal-hoist.d.ts.map +1 -0
- package/dist/esm/reify/internal-hoist.js +121 -0
- package/dist/esm/reify/internal-hoist.js.map +1 -0
- package/dist/esm/reify/update-importers-package-json.d.ts +1 -1
- package/dist/esm/reify/update-importers-package-json.d.ts.map +1 -1
- package/dist/esm/reify/update-importers-package-json.js +35 -12
- package/dist/esm/reify/update-importers-package-json.js.map +1 -1
- package/dist/esm/remove-optional-subgraph.js +1 -1
- package/dist/esm/remove-optional-subgraph.js.map +1 -1
- package/dist/esm/resolve-save-type.d.ts +6 -0
- package/dist/esm/resolve-save-type.d.ts.map +1 -0
- package/dist/esm/resolve-save-type.js +5 -0
- package/dist/esm/resolve-save-type.js.map +1 -0
- package/dist/esm/stringify-node.d.ts +1 -1
- package/dist/esm/stringify-node.d.ts.map +1 -1
- package/dist/esm/stringify-node.js.map +1 -1
- package/dist/esm/transfer-data/load.d.ts +44 -0
- package/dist/esm/transfer-data/load.d.ts.map +1 -0
- package/dist/esm/transfer-data/load.js +176 -0
- package/dist/esm/transfer-data/load.js.map +1 -0
- package/dist/esm/uninstall.d.ts +8 -6
- package/dist/esm/uninstall.d.ts.map +1 -1
- package/dist/esm/uninstall.js +51 -22
- package/dist/esm/uninstall.js.map +1 -1
- package/dist/esm/update.d.ts +13 -0
- package/dist/esm/update.d.ts.map +1 -0
- package/dist/esm/update.js +63 -0
- package/dist/esm/update.js.map +1 -0
- package/dist/esm/virtual-root.d.ts +16 -0
- package/dist/esm/virtual-root.d.ts.map +1 -0
- package/dist/esm/virtual-root.js +79 -0
- package/dist/esm/virtual-root.js.map +1 -0
- package/dist/esm/visualization/human-readable-output.d.ts +4 -5
- package/dist/esm/visualization/human-readable-output.d.ts.map +1 -1
- package/dist/esm/visualization/human-readable-output.js +51 -24
- package/dist/esm/visualization/human-readable-output.js.map +1 -1
- package/dist/esm/visualization/json-output.d.ts +7 -3
- package/dist/esm/visualization/json-output.d.ts.map +1 -1
- package/dist/esm/visualization/json-output.js +35 -12
- package/dist/esm/visualization/json-output.js.map +1 -1
- package/dist/esm/visualization/mermaid-output.d.ts +7 -1
- package/dist/esm/visualization/mermaid-output.d.ts.map +1 -1
- package/dist/esm/visualization/mermaid-output.js +64 -9
- package/dist/esm/visualization/mermaid-output.js.map +1 -1
- package/dist/esm/visualization/object-like-output.d.ts +1 -1
- package/dist/esm/visualization/object-like-output.d.ts.map +1 -1
- package/dist/esm/visualization/object-like-output.js.map +1 -1
- package/package.json +30 -25
- package/dist/esm/types.d.ts +0 -39
- package/dist/esm/types.d.ts.map +0 -1
- package/dist/esm/types.js +0 -2
- package/dist/esm/types.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-edges.js","sourceRoot":"","sources":["../../../src/lockfile/load-edges.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAE3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"load-edges.js","sourceRoot":"","sources":["../../../src/lockfile/load-edges.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAE3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAMnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAc1D,MAAM,qBAAqB,GA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CAAC;AACH,CAAC,CAAA","sourcesContent":["import { asDepID } from '@vltpkg/dep-id/browser'\nimport { error } from '@vltpkg/error-cause'\nimport { fastSplit } from '@vltpkg/fast-split'\nimport { Spec } from '@vltpkg/spec/browser'\nimport type { SpecOptions } from '@vltpkg/spec/browser'\nimport { longDependencyTypes } from '@vltpkg/types'\nimport type {\n DependencyTypeShort,\n GraphLike,\n NodeLike,\n} from '@vltpkg/types'\nimport { isDependencyTypeShort } from '../dependencies.ts'\nimport type {\n LockfileData,\n LockfileEdgeKey,\n LockfileEdgeValue,\n} from './types.ts'\n\nexport type ProcessingEdge = {\n fromNode: NodeLike\n toNode: NodeLike | undefined\n depType: DependencyTypeShort\n spec: Spec\n}\n\nconst retrieveNodeFromGraph = (\n key: string,\n value: string,\n graph: GraphLike,\n fromId: string,\n seenNodes?: Map<string, NodeLike>,\n): NodeLike => {\n const foundNode = graph.nodes.get(asDepID(fromId))\n if (!foundNode) {\n throw error('Edge info missing its `from` node', {\n found: {\n nodes: [...graph.nodes].map(([id]) => id),\n from: foundNode,\n fromId,\n edge: { [key]: value },\n },\n })\n }\n if (seenNodes) {\n seenNodes.set(fromId, foundNode)\n }\n return foundNode\n}\n\nexport const loadEdges = (\n graph: GraphLike,\n edges: LockfileData['edges'],\n options: SpecOptions,\n) => {\n const entries = Object.entries(edges) as [\n LockfileEdgeKey,\n LockfileEdgeValue,\n ][]\n\n const edgeCount = entries.length\n // Only use optimizations for non-trivial graphs\n const useOptimizations = edgeCount > 50\n const edgeProcessingQueue: ProcessingEdge[] = []\n\n // Cache for frequently accessed nodes to avoid repeated Map lookups\n const seenNodes =\n useOptimizations ? new Map<string, NodeLike>() : undefined\n\n for (const [key, value] of entries) {\n const [fromId, specName] = fastSplit(key, ' ', 2)\n const [depType, valRest] = fastSplit(value, ' ', 2)\n const vrSplit = valRest?.lastIndexOf(' ') ?? -1\n\n // not a valid edge record\n /* c8 ignore start */\n if (!valRest || !depType || !fromId || !specName || vrSplit < 1) {\n continue\n }\n /* c8 ignore stop */\n\n // Validate dependency type early\n if (!isDependencyTypeShort(depType)) {\n throw error('Found unsupported dependency type in lockfile', {\n validOptions: [...longDependencyTypes],\n })\n }\n\n // Use cached node lookup for large graphs, direct lookup for small ones\n let fromNode: NodeLike\n if (seenNodes) {\n const seen = seenNodes.get(fromId)\n if (seen) {\n fromNode = seen\n } else {\n fromNode = retrieveNodeFromGraph(\n key,\n value,\n graph,\n fromId,\n seenNodes,\n )\n }\n } else {\n fromNode = retrieveNodeFromGraph(key, value, graph, fromId)\n }\n\n const toId = valRest.substring(vrSplit + 1)\n let toNode: NodeLike | undefined = undefined\n\n if (toId !== 'MISSING') {\n if (seenNodes) {\n const seen = seenNodes.get(toId)\n if (seen) {\n toNode = seen\n } else {\n toNode = graph.nodes.get(asDepID(toId))\n if (toNode) {\n seenNodes.set(toId, toNode)\n }\n }\n } else {\n toNode = graph.nodes.get(asDepID(toId))\n }\n }\n\n // Parse spec once we know the nodes are valid\n const spec = Spec.parse(\n specName,\n valRest.substring(0, vrSplit),\n options,\n )\n\n // sets a registry for this spec to inherit from\n spec.inheritedRegistry = fromNode.registry\n\n if (useOptimizations) {\n edgeProcessingQueue.push({\n fromNode,\n toNode,\n depType,\n spec,\n })\n } else {\n // Process immediately for small graphs\n graph.addEdge(depType, spec, fromNode, toNode)\n }\n }\n\n // Batch process all edges (only for non-trivial graphs)\n if (useOptimizations) {\n for (const {\n fromNode,\n toNode,\n depType,\n spec,\n } of edgeProcessingQueue) {\n graph.addEdge(depType, spec, fromNode, toNode)\n }\n }\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { LockfileData } from './types.ts';
|
|
2
|
-
import type { GraphLike } from '
|
|
3
|
-
|
|
2
|
+
import type { GraphLike } from '@vltpkg/types';
|
|
3
|
+
import type { SpecOptions } from '@vltpkg/spec/browser';
|
|
4
|
+
export declare const loadNodes: (graph: GraphLike, nodes: LockfileData["nodes"], options: SpecOptions, actual?: GraphLike) => void;
|
|
4
5
|
//# sourceMappingURL=load-nodes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-nodes.d.ts","sourceRoot":"","sources":["../../../src/lockfile/load-nodes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"load-nodes.d.ts","sourceRoot":"","sources":["../../../src/lockfile/load-nodes.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,YAAY,CAAA;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAEvD,eAAO,MAAM,SAAS,UACb,SAAS,SACT,YAAY,CAAC,OAAO,CAAC,WACnB,WAAW,WACX,SAAS,SA8GnB,CAAA"}
|
|
@@ -1,30 +1,87 @@
|
|
|
1
1
|
import { splitDepID } from '@vltpkg/dep-id/browser';
|
|
2
|
-
import { getBooleanFlagsFromNum } from "./types.js";
|
|
3
|
-
export const loadNodes = (graph, nodes) => {
|
|
2
|
+
import { getBooleanFlagsFromNum, getBuildStateFromNum, } from "./types.js";
|
|
3
|
+
export const loadNodes = (graph, nodes, options, actual) => {
|
|
4
4
|
const entries = Object.entries(nodes);
|
|
5
|
+
const nodeCount = entries.length;
|
|
6
|
+
// Batch process registry spec parsing (only for large graphs)
|
|
7
|
+
// Only used for non-trivial graphs
|
|
8
|
+
const registryVersionCache = nodeCount > 50 ? new Map() : null;
|
|
5
9
|
for (const [id, lockfileNode] of entries) {
|
|
10
|
+
const [flags, name, integrity, resolved, location, manifest, rawManifest, platform, buildState,] = lockfileNode;
|
|
6
11
|
// workspace nodes and the project root node are already part of the
|
|
7
12
|
// graph and it should not create new nodes if an existing one is there
|
|
8
13
|
if (graph.nodes.has(id))
|
|
9
14
|
continue;
|
|
10
|
-
const [
|
|
11
|
-
const
|
|
15
|
+
const [type, filepath, maybeExtra, lastExtra] = splitDepID(id);
|
|
16
|
+
const extra = type === 'registry' || type === 'git' ? lastExtra : maybeExtra;
|
|
17
|
+
const registrySpec = maybeExtra;
|
|
18
|
+
// The reference node is a node that matches the same id from the
|
|
19
|
+
// current iterating node in the provided `actual` graph, this allows
|
|
20
|
+
// for hydrating missing manifest, integrity, and resolved values
|
|
21
|
+
// that may be missing from the lockfile
|
|
22
|
+
const referenceNode = actual?.nodes.get(id);
|
|
23
|
+
const mani = manifest ?? referenceNode?.manifest;
|
|
24
|
+
// Optimize registry version extraction with caching for large graphs
|
|
25
|
+
let version;
|
|
26
|
+
if (type === 'registry' &&
|
|
27
|
+
registrySpec &&
|
|
28
|
+
registrySpec.indexOf('@') > 0) {
|
|
29
|
+
if (registryVersionCache) {
|
|
30
|
+
const seenVersion = registryVersionCache.get(registrySpec);
|
|
31
|
+
/* c8 ignore start */
|
|
32
|
+
if (seenVersion) {
|
|
33
|
+
version = seenVersion;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
version = registrySpec.split('@').slice(-1)[0] || undefined;
|
|
37
|
+
/* c8 ignore stop */
|
|
38
|
+
if (version) {
|
|
39
|
+
registryVersionCache.set(registrySpec, version);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
version = registrySpec.split('@').slice(-1)[0] || undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
12
47
|
// if the lockfile has manifest data then it should just use that
|
|
13
48
|
// otherwise tries to infer name / version value from the lockfile node
|
|
14
|
-
const node =
|
|
15
|
-
graph.addNode(id,
|
|
16
|
-
: graph.addNode(id, undefined, undefined, name ?? undefined,
|
|
17
|
-
|
|
18
|
-
|
|
49
|
+
const node = mani ?
|
|
50
|
+
graph.addNode(id, mani)
|
|
51
|
+
: graph.addNode(id, undefined, undefined, name ?? undefined, version);
|
|
52
|
+
if (extra) {
|
|
53
|
+
node.modifier = extra;
|
|
54
|
+
}
|
|
19
55
|
const { dev, optional } = getBooleanFlagsFromNum(flags);
|
|
56
|
+
node.options = options;
|
|
20
57
|
node.dev = dev;
|
|
21
58
|
node.optional = optional;
|
|
22
|
-
node.integrity = integrity ??
|
|
23
|
-
node.resolved = resolved ??
|
|
59
|
+
node.integrity = integrity ?? referenceNode?.integrity;
|
|
60
|
+
node.resolved = resolved ?? referenceNode?.resolved;
|
|
61
|
+
node.projectRoot = graph.projectRoot;
|
|
24
62
|
if (!node.resolved)
|
|
25
63
|
node.setResolved();
|
|
26
|
-
if (location)
|
|
64
|
+
if (location) {
|
|
27
65
|
node.location = location;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// set the location to file dependencies based on the id value
|
|
69
|
+
if (type === 'file') {
|
|
70
|
+
node.location = filepath;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (mani && rawManifest) {
|
|
74
|
+
node.setConfusedManifest(mani, rawManifest);
|
|
75
|
+
}
|
|
76
|
+
// Set platform data if provided
|
|
77
|
+
/* c8 ignore next 3 */
|
|
78
|
+
if (platform) {
|
|
79
|
+
node.platform = platform;
|
|
80
|
+
}
|
|
81
|
+
// Set build state if provided
|
|
82
|
+
if (buildState !== undefined && buildState !== null) {
|
|
83
|
+
node.buildState = getBuildStateFromNum(buildState);
|
|
84
|
+
}
|
|
28
85
|
}
|
|
29
86
|
};
|
|
30
87
|
//# sourceMappingURL=load-nodes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-nodes.js","sourceRoot":"","sources":["../../../src/lockfile/load-nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,
|
|
1
|
+
{"version":3,"file":"load-nodes.js","sourceRoot":"","sources":["../../../src/lockfile/load-nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EACL,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,YAAY,CAAA;AAMnB,MAAM,CAAC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AAS,GAAG,SAAS,IAAI,aAAa,EAAE,SAAS,CAAA;QACtD,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAI,aAAa,EAAE,QAAQ,CAAA;QACnD,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,WAAW,CAAA;QACpC,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,IAAI,CAAC,WAAW,EAAE,CAAA;QACtC,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QAC1B,CAAC;aAAM,CAAC;YACN,8DAA8D;YAC9D,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;gBACpB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;YAC1B,CAAC;QACH,CAAC;QACD,IAAI,IAAI,IAAI,WAAW,EAAE,CAAC;YACxB,IAAI,CAAC,mBAAmB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAA;QAC7C,CAAC;QAED,gCAAgC;QAChC,sBAAsB;QACtB,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QAC1B,CAAC;QAED,8BAA8B;QAC9B,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;YACpD,IAAI,CAAC,UAAU,GAAG,oBAAoB,CAAC,UAAU,CAAC,CAAA;QACpD,CAAC;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { splitDepID } from '@vltpkg/dep-id/browser'\nimport {\n getBooleanFlagsFromNum,\n getBuildStateFromNum,\n} from './types.ts'\nimport type { LockfileData, LockfileNode } from './types.ts'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { GraphLike } from '@vltpkg/types'\nimport type { SpecOptions } from '@vltpkg/spec/browser'\n\nexport const loadNodes = (\n graph: GraphLike,\n nodes: LockfileData['nodes'],\n options: SpecOptions,\n actual?: GraphLike,\n) => {\n const entries = Object.entries(nodes) as [DepID, LockfileNode][]\n const nodeCount = entries.length\n\n // Batch process registry spec parsing (only for large graphs)\n // Only used for non-trivial graphs\n const registryVersionCache =\n nodeCount > 50 ? new Map<string, string>() : null\n\n for (const [id, lockfileNode] of entries) {\n const [\n flags,\n name,\n integrity,\n resolved,\n location,\n manifest,\n rawManifest,\n platform,\n buildState,\n ] = lockfileNode\n // workspace nodes and the project root node are already part of the\n // graph and it should not create new nodes if an existing one is there\n if (graph.nodes.has(id)) continue\n\n const [type, filepath, maybeExtra, lastExtra] = splitDepID(id)\n const extra =\n type === 'registry' || type === 'git' ? lastExtra : maybeExtra\n const registrySpec = maybeExtra\n\n // The reference node is a node that matches the same id from the\n // current iterating node in the provided `actual` graph, this allows\n // for hydrating missing manifest, integrity, and resolved values\n // that may be missing from the lockfile\n const referenceNode = actual?.nodes.get(id)\n const mani = manifest ?? referenceNode?.manifest\n\n // Optimize registry version extraction with caching for large graphs\n let version: string | undefined\n if (\n type === 'registry' &&\n registrySpec &&\n registrySpec.indexOf('@') > 0\n ) {\n if (registryVersionCache) {\n const seenVersion = registryVersionCache.get(registrySpec)\n /* c8 ignore start */\n if (seenVersion) {\n version = seenVersion\n } else {\n version = registrySpec.split('@').slice(-1)[0] || undefined\n /* c8 ignore stop */\n if (version) {\n registryVersionCache.set(registrySpec, version)\n }\n }\n } else {\n version = registrySpec.split('@').slice(-1)[0] || undefined\n }\n }\n\n // if the lockfile has manifest data then it should just use that\n // otherwise tries to infer name / version value from the lockfile node\n const node =\n mani ?\n graph.addNode(id, mani)\n : graph.addNode(\n id,\n undefined,\n undefined,\n name ?? undefined,\n version,\n )\n\n if (extra) {\n node.modifier = extra\n }\n\n const { dev, optional } = getBooleanFlagsFromNum(flags)\n node.options = options\n node.dev = dev\n node.optional = optional\n node.integrity = integrity ?? referenceNode?.integrity\n node.resolved = resolved ?? referenceNode?.resolved\n node.projectRoot = graph.projectRoot\n if (!node.resolved) node.setResolved()\n if (location) {\n node.location = location\n } else {\n // set the location to file dependencies based on the id value\n if (type === 'file') {\n node.location = filepath\n }\n }\n if (mani && rawManifest) {\n node.setConfusedManifest(mani, rawManifest)\n }\n\n // Set platform data if provided\n /* c8 ignore next 3 */\n if (platform) {\n node.platform = platform\n }\n\n // Set build state if provided\n if (buildState !== undefined && buildState !== null) {\n node.buildState = getBuildStateFromNum(buildState)\n }\n }\n}\n"]}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { PackageJson } from '@vltpkg/package-json';
|
|
2
|
-
import type { Manifest } from '@vltpkg/types';
|
|
3
2
|
import { Monorepo } from '@vltpkg/workspaces';
|
|
4
|
-
import type { SpecOptions } from '@vltpkg/spec';
|
|
5
|
-
import type { PathScurry } from 'path-scurry';
|
|
6
3
|
import { Graph } from '../graph.ts';
|
|
4
|
+
import type { PathScurry } from 'path-scurry';
|
|
5
|
+
import type { NormalizedManifest } from '@vltpkg/types';
|
|
6
|
+
import type { SpecOptions } from '@vltpkg/spec';
|
|
7
7
|
import type { LockfileData } from './types.ts';
|
|
8
|
+
import type { GraphModifier } from '../modifiers.ts';
|
|
8
9
|
export type LoadOptions = SpecOptions & {
|
|
10
|
+
/**
|
|
11
|
+
* An optional {@link Graph} object to hydrate extra data from.
|
|
12
|
+
*/
|
|
13
|
+
actual?: Graph;
|
|
9
14
|
/**
|
|
10
15
|
* The project root dirname.
|
|
11
16
|
*/
|
|
@@ -13,7 +18,11 @@ export type LoadOptions = SpecOptions & {
|
|
|
13
18
|
/**
|
|
14
19
|
* The project root manifest.
|
|
15
20
|
*/
|
|
16
|
-
mainManifest:
|
|
21
|
+
mainManifest: NormalizedManifest;
|
|
22
|
+
/**
|
|
23
|
+
* The graph modifiers helper object.
|
|
24
|
+
*/
|
|
25
|
+
modifiers?: GraphModifier;
|
|
17
26
|
/**
|
|
18
27
|
* A {@link Monorepo} object, for managing workspaces
|
|
19
28
|
*/
|
|
@@ -26,8 +35,12 @@ export type LoadOptions = SpecOptions & {
|
|
|
26
35
|
* A {@link PathScurry} object, for use in globs
|
|
27
36
|
*/
|
|
28
37
|
scurry?: PathScurry;
|
|
38
|
+
/**
|
|
39
|
+
* Load only importers into the graph if the modifiers have changed.
|
|
40
|
+
*/
|
|
41
|
+
skipLoadingNodesOnModifiersChange?: boolean;
|
|
29
42
|
};
|
|
30
43
|
export declare const load: (options: LoadOptions) => Graph;
|
|
31
44
|
export declare const loadHidden: (options: LoadOptions) => Graph;
|
|
32
|
-
export declare const loadObject: (options: LoadOptions, lockfileData: LockfileData) => Graph;
|
|
45
|
+
export declare const loadObject: (options: LoadOptions, lockfileData: Omit<LockfileData, "options" | "lockfileVersion"> & Partial<Pick<LockfileData, "options" | "lockfileVersion">>) => Graph;
|
|
33
46
|
//# sourceMappingURL=load.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../../src/lockfile/load.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,
|
|
1
|
+
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../../src/lockfile/load.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAK7C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAEpD,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACtC;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,CAAA;IACd;;OAEG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,YAAY,EAAE,kBAAkB,CAAA;IAChC;;OAEG;IACH,SAAS,CAAC,EAAE,aAAa,CAAA;IACzB;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB;;OAEG;IACH,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB;;OAEG;IACH,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB;;OAEG;IACH,iCAAiC,CAAC,EAAE,OAAO,CAAA;CAC5C,CAAA;AASD,eAAO,MAAM,IAAI,YAAa,WAAW,KAAG,KAM3C,CAAA;AAED,eAAO,MAAM,UAAU,YAAa,WAAW,KAAG,KAMjD,CAAA;AAED,eAAO,MAAM,UAAU,YACZ,WAAW,gBACN,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,iBAAiB,CAAC,GAC7D,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,iBAAiB,CAAC,CAAC,UAmG7D,CAAA"}
|
|
@@ -17,40 +17,71 @@ export const loadHidden = (options) => {
|
|
|
17
17
|
return loadObject(options, loadLockfile(projectRoot, 'node_modules/.vlt-lock.json'));
|
|
18
18
|
};
|
|
19
19
|
export const loadObject = (options, lockfileData) => {
|
|
20
|
-
const { mainManifest, scurry } = options;
|
|
20
|
+
const { mainManifest, modifiers, scurry, skipLoadingNodesOnModifiersChange, } = options;
|
|
21
21
|
const packageJson = options.packageJson ?? new PackageJson();
|
|
22
22
|
const monorepo = options.monorepo ??
|
|
23
23
|
Monorepo.maybeLoad(options.projectRoot, { packageJson, scurry });
|
|
24
|
-
const { 'scope-registries': scopeRegistries, registry, registries, 'git-hosts': gitHosts, 'git-host-archives': gitHostArchives,
|
|
25
|
-
|
|
26
|
-
} = lockfileData.options
|
|
24
|
+
const { catalog = {}, catalogs = {}, modifiers: modifiersLockfileConfig, 'scope-registries': scopeRegistries, registry, registries, 'git-hosts': gitHosts, 'git-host-archives': gitHostArchives,
|
|
25
|
+
/* c8 ignore next */
|
|
26
|
+
} = lockfileData.options ?? {};
|
|
27
|
+
// Optimize options merging - only create new objects when needed
|
|
27
28
|
const mergedOptions = {
|
|
28
29
|
...options,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
catalog,
|
|
31
|
+
catalogs,
|
|
32
|
+
'scope-registries': scopeRegistries ?
|
|
33
|
+
{ ...options['scope-registries'], ...scopeRegistries }
|
|
34
|
+
: options['scope-registries'],
|
|
33
35
|
registry: registry ?? options.registry,
|
|
34
|
-
registries:
|
|
35
|
-
...options.registries,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
...options['git-host-archives'],
|
|
44
|
-
...gitHostArchives,
|
|
45
|
-
},
|
|
36
|
+
registries: registries ?
|
|
37
|
+
{ ...options.registries, ...registries }
|
|
38
|
+
: options.registries,
|
|
39
|
+
'git-hosts': gitHosts ?
|
|
40
|
+
{ ...options['git-hosts'], ...gitHosts }
|
|
41
|
+
: options['git-hosts'],
|
|
42
|
+
'git-host-archives': gitHostArchives ?
|
|
43
|
+
{ ...options['git-host-archives'], ...gitHostArchives }
|
|
44
|
+
: options['git-host-archives'],
|
|
46
45
|
};
|
|
47
46
|
const graph = new Graph({
|
|
48
47
|
...mergedOptions,
|
|
49
48
|
mainManifest,
|
|
50
49
|
monorepo,
|
|
51
50
|
});
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
// When using the skipLoadingNodesOnModifiersChange option, we should skip loading
|
|
52
|
+
// dependencies in case the modifiers have changed since we'll need to
|
|
53
|
+
// recalculate the graph - useful for refreshing an ideal graph when
|
|
54
|
+
// modifiers are swapped.
|
|
55
|
+
// Optimize modifier comparison - avoid JSON.stringify for simple cases
|
|
56
|
+
let modifiersChanged = false;
|
|
57
|
+
if (skipLoadingNodesOnModifiersChange) {
|
|
58
|
+
const lockfileConfig = modifiersLockfileConfig ?? {};
|
|
59
|
+
const optionsConfig = modifiers?.config ?? {};
|
|
60
|
+
// Quick check for obvious differences
|
|
61
|
+
const lockfileKeys = Object.keys(lockfileConfig);
|
|
62
|
+
const optionsKeys = Object.keys(optionsConfig);
|
|
63
|
+
if (lockfileKeys.length !== optionsKeys.length) {
|
|
64
|
+
modifiersChanged = true;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// Only use JSON.stringify if we need deep comparison
|
|
68
|
+
const lockfileModifiers = JSON.stringify(lockfileConfig);
|
|
69
|
+
const optionsModifiers = JSON.stringify(optionsConfig);
|
|
70
|
+
modifiersChanged = lockfileModifiers !== optionsModifiers;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const shouldLoadDependencies = !(skipLoadingNodesOnModifiersChange && modifiersChanged);
|
|
74
|
+
if (shouldLoadDependencies) {
|
|
75
|
+
loadNodes(graph, lockfileData.nodes, mergedOptions, options.actual);
|
|
76
|
+
loadEdges(graph, lockfileData.edges, mergedOptions);
|
|
77
|
+
}
|
|
78
|
+
// hydrate missing node-level registry data
|
|
79
|
+
for (const node of graph.nodes.values()) {
|
|
80
|
+
const [firstEdge] = node.edgesIn;
|
|
81
|
+
if (firstEdge?.spec.registry) {
|
|
82
|
+
node.registry = firstEdge.spec.registry;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
54
85
|
return graph;
|
|
55
86
|
};
|
|
56
87
|
//# sourceMappingURL=load.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load.js","sourceRoot":"","sources":["../../../src/lockfile/load.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"load.js","sourceRoot":"","sources":["../../../src/lockfile/load.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE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port { Monorepo } from '@vltpkg/workspaces'\nimport { readFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { loadEdges } from './load-edges.ts'\nimport { loadNodes } from './load-nodes.ts'\nimport { Graph } from '../graph.ts'\nimport type { PathScurry } from 'path-scurry'\nimport type { NormalizedManifest } from '@vltpkg/types'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport type { LockfileData } from './types.ts'\nimport type { GraphModifier } from '../modifiers.ts'\n\nexport type LoadOptions = SpecOptions & {\n /**\n * An optional {@link Graph} object to hydrate extra data from.\n */\n actual?: Graph\n /**\n * The project root dirname.\n */\n projectRoot: string\n /**\n * The project root manifest.\n */\n mainManifest: NormalizedManifest\n /**\n * The graph modifiers helper object.\n */\n modifiers?: GraphModifier\n /**\n * A {@link Monorepo} object, for managing workspaces\n */\n monorepo?: Monorepo\n /**\n * A {@link PackageJson} object, for sharing manifest caches\n */\n packageJson?: PackageJson\n /**\n * A {@link PathScurry} object, for use in globs\n */\n scurry?: PathScurry\n /**\n * Load only importers into the graph if the modifiers have changed.\n */\n skipLoadingNodesOnModifiersChange?: boolean\n}\n\nconst loadLockfile = (projectRoot: string, lockfilePath: string) =>\n JSON.parse(\n readFileSync(resolve(projectRoot, lockfilePath), {\n encoding: 'utf8',\n }),\n ) as LockfileData\n\nexport const load = (options: LoadOptions): Graph => {\n const { projectRoot } = options\n return loadObject(\n options,\n loadLockfile(projectRoot, 'vlt-lock.json'),\n )\n}\n\nexport const loadHidden = (options: LoadOptions): Graph => {\n const { projectRoot } = options\n return loadObject(\n options,\n loadLockfile(projectRoot, 'node_modules/.vlt-lock.json'),\n )\n}\n\nexport const loadObject = (\n options: LoadOptions,\n lockfileData: Omit<LockfileData, 'options' | 'lockfileVersion'> &\n Partial<Pick<LockfileData, 'options' | 'lockfileVersion'>>,\n) => {\n const {\n mainManifest,\n modifiers,\n scurry,\n skipLoadingNodesOnModifiersChange,\n } = options\n const packageJson = options.packageJson ?? new PackageJson()\n const monorepo =\n options.monorepo ??\n Monorepo.maybeLoad(options.projectRoot, { packageJson, scurry })\n const {\n catalog = {},\n catalogs = {},\n modifiers: modifiersLockfileConfig,\n 'scope-registries': scopeRegistries,\n registry,\n registries,\n 'git-hosts': gitHosts,\n 'git-host-archives': gitHostArchives,\n /* c8 ignore next */\n } = lockfileData.options ?? {}\n\n // Optimize options merging - only create new objects when needed\n const mergedOptions = {\n ...options,\n catalog,\n catalogs,\n 'scope-registries':\n scopeRegistries ?\n { ...options['scope-registries'], ...scopeRegistries }\n : options['scope-registries'],\n registry: registry ?? options.registry,\n registries:\n registries ?\n { ...options.registries, ...registries }\n : options.registries,\n 'git-hosts':\n gitHosts ?\n { ...options['git-hosts'], ...gitHosts }\n : options['git-hosts'],\n 'git-host-archives':\n gitHostArchives ?\n { ...options['git-host-archives'], ...gitHostArchives }\n : options['git-host-archives'],\n }\n const graph = new Graph({\n ...mergedOptions,\n mainManifest,\n monorepo,\n })\n\n // When using the skipLoadingNodesOnModifiersChange option, we should skip loading\n // dependencies in case the modifiers have changed since we'll need to\n // recalculate the graph - useful for refreshing an ideal graph when\n // modifiers are swapped.\n\n // Optimize modifier comparison - avoid JSON.stringify for simple cases\n let modifiersChanged = false\n if (skipLoadingNodesOnModifiersChange) {\n const lockfileConfig = modifiersLockfileConfig ?? {}\n const optionsConfig = modifiers?.config ?? {}\n\n // Quick check for obvious differences\n const lockfileKeys = Object.keys(lockfileConfig)\n const optionsKeys = Object.keys(optionsConfig)\n\n if (lockfileKeys.length !== optionsKeys.length) {\n modifiersChanged = true\n } else {\n // Only use JSON.stringify if we need deep comparison\n const lockfileModifiers = JSON.stringify(lockfileConfig)\n const optionsModifiers = JSON.stringify(optionsConfig)\n modifiersChanged = lockfileModifiers !== optionsModifiers\n }\n }\n const shouldLoadDependencies = !(\n skipLoadingNodesOnModifiersChange && modifiersChanged\n )\n if (shouldLoadDependencies) {\n loadNodes(\n graph,\n lockfileData.nodes,\n mergedOptions,\n options.actual,\n )\n loadEdges(graph, lockfileData.edges, mergedOptions)\n }\n\n // hydrate missing node-level registry data\n for (const node of graph.nodes.values()) {\n const [firstEdge] = node.edgesIn\n if (firstEdge?.spec.registry) {\n node.registry = firstEdge.spec.registry\n }\n }\n\n return graph\n}\n"]}
|
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
import type { SpecOptions } from '@vltpkg/spec';
|
|
2
2
|
import type { Graph } from '../graph.ts';
|
|
3
3
|
import type { LockfileData } from './types.ts';
|
|
4
|
+
import type { GraphModifier } from '../modifiers.ts';
|
|
4
5
|
export type SaveOptions = SpecOptions & {
|
|
5
6
|
/**
|
|
6
7
|
* The graph to be stored in the lockfile.
|
|
7
8
|
*/
|
|
8
9
|
graph: Graph;
|
|
10
|
+
/**
|
|
11
|
+
* The graph modifiers helper object.
|
|
12
|
+
*/
|
|
13
|
+
modifiers?: GraphModifier;
|
|
9
14
|
/**
|
|
10
15
|
* Should it save manifest data in the lockfile?
|
|
11
16
|
*/
|
|
12
17
|
saveManifests?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Should it save build state data in the lockfile?
|
|
20
|
+
*/
|
|
21
|
+
saveBuildData?: boolean;
|
|
13
22
|
};
|
|
14
|
-
export declare const lockfileData: ({ graph, "git-hosts": gitHosts, "git-host-archives": gitHostArchives, registry, registries, saveManifests, "scope-registries": scopeRegistries, }: SaveOptions) => LockfileData;
|
|
23
|
+
export declare const lockfileData: ({ graph, catalog, catalogs, "git-hosts": gitHosts, "git-host-archives": gitHostArchives, modifiers, registry, registries, saveManifests, saveBuildData, "scope-registries": scopeRegistries, "jsr-registries": jsrRegistries, }: SaveOptions) => LockfileData;
|
|
15
24
|
export declare const saveData: (data: LockfileData, fileName: string, saveManifests?: boolean) => void;
|
|
16
|
-
export declare const save: (options: SaveOptions) => void;
|
|
17
|
-
export declare const saveHidden: (options: SaveOptions) => void;
|
|
25
|
+
export declare const save: (options: Omit<SaveOptions, "saveManifests">) => void;
|
|
26
|
+
export declare const saveHidden: (options: Omit<SaveOptions, "saveManifests" | "saveBuildData">) => void;
|
|
18
27
|
//# sourceMappingURL=save.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../../../src/lockfile/save.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../../../src/lockfile/save.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,KAAK,EACV,YAAY,EAMb,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAEpD,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACtC;;OAEG;IACH,KAAK,EAAE,KAAK,CAAA;IACZ;;OAEG;IACH,SAAS,CAAC,EAAE,aAAa,CAAA;IACzB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,CAAA;AAuGD,eAAO,MAAM,YAAY,oOAatB,WAAW,KAAG,YA8DhB,CAAA;AAeD,eAAO,MAAM,QAAQ,SACb,YAAY,YACR,MAAM,8BAEf,IAIF,CAAA;AAED,eAAO,MAAM,IAAI,YACN,IAAI,CAAC,WAAW,EAAE,eAAe,CAAC,KAC1C,IAKF,CAAA;AAED,eAAO,MAAM,UAAU,YACZ,IAAI,CAAC,WAAW,EAAE,eAAe,GAAG,eAAe,CAAC,KAC5D,IAaF,CAAA"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { expandNormalizedManifestSymbols, isRecordStringString, } from '@vltpkg/types';
|
|
2
|
+
import { defaultGitHostArchives, defaultGitHosts, defaultJsrRegistries, defaultRegistries, defaultRegistry, defaultScopeRegistries, } from '@vltpkg/spec';
|
|
2
3
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
3
4
|
import { dirname, resolve } from 'node:path';
|
|
4
|
-
import { getFlagNumFromNode } from "./types.js";
|
|
5
|
-
const formatNodes = (nodes, saveManifests, registry) => {
|
|
5
|
+
import { getFlagNumFromNode, getBuildStateFromNode } from "./types.js";
|
|
6
|
+
const formatNodes = (nodes, saveManifests, saveBuildData, registry) => {
|
|
6
7
|
// we do not store importers in the lockfile, though we do store
|
|
7
8
|
// their edges. when we load, we always read workspaces/main fresh.
|
|
8
9
|
const arr = [...nodes].filter(node => !node.importer);
|
|
@@ -13,11 +14,7 @@ const formatNodes = (nodes, saveManifests, registry) => {
|
|
|
13
14
|
const customRegistry = node.resolved && registry && !node.resolved.startsWith(registry);
|
|
14
15
|
const resolved = customRegistry ? node.resolved : undefined;
|
|
15
16
|
// if it's in a location other than the default, stash that
|
|
16
|
-
const location =
|
|
17
|
-
node.location.endsWith('/node_modules/.vlt/' +
|
|
18
|
-
node.id +
|
|
19
|
-
'/node_modules/' +
|
|
20
|
-
node.name)) ?
|
|
17
|
+
const location = node.id.startsWith('file') || node.inVltStore() ?
|
|
21
18
|
undefined
|
|
22
19
|
: node.location;
|
|
23
20
|
const flags = getFlagNumFromNode(node);
|
|
@@ -31,8 +28,22 @@ const formatNodes = (nodes, saveManifests, registry) => {
|
|
|
31
28
|
if (location) {
|
|
32
29
|
lockfileNode[4] = location;
|
|
33
30
|
}
|
|
34
|
-
if (saveManifests) {
|
|
35
|
-
lockfileNode[5] = node.manifest;
|
|
31
|
+
if (saveManifests && node.manifest) {
|
|
32
|
+
lockfileNode[5] = expandNormalizedManifestSymbols(node.manifest);
|
|
33
|
+
if (node.confused && node.rawManifest) {
|
|
34
|
+
lockfileNode[6] = expandNormalizedManifestSymbols(node.rawManifest);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Always save platform data for optional dependencies if available
|
|
38
|
+
if (node.optional && node.platform) {
|
|
39
|
+
lockfileNode[7] = node.platform;
|
|
40
|
+
}
|
|
41
|
+
// Save build state data if requested
|
|
42
|
+
if (saveBuildData) {
|
|
43
|
+
const buildState = getBuildStateFromNode(node);
|
|
44
|
+
if (buildState !== undefined) {
|
|
45
|
+
lockfileNode[8] = buildState;
|
|
46
|
+
}
|
|
36
47
|
}
|
|
37
48
|
res[node.id] = lockfileNode;
|
|
38
49
|
}
|
|
@@ -51,7 +62,6 @@ Number(b.from.importer) - Number(a.from.importer) ||
|
|
|
51
62
|
`${edge.from.id} ${edge.spec.name}`,
|
|
52
63
|
`${edge.type} ${edge.spec.bareSpec || '*'} ${edge.to?.id ?? 'MISSING'}`,
|
|
53
64
|
]));
|
|
54
|
-
const isRecordStringString = (registries) => !(!registries || typeof registries === 'string');
|
|
55
65
|
const removeDefaultItems = (defaultItems, items) => {
|
|
56
66
|
const res = {};
|
|
57
67
|
for (const [key, value] of Object.entries(items)) {
|
|
@@ -61,25 +71,40 @@ const removeDefaultItems = (defaultItems, items) => {
|
|
|
61
71
|
}
|
|
62
72
|
return res;
|
|
63
73
|
};
|
|
64
|
-
export const lockfileData = ({ graph, 'git-hosts': gitHosts, 'git-host-archives': gitHostArchives, registry, registries, saveManifests, 'scope-registries': scopeRegistries, }) => {
|
|
74
|
+
export const lockfileData = ({ graph, catalog, catalogs, 'git-hosts': gitHosts, 'git-host-archives': gitHostArchives, modifiers, registry, registries, saveManifests, saveBuildData, 'scope-registries': scopeRegistries, 'jsr-registries': jsrRegistries, }) => {
|
|
65
75
|
const cleanGitHosts = isRecordStringString(gitHosts) ?
|
|
66
76
|
removeDefaultItems(defaultGitHosts, gitHosts)
|
|
67
77
|
: undefined;
|
|
68
78
|
const cleanGitHostArchives = isRecordStringString(gitHostArchives) ?
|
|
69
79
|
removeDefaultItems(defaultGitHostArchives, gitHostArchives)
|
|
70
80
|
: undefined;
|
|
81
|
+
const cleanModifiers = modifiers && isRecordStringString(modifiers.config) ?
|
|
82
|
+
modifiers.config
|
|
83
|
+
: undefined;
|
|
71
84
|
const cleanRegistries = isRecordStringString(registries) ?
|
|
72
85
|
removeDefaultItems(defaultRegistries, registries)
|
|
73
86
|
: undefined;
|
|
74
87
|
const cleanScopeRegistries = isRecordStringString(scopeRegistries) ?
|
|
75
88
|
removeDefaultItems(defaultScopeRegistries, scopeRegistries)
|
|
76
89
|
: undefined;
|
|
90
|
+
const cleanJsrRegistries = isRecordStringString(jsrRegistries) ?
|
|
91
|
+
removeDefaultItems(defaultJsrRegistries, jsrRegistries)
|
|
92
|
+
: undefined;
|
|
77
93
|
const hasItems = (clean) => clean && Object.keys(clean).length;
|
|
78
94
|
return {
|
|
95
|
+
lockfileVersion: 0,
|
|
79
96
|
options: {
|
|
97
|
+
...(hasItems(cleanModifiers) ?
|
|
98
|
+
{ modifiers: cleanModifiers }
|
|
99
|
+
: {}),
|
|
100
|
+
...(hasItems(catalog) ? { catalog } : {}),
|
|
101
|
+
...(hasItems(catalogs) ? { catalogs } : {}),
|
|
80
102
|
...(hasItems(cleanScopeRegistries) ?
|
|
81
103
|
{ 'scope-registries': cleanScopeRegistries }
|
|
82
104
|
: undefined),
|
|
105
|
+
...(hasItems(cleanJsrRegistries) ?
|
|
106
|
+
{ 'jsr-registries': cleanJsrRegistries }
|
|
107
|
+
: undefined),
|
|
83
108
|
...(registry !== undefined && registry !== defaultRegistry ?
|
|
84
109
|
{ registry }
|
|
85
110
|
: undefined),
|
|
@@ -93,7 +118,7 @@ export const lockfileData = ({ graph, 'git-hosts': gitHosts, 'git-host-archives'
|
|
|
93
118
|
{ 'git-host-archives': cleanGitHostArchives }
|
|
94
119
|
: undefined),
|
|
95
120
|
},
|
|
96
|
-
nodes: formatNodes(graph.nodes.values(), saveManifests, registry),
|
|
121
|
+
nodes: formatNodes(graph.nodes.values(), saveManifests, saveBuildData, registry),
|
|
97
122
|
edges: formatEdges(graph.edges),
|
|
98
123
|
};
|
|
99
124
|
};
|
|
@@ -116,13 +141,17 @@ export const save = (options) => {
|
|
|
116
141
|
const { graph } = options;
|
|
117
142
|
const data = lockfileData({ ...options, saveManifests: false });
|
|
118
143
|
const fileName = resolve(graph.projectRoot, 'vlt-lock.json');
|
|
119
|
-
|
|
144
|
+
saveData(data, fileName, false);
|
|
120
145
|
};
|
|
121
146
|
export const saveHidden = (options) => {
|
|
122
147
|
const { graph } = options;
|
|
123
|
-
const data = lockfileData({
|
|
148
|
+
const data = lockfileData({
|
|
149
|
+
...options,
|
|
150
|
+
saveManifests: true,
|
|
151
|
+
saveBuildData: true,
|
|
152
|
+
});
|
|
124
153
|
const fileName = resolve(graph.projectRoot, 'node_modules/.vlt-lock.json');
|
|
125
154
|
mkdirSync(dirname(fileName), { recursive: true });
|
|
126
|
-
|
|
155
|
+
saveData(data, fileName, true);
|
|
127
156
|
};
|
|
128
157
|
//# sourceMappingURL=save.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save.js","sourceRoot":"","sources":["../../../src/lockfile/save.ts"],"names":[],"mappings":"AACA,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAI5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAoB/C,MAAM,WAAW,GAAG,CAClB,KAAqB,EACrB,aAAuB,EACvB,QAAiB,EACjB,EAAE;IACF,gEAAgE;IAChE,mEAAmE;IACnE,MAAM,GAAG,GAAW,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC7D,2DAA2D;IAC3D,MAAM,YAAY,GAAW,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAC7C,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,CAA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C,CAAA;AACvC,CAAC,CAAA","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport {\n defaultRegistry,\n defaultRegistries,\n defaultGitHosts,\n defaultGitHostArchives,\n defaultScopeRegistries,\n} from '@vltpkg/spec'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport { mkdirSync, writeFileSync } from 'node:fs'\nimport { dirname, resolve } from 'node:path'\nimport type { Edge } from '../edge.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\nimport { getFlagNumFromNode } from './types.ts'\nimport type {\n LockfileData,\n LockfileEdgeKey,\n LockfileEdges,\n LockfileEdgeValue,\n LockfileNode,\n} from './types.ts'\n\nexport type SaveOptions = SpecOptions & {\n /**\n * The graph to be stored in the lockfile.\n */\n graph: Graph\n /**\n * Should it save manifest data in the lockfile?\n */\n saveManifests?: boolean\n}\n\nconst formatNodes = (\n nodes: Iterable<Node>,\n saveManifests?: boolean,\n registry?: string,\n) => {\n // we do not store importers in the lockfile, though we do store\n // their edges. when we load, we always read workspaces/main fresh.\n const arr: Node[] = [...nodes].filter(node => !node.importer)\n // nodes are sorted in order to have a deterministic result\n const orderedNodes: Node[] = arr.sort((a, b) =>\n a.id.localeCompare(b.id, 'en'),\n )\n\n const res: Record<DepID, LockfileNode> = {}\n for (const node of orderedNodes) {\n const customRegistry =\n node.resolved && registry && !node.resolved.startsWith(registry)\n const resolved = customRegistry ? node.resolved : undefined\n // if it's in a location other than the default, stash that\n const location =\n (\n node.id.startsWith('file') ||\n node.location.endsWith(\n '/node_modules/.vlt/' +\n node.id +\n '/node_modules/' +\n node.name,\n )\n ) ?\n undefined\n : node.location\n\n const flags = getFlagNumFromNode(node)\n const lockfileNode: LockfileNode = [flags, node.name]\n\n if (node.integrity) {\n lockfileNode[2] = node.integrity\n }\n\n if (resolved) {\n lockfileNode[3] = resolved\n }\n\n if (location) {\n lockfileNode[4] = location\n }\n\n if (saveManifests) {\n lockfileNode[5] = node.manifest\n }\n\n res[node.id] = lockfileNode\n }\n return res\n}\n\nconst formatEdges = (edges: Set<Edge>): LockfileEdges =>\n Object.fromEntries(\n [...edges]\n .sort(\n (a, b) =>\n /* c8 ignore start - nondeterminstic and annoying to test */\n // sort importers to the top, then alphabetically by\n // id, type, target\n Number(b.from.importer) - Number(a.from.importer) ||\n a.from.id.localeCompare(b.from.id, 'en') ||\n a.type.localeCompare(b.type, 'en') ||\n (a.to?.id ?? '').localeCompare(b.to?.id ?? ''),\n /* c8 ignore stop */\n )\n .map((edge): [LockfileEdgeKey, LockfileEdgeValue] => [\n `${edge.from.id} ${edge.spec.name}`,\n `${edge.type} ${edge.spec.bareSpec || '*'} ${edge.to?.id ?? 'MISSING'}`,\n ]),\n )\n\nconst isRecordStringString = (\n registries: unknown,\n): registries is Record<string, string> =>\n !(!registries || typeof registries === 'string')\n\nconst removeDefaultItems = (\n defaultItems: Record<string, string>,\n items: Record<string, string>,\n) => {\n const res: Record<string, string> = {}\n for (const [key, value] of Object.entries(items)) {\n if (!defaultItems[key] || defaultItems[key] !== value) {\n res[key] = value\n }\n }\n return res\n}\n\nexport const lockfileData = ({\n graph,\n 'git-hosts': gitHosts,\n 'git-host-archives': gitHostArchives,\n registry,\n registries,\n saveManifests,\n 'scope-registries': scopeRegistries,\n}: SaveOptions): LockfileData => {\n const cleanGitHosts =\n isRecordStringString(gitHosts) ?\n removeDefaultItems(defaultGitHosts, gitHosts)\n : undefined\n const cleanGitHostArchives =\n isRecordStringString(gitHostArchives) ?\n removeDefaultItems(defaultGitHostArchives, gitHostArchives)\n : undefined\n const cleanRegistries =\n isRecordStringString(registries) ?\n removeDefaultItems(defaultRegistries, registries)\n : undefined\n const cleanScopeRegistries =\n isRecordStringString(scopeRegistries) ?\n removeDefaultItems(defaultScopeRegistries, scopeRegistries)\n : undefined\n const hasItems = (clean: Record<string, string> | undefined) =>\n clean && Object.keys(clean).length\n return {\n options: {\n ...(hasItems(cleanScopeRegistries) ?\n { 'scope-registries': cleanScopeRegistries }\n : undefined),\n ...(registry !== undefined && registry !== defaultRegistry ?\n { registry }\n : undefined),\n ...(hasItems(registries) ?\n { registries: cleanRegistries }\n : undefined),\n ...(hasItems(cleanGitHosts) ?\n { 'git-hosts': cleanGitHosts }\n : undefined),\n ...(hasItems(cleanGitHostArchives) ?\n { 'git-host-archives': cleanGitHostArchives }\n : undefined),\n },\n nodes: formatNodes(graph.nodes.values(), saveManifests, registry),\n edges: formatEdges(graph.edges),\n }\n}\n\n// renders each node / edge as a single line entry\nconst extraFormat = (jsonString: string) => {\n const str = `${jsonString}\\n`\n const [init, ...parts] = str.split(' \"nodes\": {')\n const res = [init]\n for (const part of parts) {\n res.push(\n part.replaceAll('\\n ', '').replaceAll('\\n ]', ']'),\n )\n }\n return res.join(' \"nodes\": {')\n}\n\nexport const saveData = (\n data: LockfileData,\n fileName: string,\n saveManifests = false,\n) => {\n const json = JSON.stringify(data, null, 2)\n const content = saveManifests ? json : extraFormat(json)\n writeFileSync(fileName, content)\n}\n\nexport const save = (options: SaveOptions) => {\n const { graph } = options\n const data = lockfileData({ ...options, saveManifests: false })\n const fileName = resolve(graph.projectRoot, 'vlt-lock.json')\n return saveData(data, fileName, false)\n}\n\nexport const saveHidden = (options: SaveOptions) => {\n const { graph } = options\n const data = lockfileData({ ...options, saveManifests: true })\n const fileName = resolve(\n graph.projectRoot,\n 'node_modules/.vlt-lock.json',\n )\n mkdirSync(dirname(fileName), { recursive: true })\n return saveData(data, fileName, true)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"save.js","sourceRoot":"","sources":["../../../src/lockfile/save.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,oBAAoB,GACrB,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,eAAe,EACf,sBAAsB,GACvB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAClD,OA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Q,EAAE,KAAK,CAAC,CAAA;AACjC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,OAA6D,EACvD,EAAE;IACR,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAA;IACzB,MAAM,IAAI,GAAG,YAAY,CAAC;QACxB,GAAG,OAAO;QACV,aAAa,EAAE,IAAI;QACnB,aAAa,EAAE,IAAI;KACpB,CAAC,CAAA;IACF,MAAM,QAAQ,GAAG,OAAO,CACtB,KAAK,CAAC,WAAW,EACjB,6BAA6B,CAC9B,CAAA;IACD,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IACjD,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;AAChC,CAAC,CAAA","sourcesContent":["import {\n expandNormalizedManifestSymbols,\n isRecordStringString,\n} from '@vltpkg/types'\nimport {\n defaultGitHostArchives,\n defaultGitHosts,\n defaultJsrRegistries,\n defaultRegistries,\n defaultRegistry,\n defaultScopeRegistries,\n} from '@vltpkg/spec'\nimport { mkdirSync, writeFileSync } from 'node:fs'\nimport { dirname, resolve } from 'node:path'\nimport { getFlagNumFromNode, getBuildStateFromNode } from './types.ts'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport type { Edge } from '../edge.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\nimport type {\n LockfileData,\n LockfileEdgeKey,\n LockfileEdges,\n LockfileEdgeValue,\n LockfileNode,\n LockfilePlatform,\n} from './types.ts'\nimport type { GraphModifier } from '../modifiers.ts'\n\nexport type SaveOptions = SpecOptions & {\n /**\n * The graph to be stored in the lockfile.\n */\n graph: Graph\n /**\n * The graph modifiers helper object.\n */\n modifiers?: GraphModifier\n /**\n * Should it save manifest data in the lockfile?\n */\n saveManifests?: boolean\n /**\n * Should it save build state data in the lockfile?\n */\n saveBuildData?: boolean\n}\n\nconst formatNodes = (\n nodes: Iterable<Node>,\n saveManifests?: boolean,\n saveBuildData?: boolean,\n registry?: string,\n) => {\n // we do not store importers in the lockfile, though we do store\n // their edges. when we load, we always read workspaces/main fresh.\n const arr: Node[] = [...nodes].filter(node => !node.importer)\n // nodes are sorted in order to have a deterministic result\n const orderedNodes: Node[] = arr.sort((a, b) =>\n a.id.localeCompare(b.id, 'en'),\n )\n\n const res: Record<DepID, LockfileNode> = {}\n for (const node of orderedNodes) {\n const customRegistry =\n node.resolved && registry && !node.resolved.startsWith(registry)\n const resolved = customRegistry ? node.resolved : undefined\n // if it's in a location other than the default, stash that\n const location =\n node.id.startsWith('file') || node.inVltStore() ?\n undefined\n : node.location\n\n const flags = getFlagNumFromNode(node)\n const lockfileNode: LockfileNode = [flags, node.name]\n\n if (node.integrity) {\n lockfileNode[2] = node.integrity\n }\n\n if (resolved) {\n lockfileNode[3] = resolved\n }\n\n if (location) {\n lockfileNode[4] = location\n }\n\n if (saveManifests && node.manifest) {\n lockfileNode[5] = expandNormalizedManifestSymbols(node.manifest)\n\n if (node.confused && node.rawManifest) {\n lockfileNode[6] = expandNormalizedManifestSymbols(\n node.rawManifest,\n )\n }\n }\n\n // Always save platform data for optional dependencies if available\n if (node.optional && node.platform) {\n lockfileNode[7] = node.platform as LockfilePlatform\n }\n\n // Save build state data if requested\n if (saveBuildData) {\n const buildState = getBuildStateFromNode(node)\n if (buildState !== undefined) {\n lockfileNode[8] = buildState\n }\n }\n\n res[node.id] = lockfileNode\n }\n return res\n}\n\nconst formatEdges = (edges: Set<Edge>): LockfileEdges =>\n Object.fromEntries(\n [...edges]\n .sort(\n (a, b) =>\n /* c8 ignore start - nondeterminstic and annoying to test */\n // sort importers to the top, then alphabetically by\n // id, type, target\n Number(b.from.importer) - Number(a.from.importer) ||\n a.from.id.localeCompare(b.from.id, 'en') ||\n a.type.localeCompare(b.type, 'en') ||\n (a.to?.id ?? '').localeCompare(b.to?.id ?? ''),\n /* c8 ignore stop */\n )\n .map((edge): [LockfileEdgeKey, LockfileEdgeValue] => [\n `${edge.from.id} ${edge.spec.name}`,\n `${edge.type} ${edge.spec.bareSpec || '*'} ${edge.to?.id ?? 'MISSING'}`,\n ]),\n )\n\nconst removeDefaultItems = (\n defaultItems: Record<string, string>,\n items: Record<string, string>,\n) => {\n const res: Record<string, string> = {}\n for (const [key, value] of Object.entries(items)) {\n if (!defaultItems[key] || defaultItems[key] !== value) {\n res[key] = value\n }\n }\n return res\n}\n\nexport const lockfileData = ({\n graph,\n catalog,\n catalogs,\n 'git-hosts': gitHosts,\n 'git-host-archives': gitHostArchives,\n modifiers,\n registry,\n registries,\n saveManifests,\n saveBuildData,\n 'scope-registries': scopeRegistries,\n 'jsr-registries': jsrRegistries,\n}: SaveOptions): LockfileData => {\n const cleanGitHosts =\n isRecordStringString(gitHosts) ?\n removeDefaultItems(defaultGitHosts, gitHosts)\n : undefined\n const cleanGitHostArchives =\n isRecordStringString(gitHostArchives) ?\n removeDefaultItems(defaultGitHostArchives, gitHostArchives)\n : undefined\n const cleanModifiers =\n modifiers && isRecordStringString(modifiers.config) ?\n modifiers.config\n : undefined\n const cleanRegistries =\n isRecordStringString(registries) ?\n removeDefaultItems(defaultRegistries, registries)\n : undefined\n const cleanScopeRegistries =\n isRecordStringString(scopeRegistries) ?\n removeDefaultItems(defaultScopeRegistries, scopeRegistries)\n : undefined\n const cleanJsrRegistries =\n isRecordStringString(jsrRegistries) ?\n removeDefaultItems(defaultJsrRegistries, jsrRegistries)\n : undefined\n const hasItems = (clean: Record<string, unknown> | undefined) =>\n clean && Object.keys(clean).length\n return {\n lockfileVersion: 0,\n options: {\n ...(hasItems(cleanModifiers) ?\n { modifiers: cleanModifiers }\n : {}),\n ...(hasItems(catalog) ? { catalog } : {}),\n ...(hasItems(catalogs) ? { catalogs } : {}),\n ...(hasItems(cleanScopeRegistries) ?\n { 'scope-registries': cleanScopeRegistries }\n : undefined),\n ...(hasItems(cleanJsrRegistries) ?\n { 'jsr-registries': cleanJsrRegistries }\n : undefined),\n ...(registry !== undefined && registry !== defaultRegistry ?\n { registry }\n : undefined),\n ...(hasItems(registries) ?\n { registries: cleanRegistries }\n : undefined),\n ...(hasItems(cleanGitHosts) ?\n { 'git-hosts': cleanGitHosts }\n : undefined),\n ...(hasItems(cleanGitHostArchives) ?\n { 'git-host-archives': cleanGitHostArchives }\n : undefined),\n },\n nodes: formatNodes(\n graph.nodes.values(),\n saveManifests,\n saveBuildData,\n registry,\n ),\n edges: formatEdges(graph.edges),\n }\n}\n\n// renders each node / edge as a single line entry\nconst extraFormat = (jsonString: string) => {\n const str = `${jsonString}\\n`\n const [init, ...parts] = str.split(' \"nodes\": {')\n const res = [init]\n for (const part of parts) {\n res.push(\n part.replaceAll('\\n ', '').replaceAll('\\n ]', ']'),\n )\n }\n return res.join(' \"nodes\": {')\n}\n\nexport const saveData = (\n data: LockfileData,\n fileName: string,\n saveManifests = false,\n): void => {\n const json = JSON.stringify(data, null, 2)\n const content = saveManifests ? json : extraFormat(json)\n writeFileSync(fileName, content)\n}\n\nexport const save = (\n options: Omit<SaveOptions, 'saveManifests'>,\n): void => {\n const { graph } = options\n const data = lockfileData({ ...options, saveManifests: false })\n const fileName = resolve(graph.projectRoot, 'vlt-lock.json')\n saveData(data, fileName, false)\n}\n\nexport const saveHidden = (\n options: Omit<SaveOptions, 'saveManifests' | 'saveBuildData'>,\n): void => {\n const { graph } = options\n const data = lockfileData({\n ...options,\n saveManifests: true,\n saveBuildData: true,\n })\n const fileName = resolve(\n graph.projectRoot,\n 'node_modules/.vlt-lock.json',\n )\n mkdirSync(dirname(fileName), { recursive: true })\n saveData(data, fileName, true)\n}\n"]}
|