@atlaspack/query 2.14.0 → 2.14.1-canary.6

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright (c) 2024 Atlassian US., Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/lib/bin.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const run = require('./cli').run;
5
+ require('v8-compile-cache');
6
+ run(process.argv.slice(2));
package/lib/cli.js ADDED
@@ -0,0 +1,850 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.run = run;
7
+ function _path() {
8
+ const data = _interopRequireDefault(require("path"));
9
+ _path = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _fs() {
15
+ const data = _interopRequireDefault(require("fs"));
16
+ _fs = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _repl() {
22
+ const data = _interopRequireDefault(require("repl"));
23
+ _repl = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ function _os() {
29
+ const data = _interopRequireDefault(require("os"));
30
+ _os = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ function _nullthrows() {
36
+ const data = _interopRequireDefault(require("nullthrows"));
37
+ _nullthrows = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
42
+ function _assert() {
43
+ const data = _interopRequireDefault(require("assert"));
44
+ _assert = function () {
45
+ return data;
46
+ };
47
+ return data;
48
+ }
49
+ function _v() {
50
+ const data = require("v8");
51
+ _v = function () {
52
+ return data;
53
+ };
54
+ return data;
55
+ }
56
+ function _table() {
57
+ const data = require("table");
58
+ _table = function () {
59
+ return data;
60
+ };
61
+ return data;
62
+ }
63
+ var _index = require("./index");
64
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
65
+ /* eslint-disable no-console, monorepo/no-internal-import */
66
+ // $FlowFixMe
67
+ const {
68
+ BundleGraph: {
69
+ bundleGraphEdgeTypes: bundleGraphEdgeTypes
70
+ },
71
+ Priority,
72
+ fromProjectPathRelative
73
+ } = require('./deep-imports');
74
+ async function run(input) {
75
+ let args = input;
76
+ let cacheDir = _path().default.join(process.cwd(), '.parcel-cache');
77
+ if (args[0] === '--cache') {
78
+ cacheDir = _path().default.resolve(process.cwd(), args[1]);
79
+ args = args.slice(2);
80
+ }
81
+ let initialCmd = args[0];
82
+ try {
83
+ _fs().default.accessSync(cacheDir);
84
+ } catch (e) {
85
+ console.error("Can't find cache dir", cacheDir);
86
+ process.exit(1);
87
+ }
88
+ console.log('Loading graphs...');
89
+ let {
90
+ assetGraph,
91
+ bundleGraph,
92
+ bundleInfo,
93
+ requestTracker,
94
+ cacheInfo
95
+ } = await (0, _index.loadGraphs)(cacheDir);
96
+ function hasRequestTracker() {
97
+ if (requestTracker == null) {
98
+ console.error('Request Graph could not be found');
99
+ return false;
100
+ }
101
+ return true;
102
+ }
103
+ function hasBundleGraph() {
104
+ if (bundleGraph == null) {
105
+ console.error('Bundle Graph could not be found');
106
+ return false;
107
+ }
108
+ return true;
109
+ }
110
+ function hasAssetGraph() {
111
+ if (assetGraph == null) {
112
+ console.error('Asset Graph could not be found');
113
+ return false;
114
+ }
115
+ return true;
116
+ }
117
+ function hasBundleInfo() {
118
+ if (bundleInfo == null) {
119
+ console.error('Bundle Info could not be found');
120
+ return false;
121
+ }
122
+ return true;
123
+ }
124
+
125
+ // -------------------------------------------------------
126
+
127
+ function getBundleFilePath(id) {
128
+ var _bundleInfo$get;
129
+ if (!hasBundleInfo()) {
130
+ return;
131
+ }
132
+ (0, _assert().default)(bundleInfo != null);
133
+ return fromProjectPathRelative((0, _nullthrows().default)((_bundleInfo$get = bundleInfo.get(id)) === null || _bundleInfo$get === void 0 ? void 0 : _bundleInfo$get.filePath));
134
+ }
135
+ function parseAssetLocator(v) {
136
+ let id = null;
137
+ if (v.length === 16) {
138
+ id = v;
139
+ } else {
140
+ if (!hasBundleGraph()) {
141
+ return;
142
+ }
143
+ (0, _assert().default)(bundleGraph != null);
144
+ for (let [assetId, publicId] of bundleGraph._publicIdByAssetId) {
145
+ if (publicId === v) {
146
+ id = assetId;
147
+ break;
148
+ }
149
+ }
150
+ }
151
+ if (id == null && v.length > 0) {
152
+ if (!hasAssetGraph()) {
153
+ return;
154
+ }
155
+ (0, _assert().default)(assetGraph != null);
156
+ let assetRegex = new RegExp(v);
157
+ for (let node of assetGraph.nodes.values()) {
158
+ if ((node === null || node === void 0 ? void 0 : node.type) === 'asset' && assetRegex.test(fromProjectPathRelative(node.value.filePath))) {
159
+ id = node.id;
160
+ break;
161
+ }
162
+ }
163
+ }
164
+ return id;
165
+ }
166
+ function parseBundleLocator(v) {
167
+ if (!hasBundleGraph()) {
168
+ return;
169
+ }
170
+ (0, _assert().default)(bundleGraph != null);
171
+ let bundleRegex = new RegExp(v);
172
+ for (let b of bundleGraph.getBundles()) {
173
+ let bundleFilePath = getBundleFilePath(b.id);
174
+ if (bundleFilePath !== undefined && bundleRegex.test(bundleFilePath) || b.id === v) {
175
+ return b.id;
176
+ }
177
+ }
178
+ }
179
+ function getAsset(v) {
180
+ let id = parseAssetLocator(v);
181
+ if (id == null) {
182
+ console.log(null);
183
+ } else {
184
+ try {
185
+ if (!hasBundleGraph()) {
186
+ return;
187
+ }
188
+ (0, _assert().default)(bundleGraph != null);
189
+ let asset = bundleGraph.getAssetById(id);
190
+ console.log('Public id', bundleGraph.getAssetPublicId(asset));
191
+ console.log(asset);
192
+ } catch (e) {
193
+ if (!hasAssetGraph()) {
194
+ return;
195
+ }
196
+ (0, _assert().default)(assetGraph != null);
197
+ let node = (0, _nullthrows().default)(assetGraph.getNodeByContentKey(id));
198
+ (0, _assert().default)(node.type === 'asset');
199
+ console.log(node.value);
200
+ }
201
+ }
202
+ }
203
+ function _findAssetNode(v) {
204
+ if (!hasAssetGraph()) {
205
+ return;
206
+ }
207
+ (0, _assert().default)(assetGraph != null);
208
+ let assetRegex = new RegExp(v);
209
+ for (let node of assetGraph.nodes.values()) {
210
+ if ((node === null || node === void 0 ? void 0 : node.type) === 'asset' && assetRegex.test(fromProjectPathRelative(node.value.filePath))) {
211
+ return node;
212
+ }
213
+ }
214
+ }
215
+ function findAsset(v) {
216
+ let node = _findAssetNode(v);
217
+ if (node) {
218
+ try {
219
+ if (!hasBundleGraph()) {
220
+ return;
221
+ }
222
+ (0, _assert().default)(bundleGraph != null);
223
+ console.log(`${bundleGraph.getAssetPublicId(bundleGraph.getAssetById(node.id))} ${fromProjectPathRelative(node.value.filePath)}`);
224
+ } catch (e) {
225
+ console.log(fromProjectPathRelative(node.value.filePath));
226
+ }
227
+ }
228
+ }
229
+ function findAssetWithSymbol(local) {
230
+ if (!hasBundleGraph() || !hasAssetGraph()) {
231
+ return;
232
+ }
233
+ (0, _assert().default)(bundleGraph != null);
234
+ (0, _assert().default)(assetGraph != null);
235
+ let [, assetId, binding, ref] = (0, _nullthrows().default)(local.match(/^\$([^$]+)\$([^$]+)\$(.*)$/), `symbol ${local} could not be resolved`);
236
+ let asset;
237
+ // Search against the id used by the JSTransformer and ScopeHoistingPackager,
238
+ // not the final asset id, as it may have changed with further transformation.
239
+ for (let node of assetGraph.nodes.values()) {
240
+ if ((node === null || node === void 0 ? void 0 : node.type) === 'asset' && node.value.meta.id === assetId) {
241
+ asset = node;
242
+ break;
243
+ }
244
+ }
245
+
246
+ // If the asset couldn't be found by searching for the id,
247
+ // search for the local name in asset used symbols.
248
+ if (asset == null) {
249
+ outer: for (let node of assetGraph.nodes.values()) {
250
+ if ((node === null || node === void 0 ? void 0 : node.type) === 'asset' && node.value.symbols) {
251
+ for (let symbol of node.value.symbols.values()) {
252
+ if (symbol.local === local) {
253
+ asset = node;
254
+ break outer;
255
+ }
256
+ }
257
+ }
258
+ }
259
+ }
260
+ (0, _assert().default)(asset, `An asset for ${assetId} could not be found`);
261
+ (0, _assert().default)(asset.type === 'asset', `Expected ${assetId} to be an asset, but found a ${asset.type}`);
262
+ try {
263
+ console.log(`${bundleGraph.getAssetPublicId(bundleGraph.getAssetById(asset.id))} ${fromProjectPathRelative(asset.value.filePath)}`);
264
+ } catch (e) {
265
+ console.log(fromProjectPathRelative(asset.value.filePath));
266
+ }
267
+ if (binding === 'export' && asset.value.symbols) {
268
+ for (let [symbolName, symbol] of asset.value.symbols) {
269
+ if (symbol.local === local) {
270
+ if (symbol.loc) {
271
+ let locPath = symbol.loc.filePath;
272
+ let locAsset = _findAssetNode(String(locPath));
273
+ if (locAsset != null) {
274
+ try {
275
+ console.log(`${bundleGraph.getAssetPublicId(bundleGraph.getAssetById(locAsset.id))} ${fromProjectPathRelative(locAsset.value.filePath)}`);
276
+ } catch (e) {
277
+ console.log(`imported as ${symbolName} from ${fromProjectPathRelative(locAsset.value.filePath)}`);
278
+ }
279
+ } else {
280
+ console.log(`imported as ${symbolName} from ${fromProjectPathRelative(locPath)}`);
281
+ }
282
+ } else {
283
+ console.log(`imported as ${symbolName}`);
284
+ }
285
+ }
286
+ }
287
+ } else if (ref) {
288
+ console.log(`possibly defined as ${ref}`);
289
+ }
290
+ }
291
+ function getNodeAssetGraph(v) {
292
+ if (!hasAssetGraph()) {
293
+ return;
294
+ }
295
+ (0, _assert().default)(assetGraph != null);
296
+ console.log(assetGraph.getNodeByContentKey(v));
297
+ }
298
+ function getNodeBundleGraph(v) {
299
+ if (!hasBundleGraph()) {
300
+ return;
301
+ }
302
+ (0, _assert().default)(bundleGraph != null);
303
+ console.log(bundleGraph._graph.getNodeByContentKey(v));
304
+ }
305
+ class Paths {
306
+ children = [];
307
+ constructor(value, label = '-', suffix = '') {
308
+ this.value = value;
309
+ this.label = label;
310
+ this.suffix = suffix;
311
+ }
312
+ add(v, label, suffix) {
313
+ let next = new Paths(v, label, suffix);
314
+ this.children.push(next);
315
+ return next;
316
+ }
317
+ print(format, prefix = '') {
318
+ console.log(`${prefix}${this.label} ${format(this.value)} ${this.suffix}`);
319
+ for (let i = 0; i < this.children.length; i++) {
320
+ this.children[i].print(format, prefix + ' ');
321
+ }
322
+ }
323
+ }
324
+ function _findEntries(graph, v) {
325
+ let asset = (0, _nullthrows().default)(parseAssetLocator(v), 'Asset not found');
326
+ let paths = new Paths(graph.getNodeIdByContentKey(asset), ' ');
327
+ let cb = (id, ctx, revisiting) => {
328
+ let {
329
+ paths,
330
+ lazyOutgoing
331
+ } = ctx;
332
+ let node = (0, _nullthrows().default)(graph.getNode(id));
333
+ if (node.id === asset) return ctx;
334
+ if (node.type === 'asset') {
335
+ paths = paths.add(id, lazyOutgoing ? '<' : undefined, revisiting ? '(revisiting)' : undefined);
336
+ lazyOutgoing = false;
337
+ } else if (node.type === 'dependency') {
338
+ if (node.value.priority === Priority.lazy) {
339
+ lazyOutgoing = true;
340
+ }
341
+ }
342
+ return {
343
+ paths,
344
+ lazyOutgoing
345
+ };
346
+ };
347
+
348
+ // like graph.dfs, but revisiting nodes and skipping its children
349
+ let seen = new Set();
350
+ function walk(id, ctx) {
351
+ let revisiting = seen.has(id);
352
+ let newCtx = cb(id, ctx, revisiting);
353
+ if (revisiting) return;
354
+ seen.add(id);
355
+ for (let parent of graph.getNodeIdsConnectedTo(id)) {
356
+ walk(parent, newCtx);
357
+ }
358
+ }
359
+ walk(graph.getNodeIdByContentKey(asset), {
360
+ paths,
361
+ lazyOutgoing: false
362
+ });
363
+ paths.print(id => {
364
+ let node = (0, _nullthrows().default)(graph.getNode(id));
365
+ (0, _assert().default)(node.type === 'asset');
366
+ return fromProjectPathRelative(node.value.filePath);
367
+ });
368
+ }
369
+ function findEntriesAssetGraph(v) {
370
+ if (!hasAssetGraph()) {
371
+ return;
372
+ }
373
+ (0, _assert().default)(assetGraph != null);
374
+ _findEntries(assetGraph, v);
375
+ }
376
+ function findEntriesBundleGraph(v) {
377
+ if (!hasBundleGraph()) {
378
+ return;
379
+ }
380
+ (0, _assert().default)(bundleGraph != null);
381
+ _findEntries(bundleGraph._graph, v);
382
+ }
383
+ function findEntries(v) {
384
+ findEntriesBundleGraph(v);
385
+ }
386
+ function getBundlesWithAsset(v) {
387
+ if (!hasBundleGraph()) {
388
+ return;
389
+ }
390
+ (0, _assert().default)(bundleGraph != null);
391
+ let asset = (0, _nullthrows().default)(parseAssetLocator(v), 'Asset not found');
392
+ for (let b of bundleGraph.getBundlesWithAsset(bundleGraph.getAssetById(asset))) {
393
+ let bundleFilePath = getBundleFilePath(b.id);
394
+ if (bundleFilePath !== undefined) {
395
+ console.log(`${b.id} ${bundleFilePath} ${b.mainEntryId != null ? `(main: ${b.mainEntryId})` : ''}`);
396
+ }
397
+ }
398
+ }
399
+ function getBundlesWithDependency(v) {
400
+ if (!hasBundleGraph()) {
401
+ return;
402
+ }
403
+ (0, _assert().default)(bundleGraph != null);
404
+ let node = (0, _nullthrows().default)(bundleGraph._graph.getNodeByContentKey(v));
405
+ (0, _assert().default)(node.type === 'dependency');
406
+ for (let b of bundleGraph.getBundlesWithDependency(node.value)) {
407
+ let bundleFilePath = getBundleFilePath(b.id);
408
+ if (bundleFilePath !== undefined) {
409
+ console.log(`${b.id} ${bundleFilePath} ${b.mainEntryId != null ? `(main: ${b.mainEntryId})` : ''}`);
410
+ }
411
+ }
412
+ }
413
+
414
+ // eslint-disable-next-line no-unused-vars
415
+ function getBundles(_) {
416
+ if (!hasBundleGraph()) {
417
+ return;
418
+ }
419
+ (0, _assert().default)(bundleGraph != null);
420
+ for (let b of bundleGraph.getBundles()) {
421
+ let bundleFilePath = getBundleFilePath(b.id);
422
+ if (bundleFilePath !== undefined) {
423
+ console.log(`${b.id} ${bundleFilePath} ${b.mainEntryId != null ? `(main: ${b.mainEntryId})` : ''}`);
424
+ }
425
+ }
426
+ }
427
+ function getReferencingBundles(v) {
428
+ if (!hasBundleGraph()) {
429
+ return;
430
+ }
431
+ (0, _assert().default)(bundleGraph != null);
432
+ let bundleId = (0, _nullthrows().default)(parseBundleLocator(v), 'Bundle not found');
433
+ let bundleNodeId = bundleGraph._graph.getNodeIdByContentKey(bundleId);
434
+ let bundleNode = (0, _nullthrows().default)(bundleGraph._graph.getNode(bundleNodeId), 'Bundle not found');
435
+ (0, _assert().default)(bundleNode.type === 'bundle', 'Not a bundle');
436
+ for (let b of bundleGraph.getReferencingBundles(bundleNode.value)) {
437
+ let bundleFilePath = getBundleFilePath(b.id);
438
+ if (bundleFilePath !== undefined) {
439
+ console.log(`${b.id} ${bundleFilePath} ${b.mainEntryId != null ? `(main: ${b.mainEntryId})` : ''}`);
440
+ }
441
+ }
442
+ }
443
+ function getIncomingDependenciesAssetGraph(v) {
444
+ if (!hasAssetGraph()) {
445
+ return;
446
+ }
447
+ (0, _assert().default)(assetGraph != null);
448
+ let asset = (0, _nullthrows().default)(parseAssetLocator(v), 'Asset not found');
449
+ let node = (0, _nullthrows().default)(assetGraph.getNodeByContentKey(asset));
450
+ (0, _assert().default)(node.type === 'asset');
451
+ console.log(assetGraph.getIncomingDependencies(node.value));
452
+ }
453
+ function getIncomingDependenciesBundleGraph(v) {
454
+ if (!hasBundleGraph()) {
455
+ return;
456
+ }
457
+ (0, _assert().default)(bundleGraph != null);
458
+ let asset = (0, _nullthrows().default)(parseAssetLocator(v), 'Asset not found');
459
+ let value = (0, _nullthrows().default)(bundleGraph.getAssetById(asset));
460
+ console.log(bundleGraph.getIncomingDependencies(value));
461
+ }
462
+ function getIncomingDependencies(v) {
463
+ getIncomingDependenciesBundleGraph(v);
464
+ }
465
+ function getResolvedAsset(v) {
466
+ if (!hasBundleGraph()) {
467
+ return;
468
+ }
469
+ (0, _assert().default)(bundleGraph != null);
470
+ let node = (0, _nullthrows().default)(bundleGraph._graph.getNodeByContentKey(v), 'Dependency not found');
471
+ (0, _assert().default)(node.type === 'dependency', 'Node is not a dependency, but a ' + node.type);
472
+ console.log(bundleGraph.getResolvedAsset(node.value));
473
+ }
474
+ function getAssetWithDependency(v) {
475
+ if (!hasBundleGraph()) {
476
+ return;
477
+ }
478
+ (0, _assert().default)(bundleGraph != null);
479
+ let node = (0, _nullthrows().default)(bundleGraph._graph.getNodeByContentKey(v), 'Dependency not found');
480
+ (0, _assert().default)(node.type === 'dependency', 'Node is not a dependency, but a ' + node.type);
481
+ console.log(bundleGraph.getAssetWithDependency(node.value));
482
+ }
483
+ function traverseAssets(v) {
484
+ if (!hasBundleGraph()) {
485
+ return;
486
+ }
487
+ (0, _assert().default)(bundleGraph != null);
488
+ let bundleId = (0, _nullthrows().default)(parseBundleLocator(v), 'Bundle not found');
489
+ let node = (0, _nullthrows().default)(bundleGraph._graph.getNodeByContentKey(bundleId), 'Bundle not found');
490
+ (0, _assert().default)(node.type === 'bundle', 'Node is not a bundle, but a ' + node.type);
491
+ bundleGraph.traverseAssets(node.value, asset => {
492
+ console.log(asset.id, asset.filePath);
493
+ });
494
+ }
495
+ function traverseBundle(v) {
496
+ if (!hasBundleGraph()) {
497
+ return;
498
+ }
499
+ (0, _assert().default)(bundleGraph != null);
500
+ let bundleId = (0, _nullthrows().default)(parseBundleLocator(v), 'Bundle not found');
501
+ let node = (0, _nullthrows().default)(bundleGraph._graph.getNodeByContentKey(bundleId), 'Bundle not found');
502
+ (0, _assert().default)(node.type === 'bundle', 'Node is not a bundle, but a ' + node.type);
503
+ bundleGraph.traverseBundle(node.value, node => {
504
+ if (node.type === 'asset') {
505
+ console.log(node.id, node.value.filePath);
506
+ } else {
507
+ console.log(node.id, node.value.sourcePath, '->', node.value.specifier, node.value.symbols ? `(${[...node.value.symbols.keys()].join(',')})` : '', node.excluded ? `- excluded` : '');
508
+ }
509
+ });
510
+ }
511
+ function getBundle(v) {
512
+ if (!hasBundleGraph()) {
513
+ return;
514
+ }
515
+ (0, _assert().default)(bundleGraph != null);
516
+ let bundleRegex = new RegExp(v);
517
+ for (let b of bundleGraph.getBundles()) {
518
+ let bundleFilePath = getBundleFilePath(b.id);
519
+ if (bundleFilePath !== undefined && bundleRegex.test(bundleFilePath) || b.id === v) {
520
+ console.log(getBundleFilePath(b.id), b);
521
+ }
522
+ }
523
+ }
524
+ function findBundleReason(bundle, asset) {
525
+ if (!hasBundleGraph()) {
526
+ return;
527
+ }
528
+ (0, _assert().default)(bundleGraph != null);
529
+ let bundleId = (0, _nullthrows().default)(parseBundleLocator(bundle), 'Bundle not found');
530
+ let bundleNodeId = bundleGraph._graph.getNodeIdByContentKey(bundleId);
531
+ let bundleNode = (0, _nullthrows().default)(bundleGraph._graph.getNode(bundleNodeId), 'Bundle not found');
532
+ (0, _assert().default)(bundleNode.type === 'bundle', 'Not a bundle');
533
+ let assetId = (0, _nullthrows().default)(parseAssetLocator(asset), 'Asset not found');
534
+ let assetNodeId = bundleGraph._graph.getNodeIdByContentKey(assetId);
535
+ let assetNode = (0, _nullthrows().default)(bundleGraph._graph.getNode(assetNodeId), 'Asset not found');
536
+ (0, _assert().default)(assetNode.type === 'asset', 'Not an asset');
537
+ (0, _assert().default)(bundleGraph._graph.hasEdge(bundleNodeId, assetNodeId, bundleGraphEdgeTypes.contains), 'Asset is not part of the bundle');
538
+ console.log('# Asset is main entry of bundle:', bundleNode.value.mainEntryId === assetId);
539
+ console.log('# Asset is an entry of bundle:', bundleNode.value.entryAssetIds.includes(assetId));
540
+ console.log('# Incoming dependencies contained in the bundle:');
541
+ for (let incoming of bundleGraph._graph.getNodeIdsConnectedTo(assetNodeId)) {
542
+ if (bundleGraph._graph.hasEdge(bundleNodeId, incoming, bundleGraphEdgeTypes.contains)) {
543
+ console.log(bundleGraph._graph.getNode(incoming));
544
+ }
545
+ }
546
+ console.log('# Incoming dependencies contained in referencing bundles (using this bundle as a shared bundle)');
547
+ let referencingBundles = bundleGraph.getReferencingBundles(bundleNode.value);
548
+ for (let incoming of bundleGraph._graph.getNodeIdsConnectedTo(assetNodeId)) {
549
+ if (referencingBundles.some(ref => bundleGraph._graph.hasEdge(bundleGraph._graph.getNodeIdByContentKey(ref.id), incoming, bundleGraphEdgeTypes.contains))) {
550
+ console.log(bundleGraph._graph.getNode(incoming));
551
+ }
552
+ }
553
+ }
554
+ function _getIncomingNodeOfType(bundleGraph, node, type) {
555
+ if (!hasBundleGraph()) {
556
+ return;
557
+ }
558
+ (0, _assert().default)(bundleGraph != null);
559
+ const bundleGraphNodeId = bundleGraph._graph.getNodeIdByContentKey(node.id);
560
+ return bundleGraph._graph.getNodeIdsConnectedTo(bundleGraphNodeId, -1).map(id => (0, _nullthrows().default)(bundleGraph._graph.getNode(id))).find(node => node.type == type);
561
+ }
562
+
563
+ // We find the priority of a Bundle or BundleGroup by looking at its incoming dependencies.
564
+ // If a Bundle does not have an incoming dependency, we look for an incoming BundleGroup and its dependency
565
+ // e.g. Dep(priority = 1) -> BundleGroup -> Bundle means that the Bundle has priority 1.
566
+ function _getBundlePriority(bundleGraph, bundle) {
567
+ if (!hasBundleGraph()) {
568
+ return;
569
+ }
570
+ (0, _assert().default)(bundleGraph != null);
571
+ let node = _getIncomingNodeOfType(bundleGraph, bundle, 'dependency');
572
+ if (node == null) {
573
+ node = _getIncomingNodeOfType(bundleGraph, bundle, 'bundle_group');
574
+ if (node == null) return null;
575
+ node = _getIncomingNodeOfType(bundleGraph, node, 'dependency');
576
+ }
577
+ if (node == null) return null;
578
+ (0, _assert().default)(node.type === 'dependency', 'Not a dependency');
579
+ return node.value.priority;
580
+ }
581
+ function _findEntryBundle(bundleGraph, node) {
582
+ if (!hasBundleGraph()) {
583
+ return;
584
+ }
585
+ (0, _assert().default)(bundleGraph != null);
586
+ const bundleGraphNodeId = bundleGraph._graph.getNodeIdByContentKey(node.id);
587
+ const entryBundleGroup = bundleGraph._graph.getNodeIdsConnectedTo(bundleGraphNodeId, -1).map(id => (0, _nullthrows().default)(bundleGraph._graph.getNode(id))).find(node => node.type === 'bundle_group' && bundleGraph.isEntryBundleGroup(node.value));
588
+ return entryBundleGroup;
589
+ }
590
+ // eslint-disable-next-line no-unused-vars
591
+ function inspectCache(_) {
592
+ // displays sizing of various entries of the cache
593
+ let table = [];
594
+ table.push(['Graphs', 'Size (bytes)', 'Deserialize (ms)', 'Serialize (ms)']);
595
+ let serialized = new Map();
596
+ serialized.set('RequestGraph', timeSerialize(requestTracker));
597
+ serialized.set('BundleGraph', timeSerialize(bundleGraph));
598
+ serialized.set('AssetGraph', timeSerialize(assetGraph));
599
+ for (let [name, info] of (0, _nullthrows().default)(cacheInfo).entries()) {
600
+ if (name === 'RequestGraph' && !hasRequestTracker() || name === 'BundleGraph' && !hasBundleGraph() || name === 'AssetGraph' && !hasAssetGraph()) {
601
+ continue;
602
+ }
603
+ let s = serialized.get(name);
604
+ (0, _assert().default)(s != null);
605
+ table.push([name, ...info, s]);
606
+ }
607
+ function getColumnSum(t, col) {
608
+ if (t == null) {
609
+ return '';
610
+ }
611
+ const initialValue = 0;
612
+ let column = t.map(r => r[col]);
613
+ column.shift();
614
+ (0, _assert().default)(column != null);
615
+ return column.reduce((accumulator, currentValue) => accumulator + currentValue, initialValue);
616
+ }
617
+ table.push(['Totals', getColumnSum(table, 1), getColumnSum(table, 2), getColumnSum(table, 3)]);
618
+ _printStatsTable('Cache Info', table);
619
+ }
620
+ function timeSerialize(graph) {
621
+ let date = Date.now();
622
+ (0, _v().serialize)(graph);
623
+ date = Date.now() - date;
624
+ return date;
625
+ }
626
+ function _printStatsTable(header, data) {
627
+ const config = {
628
+ columnDefault: {
629
+ width: 18
630
+ },
631
+ header: {
632
+ alignment: 'center',
633
+ content: header
634
+ }
635
+ };
636
+ console.log((0, _table().table)(data, config));
637
+ }
638
+
639
+ // eslint-disable-next-line no-unused-vars
640
+ function stats(_) {
641
+ let ag = {
642
+ asset: 0,
643
+ dependency: 0,
644
+ asset_group: 0
645
+ };
646
+ if (hasAssetGraph()) {
647
+ (0, _assert().default)(assetGraph != null);
648
+ for (let n of assetGraph.nodes) {
649
+ if (n && n.type in ag) {
650
+ // $FlowFixMe
651
+ ag[n.type]++;
652
+ }
653
+ }
654
+ _printStatsTable('# Asset Graph Node Counts', Object.entries(ag));
655
+ }
656
+ if (!hasBundleGraph()) {
657
+ return;
658
+ }
659
+ (0, _assert().default)(bundleGraph != null);
660
+ let bg = {
661
+ dependency: 0,
662
+ bundle: 0,
663
+ bundle_group: 0,
664
+ asset_node_modules: 0,
665
+ asset_source: 0
666
+ };
667
+ let b_type = {
668
+ entry: 0,
669
+ shared: 0,
670
+ async: 0,
671
+ parallel: 0,
672
+ sync: 0
673
+ };
674
+ let b_ext = {};
675
+ const entries = new Set();
676
+ for (let n of bundleGraph._graph.nodes) {
677
+ if ((n === null || n === void 0 ? void 0 : n.type) === 'bundle_group') {
678
+ bg.bundle_group++;
679
+ } else if ((n === null || n === void 0 ? void 0 : n.type) === 'bundle') {
680
+ bg.bundle++;
681
+
682
+ // $FlowFixMe
683
+ b_ext[n.value.type] = (b_ext[n.value.type] || 0) + 1;
684
+
685
+ // $FlowFixMe
686
+ const entry_group = _findEntryBundle(bundleGraph, n);
687
+ if (entry_group != null && !entries.has(entry_group.id)) {
688
+ b_type.entry++;
689
+ entries.add(entry_group.id);
690
+ } else if (n.value.mainEntryId == null) {
691
+ // In general, !bundle.mainEntryId means that it is shared. In the case of an async and shared bundle, only count it as shared.
692
+ b_type.shared++;
693
+ } else {
694
+ const priority = _getBundlePriority(bundleGraph, n);
695
+ if (priority == Priority.lazy) {
696
+ b_type.async++;
697
+ } else if (priority == Priority.parallel) {
698
+ b_type.parallel++;
699
+ } else if (priority == Priority.sync) {
700
+ b_type.sync++;
701
+ }
702
+ }
703
+ } else if ((n === null || n === void 0 ? void 0 : n.type) === 'asset') {
704
+ if (
705
+ // $FlowFixMe
706
+ fromProjectPathRelative(n.value.filePath).includes('node_modules')) {
707
+ bg.asset_node_modules++;
708
+ } else {
709
+ bg.asset_source++;
710
+ }
711
+ } else if ((n === null || n === void 0 ? void 0 : n.type) === 'dependency') {
712
+ bg.dependency++;
713
+ }
714
+ }
715
+ _printStatsTable('# Bundle Graph Node Counts', Object.entries(bg));
716
+ _printStatsTable('# Bundles By Type', Object.entries(b_type));
717
+ _printStatsTable('# Bundles By Extension', Object.entries(b_ext));
718
+
719
+ // Assert that counts for each breakdown are correct
720
+
721
+ let sum_b_ext = 0;
722
+ for (let k in b_ext) {
723
+ sum_b_ext += b_ext[k];
724
+ }
725
+ let sum_b_type = 0;
726
+ for (let k in b_type) {
727
+ sum_b_type += b_type[k];
728
+ }
729
+ (0, _assert().default)(bg.bundle == sum_b_type, `Bundles by type ${sum_b_type} does not equal total ${bg.bundle}`);
730
+ (0, _assert().default)(bg.bundle == sum_b_ext, `Bundles by extension ${sum_b_ext} does not equal total ${bg.bundle}`);
731
+ }
732
+
733
+ // -------------------------------------------------------
734
+
735
+ if (initialCmd != null) {
736
+ (async () => {
737
+ await eval(initialCmd);
738
+ process.exit(0);
739
+ })();
740
+ } else {
741
+ console.log('See .help. The graphs can be accessed via `assetGraph`, `bundleGraph` and `requestTracker`.');
742
+ process.on('uncaughtException', function (err) {
743
+ console.error(err);
744
+ server.displayPrompt();
745
+ });
746
+ const server = _repl().default.start({
747
+ useColors: true,
748
+ useGlobal: true
749
+ });
750
+ // $FlowFixMe[prop-missing]
751
+ server.setupHistory(_path().default.join(_os().default.homedir(), '.parcel_query_history'), () => {});
752
+
753
+ // $FlowFixMe[prop-missing]
754
+ server.context.bundleGraph = bundleGraph;
755
+ // $FlowFixMe[prop-missing]
756
+ server.context.assetGraph = assetGraph;
757
+ // $FlowFixMe[prop-missing]
758
+ server.context.requestTracker = requestTracker;
759
+ // $FlowFixMe[prop-missing]
760
+ server.context.cacheInfo = cacheInfo;
761
+ for (let [name, cmd] of new Map([['getAsset', {
762
+ help: 'args: <id | public id | filepath>',
763
+ action: getAsset
764
+ }], ['getNodeAssetGraph', {
765
+ help: 'args: <content key>. Find node by content key in the asset graph',
766
+ action: getNodeAssetGraph
767
+ }], ['getNodeBundleGraph', {
768
+ help: 'args: <content key>. Find node by content key in the bundle graph',
769
+ action: getNodeBundleGraph
770
+ }], ['findEntriesAssetGraph', {
771
+ help: 'args: <id | public id | filepath>. List paths from an asset to entry points (in asset graph)',
772
+ action: findEntriesAssetGraph
773
+ }], ['findEntriesBundleGraph', {
774
+ help: 'args: <id | public id | filepath>. List paths from an asset to entry points (in bundle graph)',
775
+ action: findEntriesBundleGraph
776
+ }], ['findEntries', {
777
+ help: '= findEntriesBundleGraph',
778
+ action: findEntries
779
+ }], ['getBundlesWithAsset', {
780
+ help: 'args: <id | public id | filepath>. Gets bundles containing the asset',
781
+ action: getBundlesWithAsset
782
+ }], ['getBundlesWithDependency', {
783
+ help: 'args: <id>. Gets bundles containing the dependency',
784
+ action: getBundlesWithDependency
785
+ }], ['getIncomingDependenciesAssetGraph', {
786
+ help: 'args: <asset: id | public id | filepath regex>',
787
+ action: getIncomingDependenciesAssetGraph
788
+ }], ['getIncomingDependenciesBundleGraph', {
789
+ help: 'args: <asset: id | public id | filepath regex>',
790
+ action: getIncomingDependenciesBundleGraph
791
+ }], ['getIncomingDependencies', {
792
+ help: '= getIncomingDependenciesBundleGraph',
793
+ action: getIncomingDependencies
794
+ }], ['getResolvedAsset', {
795
+ help: 'args: <dependency id>. Resolve the dependency',
796
+ action: getResolvedAsset
797
+ }], ['getAssetWithDependency', {
798
+ help: 'args: <dependency id>. Show which asset created the dependency',
799
+ action: getAssetWithDependency
800
+ }], ['traverseAssets', {
801
+ help: 'args: <bundle id>. List assets in bundle',
802
+ action: traverseAssets
803
+ }], ['traverseBundle', {
804
+ help: 'args: <bundle id>. List assets and dependencies in bundle',
805
+ action: traverseBundle
806
+ }], ['getBundle', {
807
+ help: 'args: <name prefix|bundle id>. List matching bundles',
808
+ action: getBundle
809
+ }], ['findBundleReason', {
810
+ help: 'args: <bundle> <asset>. Why is the asset in the bundle',
811
+ action: v => findBundleReason(...v.split(' '))
812
+ }], ['getBundles', {
813
+ help: 'List all bundles',
814
+ action: getBundles
815
+ }], ['getReferencingBundles', {
816
+ help: 'args: <bundle>. List bundles that reference the bundle',
817
+ action: getReferencingBundles
818
+ }], ['stats', {
819
+ help: 'Statistics',
820
+ action: stats
821
+ }], ['findAsset', {
822
+ help: 'args: <regex>. List assets matching the filepath regex',
823
+ action: findAsset
824
+ }], ['inspectCache', {
825
+ help: 'Cache Information',
826
+ action: inspectCache
827
+ }], ['findAssetWithSymbol', {
828
+ help: 'args: <local>. Get the asset that defines the symbol with the given local name',
829
+ action: findAssetWithSymbol
830
+ }]])) {
831
+ // $FlowFixMe
832
+ server.context[name] = cmd.action;
833
+ // $FlowFixMe
834
+ server.defineCommand(name, {
835
+ // $FlowFixMe
836
+ help: '📦 ' + cmd.help,
837
+ action: v => {
838
+ // $FlowFixMe
839
+ server.clearBufferedCommand();
840
+ // $FlowFixMe
841
+ try {
842
+ cmd.action(v);
843
+ } finally {
844
+ server.displayPrompt();
845
+ }
846
+ }
847
+ });
848
+ }
849
+ }
850
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ /* eslint-disable monorepo/no-internal-import */
4
+ const v = {
5
+ // Split up require specifier to outsmart packages/dev/babel-register/babel-plugin-module-translate.js
6
+ // $FlowFixMe(unsupported-syntax)
7
+ AssetGraph: require('@atlaspack/core' + '/lib/AssetGraph').default,
8
+ // $FlowFixMe(unsupported-syntax)
9
+ BundleGraph: require('@atlaspack/core' + '/lib/BundleGraph'),
10
+ // $FlowFixMe(unsupported-syntax)
11
+ RequestTracker: require('@atlaspack/core' + '/lib/RequestTracker'),
12
+ // $FlowFixMe(unsupported-syntax)
13
+ LMDBCache: require('@atlaspack/cache' + '/lib/LMDBCache').LMDBCache,
14
+ // $FlowFixMe(unsupported-syntax)
15
+ Priority: require('@atlaspack/core' + '/lib/types').Priority,
16
+ // $FlowFixMe(unsupported-syntax)
17
+ fromProjectPathRelative: require('@atlaspack/core' + '/lib/projectPath').fromProjectPathRelative
18
+ };
19
+ module.exports = v;
package/lib/index.js ADDED
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadGraphs = loadGraphs;
7
+ function _fs() {
8
+ const data = _interopRequireDefault(require("fs"));
9
+ _fs = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _path() {
15
+ const data = _interopRequireDefault(require("path"));
16
+ _path = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _v() {
22
+ const data = _interopRequireDefault(require("v8"));
23
+ _v = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ function _nullthrows() {
29
+ const data = _interopRequireDefault(require("nullthrows"));
30
+ _nullthrows = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ function _assert() {
36
+ const data = _interopRequireDefault(require("assert"));
37
+ _assert = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
42
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
43
+ /* eslint-disable no-console, monorepo/no-internal-import */
44
+ const {
45
+ AssetGraph,
46
+ BundleGraph: {
47
+ default: BundleGraph
48
+ },
49
+ RequestTracker: {
50
+ default: RequestTracker,
51
+ readAndDeserializeRequestGraph,
52
+ requestGraphEdgeTypes
53
+ },
54
+ LMDBCache
55
+ } = require('./deep-imports.js');
56
+ async function loadGraphs(cacheDir) {
57
+ let cacheInfo = new Map();
58
+ let {
59
+ requestGraphBlob,
60
+ bundleGraphBlob,
61
+ assetGraphBlob
62
+ } = function getMostRecentCacheBlobs() {
63
+ let files = _fs().default.readdirSync(cacheDir);
64
+ let result = {};
65
+ let blobsToFind = [{
66
+ name: 'requestGraphBlob',
67
+ check: basename => basename.startsWith('requestGraph-') && !basename.startsWith('requestGraph-nodes')
68
+ }, {
69
+ name: 'bundleGraphBlob',
70
+ check: basename => basename.endsWith('BundleGraph-0')
71
+ }, {
72
+ name: 'assetGraphBlob',
73
+ check: basename => basename.endsWith('AssetGraph-0')
74
+ }];
75
+ for (let file of files) {
76
+ let basename = _path().default.basename(file);
77
+ let match = blobsToFind.find(({
78
+ check
79
+ }) => check(basename));
80
+ if (match) {
81
+ let stat = _fs().default.statSync(_path().default.join(cacheDir, file));
82
+ if (!match.mtime || stat.mtime > match.mtime) {
83
+ match.mtime = stat.mtime;
84
+ result[match.name] = file;
85
+ }
86
+ }
87
+ }
88
+ return result;
89
+ }();
90
+ const cache = new LMDBCache(cacheDir);
91
+
92
+ // Get requestTracker
93
+ let requestTracker;
94
+ if (requestGraphBlob) {
95
+ try {
96
+ var _cacheInfo$get;
97
+ let requestGraphKey = requestGraphBlob.slice(0, -'-0'.length);
98
+ let date = Date.now();
99
+ let {
100
+ requestGraph,
101
+ bufferLength
102
+ } = await readAndDeserializeRequestGraph(cache, requestGraphKey, requestGraphKey.replace('requestGraph-', ''));
103
+ requestTracker = new RequestTracker({
104
+ graph: requestGraph,
105
+ // $FlowFixMe
106
+ farm: null,
107
+ // $FlowFixMe
108
+ options: null
109
+ });
110
+ let timeToDeserialize = Date.now() - date;
111
+ cacheInfo.set('RequestGraph', [bufferLength]);
112
+ (_cacheInfo$get = cacheInfo.get('RequestGraph')) === null || _cacheInfo$get === void 0 || _cacheInfo$get.push(timeToDeserialize);
113
+ } catch (e) {
114
+ console.log('Error loading Request Graph\n', e);
115
+ }
116
+ }
117
+
118
+ // Get bundleGraph
119
+ let bundleGraph;
120
+ if (bundleGraphBlob) {
121
+ try {
122
+ var _cacheInfo$get2;
123
+ let file = await cache.getLargeBlob(_path().default.basename(bundleGraphBlob).slice(0, -'-0'.length));
124
+ let timeToDeserialize = Date.now();
125
+ let obj = _v().default.deserialize(file);
126
+ (0, _assert().default)(obj.bundleGraph != null);
127
+ bundleGraph = BundleGraph.deserialize(obj.bundleGraph.value);
128
+ timeToDeserialize = Date.now() - timeToDeserialize;
129
+ cacheInfo.set('BundleGraph', [Buffer.byteLength(file)]);
130
+ (_cacheInfo$get2 = cacheInfo.get('BundleGraph')) === null || _cacheInfo$get2 === void 0 || _cacheInfo$get2.push(timeToDeserialize);
131
+ } catch (e) {
132
+ console.log('Error loading Bundle Graph\n', e);
133
+ }
134
+ }
135
+
136
+ // Get assetGraph
137
+ let assetGraph;
138
+ if (assetGraphBlob) {
139
+ try {
140
+ var _cacheInfo$get3;
141
+ let file = await cache.getLargeBlob(_path().default.basename(assetGraphBlob).slice(0, -'-0'.length));
142
+ let timeToDeserialize = Date.now();
143
+ let obj = _v().default.deserialize(file);
144
+ (0, _assert().default)(obj.assetGraph != null);
145
+ assetGraph = AssetGraph.deserialize(obj.assetGraph.value);
146
+ timeToDeserialize = Date.now() - timeToDeserialize;
147
+ cacheInfo.set('AssetGraph', [Buffer.byteLength(file)]);
148
+ (_cacheInfo$get3 = cacheInfo.get('AssetGraph')) === null || _cacheInfo$get3 === void 0 || _cacheInfo$get3.push(timeToDeserialize);
149
+ } catch (e) {
150
+ console.log('Error loading Asset Graph\n', e);
151
+ }
152
+ }
153
+ function getSubRequests(id) {
154
+ return requestTracker.graph.getNodeIdsConnectedFrom(id, requestGraphEdgeTypes.subrequest).map(n => (0, _nullthrows().default)(requestTracker.graph.getNode(n)));
155
+ }
156
+
157
+ // Load graphs by finding the main subrequests and loading their results
158
+ let bundleInfo;
159
+ try {
160
+ (0, _assert().default)(requestTracker);
161
+ let buildRequestId = requestTracker.graph.getNodeIdByContentKey('atlaspack_build_request');
162
+ let buildRequestNode = (0, _nullthrows().default)(requestTracker.graph.getNode(buildRequestId));
163
+ (0, _assert().default)(buildRequestNode.type === 1 && buildRequestNode.requestType === 1);
164
+ let buildRequestSubRequests = getSubRequests(buildRequestId);
165
+ let writeBundlesRequest = buildRequestSubRequests.find(n => n.type === 1 && n.requestType === 11);
166
+ if (writeBundlesRequest != null) {
167
+ (0, _assert().default)(writeBundlesRequest.type === 1);
168
+ // $FlowFixMe[incompatible-cast]
169
+ bundleInfo = (0, _nullthrows().default)(writeBundlesRequest.result);
170
+ }
171
+ } catch (e) {
172
+ console.log('Error loading bundleInfo\n', e);
173
+ }
174
+ return {
175
+ assetGraph,
176
+ bundleGraph,
177
+ requestTracker,
178
+ bundleInfo,
179
+ cacheInfo
180
+ };
181
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/query",
3
- "version": "2.14.0",
3
+ "version": "2.14.1-canary.6+57e29c592",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -18,17 +18,18 @@
18
18
  },
19
19
  "main": "src/index.js",
20
20
  "dependencies": {
21
- "@atlaspack/cache": "2.13.2",
22
- "@atlaspack/core": "2.14.0",
23
- "@atlaspack/graph": "3.4.0",
21
+ "@atlaspack/cache": "2.13.3-canary.6+57e29c592",
22
+ "@atlaspack/core": "2.14.1-canary.6+57e29c592",
23
+ "@atlaspack/graph": "3.4.1-canary.6+57e29c592",
24
24
  "nullthrows": "^1.1.1",
25
25
  "table": "^6.8.1",
26
26
  "v8-compile-cache": "^2.0.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@babel/core": "^7.22.11",
30
29
  "@atlaspack/babel-register": "2.14.0",
30
+ "@babel/core": "^7.22.11",
31
31
  "rimraf": "^5.0.5"
32
32
  },
33
- "type": "commonjs"
33
+ "type": "commonjs",
34
+ "gitHead": "57e29c592cff406d084b3c676a1c899f0bb6e78f"
34
35
  }