@antongolub/lockfile 0.0.0-snapshot.66 → 0.0.0-snapshot.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/complete.js CHANGED
@@ -146,11 +146,14 @@ async function completeTransitives(graph, registry, options = {}) {
146
146
  }).graph;
147
147
  };
148
148
  const frontier = [];
149
- for (const root of currentGraph.roots()) {
150
- if (!seed.recentlyOrphaned.has(root)) frontier.push(root);
151
- }
152
- for (const id of seed.recentlyAdded) {
153
- if (!seed.recentlyOrphaned.has(id)) frontier.push(id);
149
+ if (options.seed === void 0) {
150
+ for (const root of currentGraph.roots()) {
151
+ if (!seed.recentlyOrphaned.has(root)) frontier.push(root);
152
+ }
153
+ } else {
154
+ for (const id of seed.recentlyAdded) {
155
+ if (!seed.recentlyOrphaned.has(id)) frontier.push(id);
156
+ }
154
157
  }
155
158
  while (frontier.length > 0) {
156
159
  const nodeId = frontier.shift();
@@ -791,8 +791,7 @@ function deriveRegistryUrl(name, spec) {
791
791
  return registryUrlOf(aliasName, aliasVersion);
792
792
  }
793
793
  }
794
- const ver = spec;
795
- return registryUrlOf(name ?? "", ver);
794
+ return registryUrlOf(name ?? "", spec);
796
795
  }
797
796
  function looksLikeNpmName(s) {
798
797
  return /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i.test(s);
@@ -845,8 +845,7 @@ function deriveRegistryUrl(name, spec) {
845
845
  return registryUrlOf(aliasName, aliasVersion);
846
846
  }
847
847
  }
848
- const ver = spec;
849
- return registryUrlOf(name ?? "", ver);
848
+ return registryUrlOf(name ?? "", spec);
850
849
  }
851
850
  function looksLikeNpmName(s) {
852
851
  return /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i.test(s);
@@ -845,8 +845,7 @@ function deriveRegistryUrl(name, spec) {
845
845
  return registryUrlOf(aliasName, aliasVersion);
846
846
  }
847
847
  }
848
- const ver = spec;
849
- return registryUrlOf(name ?? "", ver);
848
+ return registryUrlOf(name ?? "", spec);
850
849
  }
851
850
  function looksLikeNpmName(s) {
852
851
  return /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i.test(s);
@@ -811,8 +811,7 @@ function deriveRegistryUrl(name, spec) {
811
811
  return registryUrlOf(aliasName, aliasVersion);
812
812
  }
813
813
  }
814
- const ver = spec;
815
- return registryUrlOf(name ?? "", ver);
814
+ return registryUrlOf(name ?? "", spec);
816
815
  }
817
816
  function looksLikeNpmName(s) {
818
817
  return /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i.test(s);
@@ -1313,10 +1312,7 @@ function emitBlockMap(lines, map, depth, sectionKey) {
1313
1312
  if (pair === void 0) continue;
1314
1313
  const [key, value] = pair;
1315
1314
  const emittedKey = emitScalarKey(key);
1316
- if (isTopSubsection && i > 0) lines.push("");
1317
- if (isTopSubsection) {
1318
- if (i === 0) lines.push("");
1319
- }
1315
+ if (isTopSubsection) lines.push("");
1320
1316
  if (value === void 0 || value === null) {
1321
1317
  lines.push(`${indent}${emittedKey}:`);
1322
1318
  continue;
@@ -870,8 +870,7 @@ function deriveRegistryUrl(name, spec) {
870
870
  return registryUrlOf(aliasName, aliasVersion);
871
871
  }
872
872
  }
873
- const ver = spec;
874
- return registryUrlOf(name ?? "", ver);
873
+ return registryUrlOf(name ?? "", spec);
875
874
  }
876
875
  function looksLikeNpmName(s) {
877
876
  return /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i.test(s);
@@ -1537,10 +1536,7 @@ function emitBlockMap(lines, map, depth, sectionKey) {
1537
1536
  if (pair === void 0) continue;
1538
1537
  const [key, value] = pair;
1539
1538
  const emittedKey = emitScalarKey(key);
1540
- if (isTopSubsection && i > 0) lines.push("");
1541
- if (isTopSubsection) {
1542
- if (i === 0) lines.push("");
1543
- }
1539
+ if (isTopSubsection) lines.push("");
1544
1540
  if (value === void 0 || value === null) {
1545
1541
  lines.push(`${indent}${emittedKey}:`);
1546
1542
  continue;
@@ -870,8 +870,7 @@ function deriveRegistryUrl(name, spec) {
870
870
  return registryUrlOf(aliasName, aliasVersion);
871
871
  }
872
872
  }
873
- const ver = spec;
874
- return registryUrlOf(name ?? "", ver);
873
+ return registryUrlOf(name ?? "", spec);
875
874
  }
876
875
  function looksLikeNpmName(s) {
877
876
  return /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i.test(s);
@@ -1537,10 +1536,7 @@ function emitBlockMap(lines, map, depth, sectionKey) {
1537
1536
  if (pair === void 0) continue;
1538
1537
  const [key, value] = pair;
1539
1538
  const emittedKey = emitScalarKey(key);
1540
- if (isTopSubsection && i > 0) lines.push("");
1541
- if (isTopSubsection) {
1542
- if (i === 0) lines.push("");
1543
- }
1539
+ if (isTopSubsection) lines.push("");
1544
1540
  if (value === void 0 || value === null) {
1545
1541
  lines.push(`${indent}${emittedKey}:`);
1546
1542
  continue;
@@ -1168,8 +1168,7 @@ function deriveRegistryUrl(name, spec) {
1168
1168
  return registryUrlOf(aliasName, aliasVersion);
1169
1169
  }
1170
1170
  }
1171
- const ver = spec;
1172
- return registryUrlOf(name ?? "", ver);
1171
+ return registryUrlOf(name ?? "", spec);
1173
1172
  }
1174
1173
  function looksLikeNpmName(s) {
1175
1174
  return /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i.test(s);
@@ -1168,8 +1168,7 @@ function deriveRegistryUrl(name, spec) {
1168
1168
  return registryUrlOf(aliasName, aliasVersion);
1169
1169
  }
1170
1170
  }
1171
- const ver = spec;
1172
- return registryUrlOf(name ?? "", ver);
1171
+ return registryUrlOf(name ?? "", spec);
1173
1172
  }
1174
1173
  function looksLikeNpmName(s) {
1175
1174
  return /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i.test(s);
@@ -1168,8 +1168,7 @@ function deriveRegistryUrl(name, spec) {
1168
1168
  return registryUrlOf(aliasName, aliasVersion);
1169
1169
  }
1170
1170
  }
1171
- const ver = spec;
1172
- return registryUrlOf(name ?? "", ver);
1171
+ return registryUrlOf(name ?? "", spec);
1173
1172
  }
1174
1173
  function looksLikeNpmName(s) {
1175
1174
  return /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i.test(s);
@@ -1168,8 +1168,7 @@ function deriveRegistryUrl(name, spec) {
1168
1168
  return registryUrlOf(aliasName, aliasVersion);
1169
1169
  }
1170
1170
  }
1171
- const ver = spec;
1172
- return registryUrlOf(name ?? "", ver);
1171
+ return registryUrlOf(name ?? "", spec);
1173
1172
  }
1174
1173
  function looksLikeNpmName(s) {
1175
1174
  return /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i.test(s);
@@ -1168,8 +1168,7 @@ function deriveRegistryUrl(name, spec) {
1168
1168
  return registryUrlOf(aliasName, aliasVersion);
1169
1169
  }
1170
1170
  }
1171
- const ver = spec;
1172
- return registryUrlOf(name ?? "", ver);
1171
+ return registryUrlOf(name ?? "", spec);
1173
1172
  }
1174
1173
  function looksLikeNpmName(s) {
1175
1174
  return /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i.test(s);
@@ -1168,8 +1168,7 @@ function deriveRegistryUrl(name, spec) {
1168
1168
  return registryUrlOf(aliasName, aliasVersion);
1169
1169
  }
1170
1170
  }
1171
- const ver = spec;
1172
- return registryUrlOf(name ?? "", ver);
1171
+ return registryUrlOf(name ?? "", spec);
1173
1172
  }
1174
1173
  function looksLikeNpmName(s) {
1175
1174
  return /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i.test(s);
@@ -1168,8 +1168,7 @@ function deriveRegistryUrl(name, spec) {
1168
1168
  return registryUrlOf(aliasName, aliasVersion);
1169
1169
  }
1170
1170
  }
1171
- const ver = spec;
1172
- return registryUrlOf(name ?? "", ver);
1171
+ return registryUrlOf(name ?? "", spec);
1173
1172
  }
1174
1173
  function looksLikeNpmName(s) {
1175
1174
  return /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i.test(s);
@@ -914,8 +914,7 @@ function deriveRegistryUrl(name, spec) {
914
914
  return registryUrlOf(aliasName, aliasVersion);
915
915
  }
916
916
  }
917
- const ver = spec;
918
- return registryUrlOf(name ?? "", ver);
917
+ return registryUrlOf(name ?? "", spec);
919
918
  }
920
919
  function looksLikeNpmName(s) {
921
920
  return /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i.test(s);
package/dist/index.d.ts CHANGED
@@ -21,7 +21,7 @@ type FormatId = 'yarn-berry-v4' | 'yarn-berry-v5' | 'yarn-berry-v6' | 'yarn-berr
21
21
 
22
22
  type ParseOptions = {
23
23
  /**
24
- * Filesystem root для adapter parse hooks that read out-of-lockfile
24
+ * Filesystem root for adapter parse hooks that read out-of-lockfile
25
25
  * sources (yarn-berry / pnpm v6 / pnpm v9 patch byte hashing per
26
26
  * ADR-0014 §4.F2). Adapters without out-of-lockfile reads ignore it.
27
27
  */
package/dist/index.js CHANGED
@@ -1134,8 +1134,7 @@ function deriveRegistryUrl(name, spec) {
1134
1134
  return registryUrlOf(aliasName, aliasVersion);
1135
1135
  }
1136
1136
  }
1137
- const ver = spec;
1138
- return registryUrlOf(name ?? "", ver);
1137
+ return registryUrlOf(name ?? "", spec);
1139
1138
  }
1140
1139
  function looksLikeNpmName(s) {
1141
1140
  return /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i.test(s);
@@ -2701,10 +2700,7 @@ function emitBlockMap(lines, map, depth, sectionKey) {
2701
2700
  if (pair === void 0) continue;
2702
2701
  const [key, value] = pair;
2703
2702
  const emittedKey = emitScalarKey(key);
2704
- if (isTopSubsection && i > 0) lines.push("");
2705
- if (isTopSubsection) {
2706
- if (i === 0) lines.push("");
2707
- }
2703
+ if (isTopSubsection) lines.push("");
2708
2704
  if (value === void 0 || value === null) {
2709
2705
  lines.push(`${indent}${emittedKey}:`);
2710
2706
  continue;
@@ -10349,10 +10345,8 @@ async function applyPatch(graph, spec, patchBytes, _context, options = {}) {
10349
10345
  });
10350
10346
  currentGraph = tarballResult.graph;
10351
10347
  patched.push({ from: node.id, to: newId });
10352
- if (newId !== node.id) {
10353
- recentlyAdded.add(newId);
10354
- recentlyOrphaned.add(node.id);
10355
- }
10348
+ recentlyAdded.add(newId);
10349
+ recentlyOrphaned.add(node.id);
10356
10350
  emit(appliedDiag);
10357
10351
  }
10358
10352
  if (normalised && patched.length > 0) {
@@ -10484,7 +10478,7 @@ function gcOrphans(graph, nodeId, removed, recentlyOrphaned, emit) {
10484
10478
  if (node === void 0) return graph;
10485
10479
  if (node.workspacePath !== void 0) return graph;
10486
10480
  if (graph.in(nodeId).length > 0) return graph;
10487
- const outTargets = graph.out(nodeId).map((e) => ({ dst: e.dst, kind: e.kind }));
10481
+ const outTargets = graph.out(nodeId).map((e) => e.dst);
10488
10482
  const removedDiag = modifyNodeRemoved(nodeId);
10489
10483
  graph = graph.mutate((m) => {
10490
10484
  m.removeNode(nodeId);
@@ -10493,7 +10487,7 @@ function gcOrphans(graph, nodeId, removed, recentlyOrphaned, emit) {
10493
10487
  removed.push(nodeId);
10494
10488
  recentlyOrphaned.add(nodeId);
10495
10489
  emit(removedDiag);
10496
- for (const { dst } of outTargets) {
10490
+ for (const dst of outTargets) {
10497
10491
  graph = gcOrphans(graph, dst, removed, recentlyOrphaned, emit);
10498
10492
  }
10499
10493
  return graph;
@@ -10724,7 +10718,7 @@ function gcOrphans2(graph, nodeId, removed, recentlyOrphaned, emit) {
10724
10718
  if (node === void 0) return graph;
10725
10719
  if (node.workspacePath !== void 0) return graph;
10726
10720
  if (graph.in(nodeId).length > 0) return graph;
10727
- const outTargets = graph.out(nodeId).map((e) => ({ dst: e.dst, kind: e.kind }));
10721
+ const outTargets = graph.out(nodeId).map((e) => e.dst);
10728
10722
  const removedDiag = modifyNodeRemoved(nodeId);
10729
10723
  graph = graph.mutate((m) => {
10730
10724
  m.removeNode(nodeId);
@@ -10733,7 +10727,7 @@ function gcOrphans2(graph, nodeId, removed, recentlyOrphaned, emit) {
10733
10727
  removed.push(nodeId);
10734
10728
  recentlyOrphaned.add(nodeId);
10735
10729
  emit(removedDiag);
10736
- for (const { dst } of outTargets) {
10730
+ for (const dst of outTargets) {
10737
10731
  graph = gcOrphans2(graph, dst, removed, recentlyOrphaned, emit);
10738
10732
  }
10739
10733
  return graph;
@@ -10846,6 +10840,14 @@ function optimizeNoop() {
10846
10840
  message: "optimize: no orphans to collect"
10847
10841
  };
10848
10842
  }
10843
+ function optimizeNoRoots() {
10844
+ return {
10845
+ code: "OPTIMIZE_NO_ROOTS",
10846
+ severity: "warning",
10847
+ subject: "graph",
10848
+ message: "optimize: no workspace roots or preserve set on a non-empty graph \u2014 kept all nodes to avoid pruning the whole graph"
10849
+ };
10850
+ }
10849
10851
 
10850
10852
  // src/main/ts/optimize/optimize.ts
10851
10853
  function optimize(graph, options = {}) {
@@ -10856,10 +10858,20 @@ function optimize(graph, options = {}) {
10856
10858
  const n = graph.getNode(id);
10857
10859
  if ((n == null ? void 0 : n.workspacePath) !== void 0) live.add(id);
10858
10860
  }
10861
+ let hasNodes = false;
10859
10862
  for (const node of graph.nodes()) {
10863
+ hasNodes = true;
10860
10864
  if (node.workspacePath !== void 0) live.add(node.id);
10861
10865
  }
10862
10866
  for (const id of preserve) live.add(id);
10867
+ if (live.size === 0 && hasNodes) {
10868
+ const diag = optimizeNoRoots();
10869
+ const guarded = graph.mutate((m) => {
10870
+ m.diagnostic(diag);
10871
+ }).graph;
10872
+ if (onDiagnostic !== void 0) onDiagnostic(diag);
10873
+ return { graph: guarded, removed: [], unresolved: [diag] };
10874
+ }
10863
10875
  const frontier = Array.from(live);
10864
10876
  while (frontier.length > 0) {
10865
10877
  const cur = frontier.shift();
package/dist/modify.js CHANGED
@@ -404,10 +404,8 @@ async function applyPatch(graph, spec, patchBytes, _context, options = {}) {
404
404
  });
405
405
  currentGraph = tarballResult.graph;
406
406
  patched.push({ from: node.id, to: newId });
407
- if (newId !== node.id) {
408
- recentlyAdded.add(newId);
409
- recentlyOrphaned.add(node.id);
410
- }
407
+ recentlyAdded.add(newId);
408
+ recentlyOrphaned.add(node.id);
411
409
  emit(appliedDiag);
412
410
  }
413
411
  if (normalised && patched.length > 0) {
@@ -539,7 +537,7 @@ function gcOrphans(graph, nodeId, removed, recentlyOrphaned, emit) {
539
537
  if (node === void 0) return graph;
540
538
  if (node.workspacePath !== void 0) return graph;
541
539
  if (graph.in(nodeId).length > 0) return graph;
542
- const outTargets = graph.out(nodeId).map((e) => ({ dst: e.dst, kind: e.kind }));
540
+ const outTargets = graph.out(nodeId).map((e) => e.dst);
543
541
  const removedDiag = modifyNodeRemoved(nodeId);
544
542
  graph = graph.mutate((m) => {
545
543
  m.removeNode(nodeId);
@@ -548,7 +546,7 @@ function gcOrphans(graph, nodeId, removed, recentlyOrphaned, emit) {
548
546
  removed.push(nodeId);
549
547
  recentlyOrphaned.add(nodeId);
550
548
  emit(removedDiag);
551
- for (const { dst } of outTargets) {
549
+ for (const dst of outTargets) {
552
550
  graph = gcOrphans(graph, dst, removed, recentlyOrphaned, emit);
553
551
  }
554
552
  return graph;
@@ -779,7 +777,7 @@ function gcOrphans2(graph, nodeId, removed, recentlyOrphaned, emit) {
779
777
  if (node === void 0) return graph;
780
778
  if (node.workspacePath !== void 0) return graph;
781
779
  if (graph.in(nodeId).length > 0) return graph;
782
- const outTargets = graph.out(nodeId).map((e) => ({ dst: e.dst, kind: e.kind }));
780
+ const outTargets = graph.out(nodeId).map((e) => e.dst);
783
781
  const removedDiag = modifyNodeRemoved(nodeId);
784
782
  graph = graph.mutate((m) => {
785
783
  m.removeNode(nodeId);
@@ -788,7 +786,7 @@ function gcOrphans2(graph, nodeId, removed, recentlyOrphaned, emit) {
788
786
  removed.push(nodeId);
789
787
  recentlyOrphaned.add(nodeId);
790
788
  emit(removedDiag);
791
- for (const { dst } of outTargets) {
789
+ for (const dst of outTargets) {
792
790
  graph = gcOrphans2(graph, dst, removed, recentlyOrphaned, emit);
793
791
  }
794
792
  return graph;
@@ -1,7 +1,7 @@
1
1
  export { O as OptimizeOptions, a as OptimizeResult, o as optimize } from './optimize-B6TOjYyj.js';
2
2
  import { D as Diagnostic, N as NodeId } from './graph-CPo-SvS2.js';
3
3
 
4
- type OptimizeDiagnosticCode = 'OPTIMIZE_NODE_REMOVED' | 'OPTIMIZE_WORKSPACE_UNREACHABLE' | 'OPTIMIZE_NOOP';
4
+ type OptimizeDiagnosticCode = 'OPTIMIZE_NODE_REMOVED' | 'OPTIMIZE_WORKSPACE_UNREACHABLE' | 'OPTIMIZE_NOOP' | 'OPTIMIZE_NO_ROOTS';
5
5
  interface OptimizeDiagnostic extends Diagnostic {
6
6
  code: OptimizeDiagnosticCode;
7
7
  }
package/dist/optimize.js CHANGED
@@ -59,6 +59,14 @@ function optimizeNoop() {
59
59
  message: "optimize: no orphans to collect"
60
60
  };
61
61
  }
62
+ function optimizeNoRoots() {
63
+ return {
64
+ code: "OPTIMIZE_NO_ROOTS",
65
+ severity: "warning",
66
+ subject: "graph",
67
+ message: "optimize: no workspace roots or preserve set on a non-empty graph \u2014 kept all nodes to avoid pruning the whole graph"
68
+ };
69
+ }
62
70
 
63
71
  // src/main/ts/optimize/optimize.ts
64
72
  function optimize(graph, options = {}) {
@@ -69,10 +77,20 @@ function optimize(graph, options = {}) {
69
77
  const n = graph.getNode(id);
70
78
  if ((n == null ? void 0 : n.workspacePath) !== void 0) live.add(id);
71
79
  }
80
+ let hasNodes = false;
72
81
  for (const node of graph.nodes()) {
82
+ hasNodes = true;
73
83
  if (node.workspacePath !== void 0) live.add(node.id);
74
84
  }
75
85
  for (const id of preserve) live.add(id);
86
+ if (live.size === 0 && hasNodes) {
87
+ const diag = optimizeNoRoots();
88
+ const guarded = graph.mutate((m) => {
89
+ m.diagnostic(diag);
90
+ }).graph;
91
+ if (onDiagnostic !== void 0) onDiagnostic(diag);
92
+ return { graph: guarded, removed: [], unresolved: [diag] };
93
+ }
76
94
  const frontier = Array.from(live);
77
95
  while (frontier.length > 0) {
78
96
  const cur = frontier.shift();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antongolub/lockfile",
3
- "version": "0.0.0-snapshot.66",
3
+ "version": "0.0.0-snapshot.67",
4
4
  "private": false,
5
5
  "description": "Universal lockfile model and converter for npm, yarn, pnpm, bun",
6
6
  "type": "module",