@atlaspack/bundler-default 3.2.0 → 3.2.1-typescript-17c3d1dec.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 {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 (new Bundler({
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
- let graphs = [];
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
- }): Bundler<mixed>);
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(node, context, actions) {
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
  }
@@ -1,4 +1,3 @@
1
- // @flow strict-local
2
1
  import type {Asset, Dependency, MutableBundleGraph} from '@atlaspack/types';
3
2
  import nullthrows from 'nullthrows';
4
3
 
@@ -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,
@@ -213,11 +211,13 @@ export function decorateLegacyGraph(
213
211
  }
214
212
  }
215
213
 
214
+ // @ts-expect-error TS2488
216
215
  for (let {type, from, to} of idealBundleGraph.getAllEdges()) {
217
216
  let sourceBundle = nullthrows(idealBundleGraph.getNode(from));
218
217
  if (sourceBundle === 'root') {
219
218
  continue;
220
219
  }
220
+ // @ts-expect-error TS2367
221
221
  invariant(sourceBundle !== 'root');
222
222
 
223
223
  let legacySourceBundle = nullthrows(
@@ -228,6 +228,7 @@ export function decorateLegacyGraph(
228
228
  if (targetBundle === 'root') {
229
229
  continue;
230
230
  }
231
+ // @ts-expect-error TS2367
231
232
  invariant(targetBundle !== 'root');
232
233
  let legacyTargetBundle = nullthrows(
233
234
  idealBundleToLegacyBundle.get(targetBundle),