@atlaspack/query 2.14.21 → 2.14.22-typescript-80839fbd5.0
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 +201 -0
- package/lib/cli.js +36 -26
- package/lib/deep-imports.js +2 -7
- package/lib/index.js +12 -6
- package/package.json +7 -7
- package/src/{cli.js → cli.ts} +65 -41
- package/src/{deep-imports.js → deep-imports.ts} +28 -31
- package/src/{index.js → index.ts} +30 -23
- package/tsconfig.json +4 -0
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/cli.js
CHANGED
@@ -63,7 +63,7 @@ function _table() {
|
|
63
63
|
var _index = require("./index");
|
64
64
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
65
65
|
/* eslint-disable no-console, monorepo/no-internal-import */
|
66
|
-
|
66
|
+
|
67
67
|
const {
|
68
68
|
BundleGraph: {
|
69
69
|
bundleGraphEdgeTypes: bundleGraphEdgeTypes
|
@@ -488,6 +488,8 @@ async function run(input) {
|
|
488
488
|
let bundleId = (0, _nullthrows().default)(parseBundleLocator(v), 'Bundle not found');
|
489
489
|
let node = (0, _nullthrows().default)(bundleGraph._graph.getNodeByContentKey(bundleId), 'Bundle not found');
|
490
490
|
(0, _assert().default)(node.type === 'bundle', 'Node is not a bundle, but a ' + node.type);
|
491
|
+
|
492
|
+
// @ts-expect-error TS7006
|
491
493
|
bundleGraph.traverseAssets(node.value, asset => {
|
492
494
|
console.log(asset.id, asset.filePath);
|
493
495
|
});
|
@@ -500,6 +502,8 @@ async function run(input) {
|
|
500
502
|
let bundleId = (0, _nullthrows().default)(parseBundleLocator(v), 'Bundle not found');
|
501
503
|
let node = (0, _nullthrows().default)(bundleGraph._graph.getNodeByContentKey(bundleId), 'Bundle not found');
|
502
504
|
(0, _assert().default)(node.type === 'bundle', 'Node is not a bundle, but a ' + node.type);
|
505
|
+
|
506
|
+
// @ts-expect-error TS7006
|
503
507
|
bundleGraph.traverseBundle(node.value, node => {
|
504
508
|
if (node.type === 'asset') {
|
505
509
|
console.log(node.id, node.value.filePath);
|
@@ -546,23 +550,34 @@ async function run(input) {
|
|
546
550
|
console.log('# Incoming dependencies contained in referencing bundles (using this bundle as a shared bundle)');
|
547
551
|
let referencingBundles = bundleGraph.getReferencingBundles(bundleNode.value);
|
548
552
|
for (let incoming of bundleGraph._graph.getNodeIdsConnectedTo(assetNodeId)) {
|
549
|
-
if (
|
553
|
+
if (
|
554
|
+
// @ts-expect-error TS7006
|
555
|
+
referencingBundles.some(ref => bundleGraph._graph.hasEdge(bundleGraph._graph.getNodeIdByContentKey(ref.id), incoming, bundleGraphEdgeTypes.contains))) {
|
550
556
|
console.log(bundleGraph._graph.getNode(incoming));
|
551
557
|
}
|
552
558
|
}
|
553
559
|
}
|
554
|
-
function _getIncomingNodeOfType(
|
560
|
+
function _getIncomingNodeOfType(
|
561
|
+
// @ts-expect-error TS2304
|
562
|
+
bundleGraph,
|
563
|
+
// @ts-expect-error TS7006
|
564
|
+
node, type) {
|
555
565
|
if (!hasBundleGraph()) {
|
556
566
|
return;
|
557
567
|
}
|
558
568
|
(0, _assert().default)(bundleGraph != null);
|
559
569
|
const bundleGraphNodeId = bundleGraph._graph.getNodeIdByContentKey(node.id);
|
560
|
-
return bundleGraph._graph.getNodeIdsConnectedTo(bundleGraphNodeId, -1)
|
570
|
+
return bundleGraph._graph.getNodeIdsConnectedTo(bundleGraphNodeId, -1)
|
571
|
+
// @ts-expect-error TS7006
|
572
|
+
.map(id => (0, _nullthrows().default)(bundleGraph._graph.getNode(id)))
|
573
|
+
// @ts-expect-error TS7006
|
574
|
+
.find(node => node.type == type);
|
561
575
|
}
|
562
576
|
|
563
577
|
// We find the priority of a Bundle or BundleGroup by looking at its incoming dependencies.
|
564
578
|
// If a Bundle does not have an incoming dependency, we look for an incoming BundleGroup and its dependency
|
565
579
|
// e.g. Dep(priority = 1) -> BundleGroup -> Bundle means that the Bundle has priority 1.
|
580
|
+
// @ts-expect-error TS2304
|
566
581
|
function _getBundlePriority(bundleGraph, bundle) {
|
567
582
|
if (!hasBundleGraph()) {
|
568
583
|
return;
|
@@ -578,13 +593,19 @@ async function run(input) {
|
|
578
593
|
(0, _assert().default)(node.type === 'dependency', 'Not a dependency');
|
579
594
|
return node.value.priority;
|
580
595
|
}
|
596
|
+
|
597
|
+
// @ts-expect-error TS2304
|
581
598
|
function _findEntryBundle(bundleGraph, node) {
|
582
599
|
if (!hasBundleGraph()) {
|
583
600
|
return;
|
584
601
|
}
|
585
602
|
(0, _assert().default)(bundleGraph != null);
|
586
603
|
const bundleGraphNodeId = bundleGraph._graph.getNodeIdByContentKey(node.id);
|
587
|
-
const entryBundleGroup = bundleGraph._graph.getNodeIdsConnectedTo(bundleGraphNodeId, -1)
|
604
|
+
const entryBundleGroup = bundleGraph._graph.getNodeIdsConnectedTo(bundleGraphNodeId, -1)
|
605
|
+
// @ts-expect-error TS7006
|
606
|
+
.map(id => (0, _nullthrows().default)(bundleGraph._graph.getNode(id))).find(
|
607
|
+
// @ts-expect-error TS7006
|
608
|
+
node => node.type === 'bundle_group' && bundleGraph.isEntryBundleGroup(node.value));
|
588
609
|
return entryBundleGroup;
|
589
610
|
}
|
590
611
|
// eslint-disable-next-line no-unused-vars
|
@@ -612,12 +633,16 @@ async function run(input) {
|
|
612
633
|
let column = t.map(r => r[col]);
|
613
634
|
column.shift();
|
614
635
|
(0, _assert().default)(column != null);
|
615
|
-
return column.reduce(
|
636
|
+
return column.reduce(
|
637
|
+
// @ts-expect-error TS2365
|
638
|
+
(accumulator, currentValue) => accumulator + currentValue, initialValue);
|
616
639
|
}
|
617
640
|
table.push(['Totals', getColumnSum(table, 1), getColumnSum(table, 2), getColumnSum(table, 3)]);
|
618
641
|
_printStatsTable('Cache Info', table);
|
619
642
|
}
|
620
|
-
function timeSerialize(
|
643
|
+
function timeSerialize(
|
644
|
+
// @ts-expect-error TS2304
|
645
|
+
graph) {
|
621
646
|
let date = Date.now();
|
622
647
|
(0, _v().serialize)(graph);
|
623
648
|
date = Date.now() - date;
|
@@ -647,7 +672,7 @@ async function run(input) {
|
|
647
672
|
(0, _assert().default)(assetGraph != null);
|
648
673
|
for (let n of assetGraph.nodes) {
|
649
674
|
if (n && n.type in ag) {
|
650
|
-
//
|
675
|
+
// @ts-expect-error TS7053
|
651
676
|
ag[n.type]++;
|
652
677
|
}
|
653
678
|
}
|
@@ -678,11 +703,7 @@ async function run(input) {
|
|
678
703
|
bg.bundle_group++;
|
679
704
|
} else if ((n === null || n === void 0 ? void 0 : n.type) === 'bundle') {
|
680
705
|
bg.bundle++;
|
681
|
-
|
682
|
-
// $FlowFixMe
|
683
706
|
b_ext[n.value.type] = (b_ext[n.value.type] || 0) + 1;
|
684
|
-
|
685
|
-
// $FlowFixMe
|
686
707
|
const entry_group = _findEntryBundle(bundleGraph, n);
|
687
708
|
if (entry_group != null && !entries.has(entry_group.id)) {
|
688
709
|
b_type.entry++;
|
@@ -701,9 +722,7 @@ async function run(input) {
|
|
701
722
|
}
|
702
723
|
}
|
703
724
|
} else if ((n === null || n === void 0 ? void 0 : n.type) === 'asset') {
|
704
|
-
if (
|
705
|
-
// $FlowFixMe
|
706
|
-
fromProjectPathRelative(n.value.filePath).includes('node_modules')) {
|
725
|
+
if (fromProjectPathRelative(n.value.filePath).includes('node_modules')) {
|
707
726
|
bg.asset_node_modules++;
|
708
727
|
} else {
|
709
728
|
bg.asset_source++;
|
@@ -724,6 +743,7 @@ async function run(input) {
|
|
724
743
|
}
|
725
744
|
let sum_b_type = 0;
|
726
745
|
for (let k in b_type) {
|
746
|
+
// @ts-expect-error TS7053
|
727
747
|
sum_b_type += b_type[k];
|
728
748
|
}
|
729
749
|
(0, _assert().default)(bg.bundle == sum_b_type, `Bundles by type ${sum_b_type} does not equal total ${bg.bundle}`);
|
@@ -747,16 +767,10 @@ async function run(input) {
|
|
747
767
|
useColors: true,
|
748
768
|
useGlobal: true
|
749
769
|
});
|
750
|
-
// $FlowFixMe[prop-missing]
|
751
770
|
server.setupHistory(_path().default.join(_os().default.homedir(), '.parcel_query_history'), () => {});
|
752
|
-
|
753
|
-
// $FlowFixMe[prop-missing]
|
754
771
|
server.context.bundleGraph = bundleGraph;
|
755
|
-
// $FlowFixMe[prop-missing]
|
756
772
|
server.context.assetGraph = assetGraph;
|
757
|
-
// $FlowFixMe[prop-missing]
|
758
773
|
server.context.requestTracker = requestTracker;
|
759
|
-
// $FlowFixMe[prop-missing]
|
760
774
|
server.context.cacheInfo = cacheInfo;
|
761
775
|
for (let [name, cmd] of new Map([['getAsset', {
|
762
776
|
help: 'args: <id | public id | filepath>',
|
@@ -808,6 +822,7 @@ async function run(input) {
|
|
808
822
|
action: getBundle
|
809
823
|
}], ['findBundleReason', {
|
810
824
|
help: 'args: <bundle> <asset>. Why is the asset in the bundle',
|
825
|
+
// @ts-expect-error TS2556
|
811
826
|
action: v => findBundleReason(...v.split(' '))
|
812
827
|
}], ['getBundles', {
|
813
828
|
help: 'List all bundles',
|
@@ -828,16 +843,11 @@ async function run(input) {
|
|
828
843
|
help: 'args: <local>. Get the asset that defines the symbol with the given local name',
|
829
844
|
action: findAssetWithSymbol
|
830
845
|
}]])) {
|
831
|
-
// $FlowFixMe
|
832
846
|
server.context[name] = cmd.action;
|
833
|
-
// $FlowFixMe
|
834
847
|
server.defineCommand(name, {
|
835
|
-
// $FlowFixMe
|
836
848
|
help: '📦 ' + cmd.help,
|
837
849
|
action: v => {
|
838
|
-
// $FlowFixMe
|
839
850
|
server.clearBufferedCommand();
|
840
|
-
// $FlowFixMe
|
841
851
|
try {
|
842
852
|
cmd.action(v);
|
843
853
|
} finally {
|
package/lib/deep-imports.js
CHANGED
@@ -1,19 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
/* eslint-disable monorepo/no-internal-import */
|
4
|
-
|
4
|
+
|
5
|
+
const v = process.env.ATLASPACK_BUILD_ENV === 'production' || process.env.ATLASPACK_REGISTER_USE_SRC !== 'true' ? {
|
5
6
|
// Split up require specifier to outsmart packages/dev/babel-register/babel-plugin-module-translate.js
|
6
|
-
// $FlowFixMe(unsupported-syntax)
|
7
7
|
AssetGraph: require('@atlaspack/core' + '/lib/AssetGraph').default,
|
8
|
-
// $FlowFixMe(unsupported-syntax)
|
9
8
|
BundleGraph: require('@atlaspack/core' + '/lib/BundleGraph'),
|
10
|
-
// $FlowFixMe(unsupported-syntax)
|
11
9
|
RequestTracker: require('@atlaspack/core' + '/lib/RequestTracker'),
|
12
|
-
// $FlowFixMe(unsupported-syntax)
|
13
10
|
LMDBLiteCache: require('@atlaspack/cache' + '/lib/LMDBLiteCache').LMDBLiteCache,
|
14
|
-
// $FlowFixMe(unsupported-syntax)
|
15
11
|
Priority: require('@atlaspack/core' + '/lib/types').Priority,
|
16
|
-
// $FlowFixMe(unsupported-syntax)
|
17
12
|
fromProjectPathRelative: require('@atlaspack/core' + '/lib/projectPath').fromProjectPathRelative
|
18
13
|
} : {
|
19
14
|
AssetGraph: require('@atlaspack/core/src/AssetGraph').default,
|
package/lib/index.js
CHANGED
@@ -27,6 +27,7 @@ function _assert() {
|
|
27
27
|
}
|
28
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
29
29
|
/* eslint-disable no-console, monorepo/no-internal-import */
|
30
|
+
|
30
31
|
const {
|
31
32
|
AssetGraph,
|
32
33
|
BundleGraph: {
|
@@ -38,7 +39,7 @@ const {
|
|
38
39
|
requestGraphEdgeTypes
|
39
40
|
},
|
40
41
|
LMDBLiteCache
|
41
|
-
} = require('./deep-imports.js');
|
42
|
+
} = process.env.ATLASPACK_REGISTER_USE_SRC === 'true' ? require('./deep-imports.js') : require('./deep-imports.ts');
|
42
43
|
async function loadGraphs(cacheDir) {
|
43
44
|
let cacheInfo = new Map();
|
44
45
|
const cache = new LMDBLiteCache(cacheDir);
|
@@ -70,6 +71,7 @@ async function loadGraphs(cacheDir) {
|
|
70
71
|
});
|
71
72
|
|
72
73
|
// Get requestTracker
|
74
|
+
// @ts-expect-error TS7034
|
73
75
|
let requestTracker;
|
74
76
|
if (requestGraphBlob != null && requestGraphKey != null) {
|
75
77
|
try {
|
@@ -84,9 +86,7 @@ async function loadGraphs(cacheDir) {
|
|
84
86
|
} = await readAndDeserializeRequestGraph(cache, requestGraphBlob, requestGraphKey);
|
85
87
|
requestTracker = new RequestTracker({
|
86
88
|
graph: requestGraph,
|
87
|
-
// $FlowFixMe
|
88
89
|
farm: null,
|
89
|
-
// $FlowFixMe
|
90
90
|
options: null
|
91
91
|
});
|
92
92
|
let timeToDeserialize = Date.now() - date;
|
@@ -134,7 +134,12 @@ async function loadGraphs(cacheDir) {
|
|
134
134
|
}
|
135
135
|
}
|
136
136
|
function getSubRequests(id) {
|
137
|
-
return
|
137
|
+
return (
|
138
|
+
// @ts-expect-error TS7005
|
139
|
+
requestTracker.graph.getNodeIdsConnectedFrom(id, requestGraphEdgeTypes.subrequest)
|
140
|
+
// @ts-expect-error TS7006
|
141
|
+
.map(n => (0, _nullthrows().default)(requestTracker.graph.getNode(n)))
|
142
|
+
);
|
138
143
|
}
|
139
144
|
|
140
145
|
// Load graphs by finding the main subrequests and loading their results
|
@@ -145,10 +150,11 @@ async function loadGraphs(cacheDir) {
|
|
145
150
|
let buildRequestNode = (0, _nullthrows().default)(requestTracker.graph.getNode(buildRequestId));
|
146
151
|
(0, _assert().default)(buildRequestNode.type === 1 && buildRequestNode.requestType === 1);
|
147
152
|
let buildRequestSubRequests = getSubRequests(buildRequestId);
|
148
|
-
let writeBundlesRequest = buildRequestSubRequests.find(
|
153
|
+
let writeBundlesRequest = buildRequestSubRequests.find(
|
154
|
+
// @ts-expect-error TS7006
|
155
|
+
n => n.type === 1 && n.requestType === 11);
|
149
156
|
if (writeBundlesRequest != null) {
|
150
157
|
(0, _assert().default)(writeBundlesRequest.type === 1);
|
151
|
-
// $FlowFixMe[incompatible-cast]
|
152
158
|
bundleInfo = (0, _nullthrows().default)(writeBundlesRequest.result);
|
153
159
|
}
|
154
160
|
} catch (e) {
|
package/package.json
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "@atlaspack/query",
|
3
|
-
"version": "2.14.
|
3
|
+
"version": "2.14.22-typescript-80839fbd5.0",
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
5
5
|
"publishConfig": {
|
6
6
|
"access": "public"
|
7
7
|
},
|
8
8
|
"scripts": {
|
9
|
-
"prepack": "./ensure-no-dev-lib.sh",
|
10
9
|
"dev:prepare": "rimraf ./lib/ && mkdir -p lib && cp ./bin/dev-bin.js ./lib/bin.js"
|
11
10
|
},
|
12
11
|
"repository": {
|
@@ -18,17 +17,18 @@
|
|
18
17
|
},
|
19
18
|
"main": "src/index.js",
|
20
19
|
"dependencies": {
|
21
|
-
"@atlaspack/cache": "3.2.
|
22
|
-
"@atlaspack/core": "2.19.
|
23
|
-
"@atlaspack/graph": "3.5.
|
20
|
+
"@atlaspack/cache": "3.2.16-typescript-80839fbd5.0",
|
21
|
+
"@atlaspack/core": "2.19.3-typescript-80839fbd5.0",
|
22
|
+
"@atlaspack/graph": "3.5.10-typescript-80839fbd5.0",
|
24
23
|
"nullthrows": "^1.1.1",
|
25
24
|
"table": "^6.8.1",
|
26
25
|
"v8-compile-cache": "^2.0.0"
|
27
26
|
},
|
28
27
|
"devDependencies": {
|
28
|
+
"@atlaspack/babel-register": "2.14.2-typescript-80839fbd5.0",
|
29
29
|
"@babel/core": "^7.22.11",
|
30
|
-
"@atlaspack/babel-register": "2.14.1",
|
31
30
|
"rimraf": "^5.0.5"
|
32
31
|
},
|
33
|
-
"type": "commonjs"
|
32
|
+
"type": "commonjs",
|
33
|
+
"gitHead": "80839fbd5c6d6668c2622849856a4b25601354a8"
|
34
34
|
}
|
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,4 +1,3 @@
|
|
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';
|
@@ -16,15 +15,20 @@ const {
|
|
16
15
|
requestGraphEdgeTypes,
|
17
16
|
},
|
18
17
|
LMDBLiteCache,
|
19
|
-
} =
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
|
18
|
+
} = process.env.ATLASPACK_REGISTER_USE_SRC === 'true'
|
19
|
+
? require('./deep-imports.js')
|
20
|
+
: require('./deep-imports.ts');
|
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
|
+
}> {
|
28
32
|
let cacheInfo: Map<string, Array<string | number>> = new Map();
|
29
33
|
const cache = new LMDBLiteCache(cacheDir);
|
30
34
|
|
@@ -54,6 +58,7 @@ export async function loadGraphs(cacheDir: string): Promise<{|
|
|
54
58
|
console.log({requestGraphBlob, bundleGraphBlob, assetGraphBlob});
|
55
59
|
|
56
60
|
// Get requestTracker
|
61
|
+
// @ts-expect-error TS7034
|
57
62
|
let requestTracker;
|
58
63
|
if (requestGraphBlob != null && requestGraphKey != null) {
|
59
64
|
try {
|
@@ -74,15 +79,13 @@ export async function loadGraphs(cacheDir: string): Promise<{|
|
|
74
79
|
|
75
80
|
requestTracker = new RequestTracker({
|
76
81
|
graph: requestGraph,
|
77
|
-
// $FlowFixMe
|
78
82
|
farm: null,
|
79
|
-
// $FlowFixMe
|
80
83
|
options: null,
|
81
84
|
});
|
82
85
|
let timeToDeserialize = Date.now() - date;
|
83
86
|
cacheInfo.set('RequestGraph', [bufferLength]);
|
84
87
|
cacheInfo.get('RequestGraph')?.push(timeToDeserialize);
|
85
|
-
} catch (e) {
|
88
|
+
} catch (e: any) {
|
86
89
|
console.error('Error loading Request Graph\n', e);
|
87
90
|
}
|
88
91
|
}
|
@@ -101,7 +104,7 @@ export async function loadGraphs(cacheDir: string): Promise<{|
|
|
101
104
|
|
102
105
|
cacheInfo.set('BundleGraph', [Buffer.byteLength(file)]);
|
103
106
|
cacheInfo.get('BundleGraph')?.push(timeToDeserialize);
|
104
|
-
} catch (e) {
|
107
|
+
} catch (e: any) {
|
105
108
|
console.error('Error loading Bundle Graph\n', e);
|
106
109
|
}
|
107
110
|
}
|
@@ -121,15 +124,19 @@ export async function loadGraphs(cacheDir: string): Promise<{|
|
|
121
124
|
|
122
125
|
cacheInfo.set('AssetGraph', [Buffer.byteLength(file)]);
|
123
126
|
cacheInfo.get('AssetGraph')?.push(timeToDeserialize);
|
124
|
-
} catch (e) {
|
127
|
+
} catch (e: any) {
|
125
128
|
console.error('Error loading Asset Graph\n', e);
|
126
129
|
}
|
127
130
|
}
|
128
131
|
|
129
132
|
function getSubRequests(id: NodeId) {
|
130
|
-
return
|
131
|
-
|
132
|
-
|
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
|
+
);
|
133
140
|
}
|
134
141
|
|
135
142
|
// Load graphs by finding the main subrequests and loading their results
|
@@ -148,17 +155,17 @@ export async function loadGraphs(cacheDir: string): Promise<{|
|
|
148
155
|
let buildRequestSubRequests = getSubRequests(buildRequestId);
|
149
156
|
|
150
157
|
let writeBundlesRequest = buildRequestSubRequests.find(
|
158
|
+
// @ts-expect-error TS7006
|
151
159
|
(n) => n.type === 1 && n.requestType === 11,
|
152
160
|
);
|
153
161
|
if (writeBundlesRequest != null) {
|
154
162
|
invariant(writeBundlesRequest.type === 1);
|
155
|
-
|
156
|
-
bundleInfo = (nullthrows(writeBundlesRequest.result): Map<
|
163
|
+
bundleInfo = nullthrows(writeBundlesRequest.result) as Map<
|
157
164
|
ContentKey,
|
158
|
-
PackagedBundleInfo
|
159
|
-
|
165
|
+
PackagedBundleInfo
|
166
|
+
>;
|
160
167
|
}
|
161
|
-
} catch (e) {
|
168
|
+
} catch (e: any) {
|
162
169
|
console.error('Error loading bundleInfo\n', e);
|
163
170
|
}
|
164
171
|
|
package/tsconfig.json
ADDED