@vltpkg/graph 0.0.0-24 → 0.0.0-25

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.
@@ -41,14 +41,14 @@ export declare class Diff {
41
41
  /** Edges in the `from` graph that are not found in the `to` graph */
42
42
  delete: Set<Edge>;
43
43
  };
44
+ /**
45
+ * True if the diff only contains optional nodes (computed during construction)
46
+ */
47
+ optionalOnly: boolean;
44
48
  get [Symbol.toStringTag](): string;
45
49
  constructor(from: Graph, to: Graph);
46
50
  [kCustomInspect](_: number, options?: InspectOptions): string;
47
51
  hasChanges(): boolean;
48
- /**
49
- * Return true if the diff only contains optional nodes.
50
- */
51
- optionalOnly(): boolean;
52
52
  }
53
53
  export {};
54
54
  //# sourceMappingURL=diff.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/diff.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAOrC,QAAA,MAAM,cAAc,eAA2C,CAAA;AAE/D;;;;;;;;;;GAUG;AACH,qBAAa,IAAI;IACf,IAAI,EAAE,KAAK,CAAA;IACX,EAAE,EAAE,KAAK,CAAA;IAET,WAAW,EAAE,MAAM,CAAA;IAEnB;;;OAGG;IACH,mBAAmB,UAAQ;IAE3B;;OAEG;IACH,KAAK;QACH,+DAA+D;;QAE/D,+DAA+D;;MAEhE;IAED;;OAEG;IACH,KAAK;QACH,qEAAqE;;QAErE,qEAAqE;;MAEtE;IAED,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAEvB;gBAEW,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK;IAyClC,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,MAAM;IAwC7D,UAAU,IAAI,OAAO;IASrB;;OAEG;IACH,YAAY,IAAI,OAAO;CAMxB"}
1
+ {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/diff.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAOrC,QAAA,MAAM,cAAc,eAA2C,CAAA;AAE/D;;;;;;;;;;GAUG;AACH,qBAAa,IAAI;IACf,IAAI,EAAE,KAAK,CAAA;IACX,EAAE,EAAE,KAAK,CAAA;IAET,WAAW,EAAE,MAAM,CAAA;IAEnB;;;OAGG;IACH,mBAAmB,UAAQ;IAE3B;;OAEG;IACH,KAAK;QACH,+DAA+D;;QAE/D,+DAA+D;;MAEhE;IAED;;OAEG;IACH,KAAK;QACH,qEAAqE;;QAErE,qEAAqE;;MAEtE;IAED;;OAEG;IACH,YAAY,UAAO;IAEnB,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAEvB;gBAEW,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK;IA0ClC,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,MAAM;IAwC7D,UAAU,IAAI,OAAO;CAQtB"}
package/dist/esm/diff.js CHANGED
@@ -42,6 +42,10 @@ export class Diff {
42
42
  /** Edges in the `from` graph that are not found in the `to` graph */
43
43
  delete: new Set(),
44
44
  };
45
+ /**
46
+ * True if the diff only contains optional nodes (computed during construction)
47
+ */
48
+ optionalOnly = true;
45
49
  get [Symbol.toStringTag]() {
46
50
  return '@vltpkg/graph.Diff';
47
51
  }
@@ -63,6 +67,8 @@ export class Diff {
63
67
  for (const [id, node] of this.to.nodes) {
64
68
  if (!this.from.nodes.get(id)?.equals(node)) {
65
69
  this.nodes.add.add(node);
70
+ if (!node.optional)
71
+ this.optionalOnly = false;
66
72
  }
67
73
  }
68
74
  for (const edge of this.to.edges) {
@@ -125,15 +131,5 @@ ${lines
125
131
  this.edges.add.size > 0 ||
126
132
  this.edges.delete.size > 0);
127
133
  }
128
- /**
129
- * Return true if the diff only contains optional nodes.
130
- */
131
- optionalOnly() {
132
- for (const node of this.nodes.add) {
133
- if (!node.optional)
134
- return false;
135
- }
136
- return true;
137
- }
138
134
  }
139
135
  //# sourceMappingURL=diff.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"diff.js","sourceRoot":"","sources":["../../src/diff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAM3C,uDAAuD;AACvD,6EAA6E;AAC7E,4BAA4B;AAC5B,wBAAwB;AAExB,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAA;AAE/D;;;;;;;;;;GAUG;AACH,MAAM,OAAO,IAAI;IACf,IAAI,CAAO;IACX,EAAE,CAAO;IAET,WAAW,CAAQ;IAEnB;;;OAGG;IACH,mBAAmB,GAAG,KAAK,CAAA;IAE3B;;OAEG;IACH,KAAK,GAAG;QACN,+DAA+D;QAC/D,GAAG,EAAE,IAAI,GAAG,EAAQ;QACpB,+DAA+D;QAC/D,MAAM,EAAE,IAAI,GAAG,EAAQ;KACxB,CAAA;IAED;;OAEG;IACH,KAAK,GAAG;QACN,qEAAqE;QACrE,GAAG,EAAE,IAAI,GAAG,EAAQ;QACpB,qEAAqE;QACrE,MAAM,EAAE,IAAI,GAAG,EAAQ;KACxB,CAAA;IAED,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,oBAAoB,CAAA;IAC7B,CAAC;IAED,YA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AC,CAAC,CAAA;QAC1D,MAAM,KAAK,GACT,OAAO,EAAE,MAAM,CAAC,CAAC;YACf,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;YACzD,CAAC,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAA;QAEpB,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;EACpC,KAAK;aACJ,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;aAClE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;aACzB,IAAI,CAAC,IAAI,CAAC;EACX,CAAA;IACA,CAAC;IAED,UAAU;QACR,OAAO,CACL,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;YACvB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC;YAC1B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;YACvB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAC3B,CAAA;IACH,CAAC;IAED;;OAEG;IACH,YAAY;QACV,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;YAClC,IAAI,CAAC,IAAI,CAAC,QAAQ;gBAAE,OAAO,KAAK,CAAA;QAClC,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport type { InspectOptions } from 'node:util'\nimport type { Edge } from './edge.ts'\nimport type { Graph } from './graph.ts'\nimport type { Node } from './node.ts'\n\n// XXX should file deps *always* be considered changed?\n// unless the thing containing it wasn't possibly changed because it's inside\n// a dep that didn't change?\n// Same with remote deps\n\nconst kCustomInspect = Symbol.for('nodejs.util.inspect.custom')\n\n/**\n * A Diff object is a representation of a set of changes from one\n * graph to another, typically from the actual graph as it is reified\n * on disk, to an intended ideal graph.\n *\n * The naming convention can get a bit confusing here, because it's a\n * set of directed changes from one set of directed objects to another.\n *\n * Within the context the Diff object, `from` is the Graph we're coming from,\n * and `to` is the Graph we're trying to create.\n */\nexport class Diff {\n from: Graph\n to: Graph\n\n projectRoot: string\n\n /**\n * If changes need to be made later for failures of optional nodes,\n * set this flag so that we know to call graph.gc() at the appropriate time.\n */\n hadOptionalFailures = false\n\n /**\n * Collection of nodes to add and delete\n */\n nodes = {\n /** Nodes in the `to` graph that are not in the `from` graph */\n add: new Set<Node>(),\n /** Nodes in the `from` graph that are not in the `to` graph */\n delete: new Set<Node>(),\n }\n\n /**\n * Collection of nodes to add and delete\n */\n edges = {\n /** Edges in the `to` graph that are not found in the `from` graph */\n add: new Set<Edge>(),\n /** Edges in the `from` graph that are not found in the `to` graph */\n delete: new Set<Edge>(),\n }\n\n get [Symbol.toStringTag]() {\n return '@vltpkg/graph.Diff'\n }\n\n constructor(from: Graph, to: Graph) {\n this.from = from\n this.to = to\n this.projectRoot = from.projectRoot\n if (to.projectRoot !== from.projectRoot) {\n throw error('projectRoot mismatch in Graph diff', {\n wanted: from.projectRoot,\n found: to.projectRoot,\n })\n }\n\n for (const [id, node] of this.from.nodes) {\n if (!this.to.nodes.get(id)?.equals(node)) {\n this.nodes.delete.add(node)\n }\n }\n\n for (const [id, node] of this.to.nodes) {\n if (!this.from.nodes.get(id)?.equals(node)) {\n this.nodes.add.add(node)\n }\n }\n\n for (const edge of this.to.edges) {\n // the node with this dep, in the from graph\n const fromNode = this.from.nodes.get(edge.from.id)\n const fromEdge = fromNode?.edgesOut.get(edge.spec.name)\n if (fromEdge?.to?.id === edge.to?.id) continue\n if (fromEdge?.to) this.edges.delete.add(fromEdge)\n if (edge.to) this.edges.add.add(edge)\n }\n for (const edge of this.from.edges) {\n // the node with this dep, in the to graph\n const toNode = this.to.nodes.get(edge.from.id)\n const toEdge = toNode?.edgesOut.get(edge.spec.name)\n if (toEdge?.to?.id === edge.to?.id) continue\n if (edge.to) this.edges.delete.add(edge)\n if (toEdge?.to) this.edges.add.add(toEdge)\n }\n }\n\n [kCustomInspect](_: number, options?: InspectOptions): string {\n const red: [string, string] =\n options?.colors ? ['\\x1b[31m', '\\x1b[m'] : ['', '']\n const green: [string, string] =\n options?.colors ? ['\\x1b[32m', '\\x1b[m'] : ['', '']\n const lines: string[] = []\n for (const node of this.nodes.add) {\n lines.push(`+ ${node.id}`)\n }\n for (const node of this.nodes.delete) {\n lines.push(`- ${node.id}`)\n }\n for (const edge of this.edges.add) {\n /* c8 ignore next */\n const to = edge.to?.id ?? ''\n lines.push(\n `+ ${edge.from.id} ${edge.type} ${edge.spec} ${to}`.trim(),\n )\n }\n for (const edge of this.edges.delete) {\n /* c8 ignore next */\n const to = edge.to?.id ?? ''\n lines.push(\n `- ${edge.from.id} ${edge.type} ${edge.spec} ${to}`.trim(),\n )\n }\n const wrap = (s: string, c: [string, string]) => c.join(s)\n const color =\n options?.colors ?\n (s: string) => wrap(s, s.startsWith('+') ? green : red)\n : (s: string) => s\n\n return `${this[Symbol.toStringTag]} {\n${lines\n .sort((a, b) => a.substring(1).localeCompare(b.substring(1), 'en'))\n .map(s => ' ' + color(s))\n .join('\\n')}\n}`\n }\n\n hasChanges(): boolean {\n return (\n this.nodes.add.size > 0 ||\n this.nodes.delete.size > 0 ||\n this.edges.add.size > 0 ||\n this.edges.delete.size > 0\n )\n }\n\n /**\n * Return true if the diff only contains optional nodes.\n */\n optionalOnly(): boolean {\n for (const node of this.nodes.add) {\n if (!node.optional) return false\n }\n return true\n }\n}\n"]}
1
+ {"version":3,"file":"diff.js","sourceRoot":"","s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AAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;aAClE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;aACzB,IAAI,CAAC,IAAI,CAAC;EACX,CAAA;IACA,CAAC;IAED,UAAU;QACR,OAAO,CACL,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;YACvB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC;YAC1B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;YACvB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAC3B,CAAA;IACH,CAAC;CACF","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport type { InspectOptions } from 'node:util'\nimport type { Edge } from './edge.ts'\nimport type { Graph } from './graph.ts'\nimport type { Node } from './node.ts'\n\n// XXX should file deps *always* be considered changed?\n// unless the thing containing it wasn't possibly changed because it's inside\n// a dep that didn't change?\n// Same with remote deps\n\nconst kCustomInspect = Symbol.for('nodejs.util.inspect.custom')\n\n/**\n * A Diff object is a representation of a set of changes from one\n * graph to another, typically from the actual graph as it is reified\n * on disk, to an intended ideal graph.\n *\n * The naming convention can get a bit confusing here, because it's a\n * set of directed changes from one set of directed objects to another.\n *\n * Within the context the Diff object, `from` is the Graph we're coming from,\n * and `to` is the Graph we're trying to create.\n */\nexport class Diff {\n from: Graph\n to: Graph\n\n projectRoot: string\n\n /**\n * If changes need to be made later for failures of optional nodes,\n * set this flag so that we know to call graph.gc() at the appropriate time.\n */\n hadOptionalFailures = false\n\n /**\n * Collection of nodes to add and delete\n */\n nodes = {\n /** Nodes in the `to` graph that are not in the `from` graph */\n add: new Set<Node>(),\n /** Nodes in the `from` graph that are not in the `to` graph */\n delete: new Set<Node>(),\n }\n\n /**\n * Collection of nodes to add and delete\n */\n edges = {\n /** Edges in the `to` graph that are not found in the `from` graph */\n add: new Set<Edge>(),\n /** Edges in the `from` graph that are not found in the `to` graph */\n delete: new Set<Edge>(),\n }\n\n /**\n * True if the diff only contains optional nodes (computed during construction)\n */\n optionalOnly = true\n\n get [Symbol.toStringTag]() {\n return '@vltpkg/graph.Diff'\n }\n\n constructor(from: Graph, to: Graph) {\n this.from = from\n this.to = to\n this.projectRoot = from.projectRoot\n if (to.projectRoot !== from.projectRoot) {\n throw error('projectRoot mismatch in Graph diff', {\n wanted: from.projectRoot,\n found: to.projectRoot,\n })\n }\n\n for (const [id, node] of this.from.nodes) {\n if (!this.to.nodes.get(id)?.equals(node)) {\n this.nodes.delete.add(node)\n }\n }\n\n for (const [id, node] of this.to.nodes) {\n if (!this.from.nodes.get(id)?.equals(node)) {\n this.nodes.add.add(node)\n if (!node.optional) this.optionalOnly = false\n }\n }\n\n for (const edge of this.to.edges) {\n // the node with this dep, in the from graph\n const fromNode = this.from.nodes.get(edge.from.id)\n const fromEdge = fromNode?.edgesOut.get(edge.spec.name)\n if (fromEdge?.to?.id === edge.to?.id) continue\n if (fromEdge?.to) this.edges.delete.add(fromEdge)\n if (edge.to) this.edges.add.add(edge)\n }\n for (const edge of this.from.edges) {\n // the node with this dep, in the to graph\n const toNode = this.to.nodes.get(edge.from.id)\n const toEdge = toNode?.edgesOut.get(edge.spec.name)\n if (toEdge?.to?.id === edge.to?.id) continue\n if (edge.to) this.edges.delete.add(edge)\n if (toEdge?.to) this.edges.add.add(toEdge)\n }\n }\n\n [kCustomInspect](_: number, options?: InspectOptions): string {\n const red: [string, string] =\n options?.colors ? ['\\x1b[31m', '\\x1b[m'] : ['', '']\n const green: [string, string] =\n options?.colors ? ['\\x1b[32m', '\\x1b[m'] : ['', '']\n const lines: string[] = []\n for (const node of this.nodes.add) {\n lines.push(`+ ${node.id}`)\n }\n for (const node of this.nodes.delete) {\n lines.push(`- ${node.id}`)\n }\n for (const edge of this.edges.add) {\n /* c8 ignore next */\n const to = edge.to?.id ?? ''\n lines.push(\n `+ ${edge.from.id} ${edge.type} ${edge.spec} ${to}`.trim(),\n )\n }\n for (const edge of this.edges.delete) {\n /* c8 ignore next */\n const to = edge.to?.id ?? ''\n lines.push(\n `- ${edge.from.id} ${edge.type} ${edge.spec} ${to}`.trim(),\n )\n }\n const wrap = (s: string, c: [string, string]) => c.join(s)\n const color =\n options?.colors ?\n (s: string) => wrap(s, s.startsWith('+') ? green : red)\n : (s: string) => s\n\n return `${this[Symbol.toStringTag]} {\n${lines\n .sort((a, b) => a.substring(1).localeCompare(b.substring(1), 'en'))\n .map(s => ' ' + color(s))\n .join('\\n')}\n}`\n }\n\n hasChanges(): boolean {\n return (\n this.nodes.add.size > 0 ||\n this.nodes.delete.size > 0 ||\n this.edges.add.size > 0 ||\n this.edges.delete.size > 0\n )\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"append-nodes.d.ts","sourceRoot":"","sources":["../../../src/ideal/append-nodes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAE7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAO/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEtC,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EACpB,MAAM,iBAAiB,CAAA;AA4TxB;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,QACjB,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,eACf,iBAAiB,SACvB,KAAK,YACF,IAAI,QACR,UAAU,EAAE,UACV,UAAU,WACT,WAAW,QACd,GAAG,CAAC,KAAK,CAAC,cACJ,aAAa,iBACV,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,kBAqEhD,CAAA"}
1
+ {"version":3,"file":"append-nodes.d.ts","sourceRoot":"","sources":["../../../src/ideal/append-nodes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAE7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAO/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEtC,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EACpB,MAAM,iBAAiB,CAAA;AA0UxB;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,QACjB,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,eACf,iBAAiB,SACvB,KAAK,YACF,IAAI,QACR,UAAU,EAAE,UACV,UAAU,WACT,WAAW,QACd,GAAG,CAAC,KAAK,CAAC,cACJ,aAAa,iBACV,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,kBAqEhD,CAAA"}
@@ -61,7 +61,15 @@ const fetchManifestsForDeps = async (packageInfo, graph, fromNode, deps, scurry,
61
61
  }
62
62
  const existingNode = graph.findResolution(spec, fromNode, queryModifier);
63
63
  if (existingNode) {
64
- graph.addEdge(type, spec, fromNode, existingNode);
64
+ // For peerOptional dependencies, create a dangling edge instead of linking to existing node
65
+ if (type === 'peerOptional') {
66
+ /* c8 ignore next 3 */
67
+ // This case happens when peerOptional dep already exists in graph
68
+ graph.addEdge(type, spec, fromNode);
69
+ }
70
+ else {
71
+ graph.addEdge(type, spec, fromNode, existingNode);
72
+ }
65
73
  continue;
66
74
  }
67
75
  const edgeOptional = type === 'optional' || type === 'peerOptional';
@@ -150,6 +158,12 @@ const processPlacementTasks = async (add, graph, options, placementTasks, modifi
150
158
  });
151
159
  }
152
160
  }
161
+ // Skip placing peerOptional dependencies, just create a dangling edge
162
+ if (type === 'peerOptional') {
163
+ /* c8 ignore next 3 */
164
+ graph.addEdge(type, spec, fromNode);
165
+ continue;
166
+ }
153
167
  // places a new node in the graph representing a newly seen dependency
154
168
  const node = graph.placePackage(fromNode, type, spec, normalizeManifest(manifest), fileTypeInfo?.id, queryModifier);
155
169
  /* c8 ignore start - not possible, already ensured manifest */
@@ -1 +1 @@
1
- {"version":3,"file":"append-nodes.js","sourceRoot":"","sources":["../../../src/ideal/append-nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAE3C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEnC,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAOtE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAI1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AAYvE;;;GAGG;AACH,MAAM,oBAAoB,GAAG,CAC3B,IAAU,EACV,OAA2B,EAC3B,EAAE,CACF,OAAO,KAAK,iBAAiB;IAC7B,IAAI,CAAC,QAAQ;IACb,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;AAE3B;;GAEG;AACH,MAAM,eAAe,GAAG,CACtB,IAAU,EACV,QAAc,EACd,MAAkB,EACQ,EAAE;IAC5B,MAAM,C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AE,gBAAgB,EAC9B,KAAK,GACW,EAAE,EAAE;YACpB,8DAA8D;YAC9D,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YAEjB,+CAA+C;YAC/C,MAAM,cAAc,GAAG,MAAM,qBAAqB,CAChD,WAAW,EACX,KAAK,EACL,IAAI;YACJ,4DAA4D;YAC5D,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACrB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAC7C,EACD,MAAM,EACN,gBAAgB,EAChB,KAAK,CACN,CAAA;YAED,yDAAyD;YACzD,OAAO,MAAM,qBAAqB,CAChC,GAAG,EACH,KAAK,EACL,OAAO,EACP,cAAc,EACd,SAAS,CACV,CAAA;QACH,CAAC,CACF,CACF,CAAA;QAED,oDAAoD;QACpD,KAAK,MAAM,EAAE,kBAAkB,EAAE,IAAI,YAAY,EAAE,CAAC;YAClD,KAAK,MAAM,QAAQ,IAAI,kBAAkB,EAAE,CAAC;gBAC1C,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;oBAChC,oBAAoB;oBACpB,MAAM,YAAY,GAAG,gBAAgB,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,CAAA;oBACpD,aAAa,CAAC,IAAI,CAAC;wBACjB,GAAG,QAAQ;wBACX,KAAK,EAAE,YAAY,GAAG,CAAC;qBACxB,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QAED,yBAAyB;QACzB,gBAAgB,GAAG,aAAa,CAAA;IAClC,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { joinDepIDTuple } from '@vltpkg/dep-id'\nimport type { DepID } from '@vltpkg/dep-id'\nimport { error } from '@vltpkg/error-cause'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport { Spec } from '@vltpkg/spec'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport { longDependencyTypes, normalizeManifest } from '@vltpkg/types'\nimport type {\n DependencyTypeLong,\n DependencySaveType,\n Manifest,\n} from '@vltpkg/types'\nimport type { PathScurry } from 'path-scurry'\nimport { asDependency, shorten } from '../dependencies.ts'\nimport type { Dependency } from '../dependencies.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\nimport { removeOptionalSubgraph } from '../remove-optional-subgraph.ts'\nimport type {\n GraphModifier,\n ModifierActiveEntry,\n} from '../modifiers.ts'\n\ntype FileTypeInfo = {\n id: DepID\n path: string\n isDirectory: boolean\n}\n\n/**\n * Only install devDeps for git dependencies and importers\n * Everything else always gets installed\n */\nconst shouldInstallDepType = (\n node: Node,\n depType: DependencyTypeLong,\n) =>\n depType !== 'devDependencies' ||\n node.importer ||\n node.id.startsWith('git')\n\n/**\n * Retrieve the {@link DepID} and location for a `file:` type {@link Node}.\n */\nconst getFileTypeInfo = (\n spec: Spec,\n fromNode: Node,\n scurry: PathScurry,\n): FileTypeInfo | undefined => {\n const f = spec.final\n if (f.type !== 'file') return\n\n /* c8 ignore start - should be impossible */\n if (!f.file) {\n throw error('no path on file specifier', { spec })\n }\n /* c8 ignore stop */\n\n // Given that both linked folders and local tarballs (both defined with\n // usage of the `file:` spec prefix) location needs to be relative to their\n // parents, build the expected path and use it for both location and id\n const target = scurry.cwd.resolve(fromNode.location).resolve(f.file)\n const path = target.relativePosix()\n const id = joinDepIDTuple(['file', path])\n\n return {\n path,\n id,\n isDirectory: !!target.lstatSync()?.isDirectory(),\n }\n}\n\nconst isStringArray = (a: unknown): a is string[] =>\n Array.isArray(a) && !a.some(b => typeof b !== 'string')\n\n/**\n * Represents a manifest fetch operation with all the context needed.\n */\ntype ManifestFetchTask = {\n spec: Spec\n type: DependencySaveType\n fromNode: Node\n fileTypeInfo?: FileTypeInfo\n activeModifier?: ModifierActiveEntry\n queryModifier?: string\n edgeOptional: boolean\n manifestPromise: Promise<Manifest | undefined>\n depth: number\n}\n\n/**\n * Represents a node placement operation that depends on a resolved manifest.\n */\ntype NodePlacementTask = {\n fetchTask: ManifestFetchTask\n manifest: Manifest | undefined\n node?: Node\n childDeps?: Dependency[]\n childModifierRefs?: Map<string, ModifierActiveEntry>\n}\n\n/**\n * Represents an ongoing append operation for a node and its dependencies.\n */\ntype AppendNodeEntry = {\n node: Node\n deps: Dependency[]\n modifierRefs?: Map<string, ModifierActiveEntry>\n depth: number\n}\n\n/**\n * Fetch manifests for dependencies and create placement tasks.\n */\nconst fetchManifestsForDeps = async (\n packageInfo: PackageInfoClient,\n graph: Graph,\n fromNode: Node,\n deps: Dependency[],\n scurry: PathScurry,\n modifierRefs?: Map<string, ModifierActiveEntry>,\n depth = 0,\n): Promise<NodePlacementTask[]> => {\n // Create fetch tasks for all dependencies at this level\n const fetchTasks: ManifestFetchTask[] = []\n\n for (const { spec: originalSpec, type } of deps) {\n let spec = originalSpec\n const fileTypeInfo = getFileTypeInfo(spec, fromNode, scurry)\n const activeModifier = modifierRefs?.get(spec.name)\n\n // here is the place we swap specs if a edge modifier was defined\n const queryModifier = activeModifier?.modifier.query\n const completeModifier =\n activeModifier &&\n activeModifier.interactiveBreadcrumb.current ===\n activeModifier.modifier.breadcrumb.last\n if (\n queryModifier &&\n completeModifier &&\n 'spec' in activeModifier.modifier\n ) {\n spec = activeModifier.modifier.spec\n if (spec.bareSpec === '-') {\n continue\n }\n }\n\n const existingNode = graph.findResolution(\n spec,\n fromNode,\n queryModifier,\n )\n if (existingNode) {\n graph.addEdge(type, spec, fromNode, existingNode)\n continue\n }\n\n const edgeOptional =\n type === 'optional' || type === 'peerOptional'\n\n // Start manifest fetch immediately for parallel processing\n const manifestPromise = packageInfo\n .manifest(spec, { from: scurry.resolve(fromNode.location) })\n .then(manifest => manifest as Manifest | undefined)\n .catch((er: unknown) => {\n // optional deps ignored if inaccessible\n if (edgeOptional || fromNode.optional) {\n return undefined\n }\n throw er\n })\n\n const fetchTask: ManifestFetchTask = {\n spec,\n type,\n fromNode,\n fileTypeInfo,\n activeModifier,\n queryModifier,\n edgeOptional,\n manifestPromise,\n depth,\n }\n\n fetchTasks.push(fetchTask)\n }\n\n // Create placement tasks\n const placementTasks: NodePlacementTask[] = []\n for (const fetchTask of fetchTasks) {\n const manifest = await fetchTask.manifestPromise\n\n placementTasks.push({\n fetchTask,\n manifest,\n })\n }\n\n return placementTasks\n}\n\n/**\n * Process placement tasks and collect child dependencies\n */\nconst processPlacementTasks = async (\n add: Map<string, Dependency>,\n graph: Graph,\n options: SpecOptions,\n placementTasks: NodePlacementTask[],\n modifiers?: GraphModifier,\n): Promise<{\n childDepsToProcess: Omit<AppendNodeEntry, 'depth'>[]\n}> => {\n const childDepsToProcess: Omit<AppendNodeEntry, 'depth'>[] = []\n\n for (const placementTask of placementTasks) {\n const { fetchTask, manifest } = placementTask\n let { spec } = fetchTask\n const type = fetchTask.type\n const fromNode = fetchTask.fromNode\n const fileTypeInfo = fetchTask.fileTypeInfo\n const activeModifier = fetchTask.activeModifier\n const queryModifier = fetchTask.queryModifier\n const edgeOptional = fetchTask.edgeOptional\n\n // Handle nameless dependencies\n if (manifest?.name && spec.name === '(unknown)') {\n const s = add.get(String(spec))\n if (s) {\n // removes the previous, placeholder entry key\n add.delete(String(spec))\n // replaces spec with a version with the correct name\n spec = Spec.parse(manifest.name, spec.bareSpec, options)\n // updates the add map with the fixed up spec\n const n = asDependency({\n ...s,\n spec,\n })\n add.set(manifest.name, n)\n }\n }\n\n // handles missing manifest resolution\n if (!manifest) {\n if (!edgeOptional && fromNode.isOptional()) {\n // failed resolution of a non-optional dep of an optional node\n // have to clean up the dependents\n removeOptionalSubgraph(graph, fromNode)\n continue\n } else if (edgeOptional) {\n // failed resolution of an optional dep, just ignore it,\n // nothing to prune because we never added it in the first place.\n continue\n } else {\n throw error('failed to resolve dependency', {\n spec,\n from: fromNode.location,\n })\n }\n }\n\n // places a new node in the graph representing a newly seen dependency\n const node = graph.placePackage(\n fromNode,\n type,\n spec,\n normalizeManifest(manifest),\n fileTypeInfo?.id,\n queryModifier,\n )\n\n /* c8 ignore start - not possible, already ensured manifest */\n if (!node) {\n throw error('failed to place package', {\n from: fromNode.location,\n spec,\n })\n }\n /* c8 ignore stop */\n\n // update the node modifier tracker\n if (activeModifier) {\n modifiers?.updateActiveEntry(node, activeModifier)\n }\n\n // updates graph node information\n if (fileTypeInfo?.path && fileTypeInfo.isDirectory) {\n node.location = fileTypeInfo.path\n }\n node.setResolved()\n\n // Collect child dependencies for processing in the next level\n const bundleDeps = manifest.bundleDependencies\n const bundled = new Set<string>(\n (\n node.id.startsWith('git') ||\n node.importer ||\n !isStringArray(bundleDeps)\n ) ?\n []\n : bundleDeps,\n )\n\n // recursively process all child dependencies in the manifest\n const nextDeps: Dependency[] = []\n\n for (const depTypeName of longDependencyTypes) {\n const depRecord: Record<string, string> | undefined =\n manifest[depTypeName]\n\n if (depRecord && shouldInstallDepType(node, depTypeName)) {\n for (const [name, bareSpec] of Object.entries(depRecord)) {\n if (bundled.has(name)) continue\n nextDeps.push({\n type: shorten(depTypeName, name, manifest),\n spec: Spec.parse(name, bareSpec, {\n ...options,\n registry: spec.registry,\n }),\n })\n }\n }\n }\n\n if (nextDeps.length > 0) {\n childDepsToProcess.push({\n node,\n deps: nextDeps,\n modifierRefs: modifiers?.tryDependencies(node, nextDeps),\n })\n }\n }\n\n return { childDepsToProcess }\n}\n\n/**\n * Append new nodes in the given `graph` for dependencies specified at `add`\n * and missing dependencies from the `deps` parameter.\n *\n * It also applies any modifiers that applies to a given node as it processes\n * and builds the graph.\n */\nexport const appendNodes = async (\n add: Map<string, Dependency>,\n packageInfo: PackageInfoClient,\n graph: Graph,\n fromNode: Node,\n deps: Dependency[],\n scurry: PathScurry,\n options: SpecOptions,\n seen: Set<DepID>,\n modifiers?: GraphModifier,\n modifierRefs?: Map<string, ModifierActiveEntry>,\n) => {\n /* c8 ignore next */\n if (seen.has(fromNode.id)) return\n seen.add(fromNode.id)\n\n // Use a queue for breadth-first processing\n let currentLevelDeps: AppendNodeEntry[] = [\n { node: fromNode, deps, modifierRefs, depth: 0 },\n ]\n\n while (currentLevelDeps.length > 0) {\n const nextLevelDeps: AppendNodeEntry[] = []\n\n // Process all nodes at the current level in parallel\n const levelResults = await Promise.all(\n currentLevelDeps.map(\n async ({\n node,\n deps: nodeDeps,\n modifierRefs: nodeModifierRefs,\n depth,\n }: AppendNodeEntry) => {\n // Mark node as seen when we start processing its dependencies\n seen.add(node.id)\n\n // Fetch manifests for this node's dependencies\n const placementTasks = await fetchManifestsForDeps(\n packageInfo,\n graph,\n node,\n // Sort dependencies by spec.name for deterministic ordering\n nodeDeps.sort((a, b) =>\n a.spec.name.localeCompare(b.spec.name, 'en'),\n ),\n scurry,\n nodeModifierRefs,\n depth,\n )\n\n // Process the placement tasks and get child dependencies\n return await processPlacementTasks(\n add,\n graph,\n options,\n placementTasks,\n modifiers,\n )\n },\n ),\n )\n\n // Collect all child dependencies for the next level\n for (const { childDepsToProcess } of levelResults) {\n for (const childDep of childDepsToProcess) {\n if (!seen.has(childDep.node.id)) {\n /* c8 ignore next */\n const currentDepth = currentLevelDeps[0]?.depth ?? 0\n nextLevelDeps.push({\n ...childDep,\n depth: currentDepth + 1,\n })\n }\n }\n }\n\n // Move to the next level\n currentLevelDeps = nextLevelDeps\n }\n}\n"]}
1
+ {"version":3,"file":"append-nodes.js","sourceRoot":"","sources":["../../../src/ideal/append-nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAE3C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEnC,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAOtE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CA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AO,EACP,cAAc,EACd,SAAS,CACV,CAAA;QACH,CAAC,CACF,CACF,CAAA;QAED,oDAAoD;QACpD,KAAK,MAAM,EAAE,kBAAkB,EAAE,IAAI,YAAY,EAAE,CAAC;YAClD,KAAK,MAAM,QAAQ,IAAI,kBAAkB,EAAE,CAAC;gBAC1C,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;oBAChC,oBAAoB;oBACpB,MAAM,YAAY,GAAG,gBAAgB,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,CAAA;oBACpD,aAAa,CAAC,IAAI,CAAC;wBACjB,GAAG,QAAQ;wBACX,KAAK,EAAE,YAAY,GAAG,CAAC;qBACxB,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QAED,yBAAyB;QACzB,gBAAgB,GAAG,aAAa,CAAA;IAClC,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { joinDepIDTuple } from '@vltpkg/dep-id'\nimport type { DepID } from '@vltpkg/dep-id'\nimport { error } from '@vltpkg/error-cause'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport { Spec } from '@vltpkg/spec'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport { longDependencyTypes, normalizeManifest } from '@vltpkg/types'\nimport type {\n DependencyTypeLong,\n DependencySaveType,\n Manifest,\n} from '@vltpkg/types'\nimport type { PathScurry } from 'path-scurry'\nimport { asDependency, shorten } from '../dependencies.ts'\nimport type { Dependency } from '../dependencies.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\nimport { removeOptionalSubgraph } from '../remove-optional-subgraph.ts'\nimport type {\n GraphModifier,\n ModifierActiveEntry,\n} from '../modifiers.ts'\n\ntype FileTypeInfo = {\n id: DepID\n path: string\n isDirectory: boolean\n}\n\n/**\n * Only install devDeps for git dependencies and importers\n * Everything else always gets installed\n */\nconst shouldInstallDepType = (\n node: Node,\n depType: DependencyTypeLong,\n) =>\n depType !== 'devDependencies' ||\n node.importer ||\n node.id.startsWith('git')\n\n/**\n * Retrieve the {@link DepID} and location for a `file:` type {@link Node}.\n */\nconst getFileTypeInfo = (\n spec: Spec,\n fromNode: Node,\n scurry: PathScurry,\n): FileTypeInfo | undefined => {\n const f = spec.final\n if (f.type !== 'file') return\n\n /* c8 ignore start - should be impossible */\n if (!f.file) {\n throw error('no path on file specifier', { spec })\n }\n /* c8 ignore stop */\n\n // Given that both linked folders and local tarballs (both defined with\n // usage of the `file:` spec prefix) location needs to be relative to their\n // parents, build the expected path and use it for both location and id\n const target = scurry.cwd.resolve(fromNode.location).resolve(f.file)\n const path = target.relativePosix()\n const id = joinDepIDTuple(['file', path])\n\n return {\n path,\n id,\n isDirectory: !!target.lstatSync()?.isDirectory(),\n }\n}\n\nconst isStringArray = (a: unknown): a is string[] =>\n Array.isArray(a) && !a.some(b => typeof b !== 'string')\n\n/**\n * Represents a manifest fetch operation with all the context needed.\n */\ntype ManifestFetchTask = {\n spec: Spec\n type: DependencySaveType\n fromNode: Node\n fileTypeInfo?: FileTypeInfo\n activeModifier?: ModifierActiveEntry\n queryModifier?: string\n edgeOptional: boolean\n manifestPromise: Promise<Manifest | undefined>\n depth: number\n}\n\n/**\n * Represents a node placement operation that depends on a resolved manifest.\n */\ntype NodePlacementTask = {\n fetchTask: ManifestFetchTask\n manifest: Manifest | undefined\n node?: Node\n childDeps?: Dependency[]\n childModifierRefs?: Map<string, ModifierActiveEntry>\n}\n\n/**\n * Represents an ongoing append operation for a node and its dependencies.\n */\ntype AppendNodeEntry = {\n node: Node\n deps: Dependency[]\n modifierRefs?: Map<string, ModifierActiveEntry>\n depth: number\n}\n\n/**\n * Fetch manifests for dependencies and create placement tasks.\n */\nconst fetchManifestsForDeps = async (\n packageInfo: PackageInfoClient,\n graph: Graph,\n fromNode: Node,\n deps: Dependency[],\n scurry: PathScurry,\n modifierRefs?: Map<string, ModifierActiveEntry>,\n depth = 0,\n): Promise<NodePlacementTask[]> => {\n // Create fetch tasks for all dependencies at this level\n const fetchTasks: ManifestFetchTask[] = []\n\n for (const { spec: originalSpec, type } of deps) {\n let spec = originalSpec\n const fileTypeInfo = getFileTypeInfo(spec, fromNode, scurry)\n const activeModifier = modifierRefs?.get(spec.name)\n\n // here is the place we swap specs if a edge modifier was defined\n const queryModifier = activeModifier?.modifier.query\n const completeModifier =\n activeModifier &&\n activeModifier.interactiveBreadcrumb.current ===\n activeModifier.modifier.breadcrumb.last\n if (\n queryModifier &&\n completeModifier &&\n 'spec' in activeModifier.modifier\n ) {\n spec = activeModifier.modifier.spec\n if (spec.bareSpec === '-') {\n continue\n }\n }\n\n const existingNode = graph.findResolution(\n spec,\n fromNode,\n queryModifier,\n )\n if (existingNode) {\n // For peerOptional dependencies, create a dangling edge instead of linking to existing node\n if (type === 'peerOptional') {\n /* c8 ignore next 3 */\n // This case happens when peerOptional dep already exists in graph\n graph.addEdge(type, spec, fromNode)\n } else {\n graph.addEdge(type, spec, fromNode, existingNode)\n }\n continue\n }\n\n const edgeOptional =\n type === 'optional' || type === 'peerOptional'\n\n // Start manifest fetch immediately for parallel processing\n const manifestPromise = packageInfo\n .manifest(spec, { from: scurry.resolve(fromNode.location) })\n .then(manifest => manifest as Manifest | undefined)\n .catch((er: unknown) => {\n // optional deps ignored if inaccessible\n if (edgeOptional || fromNode.optional) {\n return undefined\n }\n throw er\n })\n\n const fetchTask: ManifestFetchTask = {\n spec,\n type,\n fromNode,\n fileTypeInfo,\n activeModifier,\n queryModifier,\n edgeOptional,\n manifestPromise,\n depth,\n }\n\n fetchTasks.push(fetchTask)\n }\n\n // Create placement tasks\n const placementTasks: NodePlacementTask[] = []\n for (const fetchTask of fetchTasks) {\n const manifest = await fetchTask.manifestPromise\n\n placementTasks.push({\n fetchTask,\n manifest,\n })\n }\n\n return placementTasks\n}\n\n/**\n * Process placement tasks and collect child dependencies\n */\nconst processPlacementTasks = async (\n add: Map<string, Dependency>,\n graph: Graph,\n options: SpecOptions,\n placementTasks: NodePlacementTask[],\n modifiers?: GraphModifier,\n): Promise<{\n childDepsToProcess: Omit<AppendNodeEntry, 'depth'>[]\n}> => {\n const childDepsToProcess: Omit<AppendNodeEntry, 'depth'>[] = []\n\n for (const placementTask of placementTasks) {\n const { fetchTask, manifest } = placementTask\n let { spec } = fetchTask\n const type = fetchTask.type\n const fromNode = fetchTask.fromNode\n const fileTypeInfo = fetchTask.fileTypeInfo\n const activeModifier = fetchTask.activeModifier\n const queryModifier = fetchTask.queryModifier\n const edgeOptional = fetchTask.edgeOptional\n\n // Handle nameless dependencies\n if (manifest?.name && spec.name === '(unknown)') {\n const s = add.get(String(spec))\n if (s) {\n // removes the previous, placeholder entry key\n add.delete(String(spec))\n // replaces spec with a version with the correct name\n spec = Spec.parse(manifest.name, spec.bareSpec, options)\n // updates the add map with the fixed up spec\n const n = asDependency({\n ...s,\n spec,\n })\n add.set(manifest.name, n)\n }\n }\n\n // handles missing manifest resolution\n if (!manifest) {\n if (!edgeOptional && fromNode.isOptional()) {\n // failed resolution of a non-optional dep of an optional node\n // have to clean up the dependents\n removeOptionalSubgraph(graph, fromNode)\n continue\n } else if (edgeOptional) {\n // failed resolution of an optional dep, just ignore it,\n // nothing to prune because we never added it in the first place.\n continue\n } else {\n throw error('failed to resolve dependency', {\n spec,\n from: fromNode.location,\n })\n }\n }\n\n // Skip placing peerOptional dependencies, just create a dangling edge\n if (type === 'peerOptional') {\n /* c8 ignore next 3 */\n graph.addEdge(type, spec, fromNode)\n continue\n }\n\n // places a new node in the graph representing a newly seen dependency\n const node = graph.placePackage(\n fromNode,\n type,\n spec,\n normalizeManifest(manifest),\n fileTypeInfo?.id,\n queryModifier,\n )\n\n /* c8 ignore start - not possible, already ensured manifest */\n if (!node) {\n throw error('failed to place package', {\n from: fromNode.location,\n spec,\n })\n }\n /* c8 ignore stop */\n\n // update the node modifier tracker\n if (activeModifier) {\n modifiers?.updateActiveEntry(node, activeModifier)\n }\n\n // updates graph node information\n if (fileTypeInfo?.path && fileTypeInfo.isDirectory) {\n node.location = fileTypeInfo.path\n }\n node.setResolved()\n\n // Collect child dependencies for processing in the next level\n const bundleDeps = manifest.bundleDependencies\n const bundled = new Set<string>(\n (\n node.id.startsWith('git') ||\n node.importer ||\n !isStringArray(bundleDeps)\n ) ?\n []\n : bundleDeps,\n )\n\n // recursively process all child dependencies in the manifest\n const nextDeps: Dependency[] = []\n\n for (const depTypeName of longDependencyTypes) {\n const depRecord: Record<string, string> | undefined =\n manifest[depTypeName]\n\n if (depRecord && shouldInstallDepType(node, depTypeName)) {\n for (const [name, bareSpec] of Object.entries(depRecord)) {\n if (bundled.has(name)) continue\n nextDeps.push({\n type: shorten(depTypeName, name, manifest),\n spec: Spec.parse(name, bareSpec, {\n ...options,\n registry: spec.registry,\n }),\n })\n }\n }\n }\n\n if (nextDeps.length > 0) {\n childDepsToProcess.push({\n node,\n deps: nextDeps,\n modifierRefs: modifiers?.tryDependencies(node, nextDeps),\n })\n }\n }\n\n return { childDepsToProcess }\n}\n\n/**\n * Append new nodes in the given `graph` for dependencies specified at `add`\n * and missing dependencies from the `deps` parameter.\n *\n * It also applies any modifiers that applies to a given node as it processes\n * and builds the graph.\n */\nexport const appendNodes = async (\n add: Map<string, Dependency>,\n packageInfo: PackageInfoClient,\n graph: Graph,\n fromNode: Node,\n deps: Dependency[],\n scurry: PathScurry,\n options: SpecOptions,\n seen: Set<DepID>,\n modifiers?: GraphModifier,\n modifierRefs?: Map<string, ModifierActiveEntry>,\n) => {\n /* c8 ignore next */\n if (seen.has(fromNode.id)) return\n seen.add(fromNode.id)\n\n // Use a queue for breadth-first processing\n let currentLevelDeps: AppendNodeEntry[] = [\n { node: fromNode, deps, modifierRefs, depth: 0 },\n ]\n\n while (currentLevelDeps.length > 0) {\n const nextLevelDeps: AppendNodeEntry[] = []\n\n // Process all nodes at the current level in parallel\n const levelResults = await Promise.all(\n currentLevelDeps.map(\n async ({\n node,\n deps: nodeDeps,\n modifierRefs: nodeModifierRefs,\n depth,\n }: AppendNodeEntry) => {\n // Mark node as seen when we start processing its dependencies\n seen.add(node.id)\n\n // Fetch manifests for this node's dependencies\n const placementTasks = await fetchManifestsForDeps(\n packageInfo,\n graph,\n node,\n // Sort dependencies by spec.name for deterministic ordering\n nodeDeps.sort((a, b) =>\n a.spec.name.localeCompare(b.spec.name, 'en'),\n ),\n scurry,\n nodeModifierRefs,\n depth,\n )\n\n // Process the placement tasks and get child dependencies\n return await processPlacementTasks(\n add,\n graph,\n options,\n placementTasks,\n modifiers,\n )\n },\n ),\n )\n\n // Collect all child dependencies for the next level\n for (const { childDepsToProcess } of levelResults) {\n for (const childDep of childDepsToProcess) {\n if (!seen.has(childDep.node.id)) {\n /* c8 ignore next */\n const currentDepth = currentLevelDeps[0]?.depth ?? 0\n nextLevelDeps.push({\n ...childDep,\n depth: currentDepth + 1,\n })\n }\n }\n }\n\n // Move to the next level\n currentLevelDeps = nextLevelDeps\n }\n}\n"]}
@@ -1,5 +1,13 @@
1
+ import { Spec } from '@vltpkg/spec/browser';
1
2
  import type { SpecOptions } from '@vltpkg/spec/browser';
2
- import type { GraphLike } from '../types.ts';
3
+ import type { DependencyTypeShort } from '@vltpkg/types';
4
+ import type { GraphLike, NodeLike } from '../types.ts';
3
5
  import type { LockfileData } from './types.ts';
6
+ export type ProcessingEdge = {
7
+ fromNode: NodeLike;
8
+ toNode: NodeLike | undefined;
9
+ depType: DependencyTypeShort;
10
+ spec: Spec;
11
+ };
4
12
  export declare const loadEdges: (graph: GraphLike, edges: LockfileData["edges"], options: SpecOptions) => void;
5
13
  //# sourceMappingURL=load-edges.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"load-edges.d.ts","sourceRoot":"","sources":["../../../src/lockfile/load-edges.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAGvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EACV,YAAY,EAGb,MAAM,YAAY,CAAA;AAEnB,eAAO,MAAM,SAAS,UACb,SAAS,SACT,YAAY,CAAC,OAAO,CAAC,WACnB,WAAW,SA+CrB,CAAA"}
1
+ {"version":3,"file":"load-edges.d.ts","sourceRoot":"","sources":["../../../src/lockfile/load-edges.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAEvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAExD,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,KAAK,EACV,YAAY,EAGb,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,EAAE,QAAQ,CAAA;IAClB,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAA;IAC5B,OAAO,EAAE,mBAAmB,CAAA;IAC5B,IAAI,EAAE,IAAI,CAAA;CACX,CAAA;AA0BD,eAAO,MAAM,SAAS,UACb,SAAS,SACT,YAAY,CAAC,OAAO,CAAC,WACnB,WAAW,SA2GrB,CAAA"}
@@ -4,8 +4,31 @@ import { fastSplit } from '@vltpkg/fast-split';
4
4
  import { Spec } from '@vltpkg/spec/browser';
5
5
  import { longDependencyTypes } from '@vltpkg/types';
6
6
  import { isDependencyTypeShort } from "../dependencies.js";
7
+ const retrieveNodeFromGraph = (key, value, graph, fromId, seenNodes) => {
8
+ const foundNode = graph.nodes.get(asDepID(fromId));
9
+ if (!foundNode) {
10
+ throw error('Edge info missing its `from` node', {
11
+ found: {
12
+ nodes: [...graph.nodes].map(([id]) => id),
13
+ from: foundNode,
14
+ fromId,
15
+ edge: { [key]: value },
16
+ },
17
+ });
18
+ }
19
+ if (seenNodes) {
20
+ seenNodes.set(fromId, foundNode);
21
+ }
22
+ return foundNode;
23
+ };
7
24
  export const loadEdges = (graph, edges, options) => {
8
25
  const entries = Object.entries(edges);
26
+ const edgeCount = entries.length;
27
+ // Only use optimizations for non-trivial graphs
28
+ const useOptimizations = edgeCount > 50;
29
+ const edgeProcessingQueue = [];
30
+ // Cache for frequently accessed nodes to avoid repeated Map lookups
31
+ const seenNodes = useOptimizations ? new Map() : undefined;
9
32
  for (const [key, value] of entries) {
10
33
  const [fromId, specName] = fastSplit(key, ' ', 2);
11
34
  const [depType, valRest] = fastSplit(value, ' ', 2);
@@ -16,28 +39,67 @@ export const loadEdges = (graph, edges, options) => {
16
39
  continue;
17
40
  }
18
41
  /* c8 ignore stop */
19
- const spec = Spec.parse(specName, valRest.substring(0, vrSplit), options);
20
- const toId = valRest.substring(vrSplit + 1);
21
- const from = graph.nodes.get(asDepID(fromId));
22
- if (!from) {
23
- throw error('Edge info missing its `from` node', {
24
- found: {
25
- nodes: [...graph.nodes].map(([id]) => id),
26
- from,
27
- fromId,
28
- edge: { [key]: value },
29
- },
30
- });
31
- }
32
- // sets a registry for this spec to inherit from
33
- spec.inheritedRegistry = from.registry;
34
- const to = toId === 'MISSING' ? undefined : graph.nodes.get(asDepID(toId));
42
+ // Validate dependency type early
35
43
  if (!isDependencyTypeShort(depType)) {
36
44
  throw error('Found unsupported dependency type in lockfile', {
37
45
  validOptions: [...longDependencyTypes],
38
46
  });
39
47
  }
40
- graph.addEdge(depType, spec, from, to);
48
+ // Use cached node lookup for large graphs, direct lookup for small ones
49
+ let fromNode;
50
+ if (seenNodes) {
51
+ const seen = seenNodes.get(fromId);
52
+ if (seen) {
53
+ fromNode = seen;
54
+ }
55
+ else {
56
+ fromNode = retrieveNodeFromGraph(key, value, graph, fromId, seenNodes);
57
+ }
58
+ }
59
+ else {
60
+ fromNode = retrieveNodeFromGraph(key, value, graph, fromId);
61
+ }
62
+ const toId = valRest.substring(vrSplit + 1);
63
+ let toNode = undefined;
64
+ if (toId !== 'MISSING') {
65
+ if (seenNodes) {
66
+ const seen = seenNodes.get(toId);
67
+ if (seen) {
68
+ toNode = seen;
69
+ }
70
+ else {
71
+ toNode = graph.nodes.get(asDepID(toId));
72
+ if (toNode) {
73
+ seenNodes.set(toId, toNode);
74
+ }
75
+ }
76
+ }
77
+ else {
78
+ toNode = graph.nodes.get(asDepID(toId));
79
+ }
80
+ }
81
+ // Parse spec once we know the nodes are valid
82
+ const spec = Spec.parse(specName, valRest.substring(0, vrSplit), options);
83
+ // sets a registry for this spec to inherit from
84
+ spec.inheritedRegistry = fromNode.registry;
85
+ if (useOptimizations) {
86
+ edgeProcessingQueue.push({
87
+ fromNode,
88
+ toNode,
89
+ depType,
90
+ spec,
91
+ });
92
+ }
93
+ else {
94
+ // Process immediately for small graphs
95
+ graph.addEdge(depType, spec, fromNode, toNode);
96
+ }
97
+ }
98
+ // Batch process all edges (only for non-trivial graphs)
99
+ if (useOptimizations) {
100
+ for (const { fromNode, toNode, depType, spec, } of edgeProcessingQueue) {
101
+ graph.addEdge(depType, spec, fromNode, toNode);
102
+ }
41
103
  }
42
104
  };
43
105
  //# sourceMappingURL=load-edges.js.map
@@ -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;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAQ1D,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,KAAgB,EAChB,KAA4B,EAC5B,OAAoB,EACpB,EAAE;IACF,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAGjC,CAAA;IACH,KAAK,M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AI,CAAC,QAAQ,CAAA;QAEtC,MAAM,EAAE,GACN,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;QACjE,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,EAAE,CAAC;YACpC,MAAM,KAAK,CAAC,+CAA+C,EAAE;gBAC3D,YAAY,EAAE,CAAC,GAAG,mBAAmB,CAAC;aACvC,CAAC,CAAA;QACJ,CAAC;QAED,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;IACxC,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 { isDependencyTypeShort } from '../dependencies.ts'\nimport type { GraphLike } from '../types.ts'\nimport type {\n LockfileData,\n LockfileEdgeKey,\n LockfileEdgeValue,\n} from './types.ts'\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 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 // 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 const spec = Spec.parse(\n specName,\n valRest.substring(0, vrSplit),\n options,\n )\n const toId = valRest.substring(vrSplit + 1)\n const from = graph.nodes.get(asDepID(fromId))\n if (!from) {\n throw error('Edge info missing its `from` node', {\n found: {\n nodes: [...graph.nodes].map(([id]) => id),\n from,\n fromId,\n edge: { [key]: value },\n },\n })\n }\n\n // sets a registry for this spec to inherit from\n spec.inheritedRegistry = from.registry\n\n const to =\n toId === 'MISSING' ? undefined : graph.nodes.get(asDepID(toId))\n if (!isDependencyTypeShort(depType)) {\n throw error('Found unsupported dependency type in lockfile', {\n validOptions: [...longDependencyTypes],\n })\n }\n\n graph.addEdge(depType, spec, from, to)\n }\n}\n"]}
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;AAEnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAe1D,MAAM,qBAAqB,GAAG,CAC5B,GAAW,EACX,KAAa,EACb,KAAgB,EAChB,MAAc,EACd,SAAiC,EACvB,EAAE;IACZ,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAA;IAClD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,KAAK,CAAC,mCAAmC,EAAE;YAC/C,KAAK,EAAE;gBACL,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;gBACzC,IAAI,EAAE,SAAS;gBACf,MAAM;gBACN,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE;aACvB;SACF,CAAC,CAAA;IACJ,CAAC;IAC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AAG,IAAI,CAAC,KAAK,CACrB,QAAQ,EACR,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,EAC7B,OAAO,CACR,CAAA;QAED,gDAAgD;QAChD,IAAI,CAAC,iBAAiB,GAAG,QAAQ,CAAC,QAAQ,CAAA;QAE1C,IAAI,gBAAgB,EAAE,CAAC;YACrB,mBAAmB,CAAC,IAAI,CAAC;gBACvB,QAAQ;gBACR,MAAM;gBACN,OAAO;gBACP,IAAI;aACL,CAAC,CAAA;QACJ,CAAC;aAAM,CAAC;YACN,uCAAuC;YACvC,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;QAChD,CAAC;IACH,CAAC;IAED,wDAAwD;IACxD,IAAI,gBAAgB,EAAE,CAAC;QACrB,KAAK,MAAM,EACT,QAAQ,EACR,MAAM,EACN,OAAO,EACP,IAAI,GACL,IAAI,mBAAmB,EAAE,CAAC;YACzB,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;QAChD,CAAC;IACH,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 { DependencyTypeShort } from '@vltpkg/types'\nimport { isDependencyTypeShort } from '../dependencies.ts'\nimport type { GraphLike, NodeLike } from '../types.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 +1 @@
1
- {"version":3,"file":"load-nodes.d.ts","sourceRoot":"","sources":["../../../src/lockfile/load-nodes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,YAAY,CAAA;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C,eAAO,MAAM,SAAS,UACb,SAAS,SACT,YAAY,CAAC,OAAO,CAAC,WACnB,SAAS,SAqEnB,CAAA"}
1
+ {"version":3,"file":"load-nodes.d.ts","sourceRoot":"","sources":["../../../src/lockfile/load-nodes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,YAAY,CAAA;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C,eAAO,MAAM,SAAS,UACb,SAAS,SACT,YAAY,CAAC,OAAO,CAAC,WACnB,SAAS,SA+FnB,CAAA"}
@@ -2,12 +2,16 @@ import { splitDepID } from '@vltpkg/dep-id/browser';
2
2
  import { getBooleanFlagsFromNum } from "./types.js";
3
3
  export const loadNodes = (graph, nodes, 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,] = 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 [flags, name, integrity, resolved, location, manifest, rawManifest,] = lockfileNode;
11
15
  const [type, filepath, maybeExtra, lastExtra] = splitDepID(id);
12
16
  const extra = type === 'registry' || type === 'git' ? lastExtra : maybeExtra;
13
17
  const registrySpec = maybeExtra;
@@ -17,15 +21,34 @@ export const loadNodes = (graph, nodes, actual) => {
17
21
  // that may be missing from the lockfile
18
22
  const referenceNode = actual?.nodes.get(id);
19
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
+ }
20
47
  // if the lockfile has manifest data then it should just use that
21
48
  // otherwise tries to infer name / version value from the lockfile node
22
49
  const node = mani ?
23
50
  graph.addNode(id, mani)
24
- : graph.addNode(id, undefined, undefined, name ?? undefined, (type === 'registry' &&
25
- registrySpec &&
26
- registrySpec.indexOf('@') > 0) ?
27
- registrySpec.split('@').slice(-1)[0]
28
- : undefined);
51
+ : graph.addNode(id, undefined, undefined, name ?? undefined, version);
29
52
  if (extra) {
30
53
  node.modifier = extra;
31
54
  }
@@ -1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\nimport type { LockfileData, LockfileNode } from './types.ts'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { GraphLike } from '../types.ts'\n\nexport const loadNodes = (\n graph: GraphLike,\n nodes: LockfileData['nodes'],\n actual?: GraphLike,\n) => {\n const entries = Object.entries(nodes) as [DepID, LockfileNode][]\n for (const [id, lockfileNode] of entries) {\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 [\n flags,\n name,\n integrity,\n resolved,\n location,\n manifest,\n rawManifest,\n ] = lockfileNode\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 // 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 (\n type === 'registry' &&\n registrySpec &&\n registrySpec.indexOf('@') > 0\n ) ?\n registrySpec.split('@').slice(-1)[0]\n : undefined,\n )\n if (extra) {\n node.modifier = extra\n }\n\n const { dev, optional } = getBooleanFlagsFromNum(flags)\n node.dev = dev\n node.optional = optional\n node.integrity = integrity ?? referenceNode?.integrity\n node.resolved = resolved ?? referenceNode?.resolved\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}\n"]}
1
+ {"version":3,"file":"load-nodes.js","sourceRoot":"","sources":["../../../src/lockfile/load-nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAA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,CAAC,SAAS,GAAG,SAAS,IAAI,aAAa,EAAE,SAAS,CAAA;QACtD,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAI,aAAa,EAAE,QAAQ,CAAA;QACnD,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;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { splitDepID } from '@vltpkg/dep-id/browser'\nimport { getBooleanFlagsFromNum } from './types.ts'\nimport type { LockfileData, LockfileNode } from './types.ts'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { GraphLike } from '../types.ts'\n\nexport const loadNodes = (\n graph: GraphLike,\n nodes: LockfileData['nodes'],\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 ] = 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.dev = dev\n node.optional = optional\n node.integrity = integrity ?? referenceNode?.integrity\n node.resolved = resolved ?? referenceNode?.resolved\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}\n"]}
@@ -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,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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,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,UA6F7D,CAAA"}
@@ -22,27 +22,24 @@ export const loadObject = (options, lockfileData) => {
22
22
  const monorepo = options.monorepo ??
23
23
  Monorepo.maybeLoad(options.projectRoot, { packageJson, scurry });
24
24
  const { catalog = {}, catalogs = {}, modifiers: modifiersLockfileConfig, 'scope-registries': scopeRegistries, registry, registries, 'git-hosts': gitHosts, 'git-host-archives': gitHostArchives, } = lockfileData.options ?? {};
25
+ // Optimize options merging - only create new objects when needed
25
26
  const mergedOptions = {
26
27
  ...options,
27
28
  catalog,
28
29
  catalogs,
29
- 'scope-registries': {
30
- ...options['scope-registries'],
31
- ...scopeRegistries,
32
- },
30
+ 'scope-registries': scopeRegistries ?
31
+ { ...options['scope-registries'], ...scopeRegistries }
32
+ : options['scope-registries'],
33
33
  registry: registry ?? options.registry,
34
- registries: {
35
- ...options.registries,
36
- ...registries,
37
- },
38
- 'git-hosts': {
39
- ...options['git-hosts'],
40
- ...gitHosts,
41
- },
42
- 'git-host-archives': {
43
- ...options['git-host-archives'],
44
- ...gitHostArchives,
45
- },
34
+ registries: registries ?
35
+ { ...options.registries, ...registries }
36
+ : options.registries,
37
+ 'git-hosts': gitHosts ?
38
+ { ...options['git-hosts'], ...gitHosts }
39
+ : options['git-hosts'],
40
+ 'git-host-archives': gitHostArchives ?
41
+ { ...options['git-host-archives'], ...gitHostArchives }
42
+ : options['git-host-archives'],
46
43
  };
47
44
  const graph = new Graph({
48
45
  ...mergedOptions,
@@ -53,9 +50,24 @@ export const loadObject = (options, lockfileData) => {
53
50
  // dependencies in case the modifiers have changed since we'll need to
54
51
  // recalculate the graph - useful for refreshing an ideal graph when
55
52
  // modifiers are swapped.
56
- const lockfileModifiers = JSON.stringify(modifiersLockfileConfig ?? {});
57
- const optionsModifiers = JSON.stringify(modifiers?.config);
58
- const modifiersChanged = lockfileModifiers !== optionsModifiers;
53
+ // Optimize modifier comparison - avoid JSON.stringify for simple cases
54
+ let modifiersChanged = false;
55
+ if (skipLoadingNodesOnModifiersChange) {
56
+ const lockfileConfig = modifiersLockfileConfig ?? {};
57
+ const optionsConfig = modifiers?.config ?? {};
58
+ // Quick check for obvious differences
59
+ const lockfileKeys = Object.keys(lockfileConfig);
60
+ const optionsKeys = Object.keys(optionsConfig);
61
+ if (lockfileKeys.length !== optionsKeys.length) {
62
+ modifiersChanged = true;
63
+ }
64
+ else {
65
+ // Only use JSON.stringify if we need deep comparison
66
+ const lockfileModifiers = JSON.stringify(lockfileConfig);
67
+ const optionsModifiers = JSON.stringify(optionsConfig);
68
+ modifiersChanged = lockfileModifiers !== optionsModifiers;
69
+ }
70
+ }
59
71
  const shouldLoadDependencies = !(skipLoadingNodesOnModifiersChange && modifiersChanged);
60
72
  if (shouldLoadDependencies) {
61
73
  loadNodes(graph, lockfileData.nodes, options.actual);
@@ -1 +1 @@
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,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AA0CnC,MAAM,YAAY,GAAG,CAAC,WAAmB,EAAE,YAAoB,EAAE,EAAE,CACjE,IAAI,CAAC,KAAK,CACR,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,YAAY,CAAC,EAAE;IAC/C,QAAQ,EAAE,MAAM;CACjB,CAAC,CACa,CAAA;AAEnB,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,OAAoB,EAAS,EAAE;IAClD,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAA;IAC/B,OAAO,UAAU,CACf,OAAO,EACP,YAAY,CAAC,WAAW,EAAE,eAAe,CAAC,CAC3C,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAoB,EAAS,EAAE;IACxD,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAA;IAC/B,OAAO,UAAU,CACf,OAAO,EACP,YAAY,CAAC,WAAW,EAAE,6BAA6B,CAAC,CACzD,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,OAAoB,EACpB,YAC4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IACD,MAAM,gBAAgB,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;IAC1D,MAAM,gBAAgB,GAAG,iBAAiB,KAAK,gBAAgB,CAAA;IAC/D,MAAM,sBAAsB,GAAG,CAAC,CAC9B,iCAAiC,IAAI,gBAAgB,CACtD,CAAA;IACD,IAAI,sBAAsB,EAAE,CAAC;QAC3B,SAAS,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;QACpD,SAAS,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,EAAE,aAAa,CAAC,CAAA;IACrD,CAAC;IAED,2CAA2C;IAC3C,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;QACxC,MAAM,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,OAAO,CAAA;QAChC,IAAI,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC7B,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAA;QACzC,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { PackageJson } from '@vltpkg/package-json'\nimport { 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 } = lockfileData.options ?? {}\n const mergedOptions = {\n ...options,\n catalog,\n catalogs,\n 'scope-registries': {\n ...options['scope-registries'],\n ...scopeRegistries,\n },\n registry: registry ?? options.registry,\n registries: {\n ...options.registries,\n ...registries,\n },\n 'git-hosts': {\n ...options['git-hosts'],\n ...gitHosts,\n },\n 'git-host-archives': {\n ...options['git-host-archives'],\n ...gitHostArchives,\n },\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 const lockfileModifiers = JSON.stringify(\n modifiersLockfileConfig ?? {},\n )\n const optionsModifiers = JSON.stringify(modifiers?.config)\n const modifiersChanged = lockfileModifiers !== optionsModifiers\n const shouldLoadDependencies = !(\n skipLoadingNodesOnModifiersChange && modifiersChanged\n )\n if (shouldLoadDependencies) {\n loadNodes(graph, lockfileData.nodes, options.actual)\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
+ {"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,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AA0CnC,MAAM,YAAY,GAAG,CAAC,WAAmB,EAAE,YAAoB,EAAE,EAAE,CACjE,IAAI,CAAC,KAAK,CACR,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,YAAY,CAAC,EAAE;IAC/C,QAAQ,EAAE,MAAM;CACjB,CAAC,CACa,CAAA;AAEnB,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,OAAoB,EAAS,EAAE;IAClD,MAAM,EAAE,WAAW,EA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iBAAiB,KAAK,gBAAgB,CAAA;QAC3D,CAAC;IACH,CAAC;IACD,MAAM,sBAAsB,GAAG,CAAC,CAC9B,iCAAiC,IAAI,gBAAgB,CACtD,CAAA;IACD,IAAI,sBAAsB,EAAE,CAAC;QAC3B,SAAS,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;QACpD,SAAS,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,EAAE,aAAa,CAAC,CAAA;IACrD,CAAC;IAED,2CAA2C;IAC3C,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;QACxC,MAAM,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,OAAO,CAAA;QAChC,IAAI,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC7B,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAA;QACzC,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { PackageJson } from '@vltpkg/package-json'\nimport { 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 } = 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(graph, lockfileData.nodes, options.actual)\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"]}
@@ -28,7 +28,7 @@ export const reify = async (options) => {
28
28
  loadManifests: true,
29
29
  });
30
30
  const diff = new Diff(actual, graph);
31
- const skipOptionalOnly = options.add?.modifiedDependencies && diff.optionalOnly();
31
+ const skipOptionalOnly = options.add?.modifiedDependencies && diff.optionalOnly;
32
32
  if (!diff.hasChanges() || skipOptionalOnly) {
33
33
  // nothing to do, so just return the diff
34
34
  done();
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reify/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,OAAO,EAAE,cAAc,EAAE,MA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AAW,CAC/C,IAAI,EACJ,OAAO,EACP,MAAM,CACP,CAAA;IACD,IAAI,SAAS,CAAC,MAAM;QAAE,MAAM,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;IAElD,6DAA6D;IAC7D,wBAAwB,EAAE,EAAE,CAAA;IAE5B,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,KAAK,CAAC,CAAA;IAExD,8DAA8D;IAC9D,IAAI,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;QACjC,YAAY,CACV,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAC1B,MAAM,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAC7C,CAAA;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { graphStep } from '@vltpkg/output'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport { RollbackRemove } from '@vltpkg/rollback-remove'\nimport { availableParallelism } from 'node:os'\nimport { callLimit } from 'promise-call-limit'\nimport type { LoadOptions } from '../actual/load.ts'\nimport { load as loadActual } from '../actual/load.ts'\nimport type {\n AddImportersDependenciesMap,\n RemoveImportersDependenciesMap,\n} from '../dependencies.ts'\nimport { Diff } from '../diff.ts'\nimport type { Graph } from '../graph.ts'\nimport { lockfile } from '../index.ts'\nimport type { GraphModifier } from '../modifiers.ts'\nimport {\n lockfileData,\n saveData,\n saveHidden,\n} from '../lockfile/save.ts'\nimport { addEdges } from './add-edges.ts'\nimport { addNodes } from './add-nodes.ts'\nimport { build } from './build.ts'\nimport { deleteEdges } from './delete-edges.ts'\nimport { deleteNodes } from './delete-nodes.ts'\nimport { internalHoist } from './internal-hoist.ts'\nimport { rollback } from './rollback.ts'\nimport { updatePackageJson } from './update-importers-package-json.ts'\nimport { copyFileSync } from 'node:fs'\n\nconst limit = Math.max(availableParallelism() - 1, 1) * 8\n\n// - [ ] depid's with peer resolutions\n// - [ ] depid shortening\n\nexport type ReifyOptions = LoadOptions & {\n add?: AddImportersDependenciesMap\n remove?: RemoveImportersDependenciesMap\n graph: Graph\n actual?: Graph\n packageInfo: PackageInfoClient\n modifiers?: GraphModifier\n}\n\n/**\n * Make the current project match the supplied graph.\n */\nexport const reify = async (options: ReifyOptions) => {\n const done = graphStep('reify')\n\n const { graph, scurry } = options\n\n const actual =\n options.actual ??\n loadActual({\n ...options,\n loadManifests: true,\n })\n\n const diff = new Diff(actual, graph)\n const skipOptionalOnly =\n options.add?.modifiedDependencies && diff.optionalOnly()\n if (!diff.hasChanges() || skipOptionalOnly) {\n // nothing to do, so just return the diff\n done()\n return diff\n }\n\n const remover = new RollbackRemove()\n let success = false\n try {\n await reify_(options, diff, remover)\n remover.confirm()\n success = true\n } finally {\n /* c8 ignore start */\n if (!success) {\n await rollback(remover, diff, scurry).catch(() => {})\n }\n /* c8 ignore stop */\n }\n\n done()\n\n return diff\n}\n\nconst reify_ = async (\n options: ReifyOptions,\n diff: Diff,\n remover: RollbackRemove,\n) => {\n const { add, remove, packageInfo, packageJson, scurry } = options\n const saveImportersPackageJson =\n add?.modifiedDependencies || remove?.modifiedDependencies ?\n updatePackageJson({\n add,\n remove,\n graph: options.graph,\n packageJson,\n })\n : undefined\n\n // before anything else happens, grab the ideal tree as it was resolved\n // so that we can store it in the lockfile. We do this here so that\n // any failed/removed optional deps are not reflected in the lockfile\n // data as it is saved.\n const lfData = lockfileData(options)\n const actions: (() => Promise<unknown>)[] = addNodes(\n diff,\n scurry,\n remover,\n options,\n packageInfo,\n ).concat(deleteEdges(diff, scurry, remover))\n\n // need to wait, so that the nodes exist to link to\n if (actions.length) await callLimit(actions, { limit })\n\n // create all node_modules symlinks, and link bins to nm/.bin\n const edgeActions: Promise<unknown>[] = addEdges(\n diff,\n packageJson,\n scurry,\n remover,\n )\n if (edgeActions.length) await Promise.all(edgeActions)\n\n await internalHoist(diff.to, options, remover)\n\n // run lifecycles and chmod bins\n await build(diff, packageJson, scurry)\n\n // save the lockfile\n lockfile.save(options)\n\n // if we had to change the actual graph along the way,\n // make sure we do not leave behind any unreachable nodes\n if (diff.hadOptionalFailures) {\n for (const node of options.graph.gc().values()) {\n diff.nodes.add.delete(node)\n diff.nodes.delete.add(node)\n }\n }\n saveHidden(options)\n\n // delete garbage from the store.\n const rmActions: Promise<unknown>[] = deleteNodes(\n diff,\n remover,\n scurry,\n )\n if (rmActions.length) await Promise.all(rmActions)\n\n // updates package.json files if anything was added / removed\n saveImportersPackageJson?.()\n\n // write the ideal graph data to the lockfile\n saveData(lfData, scurry.resolve('vlt-lock.json'), false)\n\n // update the store config reference if a config file was used\n if (scurry.lstatSync('vlt.json')) {\n copyFileSync(\n scurry.resolve('vlt.json'),\n scurry.resolve('node_modules/.vlt/vlt.json'),\n )\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reify/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAE9C,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAKtD,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEjC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,UAAU,GACX,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,WAAW,E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AAM,aAAa,CAAC,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IAE9C,gCAAgC;IAChC,MAAM,KAAK,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,CAAC,CAAA;IAEtC,oBAAoB;IACpB,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAEtB,sDAAsD;IACtD,yDAAyD;IACzD,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC7B,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC;YAC/C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YAC3B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAC7B,CAAC;IACH,CAAC;IACD,UAAU,CAAC,OAAO,CAAC,CAAA;IAEnB,iCAAiC;IACjC,MAAM,SAAS,GAAuB,WAAW,CAC/C,IAAI,EACJ,OAAO,EACP,MAAM,CACP,CAAA;IACD,IAAI,SAAS,CAAC,MAAM;QAAE,MAAM,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;IAElD,6DAA6D;IAC7D,wBAAwB,EAAE,EAAE,CAAA;IAE5B,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,KAAK,CAAC,CAAA;IAExD,8DAA8D;IAC9D,IAAI,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;QACjC,YAAY,CACV,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAC1B,MAAM,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAC7C,CAAA;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { graphStep } from '@vltpkg/output'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport { RollbackRemove } from '@vltpkg/rollback-remove'\nimport { availableParallelism } from 'node:os'\nimport { callLimit } from 'promise-call-limit'\nimport type { LoadOptions } from '../actual/load.ts'\nimport { load as loadActual } from '../actual/load.ts'\nimport type {\n AddImportersDependenciesMap,\n RemoveImportersDependenciesMap,\n} from '../dependencies.ts'\nimport { Diff } from '../diff.ts'\nimport type { Graph } from '../graph.ts'\nimport { lockfile } from '../index.ts'\nimport type { GraphModifier } from '../modifiers.ts'\nimport {\n lockfileData,\n saveData,\n saveHidden,\n} from '../lockfile/save.ts'\nimport { addEdges } from './add-edges.ts'\nimport { addNodes } from './add-nodes.ts'\nimport { build } from './build.ts'\nimport { deleteEdges } from './delete-edges.ts'\nimport { deleteNodes } from './delete-nodes.ts'\nimport { internalHoist } from './internal-hoist.ts'\nimport { rollback } from './rollback.ts'\nimport { updatePackageJson } from './update-importers-package-json.ts'\nimport { copyFileSync } from 'node:fs'\n\nconst limit = Math.max(availableParallelism() - 1, 1) * 8\n\n// - [ ] depid's with peer resolutions\n// - [ ] depid shortening\n\nexport type ReifyOptions = LoadOptions & {\n add?: AddImportersDependenciesMap\n remove?: RemoveImportersDependenciesMap\n graph: Graph\n actual?: Graph\n packageInfo: PackageInfoClient\n modifiers?: GraphModifier\n}\n\n/**\n * Make the current project match the supplied graph.\n */\nexport const reify = async (options: ReifyOptions) => {\n const done = graphStep('reify')\n\n const { graph, scurry } = options\n\n const actual =\n options.actual ??\n loadActual({\n ...options,\n loadManifests: true,\n })\n\n const diff = new Diff(actual, graph)\n const skipOptionalOnly =\n options.add?.modifiedDependencies && diff.optionalOnly\n if (!diff.hasChanges() || skipOptionalOnly) {\n // nothing to do, so just return the diff\n done()\n return diff\n }\n\n const remover = new RollbackRemove()\n let success = false\n try {\n await reify_(options, diff, remover)\n remover.confirm()\n success = true\n } finally {\n /* c8 ignore start */\n if (!success) {\n await rollback(remover, diff, scurry).catch(() => {})\n }\n /* c8 ignore stop */\n }\n\n done()\n\n return diff\n}\n\nconst reify_ = async (\n options: ReifyOptions,\n diff: Diff,\n remover: RollbackRemove,\n) => {\n const { add, remove, packageInfo, packageJson, scurry } = options\n const saveImportersPackageJson =\n add?.modifiedDependencies || remove?.modifiedDependencies ?\n updatePackageJson({\n add,\n remove,\n graph: options.graph,\n packageJson,\n })\n : undefined\n\n // before anything else happens, grab the ideal tree as it was resolved\n // so that we can store it in the lockfile. We do this here so that\n // any failed/removed optional deps are not reflected in the lockfile\n // data as it is saved.\n const lfData = lockfileData(options)\n const actions: (() => Promise<unknown>)[] = addNodes(\n diff,\n scurry,\n remover,\n options,\n packageInfo,\n ).concat(deleteEdges(diff, scurry, remover))\n\n // need to wait, so that the nodes exist to link to\n if (actions.length) await callLimit(actions, { limit })\n\n // create all node_modules symlinks, and link bins to nm/.bin\n const edgeActions: Promise<unknown>[] = addEdges(\n diff,\n packageJson,\n scurry,\n remover,\n )\n if (edgeActions.length) await Promise.all(edgeActions)\n\n await internalHoist(diff.to, options, remover)\n\n // run lifecycles and chmod bins\n await build(diff, packageJson, scurry)\n\n // save the lockfile\n lockfile.save(options)\n\n // if we had to change the actual graph along the way,\n // make sure we do not leave behind any unreachable nodes\n if (diff.hadOptionalFailures) {\n for (const node of options.graph.gc().values()) {\n diff.nodes.add.delete(node)\n diff.nodes.delete.add(node)\n }\n }\n saveHidden(options)\n\n // delete garbage from the store.\n const rmActions: Promise<unknown>[] = deleteNodes(\n diff,\n remover,\n scurry,\n )\n if (rmActions.length) await Promise.all(rmActions)\n\n // updates package.json files if anything was added / removed\n saveImportersPackageJson?.()\n\n // write the ideal graph data to the lockfile\n saveData(lfData, scurry.resolve('vlt-lock.json'), false)\n\n // update the store config reference if a config file was used\n if (scurry.lstatSync('vlt.json')) {\n copyFileSync(\n scurry.resolve('vlt.json'),\n scurry.resolve('node_modules/.vlt/vlt.json'),\n )\n }\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vltpkg/graph",
3
3
  "description": "A library that helps understanding & expressing what happens on an install",
4
- "version": "0.0.0-24",
4
+ "version": "0.0.0-25",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
@@ -23,23 +23,23 @@
23
23
  "graph-run": "^1.1.0",
24
24
  "path-scurry": "^2.0.0",
25
25
  "promise-call-limit": "^3.0.2",
26
- "@vltpkg/cmd-shim": "0.0.0-24",
27
- "@vltpkg/dep-id": "0.0.0-24",
28
- "@vltpkg/error-cause": "0.0.0-24",
29
- "@vltpkg/fast-split": "0.0.0-24",
30
- "@vltpkg/dss-breadcrumb": "0.0.0-24",
31
- "@vltpkg/init": "0.0.0-24",
32
- "@vltpkg/package-info": "0.0.0-24",
33
- "@vltpkg/output": "0.0.0-24",
34
- "@vltpkg/package-json": "0.0.0-24",
35
- "@vltpkg/pick-manifest": "0.0.0-24",
36
- "@vltpkg/rollback-remove": "0.0.0-24",
37
- "@vltpkg/spec": "0.0.0-24",
38
- "@vltpkg/run": "0.0.0-24",
39
- "@vltpkg/vlt-json": "0.0.0-24",
40
- "@vltpkg/workspaces": "0.0.0-24",
41
- "@vltpkg/satisfies": "0.0.0-24",
42
- "@vltpkg/types": "0.0.0-24"
26
+ "@vltpkg/cmd-shim": "0.0.0-25",
27
+ "@vltpkg/dss-breadcrumb": "0.0.0-25",
28
+ "@vltpkg/dep-id": "0.0.0-25",
29
+ "@vltpkg/fast-split": "0.0.0-25",
30
+ "@vltpkg/error-cause": "0.0.0-25",
31
+ "@vltpkg/output": "0.0.0-25",
32
+ "@vltpkg/init": "0.0.0-25",
33
+ "@vltpkg/package-json": "0.0.0-25",
34
+ "@vltpkg/package-info": "0.0.0-25",
35
+ "@vltpkg/pick-manifest": "0.0.0-25",
36
+ "@vltpkg/rollback-remove": "0.0.0-25",
37
+ "@vltpkg/run": "0.0.0-25",
38
+ "@vltpkg/satisfies": "0.0.0-25",
39
+ "@vltpkg/spec": "0.0.0-25",
40
+ "@vltpkg/vlt-json": "0.0.0-25",
41
+ "@vltpkg/workspaces": "0.0.0-25",
42
+ "@vltpkg/types": "0.0.0-25"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@eslint/js": "^9.34.0",
@@ -52,7 +52,7 @@
52
52
  "typedoc": "~0.27.9",
53
53
  "typescript": "5.7.3",
54
54
  "typescript-eslint": "^8.40.0",
55
- "@vltpkg/vlt-json": "0.0.0-24"
55
+ "@vltpkg/vlt-json": "0.0.0-25"
56
56
  },
57
57
  "license": "BSD-2-Clause-Patent",
58
58
  "engines": {