@atlaspack/bundler-default 2.14.5-canary.14 → 2.14.5-canary.140
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/CHANGELOG.md +302 -0
- package/lib/DefaultBundler.d.ts +18 -0
- package/lib/DefaultBundler.js +6 -1
- package/lib/MonolithicBundler.d.ts +2 -0
- package/lib/bundleMerge.d.ts +9 -0
- package/lib/bundleMerge.js +107 -37
- package/lib/bundlerConfig.d.ts +27 -0
- package/lib/bundlerConfig.js +49 -9
- package/lib/decorateLegacyGraph.d.ts +3 -0
- package/lib/decorateLegacyGraph.js +24 -3
- package/lib/idealGraph.d.ts +40 -0
- package/lib/idealGraph.js +217 -36
- package/lib/memoize.d.ts +2 -0
- package/lib/memoize.js +39 -0
- package/package.json +16 -11
- package/src/{DefaultBundler.js → DefaultBundler.ts} +21 -6
- package/src/{MonolithicBundler.js → MonolithicBundler.ts} +0 -1
- package/src/bundleMerge.ts +245 -0
- package/src/{bundlerConfig.js → bundlerConfig.ts} +87 -49
- package/src/{decorateLegacyGraph.js → decorateLegacyGraph.ts} +25 -6
- package/src/{idealGraph.js → idealGraph.ts} +367 -94
- package/src/memoize.ts +32 -0
- package/tsconfig.json +4 -0
- package/src/bundleMerge.js +0 -103
package/lib/bundlerConfig.js
CHANGED
|
@@ -11,6 +11,13 @@ function _diagnostic() {
|
|
|
11
11
|
};
|
|
12
12
|
return data;
|
|
13
13
|
}
|
|
14
|
+
function _featureFlags() {
|
|
15
|
+
const data = require("@atlaspack/feature-flags");
|
|
16
|
+
_featureFlags = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
14
21
|
function _utils() {
|
|
15
22
|
const data = require("@atlaspack/utils");
|
|
16
23
|
_utils = function () {
|
|
@@ -32,14 +39,13 @@ function resolveModeConfig(config, mode) {
|
|
|
32
39
|
for (const key of Object.keys(config)) {
|
|
33
40
|
if (key === 'development' || key === 'production') {
|
|
34
41
|
if (key === mode) {
|
|
42
|
+
// @ts-expect-error TS2322
|
|
35
43
|
modeConfig = config[key];
|
|
36
44
|
}
|
|
37
45
|
} else {
|
|
38
46
|
generalConfig[key] = config[key];
|
|
39
47
|
}
|
|
40
48
|
}
|
|
41
|
-
|
|
42
|
-
// $FlowFixMe Not sure how to convince flow here...
|
|
43
49
|
return {
|
|
44
50
|
...generalConfig,
|
|
45
51
|
...modeConfig
|
|
@@ -54,7 +60,7 @@ const HTTP_OPTIONS = {
|
|
|
54
60
|
minBundleSize: 30000,
|
|
55
61
|
maxParallelRequests: 6,
|
|
56
62
|
disableSharedBundles: false,
|
|
57
|
-
|
|
63
|
+
sharedBundleMerge: []
|
|
58
64
|
},
|
|
59
65
|
'2': {
|
|
60
66
|
minBundles: 1,
|
|
@@ -62,7 +68,7 @@ const HTTP_OPTIONS = {
|
|
|
62
68
|
minBundleSize: 20000,
|
|
63
69
|
maxParallelRequests: 25,
|
|
64
70
|
disableSharedBundles: false,
|
|
65
|
-
|
|
71
|
+
sharedBundleMerge: []
|
|
66
72
|
}
|
|
67
73
|
};
|
|
68
74
|
const CONFIG_SCHEMA = {
|
|
@@ -103,6 +109,30 @@ const CONFIG_SCHEMA = {
|
|
|
103
109
|
additionalProperties: false
|
|
104
110
|
}
|
|
105
111
|
},
|
|
112
|
+
sharedBundleMerge: {
|
|
113
|
+
type: 'array',
|
|
114
|
+
items: {
|
|
115
|
+
type: 'object',
|
|
116
|
+
properties: {
|
|
117
|
+
overlapThreshold: {
|
|
118
|
+
type: 'number'
|
|
119
|
+
},
|
|
120
|
+
maxBundleSize: {
|
|
121
|
+
type: 'number'
|
|
122
|
+
},
|
|
123
|
+
sourceBundles: {
|
|
124
|
+
type: 'array',
|
|
125
|
+
items: {
|
|
126
|
+
type: 'string'
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
minBundlesInGroup: {
|
|
130
|
+
type: 'number'
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
additionalProperties: false
|
|
134
|
+
}
|
|
135
|
+
},
|
|
106
136
|
minBundles: {
|
|
107
137
|
type: 'number'
|
|
108
138
|
},
|
|
@@ -125,17 +155,26 @@ const CONFIG_SCHEMA = {
|
|
|
125
155
|
additionalProperties: false
|
|
126
156
|
};
|
|
127
157
|
async function loadBundlerConfig(config, options, logger) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
158
|
+
var _conf;
|
|
159
|
+
let conf;
|
|
160
|
+
if ((0, _featureFlags().getFeatureFlag)('resolveBundlerConfigFromCwd')) {
|
|
161
|
+
conf = await config.getConfigFrom(`${process.cwd()}/index`, [], {
|
|
162
|
+
packageKey: '@atlaspack/bundler-default'
|
|
163
|
+
});
|
|
164
|
+
} else {
|
|
165
|
+
conf = await config.getConfig([], {
|
|
166
|
+
packageKey: '@atlaspack/bundler-default'
|
|
167
|
+
});
|
|
168
|
+
}
|
|
131
169
|
if (!conf) {
|
|
132
170
|
const modDefault = {
|
|
133
171
|
...HTTP_OPTIONS['2'],
|
|
134
172
|
projectRoot: options.projectRoot
|
|
135
173
|
};
|
|
174
|
+
// @ts-expect-error TS2322
|
|
136
175
|
return modDefault;
|
|
137
176
|
}
|
|
138
|
-
(0, _assert().default)((conf === null ||
|
|
177
|
+
(0, _assert().default)(((_conf = conf) === null || _conf === void 0 ? void 0 : _conf.contents) != null);
|
|
139
178
|
let modeConfig = resolveModeConfig(conf.contents, options.mode);
|
|
140
179
|
|
|
141
180
|
// minBundles will be ignored if shared bundles are disabled
|
|
@@ -173,11 +212,12 @@ async function loadBundlerConfig(config, options, logger) {
|
|
|
173
212
|
prependKey: `/${(0, _diagnostic().encodeJSONKeyComponent)('@atlaspack/bundler-default')}`
|
|
174
213
|
}, '@atlaspack/bundler-default', 'Invalid config for @atlaspack/bundler-default');
|
|
175
214
|
let http = modeConfig.http ?? 2;
|
|
215
|
+
// @ts-expect-error TS7053
|
|
176
216
|
let defaults = HTTP_OPTIONS[http];
|
|
177
217
|
return {
|
|
178
218
|
minBundles: modeConfig.minBundles ?? defaults.minBundles,
|
|
179
219
|
minBundleSize: modeConfig.minBundleSize ?? defaults.minBundleSize,
|
|
180
|
-
|
|
220
|
+
sharedBundleMerge: modeConfig.sharedBundleMerge ?? defaults.sharedBundleMerge,
|
|
181
221
|
maxParallelRequests: modeConfig.maxParallelRequests ?? defaults.maxParallelRequests,
|
|
182
222
|
projectRoot: options.projectRoot,
|
|
183
223
|
disableSharedBundles: modeConfig.disableSharedBundles ?? defaults.disableSharedBundles,
|
|
@@ -42,11 +42,13 @@ function decorateLegacyGraph(idealGraph, bundleGraph) {
|
|
|
42
42
|
bundleGroupBundleIds,
|
|
43
43
|
manualAssetToBundle
|
|
44
44
|
} = idealGraph;
|
|
45
|
+
// This line can be deleted once supportWebpackChunkName feature flag is removed.
|
|
45
46
|
let entryBundleToBundleGroup = new Map();
|
|
46
47
|
// Step Create Bundles: Create bundle groups, bundles, and shared bundles and add assets to them
|
|
47
48
|
for (let [bundleNodeId, idealBundle] of idealBundleGraph.nodes.entries()) {
|
|
48
49
|
if (!idealBundle || idealBundle === 'root') continue;
|
|
49
50
|
let entryAsset = idealBundle.mainEntryAsset;
|
|
51
|
+
// This line can be deleted once supportWebpackChunkName feature flag is removed.
|
|
50
52
|
let bundleGroup;
|
|
51
53
|
let bundle;
|
|
52
54
|
if (bundleGroupBundleIds.has(bundleNodeId)) {
|
|
@@ -57,19 +59,33 @@ function decorateLegacyGraph(idealGraph, bundleGraph) {
|
|
|
57
59
|
return dependency.value;
|
|
58
60
|
});
|
|
59
61
|
(0, _assert().default)(entryAsset != null, 'Processing a bundleGroup with no entry asset');
|
|
62
|
+
let bundleGroups = new Map();
|
|
60
63
|
for (let dependency of dependencies) {
|
|
61
64
|
bundleGroup = bundleGraph.createBundleGroup(dependency, idealBundle.target);
|
|
65
|
+
bundleGroups.set(bundleGroup.entryAssetId, bundleGroup);
|
|
66
|
+
}
|
|
67
|
+
if ((0, _featureFlags().getFeatureFlag)('supportWebpackChunkName')) {
|
|
68
|
+
(0, _assert().default)(bundleGroups.size > 0, 'No bundle groups created');
|
|
69
|
+
} else {
|
|
70
|
+
(0, _assert().default)(bundleGroup);
|
|
71
|
+
entryBundleToBundleGroup.set(bundleNodeId, bundleGroup);
|
|
62
72
|
}
|
|
63
|
-
(0, _assert().default)(bundleGroup);
|
|
64
|
-
entryBundleToBundleGroup.set(bundleNodeId, bundleGroup);
|
|
65
73
|
bundle = (0, _nullthrows().default)(bundleGraph.createBundle({
|
|
66
74
|
entryAsset: (0, _nullthrows().default)(entryAsset),
|
|
75
|
+
bundleRoots: Array.from(idealBundle.bundleRoots),
|
|
67
76
|
needsStableName: idealBundle.needsStableName,
|
|
68
77
|
bundleBehavior: idealBundle.bundleBehavior,
|
|
69
78
|
target: idealBundle.target,
|
|
70
79
|
manualSharedBundle: idealBundle.manualSharedBundle
|
|
71
80
|
}));
|
|
72
|
-
|
|
81
|
+
if ((0, _featureFlags().getFeatureFlag)('supportWebpackChunkName')) {
|
|
82
|
+
for (let bundleGroup of bundleGroups.values()) {
|
|
83
|
+
bundleGraph.addBundleToBundleGroup(bundle, bundleGroup);
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
(0, _assert().default)(bundleGroup);
|
|
87
|
+
bundleGraph.addBundleToBundleGroup(bundle, bundleGroup);
|
|
88
|
+
}
|
|
73
89
|
} else if (idealBundle.sourceBundles.size > 0 && !idealBundle.mainEntryAsset) {
|
|
74
90
|
let uniqueKey = idealBundle.uniqueKey != null ? idealBundle.uniqueKey : [...idealBundle.assets].map(asset => asset.id).join(',');
|
|
75
91
|
bundle = (0, _nullthrows().default)(bundleGraph.createBundle({
|
|
@@ -95,6 +111,7 @@ function decorateLegacyGraph(idealGraph, bundleGraph) {
|
|
|
95
111
|
(0, _assert().default)(entryAsset != null);
|
|
96
112
|
bundle = (0, _nullthrows().default)(bundleGraph.createBundle({
|
|
97
113
|
entryAsset,
|
|
114
|
+
bundleRoots: Array.from(idealBundle.bundleRoots),
|
|
98
115
|
needsStableName: idealBundle.needsStableName,
|
|
99
116
|
bundleBehavior: idealBundle.bundleBehavior,
|
|
100
117
|
target: idealBundle.target,
|
|
@@ -162,6 +179,8 @@ function decorateLegacyGraph(idealGraph, bundleGraph) {
|
|
|
162
179
|
bundleGraph.createAssetReference(dependency, asset, legacyBundle);
|
|
163
180
|
}
|
|
164
181
|
}
|
|
182
|
+
|
|
183
|
+
// @ts-expect-error TS2488
|
|
165
184
|
for (let {
|
|
166
185
|
type,
|
|
167
186
|
from,
|
|
@@ -171,12 +190,14 @@ function decorateLegacyGraph(idealGraph, bundleGraph) {
|
|
|
171
190
|
if (sourceBundle === 'root') {
|
|
172
191
|
continue;
|
|
173
192
|
}
|
|
193
|
+
// @ts-expect-error TS2367
|
|
174
194
|
(0, _assert().default)(sourceBundle !== 'root');
|
|
175
195
|
let legacySourceBundle = (0, _nullthrows().default)(idealBundleToLegacyBundle.get(sourceBundle));
|
|
176
196
|
let targetBundle = (0, _nullthrows().default)(idealBundleGraph.getNode(to));
|
|
177
197
|
if (targetBundle === 'root') {
|
|
178
198
|
continue;
|
|
179
199
|
}
|
|
200
|
+
// @ts-expect-error TS2367
|
|
180
201
|
(0, _assert().default)(targetBundle !== 'root');
|
|
181
202
|
let legacyTargetBundle = (0, _nullthrows().default)(idealBundleToLegacyBundle.get(targetBundle));
|
|
182
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;
|