Skip to content

Commit

Permalink
Edge types for asset graph
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Aug 11, 2022
1 parent 46134dd commit 82f469b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
15 changes: 13 additions & 2 deletions packages/core/core/src/AssetGraph.js
Expand Up @@ -30,6 +30,14 @@ import {ContentGraph} from '@parcel/graph';
import {createDependency} from './Dependency';
import {type ProjectPath, fromProjectPathRelative} from './projectPath';

export const assetGraphEdgeTypes = {
null: 1,
//TODO
original: 2,
};

export type AssetGraphEdgeType = $Values<typeof assetGraphEdgeTypes>;

type InitOpts = {|
entries?: Array<ProjectPath>,
targets?: Array<Target>,
Expand All @@ -43,7 +51,7 @@ type AssetGraphOpts = {|
|};

type SerializedAssetGraph = {|
...SerializedContentGraph<AssetGraphNode>,
...SerializedContentGraph<AssetGraphNode, AssetGraphEdgeType>,
hash?: ?string,
symbolPropagationRan: boolean,
|};
Expand Down Expand Up @@ -110,7 +118,10 @@ export function nodeFromEntryFile(entry: Entry): EntryFileNode {
};
}

export default class AssetGraph extends ContentGraph<AssetGraphNode> {
export default class AssetGraph extends ContentGraph<
AssetGraphNode,
AssetGraphEdgeType,
> {
onNodeRemoved: ?(nodeId: NodeId) => mixed;
hash: ?string;
envCache: Map<string, Environment>;
Expand Down
10 changes: 8 additions & 2 deletions packages/core/core/src/dumpGraphToGraphViz.js
Expand Up @@ -3,6 +3,8 @@
import type {Asset, BundleBehavior} from '@parcel/types';
import type {Graph} from '@parcel/graph';
import type {AssetGraphNode, BundleGraphNode, Environment} from './types';
import type {AssetGraphEdgeType} from './AssetGraph';
import {assetGraphEdgeTypes} from './AssetGraph';
import {bundleGraphEdgeTypes} from './BundleGraph';
import {requestGraphEdgeTypes} from './RequestTracker';

Expand All @@ -26,6 +28,7 @@ const TYPE_COLORS = {
internal_async: 'orange',
references: 'red',
sibling: 'green',
original: 'grey',
invalidated_by_create: 'green',
invalidated_by_create_above: 'orange',
invalidate_by_update: 'cyan',
Expand All @@ -34,15 +37,18 @@ const TYPE_COLORS = {

export default async function dumpGraphToGraphViz(
graph:
| Graph<AssetGraphNode>
| Graph<AssetGraphNode, AssetGraphEdgeType>
| Graph<{|
assets: Array<Asset>,
sourceBundles: Array<number>,
bundleBehavior?: ?BundleBehavior,
|}>
| Graph<BundleGraphNode>,
name: string,
edgeTypes?: typeof bundleGraphEdgeTypes | typeof requestGraphEdgeTypes,
edgeTypes?:
| typeof assetGraphEdgeTypes
| typeof bundleGraphEdgeTypes
| typeof requestGraphEdgeTypes,
): Promise<void> {
if (
process.env.PARCEL_BUILD_ENV === 'production' ||
Expand Down

0 comments on commit 82f469b

Please sign in to comment.