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