@atlaspack/core 2.34.0 → 2.36.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 +70 -0
- package/dist/AssetGraph.js +4 -72
- package/dist/BundleGraph.js +34 -0
- package/dist/PackagerRunner.js +8 -53
- package/dist/RequestTracker.js +17 -80
- package/dist/TargetDescriptor.schema.js +3 -0
- package/dist/UncommittedAsset.js +0 -5
- package/dist/atlaspack-v3/AtlaspackV3.js +6 -2
- package/dist/requests/AssetGraphRequest.js +6 -15
- package/dist/requests/AssetGraphRequestRust.js +51 -7
- package/dist/requests/AtlaspackBuildRequest.js +8 -2
- package/dist/requests/BundleGraphRequest.js +17 -21
- package/dist/requests/BundleGraphRequestRust.js +2 -2
- package/dist/requests/BundleGraphRequestUtils.js +133 -2
- package/dist/requests/PackageRequest.js +1 -1
- package/dist/requests/TargetRequest.js +5 -0
- package/dist/requests/WriteBundleRequest.js +169 -24
- package/dist/resolveOptions.js +2 -4
- package/lib/AssetGraph.js +3 -62
- package/lib/BundleGraph.js +38 -0
- package/lib/PackagerRunner.js +8 -42
- package/lib/RequestTracker.js +15 -69
- package/lib/TargetDescriptor.schema.js +3 -0
- package/lib/UncommittedAsset.js +0 -11
- package/lib/atlaspack-v3/AtlaspackV3.js +6 -2
- package/lib/requests/AssetGraphRequest.js +4 -18
- package/lib/requests/AssetGraphRequestRust.js +51 -7
- package/lib/requests/AtlaspackBuildRequest.js +8 -2
- package/lib/requests/BundleGraphRequest.js +20 -22
- package/lib/requests/BundleGraphRequestRust.js +3 -3
- package/lib/requests/BundleGraphRequestUtils.js +132 -2
- package/lib/requests/PackageRequest.js +3 -1
- package/lib/requests/TargetRequest.js +5 -0
- package/lib/requests/WriteBundleRequest.js +182 -14
- package/lib/resolveOptions.js +2 -4
- package/lib/types/AssetGraph.d.ts +2 -27
- package/lib/types/BundleGraph.d.ts +5 -0
- package/lib/types/atlaspack-v3/AtlaspackV3.d.ts +3 -2
- package/lib/types/requests/BundleGraphRequest.d.ts +1 -1
- package/lib/types/requests/BundleGraphRequestUtils.d.ts +7 -0
- package/lib/types/requests/WriteBundleRequest.d.ts +33 -0
- package/lib/types/types.d.ts +1 -0
- package/package.json +15 -15
- package/src/AssetGraph.ts +4 -72
- package/src/BundleGraph.ts +39 -0
- package/src/PackagerRunner.ts +9 -55
- package/src/RequestTracker.ts +24 -110
- package/src/TargetDescriptor.schema.ts +3 -0
- package/src/UncommittedAsset.ts +1 -11
- package/src/atlaspack-v3/AtlaspackV3.ts +19 -3
- package/src/requests/AssetGraphRequest.ts +8 -20
- package/src/requests/AssetGraphRequestRust.ts +59 -7
- package/src/requests/AtlaspackBuildRequest.ts +16 -8
- package/src/requests/BundleGraphRequest.ts +22 -36
- package/src/requests/BundleGraphRequestRust.ts +4 -2
- package/src/requests/BundleGraphRequestUtils.ts +157 -1
- package/src/requests/PackageRequest.ts +1 -1
- package/src/requests/TargetRequest.ts +5 -0
- package/src/requests/WriteBundleRequest.ts +203 -29
- package/src/resolveOptions.ts +2 -4
- package/src/types.ts +1 -0
- package/test/AssetGraph.test.ts +0 -32
- package/test/RequestTracker.test.ts +0 -165
- package/test/TargetRequest.test.ts +25 -0
- package/test/requests/WriteBundleRequest.test.ts +363 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -8,7 +8,6 @@ exports.default = createAssetGraphRequest;
|
|
|
8
8
|
const logger_1 = __importDefault(require("@atlaspack/logger"));
|
|
9
9
|
const assert_1 = __importDefault(require("assert"));
|
|
10
10
|
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
11
|
-
const feature_flags_1 = require("@atlaspack/feature-flags");
|
|
12
11
|
const utils_1 = require("@atlaspack/utils");
|
|
13
12
|
const rust_1 = require("@atlaspack/rust");
|
|
14
13
|
const diagnostic_1 = __importDefault(require("@atlaspack/diagnostic"));
|
|
@@ -32,8 +31,10 @@ function createAssetGraphRequest(requestInput) {
|
|
|
32
31
|
let builder = new AssetGraphBuilder(input, prevResult);
|
|
33
32
|
let assetGraphRequest = await builder.build();
|
|
34
33
|
// early break for incremental bundling if production or flag is off;
|
|
35
|
-
|
|
36
|
-
input.options.mode === 'production')
|
|
34
|
+
if (!input.options.shouldBundleIncrementally ||
|
|
35
|
+
input.options.mode === 'production') {
|
|
36
|
+
assetGraphRequest.assetGraph.safeToIncrementallyBundle = false;
|
|
37
|
+
}
|
|
37
38
|
if (!input.options.shouldBundleIncrementally ||
|
|
38
39
|
input.options.mode === 'production') {
|
|
39
40
|
assetGraphRequest.assetGraph.safeToIncrementallyBundle = false;
|
|
@@ -77,14 +78,8 @@ class AssetGraphBuilder {
|
|
|
77
78
|
this.lazyIncludes = lazyIncludes ?? [];
|
|
78
79
|
this.lazyExcludes = lazyExcludes ?? [];
|
|
79
80
|
this.skipSymbolProp = input.skipSymbolProp ?? false;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
this.cacheKey = `AssetGraph/${constants_1.ATLASPACK_VERSION}/${options.mode}/${key}`;
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
this.cacheKey =
|
|
86
|
-
(0, rust_1.hashString)(`${constants_1.ATLASPACK_VERSION}${name}${JSON.stringify(entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-AssetGraph';
|
|
87
|
-
}
|
|
81
|
+
this.cacheKey =
|
|
82
|
+
(0, rust_1.hashString)(`${constants_1.ATLASPACK_VERSION}${name}${JSON.stringify(entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-AssetGraph';
|
|
88
83
|
this.isSingleChangeRebuild =
|
|
89
84
|
api
|
|
90
85
|
.getInvalidSubRequests()
|
|
@@ -357,7 +352,6 @@ class AssetGraphBuilder {
|
|
|
357
352
|
prevEntries.every((entryId, index) => entryId === currentEntries[index]);
|
|
358
353
|
if (didEntriesChange) {
|
|
359
354
|
this.assetGraph.safeToIncrementallyBundle = false;
|
|
360
|
-
this.assetGraph.setNeedsBundling();
|
|
361
355
|
}
|
|
362
356
|
}
|
|
363
357
|
}
|
|
@@ -399,13 +393,11 @@ class AssetGraphBuilder {
|
|
|
399
393
|
(0, assert_1.default)(otherAsset.type === 'asset');
|
|
400
394
|
if (!this._areDependenciesEqualForAssets(asset, otherAsset.value)) {
|
|
401
395
|
this.assetGraph.safeToIncrementallyBundle = false;
|
|
402
|
-
this.assetGraph.setNeedsBundling();
|
|
403
396
|
}
|
|
404
397
|
}
|
|
405
398
|
else {
|
|
406
399
|
// adding a new entry or dependency
|
|
407
400
|
this.assetGraph.safeToIncrementallyBundle = false;
|
|
408
|
-
this.assetGraph.setNeedsBundling();
|
|
409
401
|
}
|
|
410
402
|
}
|
|
411
403
|
this.changedAssets.set(asset.id, asset);
|
|
@@ -415,7 +407,6 @@ class AssetGraphBuilder {
|
|
|
415
407
|
}
|
|
416
408
|
else {
|
|
417
409
|
this.assetGraph.safeToIncrementallyBundle = false;
|
|
418
|
-
this.assetGraph.setNeedsBundling();
|
|
419
410
|
}
|
|
420
411
|
this.isSingleChangeRebuild = false;
|
|
421
412
|
}
|
|
@@ -203,14 +203,58 @@ function getAssetGraph(serializedGraph, prevAssetGraph) {
|
|
|
203
203
|
}
|
|
204
204
|
return envId;
|
|
205
205
|
};
|
|
206
|
-
function
|
|
206
|
+
function describeNode(node) {
|
|
207
|
+
const base = { type: node.type, id: node.id };
|
|
208
|
+
if (node.type === 'asset') {
|
|
209
|
+
return {
|
|
210
|
+
...base,
|
|
211
|
+
filePath: node.value.filePath,
|
|
212
|
+
fileType: node.value.type,
|
|
213
|
+
pipeline: node.value.pipeline,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
else if (node.type === 'dependency') {
|
|
217
|
+
return {
|
|
218
|
+
...base,
|
|
219
|
+
specifier: node.value.specifier,
|
|
220
|
+
specifierType: node.value.specifierType,
|
|
221
|
+
sourceAssetId: node.value.sourceAssetId,
|
|
222
|
+
sourcePath: node.value.sourcePath,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
return base;
|
|
226
|
+
}
|
|
227
|
+
function updateNode(newNode, isUpdateNode, index) {
|
|
207
228
|
if (isUpdateNode) {
|
|
208
229
|
let existingNode = graph.getNodeByContentKey(newNode.id);
|
|
209
230
|
(0, assert_2.default)(existingNode && existingNode.type === newNode.type);
|
|
210
231
|
Object.assign(existingNode, newNode);
|
|
211
232
|
}
|
|
212
233
|
else {
|
|
213
|
-
|
|
234
|
+
try {
|
|
235
|
+
graph.addNodeByContentKey(newNode.id, newNode);
|
|
236
|
+
}
|
|
237
|
+
catch (e) {
|
|
238
|
+
if (e instanceof Error &&
|
|
239
|
+
e.message.includes('already has content key')) {
|
|
240
|
+
let existingNode = graph.getNodeByContentKey(newNode.id);
|
|
241
|
+
let diagnostics = {
|
|
242
|
+
contentKey: newNode.id,
|
|
243
|
+
newNode: describeNode(newNode),
|
|
244
|
+
existingNode: existingNode ? describeNode(existingNode) : null,
|
|
245
|
+
iterationIndex: index,
|
|
246
|
+
totalSerializedNodes: nodesCount,
|
|
247
|
+
newNodesCount: serializedGraph.nodes.length,
|
|
248
|
+
updatesCount: serializedGraph.updates.length,
|
|
249
|
+
edgesCount: serializedGraph.edges.length,
|
|
250
|
+
hadPreviousGraph: !!prevAssetGraph,
|
|
251
|
+
safeToSkipBundling: serializedGraph.safeToSkipBundling,
|
|
252
|
+
graphNodeCount: graph._contentKeyToNodeId.size,
|
|
253
|
+
};
|
|
254
|
+
throw new Error(`Graph already has content key '${newNode.id}'. Diagnostics: ${JSON.stringify(diagnostics, null, 2)}`);
|
|
255
|
+
}
|
|
256
|
+
throw e;
|
|
257
|
+
}
|
|
214
258
|
}
|
|
215
259
|
}
|
|
216
260
|
let nodeTypeSwitchoverIndex = serializedGraph.nodes.length;
|
|
@@ -257,7 +301,7 @@ function getAssetGraph(serializedGraph, prevAssetGraph) {
|
|
|
257
301
|
usedSymbolsUpDirty: true,
|
|
258
302
|
value: asset,
|
|
259
303
|
};
|
|
260
|
-
updateNode(assetNode, isUpdateNode);
|
|
304
|
+
updateNode(assetNode, isUpdateNode, index);
|
|
261
305
|
}
|
|
262
306
|
else if (node.type === 'dependency') {
|
|
263
307
|
let { dependency, id } = node.value;
|
|
@@ -274,12 +318,12 @@ function getAssetGraph(serializedGraph, prevAssetGraph) {
|
|
|
274
318
|
let usedSymbolsUp = new Map();
|
|
275
319
|
if (node.used_symbols_up) {
|
|
276
320
|
for (let usedSymbol of node.used_symbols_up) {
|
|
277
|
-
// Transform Rust UsedSymbol { symbol: Symbol, asset: string }
|
|
278
|
-
// to JS format { symbol: string, asset: string } where symbol is the
|
|
321
|
+
// Transform Rust UsedSymbol { symbol: Symbol, asset: string, resolved_symbol: string }
|
|
322
|
+
// to JS format { symbol: string, asset: string } where symbol is the resolved name
|
|
279
323
|
const exportedName = usedSymbol.symbol.exported;
|
|
280
324
|
usedSymbolsUp.set(exportedName, {
|
|
281
325
|
asset: usedSymbol.asset,
|
|
282
|
-
symbol: exportedName,
|
|
326
|
+
symbol: usedSymbol.resolved_symbol ?? exportedName,
|
|
283
327
|
});
|
|
284
328
|
}
|
|
285
329
|
}
|
|
@@ -301,7 +345,7 @@ function getAssetGraph(serializedGraph, prevAssetGraph) {
|
|
|
301
345
|
usedSymbolsUpDirtyUp: true,
|
|
302
346
|
value: dependency,
|
|
303
347
|
};
|
|
304
|
-
updateNode(depNode, isUpdateNode);
|
|
348
|
+
updateNode(depNode, isUpdateNode, index);
|
|
305
349
|
}
|
|
306
350
|
}
|
|
307
351
|
if (!reuseEdges) {
|
|
@@ -39,7 +39,7 @@ async function run({ input, api, options, rustAtlaspack, }) {
|
|
|
39
39
|
requestedAssetIds,
|
|
40
40
|
signal,
|
|
41
41
|
});
|
|
42
|
-
let { bundleGraph, changedAssets, assetRequests } = await api.runRequest(bundleGraphRequest, {
|
|
42
|
+
let { bundleGraph, changedAssets, assetRequests, didIncrementallyBundle, } = await api.runRequest(bundleGraphRequest, {
|
|
43
43
|
force: Boolean(rustAtlaspack) ||
|
|
44
44
|
(options.shouldBuildLazily && requestedAssetIds.size > 0),
|
|
45
45
|
});
|
|
@@ -55,7 +55,13 @@ async function run({ input, api, options, rustAtlaspack, }) {
|
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
if (hasSupportedTarget) {
|
|
58
|
-
|
|
58
|
+
if (didIncrementallyBundle) {
|
|
59
|
+
const changedAssetIds = Array.from(changedAssets.keys());
|
|
60
|
+
await rustAtlaspack.updateBundleGraph(bundleGraph, changedAssetIds);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
await rustAtlaspack.loadBundleGraph(bundleGraph);
|
|
64
|
+
}
|
|
59
65
|
}
|
|
60
66
|
}
|
|
61
67
|
// @ts-expect-error TS2345
|
|
@@ -157,7 +157,6 @@ function createBundleGraphRequest(input) {
|
|
|
157
157
|
.some((req) => !input.api.canSkipSubrequest(req.id));
|
|
158
158
|
if (subRequestsInvalid) {
|
|
159
159
|
assetGraph.safeToIncrementallyBundle = false;
|
|
160
|
-
assetGraph.setNeedsBundling();
|
|
161
160
|
}
|
|
162
161
|
let configResult = (0, nullthrows_1.default)(await input.api.runRequest((0, AtlaspackConfigRequest_1.default)()));
|
|
163
162
|
(0, utils_1.assertSignalNotAborted)(signal);
|
|
@@ -193,14 +192,8 @@ class BundlerRunner {
|
|
|
193
192
|
this.devDepRequests = new Map();
|
|
194
193
|
this.configs = new Map();
|
|
195
194
|
this.pluginOptions = new PluginOptions_1.default((0, utils_1.optionsProxy)(this.options, api.invalidateOnOptionChange));
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
this.cacheKey = `BundleGraph/${constants_1.ATLASPACK_VERSION}/${options.mode}/${key}`;
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
this.cacheKey =
|
|
202
|
-
(0, rust_1.hashString)(`${constants_1.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-BundleGraph';
|
|
203
|
-
}
|
|
195
|
+
this.cacheKey =
|
|
196
|
+
(0, rust_1.hashString)(`${constants_1.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-BundleGraph';
|
|
204
197
|
}
|
|
205
198
|
async loadConfigs() {
|
|
206
199
|
// Load all configs up front so we can use them in the cache key
|
|
@@ -226,16 +219,15 @@ class BundlerRunner {
|
|
|
226
219
|
type: 'buildProgress',
|
|
227
220
|
phase: 'bundling',
|
|
228
221
|
});
|
|
222
|
+
let didIncrementallyBundle = false;
|
|
229
223
|
await this.loadConfigs();
|
|
230
224
|
let plugin = await this.config.getBundler();
|
|
231
225
|
let { plugin: bundler, name, resolveFrom } = plugin;
|
|
232
226
|
// if a previous asset graph hash is passed in, check if the bundle graph is also available
|
|
233
227
|
const previousBundleGraphResult = await this.api.getPreviousResult();
|
|
234
|
-
const canIncrementallyBundle = previousBundleGraphResult
|
|
235
|
-
graph.canIncrementallyBundle(previousBundleGraphResult.assetGraphBundlingVersion);
|
|
228
|
+
const canIncrementallyBundle = previousBundleGraphResult != null && graph.canIncrementallyBundle();
|
|
236
229
|
if (graph.safeToIncrementallyBundle && previousBundleGraphResult == null) {
|
|
237
230
|
graph.safeToIncrementallyBundle = false;
|
|
238
|
-
graph.setNeedsBundling();
|
|
239
231
|
}
|
|
240
232
|
let internalBundleGraph;
|
|
241
233
|
let logger = new logger_1.PluginLogger({ origin: name });
|
|
@@ -252,6 +244,7 @@ class BundlerRunner {
|
|
|
252
244
|
(0, assert_1.default)(changedAssetNode.type === 'asset');
|
|
253
245
|
internalBundleGraph.updateAsset(changedAssetNode);
|
|
254
246
|
}
|
|
247
|
+
didIncrementallyBundle = true;
|
|
255
248
|
}
|
|
256
249
|
else {
|
|
257
250
|
internalBundleGraph = BundleGraph_1.default.fromAssetGraph(graph, this.options.mode === 'production');
|
|
@@ -270,14 +263,17 @@ class BundlerRunner {
|
|
|
270
263
|
measurement = tracer.createMeasurement(plugin.name, 'bundling:bundle', measurementFilename);
|
|
271
264
|
}
|
|
272
265
|
// this the normal bundle workflow (bundle, optimizing, run-times, naming)
|
|
273
|
-
await
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
266
|
+
await (0, logger_1.instrumentAsync)('bundle (V2)', async () => {
|
|
267
|
+
await bundler.bundle({
|
|
268
|
+
bundleGraph: mutableBundleGraph,
|
|
269
|
+
config: this.configs.get(plugin.name)?.result,
|
|
270
|
+
options: this.pluginOptions,
|
|
271
|
+
logger,
|
|
272
|
+
tracer,
|
|
273
|
+
});
|
|
279
274
|
});
|
|
280
275
|
measurement && measurement.end();
|
|
276
|
+
(0, BundleGraphRequestUtils_1.dumpBundleGraphSnapshot)(internalBundleGraph, 'js');
|
|
281
277
|
if (this.pluginOptions.mode === 'production') {
|
|
282
278
|
let optimizeMeasurement;
|
|
283
279
|
try {
|
|
@@ -318,9 +314,9 @@ class BundlerRunner {
|
|
|
318
314
|
if (internalBundleGraph != null) {
|
|
319
315
|
this.api.storeResult({
|
|
320
316
|
bundleGraph: internalBundleGraph,
|
|
321
|
-
assetGraphBundlingVersion: graph.getBundlingVersion(),
|
|
322
317
|
changedAssets: new Map(),
|
|
323
318
|
assetRequests: [],
|
|
319
|
+
didIncrementallyBundle,
|
|
324
320
|
}, this.cacheKey);
|
|
325
321
|
}
|
|
326
322
|
throw new diagnostic_1.default({
|
|
@@ -371,15 +367,15 @@ class BundlerRunner {
|
|
|
371
367
|
internalBundleGraph._graph, 'after_runtimes', BundleGraph_1.bundleGraphEdgeTypes);
|
|
372
368
|
this.api.storeResult({
|
|
373
369
|
bundleGraph: internalBundleGraph,
|
|
374
|
-
assetGraphBundlingVersion: graph.getBundlingVersion(),
|
|
375
370
|
changedAssets: new Map(),
|
|
376
371
|
assetRequests: [],
|
|
372
|
+
didIncrementallyBundle,
|
|
377
373
|
}, this.cacheKey);
|
|
378
374
|
return {
|
|
379
375
|
bundleGraph: internalBundleGraph,
|
|
380
|
-
assetGraphBundlingVersion: graph.getBundlingVersion(),
|
|
381
376
|
changedAssets: changedRuntimes,
|
|
382
377
|
assetRequests,
|
|
378
|
+
didIncrementallyBundle,
|
|
383
379
|
};
|
|
384
380
|
}
|
|
385
381
|
}
|
|
@@ -71,6 +71,7 @@ function createBundleGraphRequestRust(input) {
|
|
|
71
71
|
}
|
|
72
72
|
// Don’t reuse previous JS result yet; we just rebuild from scratch.
|
|
73
73
|
let { bundleGraph, changedAssets } = (0, logger_1.instrument)('atlaspack_v3_getBundleGraph', () => getBundleGraph(serializedBundleGraph));
|
|
74
|
+
(0, BundleGraphRequestUtils_1.dumpBundleGraphSnapshot)(bundleGraph, 'rust');
|
|
74
75
|
const runner = new NativeBundlerRunner({ api, options }, input.optionsRef);
|
|
75
76
|
await runner.loadConfigs();
|
|
76
77
|
// Name all bundles
|
|
@@ -112,10 +113,9 @@ function createBundleGraphRequestRust(input) {
|
|
|
112
113
|
}
|
|
113
114
|
return {
|
|
114
115
|
bundleGraph,
|
|
115
|
-
// Not accurate yet — ok for now.
|
|
116
|
-
assetGraphBundlingVersion: 0,
|
|
117
116
|
changedAssets: changedRuntimes,
|
|
118
117
|
assetRequests: [],
|
|
118
|
+
didIncrementallyBundle: false,
|
|
119
119
|
};
|
|
120
120
|
},
|
|
121
121
|
input,
|
|
@@ -37,15 +37,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.validateBundles = validateBundles;
|
|
40
|
+
exports.dumpBundleGraphSnapshot = dumpBundleGraphSnapshot;
|
|
40
41
|
exports.nameBundle = nameBundle;
|
|
41
42
|
exports.loadPluginConfigWithDevDeps = loadPluginConfigWithDevDeps;
|
|
42
43
|
exports.runDevDepRequest = runDevDepRequest;
|
|
43
44
|
const assert_1 = __importDefault(require("assert"));
|
|
45
|
+
const fs_1 = __importDefault(require("fs"));
|
|
44
46
|
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
47
|
+
const path_1 = __importDefault(require("path"));
|
|
45
48
|
const logger_1 = require("@atlaspack/logger");
|
|
46
49
|
const diagnostic_1 = __importStar(require("@atlaspack/diagnostic"));
|
|
47
50
|
const utils_1 = require("@atlaspack/utils");
|
|
48
|
-
const BundleGraph_1 =
|
|
51
|
+
const BundleGraph_1 = require("../BundleGraph");
|
|
52
|
+
const BundleGraph_2 = __importDefault(require("../public/BundleGraph"));
|
|
49
53
|
const Bundle_1 = require("../public/Bundle");
|
|
50
54
|
const InternalConfig_1 = require("../InternalConfig");
|
|
51
55
|
const DevDepRequest_1 = require("./DevDepRequest");
|
|
@@ -64,12 +68,139 @@ function validateBundles(bundleGraph) {
|
|
|
64
68
|
...(0, utils_1.setSymmetricDifference)(new Set(bundleNames), new Set((0, utils_1.unique)(bundleNames))),
|
|
65
69
|
].join());
|
|
66
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Dump a canonical JSON snapshot of the bundle graph for parity comparison.
|
|
73
|
+
* Gated by ATLASPACK_DUMP_BUNDLE_GRAPH environment variable which specifies the output directory.
|
|
74
|
+
* The snapshot captures bundle identity, type, contained assets, and bundle group structure
|
|
75
|
+
* in a deterministic, sorted format suitable for diffing.
|
|
76
|
+
*/
|
|
77
|
+
function dumpBundleGraphSnapshot(bundleGraph, variant) {
|
|
78
|
+
let outDir = process.env.ATLASPACK_DUMP_BUNDLE_GRAPH;
|
|
79
|
+
if (!outDir)
|
|
80
|
+
return;
|
|
81
|
+
let filename = variant === 'js' ? 'bundle-graph-js.json' : 'bundle-graph-rust.json';
|
|
82
|
+
let outPath = path_1.default.join(outDir, filename);
|
|
83
|
+
fs_1.default.mkdirSync(outDir, { recursive: true });
|
|
84
|
+
let bundles = bundleGraph.getBundles();
|
|
85
|
+
let bundlesSnapshot = bundles
|
|
86
|
+
.map((bundle) => {
|
|
87
|
+
let bundleNodeId = bundleGraph._graph.getNodeIdByContentKey(bundle.id);
|
|
88
|
+
let containedAssetNodeIds = bundleGraph._graph.getNodeIdsConnectedFrom(bundleNodeId, BundleGraph_1.bundleGraphEdgeTypes.contains);
|
|
89
|
+
let containedAssets = containedAssetNodeIds
|
|
90
|
+
.map((nodeId) => bundleGraph._graph.getNode(nodeId))
|
|
91
|
+
.flatMap((node) => {
|
|
92
|
+
if (node?.type !== 'asset')
|
|
93
|
+
return [];
|
|
94
|
+
return [
|
|
95
|
+
{
|
|
96
|
+
id: node.value.id,
|
|
97
|
+
filePath: (0, projectPath_1.fromProjectPathRelative)(node.value.filePath),
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
})
|
|
101
|
+
.sort((a, b) => a.filePath.localeCompare(b.filePath));
|
|
102
|
+
// Resolve mainEntry and entry asset file paths
|
|
103
|
+
let mainEntryPath = null;
|
|
104
|
+
let entryAssetPaths = [];
|
|
105
|
+
if (bundle.mainEntryId) {
|
|
106
|
+
let mainEntryNodeId = bundleGraph._graph.getNodeIdByContentKey(bundle.mainEntryId);
|
|
107
|
+
let mainEntryNode = bundleGraph._graph.getNode(mainEntryNodeId);
|
|
108
|
+
if (mainEntryNode?.type === 'asset') {
|
|
109
|
+
mainEntryPath = (0, projectPath_1.fromProjectPathRelative)(mainEntryNode.value.filePath);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
for (let entryId of bundle.entryAssetIds) {
|
|
113
|
+
let entryNodeId = bundleGraph._graph.getNodeIdByContentKey(entryId);
|
|
114
|
+
let entryNode = bundleGraph._graph.getNode(entryNodeId);
|
|
115
|
+
if (entryNode?.type === 'asset') {
|
|
116
|
+
entryAssetPaths.push((0, projectPath_1.fromProjectPathRelative)(entryNode.value.filePath));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
entryAssetPaths.sort();
|
|
120
|
+
return {
|
|
121
|
+
id: bundle.id,
|
|
122
|
+
type: bundle.type,
|
|
123
|
+
bundleBehavior: bundle.bundleBehavior ?? null,
|
|
124
|
+
needsStableName: bundle.needsStableName,
|
|
125
|
+
isSplittable: bundle.isSplittable,
|
|
126
|
+
isPlaceholder: bundle.isPlaceholder,
|
|
127
|
+
mainEntryPath,
|
|
128
|
+
entryAssetPaths,
|
|
129
|
+
assets: containedAssets.map((a) => a.filePath),
|
|
130
|
+
};
|
|
131
|
+
})
|
|
132
|
+
.sort((a, b) => {
|
|
133
|
+
// Sort by mainEntryPath first, then by sorted assets as tiebreaker
|
|
134
|
+
let aKey = a.mainEntryPath || a.assets.join(',');
|
|
135
|
+
let bKey = b.mainEntryPath || b.assets.join(',');
|
|
136
|
+
return aKey.localeCompare(bKey);
|
|
137
|
+
});
|
|
138
|
+
let bundleGroupsSnapshot = bundleGraph._graph.nodes
|
|
139
|
+
.flatMap((node) => {
|
|
140
|
+
if (node?.type !== 'bundle_group')
|
|
141
|
+
return [];
|
|
142
|
+
let bundleGroup = node.value;
|
|
143
|
+
// Resolve entry asset file path
|
|
144
|
+
let entryAssetPath = null;
|
|
145
|
+
try {
|
|
146
|
+
let entryNodeId = bundleGraph._graph.getNodeIdByContentKey(bundleGroup.entryAssetId);
|
|
147
|
+
let entryNode = bundleGraph._graph.getNode(entryNodeId);
|
|
148
|
+
if (entryNode?.type === 'asset') {
|
|
149
|
+
entryAssetPath = (0, projectPath_1.fromProjectPathRelative)(entryNode.value.filePath);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
// Content key not found
|
|
154
|
+
}
|
|
155
|
+
let bundlesInGroup = bundleGraph.getBundlesInBundleGroup(bundleGroup);
|
|
156
|
+
let bundlePaths = bundlesInGroup
|
|
157
|
+
.map((b) => {
|
|
158
|
+
// Use mainEntry file path if available, otherwise bundle id as fallback
|
|
159
|
+
if (b.mainEntryId) {
|
|
160
|
+
try {
|
|
161
|
+
let nodeId = bundleGraph._graph.getNodeIdByContentKey(b.mainEntryId);
|
|
162
|
+
let node = bundleGraph._graph.getNode(nodeId);
|
|
163
|
+
if (node?.type === 'asset') {
|
|
164
|
+
return (0, projectPath_1.fromProjectPathRelative)(node.value.filePath);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
// fallback
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return `[bundle:${b.id}]`;
|
|
172
|
+
})
|
|
173
|
+
.sort();
|
|
174
|
+
return [
|
|
175
|
+
{
|
|
176
|
+
entryAssetPath: entryAssetPath ?? `[unknown:${bundleGroup.entryAssetId}]`,
|
|
177
|
+
bundlePaths,
|
|
178
|
+
},
|
|
179
|
+
];
|
|
180
|
+
})
|
|
181
|
+
.sort((a, b) => a.entryAssetPath.localeCompare(b.entryAssetPath));
|
|
182
|
+
let totalAssets = bundleGraph._graph.nodes.filter((node) => node?.type === 'asset').length;
|
|
183
|
+
let snapshot = {
|
|
184
|
+
version: 1,
|
|
185
|
+
variant,
|
|
186
|
+
stats: {
|
|
187
|
+
totalBundles: bundlesSnapshot.length,
|
|
188
|
+
totalBundleGroups: bundleGroupsSnapshot.length,
|
|
189
|
+
totalAssets,
|
|
190
|
+
},
|
|
191
|
+
bundles: bundlesSnapshot,
|
|
192
|
+
bundleGroups: bundleGroupsSnapshot,
|
|
193
|
+
};
|
|
194
|
+
fs_1.default.writeFileSync(outPath, JSON.stringify(snapshot, null, 2), 'utf8');
|
|
195
|
+
// eslint-disable-next-line no-console
|
|
196
|
+
console.log(`[BundleGraphSnapshot] Wrote ${variant} snapshot to ${outPath}`);
|
|
197
|
+
}
|
|
67
198
|
/**
|
|
68
199
|
* Names a bundle by running through the configured namers until one returns a name.
|
|
69
200
|
*/
|
|
70
201
|
async function nameBundle(namers, internalBundle, internalBundleGraph, options, pluginOptions, configs) {
|
|
71
202
|
const bundle = Bundle_1.Bundle.get(internalBundle, internalBundleGraph, options);
|
|
72
|
-
const bundleGraph = new
|
|
203
|
+
const bundleGraph = new BundleGraph_2.default(internalBundleGraph, Bundle_1.NamedBundle.get.bind(Bundle_1.NamedBundle), options);
|
|
73
204
|
for (const namer of namers) {
|
|
74
205
|
let measurement;
|
|
75
206
|
try {
|
|
@@ -34,7 +34,7 @@ async function run({ input, api, farm, rustAtlaspack }) {
|
|
|
34
34
|
(0, EnvironmentManager_1.fromEnvironmentId)(bundle.env).context === 'tesseract' &&
|
|
35
35
|
bundle.type === 'js') {
|
|
36
36
|
// Once this actually does something, the code below will be in an `else` block (i.e. we'll only run one or the other)
|
|
37
|
-
let result = await rustAtlaspack.package(bundle.id);
|
|
37
|
+
let result = await rustAtlaspack.package(bundle.id, { inlineRequires: true });
|
|
38
38
|
let error = null;
|
|
39
39
|
[packagingResult, error] = result;
|
|
40
40
|
if (error) {
|
|
@@ -227,6 +227,7 @@ class TargetResolver {
|
|
|
227
227
|
distDir: (0, projectPath_1.toProjectPath)(this.options.projectRoot, path_1.default.resolve(this.fs.cwd(), distDir)),
|
|
228
228
|
publicUrl: descriptor.publicUrl ??
|
|
229
229
|
this.options.defaultTargetOptions.publicUrl,
|
|
230
|
+
inlineRequires: descriptor.inlineRequires ?? false,
|
|
230
231
|
env: (0, Environment_1.createEnvironment)({
|
|
231
232
|
engines: descriptor.engines,
|
|
232
233
|
context: descriptor.context,
|
|
@@ -299,6 +300,7 @@ class TargetResolver {
|
|
|
299
300
|
name: 'default',
|
|
300
301
|
distDir: (0, projectPath_1.toProjectPath)(this.options.projectRoot, this.options.serveOptions.distDir),
|
|
301
302
|
publicUrl: this.options.defaultTargetOptions.publicUrl ?? '/',
|
|
303
|
+
inlineRequires: false,
|
|
302
304
|
env: (0, Environment_1.createEnvironment)({
|
|
303
305
|
context: 'browser',
|
|
304
306
|
engines: {
|
|
@@ -705,6 +707,7 @@ class TargetResolver {
|
|
|
705
707
|
distDir,
|
|
706
708
|
distEntry,
|
|
707
709
|
publicUrl: descriptor.publicUrl ?? this.options.defaultTargetOptions.publicUrl,
|
|
710
|
+
inlineRequires: descriptor.inlineRequires ?? false,
|
|
708
711
|
env: (0, Environment_1.createEnvironment)({
|
|
709
712
|
engines: descriptor.engines ?? pkgEngines,
|
|
710
713
|
// @ts-expect-error TS2322
|
|
@@ -870,6 +873,7 @@ class TargetResolver {
|
|
|
870
873
|
: distDir),
|
|
871
874
|
distEntry,
|
|
872
875
|
publicUrl: descriptor.publicUrl ?? this.options.defaultTargetOptions.publicUrl,
|
|
876
|
+
inlineRequires: descriptor.inlineRequires ?? false,
|
|
873
877
|
env: (0, Environment_1.createEnvironment)({
|
|
874
878
|
engines: descriptor.engines ?? pkgEngines,
|
|
875
879
|
context: descriptor.context,
|
|
@@ -932,6 +936,7 @@ class TargetResolver {
|
|
|
932
936
|
distDir: this.options.defaultTargetOptions.distDir ??
|
|
933
937
|
(0, projectPath_1.toProjectPath)(this.options.projectRoot, path_1.default.join(pkgDir, DEFAULT_DIST_DIRNAME)),
|
|
934
938
|
publicUrl: this.options.defaultTargetOptions.publicUrl,
|
|
939
|
+
inlineRequires: false,
|
|
935
940
|
env: (0, Environment_1.createEnvironment)({
|
|
936
941
|
engines: pkgEngines,
|
|
937
942
|
// @ts-expect-error TS2322
|