@atlaspack/bundler-default 3.1.2 → 3.1.3-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/DefaultBundler.js +7 -4
- package/lib/bundleMerge.js +4 -3
- package/lib/bundlerConfig.js +3 -2
- package/lib/decorateLegacyGraph.js +4 -0
- package/lib/idealGraph.js +35 -6
- package/lib/memoize.js +1 -2
- package/package.json +16 -11
- package/src/{DefaultBundler.js → DefaultBundler.ts} +21 -7
- package/src/{MonolithicBundler.js → MonolithicBundler.ts} +0 -1
- package/src/{bundleMerge.js → bundleMerge.ts} +16 -19
- package/src/{bundlerConfig.js → bundlerConfig.ts} +43 -44
- package/src/{decorateLegacyGraph.js → decorateLegacyGraph.ts} +4 -3
- package/src/{idealGraph.js → idealGraph.ts} +120 -79
- package/src/{memoize.js → memoize.ts} +3 -6
- 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/DefaultBundler.js
CHANGED
|
@@ -59,6 +59,7 @@ var _default = exports.default = new (_plugin().Bundler)({
|
|
|
59
59
|
logger
|
|
60
60
|
}) {
|
|
61
61
|
let targetMap = getEntryByTarget(bundleGraph); // Organize entries by target output folder/ distDir
|
|
62
|
+
// @ts-expect-error TS2304
|
|
62
63
|
let graphs = [];
|
|
63
64
|
for (let entries of targetMap.values()) {
|
|
64
65
|
let singleFileEntries = new Map();
|
|
@@ -75,9 +76,7 @@ var _default = exports.default = new (_plugin().Bundler)({
|
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
// Create separate bundleGraphs per distDir
|
|
78
|
-
graphs.push(
|
|
79
|
-
// $FlowFixMe
|
|
80
|
-
(0, _idealGraph.createIdealGraph)(bundleGraph, config, idealGraphEntries, logger));
|
|
79
|
+
graphs.push((0, _idealGraph.createIdealGraph)(bundleGraph, config, idealGraphEntries, logger));
|
|
81
80
|
|
|
82
81
|
// Do this after the ideal graph so that the mutation of the bundleGraph doesn't
|
|
83
82
|
// interfere with the main bundling algorithm
|
|
@@ -96,7 +95,11 @@ function getEntryByTarget(bundleGraph) {
|
|
|
96
95
|
// Find entries from assetGraph per target
|
|
97
96
|
let targets = new (_utils().DefaultMap)(() => new Map());
|
|
98
97
|
bundleGraph.traverse({
|
|
99
|
-
enter(
|
|
98
|
+
enter(
|
|
99
|
+
// @ts-expect-error TS2304
|
|
100
|
+
node, context,
|
|
101
|
+
// @ts-expect-error TS2304
|
|
102
|
+
actions) {
|
|
100
103
|
if (node.type !== 'asset') {
|
|
101
104
|
return node;
|
|
102
105
|
}
|
package/lib/bundleMerge.js
CHANGED
|
@@ -38,6 +38,7 @@ function getBundlesForBundleGroup(bundleGraph, bundleGroupId) {
|
|
|
38
38
|
let count = 0;
|
|
39
39
|
bundleGraph.traverse(nodeId => {
|
|
40
40
|
var _bundleGraph$getNode;
|
|
41
|
+
// @ts-expect-error TS2339
|
|
41
42
|
if (((_bundleGraph$getNode = bundleGraph.getNode(nodeId)) === null || _bundleGraph$getNode === void 0 ? void 0 : _bundleGraph$getNode.bundleBehavior) !== 'inline') {
|
|
42
43
|
count++;
|
|
43
44
|
}
|
|
@@ -118,9 +119,9 @@ function getPossibleMergeCandidates(bundleGraph, bundles) {
|
|
|
118
119
|
for (let j = i + 1; j < mergeCandidates.length; j++) {
|
|
119
120
|
let a = mergeCandidates[i];
|
|
120
121
|
let b = mergeCandidates[j];
|
|
121
|
-
|
|
122
|
-
//
|
|
123
|
-
a.bundle.internalizedAssets.equals(b.bundle.internalizedAssets)) {
|
|
122
|
+
|
|
123
|
+
// @ts-expect-error TS18048
|
|
124
|
+
if (a.bundle.internalizedAssets.equals(b.bundle.internalizedAssets)) {
|
|
124
125
|
uniquePairs.push([a, b]);
|
|
125
126
|
}
|
|
126
127
|
}
|
package/lib/bundlerConfig.js
CHANGED
|
@@ -39,14 +39,13 @@ function resolveModeConfig(config, mode) {
|
|
|
39
39
|
for (const key of Object.keys(config)) {
|
|
40
40
|
if (key === 'development' || key === 'production') {
|
|
41
41
|
if (key === mode) {
|
|
42
|
+
// @ts-expect-error TS2322
|
|
42
43
|
modeConfig = config[key];
|
|
43
44
|
}
|
|
44
45
|
} else {
|
|
45
46
|
generalConfig[key] = config[key];
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
|
-
|
|
49
|
-
// $FlowFixMe Not sure how to convince flow here...
|
|
50
49
|
return {
|
|
51
50
|
...generalConfig,
|
|
52
51
|
...modeConfig
|
|
@@ -172,6 +171,7 @@ async function loadBundlerConfig(config, options, logger) {
|
|
|
172
171
|
...HTTP_OPTIONS['2'],
|
|
173
172
|
projectRoot: options.projectRoot
|
|
174
173
|
};
|
|
174
|
+
// @ts-expect-error TS2322
|
|
175
175
|
return modDefault;
|
|
176
176
|
}
|
|
177
177
|
(0, _assert().default)(((_conf = conf) === null || _conf === void 0 ? void 0 : _conf.contents) != null);
|
|
@@ -212,6 +212,7 @@ async function loadBundlerConfig(config, options, logger) {
|
|
|
212
212
|
prependKey: `/${(0, _diagnostic().encodeJSONKeyComponent)('@atlaspack/bundler-default')}`
|
|
213
213
|
}, '@atlaspack/bundler-default', 'Invalid config for @atlaspack/bundler-default');
|
|
214
214
|
let http = modeConfig.http ?? 2;
|
|
215
|
+
// @ts-expect-error TS7053
|
|
215
216
|
let defaults = HTTP_OPTIONS[http];
|
|
216
217
|
return {
|
|
217
218
|
minBundles: modeConfig.minBundles ?? defaults.minBundles,
|
|
@@ -162,6 +162,8 @@ function decorateLegacyGraph(idealGraph, bundleGraph) {
|
|
|
162
162
|
bundleGraph.createAssetReference(dependency, asset, legacyBundle);
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
|
+
|
|
166
|
+
// @ts-expect-error TS2488
|
|
165
167
|
for (let {
|
|
166
168
|
type,
|
|
167
169
|
from,
|
|
@@ -171,12 +173,14 @@ function decorateLegacyGraph(idealGraph, bundleGraph) {
|
|
|
171
173
|
if (sourceBundle === 'root') {
|
|
172
174
|
continue;
|
|
173
175
|
}
|
|
176
|
+
// @ts-expect-error TS2367
|
|
174
177
|
(0, _assert().default)(sourceBundle !== 'root');
|
|
175
178
|
let legacySourceBundle = (0, _nullthrows().default)(idealBundleToLegacyBundle.get(sourceBundle));
|
|
176
179
|
let targetBundle = (0, _nullthrows().default)(idealBundleGraph.getNode(to));
|
|
177
180
|
if (targetBundle === 'root') {
|
|
178
181
|
continue;
|
|
179
182
|
}
|
|
183
|
+
// @ts-expect-error TS2367
|
|
180
184
|
(0, _assert().default)(targetBundle !== 'root');
|
|
181
185
|
let legacyTargetBundle = (0, _nullthrows().default)(idealBundleToLegacyBundle.get(targetBundle));
|
|
182
186
|
if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi') && type === _idealGraph.idealBundleGraphEdges.conditional) {
|
package/lib/idealGraph.js
CHANGED
|
@@ -50,6 +50,7 @@ function _nullthrows() {
|
|
|
50
50
|
var _bundleMerge = require("./bundleMerge");
|
|
51
51
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
52
52
|
/* BundleRoot - An asset that is the main entry of a Bundle. */
|
|
53
|
+
|
|
53
54
|
const dependencyPriorityEdges = {
|
|
54
55
|
sync: 1,
|
|
55
56
|
parallel: 2,
|
|
@@ -121,6 +122,7 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
121
122
|
let parentsToConfig = new (_utils().DefaultMap)(() => []);
|
|
122
123
|
for (let c of config.manualSharedBundles) {
|
|
123
124
|
if (c.root != null) {
|
|
125
|
+
// @ts-expect-error TS2345
|
|
124
126
|
parentsToConfig.get(_path().default.join(config.projectRoot, c.root)).push(c);
|
|
125
127
|
}
|
|
126
128
|
}
|
|
@@ -157,6 +159,7 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
157
159
|
// We track all matching MSB's for constant modules as they are never duplicated
|
|
158
160
|
// and need to be assigned to all matching bundles
|
|
159
161
|
if (node.value.meta.isConstantModule === true) {
|
|
162
|
+
// @ts-expect-error TS2345
|
|
160
163
|
constantModuleToMSB.get(node.value).push(c);
|
|
161
164
|
}
|
|
162
165
|
if (assetRegexes.some(regex => regex.test(projectRelativePath))) {
|
|
@@ -197,7 +200,9 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
197
200
|
* adding only that asset to each bundle, not its entire subgraph.
|
|
198
201
|
*/
|
|
199
202
|
assetGraph.traverse({
|
|
200
|
-
enter(node, context,
|
|
203
|
+
enter(node, context,
|
|
204
|
+
// @ts-expect-error TS2304
|
|
205
|
+
actions) {
|
|
201
206
|
if (node.type === 'asset') {
|
|
202
207
|
if ((context === null || context === void 0 ? void 0 : context.type) === 'dependency' && context !== null && context !== void 0 && context.value.isEntry && !entries.has(node.value)) {
|
|
203
208
|
// Skip whole subtrees of other targets by skipping those entries
|
|
@@ -282,7 +287,9 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
282
287
|
}), dependencyBundleGraph.addNodeByContentKeyIfNeeded(String(bundleId), {
|
|
283
288
|
value: bundle,
|
|
284
289
|
type: 'bundle'
|
|
285
|
-
}),
|
|
290
|
+
}),
|
|
291
|
+
// @ts-expect-error TS7053
|
|
292
|
+
dependencyPriorityEdges[dependency.priority]);
|
|
286
293
|
if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi') && dependency.priority === 'conditional') {
|
|
287
294
|
let [referencingBundleRoot, bundleGroupNodeId] = (0, _nullthrows().default)(stack[stack.length - 1]);
|
|
288
295
|
let referencingBundleId = (0, _nullthrows().default)(bundleRoots.get(referencingBundleRoot))[0];
|
|
@@ -342,13 +349,16 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
342
349
|
}
|
|
343
350
|
assetReference.get(childAsset).push([dependency, bundle]);
|
|
344
351
|
} else {
|
|
352
|
+
// @ts-expect-error TS2322
|
|
345
353
|
bundleId = null;
|
|
346
354
|
}
|
|
347
355
|
if (manualSharedObject && bundleId != null) {
|
|
348
356
|
// MSB Step 5: At this point we've either created or found an existing MSB bundle
|
|
349
357
|
// add the asset if it doesn't already have it and set key
|
|
350
358
|
|
|
351
|
-
(0, _assert().default)(
|
|
359
|
+
(0, _assert().default)(
|
|
360
|
+
// @ts-expect-error TS2367
|
|
361
|
+
bundle !== 'root' && bundle != null && bundleId != null);
|
|
352
362
|
manualAssetToBundle.set(childAsset, bundleId);
|
|
353
363
|
if (!bundle.assets.has(childAsset)) {
|
|
354
364
|
// Add asset to bundle
|
|
@@ -369,6 +379,7 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
369
379
|
}
|
|
370
380
|
return node;
|
|
371
381
|
},
|
|
382
|
+
// @ts-expect-error TS2322
|
|
372
383
|
exit(node) {
|
|
373
384
|
var _stack;
|
|
374
385
|
if (((_stack = stack[stack.length - 1]) === null || _stack === void 0 ? void 0 : _stack[0]) === node.value) {
|
|
@@ -597,8 +608,11 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
597
608
|
}
|
|
598
609
|
function assignInlineConstants(parentAsset, bundle) {
|
|
599
610
|
for (let inlineConstant of inlineConstantDeps.get(parentAsset)) {
|
|
611
|
+
// @ts-expect-error TS2345
|
|
600
612
|
if (!bundle.assets.has(inlineConstant)) {
|
|
613
|
+
// @ts-expect-error TS2345
|
|
601
614
|
bundle.assets.add(inlineConstant);
|
|
615
|
+
// @ts-expect-error TS18046
|
|
602
616
|
bundle.size += inlineConstant.stats.size;
|
|
603
617
|
}
|
|
604
618
|
}
|
|
@@ -812,8 +826,9 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
812
826
|
if (modNum != null) {
|
|
813
827
|
for (let a of [...manualBundle.assets]) {
|
|
814
828
|
let numRep = getBigIntFromContentKey(a.id);
|
|
815
|
-
// $FlowFixMe Flow doesn't know about BigInt
|
|
816
829
|
let r = Number(numRep % BigInt(modNum));
|
|
830
|
+
|
|
831
|
+
// @ts-expect-error TS2345
|
|
817
832
|
remainderMap.get(r).push(a);
|
|
818
833
|
}
|
|
819
834
|
for (let i = 1; i < [...remainderMap.keys()].length; i++) {
|
|
@@ -835,8 +850,10 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
835
850
|
}
|
|
836
851
|
for (let sp of remainderMap.get(i)) {
|
|
837
852
|
bundle.assets.add(sp);
|
|
853
|
+
// @ts-expect-error TS2339
|
|
838
854
|
bundle.size += sp.stats.size;
|
|
839
855
|
manualBundle.assets.delete(sp);
|
|
856
|
+
// @ts-expect-error TS2339
|
|
840
857
|
manualBundle.size -= sp.stats.size;
|
|
841
858
|
}
|
|
842
859
|
}
|
|
@@ -849,12 +866,17 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
849
866
|
// match multiple MSB's
|
|
850
867
|
for (let [asset, msbs] of constantModuleToMSB.entries()) {
|
|
851
868
|
for (let manualSharedObject of msbs) {
|
|
869
|
+
// @ts-expect-error TS2339
|
|
852
870
|
let bundleId = manualSharedMap.get(manualSharedObject.name + ',js');
|
|
853
871
|
if (bundleId == null) continue;
|
|
854
872
|
let bundle = (0, _nullthrows().default)(bundleGraph.getNode(bundleId));
|
|
855
873
|
(0, _assert().default)(bundle != null && bundle !== 'root', 'We tried to use the root incorrectly');
|
|
874
|
+
|
|
875
|
+
// @ts-expect-error TS2345
|
|
856
876
|
if (!bundle.assets.has(asset)) {
|
|
877
|
+
// @ts-expect-error TS2345
|
|
857
878
|
bundle.assets.add(asset);
|
|
879
|
+
// @ts-expect-error TS18046
|
|
858
880
|
bundle.size += asset.stats.size;
|
|
859
881
|
}
|
|
860
882
|
}
|
|
@@ -890,6 +912,7 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
890
912
|
let numBundlesContributingToPRL = bundleIdsInGroup.reduce((count, b) => {
|
|
891
913
|
let bundle = (0, _nullthrows().default)(bundleGraph.getNode(b));
|
|
892
914
|
(0, _assert().default)(bundle !== 'root');
|
|
915
|
+
// @ts-expect-error TS2365
|
|
893
916
|
return count + (bundle.bundleBehavior !== 'inline');
|
|
894
917
|
}, 0);
|
|
895
918
|
if (numBundlesContributingToPRL > config.maxParallelRequests) {
|
|
@@ -919,7 +942,9 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
919
942
|
// Remove bundles until the bundle group is within the parallel request limit.
|
|
920
943
|
while (sharedBundlesInGroup.length > 0 && numBundlesContributingToPRL > config.maxParallelRequests) {
|
|
921
944
|
let bundleTuple = sharedBundlesInGroup.pop();
|
|
945
|
+
// @ts-expect-error TS18048
|
|
922
946
|
let bundleToRemove = bundleTuple.bundle;
|
|
947
|
+
// @ts-expect-error TS18048
|
|
923
948
|
let bundleIdToRemove = bundleTuple.id;
|
|
924
949
|
//TODO add integration test where bundles in bunlde group > max parallel request limit & only remove a couple shared bundles
|
|
925
950
|
// but total # bundles still exceeds limit due to non shared bundles
|
|
@@ -970,6 +995,8 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
970
995
|
bundleToKeep.assets.add(asset);
|
|
971
996
|
bundleToKeep.size += asset.stats.size;
|
|
972
997
|
let newAssetReference = assetReference.get(asset).map(([dep, bundle]) => bundle === bundleToRemove ? [dep, bundleToKeep] : [dep, bundle]);
|
|
998
|
+
|
|
999
|
+
// @ts-expect-error TS2345
|
|
973
1000
|
assetReference.set(asset, newAssetReference);
|
|
974
1001
|
}
|
|
975
1002
|
|
|
@@ -1027,14 +1054,16 @@ function createIdealGraph(assetGraph, config, entries, logger) {
|
|
|
1027
1054
|
function getBigIntFromContentKey(contentKey) {
|
|
1028
1055
|
let b = Buffer.alloc(64);
|
|
1029
1056
|
b.write(contentKey);
|
|
1030
|
-
// $FlowFixMe Flow doesn't have BigInt types in this version
|
|
1031
1057
|
return b.readBigInt64BE();
|
|
1032
1058
|
}
|
|
1033
1059
|
// Fix asset order in source bundles as they are likely now incorrect after shared bundle deletion
|
|
1034
1060
|
if (modifiedSourceBundles.size > 0) {
|
|
1035
1061
|
let assetOrderMap = new Map(assets.map((a, index) => [a, index]));
|
|
1036
1062
|
for (let bundle of modifiedSourceBundles) {
|
|
1037
|
-
|
|
1063
|
+
// @ts-expect-error TS18046
|
|
1064
|
+
bundle.assets = new Set(
|
|
1065
|
+
// @ts-expect-error TS18046
|
|
1066
|
+
[...bundle.assets].sort((a, b) => {
|
|
1038
1067
|
let aIndex = (0, _nullthrows().default)(assetOrderMap.get(a));
|
|
1039
1068
|
let bIndex = (0, _nullthrows().default)(assetOrderMap.get(b));
|
|
1040
1069
|
return aIndex - bIndex;
|
package/lib/memoize.js
CHANGED
|
@@ -13,7 +13,6 @@ function _manyKeysMap() {
|
|
|
13
13
|
return data;
|
|
14
14
|
}
|
|
15
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
// $FlowFixMe
|
|
17
16
|
let caches = [];
|
|
18
17
|
function clearCaches() {
|
|
19
18
|
for (let cache of caches) {
|
|
@@ -32,8 +31,8 @@ function memoize(fn) {
|
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
// Calculate the result and cache it
|
|
34
|
+
// @ts-expect-error TS2683
|
|
35
35
|
const result = fn.apply(this, args);
|
|
36
|
-
// $FlowFixMe
|
|
37
36
|
cache.set(args, result);
|
|
38
37
|
return result;
|
|
39
38
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/bundler-default",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.3-typescript-80839fbd5.0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"publishConfig": {
|
|
@@ -11,18 +11,23 @@
|
|
|
11
11
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
12
12
|
},
|
|
13
13
|
"main": "lib/DefaultBundler.js",
|
|
14
|
-
"source": "src/DefaultBundler.
|
|
14
|
+
"source": "src/DefaultBundler.ts",
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">= 16.0.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@atlaspack/diagnostic": "2.14.
|
|
20
|
-
"@atlaspack/feature-flags": "2.19.
|
|
21
|
-
"@atlaspack/graph": "3.5.
|
|
22
|
-
"@atlaspack/plugin": "2.14.
|
|
23
|
-
"@atlaspack/rust": "3.4.
|
|
24
|
-
"@atlaspack/utils": "2.17.
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
}
|
|
19
|
+
"@atlaspack/diagnostic": "2.14.2-typescript-80839fbd5.0",
|
|
20
|
+
"@atlaspack/feature-flags": "2.19.3-typescript-80839fbd5.0",
|
|
21
|
+
"@atlaspack/graph": "3.5.10-typescript-80839fbd5.0",
|
|
22
|
+
"@atlaspack/plugin": "2.14.21-typescript-80839fbd5.0",
|
|
23
|
+
"@atlaspack/rust": "3.4.2-typescript-80839fbd5.0",
|
|
24
|
+
"@atlaspack/utils": "2.17.3-typescript-80839fbd5.0",
|
|
25
|
+
"many-keys-map": "^1.0.3",
|
|
26
|
+
"nullthrows": "^1.1.1"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"check-ts": "tsc --noEmit"
|
|
30
|
+
},
|
|
31
|
+
"types": "src/DefaultBundler.ts",
|
|
32
|
+
"gitHead": "80839fbd5c6d6668c2622849856a4b25601354a8"
|
|
28
33
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import {Bundler} from '@atlaspack/plugin';
|
|
4
2
|
import type {Asset, Dependency, MutableBundleGraph} from '@atlaspack/types';
|
|
5
3
|
import {DefaultMap} from '@atlaspack/utils';
|
|
@@ -25,14 +23,15 @@ import {addJSMonolithBundle} from './MonolithicBundler';
|
|
|
25
23
|
* will have two or more distDirs, or output folders.) Then calls create IdealGraph and Decorate per target.
|
|
26
24
|
*
|
|
27
25
|
*/
|
|
28
|
-
export default
|
|
26
|
+
export default new Bundler({
|
|
29
27
|
loadConfig({config, options, logger}) {
|
|
30
28
|
return loadBundlerConfig(config, options, logger);
|
|
31
29
|
},
|
|
32
30
|
|
|
33
31
|
bundle({bundleGraph, config, logger}) {
|
|
34
32
|
let targetMap = getEntryByTarget(bundleGraph); // Organize entries by target output folder/ distDir
|
|
35
|
-
|
|
33
|
+
// @ts-expect-error TS2304
|
|
34
|
+
let graphs: Array<IdealGraph> = [];
|
|
36
35
|
|
|
37
36
|
for (let entries of targetMap.values()) {
|
|
38
37
|
let singleFileEntries = new Map();
|
|
@@ -49,7 +48,6 @@ export default (new Bundler({
|
|
|
49
48
|
|
|
50
49
|
// Create separate bundleGraphs per distDir
|
|
51
50
|
graphs.push(
|
|
52
|
-
// $FlowFixMe
|
|
53
51
|
createIdealGraph(bundleGraph, config, idealGraphEntries, logger),
|
|
54
52
|
);
|
|
55
53
|
|
|
@@ -65,7 +63,7 @@ export default (new Bundler({
|
|
|
65
63
|
}
|
|
66
64
|
},
|
|
67
65
|
optimize() {},
|
|
68
|
-
})
|
|
66
|
+
}) as Bundler<unknown>;
|
|
69
67
|
|
|
70
68
|
function getEntryByTarget(
|
|
71
69
|
bundleGraph: MutableBundleGraph,
|
|
@@ -75,7 +73,23 @@ function getEntryByTarget(
|
|
|
75
73
|
() => new Map(),
|
|
76
74
|
);
|
|
77
75
|
bundleGraph.traverse({
|
|
78
|
-
enter(
|
|
76
|
+
enter(
|
|
77
|
+
// @ts-expect-error TS2304
|
|
78
|
+
node: BundleGraphTraversable,
|
|
79
|
+
context:
|
|
80
|
+
| {
|
|
81
|
+
readonly type: 'asset';
|
|
82
|
+
value: Asset;
|
|
83
|
+
}
|
|
84
|
+
| null
|
|
85
|
+
| undefined
|
|
86
|
+
| {
|
|
87
|
+
readonly type: 'dependency';
|
|
88
|
+
value: Dependency;
|
|
89
|
+
},
|
|
90
|
+
// @ts-expect-error TS2304
|
|
91
|
+
actions: TraversalActions,
|
|
92
|
+
) {
|
|
79
93
|
if (node.type !== 'asset') {
|
|
80
94
|
return node;
|
|
81
95
|
}
|