@atlaspack/query 2.14.5-canary.18 → 2.14.5-canary.181
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 +217 -0
- package/lib/bin.js +8 -6
- package/lib/cli.js +36 -26
- package/lib/deep-imports.js +9 -7
- package/lib/index.js +49 -61
- 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 +4 -0
|
@@ -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};
|
package/tsconfig.json
ADDED