@atlaspack/core 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 +61 -0
- package/package.json +20 -20
- package/src/Atlaspack.js +3 -2
- package/src/atlaspack-v3/AtlaspackV3.js +24 -8
- package/src/loadAtlaspackPlugin.js +26 -71
- package/src/projectPath.js +14 -1
- package/src/requests/WriteBundlesRequest.js +31 -22
- package/LICENSE +0 -201
- package/lib/AssetGraph.js +0 -521
- package/lib/Atlaspack.js +0 -676
- package/lib/AtlaspackConfig.js +0 -298
- package/lib/AtlaspackConfig.schema.js +0 -103
- package/lib/BundleGraph.js +0 -1527
- package/lib/CommittedAsset.js +0 -155
- package/lib/Dependency.js +0 -136
- package/lib/Environment.js +0 -144
- package/lib/IdentifierRegistry.js +0 -36
- package/lib/InternalConfig.js +0 -56
- package/lib/PackagerRunner.js +0 -525
- package/lib/ReporterRunner.js +0 -151
- package/lib/RequestTracker.js +0 -1178
- package/lib/SymbolPropagation.js +0 -618
- package/lib/TargetDescriptor.schema.js +0 -118
- package/lib/Transformation.js +0 -522
- package/lib/UncommittedAsset.js +0 -348
- package/lib/Validation.js +0 -203
- package/lib/applyRuntimes.js +0 -355
- package/lib/assetUtils.js +0 -205
- package/lib/atlaspack-v3/AtlaspackV3.js +0 -57
- package/lib/atlaspack-v3/NapiWorkerPool.js +0 -71
- package/lib/atlaspack-v3/fs.js +0 -39
- package/lib/atlaspack-v3/index.js +0 -26
- package/lib/atlaspack-v3/jsCallable.js +0 -20
- package/lib/atlaspack-v3/worker/compat/asset-symbols.js +0 -197
- package/lib/atlaspack-v3/worker/compat/bitflags.js +0 -84
- package/lib/atlaspack-v3/worker/compat/dependency.js +0 -44
- package/lib/atlaspack-v3/worker/compat/environment.js +0 -57
- package/lib/atlaspack-v3/worker/compat/index.js +0 -104
- package/lib/atlaspack-v3/worker/compat/mutable-asset.js +0 -164
- package/lib/atlaspack-v3/worker/compat/plugin-config.js +0 -78
- package/lib/atlaspack-v3/worker/compat/plugin-logger.js +0 -29
- package/lib/atlaspack-v3/worker/compat/plugin-options.js +0 -113
- package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +0 -12
- package/lib/atlaspack-v3/worker/compat/target.js +0 -17
- package/lib/atlaspack-v3/worker/index.js +0 -3
- package/lib/atlaspack-v3/worker/worker.js +0 -280
- package/lib/constants.js +0 -21
- package/lib/dumpGraphToGraphViz.js +0 -206
- package/lib/index.js +0 -70
- package/lib/loadAtlaspackPlugin.js +0 -136
- package/lib/loadDotEnv.js +0 -54
- package/lib/projectPath.js +0 -94
- package/lib/public/Asset.js +0 -259
- package/lib/public/Bundle.js +0 -236
- package/lib/public/BundleGraph.js +0 -279
- package/lib/public/BundleGroup.js +0 -50
- package/lib/public/Config.js +0 -202
- package/lib/public/Dependency.js +0 -131
- package/lib/public/Environment.js +0 -247
- package/lib/public/MutableBundleGraph.js +0 -204
- package/lib/public/PluginOptions.js +0 -71
- package/lib/public/Symbols.js +0 -247
- package/lib/public/Target.js +0 -64
- package/lib/registerCoreWithSerializer.js +0 -51
- package/lib/requests/AssetGraphRequest.js +0 -432
- package/lib/requests/AssetGraphRequestRust.js +0 -220
- package/lib/requests/AssetRequest.js +0 -132
- package/lib/requests/AtlaspackBuildRequest.js +0 -79
- package/lib/requests/AtlaspackConfigRequest.js +0 -479
- package/lib/requests/BundleGraphRequest.js +0 -485
- package/lib/requests/ConfigRequest.js +0 -203
- package/lib/requests/DevDepRequest.js +0 -193
- package/lib/requests/EntryRequest.js +0 -295
- package/lib/requests/PackageRequest.js +0 -88
- package/lib/requests/PathRequest.js +0 -357
- package/lib/requests/TargetRequest.js +0 -1179
- package/lib/requests/ValidationRequest.js +0 -66
- package/lib/requests/WriteBundleRequest.js +0 -252
- package/lib/requests/WriteBundlesRequest.js +0 -153
- package/lib/requests/asset-graph-diff.js +0 -128
- package/lib/requests/asset-graph-dot.js +0 -131
- package/lib/resolveOptions.js +0 -265
- package/lib/serializerCore.browser.js +0 -29
- package/lib/summarizeRequest.js +0 -55
- package/lib/types.js +0 -35
- package/lib/utils.js +0 -160
- package/lib/worker.js +0 -184
|
@@ -1,432 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.AssetGraphBuilder = void 0;
|
|
7
|
-
exports.default = createAssetGraphRequest;
|
|
8
|
-
function _logger() {
|
|
9
|
-
const data = _interopRequireDefault(require("@atlaspack/logger"));
|
|
10
|
-
_logger = function () {
|
|
11
|
-
return data;
|
|
12
|
-
};
|
|
13
|
-
return data;
|
|
14
|
-
}
|
|
15
|
-
function _assert() {
|
|
16
|
-
const data = _interopRequireDefault(require("assert"));
|
|
17
|
-
_assert = function () {
|
|
18
|
-
return data;
|
|
19
|
-
};
|
|
20
|
-
return data;
|
|
21
|
-
}
|
|
22
|
-
function _nullthrows() {
|
|
23
|
-
const data = _interopRequireDefault(require("nullthrows"));
|
|
24
|
-
_nullthrows = function () {
|
|
25
|
-
return data;
|
|
26
|
-
};
|
|
27
|
-
return data;
|
|
28
|
-
}
|
|
29
|
-
function _utils() {
|
|
30
|
-
const data = require("@atlaspack/utils");
|
|
31
|
-
_utils = function () {
|
|
32
|
-
return data;
|
|
33
|
-
};
|
|
34
|
-
return data;
|
|
35
|
-
}
|
|
36
|
-
function _rust() {
|
|
37
|
-
const data = require("@atlaspack/rust");
|
|
38
|
-
_rust = function () {
|
|
39
|
-
return data;
|
|
40
|
-
};
|
|
41
|
-
return data;
|
|
42
|
-
}
|
|
43
|
-
function _diagnostic() {
|
|
44
|
-
const data = _interopRequireDefault(require("@atlaspack/diagnostic"));
|
|
45
|
-
_diagnostic = function () {
|
|
46
|
-
return data;
|
|
47
|
-
};
|
|
48
|
-
return data;
|
|
49
|
-
}
|
|
50
|
-
var _types = require("../types");
|
|
51
|
-
var _AssetGraph = _interopRequireDefault(require("../AssetGraph"));
|
|
52
|
-
var _constants = require("../constants");
|
|
53
|
-
var _EntryRequest = _interopRequireDefault(require("./EntryRequest"));
|
|
54
|
-
var _TargetRequest = _interopRequireDefault(require("./TargetRequest"));
|
|
55
|
-
var _AssetRequest = _interopRequireDefault(require("./AssetRequest"));
|
|
56
|
-
var _PathRequest = _interopRequireDefault(require("./PathRequest"));
|
|
57
|
-
var _projectPath = require("../projectPath");
|
|
58
|
-
var _dumpGraphToGraphViz = _interopRequireDefault(require("../dumpGraphToGraphViz"));
|
|
59
|
-
var _SymbolPropagation = require("../SymbolPropagation");
|
|
60
|
-
var _RequestTracker = require("../RequestTracker");
|
|
61
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
62
|
-
function createAssetGraphRequest(requestInput) {
|
|
63
|
-
return {
|
|
64
|
-
type: _RequestTracker.requestTypes.asset_graph_request,
|
|
65
|
-
id: requestInput.name,
|
|
66
|
-
run: async input => {
|
|
67
|
-
let prevResult = await input.api.getPreviousResult();
|
|
68
|
-
let builder = new AssetGraphBuilder(input, prevResult);
|
|
69
|
-
let assetGraphRequest = await await builder.build();
|
|
70
|
-
|
|
71
|
-
// early break for incremental bundling if production or flag is off;
|
|
72
|
-
if (!input.options.shouldBundleIncrementally || input.options.mode === 'production') {
|
|
73
|
-
assetGraphRequest.assetGraph.safeToIncrementallyBundle = false;
|
|
74
|
-
}
|
|
75
|
-
return assetGraphRequest;
|
|
76
|
-
},
|
|
77
|
-
input: requestInput
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
const typesWithRequests = new Set(['entry_specifier', 'entry_file', 'dependency', 'asset_group']);
|
|
81
|
-
class AssetGraphBuilder {
|
|
82
|
-
assetRequests = [];
|
|
83
|
-
constructor({
|
|
84
|
-
input,
|
|
85
|
-
api,
|
|
86
|
-
options
|
|
87
|
-
}, prevResult) {
|
|
88
|
-
let {
|
|
89
|
-
entries,
|
|
90
|
-
assetGroups,
|
|
91
|
-
optionsRef,
|
|
92
|
-
name,
|
|
93
|
-
requestedAssetIds,
|
|
94
|
-
shouldBuildLazily,
|
|
95
|
-
lazyIncludes,
|
|
96
|
-
lazyExcludes
|
|
97
|
-
} = input;
|
|
98
|
-
let assetGraph = (prevResult === null || prevResult === void 0 ? void 0 : prevResult.assetGraph) ?? new _AssetGraph.default();
|
|
99
|
-
assetGraph.safeToIncrementallyBundle = true;
|
|
100
|
-
assetGraph.setRootConnections({
|
|
101
|
-
entries,
|
|
102
|
-
assetGroups
|
|
103
|
-
});
|
|
104
|
-
assetGraph.undeferredDependencies.clear();
|
|
105
|
-
this.assetGroupsWithRemovedParents = (prevResult === null || prevResult === void 0 ? void 0 : prevResult.assetGroupsWithRemovedParents) ?? new Set();
|
|
106
|
-
this.previousSymbolPropagationErrors = (prevResult === null || prevResult === void 0 ? void 0 : prevResult.previousSymbolPropagationErrors) ?? new Map();
|
|
107
|
-
this.changedAssets = (prevResult === null || prevResult === void 0 ? void 0 : prevResult.changedAssets) ?? new Map();
|
|
108
|
-
this.changedAssetsPropagation = new Set();
|
|
109
|
-
this.prevChangedAssetsPropagation = prevResult === null || prevResult === void 0 ? void 0 : prevResult.changedAssetsPropagation;
|
|
110
|
-
this.assetGraph = assetGraph;
|
|
111
|
-
this.optionsRef = optionsRef;
|
|
112
|
-
this.options = options;
|
|
113
|
-
this.api = api;
|
|
114
|
-
this.name = name;
|
|
115
|
-
this.requestedAssetIds = requestedAssetIds ?? new Set();
|
|
116
|
-
this.shouldBuildLazily = shouldBuildLazily ?? false;
|
|
117
|
-
this.lazyIncludes = lazyIncludes ?? [];
|
|
118
|
-
this.lazyExcludes = lazyExcludes ?? [];
|
|
119
|
-
this.cacheKey = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}${name}${JSON.stringify(entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-AssetGraph';
|
|
120
|
-
this.isSingleChangeRebuild = api.getInvalidSubRequests().filter(req => req.requestType === 'asset_request').length === 1;
|
|
121
|
-
this.queue = new (_utils().PromiseQueue)();
|
|
122
|
-
assetGraph.onNodeRemoved = nodeId => {
|
|
123
|
-
this.assetGroupsWithRemovedParents.delete(nodeId);
|
|
124
|
-
|
|
125
|
-
// This needs to mark all connected nodes that doesn't become orphaned
|
|
126
|
-
// due to replaceNodesConnectedTo to make sure that the symbols of
|
|
127
|
-
// nodes from which at least one parent was removed are updated.
|
|
128
|
-
let node = (0, _nullthrows().default)(assetGraph.getNode(nodeId));
|
|
129
|
-
if (assetGraph.isOrphanedNode(nodeId) && node.type === 'dependency') {
|
|
130
|
-
let children = assetGraph.getNodeIdsConnectedFrom(nodeId);
|
|
131
|
-
for (let child of children) {
|
|
132
|
-
let childNode = (0, _nullthrows().default)(assetGraph.getNode(child));
|
|
133
|
-
(0, _assert().default)(childNode.type === 'asset_group' || childNode.type === 'asset');
|
|
134
|
-
childNode.usedSymbolsDownDirty = true;
|
|
135
|
-
this.assetGroupsWithRemovedParents.add(child);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
async build() {
|
|
141
|
-
let errors = [];
|
|
142
|
-
let rootNodeId = (0, _nullthrows().default)(this.assetGraph.rootNodeId, 'A root node is required to traverse');
|
|
143
|
-
let visitedAssetGroups = new Set();
|
|
144
|
-
let visited = new Set([rootNodeId]);
|
|
145
|
-
const visit = nodeId => {
|
|
146
|
-
if (errors.length > 0) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
if (this.shouldSkipRequest(nodeId)) {
|
|
150
|
-
visitChildren(nodeId);
|
|
151
|
-
} else {
|
|
152
|
-
// ? do we need to visit children inside of the promise that is queued?
|
|
153
|
-
this.queueCorrespondingRequest(nodeId, errors).then(() => visitChildren(nodeId));
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
const visitChildren = nodeId => {
|
|
157
|
-
for (let childNodeId of this.assetGraph.getNodeIdsConnectedFrom(nodeId)) {
|
|
158
|
-
let child = (0, _nullthrows().default)(this.assetGraph.getNode(childNodeId));
|
|
159
|
-
if ((!visited.has(childNodeId) || child.hasDeferred) && this.shouldVisitChild(nodeId, childNodeId)) {
|
|
160
|
-
if (child.type === 'asset_group') {
|
|
161
|
-
visitedAssetGroups.add(childNodeId);
|
|
162
|
-
}
|
|
163
|
-
visited.add(childNodeId);
|
|
164
|
-
visit(childNodeId);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
visit(rootNodeId);
|
|
169
|
-
await this.queue.run();
|
|
170
|
-
_logger().default.verbose({
|
|
171
|
-
origin: '@atlaspack/core',
|
|
172
|
-
message: 'Asset graph walked',
|
|
173
|
-
meta: {
|
|
174
|
-
visitedAssetGroupsCount: visitedAssetGroups.size
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
if (this.prevChangedAssetsPropagation) {
|
|
178
|
-
// Add any previously seen Assets that have not been propagated yet to
|
|
179
|
-
// 'this.changedAssetsPropagation', but only if they still remain in the graph
|
|
180
|
-
// as they could have been removed since the last build
|
|
181
|
-
for (let assetId of this.prevChangedAssetsPropagation) {
|
|
182
|
-
if (this.assetGraph.hasContentKey(assetId)) {
|
|
183
|
-
this.changedAssetsPropagation.add(assetId);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
if (errors.length) {
|
|
188
|
-
this.api.storeResult({
|
|
189
|
-
assetGraph: this.assetGraph,
|
|
190
|
-
changedAssets: this.changedAssets,
|
|
191
|
-
changedAssetsPropagation: this.changedAssetsPropagation,
|
|
192
|
-
assetGroupsWithRemovedParents: this.assetGroupsWithRemovedParents,
|
|
193
|
-
previousSymbolPropagationErrors: undefined,
|
|
194
|
-
assetRequests: []
|
|
195
|
-
}, this.cacheKey);
|
|
196
|
-
|
|
197
|
-
// TODO: eventually support multiple errors since requests could reject in parallel
|
|
198
|
-
throw errors[0];
|
|
199
|
-
}
|
|
200
|
-
if (this.assetGraph.nodes.length > 1) {
|
|
201
|
-
await (0, _dumpGraphToGraphViz.default)(this.assetGraph, 'AssetGraph_' + this.name + '_before_prop');
|
|
202
|
-
try {
|
|
203
|
-
let errors = (0, _SymbolPropagation.propagateSymbols)({
|
|
204
|
-
options: this.options,
|
|
205
|
-
assetGraph: this.assetGraph,
|
|
206
|
-
changedAssetsPropagation: this.changedAssetsPropagation,
|
|
207
|
-
assetGroupsWithRemovedParents: this.assetGroupsWithRemovedParents,
|
|
208
|
-
previousErrors: this.previousSymbolPropagationErrors
|
|
209
|
-
});
|
|
210
|
-
this.changedAssetsPropagation.clear();
|
|
211
|
-
if (errors.size > 0) {
|
|
212
|
-
this.api.storeResult({
|
|
213
|
-
assetGraph: this.assetGraph,
|
|
214
|
-
changedAssets: this.changedAssets,
|
|
215
|
-
changedAssetsPropagation: this.changedAssetsPropagation,
|
|
216
|
-
assetGroupsWithRemovedParents: this.assetGroupsWithRemovedParents,
|
|
217
|
-
previousSymbolPropagationErrors: errors,
|
|
218
|
-
assetRequests: []
|
|
219
|
-
}, this.cacheKey);
|
|
220
|
-
|
|
221
|
-
// Just throw the first error. Since errors can bubble (e.g. reexporting a reexported symbol also fails),
|
|
222
|
-
// determining which failing export is the root cause is nontrivial (because of circular dependencies).
|
|
223
|
-
throw new (_diagnostic().default)({
|
|
224
|
-
diagnostic: [...errors.values()][0]
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
} catch (e) {
|
|
228
|
-
await (0, _dumpGraphToGraphViz.default)(this.assetGraph, 'AssetGraph_' + this.name + '_failed');
|
|
229
|
-
throw e;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
await (0, _dumpGraphToGraphViz.default)(this.assetGraph, 'AssetGraph_' + this.name);
|
|
233
|
-
this.api.storeResult({
|
|
234
|
-
assetGraph: this.assetGraph,
|
|
235
|
-
changedAssets: new Map(),
|
|
236
|
-
changedAssetsPropagation: this.changedAssetsPropagation,
|
|
237
|
-
assetGroupsWithRemovedParents: undefined,
|
|
238
|
-
previousSymbolPropagationErrors: undefined,
|
|
239
|
-
assetRequests: []
|
|
240
|
-
}, this.cacheKey);
|
|
241
|
-
return {
|
|
242
|
-
assetGraph: this.assetGraph,
|
|
243
|
-
changedAssets: this.changedAssets,
|
|
244
|
-
changedAssetsPropagation: this.changedAssetsPropagation,
|
|
245
|
-
assetGroupsWithRemovedParents: undefined,
|
|
246
|
-
previousSymbolPropagationErrors: undefined,
|
|
247
|
-
assetRequests: this.assetRequests
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
shouldVisitChild(nodeId, childNodeId) {
|
|
251
|
-
if (this.shouldBuildLazily) {
|
|
252
|
-
let node = (0, _nullthrows().default)(this.assetGraph.getNode(nodeId));
|
|
253
|
-
let childNode = (0, _nullthrows().default)(this.assetGraph.getNode(childNodeId));
|
|
254
|
-
if (node.type === 'asset' && childNode.type === 'dependency') {
|
|
255
|
-
// This logic will set `node.requested` to `true` if the node is in the list of requested asset ids
|
|
256
|
-
// (i.e. this is an entry of a (probably) placeholder bundle that wasn't previously requested)
|
|
257
|
-
//
|
|
258
|
-
// Otherwise, if this node either is explicitly not requested, or has had it's requested attribute deleted,
|
|
259
|
-
// it will determine whether this node is an "async child" - that is, is it a (probably)
|
|
260
|
-
// dynamic import(). If so, it will explicitly have it's `node.requested` set to `false`
|
|
261
|
-
//
|
|
262
|
-
// If it's not requested, but it's not an async child then it's `node.requested` is deleted (undefined)
|
|
263
|
-
|
|
264
|
-
// by default with lazy compilation all nodes are lazy
|
|
265
|
-
let isNodeLazy = true;
|
|
266
|
-
|
|
267
|
-
// For conditional lazy building - if this node matches the `lazyInclude` globs that means we want
|
|
268
|
-
// only those nodes to be treated as lazy - that means if this node does _NOT_ match that glob, then we
|
|
269
|
-
// also consider it not lazy (so it gets marked as requested).
|
|
270
|
-
const relativePath = (0, _projectPath.fromProjectPathRelative)(node.value.filePath);
|
|
271
|
-
if (this.lazyIncludes.length > 0) {
|
|
272
|
-
isNodeLazy = this.lazyIncludes.some(lazyIncludeRegex => relativePath.match(lazyIncludeRegex));
|
|
273
|
-
}
|
|
274
|
-
// Excludes override includes, so a node is _not_ lazy if it is included in the exclude list.
|
|
275
|
-
if (this.lazyExcludes.length > 0 && isNodeLazy) {
|
|
276
|
-
isNodeLazy = !this.lazyExcludes.some(lazyExcludeRegex => relativePath.match(lazyExcludeRegex));
|
|
277
|
-
}
|
|
278
|
-
if (this.requestedAssetIds.has(node.value.id) || !isNodeLazy) {
|
|
279
|
-
node.requested = true;
|
|
280
|
-
} else if (!node.requested) {
|
|
281
|
-
let isAsyncChild = this.assetGraph.getIncomingDependencies(node.value).every(dep => dep.isEntry || dep.priority !== _types.Priority.sync);
|
|
282
|
-
if (isAsyncChild && childNode.value.priority !== _types.Priority.conditional) {
|
|
283
|
-
// Skip if we're on a conditional import
|
|
284
|
-
node.requested = !isNodeLazy;
|
|
285
|
-
} else {
|
|
286
|
-
delete node.requested;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
let previouslyDeferred = childNode.deferred;
|
|
290
|
-
childNode.deferred = node.requested === false;
|
|
291
|
-
|
|
292
|
-
// The child dependency node we're now evaluating should not be deferred if it's parent
|
|
293
|
-
// is explicitly not requested (requested = false, but not requested = undefined)
|
|
294
|
-
//
|
|
295
|
-
// if we weren't previously deferred but we are now, then this dependency node's parents should also
|
|
296
|
-
// be marked as deferred
|
|
297
|
-
//
|
|
298
|
-
// if we were previously deferred but we not longer are, then then all parents should no longer be
|
|
299
|
-
// deferred either
|
|
300
|
-
if (!previouslyDeferred && childNode.deferred) {
|
|
301
|
-
this.assetGraph.markParentsWithHasDeferred(childNodeId);
|
|
302
|
-
} else if (previouslyDeferred && !childNode.deferred) {
|
|
303
|
-
// Mark Asset and Dependency as dirty for symbol propagation as it was
|
|
304
|
-
// previously deferred and it's used symbols may have changed
|
|
305
|
-
this.changedAssetsPropagation.add(node.id);
|
|
306
|
-
node.usedSymbolsDownDirty = true;
|
|
307
|
-
this.changedAssetsPropagation.add(childNode.id);
|
|
308
|
-
childNode.usedSymbolsDownDirty = true;
|
|
309
|
-
this.assetGraph.unmarkParentsWithHasDeferred(childNodeId);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
// We `shouldVisitChild` if the childNode is not deferred
|
|
313
|
-
return !childNode.deferred;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
return this.assetGraph.shouldVisitChild(nodeId, childNodeId);
|
|
317
|
-
}
|
|
318
|
-
shouldSkipRequest(nodeId) {
|
|
319
|
-
let node = (0, _nullthrows().default)(this.assetGraph.getNode(nodeId));
|
|
320
|
-
return node.complete === true || !typesWithRequests.has(node.type) || node.correspondingRequest != null && this.api.canSkipSubrequest(node.correspondingRequest);
|
|
321
|
-
}
|
|
322
|
-
queueCorrespondingRequest(nodeId, errors) {
|
|
323
|
-
let promise;
|
|
324
|
-
let node = (0, _nullthrows().default)(this.assetGraph.getNode(nodeId));
|
|
325
|
-
switch (node.type) {
|
|
326
|
-
case 'entry_specifier':
|
|
327
|
-
promise = this.runEntryRequest(node.value);
|
|
328
|
-
break;
|
|
329
|
-
case 'entry_file':
|
|
330
|
-
promise = this.runTargetRequest(node.value);
|
|
331
|
-
break;
|
|
332
|
-
case 'dependency':
|
|
333
|
-
promise = this.runPathRequest(node.value);
|
|
334
|
-
break;
|
|
335
|
-
case 'asset_group':
|
|
336
|
-
promise = this.runAssetRequest(node.value);
|
|
337
|
-
break;
|
|
338
|
-
default:
|
|
339
|
-
throw new Error(`Can not queue corresponding request of node with type ${node.type}`);
|
|
340
|
-
}
|
|
341
|
-
return new Promise(resolve => {
|
|
342
|
-
this.queue.add(() => promise.then(() => {
|
|
343
|
-
resolve(null);
|
|
344
|
-
}, error => errors.push(error)));
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
async runEntryRequest(input) {
|
|
348
|
-
let prevEntries = this.assetGraph.safeToIncrementallyBundle ? this.assetGraph.getEntryAssets().map(asset => asset.id).sort() : [];
|
|
349
|
-
let request = (0, _EntryRequest.default)(input);
|
|
350
|
-
let result = await this.api.runRequest(request, {
|
|
351
|
-
force: true
|
|
352
|
-
});
|
|
353
|
-
this.assetGraph.resolveEntry(request.input, result.entries, request.id);
|
|
354
|
-
if (this.assetGraph.safeToIncrementallyBundle) {
|
|
355
|
-
let currentEntries = this.assetGraph.getEntryAssets().map(asset => asset.id).sort();
|
|
356
|
-
let didEntriesChange = prevEntries.length !== currentEntries.length || prevEntries.every((entryId, index) => entryId === currentEntries[index]);
|
|
357
|
-
if (didEntriesChange) {
|
|
358
|
-
this.assetGraph.safeToIncrementallyBundle = false;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
async runTargetRequest(input) {
|
|
363
|
-
let request = (0, _TargetRequest.default)(input);
|
|
364
|
-
let targets = await this.api.runRequest(request, {
|
|
365
|
-
force: true
|
|
366
|
-
});
|
|
367
|
-
this.assetGraph.resolveTargets(request.input, targets, request.id);
|
|
368
|
-
}
|
|
369
|
-
async runPathRequest(input) {
|
|
370
|
-
let request = (0, _PathRequest.default)({
|
|
371
|
-
dependency: input,
|
|
372
|
-
name: this.name
|
|
373
|
-
});
|
|
374
|
-
let result = await this.api.runRequest(request, {
|
|
375
|
-
force: true
|
|
376
|
-
});
|
|
377
|
-
this.assetGraph.resolveDependency(input, result, request.id);
|
|
378
|
-
}
|
|
379
|
-
async runAssetRequest(input) {
|
|
380
|
-
this.assetRequests.push(input);
|
|
381
|
-
let request = (0, _AssetRequest.default)({
|
|
382
|
-
...input,
|
|
383
|
-
name: this.name,
|
|
384
|
-
optionsRef: this.optionsRef,
|
|
385
|
-
isSingleChangeRebuild: this.isSingleChangeRebuild
|
|
386
|
-
});
|
|
387
|
-
let assets = await this.api.runRequest(request, {
|
|
388
|
-
force: true
|
|
389
|
-
});
|
|
390
|
-
if (assets != null) {
|
|
391
|
-
for (let asset of assets) {
|
|
392
|
-
if (this.assetGraph.safeToIncrementallyBundle) {
|
|
393
|
-
let otherAsset = this.assetGraph.getNodeByContentKey(asset.id);
|
|
394
|
-
if (otherAsset != null) {
|
|
395
|
-
(0, _assert().default)(otherAsset.type === 'asset');
|
|
396
|
-
if (!this._areDependenciesEqualForAssets(asset, otherAsset.value)) {
|
|
397
|
-
this.assetGraph.safeToIncrementallyBundle = false;
|
|
398
|
-
}
|
|
399
|
-
} else {
|
|
400
|
-
// adding a new entry or dependency
|
|
401
|
-
this.assetGraph.safeToIncrementallyBundle = false;
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
this.changedAssets.set(asset.id, asset);
|
|
405
|
-
this.changedAssetsPropagation.add(asset.id);
|
|
406
|
-
}
|
|
407
|
-
this.assetGraph.resolveAssetGroup(input, assets, request.id);
|
|
408
|
-
} else {
|
|
409
|
-
this.assetGraph.safeToIncrementallyBundle = false;
|
|
410
|
-
}
|
|
411
|
-
this.isSingleChangeRebuild = false;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* Used for incremental bundling of modified assets
|
|
416
|
-
*/
|
|
417
|
-
_areDependenciesEqualForAssets(asset, otherAsset) {
|
|
418
|
-
let assetDependencies = Array.from(asset === null || asset === void 0 ? void 0 : asset.dependencies.keys()).sort();
|
|
419
|
-
let otherAssetDependencies = Array.from(otherAsset === null || otherAsset === void 0 ? void 0 : otherAsset.dependencies.keys()).sort();
|
|
420
|
-
if (assetDependencies.length !== otherAssetDependencies.length) {
|
|
421
|
-
return false;
|
|
422
|
-
}
|
|
423
|
-
return assetDependencies.every((key, index) => {
|
|
424
|
-
var _asset$dependencies$g, _otherAsset$dependenc;
|
|
425
|
-
if (key !== otherAssetDependencies[index]) {
|
|
426
|
-
return false;
|
|
427
|
-
}
|
|
428
|
-
return (0, _utils().setEqual)(new Set(asset === null || asset === void 0 || (_asset$dependencies$g = asset.dependencies.get(key)) === null || _asset$dependencies$g === void 0 || (_asset$dependencies$g = _asset$dependencies$g.symbols) === null || _asset$dependencies$g === void 0 ? void 0 : _asset$dependencies$g.keys()), new Set(otherAsset === null || otherAsset === void 0 || (_otherAsset$dependenc = otherAsset.dependencies.get(key)) === null || _otherAsset$dependenc === void 0 || (_otherAsset$dependenc = _otherAsset$dependenc.symbols) === null || _otherAsset$dependenc === void 0 ? void 0 : _otherAsset$dependenc.keys()));
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
exports.AssetGraphBuilder = AssetGraphBuilder;
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createAssetGraphRequestRust = createAssetGraphRequestRust;
|
|
7
|
-
exports.getAssetGraph = getAssetGraph;
|
|
8
|
-
function _assert() {
|
|
9
|
-
const data = _interopRequireDefault(require("assert"));
|
|
10
|
-
_assert = function () {
|
|
11
|
-
return data;
|
|
12
|
-
};
|
|
13
|
-
return data;
|
|
14
|
-
}
|
|
15
|
-
function _diagnostic() {
|
|
16
|
-
const data = _interopRequireDefault(require("@atlaspack/diagnostic"));
|
|
17
|
-
_diagnostic = function () {
|
|
18
|
-
return data;
|
|
19
|
-
};
|
|
20
|
-
return data;
|
|
21
|
-
}
|
|
22
|
-
function _logger() {
|
|
23
|
-
const data = require("@atlaspack/logger");
|
|
24
|
-
_logger = function () {
|
|
25
|
-
return data;
|
|
26
|
-
};
|
|
27
|
-
return data;
|
|
28
|
-
}
|
|
29
|
-
var _AssetGraph = _interopRequireWildcard(require("../AssetGraph"));
|
|
30
|
-
var _RequestTracker = require("../RequestTracker");
|
|
31
|
-
var _SymbolPropagation = require("../SymbolPropagation");
|
|
32
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
33
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
34
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
35
|
-
function createAssetGraphRequestRust(rustAtlaspack) {
|
|
36
|
-
return input => ({
|
|
37
|
-
type: _RequestTracker.requestTypes.asset_graph_request,
|
|
38
|
-
id: input.name,
|
|
39
|
-
run: async input => {
|
|
40
|
-
let options = input.options;
|
|
41
|
-
let serializedAssetGraph = await rustAtlaspack.buildAssetGraph();
|
|
42
|
-
serializedAssetGraph.nodes = serializedAssetGraph.nodes.map(node => JSON.parse(node));
|
|
43
|
-
let {
|
|
44
|
-
assetGraph,
|
|
45
|
-
changedAssets
|
|
46
|
-
} = (0, _logger().instrument)('atlaspack_v3_getAssetGraph', () => getAssetGraph(serializedAssetGraph));
|
|
47
|
-
let changedAssetsPropagation = new Set(changedAssets.keys());
|
|
48
|
-
let errors = (0, _SymbolPropagation.propagateSymbols)({
|
|
49
|
-
options,
|
|
50
|
-
assetGraph,
|
|
51
|
-
changedAssetsPropagation,
|
|
52
|
-
assetGroupsWithRemovedParents: new Set(),
|
|
53
|
-
previousErrors: new Map() //this.previousSymbolPropagationErrors,
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
if (errors.size > 0) {
|
|
57
|
-
// Just throw the first error. Since errors can bubble (e.g. reexporting a reexported symbol also fails),
|
|
58
|
-
// determining which failing export is the root cause is nontrivial (because of circular dependencies).
|
|
59
|
-
throw new (_diagnostic().default)({
|
|
60
|
-
diagnostic: [...errors.values()][0]
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
assetGraph,
|
|
65
|
-
assetRequests: [],
|
|
66
|
-
assetGroupsWithRemovedParents: new Set(),
|
|
67
|
-
changedAssets,
|
|
68
|
-
changedAssetsPropagation,
|
|
69
|
-
previousSymbolPropagationErrors: undefined
|
|
70
|
-
};
|
|
71
|
-
},
|
|
72
|
-
input
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// $FlowFixMe
|
|
77
|
-
function getAssetGraph(serializedGraph) {
|
|
78
|
-
let graph = new _AssetGraph.default({
|
|
79
|
-
_contentKeyToNodeId: new Map(),
|
|
80
|
-
_nodeIdToContentKey: new Map(),
|
|
81
|
-
initialCapacity: serializedGraph.edges.length
|
|
82
|
-
});
|
|
83
|
-
graph.safeToIncrementallyBundle = false;
|
|
84
|
-
function mapSymbols({
|
|
85
|
-
exported,
|
|
86
|
-
...symbol
|
|
87
|
-
}) {
|
|
88
|
-
let jsSymbol = {
|
|
89
|
-
local: symbol.local ?? undefined,
|
|
90
|
-
loc: symbol.loc ?? undefined,
|
|
91
|
-
meta: undefined,
|
|
92
|
-
isWeak: symbol.isWeak
|
|
93
|
-
};
|
|
94
|
-
if (symbol.exported) {
|
|
95
|
-
// $FlowFixMe
|
|
96
|
-
jsSymbol.exported = symbol.exported;
|
|
97
|
-
}
|
|
98
|
-
if (symbol.isEsmExport) {
|
|
99
|
-
// $FlowFixMe
|
|
100
|
-
jsSymbol.meta = {
|
|
101
|
-
isEsm: true
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
return [exported, jsSymbol];
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// See crates/atlaspack_core/src/types/environment.rs
|
|
108
|
-
let changedAssets = new Map();
|
|
109
|
-
let entry = 0;
|
|
110
|
-
let envs = new Map();
|
|
111
|
-
let getEnvId = env => {
|
|
112
|
-
let envKey = [env.context, env.engines.atlaspack, env.engines.browsers, env.engines.electron, env.engines.node, env.includeNodeModules, env.isLibrary, env.outputFormat, env.shouldScopeHoist, env.shouldOptimize, env.sourceType].join(':');
|
|
113
|
-
let envId = envs.get(envKey);
|
|
114
|
-
if (envId == null) {
|
|
115
|
-
envId = envs.size;
|
|
116
|
-
envs.set(envKey, envId);
|
|
117
|
-
}
|
|
118
|
-
return envId;
|
|
119
|
-
};
|
|
120
|
-
for (let node of serializedGraph.nodes) {
|
|
121
|
-
if (node.type === 'root') {
|
|
122
|
-
let index = graph.addNodeByContentKey('@@root', {
|
|
123
|
-
id: '@@root',
|
|
124
|
-
type: 'root',
|
|
125
|
-
value: null
|
|
126
|
-
});
|
|
127
|
-
graph.setRootNodeId(index);
|
|
128
|
-
} else if (node.type === 'entry') {
|
|
129
|
-
let id = 'entry:' + ++entry;
|
|
130
|
-
graph.addNodeByContentKey(id, {
|
|
131
|
-
id: id,
|
|
132
|
-
type: 'root',
|
|
133
|
-
value: null
|
|
134
|
-
});
|
|
135
|
-
} else if (node.type === 'asset') {
|
|
136
|
-
let asset = node.value;
|
|
137
|
-
let id = asset.id;
|
|
138
|
-
asset.committed = true;
|
|
139
|
-
asset.contentKey = id;
|
|
140
|
-
asset.env.id = getEnvId(asset.env);
|
|
141
|
-
asset.mapKey = `map:${asset.id}`;
|
|
142
|
-
|
|
143
|
-
// This is populated later when we map the edges between assets and dependencies
|
|
144
|
-
asset.dependencies = new Map();
|
|
145
|
-
|
|
146
|
-
// We need to add this property for source map handling, as some assets like runtimes
|
|
147
|
-
// are processed after the Rust transformation and take the v2 code path
|
|
148
|
-
asset.meta.isV3 = true;
|
|
149
|
-
if (asset.symbols != null) {
|
|
150
|
-
asset.symbols = new Map(asset.symbols.map(mapSymbols));
|
|
151
|
-
}
|
|
152
|
-
changedAssets.set(id, asset);
|
|
153
|
-
graph.addNodeByContentKey(id, {
|
|
154
|
-
id,
|
|
155
|
-
type: 'asset',
|
|
156
|
-
usedSymbols: new Set(),
|
|
157
|
-
usedSymbolsDownDirty: true,
|
|
158
|
-
usedSymbolsUpDirty: true,
|
|
159
|
-
value: asset
|
|
160
|
-
});
|
|
161
|
-
} else if (node.type === 'dependency') {
|
|
162
|
-
let id = node.value.id;
|
|
163
|
-
let dependency = node.value.dependency;
|
|
164
|
-
dependency.id = id;
|
|
165
|
-
dependency.env.id = getEnvId(dependency.env);
|
|
166
|
-
if (dependency.symbols != null) {
|
|
167
|
-
var _dependency$symbols;
|
|
168
|
-
dependency.symbols = new Map((_dependency$symbols = dependency.symbols) === null || _dependency$symbols === void 0 ? void 0 : _dependency$symbols.map(mapSymbols));
|
|
169
|
-
}
|
|
170
|
-
let usedSymbolsDown = new Set();
|
|
171
|
-
let usedSymbolsUp = new Map();
|
|
172
|
-
if (dependency.isEntry && dependency.isLibrary) {
|
|
173
|
-
usedSymbolsDown.add('*');
|
|
174
|
-
usedSymbolsUp.set('*', undefined);
|
|
175
|
-
}
|
|
176
|
-
graph.addNodeByContentKey(id, {
|
|
177
|
-
id,
|
|
178
|
-
type: 'dependency',
|
|
179
|
-
deferred: false,
|
|
180
|
-
excluded: false,
|
|
181
|
-
hasDeferred: node.has_deferred,
|
|
182
|
-
usedSymbolsDown,
|
|
183
|
-
usedSymbolsDownDirty: true,
|
|
184
|
-
usedSymbolsUp,
|
|
185
|
-
usedSymbolsUpDirtyDown: true,
|
|
186
|
-
usedSymbolsUpDirtyUp: true,
|
|
187
|
-
value: dependency
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
for (let i = 0; i < serializedGraph.edges.length; i += 2) {
|
|
192
|
-
let from = serializedGraph.edges[i];
|
|
193
|
-
let to = serializedGraph.edges[i + 1];
|
|
194
|
-
let fromNode = graph.getNode(from);
|
|
195
|
-
let toNode = graph.getNode(to);
|
|
196
|
-
if ((fromNode === null || fromNode === void 0 ? void 0 : fromNode.type) === 'dependency') {
|
|
197
|
-
(0, _assert().default)((toNode === null || toNode === void 0 ? void 0 : toNode.type) === 'asset');
|
|
198
|
-
|
|
199
|
-
// For backwards compatibility, create asset group node if needed.
|
|
200
|
-
let assetGroupNode = (0, _AssetGraph.nodeFromAssetGroup)({
|
|
201
|
-
filePath: toNode.value.filePath,
|
|
202
|
-
env: fromNode.value.env,
|
|
203
|
-
pipeline: toNode.value.pipeline,
|
|
204
|
-
sideEffects: Boolean(toNode.value.sideEffects)
|
|
205
|
-
});
|
|
206
|
-
let index = graph.addNodeByContentKeyIfNeeded(assetGroupNode.id, assetGroupNode);
|
|
207
|
-
graph.addEdge(from, index);
|
|
208
|
-
graph.addEdge(index, to);
|
|
209
|
-
} else if ((fromNode === null || fromNode === void 0 ? void 0 : fromNode.type) === 'asset' && (toNode === null || toNode === void 0 ? void 0 : toNode.type) === 'dependency') {
|
|
210
|
-
fromNode.value.dependencies.set(toNode.value.id, toNode.value);
|
|
211
|
-
graph.addEdge(from, to);
|
|
212
|
-
} else {
|
|
213
|
-
graph.addEdge(from, to);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
return {
|
|
217
|
-
assetGraph: graph,
|
|
218
|
-
changedAssets
|
|
219
|
-
};
|
|
220
|
-
}
|