@parcel/graph 2.0.2-nightly.2563 → 2.0.2-nightly.2571
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/ContentGraph.js +4 -0
- package/lib/Graph.js +10 -0
- package/package.json +2 -2
- package/src/ContentGraph.js +6 -0
- package/src/Graph.js +10 -0
- package/test/Graph.test.js +8 -2
package/lib/ContentGraph.js
CHANGED
@@ -65,6 +65,10 @@ class ContentGraph extends _Graph.default {
|
|
65
65
|
return nodeId;
|
66
66
|
}
|
67
67
|
|
68
|
+
addNodeByContentKeyIfNeeded(contentKey, node) {
|
69
|
+
return this.hasContentKey(contentKey) ? this.getNodeIdByContentKey(contentKey) : this.addNodeByContentKey(contentKey, node);
|
70
|
+
}
|
71
|
+
|
68
72
|
getNodeByContentKey(contentKey) {
|
69
73
|
let nodeId = this._contentKeyToNodeId.get(contentKey);
|
70
74
|
|
package/lib/Graph.js
CHANGED
@@ -338,6 +338,16 @@ class Graph {
|
|
338
338
|
return null;
|
339
339
|
}
|
340
340
|
|
341
|
+
topoSort() {
|
342
|
+
let sorted = [];
|
343
|
+
this.traverse({
|
344
|
+
exit: nodeId => {
|
345
|
+
sorted.push(nodeId);
|
346
|
+
}
|
347
|
+
});
|
348
|
+
return sorted.reverse();
|
349
|
+
}
|
350
|
+
|
341
351
|
findAncestor(nodeId, fn) {
|
342
352
|
let res = null;
|
343
353
|
this.traverseAncestors(nodeId, (nodeId, ctx, traversal) => {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@parcel/graph",
|
3
|
-
"version": "2.0.2-nightly.
|
3
|
+
"version": "2.0.2-nightly.2571+588bf4c0",
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
5
5
|
"license": "MIT",
|
6
6
|
"publishConfig": {
|
@@ -22,5 +22,5 @@
|
|
22
22
|
"dependencies": {
|
23
23
|
"nullthrows": "^1.1.1"
|
24
24
|
},
|
25
|
-
"gitHead": "
|
25
|
+
"gitHead": "588bf4c0d6d9dac65a9bf89bf734d7684b523ca2"
|
26
26
|
}
|
package/src/ContentGraph.js
CHANGED
@@ -62,6 +62,12 @@ export default class ContentGraph<TNode, TEdgeType: number = 1> extends Graph<
|
|
62
62
|
return nodeId;
|
63
63
|
}
|
64
64
|
|
65
|
+
addNodeByContentKeyIfNeeded(contentKey: ContentKey, node: TNode): NodeId {
|
66
|
+
return this.hasContentKey(contentKey)
|
67
|
+
? this.getNodeIdByContentKey(contentKey)
|
68
|
+
: this.addNodeByContentKey(contentKey, node);
|
69
|
+
}
|
70
|
+
|
65
71
|
getNodeByContentKey(contentKey: ContentKey): ?TNode {
|
66
72
|
let nodeId = this._contentKeyToNodeId.get(contentKey);
|
67
73
|
if (nodeId != null) {
|
package/src/Graph.js
CHANGED
@@ -403,6 +403,16 @@ export default class Graph<TNode, TEdgeType: number = 1> {
|
|
403
403
|
return null;
|
404
404
|
}
|
405
405
|
|
406
|
+
topoSort(): Array<NodeId> {
|
407
|
+
let sorted: Array<NodeId> = [];
|
408
|
+
this.traverse({
|
409
|
+
exit: nodeId => {
|
410
|
+
sorted.push(nodeId);
|
411
|
+
},
|
412
|
+
});
|
413
|
+
return sorted.reverse();
|
414
|
+
}
|
415
|
+
|
406
416
|
findAncestor(nodeId: NodeId, fn: (nodeId: NodeId) => boolean): ?NodeId {
|
407
417
|
let res = null;
|
408
418
|
this.traverseAncestors(nodeId, (nodeId, ctx, traversal) => {
|
package/test/Graph.test.js
CHANGED
@@ -83,11 +83,14 @@ describe('Graph', () => {
|
|
83
83
|
|
84
84
|
it('isOrphanedNode should return true or false if the node is orphaned or not', () => {
|
85
85
|
let graph = new Graph();
|
86
|
+
let rootNode = graph.addNode('root');
|
87
|
+
graph.setRootNodeId(rootNode);
|
88
|
+
|
86
89
|
let nodeA = graph.addNode('a');
|
87
90
|
let nodeB = graph.addNode('b');
|
88
91
|
let nodeC = graph.addNode('c');
|
89
|
-
graph.addEdge(
|
90
|
-
graph.addEdge(
|
92
|
+
graph.addEdge(rootNode, nodeB);
|
93
|
+
graph.addEdge(nodeB, nodeC, 1);
|
91
94
|
assert(graph.isOrphanedNode(nodeA));
|
92
95
|
assert(!graph.isOrphanedNode(nodeB));
|
93
96
|
assert(!graph.isOrphanedNode(nodeC));
|
@@ -101,6 +104,7 @@ describe('Graph', () => {
|
|
101
104
|
// c
|
102
105
|
let graph = new Graph();
|
103
106
|
let nodeA = graph.addNode('a');
|
107
|
+
graph.setRootNodeId(nodeA);
|
104
108
|
let nodeB = graph.addNode('b');
|
105
109
|
let nodeC = graph.addNode('c');
|
106
110
|
let nodeD = graph.addNode('d');
|
@@ -140,6 +144,7 @@ describe('Graph', () => {
|
|
140
144
|
|
141
145
|
let graph = new Graph();
|
142
146
|
let nodeA = graph.addNode('a');
|
147
|
+
graph.setRootNodeId(nodeA);
|
143
148
|
let nodeB = graph.addNode('b');
|
144
149
|
let nodeC = graph.addNode('c');
|
145
150
|
let nodeD = graph.addNode('d');
|
@@ -268,6 +273,7 @@ describe('Graph', () => {
|
|
268
273
|
it("replaceNodeIdsConnectedTo should update a node's downstream nodes", () => {
|
269
274
|
let graph = new Graph();
|
270
275
|
let nodeA = graph.addNode('a');
|
276
|
+
graph.setRootNodeId(nodeA);
|
271
277
|
let nodeB = graph.addNode('b');
|
272
278
|
let nodeC = graph.addNode('c');
|
273
279
|
graph.addEdge(nodeA, nodeB);
|