@parcel/graph 2.4.2-nightly.2676 → 2.4.2-nightly.2677

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/lib/Graph.js CHANGED
@@ -117,7 +117,9 @@ class Graph {
117
117
 
118
118
 
119
119
  removeNode(nodeId) {
120
- this._assertHasNodeId(nodeId);
120
+ if (!this.hasNode(nodeId)) {
121
+ return;
122
+ }
121
123
 
122
124
  for (let {
123
125
  type,
@@ -140,7 +142,9 @@ class Graph {
140
142
  }
141
143
 
142
144
  removeEdges(nodeId, type = 1) {
143
- this._assertHasNodeId(nodeId);
145
+ if (!this.hasNode(nodeId)) {
146
+ return;
147
+ }
144
148
 
145
149
  for (let to of this.getNodeIdsConnectedFrom(nodeId, type)) {
146
150
  this.removeEdge(nodeId, to, type);
@@ -150,7 +154,7 @@ class Graph {
150
154
 
151
155
  removeEdge(from, to, type = 1, removeOrphans = true) {
152
156
  if (!this.adjacencyList.hasEdge(from, to, type)) {
153
- throw new Error(`Edge from ${(0, _types.fromNodeId)(from)} to ${(0, _types.fromNodeId)(to)} not found!`);
157
+ return;
154
158
  }
155
159
 
156
160
  this.adjacencyList.removeEdge(from, to, type);
@@ -161,7 +165,9 @@ class Graph {
161
165
  }
162
166
 
163
167
  isOrphanedNode(nodeId) {
164
- this._assertHasNodeId(nodeId);
168
+ if (!this.hasNode(nodeId)) {
169
+ return false;
170
+ }
165
171
 
166
172
  if (this.rootNodeId == null) {
167
173
  // If the graph does not have a root, and there are inbound edges,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/graph",
3
- "version": "2.4.2-nightly.2676+681f2b348",
3
+ "version": "2.4.2-nightly.2677+3e5b6c862",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -20,8 +20,8 @@
20
20
  "node": ">= 12.0.0"
21
21
  },
22
22
  "dependencies": {
23
- "@parcel/utils": "2.0.0-nightly.1053+681f2b348",
23
+ "@parcel/utils": "2.0.0-nightly.1054+3e5b6c862",
24
24
  "nullthrows": "^1.1.1"
25
25
  },
26
- "gitHead": "681f2b348dda36bce27914051f245604bb94f14e"
26
+ "gitHead": "3e5b6c862efe926a3af1511eac77a0d7c78cfcec"
27
27
  }
package/src/Graph.js CHANGED
@@ -137,7 +137,9 @@ export default class Graph<TNode, TEdgeType: number = 1> {
137
137
 
138
138
  // Removes node and any edges coming from or to that node
139
139
  removeNode(nodeId: NodeId) {
140
- this._assertHasNodeId(nodeId);
140
+ if (!this.hasNode(nodeId)) {
141
+ return;
142
+ }
141
143
 
142
144
  for (let {type, from} of this.adjacencyList.getInboundEdgesByType(nodeId)) {
143
145
  this.removeEdge(
@@ -159,7 +161,9 @@ export default class Graph<TNode, TEdgeType: number = 1> {
159
161
  }
160
162
 
161
163
  removeEdges(nodeId: NodeId, type: TEdgeType | NullEdgeType = 1) {
162
- this._assertHasNodeId(nodeId);
164
+ if (!this.hasNode(nodeId)) {
165
+ return;
166
+ }
163
167
 
164
168
  for (let to of this.getNodeIdsConnectedFrom(nodeId, type)) {
165
169
  this.removeEdge(nodeId, to, type);
@@ -174,9 +178,7 @@ export default class Graph<TNode, TEdgeType: number = 1> {
174
178
  removeOrphans: boolean = true,
175
179
  ) {
176
180
  if (!this.adjacencyList.hasEdge(from, to, type)) {
177
- throw new Error(
178
- `Edge from ${fromNodeId(from)} to ${fromNodeId(to)} not found!`,
179
- );
181
+ return;
180
182
  }
181
183
 
182
184
  this.adjacencyList.removeEdge(from, to, type);
@@ -186,7 +188,9 @@ export default class Graph<TNode, TEdgeType: number = 1> {
186
188
  }
187
189
 
188
190
  isOrphanedNode(nodeId: NodeId): boolean {
189
- this._assertHasNodeId(nodeId);
191
+ if (!this.hasNode(nodeId)) {
192
+ return false;
193
+ }
190
194
 
191
195
  if (this.rootNodeId == null) {
192
196
  // If the graph does not have a root, and there are inbound edges,
@@ -20,13 +20,6 @@ describe('Graph', () => {
20
20
  assert.equal(graph.nodes.get(id), node);
21
21
  });
22
22
 
23
- it("errors when removeNode is called with a node that doesn't belong", () => {
24
- let graph = new Graph();
25
- assert.throws(() => {
26
- graph.removeNode(toNodeId(-1));
27
- }, /Does not have node/);
28
- });
29
-
30
23
  it('errors when traversing a graph with no root', () => {
31
24
  let graph = new Graph();
32
25
 
@@ -317,4 +310,24 @@ describe('Graph', () => {
317
310
 
318
311
  assert.deepEqual(visited, [nodeA, nodeB, nodeD]);
319
312
  });
313
+
314
+ it('correctly removes non-tree subgraphs', () => {
315
+ let graph = new Graph();
316
+ let nodeRoot = graph.addNode('root');
317
+ let node1 = graph.addNode('1');
318
+ let node2 = graph.addNode('2');
319
+ let node3 = graph.addNode('3');
320
+
321
+ graph.addEdge(nodeRoot, node1);
322
+ graph.addEdge(node1, node2);
323
+ graph.addEdge(node1, node3);
324
+ graph.addEdge(node2, node3);
325
+
326
+ graph.setRootNodeId(nodeRoot);
327
+
328
+ graph.removeNode(node1);
329
+
330
+ assert.strictEqual(graph.nodes.size, 1);
331
+ assert.deepStrictEqual(Array.from(graph.getAllEdges()), []);
332
+ });
320
333
  });