@atlaspack/bundler-default 2.13.2-dev.3682 → 2.14.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/CHANGELOG.md +39 -0
- package/package.json +10 -10
- package/src/MonolithicBundler.js +57 -3
- package/src/idealGraph.js +3 -7
- package/LICENSE +0 -201
- package/lib/DefaultBundler.js +0 -108
- package/lib/MonolithicBundler.js +0 -39
- package/lib/bundlerConfig.js +0 -181
- package/lib/decorateLegacyGraph.js +0 -188
- package/lib/idealGraph.js +0 -1068
package/lib/bundlerConfig.js
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.loadBundlerConfig = loadBundlerConfig;
|
|
7
|
-
function _diagnostic() {
|
|
8
|
-
const data = require("@atlaspack/diagnostic");
|
|
9
|
-
_diagnostic = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _utils() {
|
|
15
|
-
const data = require("@atlaspack/utils");
|
|
16
|
-
_utils = function () {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
function _assert() {
|
|
22
|
-
const data = _interopRequireDefault(require("assert"));
|
|
23
|
-
_assert = function () {
|
|
24
|
-
return data;
|
|
25
|
-
};
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
-
function resolveModeConfig(config, mode) {
|
|
30
|
-
let generalConfig = {};
|
|
31
|
-
let modeConfig = {};
|
|
32
|
-
for (const key of Object.keys(config)) {
|
|
33
|
-
if (key === 'development' || key === 'production') {
|
|
34
|
-
if (key === mode) {
|
|
35
|
-
modeConfig = config[key];
|
|
36
|
-
}
|
|
37
|
-
} else {
|
|
38
|
-
generalConfig[key] = config[key];
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// $FlowFixMe Not sure how to convince flow here...
|
|
43
|
-
return {
|
|
44
|
-
...generalConfig,
|
|
45
|
-
...modeConfig
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Default options by http version.
|
|
50
|
-
const HTTP_OPTIONS = {
|
|
51
|
-
'1': {
|
|
52
|
-
minBundles: 1,
|
|
53
|
-
manualSharedBundles: [],
|
|
54
|
-
minBundleSize: 30000,
|
|
55
|
-
maxParallelRequests: 6,
|
|
56
|
-
disableSharedBundles: false
|
|
57
|
-
},
|
|
58
|
-
'2': {
|
|
59
|
-
minBundles: 1,
|
|
60
|
-
manualSharedBundles: [],
|
|
61
|
-
minBundleSize: 20000,
|
|
62
|
-
maxParallelRequests: 25,
|
|
63
|
-
disableSharedBundles: false
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
const CONFIG_SCHEMA = {
|
|
67
|
-
type: 'object',
|
|
68
|
-
properties: {
|
|
69
|
-
http: {
|
|
70
|
-
type: 'number',
|
|
71
|
-
enum: Object.keys(HTTP_OPTIONS).map(k => Number(k))
|
|
72
|
-
},
|
|
73
|
-
manualSharedBundles: {
|
|
74
|
-
type: 'array',
|
|
75
|
-
items: {
|
|
76
|
-
type: 'object',
|
|
77
|
-
properties: {
|
|
78
|
-
name: {
|
|
79
|
-
type: 'string'
|
|
80
|
-
},
|
|
81
|
-
assets: {
|
|
82
|
-
type: 'array',
|
|
83
|
-
items: {
|
|
84
|
-
type: 'string'
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
types: {
|
|
88
|
-
type: 'array',
|
|
89
|
-
items: {
|
|
90
|
-
type: 'string'
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
root: {
|
|
94
|
-
type: 'string'
|
|
95
|
-
},
|
|
96
|
-
split: {
|
|
97
|
-
type: 'number'
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
required: ['name', 'assets'],
|
|
101
|
-
additionalProperties: false
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
minBundles: {
|
|
105
|
-
type: 'number'
|
|
106
|
-
},
|
|
107
|
-
minBundleSize: {
|
|
108
|
-
type: 'number'
|
|
109
|
-
},
|
|
110
|
-
maxParallelRequests: {
|
|
111
|
-
type: 'number'
|
|
112
|
-
},
|
|
113
|
-
disableSharedBundles: {
|
|
114
|
-
type: 'boolean'
|
|
115
|
-
},
|
|
116
|
-
loadConditionalBundlesInParallel: {
|
|
117
|
-
type: 'boolean'
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
additionalProperties: false
|
|
121
|
-
};
|
|
122
|
-
async function loadBundlerConfig(config, options, logger) {
|
|
123
|
-
let conf = await config.getConfig([], {
|
|
124
|
-
packageKey: '@atlaspack/bundler-default'
|
|
125
|
-
});
|
|
126
|
-
if (!conf) {
|
|
127
|
-
const modDefault = {
|
|
128
|
-
...HTTP_OPTIONS['2'],
|
|
129
|
-
projectRoot: options.projectRoot
|
|
130
|
-
};
|
|
131
|
-
return modDefault;
|
|
132
|
-
}
|
|
133
|
-
(0, _assert().default)((conf === null || conf === void 0 ? void 0 : conf.contents) != null);
|
|
134
|
-
let modeConfig = resolveModeConfig(conf.contents, options.mode);
|
|
135
|
-
|
|
136
|
-
// minBundles will be ignored if shared bundles are disabled
|
|
137
|
-
if (modeConfig.minBundles != null && modeConfig.disableSharedBundles === true) {
|
|
138
|
-
logger.warn({
|
|
139
|
-
origin: '@atlaspack/bundler-default',
|
|
140
|
-
message: `The value of "${modeConfig.minBundles}" set for minBundles will not be used as shared bundles have been disabled`
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// minBundleSize will be ignored if shared bundles are disabled
|
|
145
|
-
if (modeConfig.minBundleSize != null && modeConfig.disableSharedBundles === true) {
|
|
146
|
-
logger.warn({
|
|
147
|
-
origin: '@atlaspack/bundler-default',
|
|
148
|
-
message: `The value of "${modeConfig.minBundleSize}" set for minBundleSize will not be used as shared bundles have been disabled`
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// maxParallelRequests will be ignored if shared bundles are disabled
|
|
153
|
-
if (modeConfig.maxParallelRequests != null && modeConfig.disableSharedBundles === true) {
|
|
154
|
-
logger.warn({
|
|
155
|
-
origin: '@atlaspack/bundler-default',
|
|
156
|
-
message: `The value of "${modeConfig.maxParallelRequests}" set for maxParallelRequests will not be used as shared bundles have been disabled`
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
if (modeConfig.manualSharedBundles) {
|
|
160
|
-
let nameArray = modeConfig.manualSharedBundles.map(a => a.name);
|
|
161
|
-
let nameSet = new Set(nameArray);
|
|
162
|
-
(0, _assert().default)(nameSet.size == nameArray.length, 'The name field must be unique for property manualSharedBundles');
|
|
163
|
-
}
|
|
164
|
-
_utils().validateSchema.diagnostic(CONFIG_SCHEMA, {
|
|
165
|
-
data: modeConfig,
|
|
166
|
-
source: await options.inputFS.readFile(conf.filePath, 'utf8'),
|
|
167
|
-
filePath: conf.filePath,
|
|
168
|
-
prependKey: `/${(0, _diagnostic().encodeJSONKeyComponent)('@atlaspack/bundler-default')}`
|
|
169
|
-
}, '@atlaspack/bundler-default', 'Invalid config for @atlaspack/bundler-default');
|
|
170
|
-
let http = modeConfig.http ?? 2;
|
|
171
|
-
let defaults = HTTP_OPTIONS[http];
|
|
172
|
-
return {
|
|
173
|
-
minBundles: modeConfig.minBundles ?? defaults.minBundles,
|
|
174
|
-
minBundleSize: modeConfig.minBundleSize ?? defaults.minBundleSize,
|
|
175
|
-
maxParallelRequests: modeConfig.maxParallelRequests ?? defaults.maxParallelRequests,
|
|
176
|
-
projectRoot: options.projectRoot,
|
|
177
|
-
disableSharedBundles: modeConfig.disableSharedBundles ?? defaults.disableSharedBundles,
|
|
178
|
-
manualSharedBundles: modeConfig.manualSharedBundles ?? defaults.manualSharedBundles,
|
|
179
|
-
loadConditionalBundlesInParallel: modeConfig.loadConditionalBundlesInParallel
|
|
180
|
-
};
|
|
181
|
-
}
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.decorateLegacyGraph = decorateLegacyGraph;
|
|
7
|
-
function _graph() {
|
|
8
|
-
const data = require("@atlaspack/graph");
|
|
9
|
-
_graph = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _featureFlags() {
|
|
15
|
-
const data = require("@atlaspack/feature-flags");
|
|
16
|
-
_featureFlags = function () {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
function _assert() {
|
|
22
|
-
const data = _interopRequireDefault(require("assert"));
|
|
23
|
-
_assert = function () {
|
|
24
|
-
return data;
|
|
25
|
-
};
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
function _nullthrows() {
|
|
29
|
-
const data = _interopRequireDefault(require("nullthrows"));
|
|
30
|
-
_nullthrows = function () {
|
|
31
|
-
return data;
|
|
32
|
-
};
|
|
33
|
-
return data;
|
|
34
|
-
}
|
|
35
|
-
var _idealGraph = require("./idealGraph");
|
|
36
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
37
|
-
function decorateLegacyGraph(idealGraph, bundleGraph) {
|
|
38
|
-
let idealBundleToLegacyBundle = new Map();
|
|
39
|
-
let {
|
|
40
|
-
bundleGraph: idealBundleGraph,
|
|
41
|
-
dependencyBundleGraph,
|
|
42
|
-
bundleGroupBundleIds,
|
|
43
|
-
manualAssetToBundle
|
|
44
|
-
} = idealGraph;
|
|
45
|
-
let entryBundleToBundleGroup = new Map();
|
|
46
|
-
// Step Create Bundles: Create bundle groups, bundles, and shared bundles and add assets to them
|
|
47
|
-
for (let [bundleNodeId, idealBundle] of idealBundleGraph.nodes.entries()) {
|
|
48
|
-
if (!idealBundle || idealBundle === 'root') continue;
|
|
49
|
-
let entryAsset = idealBundle.mainEntryAsset;
|
|
50
|
-
let bundleGroup;
|
|
51
|
-
let bundle;
|
|
52
|
-
if (bundleGroupBundleIds.has(bundleNodeId)) {
|
|
53
|
-
(0, _assert().default)(idealBundle.manualSharedBundle == null, 'Processing a manualSharedBundle as a BundleGroup');
|
|
54
|
-
let dependencies = dependencyBundleGraph.getNodeIdsConnectedTo(dependencyBundleGraph.getNodeIdByContentKey(String(bundleNodeId)), _graph().ALL_EDGE_TYPES).map(nodeId => {
|
|
55
|
-
let dependency = (0, _nullthrows().default)(dependencyBundleGraph.getNode(nodeId));
|
|
56
|
-
(0, _assert().default)(dependency.type === 'dependency');
|
|
57
|
-
return dependency.value;
|
|
58
|
-
});
|
|
59
|
-
(0, _assert().default)(entryAsset != null, 'Processing a bundleGroup with no entry asset');
|
|
60
|
-
for (let dependency of dependencies) {
|
|
61
|
-
bundleGroup = bundleGraph.createBundleGroup(dependency, idealBundle.target);
|
|
62
|
-
}
|
|
63
|
-
(0, _assert().default)(bundleGroup);
|
|
64
|
-
entryBundleToBundleGroup.set(bundleNodeId, bundleGroup);
|
|
65
|
-
bundle = (0, _nullthrows().default)(bundleGraph.createBundle({
|
|
66
|
-
entryAsset: (0, _nullthrows().default)(entryAsset),
|
|
67
|
-
needsStableName: idealBundle.needsStableName,
|
|
68
|
-
bundleBehavior: idealBundle.bundleBehavior,
|
|
69
|
-
target: idealBundle.target,
|
|
70
|
-
manualSharedBundle: idealBundle.manualSharedBundle
|
|
71
|
-
}));
|
|
72
|
-
bundleGraph.addBundleToBundleGroup(bundle, bundleGroup);
|
|
73
|
-
} else if (idealBundle.sourceBundles.size > 0 && !idealBundle.mainEntryAsset) {
|
|
74
|
-
let uniqueKey = idealBundle.uniqueKey != null ? idealBundle.uniqueKey : [...idealBundle.assets].map(asset => asset.id).join(',');
|
|
75
|
-
bundle = (0, _nullthrows().default)(bundleGraph.createBundle({
|
|
76
|
-
uniqueKey,
|
|
77
|
-
needsStableName: idealBundle.needsStableName,
|
|
78
|
-
bundleBehavior: idealBundle.bundleBehavior,
|
|
79
|
-
type: idealBundle.type,
|
|
80
|
-
target: idealBundle.target,
|
|
81
|
-
env: idealBundle.env,
|
|
82
|
-
manualSharedBundle: idealBundle.manualSharedBundle
|
|
83
|
-
}));
|
|
84
|
-
} else if (idealBundle.uniqueKey != null) {
|
|
85
|
-
bundle = (0, _nullthrows().default)(bundleGraph.createBundle({
|
|
86
|
-
uniqueKey: idealBundle.uniqueKey,
|
|
87
|
-
needsStableName: idealBundle.needsStableName,
|
|
88
|
-
bundleBehavior: idealBundle.bundleBehavior,
|
|
89
|
-
type: idealBundle.type,
|
|
90
|
-
target: idealBundle.target,
|
|
91
|
-
env: idealBundle.env,
|
|
92
|
-
manualSharedBundle: idealBundle.manualSharedBundle
|
|
93
|
-
}));
|
|
94
|
-
} else {
|
|
95
|
-
(0, _assert().default)(entryAsset != null);
|
|
96
|
-
bundle = (0, _nullthrows().default)(bundleGraph.createBundle({
|
|
97
|
-
entryAsset,
|
|
98
|
-
needsStableName: idealBundle.needsStableName,
|
|
99
|
-
bundleBehavior: idealBundle.bundleBehavior,
|
|
100
|
-
target: idealBundle.target,
|
|
101
|
-
manualSharedBundle: idealBundle.manualSharedBundle
|
|
102
|
-
}));
|
|
103
|
-
}
|
|
104
|
-
idealBundleToLegacyBundle.set(idealBundle, bundle);
|
|
105
|
-
for (let asset of idealBundle.assets) {
|
|
106
|
-
bundleGraph.addAssetToBundle(asset, bundle);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
// Step Internalization: Internalize dependencies for bundles
|
|
110
|
-
for (let idealBundle of idealBundleGraph.nodes) {
|
|
111
|
-
if (!idealBundle || idealBundle === 'root') continue;
|
|
112
|
-
let bundle = (0, _nullthrows().default)(idealBundleToLegacyBundle.get(idealBundle));
|
|
113
|
-
if (idealBundle.internalizedAssets) {
|
|
114
|
-
idealBundle.internalizedAssets.forEach(internalized => {
|
|
115
|
-
let incomingDeps = bundleGraph.getIncomingDependencies(idealGraph.assets[internalized]);
|
|
116
|
-
for (let incomingDep of incomingDeps) {
|
|
117
|
-
if (incomingDep.priority === 'lazy' && incomingDep.specifierType !== 'url' && bundle.hasDependency(incomingDep)) {
|
|
118
|
-
bundleGraph.internalizeAsyncDependency(bundle, incomingDep);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
// Manual Shared Bundles
|
|
125
|
-
// NOTE: This only works under the assumption that manual shared bundles would have
|
|
126
|
-
// always already been loaded before the bundle that requires internalization.
|
|
127
|
-
for (let manualSharedAsset of manualAssetToBundle.keys()) {
|
|
128
|
-
let incomingDeps = bundleGraph.getIncomingDependencies(manualSharedAsset);
|
|
129
|
-
for (let incomingDep of incomingDeps) {
|
|
130
|
-
if (incomingDep.priority === 'lazy' && incomingDep.specifierType !== 'url') {
|
|
131
|
-
let bundles = bundleGraph.getBundlesWithDependency(incomingDep);
|
|
132
|
-
for (let bundle of bundles) {
|
|
133
|
-
bundleGraph.internalizeAsyncDependency(bundle, incomingDep);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Step Add to BundleGroups: Add bundles to their bundle groups
|
|
140
|
-
idealBundleGraph.traverse((nodeId, _, actions) => {
|
|
141
|
-
let node = idealBundleGraph.getNode(nodeId);
|
|
142
|
-
if (node === 'root') {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
actions.skipChildren();
|
|
146
|
-
let outboundNodeIds = idealBundleGraph.getNodeIdsConnectedFrom(nodeId);
|
|
147
|
-
let entryBundle = (0, _nullthrows().default)(idealBundleGraph.getNode(nodeId));
|
|
148
|
-
(0, _assert().default)(entryBundle !== 'root');
|
|
149
|
-
let legacyEntryBundle = (0, _nullthrows().default)(idealBundleToLegacyBundle.get(entryBundle));
|
|
150
|
-
for (let id of outboundNodeIds) {
|
|
151
|
-
let siblingBundle = (0, _nullthrows().default)(idealBundleGraph.getNode(id));
|
|
152
|
-
(0, _assert().default)(siblingBundle !== 'root');
|
|
153
|
-
let legacySiblingBundle = (0, _nullthrows().default)(idealBundleToLegacyBundle.get(siblingBundle));
|
|
154
|
-
bundleGraph.createBundleReference(legacyEntryBundle, legacySiblingBundle);
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
// Step References: Add references to all bundles
|
|
159
|
-
for (let [asset, references] of idealGraph.assetReference) {
|
|
160
|
-
for (let [dependency, bundle] of references) {
|
|
161
|
-
let legacyBundle = (0, _nullthrows().default)(idealBundleToLegacyBundle.get(bundle));
|
|
162
|
-
bundleGraph.createAssetReference(dependency, asset, legacyBundle);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
for (let {
|
|
166
|
-
type,
|
|
167
|
-
from,
|
|
168
|
-
to
|
|
169
|
-
} of idealBundleGraph.getAllEdges()) {
|
|
170
|
-
let sourceBundle = (0, _nullthrows().default)(idealBundleGraph.getNode(from));
|
|
171
|
-
if (sourceBundle === 'root') {
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
(0, _assert().default)(sourceBundle !== 'root');
|
|
175
|
-
let legacySourceBundle = (0, _nullthrows().default)(idealBundleToLegacyBundle.get(sourceBundle));
|
|
176
|
-
let targetBundle = (0, _nullthrows().default)(idealBundleGraph.getNode(to));
|
|
177
|
-
if (targetBundle === 'root') {
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
(0, _assert().default)(targetBundle !== 'root');
|
|
181
|
-
let legacyTargetBundle = (0, _nullthrows().default)(idealBundleToLegacyBundle.get(targetBundle));
|
|
182
|
-
if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi') && type === _idealGraph.idealBundleGraphEdges.conditional) {
|
|
183
|
-
bundleGraph.createBundleConditionalReference(legacySourceBundle, legacyTargetBundle);
|
|
184
|
-
} else {
|
|
185
|
-
bundleGraph.createBundleReference(legacySourceBundle, legacyTargetBundle);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|