@atlaspack/query 2.14.5-canary.35 → 2.14.5-canary.350
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/CHANGELOG.md +363 -0
- package/dist/cli.js +911 -0
- package/dist/deep-imports.js +26 -0
- package/dist/index.js +125 -0
- package/lib/bin.js +3 -0
- package/lib/cli.js +36 -26
- package/lib/deep-imports.js +9 -7
- package/lib/index.js +49 -61
- package/lib/types/cli.d.ts +1 -0
- package/lib/types/deep-imports.d.ts +1 -0
- package/lib/types/index.d.ts +9 -0
- package/package.json +10 -9
- package/src/bin.js +2 -1
- package/src/{cli.js → cli.ts} +65 -41
- package/src/{deep-imports.js → deep-imports.ts} +28 -31
- package/src/{index.js → index.ts} +71 -84
- package/tsconfig.json +21 -0
- package/tsconfig.tsbuildinfo +1 -0
package/src/{cli.js → cli.ts}
RENAMED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
1
|
/* eslint-disable no-console, monorepo/no-internal-import */
|
|
3
2
|
import type {ContentGraph, ContentKey, NodeId} from '@atlaspack/graph';
|
|
4
3
|
import type {BundleGraphEdgeType} from '@atlaspack/core/src/BundleGraph';
|
|
@@ -11,7 +10,6 @@ import os from 'os';
|
|
|
11
10
|
import nullthrows from 'nullthrows';
|
|
12
11
|
import invariant from 'assert';
|
|
13
12
|
import {serialize} from 'v8';
|
|
14
|
-
// $FlowFixMe
|
|
15
13
|
import {table} from 'table';
|
|
16
14
|
|
|
17
15
|
import {loadGraphs} from './index';
|
|
@@ -33,7 +31,7 @@ export async function run(input: string[]) {
|
|
|
33
31
|
|
|
34
32
|
try {
|
|
35
33
|
fs.accessSync(cacheDir);
|
|
36
|
-
} catch (e) {
|
|
34
|
+
} catch (e: any) {
|
|
37
35
|
console.error("Can't find cache dir", cacheDir);
|
|
38
36
|
process.exit(1);
|
|
39
37
|
}
|
|
@@ -85,7 +83,7 @@ export async function run(input: string[]) {
|
|
|
85
83
|
}
|
|
86
84
|
|
|
87
85
|
function parseAssetLocator(v: string) {
|
|
88
|
-
let id:
|
|
86
|
+
let id: string | null | undefined = null;
|
|
89
87
|
if (v.length === 16) {
|
|
90
88
|
id = v;
|
|
91
89
|
} else {
|
|
@@ -138,7 +136,7 @@ export async function run(input: string[]) {
|
|
|
138
136
|
}
|
|
139
137
|
|
|
140
138
|
function getAsset(v: string) {
|
|
141
|
-
let id:
|
|
139
|
+
let id: string | null | undefined = parseAssetLocator(v);
|
|
142
140
|
|
|
143
141
|
if (id == null) {
|
|
144
142
|
console.log(null);
|
|
@@ -151,7 +149,7 @@ export async function run(input: string[]) {
|
|
|
151
149
|
let asset = bundleGraph.getAssetById(id);
|
|
152
150
|
console.log('Public id', bundleGraph.getAssetPublicId(asset));
|
|
153
151
|
console.log(asset);
|
|
154
|
-
} catch (e) {
|
|
152
|
+
} catch (e: any) {
|
|
155
153
|
if (!hasAssetGraph()) {
|
|
156
154
|
return;
|
|
157
155
|
}
|
|
@@ -192,7 +190,7 @@ export async function run(input: string[]) {
|
|
|
192
190
|
bundleGraph.getAssetById(node.id),
|
|
193
191
|
)} ${fromProjectPathRelative(node.value.filePath)}`,
|
|
194
192
|
);
|
|
195
|
-
} catch (e) {
|
|
193
|
+
} catch (e: any) {
|
|
196
194
|
console.log(fromProjectPathRelative(node.value.filePath));
|
|
197
195
|
}
|
|
198
196
|
}
|
|
@@ -246,7 +244,7 @@ export async function run(input: string[]) {
|
|
|
246
244
|
bundleGraph.getAssetById(asset.id),
|
|
247
245
|
)} ${fromProjectPathRelative(asset.value.filePath)}`,
|
|
248
246
|
);
|
|
249
|
-
} catch (e) {
|
|
247
|
+
} catch (e: any) {
|
|
250
248
|
console.log(fromProjectPathRelative(asset.value.filePath));
|
|
251
249
|
}
|
|
252
250
|
if (binding === 'export' && asset.value.symbols) {
|
|
@@ -262,7 +260,7 @@ export async function run(input: string[]) {
|
|
|
262
260
|
bundleGraph.getAssetById(locAsset.id),
|
|
263
261
|
)} ${fromProjectPathRelative(locAsset.value.filePath)}`,
|
|
264
262
|
);
|
|
265
|
-
} catch (e) {
|
|
263
|
+
} catch (e: any) {
|
|
266
264
|
console.log(
|
|
267
265
|
`imported as ${symbolName} from ${fromProjectPathRelative(
|
|
268
266
|
locAsset.value.filePath,
|
|
@@ -311,12 +309,12 @@ export async function run(input: string[]) {
|
|
|
311
309
|
this.label = label;
|
|
312
310
|
this.suffix = suffix;
|
|
313
311
|
}
|
|
314
|
-
add(v: T, label
|
|
312
|
+
add(v: T, label?: string, suffix?: string): Paths<T> {
|
|
315
313
|
let next = new Paths(v, label, suffix);
|
|
316
314
|
this.children.push(next);
|
|
317
315
|
return next;
|
|
318
316
|
}
|
|
319
|
-
print(format: (T) => string, prefix = '') {
|
|
317
|
+
print(format: (arg1: T) => string, prefix = '') {
|
|
320
318
|
console.log(
|
|
321
319
|
`${prefix}${this.label} ${format(this.value)} ${this.suffix}`,
|
|
322
320
|
);
|
|
@@ -335,7 +333,14 @@ export async function run(input: string[]) {
|
|
|
335
333
|
let asset = nullthrows(parseAssetLocator(v), 'Asset not found');
|
|
336
334
|
|
|
337
335
|
let paths = new Paths<NodeId>(graph.getNodeIdByContentKey(asset), ' ');
|
|
338
|
-
let cb = (
|
|
336
|
+
let cb = (
|
|
337
|
+
id: NodeId,
|
|
338
|
+
ctx: {
|
|
339
|
+
lazyOutgoing: boolean;
|
|
340
|
+
paths: Paths<NodeId>;
|
|
341
|
+
},
|
|
342
|
+
revisiting: boolean,
|
|
343
|
+
) => {
|
|
339
344
|
let {paths, lazyOutgoing} = ctx;
|
|
340
345
|
let node = nullthrows(graph.getNode(id));
|
|
341
346
|
if (node.id === asset) return ctx;
|
|
@@ -356,7 +361,13 @@ export async function run(input: string[]) {
|
|
|
356
361
|
|
|
357
362
|
// like graph.dfs, but revisiting nodes and skipping its children
|
|
358
363
|
let seen = new Set();
|
|
359
|
-
function walk(
|
|
364
|
+
function walk(
|
|
365
|
+
id: NodeId,
|
|
366
|
+
ctx: {
|
|
367
|
+
lazyOutgoing: boolean;
|
|
368
|
+
paths: Paths<NodeId>;
|
|
369
|
+
},
|
|
370
|
+
) {
|
|
360
371
|
let revisiting = seen.has(id);
|
|
361
372
|
let newCtx = cb(id, ctx, revisiting);
|
|
362
373
|
if (revisiting) return;
|
|
@@ -434,7 +445,7 @@ export async function run(input: string[]) {
|
|
|
434
445
|
}
|
|
435
446
|
|
|
436
447
|
// eslint-disable-next-line no-unused-vars
|
|
437
|
-
function getBundles(_) {
|
|
448
|
+
function getBundles(_: any) {
|
|
438
449
|
if (!hasBundleGraph()) {
|
|
439
450
|
return;
|
|
440
451
|
}
|
|
@@ -549,6 +560,7 @@ export async function run(input: string[]) {
|
|
|
549
560
|
'Node is not a bundle, but a ' + node.type,
|
|
550
561
|
);
|
|
551
562
|
|
|
563
|
+
// @ts-expect-error TS7006
|
|
552
564
|
bundleGraph.traverseAssets(node.value, (asset) => {
|
|
553
565
|
console.log(asset.id, asset.filePath);
|
|
554
566
|
});
|
|
@@ -568,6 +580,7 @@ export async function run(input: string[]) {
|
|
|
568
580
|
'Node is not a bundle, but a ' + node.type,
|
|
569
581
|
);
|
|
570
582
|
|
|
583
|
+
// @ts-expect-error TS7006
|
|
571
584
|
bundleGraph.traverseBundle(node.value, (node) => {
|
|
572
585
|
if (node.type === 'asset') {
|
|
573
586
|
console.log(node.id, node.value.filePath);
|
|
@@ -667,6 +680,7 @@ export async function run(input: string[]) {
|
|
|
667
680
|
assetNodeId,
|
|
668
681
|
)) {
|
|
669
682
|
if (
|
|
683
|
+
// @ts-expect-error TS7006
|
|
670
684
|
referencingBundles.some((ref) =>
|
|
671
685
|
bundleGraph._graph.hasEdge(
|
|
672
686
|
bundleGraph._graph.getNodeIdByContentKey(ref.id),
|
|
@@ -680,22 +694,33 @@ export async function run(input: string[]) {
|
|
|
680
694
|
}
|
|
681
695
|
}
|
|
682
696
|
|
|
683
|
-
function _getIncomingNodeOfType(
|
|
697
|
+
function _getIncomingNodeOfType(
|
|
698
|
+
// @ts-expect-error TS2304
|
|
699
|
+
bundleGraph: BundleGraph,
|
|
700
|
+
// @ts-expect-error TS7006
|
|
701
|
+
node,
|
|
702
|
+
type: string,
|
|
703
|
+
) {
|
|
684
704
|
if (!hasBundleGraph()) {
|
|
685
705
|
return;
|
|
686
706
|
}
|
|
687
707
|
invariant(bundleGraph != null);
|
|
688
708
|
const bundleGraphNodeId = bundleGraph._graph.getNodeIdByContentKey(node.id);
|
|
689
|
-
return
|
|
690
|
-
.
|
|
691
|
-
|
|
692
|
-
|
|
709
|
+
return (
|
|
710
|
+
bundleGraph._graph
|
|
711
|
+
.getNodeIdsConnectedTo(bundleGraphNodeId, -1)
|
|
712
|
+
// @ts-expect-error TS7006
|
|
713
|
+
.map((id) => nullthrows(bundleGraph._graph.getNode(id)))
|
|
714
|
+
// @ts-expect-error TS7006
|
|
715
|
+
.find((node) => node.type == type)
|
|
716
|
+
);
|
|
693
717
|
}
|
|
694
718
|
|
|
695
719
|
// We find the priority of a Bundle or BundleGroup by looking at its incoming dependencies.
|
|
696
720
|
// If a Bundle does not have an incoming dependency, we look for an incoming BundleGroup and its dependency
|
|
697
721
|
// e.g. Dep(priority = 1) -> BundleGroup -> Bundle means that the Bundle has priority 1.
|
|
698
|
-
|
|
722
|
+
// @ts-expect-error TS2304
|
|
723
|
+
function _getBundlePriority(bundleGraph: BundleGraph, bundle: BundleNode) {
|
|
699
724
|
if (!hasBundleGraph()) {
|
|
700
725
|
return;
|
|
701
726
|
}
|
|
@@ -715,7 +740,8 @@ export async function run(input: string[]) {
|
|
|
715
740
|
return node.value.priority;
|
|
716
741
|
}
|
|
717
742
|
|
|
718
|
-
|
|
743
|
+
// @ts-expect-error TS2304
|
|
744
|
+
function _findEntryBundle(bundleGraph: BundleGraph, node: BundleNode) {
|
|
719
745
|
if (!hasBundleGraph()) {
|
|
720
746
|
return;
|
|
721
747
|
}
|
|
@@ -723,8 +749,10 @@ export async function run(input: string[]) {
|
|
|
723
749
|
const bundleGraphNodeId = bundleGraph._graph.getNodeIdByContentKey(node.id);
|
|
724
750
|
const entryBundleGroup = bundleGraph._graph
|
|
725
751
|
.getNodeIdsConnectedTo(bundleGraphNodeId, -1)
|
|
752
|
+
// @ts-expect-error TS7006
|
|
726
753
|
.map((id) => nullthrows(bundleGraph._graph.getNode(id)))
|
|
727
754
|
.find(
|
|
755
|
+
// @ts-expect-error TS7006
|
|
728
756
|
(node) =>
|
|
729
757
|
node.type === 'bundle_group' &&
|
|
730
758
|
bundleGraph.isEntryBundleGroup(node.value),
|
|
@@ -733,7 +761,7 @@ export async function run(input: string[]) {
|
|
|
733
761
|
return entryBundleGroup;
|
|
734
762
|
}
|
|
735
763
|
// eslint-disable-next-line no-unused-vars
|
|
736
|
-
function inspectCache(_) {
|
|
764
|
+
function inspectCache(_: any) {
|
|
737
765
|
// displays sizing of various entries of the cache
|
|
738
766
|
let table: Array<Array<string | number>> = [];
|
|
739
767
|
table.push([
|
|
@@ -767,6 +795,7 @@ export async function run(input: string[]) {
|
|
|
767
795
|
column.shift();
|
|
768
796
|
invariant(column != null);
|
|
769
797
|
return column.reduce(
|
|
798
|
+
// @ts-expect-error TS2365
|
|
770
799
|
(accumulator, currentValue) => accumulator + currentValue,
|
|
771
800
|
initialValue,
|
|
772
801
|
);
|
|
@@ -780,13 +809,19 @@ export async function run(input: string[]) {
|
|
|
780
809
|
_printStatsTable('Cache Info', table);
|
|
781
810
|
}
|
|
782
811
|
|
|
783
|
-
function timeSerialize(
|
|
812
|
+
function timeSerialize(
|
|
813
|
+
// @ts-expect-error TS2304
|
|
814
|
+
graph: AssetGraph | null | undefined | BundleGraph | RequestTracker,
|
|
815
|
+
) {
|
|
784
816
|
let date = Date.now();
|
|
785
817
|
serialize(graph);
|
|
786
818
|
date = Date.now() - date;
|
|
787
819
|
return date;
|
|
788
820
|
}
|
|
789
|
-
function _printStatsTable(
|
|
821
|
+
function _printStatsTable(
|
|
822
|
+
header: string,
|
|
823
|
+
data: Array<Array<string | number>> | Array<[string, unknown]>,
|
|
824
|
+
) {
|
|
790
825
|
const config = {
|
|
791
826
|
columnDefault: {
|
|
792
827
|
width: 18,
|
|
@@ -795,13 +830,13 @@ export async function run(input: string[]) {
|
|
|
795
830
|
alignment: 'center',
|
|
796
831
|
content: header,
|
|
797
832
|
},
|
|
798
|
-
};
|
|
833
|
+
} as const;
|
|
799
834
|
|
|
800
835
|
console.log(table(data, config));
|
|
801
836
|
}
|
|
802
837
|
|
|
803
838
|
// eslint-disable-next-line no-unused-vars
|
|
804
|
-
function stats(_) {
|
|
839
|
+
function stats(_: any) {
|
|
805
840
|
let ag = {
|
|
806
841
|
asset: 0,
|
|
807
842
|
dependency: 0,
|
|
@@ -812,7 +847,7 @@ export async function run(input: string[]) {
|
|
|
812
847
|
invariant(assetGraph != null);
|
|
813
848
|
for (let n of assetGraph.nodes) {
|
|
814
849
|
if (n && n.type in ag) {
|
|
815
|
-
//
|
|
850
|
+
// @ts-expect-error TS7053
|
|
816
851
|
ag[n.type]++;
|
|
817
852
|
}
|
|
818
853
|
}
|
|
@@ -839,7 +874,7 @@ export async function run(input: string[]) {
|
|
|
839
874
|
sync: 0,
|
|
840
875
|
};
|
|
841
876
|
|
|
842
|
-
let b_ext = {};
|
|
877
|
+
let b_ext: Record<string, any> = {};
|
|
843
878
|
|
|
844
879
|
const entries = new Set();
|
|
845
880
|
|
|
@@ -849,10 +884,8 @@ export async function run(input: string[]) {
|
|
|
849
884
|
} else if (n?.type === 'bundle') {
|
|
850
885
|
bg.bundle++;
|
|
851
886
|
|
|
852
|
-
// $FlowFixMe
|
|
853
887
|
b_ext[n.value.type] = (b_ext[n.value.type] || 0) + 1;
|
|
854
888
|
|
|
855
|
-
// $FlowFixMe
|
|
856
889
|
const entry_group = _findEntryBundle(bundleGraph, n);
|
|
857
890
|
|
|
858
891
|
if (entry_group != null && !entries.has(entry_group.id)) {
|
|
@@ -874,7 +907,6 @@ export async function run(input: string[]) {
|
|
|
874
907
|
}
|
|
875
908
|
} else if (n?.type === 'asset') {
|
|
876
909
|
if (
|
|
877
|
-
// $FlowFixMe
|
|
878
910
|
fromProjectPathRelative(n.value.filePath).includes('node_modules')
|
|
879
911
|
) {
|
|
880
912
|
bg.asset_node_modules++;
|
|
@@ -899,6 +931,7 @@ export async function run(input: string[]) {
|
|
|
899
931
|
|
|
900
932
|
let sum_b_type = 0;
|
|
901
933
|
for (let k in b_type) {
|
|
934
|
+
// @ts-expect-error TS7053
|
|
902
935
|
sum_b_type += b_type[k];
|
|
903
936
|
}
|
|
904
937
|
|
|
@@ -929,19 +962,14 @@ export async function run(input: string[]) {
|
|
|
929
962
|
});
|
|
930
963
|
|
|
931
964
|
const server = repl.start({useColors: true, useGlobal: true});
|
|
932
|
-
// $FlowFixMe[prop-missing]
|
|
933
965
|
server.setupHistory(
|
|
934
966
|
path.join(os.homedir(), '.parcel_query_history'),
|
|
935
967
|
() => {},
|
|
936
968
|
);
|
|
937
969
|
|
|
938
|
-
// $FlowFixMe[prop-missing]
|
|
939
970
|
server.context.bundleGraph = bundleGraph;
|
|
940
|
-
// $FlowFixMe[prop-missing]
|
|
941
971
|
server.context.assetGraph = assetGraph;
|
|
942
|
-
// $FlowFixMe[prop-missing]
|
|
943
972
|
server.context.requestTracker = requestTracker;
|
|
944
|
-
// $FlowFixMe[prop-missing]
|
|
945
973
|
server.context.cacheInfo = cacheInfo;
|
|
946
974
|
for (let [name, cmd] of new Map([
|
|
947
975
|
[
|
|
@@ -1060,6 +1088,7 @@ export async function run(input: string[]) {
|
|
|
1060
1088
|
'findBundleReason',
|
|
1061
1089
|
{
|
|
1062
1090
|
help: 'args: <bundle> <asset>. Why is the asset in the bundle',
|
|
1091
|
+
// @ts-expect-error TS2556
|
|
1063
1092
|
action: (v) => findBundleReason(...v.split(' ')),
|
|
1064
1093
|
},
|
|
1065
1094
|
],
|
|
@@ -1106,16 +1135,11 @@ export async function run(input: string[]) {
|
|
|
1106
1135
|
},
|
|
1107
1136
|
],
|
|
1108
1137
|
])) {
|
|
1109
|
-
// $FlowFixMe
|
|
1110
1138
|
server.context[name] = cmd.action;
|
|
1111
|
-
// $FlowFixMe
|
|
1112
1139
|
server.defineCommand(name, {
|
|
1113
|
-
// $FlowFixMe
|
|
1114
1140
|
help: '📦 ' + cmd.help,
|
|
1115
1141
|
action: (v) => {
|
|
1116
|
-
// $FlowFixMe
|
|
1117
1142
|
server.clearBufferedCommand();
|
|
1118
|
-
// $FlowFixMe
|
|
1119
1143
|
try {
|
|
1120
1144
|
cmd.action(v);
|
|
1121
1145
|
} finally {
|
|
@@ -1,34 +1,28 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
/* eslint-disable monorepo/no-internal-import */
|
|
3
|
-
import
|
|
4
|
-
import
|
|
2
|
+
import AssetGraph from '@atlaspack/core/src/AssetGraph';
|
|
3
|
+
import BundleGraph, {
|
|
5
4
|
bundleGraphEdgeTypes,
|
|
6
5
|
} from '@atlaspack/core/src/BundleGraph';
|
|
7
|
-
import
|
|
6
|
+
import RequestTracker, {
|
|
8
7
|
RequestGraph,
|
|
9
8
|
readAndDeserializeRequestGraph,
|
|
10
9
|
} from '@atlaspack/core/src/RequestTracker';
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
10
|
+
import {requestGraphEdgeTypes} from '@atlaspack/core/src/RequestTracker';
|
|
11
|
+
import {LMDBLiteCache} from '@atlaspack/cache/src/LMDBLiteCache';
|
|
12
|
+
import {Priority} from '@atlaspack/core/src/types';
|
|
13
|
+
import {fromProjectPathRelative} from '@atlaspack/core/src/projectPath';
|
|
15
14
|
|
|
16
15
|
const v =
|
|
17
|
-
process.env.ATLASPACK_BUILD_ENV === 'production'
|
|
16
|
+
process.env.ATLASPACK_BUILD_ENV === 'production' ||
|
|
17
|
+
process.env.ATLASPACK_REGISTER_USE_SRC !== 'true'
|
|
18
18
|
? {
|
|
19
19
|
// Split up require specifier to outsmart packages/dev/babel-register/babel-plugin-module-translate.js
|
|
20
|
-
// $FlowFixMe(unsupported-syntax)
|
|
21
20
|
AssetGraph: require('@atlaspack/core' + '/lib/AssetGraph').default,
|
|
22
|
-
// $FlowFixMe(unsupported-syntax)
|
|
23
21
|
BundleGraph: require('@atlaspack/core' + '/lib/BundleGraph'),
|
|
24
|
-
// $FlowFixMe(unsupported-syntax)
|
|
25
22
|
RequestTracker: require('@atlaspack/core' + '/lib/RequestTracker'),
|
|
26
|
-
// $FlowFixMe(unsupported-syntax)
|
|
27
23
|
LMDBLiteCache: require('@atlaspack/cache' + '/lib/LMDBLiteCache')
|
|
28
24
|
.LMDBLiteCache,
|
|
29
|
-
// $FlowFixMe(unsupported-syntax)
|
|
30
25
|
Priority: require('@atlaspack/core' + '/lib/types').Priority,
|
|
31
|
-
// $FlowFixMe(unsupported-syntax)
|
|
32
26
|
fromProjectPathRelative: require('@atlaspack/core' + '/lib/projectPath')
|
|
33
27
|
.fromProjectPathRelative,
|
|
34
28
|
}
|
|
@@ -43,21 +37,24 @@ const v =
|
|
|
43
37
|
.fromProjectPathRelative,
|
|
44
38
|
};
|
|
45
39
|
|
|
46
|
-
module.exports =
|
|
47
|
-
AssetGraph: AssetGraph
|
|
40
|
+
module.exports = v as {
|
|
41
|
+
AssetGraph: AssetGraph;
|
|
48
42
|
BundleGraph: {
|
|
49
|
-
default: BundleGraph
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
43
|
+
default: BundleGraph;
|
|
44
|
+
// @ts-expect-error TS2749
|
|
45
|
+
bundleGraphEdgeTypes: bundleGraphEdgeTypes;
|
|
46
|
+
};
|
|
53
47
|
RequestTracker: {
|
|
54
|
-
default: RequestTracker
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
48
|
+
default: RequestTracker;
|
|
49
|
+
// @ts-expect-error TS2749
|
|
50
|
+
readAndDeserializeRequestGraph: readAndDeserializeRequestGraph;
|
|
51
|
+
RequestGraph: RequestGraph;
|
|
52
|
+
// @ts-expect-error TS2749
|
|
53
|
+
requestGraphEdgeTypes: requestGraphEdgeTypes;
|
|
54
|
+
};
|
|
55
|
+
LMDBLiteCache: LMDBLiteCache;
|
|
56
|
+
// @ts-expect-error TS2749
|
|
57
|
+
Priority: Priority;
|
|
58
|
+
// @ts-expect-error TS2749
|
|
59
|
+
fromProjectPathRelative: fromProjectPathRelative;
|
|
60
|
+
};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
1
|
/* eslint-disable no-console, monorepo/no-internal-import */
|
|
3
2
|
import type {ContentKey, NodeId} from '@atlaspack/graph';
|
|
4
3
|
import type {PackagedBundleInfo} from '@atlaspack/core/src/types';
|
|
5
4
|
|
|
6
|
-
import fs from 'fs';
|
|
7
|
-
import path from 'path';
|
|
8
5
|
import v8 from 'v8';
|
|
9
6
|
import nullthrows from 'nullthrows';
|
|
10
7
|
import invariant from 'assert';
|
|
@@ -18,98 +15,86 @@ const {
|
|
|
18
15
|
requestGraphEdgeTypes,
|
|
19
16
|
},
|
|
20
17
|
LMDBLiteCache,
|
|
21
|
-
} =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
name: 'bundleGraphBlob',
|
|
48
|
-
check: (basename) => basename.endsWith('BundleGraph-0'),
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
name: 'assetGraphBlob',
|
|
52
|
-
check: (basename) => basename.endsWith('AssetGraph-0'),
|
|
53
|
-
},
|
|
54
|
-
];
|
|
55
|
-
|
|
56
|
-
for (let file of files) {
|
|
57
|
-
let basename = path.basename(file);
|
|
58
|
-
let match = blobsToFind.find(({check}) => check(basename));
|
|
59
|
-
|
|
60
|
-
if (match) {
|
|
61
|
-
let stat = fs.statSync(path.join(cacheDir, file));
|
|
62
|
-
|
|
63
|
-
if (!match.mtime || stat.mtime > match.mtime) {
|
|
64
|
-
match.mtime = stat.mtime;
|
|
65
|
-
result[match.name] = file;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
18
|
+
} = process.env.ATLASPACK_REGISTER_USE_SRC === 'true'
|
|
19
|
+
? require('./deep-imports.ts')
|
|
20
|
+
: require('./deep-imports.js');
|
|
21
|
+
|
|
22
|
+
export async function loadGraphs(cacheDir: string): Promise<{
|
|
23
|
+
// @ts-expect-error TS2749
|
|
24
|
+
assetGraph: AssetGraph | null | undefined;
|
|
25
|
+
// @ts-expect-error TS2749
|
|
26
|
+
bundleGraph: BundleGraph | null | undefined;
|
|
27
|
+
// @ts-expect-error TS2749
|
|
28
|
+
requestTracker: RequestTracker | null | undefined;
|
|
29
|
+
bundleInfo: Map<ContentKey, PackagedBundleInfo> | null | undefined;
|
|
30
|
+
cacheInfo: Map<string, Array<string | number>> | null | undefined;
|
|
31
|
+
}> {
|
|
32
|
+
let cacheInfo: Map<string, Array<string | number>> = new Map();
|
|
33
|
+
const cache = new LMDBLiteCache(cacheDir);
|
|
34
|
+
|
|
35
|
+
let requestGraphBlob;
|
|
36
|
+
let requestGraphKey;
|
|
37
|
+
let bundleGraphBlob;
|
|
38
|
+
let assetGraphBlob;
|
|
39
|
+
for (let key of cache.keys()) {
|
|
40
|
+
if (key.startsWith('Asset/')) {
|
|
41
|
+
continue;
|
|
42
|
+
} else if (key.startsWith('PackagerRunner/')) {
|
|
43
|
+
continue;
|
|
68
44
|
}
|
|
69
45
|
|
|
70
|
-
|
|
46
|
+
if (key.startsWith('RequestTracker/') && key.endsWith('/RequestGraph')) {
|
|
47
|
+
requestGraphBlob = key;
|
|
48
|
+
requestGraphKey = key.split('/').slice(0, -1).join('/');
|
|
49
|
+
}
|
|
50
|
+
if (key.startsWith('BundleGraph/')) {
|
|
51
|
+
bundleGraphBlob = key;
|
|
52
|
+
}
|
|
53
|
+
if (key.startsWith('AssetGraph/')) {
|
|
54
|
+
assetGraphBlob = key;
|
|
55
|
+
}
|
|
71
56
|
}
|
|
72
57
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
let {requestGraphBlob, bundleGraphBlob, assetGraphBlob} =
|
|
76
|
-
getMostRecentCacheBlobs();
|
|
77
|
-
const cache = new LMDBLiteCache(cacheDir);
|
|
58
|
+
console.log({requestGraphBlob, bundleGraphBlob, assetGraphBlob});
|
|
78
59
|
|
|
79
60
|
// Get requestTracker
|
|
61
|
+
// @ts-expect-error TS7034
|
|
80
62
|
let requestTracker;
|
|
81
|
-
if (requestGraphBlob) {
|
|
63
|
+
if (requestGraphBlob != null && requestGraphKey != null) {
|
|
82
64
|
try {
|
|
83
|
-
let requestGraphKey = requestGraphBlob.slice(0, -'-0'.length);
|
|
84
65
|
let date = Date.now();
|
|
66
|
+
|
|
67
|
+
const buffer = await cache.getBlob(requestGraphBlob);
|
|
68
|
+
const deserializer = new v8.Deserializer(buffer);
|
|
69
|
+
console.log(
|
|
70
|
+
'Wire format version stored',
|
|
71
|
+
deserializer.getWireFormatVersion(),
|
|
72
|
+
);
|
|
73
|
+
|
|
85
74
|
let {requestGraph, bufferLength} = await readAndDeserializeRequestGraph(
|
|
86
75
|
cache,
|
|
76
|
+
requestGraphBlob,
|
|
87
77
|
requestGraphKey,
|
|
88
|
-
requestGraphKey.replace('requestGraph-', ''),
|
|
89
78
|
);
|
|
90
79
|
|
|
91
80
|
requestTracker = new RequestTracker({
|
|
92
81
|
graph: requestGraph,
|
|
93
|
-
// $FlowFixMe
|
|
94
82
|
farm: null,
|
|
95
|
-
// $FlowFixMe
|
|
96
83
|
options: null,
|
|
97
84
|
});
|
|
98
85
|
let timeToDeserialize = Date.now() - date;
|
|
99
86
|
cacheInfo.set('RequestGraph', [bufferLength]);
|
|
100
87
|
cacheInfo.get('RequestGraph')?.push(timeToDeserialize);
|
|
101
|
-
} catch (e) {
|
|
102
|
-
console.
|
|
88
|
+
} catch (e: any) {
|
|
89
|
+
console.error('Error loading Request Graph\n', e);
|
|
103
90
|
}
|
|
104
91
|
}
|
|
105
92
|
|
|
106
93
|
// Get bundleGraph
|
|
107
94
|
let bundleGraph;
|
|
108
|
-
if (bundleGraphBlob) {
|
|
95
|
+
if (bundleGraphBlob != null) {
|
|
109
96
|
try {
|
|
110
|
-
let file = await cache.
|
|
111
|
-
path.basename(bundleGraphBlob).slice(0, -'-0'.length),
|
|
112
|
-
);
|
|
97
|
+
let file = await cache.getBlob(bundleGraphBlob);
|
|
113
98
|
|
|
114
99
|
let timeToDeserialize = Date.now();
|
|
115
100
|
let obj = v8.deserialize(file);
|
|
@@ -119,19 +104,17 @@ export async function loadGraphs(cacheDir: string): Promise<{|
|
|
|
119
104
|
|
|
120
105
|
cacheInfo.set('BundleGraph', [Buffer.byteLength(file)]);
|
|
121
106
|
cacheInfo.get('BundleGraph')?.push(timeToDeserialize);
|
|
122
|
-
} catch (e) {
|
|
123
|
-
console.
|
|
107
|
+
} catch (e: any) {
|
|
108
|
+
console.error('Error loading Bundle Graph\n', e);
|
|
124
109
|
}
|
|
125
110
|
}
|
|
126
111
|
|
|
127
112
|
// Get assetGraph
|
|
128
113
|
let assetGraph;
|
|
129
|
-
if (assetGraphBlob) {
|
|
114
|
+
if (assetGraphBlob != null) {
|
|
130
115
|
try {
|
|
131
116
|
// TODO: this should be reviewed when `cachePerformanceImprovements` flag is removed, as we'll be writing files to LMDB cache instead of large blobs
|
|
132
|
-
let file = await cache.
|
|
133
|
-
path.basename(assetGraphBlob).slice(0, -'-0'.length),
|
|
134
|
-
);
|
|
117
|
+
let file = await cache.getBlob(assetGraphBlob);
|
|
135
118
|
|
|
136
119
|
let timeToDeserialize = Date.now();
|
|
137
120
|
let obj = v8.deserialize(file);
|
|
@@ -141,15 +124,19 @@ export async function loadGraphs(cacheDir: string): Promise<{|
|
|
|
141
124
|
|
|
142
125
|
cacheInfo.set('AssetGraph', [Buffer.byteLength(file)]);
|
|
143
126
|
cacheInfo.get('AssetGraph')?.push(timeToDeserialize);
|
|
144
|
-
} catch (e) {
|
|
145
|
-
console.
|
|
127
|
+
} catch (e: any) {
|
|
128
|
+
console.error('Error loading Asset Graph\n', e);
|
|
146
129
|
}
|
|
147
130
|
}
|
|
148
131
|
|
|
149
132
|
function getSubRequests(id: NodeId) {
|
|
150
|
-
return
|
|
151
|
-
|
|
152
|
-
|
|
133
|
+
return (
|
|
134
|
+
// @ts-expect-error TS7005
|
|
135
|
+
requestTracker.graph
|
|
136
|
+
.getNodeIdsConnectedFrom(id, requestGraphEdgeTypes.subrequest)
|
|
137
|
+
// @ts-expect-error TS7006
|
|
138
|
+
.map((n) => nullthrows(requestTracker.graph.getNode(n)))
|
|
139
|
+
);
|
|
153
140
|
}
|
|
154
141
|
|
|
155
142
|
// Load graphs by finding the main subrequests and loading their results
|
|
@@ -168,18 +155,18 @@ export async function loadGraphs(cacheDir: string): Promise<{|
|
|
|
168
155
|
let buildRequestSubRequests = getSubRequests(buildRequestId);
|
|
169
156
|
|
|
170
157
|
let writeBundlesRequest = buildRequestSubRequests.find(
|
|
158
|
+
// @ts-expect-error TS7006
|
|
171
159
|
(n) => n.type === 1 && n.requestType === 11,
|
|
172
160
|
);
|
|
173
161
|
if (writeBundlesRequest != null) {
|
|
174
162
|
invariant(writeBundlesRequest.type === 1);
|
|
175
|
-
|
|
176
|
-
bundleInfo = (nullthrows(writeBundlesRequest.result): Map<
|
|
163
|
+
bundleInfo = nullthrows(writeBundlesRequest.result) as Map<
|
|
177
164
|
ContentKey,
|
|
178
|
-
PackagedBundleInfo
|
|
179
|
-
|
|
165
|
+
PackagedBundleInfo
|
|
166
|
+
>;
|
|
180
167
|
}
|
|
181
|
-
} catch (e) {
|
|
182
|
-
console.
|
|
168
|
+
} catch (e: any) {
|
|
169
|
+
console.error('Error loading bundleInfo\n', e);
|
|
183
170
|
}
|
|
184
171
|
|
|
185
172
|
return {assetGraph, bundleGraph, requestTracker, bundleInfo, cacheInfo};
|