@atlaspack/bundler-default 2.14.5-canary.16 → 2.14.5-canary.160

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,61 +1,67 @@
1
- // @flow strict-local
2
-
3
1
  import {encodeJSONKeyComponent} from '@atlaspack/diagnostic';
4
2
  import type {
5
3
  Config,
6
4
  PluginOptions,
7
5
  BuildMode,
8
6
  PluginLogger,
9
- } from '@atlaspack/types';
10
- import {type SchemaEntity, validateSchema} from '@atlaspack/utils';
7
+ } from '@atlaspack/types-internal';
8
+ import {getFeatureFlag} from '@atlaspack/feature-flags';
9
+ import {SchemaEntity, validateSchema} from '@atlaspack/utils';
11
10
  import invariant from 'assert';
12
11
 
13
12
  type Glob = string;
14
13
 
15
- type ManualSharedBundles = Array<{|
16
- name: string,
17
- assets: Array<Glob>,
18
- types?: Array<string>,
19
- root?: string,
20
- split?: number,
21
- |}>;
22
-
23
- type BaseBundlerConfig = {|
24
- http?: number,
25
- minBundles?: number,
26
- minBundleSize?: number,
27
- maxParallelRequests?: number,
28
- disableSharedBundles?: boolean,
29
- manualSharedBundles?: ManualSharedBundles,
30
- loadConditionalBundlesInParallel?: boolean,
31
- sharedBundleMergeThreshold?: number,
32
- |};
33
-
34
- type BundlerConfig = {|
35
- [mode: BuildMode]: BaseBundlerConfig,
36
- |} & BaseBundlerConfig;
37
-
38
- export type ResolvedBundlerConfig = {|
39
- minBundles: number,
40
- minBundleSize: number,
41
- maxParallelRequests: number,
42
- projectRoot: string,
43
- disableSharedBundles: boolean,
44
- manualSharedBundles: ManualSharedBundles,
45
- loadConditionalBundlesInParallel?: boolean,
46
- sharedBundleMergeThreshold: number,
47
- |};
14
+ type ManualSharedBundles = Array<{
15
+ name: string;
16
+ assets: Array<Glob>;
17
+ types?: Array<string>;
18
+ root?: string;
19
+ split?: number;
20
+ }>;
21
+
22
+ export type MergeCandidates = Array<{
23
+ overlapThreshold?: number;
24
+ maxBundleSize?: number;
25
+ sourceBundles?: Array<string>;
26
+ minBundlesInGroup?: number;
27
+ }>;
28
+
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
+ };
39
+
40
+ type BundlerConfig = Partial<Record<BuildMode, BaseBundlerConfig>> &
41
+ BaseBundlerConfig;
42
+
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
+ };
48
53
 
49
54
  function resolveModeConfig(
50
55
  config: BundlerConfig,
51
56
  mode: BuildMode,
52
57
  ): BaseBundlerConfig {
53
- let generalConfig = {};
54
- let modeConfig = {};
58
+ let generalConfig: Record<string, any> = {};
59
+ let modeConfig: Record<string, any> = {};
55
60
 
56
61
  for (const key of Object.keys(config)) {
57
62
  if (key === 'development' || key === 'production') {
58
63
  if (key === mode) {
64
+ // @ts-expect-error TS2322
59
65
  modeConfig = config[key];
60
66
  }
61
67
  } else {
@@ -63,7 +69,6 @@ function resolveModeConfig(
63
69
  }
64
70
  }
65
71
 
66
- // $FlowFixMe Not sure how to convince flow here...
67
72
  return {
68
73
  ...generalConfig,
69
74
  ...modeConfig,
@@ -78,7 +83,7 @@ const HTTP_OPTIONS = {
78
83
  minBundleSize: 30000,
79
84
  maxParallelRequests: 6,
80
85
  disableSharedBundles: false,
81
- sharedBundleMergeThreshold: 1,
86
+ sharedBundleMerge: [],
82
87
  },
83
88
  '2': {
84
89
  minBundles: 1,
@@ -86,9 +91,9 @@ const HTTP_OPTIONS = {
86
91
  minBundleSize: 20000,
87
92
  maxParallelRequests: 25,
88
93
  disableSharedBundles: false,
89
- sharedBundleMergeThreshold: 1,
94
+ sharedBundleMerge: [],
90
95
  },
91
- };
96
+ } as const;
92
97
 
93
98
  const CONFIG_SCHEMA: SchemaEntity = {
94
99
  type: 'object',
@@ -128,6 +133,30 @@ const CONFIG_SCHEMA: SchemaEntity = {
128
133
  additionalProperties: false,
129
134
  },
130
135
  },
136
+ sharedBundleMerge: {
137
+ type: 'array',
138
+ items: {
139
+ type: 'object',
140
+ properties: {
141
+ overlapThreshold: {
142
+ type: 'number',
143
+ },
144
+ maxBundleSize: {
145
+ type: 'number',
146
+ },
147
+ sourceBundles: {
148
+ type: 'array',
149
+ items: {
150
+ type: 'string',
151
+ },
152
+ },
153
+ minBundlesInGroup: {
154
+ type: 'number',
155
+ },
156
+ },
157
+ additionalProperties: false,
158
+ },
159
+ },
131
160
  minBundles: {
132
161
  type: 'number',
133
162
  },
@@ -155,15 +184,24 @@ export async function loadBundlerConfig(
155
184
  options: PluginOptions,
156
185
  logger: PluginLogger,
157
186
  ): Promise<ResolvedBundlerConfig> {
158
- let conf = await config.getConfig<BundlerConfig>([], {
159
- packageKey: '@atlaspack/bundler-default',
160
- });
187
+ let conf;
188
+
189
+ if (getFeatureFlag('resolveBundlerConfigFromCwd')) {
190
+ conf = await config.getConfigFrom(`${process.cwd()}/index`, [], {
191
+ packageKey: '@atlaspack/bundler-default',
192
+ });
193
+ } else {
194
+ conf = await config.getConfig<BundlerConfig>([], {
195
+ packageKey: '@atlaspack/bundler-default',
196
+ });
197
+ }
161
198
 
162
199
  if (!conf) {
163
200
  const modDefault = {
164
201
  ...HTTP_OPTIONS['2'],
165
202
  projectRoot: options.projectRoot,
166
- };
203
+ } as const;
204
+ // @ts-expect-error TS2322
167
205
  return modDefault;
168
206
  }
169
207
 
@@ -226,14 +264,14 @@ export async function loadBundlerConfig(
226
264
  );
227
265
 
228
266
  let http = modeConfig.http ?? 2;
267
+ // @ts-expect-error TS7053
229
268
  let defaults = HTTP_OPTIONS[http];
230
269
 
231
270
  return {
232
271
  minBundles: modeConfig.minBundles ?? defaults.minBundles,
233
272
  minBundleSize: modeConfig.minBundleSize ?? defaults.minBundleSize,
234
- sharedBundleMergeThreshold:
235
- modeConfig.sharedBundleMergeThreshold ??
236
- defaults.sharedBundleMergeThreshold,
273
+ sharedBundleMerge:
274
+ modeConfig.sharedBundleMerge ?? defaults.sharedBundleMerge,
237
275
  maxParallelRequests:
238
276
  modeConfig.maxParallelRequests ?? defaults.maxParallelRequests,
239
277
  projectRoot: options.projectRoot,
@@ -1,11 +1,9 @@
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,
7
5
  MutableBundleGraph,
8
- } from '@atlaspack/types';
6
+ } from '@atlaspack/types-internal';
9
7
  import {getFeatureFlag} from '@atlaspack/feature-flags';
10
8
  import invariant from 'assert';
11
9
  import nullthrows from 'nullthrows';
@@ -25,11 +23,13 @@ export function decorateLegacyGraph(
25
23
  bundleGroupBundleIds,
26
24
  manualAssetToBundle,
27
25
  } = idealGraph;
26
+ // This line can be deleted once supportWebpackChunkName feature flag is removed.
28
27
  let entryBundleToBundleGroup: Map<NodeId, BundleGroup> = new Map();
29
28
  // Step Create Bundles: Create bundle groups, bundles, and shared bundles and add assets to them
30
29
  for (let [bundleNodeId, idealBundle] of idealBundleGraph.nodes.entries()) {
31
30
  if (!idealBundle || idealBundle === 'root') continue;
32
31
  let entryAsset = idealBundle.mainEntryAsset;
32
+ // This line can be deleted once supportWebpackChunkName feature flag is removed.
33
33
  let bundleGroup;
34
34
  let bundle;
35
35
 
@@ -52,18 +52,26 @@ export function decorateLegacyGraph(
52
52
  entryAsset != null,
53
53
  'Processing a bundleGroup with no entry asset',
54
54
  );
55
+
56
+ let bundleGroups = new Map();
55
57
  for (let dependency of dependencies) {
56
58
  bundleGroup = bundleGraph.createBundleGroup(
57
59
  dependency,
58
60
  idealBundle.target,
59
61
  );
62
+ bundleGroups.set(bundleGroup.entryAssetId, bundleGroup);
63
+ }
64
+ if (getFeatureFlag('supportWebpackChunkName')) {
65
+ invariant(bundleGroups.size > 0, 'No bundle groups created');
66
+ } else {
67
+ invariant(bundleGroup);
68
+ entryBundleToBundleGroup.set(bundleNodeId, bundleGroup);
60
69
  }
61
- invariant(bundleGroup);
62
- entryBundleToBundleGroup.set(bundleNodeId, bundleGroup);
63
70
 
64
71
  bundle = nullthrows(
65
72
  bundleGraph.createBundle({
66
73
  entryAsset: nullthrows(entryAsset),
74
+ bundleRoots: Array.from(idealBundle.bundleRoots),
67
75
  needsStableName: idealBundle.needsStableName,
68
76
  bundleBehavior: idealBundle.bundleBehavior,
69
77
  target: idealBundle.target,
@@ -71,7 +79,14 @@ export function decorateLegacyGraph(
71
79
  }),
72
80
  );
73
81
 
74
- bundleGraph.addBundleToBundleGroup(bundle, bundleGroup);
82
+ if (getFeatureFlag('supportWebpackChunkName')) {
83
+ for (let bundleGroup of bundleGroups.values()) {
84
+ bundleGraph.addBundleToBundleGroup(bundle, bundleGroup);
85
+ }
86
+ } else {
87
+ invariant(bundleGroup);
88
+ bundleGraph.addBundleToBundleGroup(bundle, bundleGroup);
89
+ }
75
90
  } else if (
76
91
  idealBundle.sourceBundles.size > 0 &&
77
92
  !idealBundle.mainEntryAsset
@@ -109,6 +124,7 @@ export function decorateLegacyGraph(
109
124
  bundle = nullthrows(
110
125
  bundleGraph.createBundle({
111
126
  entryAsset,
127
+ bundleRoots: Array.from(idealBundle.bundleRoots),
112
128
  needsStableName: idealBundle.needsStableName,
113
129
  bundleBehavior: idealBundle.bundleBehavior,
114
130
  target: idealBundle.target,
@@ -195,11 +211,13 @@ export function decorateLegacyGraph(
195
211
  }
196
212
  }
197
213
 
214
+ // @ts-expect-error TS2488
198
215
  for (let {type, from, to} of idealBundleGraph.getAllEdges()) {
199
216
  let sourceBundle = nullthrows(idealBundleGraph.getNode(from));
200
217
  if (sourceBundle === 'root') {
201
218
  continue;
202
219
  }
220
+ // @ts-expect-error TS2367
203
221
  invariant(sourceBundle !== 'root');
204
222
 
205
223
  let legacySourceBundle = nullthrows(
@@ -210,6 +228,7 @@ export function decorateLegacyGraph(
210
228
  if (targetBundle === 'root') {
211
229
  continue;
212
230
  }
231
+ // @ts-expect-error TS2367
213
232
  invariant(targetBundle !== 'root');
214
233
  let legacyTargetBundle = nullthrows(
215
234
  idealBundleToLegacyBundle.get(targetBundle),