@atlaspack/bundler-default 3.2.0 → 3.2.1-typescript-5ad950d33.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 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.
@@ -0,0 +1,18 @@
1
+ import { Bundler } from '@atlaspack/plugin';
2
+ /**
3
+ *
4
+ * The Bundler works by creating an IdealGraph, which contains a BundleGraph that models bundles
5
+ * connected to other bundles by what references them, and thus models BundleGroups.
6
+ *
7
+ * First, we enter `bundle({bundleGraph, config})`. Here, "bundleGraph" is actually just the
8
+ * assetGraph turned into a type `MutableBundleGraph`, which will then be mutated in decorate,
9
+ * and turned into what we expect the bundleGraph to be as per the old (default) bundler structure
10
+ * & what the rest of Atlaspack expects a BundleGraph to be.
11
+ *
12
+ * `bundle({bundleGraph, config})` First gets a Mapping of target to entries, In most cases there is
13
+ * only one target, and one or more entries. (Targets are pertinent in monorepos or projects where you
14
+ * will have two or more distDirs, or output folders.) Then calls create IdealGraph and Decorate per target.
15
+ *
16
+ */
17
+ declare const _default: Bundler<unknown>;
18
+ export default _default;
@@ -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(node, context, actions) {
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
  }
@@ -0,0 +1,2 @@
1
+ import type { Asset, Dependency, MutableBundleGraph } from '@atlaspack/types';
2
+ export declare function addJSMonolithBundle(bundleGraph: MutableBundleGraph, entryAsset: Asset, entryDep: Dependency): void;
@@ -0,0 +1,9 @@
1
+ import type { NodeId } from '@atlaspack/graph';
2
+ import type { IdealBundleGraph } from './idealGraph';
3
+ export type MergeGroup = {
4
+ overlapThreshold?: number;
5
+ maxBundleSize?: number;
6
+ sourceBundles?: Array<NodeId>;
7
+ minBundlesInGroup?: number;
8
+ };
9
+ export declare function findMergeCandidates(bundleGraph: IdealBundleGraph, bundles: Array<NodeId>, config: Array<MergeGroup>): Array<Array<NodeId>>;
@@ -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
- if (
122
- // $FlowFixMe both bundles will always have internalizedAssets
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
  }
@@ -0,0 +1,27 @@
1
+ import type { Config, PluginOptions, PluginLogger } from '@atlaspack/types';
2
+ type Glob = string;
3
+ type ManualSharedBundles = Array<{
4
+ name: string;
5
+ assets: Array<Glob>;
6
+ types?: Array<string>;
7
+ root?: string;
8
+ split?: number;
9
+ }>;
10
+ export type MergeCandidates = Array<{
11
+ overlapThreshold?: number;
12
+ maxBundleSize?: number;
13
+ sourceBundles?: Array<string>;
14
+ minBundlesInGroup?: number;
15
+ }>;
16
+ export type ResolvedBundlerConfig = {
17
+ minBundles: number;
18
+ minBundleSize: number;
19
+ maxParallelRequests: number;
20
+ projectRoot: string;
21
+ disableSharedBundles: boolean;
22
+ manualSharedBundles: ManualSharedBundles;
23
+ loadConditionalBundlesInParallel?: boolean;
24
+ sharedBundleMerge?: MergeCandidates;
25
+ };
26
+ export declare function loadBundlerConfig(config: Config, options: PluginOptions, logger: PluginLogger): Promise<ResolvedBundlerConfig>;
27
+ export {};
@@ -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,
@@ -0,0 +1,3 @@
1
+ import type { MutableBundleGraph } from '@atlaspack/types';
2
+ import type { IdealGraph } from './idealGraph';
3
+ export declare function decorateLegacyGraph(idealGraph: IdealGraph, bundleGraph: MutableBundleGraph): void;
@@ -179,6 +179,8 @@ function decorateLegacyGraph(idealGraph, bundleGraph) {
179
179
  bundleGraph.createAssetReference(dependency, asset, legacyBundle);
180
180
  }
181
181
  }
182
+
183
+ // @ts-expect-error TS2488
182
184
  for (let {
183
185
  type,
184
186
  from,
@@ -188,12 +190,14 @@ function decorateLegacyGraph(idealGraph, bundleGraph) {
188
190
  if (sourceBundle === 'root') {
189
191
  continue;
190
192
  }
193
+ // @ts-expect-error TS2367
191
194
  (0, _assert().default)(sourceBundle !== 'root');
192
195
  let legacySourceBundle = (0, _nullthrows().default)(idealBundleToLegacyBundle.get(sourceBundle));
193
196
  let targetBundle = (0, _nullthrows().default)(idealBundleGraph.getNode(to));
194
197
  if (targetBundle === 'root') {
195
198
  continue;
196
199
  }
200
+ // @ts-expect-error TS2367
197
201
  (0, _assert().default)(targetBundle !== 'root');
198
202
  let legacyTargetBundle = (0, _nullthrows().default)(idealBundleToLegacyBundle.get(targetBundle));
199
203
  if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi') && type === _idealGraph.idealBundleGraphEdges.conditional) {
@@ -0,0 +1,40 @@
1
+ import { BitSet, ContentGraph, Graph, NodeId } from '@atlaspack/graph';
2
+ import type { Asset, BundleBehavior, Dependency, Environment, MutableBundleGraph, Target, PluginLogger } from '@atlaspack/types';
3
+ import { DefaultMap } from '@atlaspack/utils';
4
+ import type { ResolvedBundlerConfig } from './bundlerConfig';
5
+ export type Bundle = {
6
+ uniqueKey: string | null | undefined;
7
+ assets: Set<Asset>;
8
+ internalizedAssets?: BitSet;
9
+ bundleBehavior?: BundleBehavior | null | undefined;
10
+ needsStableName: boolean;
11
+ mainEntryAsset: Asset | null | undefined;
12
+ bundleRoots: Set<Asset>;
13
+ size: number;
14
+ sourceBundles: Set<NodeId>;
15
+ target: Target;
16
+ env: Environment;
17
+ type: string;
18
+ manualSharedBundle: string | null | undefined;
19
+ };
20
+ export type DependencyBundleGraph = ContentGraph<{
21
+ value: Bundle;
22
+ type: 'bundle';
23
+ } | {
24
+ value: Dependency;
25
+ type: 'dependency';
26
+ }, number>;
27
+ export declare const idealBundleGraphEdges: Readonly<{
28
+ default: 1;
29
+ conditional: 2;
30
+ }>;
31
+ export type IdealBundleGraph = Graph<Bundle | 'root', (typeof idealBundleGraphEdges)[keyof typeof idealBundleGraphEdges]>;
32
+ export type IdealGraph = {
33
+ assetReference: DefaultMap<Asset, Array<[Dependency, Bundle]>>;
34
+ assets: Array<Asset>;
35
+ bundleGraph: IdealBundleGraph;
36
+ bundleGroupBundleIds: Set<NodeId>;
37
+ dependencyBundleGraph: DependencyBundleGraph;
38
+ manualAssetToBundle: Map<Asset, NodeId>;
39
+ };
40
+ export declare function createIdealGraph(assetGraph: MutableBundleGraph, config: ResolvedBundlerConfig, entries: Map<Asset, Dependency>, logger: PluginLogger): IdealGraph;
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,
@@ -126,6 +127,7 @@ function createIdealGraph(assetGraph, config, entries, logger) {
126
127
  let parentsToConfig = new (_utils().DefaultMap)(() => []);
127
128
  for (let c of config.manualSharedBundles) {
128
129
  if (c.root != null) {
130
+ // @ts-expect-error TS2345
129
131
  parentsToConfig.get(_path().default.join(config.projectRoot, c.root)).push(c);
130
132
  }
131
133
  }
@@ -162,6 +164,7 @@ function createIdealGraph(assetGraph, config, entries, logger) {
162
164
  // We track all matching MSB's for constant modules as they are never duplicated
163
165
  // and need to be assigned to all matching bundles
164
166
  if (node.value.meta.isConstantModule === true) {
167
+ // @ts-expect-error TS2345
165
168
  constantModuleToMSB.get(node.value).push(c);
166
169
  }
167
170
  if (assetRegexes.some(regex => regex.test(projectRelativePath))) {
@@ -202,7 +205,9 @@ function createIdealGraph(assetGraph, config, entries, logger) {
202
205
  * adding only that asset to each bundle, not its entire subgraph.
203
206
  */
204
207
  assetGraph.traverse({
205
- enter(node, context, actions) {
208
+ enter(node, context,
209
+ // @ts-expect-error TS2304
210
+ actions) {
206
211
  if (node.type === 'asset') {
207
212
  if ((context === null || context === void 0 ? void 0 : context.type) === 'dependency' && context !== null && context !== void 0 && context.value.isEntry && !entries.has(node.value)) {
208
213
  // Skip whole subtrees of other targets by skipping those entries
@@ -287,7 +292,9 @@ function createIdealGraph(assetGraph, config, entries, logger) {
287
292
  }), dependencyBundleGraph.addNodeByContentKeyIfNeeded(String(bundleId), {
288
293
  value: bundle,
289
294
  type: 'bundle'
290
- }), dependencyPriorityEdges[dependency.priority]);
295
+ }),
296
+ // @ts-expect-error TS7053
297
+ dependencyPriorityEdges[dependency.priority]);
291
298
  if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi') && dependency.priority === 'conditional') {
292
299
  let [referencingBundleRoot, bundleGroupNodeId] = (0, _nullthrows().default)(stack[stack.length - 1]);
293
300
  let referencingBundleId = (0, _nullthrows().default)(bundleRoots.get(referencingBundleRoot))[0];
@@ -347,13 +354,16 @@ function createIdealGraph(assetGraph, config, entries, logger) {
347
354
  }
348
355
  assetReference.get(childAsset).push([dependency, bundle]);
349
356
  } else {
357
+ // @ts-expect-error TS2322
350
358
  bundleId = null;
351
359
  }
352
360
  if (manualSharedObject && bundleId != null) {
353
361
  // MSB Step 5: At this point we've either created or found an existing MSB bundle
354
362
  // add the asset if it doesn't already have it and set key
355
363
 
356
- (0, _assert().default)(bundle !== 'root' && bundle != null && bundleId != null);
364
+ (0, _assert().default)(
365
+ // @ts-expect-error TS2367
366
+ bundle !== 'root' && bundle != null && bundleId != null);
357
367
  manualAssetToBundle.set(childAsset, bundleId);
358
368
  if (!bundle.assets.has(childAsset)) {
359
369
  // Add asset to bundle
@@ -374,6 +384,7 @@ function createIdealGraph(assetGraph, config, entries, logger) {
374
384
  }
375
385
  return node;
376
386
  },
387
+ // @ts-expect-error TS2322
377
388
  exit(node) {
378
389
  var _stack;
379
390
  if (((_stack = stack[stack.length - 1]) === null || _stack === void 0 ? void 0 : _stack[0]) === node.value) {
@@ -602,8 +613,11 @@ function createIdealGraph(assetGraph, config, entries, logger) {
602
613
  }
603
614
  function assignInlineConstants(parentAsset, bundle) {
604
615
  for (let inlineConstant of inlineConstantDeps.get(parentAsset)) {
616
+ // @ts-expect-error TS2345
605
617
  if (!bundle.assets.has(inlineConstant)) {
618
+ // @ts-expect-error TS2345
606
619
  bundle.assets.add(inlineConstant);
620
+ // @ts-expect-error TS18046
607
621
  bundle.size += inlineConstant.stats.size;
608
622
  }
609
623
  }
@@ -819,8 +833,9 @@ function createIdealGraph(assetGraph, config, entries, logger) {
819
833
  if (modNum != null) {
820
834
  for (let a of [...manualBundle.assets]) {
821
835
  let numRep = getBigIntFromContentKey(a.id);
822
- // $FlowFixMe Flow doesn't know about BigInt
823
836
  let r = Number(numRep % BigInt(modNum));
837
+
838
+ // @ts-expect-error TS2345
824
839
  remainderMap.get(r).push(a);
825
840
  }
826
841
  for (let i = 1; i < [...remainderMap.keys()].length; i++) {
@@ -842,8 +857,10 @@ function createIdealGraph(assetGraph, config, entries, logger) {
842
857
  }
843
858
  for (let sp of remainderMap.get(i)) {
844
859
  bundle.assets.add(sp);
860
+ // @ts-expect-error TS2339
845
861
  bundle.size += sp.stats.size;
846
862
  manualBundle.assets.delete(sp);
863
+ // @ts-expect-error TS2339
847
864
  manualBundle.size -= sp.stats.size;
848
865
  }
849
866
  }
@@ -856,12 +873,17 @@ function createIdealGraph(assetGraph, config, entries, logger) {
856
873
  // match multiple MSB's
857
874
  for (let [asset, msbs] of constantModuleToMSB.entries()) {
858
875
  for (let manualSharedObject of msbs) {
876
+ // @ts-expect-error TS2339
859
877
  let bundleId = manualSharedMap.get(manualSharedObject.name + ',js');
860
878
  if (bundleId == null) continue;
861
879
  let bundle = (0, _nullthrows().default)(bundleGraph.getNode(bundleId));
862
880
  (0, _assert().default)(bundle != null && bundle !== 'root', 'We tried to use the root incorrectly');
881
+
882
+ // @ts-expect-error TS2345
863
883
  if (!bundle.assets.has(asset)) {
884
+ // @ts-expect-error TS2345
864
885
  bundle.assets.add(asset);
886
+ // @ts-expect-error TS18046
865
887
  bundle.size += asset.stats.size;
866
888
  }
867
889
  }
@@ -912,6 +934,7 @@ function createIdealGraph(assetGraph, config, entries, logger) {
912
934
  // Merge all bundles with the same chunk name into the first one.
913
935
  let [firstBundleId, ...rest] = Array.from(bundleIds);
914
936
  for (let bundleId of rest) {
937
+ // @ts-expect-error TS2345
915
938
  mergeBundles(firstBundleId, bundleId);
916
939
  }
917
940
  }
@@ -947,6 +970,7 @@ function createIdealGraph(assetGraph, config, entries, logger) {
947
970
  let numBundlesContributingToPRL = bundleIdsInGroup.reduce((count, b) => {
948
971
  let bundle = (0, _nullthrows().default)(bundleGraph.getNode(b));
949
972
  (0, _assert().default)(bundle !== 'root');
973
+ // @ts-expect-error TS2365
950
974
  return count + (bundle.bundleBehavior !== 'inline');
951
975
  }, 0);
952
976
  if (numBundlesContributingToPRL > config.maxParallelRequests) {
@@ -976,7 +1000,9 @@ function createIdealGraph(assetGraph, config, entries, logger) {
976
1000
  // Remove bundles until the bundle group is within the parallel request limit.
977
1001
  while (sharedBundlesInGroup.length > 0 && numBundlesContributingToPRL > config.maxParallelRequests) {
978
1002
  let bundleTuple = sharedBundlesInGroup.pop();
1003
+ // @ts-expect-error TS18048
979
1004
  let bundleToRemove = bundleTuple.bundle;
1005
+ // @ts-expect-error TS18048
980
1006
  let bundleIdToRemove = bundleTuple.id;
981
1007
  //TODO add integration test where bundles in bunlde group > max parallel request limit & only remove a couple shared bundles
982
1008
  // but total # bundles still exceeds limit due to non shared bundles
@@ -1027,6 +1053,8 @@ function createIdealGraph(assetGraph, config, entries, logger) {
1027
1053
  bundleToKeep.assets.add(asset);
1028
1054
  bundleToKeep.size += asset.stats.size;
1029
1055
  let newAssetReference = assetReference.get(asset).map(([dep, bundle]) => bundle === bundleToRemove ? [dep, bundleToKeep] : [dep, bundle]);
1056
+
1057
+ // @ts-expect-error TS2345
1030
1058
  assetReference.set(asset, newAssetReference);
1031
1059
  }
1032
1060
 
@@ -1161,7 +1189,6 @@ function createIdealGraph(assetGraph, config, entries, logger) {
1161
1189
  function getBigIntFromContentKey(contentKey) {
1162
1190
  let b = Buffer.alloc(64);
1163
1191
  b.write(contentKey);
1164
- // $FlowFixMe Flow doesn't have BigInt types in this version
1165
1192
  return b.readBigInt64BE();
1166
1193
  }
1167
1194
  // Fix asset order in source bundles as they are likely now incorrect after shared bundle deletion
@@ -0,0 +1,2 @@
1
+ export declare function clearCaches(): void;
2
+ export declare function memoize<Args extends Array<unknown>, Return>(fn: (...args: Args) => Return): (...args: Args) => Return;
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.2.0",
3
+ "version": "3.2.1-typescript-5ad950d33.0",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "type": "commonjs",
6
6
  "publishConfig": {
@@ -10,19 +10,24 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/atlassian-labs/atlaspack.git"
12
12
  },
13
- "main": "lib/DefaultBundler.js",
14
- "source": "src/DefaultBundler.js",
13
+ "main": "./lib/DefaultBundler.js",
14
+ "source": "./src/DefaultBundler.ts",
15
+ "types": "./lib/DefaultBundler.d.ts",
15
16
  "engines": {
16
17
  "node": ">= 16.0.0"
17
18
  },
18
19
  "dependencies": {
19
- "@atlaspack/diagnostic": "2.14.1",
20
- "@atlaspack/feature-flags": "2.20.0",
21
- "@atlaspack/graph": "3.5.10",
22
- "@atlaspack/plugin": "2.14.21",
23
- "@atlaspack/rust": "3.4.1",
24
- "@atlaspack/utils": "2.17.3",
25
- "nullthrows": "^1.1.1",
26
- "many-keys-map": "^1.0.3"
27
- }
28
- }
20
+ "@atlaspack/diagnostic": "2.14.2-typescript-5ad950d33.0",
21
+ "@atlaspack/feature-flags": "2.20.1-typescript-5ad950d33.0",
22
+ "@atlaspack/graph": "3.5.11-typescript-5ad950d33.0",
23
+ "@atlaspack/plugin": "2.14.22-typescript-5ad950d33.0",
24
+ "@atlaspack/rust": "3.4.2-typescript-5ad950d33.0",
25
+ "@atlaspack/utils": "2.17.4-typescript-5ad950d33.0",
26
+ "many-keys-map": "^1.0.3",
27
+ "nullthrows": "^1.1.1"
28
+ },
29
+ "scripts": {
30
+ "check-ts": "tsc --emitDeclarationOnly --rootDir src"
31
+ },
32
+ "gitHead": "5ad950d33a5f2255ebeb10c04a2e84c346e2de85"
33
+ }