@atlaspack/bundler-default 3.1.2 → 3.1.3-typescript-08dcc1c9b.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.
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import invariant from 'assert';
4
2
  import nullthrows from 'nullthrows';
5
3
  import {ContentGraph} from '@atlaspack/graph';
@@ -14,6 +12,7 @@ function getBundlesForBundleGroup(
14
12
  ): number {
15
13
  let count = 0;
16
14
  bundleGraph.traverse((nodeId) => {
15
+ // @ts-expect-error TS2339
17
16
  if (bundleGraph.getNode(nodeId)?.bundleBehavior !== 'inline') {
18
17
  count++;
19
18
  }
@@ -125,7 +124,7 @@ function getMergeClusters(
125
124
  graph: ContentGraph<NodeId, EdgeType>,
126
125
  candidates: Map<NodeId, EdgeType>,
127
126
  ): Array<Array<NodeId>> {
128
- let clusters = [];
127
+ let clusters: Array<Array<NodeId>> = [];
129
128
 
130
129
  for (let [candidate, edgeType] of candidates.entries()) {
131
130
  let cluster: Array<NodeId> = [];
@@ -145,11 +144,11 @@ function getMergeClusters(
145
144
  return clusters;
146
145
  }
147
146
 
148
- type MergeCandidate = {|
149
- bundle: Bundle,
150
- id: NodeId,
151
- contentKey: string,
152
- |};
147
+ type MergeCandidate = {
148
+ bundle: Bundle;
149
+ id: NodeId;
150
+ contentKey: string;
151
+ };
153
152
  function getPossibleMergeCandidates(
154
153
  bundleGraph: IdealBundleGraph,
155
154
  bundles: Array<NodeId>,
@@ -165,17 +164,15 @@ function getPossibleMergeCandidates(
165
164
  };
166
165
  });
167
166
 
168
- const uniquePairs = [];
167
+ const uniquePairs: Array<[MergeCandidate, MergeCandidate]> = [];
169
168
 
170
169
  for (let i = 0; i < mergeCandidates.length; i++) {
171
170
  for (let j = i + 1; j < mergeCandidates.length; j++) {
172
171
  let a = mergeCandidates[i];
173
172
  let b = mergeCandidates[j];
174
173
 
175
- if (
176
- // $FlowFixMe both bundles will always have internalizedAssets
177
- a.bundle.internalizedAssets.equals(b.bundle.internalizedAssets)
178
- ) {
174
+ // @ts-expect-error TS18048
175
+ if (a.bundle.internalizedAssets.equals(b.bundle.internalizedAssets)) {
179
176
  uniquePairs.push([a, b]);
180
177
  }
181
178
  }
@@ -183,12 +180,12 @@ function getPossibleMergeCandidates(
183
180
  return uniquePairs;
184
181
  }
185
182
 
186
- export type MergeGroup = {|
187
- overlapThreshold?: number,
188
- maxBundleSize?: number,
189
- sourceBundles?: Array<NodeId>,
190
- minBundlesInGroup?: number,
191
- |};
183
+ export type MergeGroup = {
184
+ overlapThreshold?: number;
185
+ maxBundleSize?: number;
186
+ sourceBundles?: Array<NodeId>;
187
+ minBundlesInGroup?: number;
188
+ };
192
189
  type EdgeType = number;
193
190
 
194
191
  export function findMergeCandidates(
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import {encodeJSONKeyComponent} from '@atlaspack/diagnostic';
4
2
  import type {
5
3
  Config,
@@ -8,62 +6,62 @@ import type {
8
6
  PluginLogger,
9
7
  } from '@atlaspack/types';
10
8
  import {getFeatureFlag} from '@atlaspack/feature-flags';
11
- import {type SchemaEntity, validateSchema} from '@atlaspack/utils';
9
+ import {SchemaEntity, validateSchema} from '@atlaspack/utils';
12
10
  import invariant from 'assert';
13
11
 
14
12
  type Glob = string;
15
13
 
16
- type ManualSharedBundles = Array<{|
17
- name: string,
18
- assets: Array<Glob>,
19
- types?: Array<string>,
20
- root?: string,
21
- split?: number,
22
- |}>;
14
+ type ManualSharedBundles = Array<{
15
+ name: string;
16
+ assets: Array<Glob>;
17
+ types?: Array<string>;
18
+ root?: string;
19
+ split?: number;
20
+ }>;
23
21
 
24
- export type MergeCandidates = Array<{|
25
- overlapThreshold?: number,
26
- maxBundleSize?: number,
27
- sourceBundles?: Array<string>,
28
- minBundlesInGroup?: number,
29
- |}>;
22
+ export type MergeCandidates = Array<{
23
+ overlapThreshold?: number;
24
+ maxBundleSize?: number;
25
+ sourceBundles?: Array<string>;
26
+ minBundlesInGroup?: number;
27
+ }>;
30
28
 
31
- type BaseBundlerConfig = {|
32
- http?: number,
33
- minBundles?: number,
34
- minBundleSize?: number,
35
- maxParallelRequests?: number,
36
- disableSharedBundles?: boolean,
37
- manualSharedBundles?: ManualSharedBundles,
38
- loadConditionalBundlesInParallel?: boolean,
39
- sharedBundleMerge?: MergeCandidates,
40
- |};
29
+ type BaseBundlerConfig = {
30
+ http?: number;
31
+ minBundles?: number;
32
+ minBundleSize?: number;
33
+ maxParallelRequests?: number;
34
+ disableSharedBundles?: boolean;
35
+ manualSharedBundles?: ManualSharedBundles;
36
+ loadConditionalBundlesInParallel?: boolean;
37
+ sharedBundleMerge?: MergeCandidates;
38
+ };
41
39
 
42
- type BundlerConfig = {|
43
- [mode: BuildMode]: BaseBundlerConfig,
44
- |} & BaseBundlerConfig;
40
+ type BundlerConfig = Partial<Record<BuildMode, BaseBundlerConfig>> &
41
+ BaseBundlerConfig;
45
42
 
46
- export type ResolvedBundlerConfig = {|
47
- minBundles: number,
48
- minBundleSize: number,
49
- maxParallelRequests: number,
50
- projectRoot: string,
51
- disableSharedBundles: boolean,
52
- manualSharedBundles: ManualSharedBundles,
53
- loadConditionalBundlesInParallel?: boolean,
54
- sharedBundleMerge?: MergeCandidates,
55
- |};
43
+ export type ResolvedBundlerConfig = {
44
+ minBundles: number;
45
+ minBundleSize: number;
46
+ maxParallelRequests: number;
47
+ projectRoot: string;
48
+ disableSharedBundles: boolean;
49
+ manualSharedBundles: ManualSharedBundles;
50
+ loadConditionalBundlesInParallel?: boolean;
51
+ sharedBundleMerge?: MergeCandidates;
52
+ };
56
53
 
57
54
  function resolveModeConfig(
58
55
  config: BundlerConfig,
59
56
  mode: BuildMode,
60
57
  ): BaseBundlerConfig {
61
- let generalConfig = {};
62
- let modeConfig = {};
58
+ let generalConfig: Record<string, any> = {};
59
+ let modeConfig: Record<string, any> = {};
63
60
 
64
61
  for (const key of Object.keys(config)) {
65
62
  if (key === 'development' || key === 'production') {
66
63
  if (key === mode) {
64
+ // @ts-expect-error TS2322
67
65
  modeConfig = config[key];
68
66
  }
69
67
  } else {
@@ -71,7 +69,6 @@ function resolveModeConfig(
71
69
  }
72
70
  }
73
71
 
74
- // $FlowFixMe Not sure how to convince flow here...
75
72
  return {
76
73
  ...generalConfig,
77
74
  ...modeConfig,
@@ -96,7 +93,7 @@ const HTTP_OPTIONS = {
96
93
  disableSharedBundles: false,
97
94
  sharedBundleMerge: [],
98
95
  },
99
- };
96
+ } as const;
100
97
 
101
98
  const CONFIG_SCHEMA: SchemaEntity = {
102
99
  type: 'object',
@@ -203,7 +200,8 @@ export async function loadBundlerConfig(
203
200
  const modDefault = {
204
201
  ...HTTP_OPTIONS['2'],
205
202
  projectRoot: options.projectRoot,
206
- };
203
+ } as const;
204
+ // @ts-expect-error TS2322
207
205
  return modDefault;
208
206
  }
209
207
 
@@ -266,6 +264,7 @@ export async function loadBundlerConfig(
266
264
  );
267
265
 
268
266
  let http = modeConfig.http ?? 2;
267
+ // @ts-expect-error TS7053
269
268
  let defaults = HTTP_OPTIONS[http];
270
269
 
271
270
  return {
@@ -1,6 +1,4 @@
1
- // @flow strict-local
2
-
3
- import {ALL_EDGE_TYPES, type NodeId} from '@atlaspack/graph';
1
+ import {ALL_EDGE_TYPES, NodeId} from '@atlaspack/graph';
4
2
  import type {
5
3
  Bundle as LegacyBundle,
6
4
  BundleGroup,
@@ -195,11 +193,13 @@ export function decorateLegacyGraph(
195
193
  }
196
194
  }
197
195
 
196
+ // @ts-expect-error TS2488
198
197
  for (let {type, from, to} of idealBundleGraph.getAllEdges()) {
199
198
  let sourceBundle = nullthrows(idealBundleGraph.getNode(from));
200
199
  if (sourceBundle === 'root') {
201
200
  continue;
202
201
  }
202
+ // @ts-expect-error TS2367
203
203
  invariant(sourceBundle !== 'root');
204
204
 
205
205
  let legacySourceBundle = nullthrows(
@@ -210,6 +210,7 @@ export function decorateLegacyGraph(
210
210
  if (targetBundle === 'root') {
211
211
  continue;
212
212
  }
213
+ // @ts-expect-error TS2367
213
214
  invariant(targetBundle !== 'root');
214
215
  let legacyTargetBundle = nullthrows(
215
216
  idealBundleToLegacyBundle.get(targetBundle),