@atlaspack/bundler-experimental 2.13.7-canary.138 → 2.13.7-canary.139

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.
@@ -0,0 +1,13 @@
1
+ import { ContentGraph, NodeId } from '@atlaspack/graph';
2
+ /**
3
+ * A `ContentGraph` that also stores weights on edges.
4
+ *
5
+ * @template N The type of the node weight.
6
+ * @template EW The type of the edge weight.
7
+ */
8
+ export declare class EdgeContentGraph<N, EW> extends ContentGraph<N, number> {
9
+ #private;
10
+ clone(): EdgeContentGraph<N, EW>;
11
+ addWeightedEdge(from: NodeId, to: NodeId, type: number, weight: EW | null): void;
12
+ getEdgeWeight(from: NodeId, to: NodeId): EW | null;
13
+ }
@@ -34,7 +34,7 @@ class EdgeContentGraph extends _graph().ContentGraph {
34
34
  const contentKey = this._nodeIdToContentKey.get(nodeId);
35
35
  if (node == null) {
36
36
  // Add null node to preserve node ids
37
- // $FlowFixMe
37
+ // @ts-expect-error TS2345
38
38
  newGraph.addNode(null);
39
39
  } else if (contentKey == null) {
40
40
  newGraph.addNode(node);
@@ -43,6 +43,7 @@ class EdgeContentGraph extends _graph().ContentGraph {
43
43
  }
44
44
  nodeId += 1;
45
45
  }
46
+ // @ts-expect-error TS2488
46
47
  for (let edge of this.getAllEdges()) {
47
48
  const weight = this.getEdgeWeight(edge.from, edge.to);
48
49
  newGraph.addWeightedEdge(edge.from, edge.to, edge.type, weight);
@@ -0,0 +1,12 @@
1
+ import type { Graph, NodeId } from '@atlaspack/graph';
2
+ export type StronglyConnectedComponent = NodeId[];
3
+ /**
4
+ * Robert Tarjan's algorithm to find strongly connected components in a graph.
5
+ *
6
+ * Time complexity: O(V + E)
7
+ * Space complexity (worst case): O(V)
8
+ *
9
+ * * https://web.archive.org/web/20170829214726id_/http://www.cs.ucsb.edu/~gilbert/cs240a/old/cs240aSpr2011/slides/TarjanDFS.pdf
10
+ * * https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm
11
+ */
12
+ export declare function findStronglyConnectedComponents<T, E extends number>(graph: Graph<T, E>): StronglyConnectedComponent[];
@@ -48,7 +48,9 @@ function findStronglyConnectedComponents(graph) {
48
48
  let member;
49
49
  do {
50
50
  member = stack.pop();
51
+ // @ts-expect-error TS2538
51
52
  state[member].onStack = false;
53
+ // @ts-expect-error TS2345
52
54
  component.push(member);
53
55
  } while (member !== nodeId);
54
56
  result.push(component);
@@ -0,0 +1,58 @@
1
+ import { NodeId, Graph } from '@atlaspack/graph';
2
+ /**
3
+ * Implements "A simple, fast dominance algorithm", to find the immediate
4
+ * dominators of all nodes in a graph.
5
+ *
6
+ * Returns a map of node IDs to their immediate dominator's node ID.
7
+ * This map is represented by an array where the index is the node ID and the
8
+ * value is its dominator.
9
+ *
10
+ * For example, given a node `3`, `dominators[3]` is the immediate dominator
11
+ * of node 3.
12
+ *
13
+ * - https://www.cs.tufts.edu/comp/150FP/archive/keith-cooper/dom14.pdf
14
+ */
15
+ export declare function simpleFastDominance<T>(graph: Graph<T, number>): NodeId[];
16
+ /**
17
+ * Return the post-order of the graph.
18
+ */
19
+ export declare function getGraphPostOrder<T>(graph: Graph<T, number>, type?: number): NodeId[];
20
+ /**
21
+ * From "A Simple, Fast Dominance Algorithm"
22
+ * Keith D. Cooper, Timothy J. Harvey, and Ken Kennedy:
23
+ *
24
+ * > The intersection routine appears at the bottom of the figure.
25
+ * > It implements a “two-finger” algorithm – one can imagine a finger pointing
26
+ * > to each dominator set, each finger moving independently as the comparisons
27
+ * > dictate. In this case, the comparisons are on postorder numbers; for each
28
+ * > intersection, we start the two fingers at the ends of the two sets, and,
29
+ * > until the fingers point to the same postorder number, we move the finger
30
+ * > pointing to the smaller number back one element. Remember that nodes higher
31
+ * > in the dominator tree have higher postorder numbers, which is why intersect
32
+ * > moves the finger whose value is less than the other finger’s. When the two
33
+ * > fingers point at the same element, intersect returns that element. The set
34
+ * > resulting from the intersection begins with the returned element and chains
35
+ * > its way up the doms array to the entry node.
36
+ *
37
+ * `postOrder` is the post-order node list of the graph.
38
+ *
39
+ * `dominators` is the current immediate dominator state for node in the graph.
40
+ *
41
+ * This is coupled with the fact node ids are indexes into an array. It is a map
42
+ * of NodeId -> NodeId, where the value at index `i` is the immediate dominator
43
+ * of the node `i`.
44
+ *
45
+ * `predecessor` is one predecessor node id of the node we're currently
46
+ * computing the immediate dominator for.
47
+ *
48
+ * `newImmediateDominator` is current best immediate dominator candidate for the
49
+ * node we're computing the immediate dominator for.
50
+ *
51
+ * The algorithm is intersecting the dominator sets of the two predecessors and
52
+ * returning dominator node with the highest post-order number by walking up
53
+ * the dominator tree until the two sets intersect.
54
+ *
55
+ * The node with the highest post-order index is the immediate dominator, as
56
+ * it is the closest to the node we're computing for.
57
+ */
58
+ export declare function intersect(postOrderIndexes: number[], dominators: NodeId | null[], predecessor: NodeId, newImmediateDominator: NodeId): NodeId;
@@ -44,15 +44,22 @@ function simpleFastDominance(graph) {
44
44
  changed = false;
45
45
  for (let node of reversedPostOrder) {
46
46
  if (node === graph.rootNodeId) continue;
47
+
48
+ // @ts-expect-error TS7034
47
49
  let newImmediateDominator = null;
48
- graph.forEachNodeIdConnectedTo(node, predecessor => {
50
+ graph.forEachNodeIdConnectedTo(node,
51
+ // @ts-expect-error TS2345
52
+ predecessor => {
53
+ // @ts-expect-error TS7005
49
54
  if (newImmediateDominator == null) {
50
55
  newImmediateDominator = predecessor;
51
56
  } else {
52
57
  if (dominators[predecessor] == null) {
53
58
  return;
54
59
  }
55
- newImmediateDominator = intersect(postOrderIndexes, dominators, predecessor, newImmediateDominator);
60
+ newImmediateDominator = intersect(postOrderIndexes, dominators, predecessor,
61
+ // @ts-expect-error TS7005
62
+ newImmediateDominator);
56
63
  }
57
64
  }, _graph().ALL_EDGE_TYPES);
58
65
  if (dominators[node] !== newImmediateDominator) {
@@ -120,9 +127,11 @@ function intersect(postOrderIndexes, dominators, predecessor, newImmediateDomina
120
127
  let n2 = newImmediateDominator;
121
128
  while (n1 !== n2) {
122
129
  while (postOrderIndexes[n1] < postOrderIndexes[n2]) {
130
+ // @ts-expect-error TS7053
123
131
  n1 = Number(dominators[n1]);
124
132
  }
125
133
  while (postOrderIndexes[n2] < postOrderIndexes[n1]) {
134
+ // @ts-expect-error TS7053
126
135
  n2 = Number(dominators[n2]);
127
136
  }
128
137
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/bundler-experimental",
3
- "version": "2.13.7-canary.138+eda07caaf",
3
+ "version": "2.13.7-canary.139+d2fd84977",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "type": "commonjs",
6
6
  "publishConfig": {
@@ -10,25 +10,29 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/atlassian-labs/atlaspack.git"
12
12
  },
13
- "main": "lib/index.js",
14
- "source": "src/index.js",
13
+ "main": "./lib/index.js",
14
+ "source": "./src/index.ts",
15
+ "types": "./lib/index.d.ts",
15
16
  "engines": {
16
17
  "node": ">= 16.0.0"
17
18
  },
18
19
  "dependencies": {
19
- "@atlaspack/core": "2.16.2-canary.138+eda07caaf",
20
- "@atlaspack/diagnostic": "2.14.1-canary.206+eda07caaf",
21
- "@atlaspack/feature-flags": "2.14.1-canary.206+eda07caaf",
22
- "@atlaspack/graph": "3.4.1-canary.206+eda07caaf",
23
- "@atlaspack/logger": "2.14.5-canary.138+eda07caaf",
24
- "@atlaspack/plugin": "2.14.5-canary.138+eda07caaf",
25
- "@atlaspack/rust": "3.2.1-canary.138+eda07caaf",
26
- "@atlaspack/types": "2.14.5-canary.138+eda07caaf",
27
- "@atlaspack/utils": "2.14.5-canary.138+eda07caaf",
20
+ "@atlaspack/core": "2.16.2-canary.139+d2fd84977",
21
+ "@atlaspack/diagnostic": "2.14.1-canary.207+d2fd84977",
22
+ "@atlaspack/feature-flags": "2.14.1-canary.207+d2fd84977",
23
+ "@atlaspack/graph": "3.4.1-canary.207+d2fd84977",
24
+ "@atlaspack/logger": "2.14.5-canary.139+d2fd84977",
25
+ "@atlaspack/plugin": "2.14.5-canary.139+d2fd84977",
26
+ "@atlaspack/rust": "3.2.1-canary.139+d2fd84977",
27
+ "@atlaspack/types": "2.14.5-canary.139+d2fd84977",
28
+ "@atlaspack/utils": "2.14.5-canary.139+d2fd84977",
28
29
  "nullthrows": "^1.1.1"
29
30
  },
30
31
  "devDependencies": {
31
- "@atlaspack/fs": "2.14.5-canary.138+eda07caaf"
32
+ "@atlaspack/fs": "2.14.5-canary.139+d2fd84977"
32
33
  },
33
- "gitHead": "eda07caafd2ebb814bbdbfd0ec12fa63124e213f"
34
- }
34
+ "scripts": {
35
+ "check-ts": "tsc --emitDeclarationOnly --rootDir src"
36
+ },
37
+ "gitHead": "d2fd849770fe6305e9c694bd97b1bd905abd9d94"
38
+ }
@@ -1,6 +1,4 @@
1
- // @flow strict-local
2
-
3
- import {ContentGraph, type NodeId} from '@atlaspack/graph';
1
+ import {ContentGraph, NodeId} from '@atlaspack/graph';
4
2
  import nullthrows from 'nullthrows';
5
3
 
6
4
  /**
@@ -19,7 +17,7 @@ export class EdgeContentGraph<N, EW> extends ContentGraph<N, number> {
19
17
  const contentKey = this._nodeIdToContentKey.get(nodeId);
20
18
  if (node == null) {
21
19
  // Add null node to preserve node ids
22
- // $FlowFixMe
20
+ // @ts-expect-error TS2345
23
21
  newGraph.addNode(null);
24
22
  } else if (contentKey == null) {
25
23
  newGraph.addNode(node);
@@ -28,6 +26,7 @@ export class EdgeContentGraph<N, EW> extends ContentGraph<N, number> {
28
26
  }
29
27
  nodeId += 1;
30
28
  }
29
+ // @ts-expect-error TS2488
31
30
  for (let edge of this.getAllEdges()) {
32
31
  const weight = this.getEdgeWeight(edge.from, edge.to);
33
32
  newGraph.addWeightedEdge(edge.from, edge.to, edge.type, weight);
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import type {Graph, NodeId} from '@atlaspack/graph';
4
2
 
5
3
  export type StronglyConnectedComponent = NodeId[];
@@ -13,17 +11,17 @@ export type StronglyConnectedComponent = NodeId[];
13
11
  * * https://web.archive.org/web/20170829214726id_/http://www.cs.ucsb.edu/~gilbert/cs240a/old/cs240aSpr2011/slides/TarjanDFS.pdf
14
12
  * * https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm
15
13
  */
16
- export function findStronglyConnectedComponents<T, E: number>(
14
+ export function findStronglyConnectedComponents<T, E extends number>(
17
15
  graph: Graph<T, E>,
18
16
  ): StronglyConnectedComponent[] {
19
- type State = {|
20
- index: null | NodeId,
21
- lowlink: null | NodeId,
22
- onStack: boolean,
23
- |};
24
- const result = [];
17
+ type State = {
18
+ index: null | NodeId;
19
+ lowlink: null | NodeId;
20
+ onStack: boolean;
21
+ };
22
+ const result: Array<StronglyConnectedComponent> = [];
25
23
  let index = 0;
26
- const stack = [];
24
+ const stack: Array<NodeId | number> = [];
27
25
  const state: State[] = new Array(graph.nodes.length).fill(null).map(() => ({
28
26
  index: null,
29
27
  lowlink: null,
@@ -34,7 +32,7 @@ export function findStronglyConnectedComponents<T, E: number>(
34
32
  strongConnect(nodeId);
35
33
  }
36
34
  });
37
- function strongConnect(nodeId) {
35
+ function strongConnect(nodeId: NodeId | number) {
38
36
  const nodeState = state[nodeId];
39
37
  nodeState.index = index;
40
38
  nodeState.lowlink = index;
@@ -62,12 +60,14 @@ export function findStronglyConnectedComponents<T, E: number>(
62
60
  }
63
61
 
64
62
  if (nodeState.lowlink === nodeState.index) {
65
- const component = [];
63
+ const component: Array<NodeId> = [];
66
64
  let member;
67
65
 
68
66
  do {
69
67
  member = stack.pop();
68
+ // @ts-expect-error TS2538
70
69
  state[member].onStack = false;
70
+ // @ts-expect-error TS2345
71
71
  component.push(member);
72
72
  } while (member !== nodeId);
73
73
 
@@ -1,6 +1,4 @@
1
- // @flow strict-local
2
-
3
- import {type NodeId, Graph, ALL_EDGE_TYPES} from '@atlaspack/graph';
1
+ import {NodeId, Graph, ALL_EDGE_TYPES} from '@atlaspack/graph';
4
2
 
5
3
  /**
6
4
  * Implements "A simple, fast dominance algorithm", to find the immediate
@@ -40,10 +38,13 @@ export function simpleFastDominance<T>(graph: Graph<T, number>): NodeId[] {
40
38
  for (let node of reversedPostOrder) {
41
39
  if (node === graph.rootNodeId) continue;
42
40
 
41
+ // @ts-expect-error TS7034
43
42
  let newImmediateDominator = null;
44
43
  graph.forEachNodeIdConnectedTo(
45
44
  node,
45
+ // @ts-expect-error TS2345
46
46
  (predecessor) => {
47
+ // @ts-expect-error TS7005
47
48
  if (newImmediateDominator == null) {
48
49
  newImmediateDominator = predecessor;
49
50
  } else {
@@ -55,6 +56,7 @@ export function simpleFastDominance<T>(graph: Graph<T, number>): NodeId[] {
55
56
  postOrderIndexes,
56
57
  dominators,
57
58
  predecessor,
59
+ // @ts-expect-error TS7005
58
60
  newImmediateDominator,
59
61
  );
60
62
  }
@@ -79,7 +81,7 @@ export function getGraphPostOrder<T>(
79
81
  graph: Graph<T, number>,
80
82
  type: number = 1,
81
83
  ): NodeId[] {
82
- const postOrder = [];
84
+ const postOrder: Array<NodeId> = [];
83
85
  graph.traverse(
84
86
  {
85
87
  exit: (node) => {
@@ -132,7 +134,7 @@ export function getGraphPostOrder<T>(
132
134
  */
133
135
  export function intersect(
134
136
  postOrderIndexes: number[],
135
- dominators: (NodeId | null)[],
137
+ dominators: NodeId | null[],
136
138
  predecessor: NodeId,
137
139
  newImmediateDominator: NodeId,
138
140
  ): NodeId {
@@ -140,9 +142,11 @@ export function intersect(
140
142
  let n2: number = newImmediateDominator;
141
143
  while (n1 !== n2) {
142
144
  while (postOrderIndexes[n1] < postOrderIndexes[n2]) {
145
+ // @ts-expect-error TS7053
143
146
  n1 = Number(dominators[n1]);
144
147
  }
145
148
  while (postOrderIndexes[n2] < postOrderIndexes[n1]) {
149
+ // @ts-expect-error TS7053
146
150
  n2 = Number(dominators[n2]);
147
151
  }
148
152
  }
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import assert from 'assert';
4
2
  import {EdgeContentGraph} from '../../src/DominatorBundler/EdgeContentGraph';
5
3
 
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import {Graph} from '@atlaspack/graph';
4
2
  import assert from 'assert';
5
3
  import {findStronglyConnectedComponents} from '../../../src/DominatorBundler/cycleBreaker/findStronglyConnectedComponents';
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import assert from 'assert';
4
2
  import {Graph} from '@atlaspack/graph';
5
3
  import {simpleFastDominance} from '../../../src/DominatorBundler/findAssetDominators/simpleFastDominance';
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import {MemoryFS} from '@atlaspack/fs';
4
2
  import assert from 'assert';
5
3
  import {workerFarm} from '@atlaspack/test-utils';
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  /*!
4
2
  * This module provides a way to write fixtures where we don't care about the
5
3
  * code within the assets; only the shape of the asset graphs.
@@ -15,44 +13,44 @@ export type GraphEntry = AssetEntry;
15
13
  /**
16
14
  * An asset in the fixture graph. Just a path and dependencies
17
15
  */
18
- export type AssetEntry = {|
19
- type: 'asset',
20
- value: {|
21
- filePath: string,
22
- dependencies: DependencyEntry[],
23
- |},
24
- |};
16
+ export type AssetEntry = {
17
+ type: 'asset';
18
+ value: {
19
+ filePath: string;
20
+ dependencies: DependencyEntry[];
21
+ };
22
+ };
25
23
 
26
24
  /**
27
25
  * Sync or async dependency between assets
28
26
  */
29
- export type DependencyEntry = {|
30
- type: 'dependency',
31
- value: {|
32
- from: string,
33
- to: string,
34
- type: 'sync' | 'async',
35
- |},
36
- |};
27
+ export type DependencyEntry = {
28
+ type: 'dependency';
29
+ value: {
30
+ from: string;
31
+ to: string;
32
+ type: 'sync' | 'async';
33
+ };
34
+ };
37
35
 
38
- export type DependencySpec = {|
39
- to: string,
40
- type: 'sync' | 'async',
41
- |};
36
+ export type DependencySpec = {
37
+ to: string;
38
+ type: 'sync' | 'async';
39
+ };
42
40
 
43
41
  /**
44
42
  * Create an asset node in the fixture graph
45
43
  */
46
44
  export function asset(
47
45
  path: string,
48
- dependencies?: (string | DependencySpec)[],
46
+ dependencies?: string | DependencySpec[],
49
47
  ): GraphEntry {
50
48
  return {
51
49
  type: 'asset',
52
50
  value: {
53
51
  filePath: path,
54
52
  dependencies:
55
- dependencies?.map((dependency) => {
53
+ dependencies?.map((dependency: DependencySpec | string) => {
56
54
  if (typeof dependency === 'string') {
57
55
  return {
58
56
  type: 'dependency',
@@ -159,7 +157,7 @@ export async function fixtureFromGraph(
159
157
  *
160
158
  */
161
159
  export function dotFromGraph(entries: GraphEntry[]): string {
162
- const contents = [];
160
+ const contents: Array<string> = [];
163
161
 
164
162
  for (let entry of entries) {
165
163
  if (entry.type === 'asset') {
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "include": ["src"]
4
+ }