@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.
Files changed (66) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/dist/AssetGraph.js +4 -72
  3. package/dist/BundleGraph.js +34 -0
  4. package/dist/PackagerRunner.js +8 -53
  5. package/dist/RequestTracker.js +17 -80
  6. package/dist/TargetDescriptor.schema.js +3 -0
  7. package/dist/UncommittedAsset.js +0 -5
  8. package/dist/atlaspack-v3/AtlaspackV3.js +6 -2
  9. package/dist/requests/AssetGraphRequest.js +6 -15
  10. package/dist/requests/AssetGraphRequestRust.js +51 -7
  11. package/dist/requests/AtlaspackBuildRequest.js +8 -2
  12. package/dist/requests/BundleGraphRequest.js +17 -21
  13. package/dist/requests/BundleGraphRequestRust.js +2 -2
  14. package/dist/requests/BundleGraphRequestUtils.js +133 -2
  15. package/dist/requests/PackageRequest.js +1 -1
  16. package/dist/requests/TargetRequest.js +5 -0
  17. package/dist/requests/WriteBundleRequest.js +169 -24
  18. package/dist/resolveOptions.js +2 -4
  19. package/lib/AssetGraph.js +3 -62
  20. package/lib/BundleGraph.js +38 -0
  21. package/lib/PackagerRunner.js +8 -42
  22. package/lib/RequestTracker.js +15 -69
  23. package/lib/TargetDescriptor.schema.js +3 -0
  24. package/lib/UncommittedAsset.js +0 -11
  25. package/lib/atlaspack-v3/AtlaspackV3.js +6 -2
  26. package/lib/requests/AssetGraphRequest.js +4 -18
  27. package/lib/requests/AssetGraphRequestRust.js +51 -7
  28. package/lib/requests/AtlaspackBuildRequest.js +8 -2
  29. package/lib/requests/BundleGraphRequest.js +20 -22
  30. package/lib/requests/BundleGraphRequestRust.js +3 -3
  31. package/lib/requests/BundleGraphRequestUtils.js +132 -2
  32. package/lib/requests/PackageRequest.js +3 -1
  33. package/lib/requests/TargetRequest.js +5 -0
  34. package/lib/requests/WriteBundleRequest.js +182 -14
  35. package/lib/resolveOptions.js +2 -4
  36. package/lib/types/AssetGraph.d.ts +2 -27
  37. package/lib/types/BundleGraph.d.ts +5 -0
  38. package/lib/types/atlaspack-v3/AtlaspackV3.d.ts +3 -2
  39. package/lib/types/requests/BundleGraphRequest.d.ts +1 -1
  40. package/lib/types/requests/BundleGraphRequestUtils.d.ts +7 -0
  41. package/lib/types/requests/WriteBundleRequest.d.ts +33 -0
  42. package/lib/types/types.d.ts +1 -0
  43. package/package.json +15 -15
  44. package/src/AssetGraph.ts +4 -72
  45. package/src/BundleGraph.ts +39 -0
  46. package/src/PackagerRunner.ts +9 -55
  47. package/src/RequestTracker.ts +24 -110
  48. package/src/TargetDescriptor.schema.ts +3 -0
  49. package/src/UncommittedAsset.ts +1 -11
  50. package/src/atlaspack-v3/AtlaspackV3.ts +19 -3
  51. package/src/requests/AssetGraphRequest.ts +8 -20
  52. package/src/requests/AssetGraphRequestRust.ts +59 -7
  53. package/src/requests/AtlaspackBuildRequest.ts +16 -8
  54. package/src/requests/BundleGraphRequest.ts +22 -36
  55. package/src/requests/BundleGraphRequestRust.ts +4 -2
  56. package/src/requests/BundleGraphRequestUtils.ts +157 -1
  57. package/src/requests/PackageRequest.ts +1 -1
  58. package/src/requests/TargetRequest.ts +5 -0
  59. package/src/requests/WriteBundleRequest.ts +203 -29
  60. package/src/resolveOptions.ts +2 -4
  61. package/src/types.ts +1 -0
  62. package/test/AssetGraph.test.ts +0 -32
  63. package/test/RequestTracker.test.ts +0 -165
  64. package/test/TargetRequest.test.ts +25 -0
  65. package/test/requests/WriteBundleRequest.test.ts +363 -0
  66. package/tsconfig.tsbuildinfo +1 -1
@@ -18,7 +18,6 @@ import logger from '@atlaspack/logger';
18
18
 
19
19
  import invariant from 'assert';
20
20
  import nullthrows from 'nullthrows';
21
- import {getFeatureFlag} from '@atlaspack/feature-flags';
22
21
  import {PromiseQueue, setEqual} from '@atlaspack/utils';
23
22
  import {hashString} from '@atlaspack/rust';
24
23
  import ThrowableDiagnostic from '@atlaspack/diagnostic';
@@ -85,10 +84,12 @@ export default function createAssetGraphRequest(
85
84
  let assetGraphRequest = await builder.build();
86
85
 
87
86
  // early break for incremental bundling if production or flag is off;
88
- assetGraphRequest.assetGraph.setDisableIncrementalBundling(
87
+ if (
89
88
  !input.options.shouldBundleIncrementally ||
90
- input.options.mode === 'production',
91
- );
89
+ input.options.mode === 'production'
90
+ ) {
91
+ assetGraphRequest.assetGraph.safeToIncrementallyBundle = false;
92
+ }
92
93
 
93
94
  if (
94
95
  !input.options.shouldBundleIncrementally ||
@@ -171,21 +172,12 @@ export class AssetGraphBuilder {
171
172
  this.lazyExcludes = lazyExcludes ?? [];
172
173
  this.skipSymbolProp = input.skipSymbolProp ?? false;
173
174
 
174
- if (getFeatureFlag('cachePerformanceImprovements')) {
175
- const key = hashString(
175
+ this.cacheKey =
176
+ hashString(
176
177
  `${ATLASPACK_VERSION}${name}${JSON.stringify(entries) ?? ''}${
177
178
  options.mode
178
179
  }${options.shouldBuildLazily ? 'lazy' : 'eager'}`,
179
- );
180
- this.cacheKey = `AssetGraph/${ATLASPACK_VERSION}/${options.mode}/${key}`;
181
- } else {
182
- this.cacheKey =
183
- hashString(
184
- `${ATLASPACK_VERSION}${name}${JSON.stringify(entries) ?? ''}${
185
- options.mode
186
- }${options.shouldBuildLazily ? 'lazy' : 'eager'}`,
187
- ) + '-AssetGraph';
188
- }
180
+ ) + '-AssetGraph';
189
181
 
190
182
  this.isSingleChangeRebuild =
191
183
  api
@@ -535,7 +527,6 @@ export class AssetGraphBuilder {
535
527
 
536
528
  if (didEntriesChange) {
537
529
  this.assetGraph.safeToIncrementallyBundle = false;
538
- this.assetGraph.setNeedsBundling();
539
530
  }
540
531
  }
541
532
  }
@@ -590,12 +581,10 @@ export class AssetGraphBuilder {
590
581
  invariant(otherAsset.type === 'asset');
591
582
  if (!this._areDependenciesEqualForAssets(asset, otherAsset.value)) {
592
583
  this.assetGraph.safeToIncrementallyBundle = false;
593
- this.assetGraph.setNeedsBundling();
594
584
  }
595
585
  } else {
596
586
  // adding a new entry or dependency
597
587
  this.assetGraph.safeToIncrementallyBundle = false;
598
- this.assetGraph.setNeedsBundling();
599
588
  }
600
589
  }
601
590
  this.changedAssets.set(asset.id, asset);
@@ -604,7 +593,6 @@ export class AssetGraphBuilder {
604
593
  this.assetGraph.resolveAssetGroup(input, assets, request.id);
605
594
  } else {
606
595
  this.assetGraph.safeToIncrementallyBundle = false;
607
- this.assetGraph.setNeedsBundling();
608
596
  }
609
597
 
610
598
  this.isSingleChangeRebuild = false;
@@ -238,7 +238,32 @@ export function getAssetGraph(
238
238
  return envId;
239
239
  };
240
240
 
241
- function updateNode(newNode: AssetGraphNode, isUpdateNode: boolean) {
241
+ function describeNode(node: AssetGraphNode): Record<string, unknown> {
242
+ const base = {type: node.type, id: node.id};
243
+ if (node.type === 'asset') {
244
+ return {
245
+ ...base,
246
+ filePath: node.value.filePath,
247
+ fileType: node.value.type,
248
+ pipeline: node.value.pipeline,
249
+ };
250
+ } else if (node.type === 'dependency') {
251
+ return {
252
+ ...base,
253
+ specifier: node.value.specifier,
254
+ specifierType: node.value.specifierType,
255
+ sourceAssetId: node.value.sourceAssetId,
256
+ sourcePath: node.value.sourcePath,
257
+ };
258
+ }
259
+ return base;
260
+ }
261
+
262
+ function updateNode(
263
+ newNode: AssetGraphNode,
264
+ isUpdateNode: boolean,
265
+ index: number,
266
+ ) {
242
267
  if (isUpdateNode) {
243
268
  let existingNode = graph.getNodeByContentKey(newNode.id);
244
269
 
@@ -246,7 +271,34 @@ export function getAssetGraph(
246
271
 
247
272
  Object.assign(existingNode, newNode);
248
273
  } else {
249
- graph.addNodeByContentKey(newNode.id, newNode);
274
+ try {
275
+ graph.addNodeByContentKey(newNode.id, newNode);
276
+ } catch (e) {
277
+ if (
278
+ e instanceof Error &&
279
+ e.message.includes('already has content key')
280
+ ) {
281
+ let existingNode = graph.getNodeByContentKey(newNode.id);
282
+ let diagnostics = {
283
+ contentKey: newNode.id,
284
+ newNode: describeNode(newNode),
285
+ existingNode: existingNode ? describeNode(existingNode) : null,
286
+ iterationIndex: index,
287
+ totalSerializedNodes: nodesCount,
288
+ newNodesCount: serializedGraph.nodes.length,
289
+ updatesCount: serializedGraph.updates.length,
290
+ edgesCount: serializedGraph.edges.length,
291
+ hadPreviousGraph: !!prevAssetGraph,
292
+ safeToSkipBundling: serializedGraph.safeToSkipBundling,
293
+ graphNodeCount: graph._contentKeyToNodeId.size,
294
+ };
295
+
296
+ throw new Error(
297
+ `Graph already has content key '${newNode.id}'. Diagnostics: ${JSON.stringify(diagnostics, null, 2)}`,
298
+ );
299
+ }
300
+ throw e;
301
+ }
250
302
  }
251
303
  }
252
304
 
@@ -305,7 +357,7 @@ export function getAssetGraph(
305
357
  usedSymbolsUpDirty: true,
306
358
  value: asset,
307
359
  };
308
- updateNode(assetNode, isUpdateNode);
360
+ updateNode(assetNode, isUpdateNode, index);
309
361
  } else if (node.type === 'dependency') {
310
362
  let {dependency, id} = node.value;
311
363
 
@@ -325,12 +377,12 @@ export function getAssetGraph(
325
377
 
326
378
  if (node.used_symbols_up) {
327
379
  for (let usedSymbol of node.used_symbols_up) {
328
- // Transform Rust UsedSymbol { symbol: Symbol, asset: string }
329
- // to JS format { symbol: string, asset: string } where symbol is the exported name
380
+ // Transform Rust UsedSymbol { symbol: Symbol, asset: string, resolved_symbol: string }
381
+ // to JS format { symbol: string, asset: string } where symbol is the resolved name
330
382
  const exportedName = usedSymbol.symbol.exported;
331
383
  usedSymbolsUp.set(exportedName, {
332
384
  asset: usedSymbol.asset,
333
- symbol: exportedName,
385
+ symbol: usedSymbol.resolved_symbol ?? exportedName,
334
386
  });
335
387
  }
336
388
  }
@@ -355,7 +407,7 @@ export function getAssetGraph(
355
407
  value: dependency,
356
408
  };
357
409
 
358
- updateNode(depNode, isUpdateNode);
410
+ updateNode(depNode, isUpdateNode, index);
359
411
  }
360
412
  }
361
413
 
@@ -23,7 +23,6 @@ import {tracer} from '@atlaspack/profiler';
23
23
  import {requestTypes} from '../RequestTracker';
24
24
  import {getFeatureFlag} from '@atlaspack/feature-flags';
25
25
  import {fromEnvironmentId} from '../EnvironmentManager';
26
- import invariant from 'assert';
27
26
 
28
27
  type AtlaspackBuildRequestInput = {
29
28
  optionsRef: SharedReference;
@@ -87,12 +86,16 @@ async function run({
87
86
  signal,
88
87
  });
89
88
 
90
- let {bundleGraph, changedAssets, assetRequests}: BundleGraphResult =
91
- await api.runRequest(bundleGraphRequest, {
92
- force:
93
- Boolean(rustAtlaspack) ||
94
- (options.shouldBuildLazily && requestedAssetIds.size > 0),
95
- });
89
+ let {
90
+ bundleGraph,
91
+ changedAssets,
92
+ assetRequests,
93
+ didIncrementallyBundle,
94
+ }: BundleGraphResult = await api.runRequest(bundleGraphRequest, {
95
+ force:
96
+ Boolean(rustAtlaspack) ||
97
+ (options.shouldBuildLazily && requestedAssetIds.size > 0),
98
+ });
96
99
 
97
100
  if (
98
101
  getFeatureFlag('nativePackager') &&
@@ -110,7 +113,12 @@ async function run({
110
113
  }
111
114
  });
112
115
  if (hasSupportedTarget) {
113
- await rustAtlaspack.loadBundleGraph(bundleGraph);
116
+ if (didIncrementallyBundle) {
117
+ const changedAssetIds = Array.from(changedAssets.keys());
118
+ await rustAtlaspack.updateBundleGraph(bundleGraph, changedAssetIds);
119
+ } else {
120
+ await rustAtlaspack.loadBundleGraph(bundleGraph);
121
+ }
114
122
  }
115
123
  }
116
124
 
@@ -14,7 +14,6 @@ import type {ConfigAndCachePath} from './AtlaspackConfigRequest';
14
14
 
15
15
  import fs from 'fs';
16
16
  import invariant from 'assert';
17
- import assert from 'assert';
18
17
  import nullthrows from 'nullthrows';
19
18
  import {instrumentAsync, PluginLogger} from '@atlaspack/logger';
20
19
  import {getFeatureFlag} from '@atlaspack/feature-flags';
@@ -36,19 +35,15 @@ import {
36
35
  createDevDependency,
37
36
  getDevDepRequests,
38
37
  invalidateDevDeps,
39
- runDevDepRequest,
40
38
  } from './DevDepRequest';
41
- import {
42
- loadPluginConfig,
43
- runConfigRequest,
44
- PluginWithLoadConfig,
45
- } from './ConfigRequest';
39
+ import {PluginWithLoadConfig} from './ConfigRequest';
46
40
  import {fromProjectPathRelative} from '../projectPath';
47
41
  import {
48
42
  validateBundles,
49
43
  nameBundle,
50
44
  loadPluginConfigWithDevDeps,
51
45
  runDevDepRequest as runDevDepRequestShared,
46
+ dumpBundleGraphSnapshot,
52
47
  } from './BundleGraphRequestUtils';
53
48
  import createAssetGraphRequestJS from './AssetGraphRequest';
54
49
  import {createAssetGraphRequestRust} from './AssetGraphRequestRust';
@@ -74,9 +69,9 @@ type RunInput = {
74
69
  // TODO: Rename to BundleGraphRequestResult
75
70
  export type BundleGraphResult = {
76
71
  bundleGraph: InternalBundleGraph;
77
- assetGraphBundlingVersion: number;
78
72
  changedAssets: Map<string, Asset>;
79
73
  assetRequests: Array<AssetGroup>;
74
+ didIncrementallyBundle: boolean;
80
75
  };
81
76
 
82
77
  type BundleGraphRequest = {
@@ -214,7 +209,6 @@ export default function createBundleGraphRequest(
214
209
 
215
210
  if (subRequestsInvalid) {
216
211
  assetGraph.safeToIncrementallyBundle = false;
217
- assetGraph.setNeedsBundling();
218
212
  }
219
213
 
220
214
  let configResult = nullthrows(
@@ -283,21 +277,12 @@ class BundlerRunner {
283
277
  this.pluginOptions = new PluginOptions(
284
278
  optionsProxy(this.options, api.invalidateOnOptionChange),
285
279
  );
286
- if (getFeatureFlag('cachePerformanceImprovements')) {
287
- const key = hashString(
280
+ this.cacheKey =
281
+ hashString(
288
282
  `${ATLASPACK_VERSION}:BundleGraph:${
289
283
  JSON.stringify(options.entries) ?? ''
290
284
  }${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`,
291
- );
292
- this.cacheKey = `BundleGraph/${ATLASPACK_VERSION}/${options.mode}/${key}`;
293
- } else {
294
- this.cacheKey =
295
- hashString(
296
- `${ATLASPACK_VERSION}:BundleGraph:${
297
- JSON.stringify(options.entries) ?? ''
298
- }${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`,
299
- ) + '-BundleGraph';
300
- }
285
+ ) + '-BundleGraph';
301
286
  }
302
287
 
303
288
  async loadConfigs() {
@@ -344,7 +329,7 @@ class BundlerRunner {
344
329
  type: 'buildProgress',
345
330
  phase: 'bundling',
346
331
  });
347
-
332
+ let didIncrementallyBundle = false;
348
333
  await this.loadConfigs();
349
334
 
350
335
  let plugin = await this.config.getBundler();
@@ -354,14 +339,10 @@ class BundlerRunner {
354
339
  const previousBundleGraphResult: BundleGraphResult | null | undefined =
355
340
  await this.api.getPreviousResult();
356
341
  const canIncrementallyBundle =
357
- previousBundleGraphResult?.assetGraphBundlingVersion != null &&
358
- graph.canIncrementallyBundle(
359
- previousBundleGraphResult.assetGraphBundlingVersion,
360
- );
342
+ previousBundleGraphResult != null && graph.canIncrementallyBundle();
361
343
 
362
344
  if (graph.safeToIncrementallyBundle && previousBundleGraphResult == null) {
363
345
  graph.safeToIncrementallyBundle = false;
364
- graph.setNeedsBundling();
365
346
  }
366
347
 
367
348
  let internalBundleGraph;
@@ -382,6 +363,7 @@ class BundlerRunner {
382
363
  invariant(changedAssetNode.type === 'asset');
383
364
  internalBundleGraph.updateAsset(changedAssetNode);
384
365
  }
366
+ didIncrementallyBundle = true;
385
367
  } else {
386
368
  internalBundleGraph = InternalBundleGraph.fromAssetGraph(
387
369
  graph,
@@ -415,16 +397,20 @@ class BundlerRunner {
415
397
  }
416
398
 
417
399
  // this the normal bundle workflow (bundle, optimizing, run-times, naming)
418
- await bundler.bundle({
419
- bundleGraph: mutableBundleGraph,
420
- config: this.configs.get(plugin.name)?.result,
421
- options: this.pluginOptions,
422
- logger,
423
- tracer,
400
+ await instrumentAsync('bundle (V2)', async () => {
401
+ await bundler.bundle({
402
+ bundleGraph: mutableBundleGraph,
403
+ config: this.configs.get(plugin.name)?.result,
404
+ options: this.pluginOptions,
405
+ logger,
406
+ tracer,
407
+ });
424
408
  });
425
409
 
426
410
  measurement && measurement.end();
427
411
 
412
+ dumpBundleGraphSnapshot(internalBundleGraph, 'js');
413
+
428
414
  if (this.pluginOptions.mode === 'production') {
429
415
  let optimizeMeasurement;
430
416
  try {
@@ -474,9 +460,9 @@ class BundlerRunner {
474
460
  this.api.storeResult(
475
461
  {
476
462
  bundleGraph: internalBundleGraph,
477
- assetGraphBundlingVersion: graph.getBundlingVersion(),
478
463
  changedAssets: new Map(),
479
464
  assetRequests: [],
465
+ didIncrementallyBundle,
480
466
  },
481
467
  this.cacheKey,
482
468
  );
@@ -560,18 +546,18 @@ class BundlerRunner {
560
546
  this.api.storeResult(
561
547
  {
562
548
  bundleGraph: internalBundleGraph,
563
- assetGraphBundlingVersion: graph.getBundlingVersion(),
564
549
  changedAssets: new Map(),
565
550
  assetRequests: [],
551
+ didIncrementallyBundle,
566
552
  },
567
553
  this.cacheKey,
568
554
  );
569
555
 
570
556
  return {
571
557
  bundleGraph: internalBundleGraph,
572
- assetGraphBundlingVersion: graph.getBundlingVersion(),
573
558
  changedAssets: changedRuntimes,
574
559
  assetRequests,
560
+ didIncrementallyBundle,
575
561
  };
576
562
  }
577
563
  }
@@ -32,6 +32,7 @@ import {
32
32
  nameBundle,
33
33
  loadPluginConfigWithDevDeps,
34
34
  runDevDepRequest,
35
+ dumpBundleGraphSnapshot,
35
36
  } from './BundleGraphRequestUtils';
36
37
  import {toEnvironmentRef} from '../EnvironmentManager';
37
38
  import {getEnvironmentHash} from '../Environment';
@@ -109,6 +110,8 @@ export default function createBundleGraphRequestRust(
109
110
  () => getBundleGraph(serializedBundleGraph),
110
111
  );
111
112
 
113
+ dumpBundleGraphSnapshot(bundleGraph, 'rust');
114
+
112
115
  const runner = new NativeBundlerRunner(
113
116
  {api, options} as any,
114
117
  input.optionsRef,
@@ -181,10 +184,9 @@ export default function createBundleGraphRequestRust(
181
184
 
182
185
  return {
183
186
  bundleGraph,
184
- // Not accurate yet — ok for now.
185
- assetGraphBundlingVersion: 0,
186
187
  changedAssets: changedRuntimes,
187
188
  assetRequests: [],
189
+ didIncrementallyBundle: false,
188
190
  };
189
191
  },
190
192
  input,
@@ -17,11 +17,13 @@ import type {
17
17
  } from '../types';
18
18
 
19
19
  import assert from 'assert';
20
+ import fs from 'fs';
20
21
  import nullthrows from 'nullthrows';
22
+ import path from 'path';
21
23
  import {PluginLogger} from '@atlaspack/logger';
22
24
  import ThrowableDiagnostic, {errorToDiagnostic} from '@atlaspack/diagnostic';
23
25
  import {unique, setSymmetricDifference} from '@atlaspack/utils';
24
- import InternalBundleGraph from '../BundleGraph';
26
+ import InternalBundleGraph, {bundleGraphEdgeTypes} from '../BundleGraph';
25
27
  import BundleGraph from '../public/BundleGraph';
26
28
  import {Bundle, NamedBundle} from '../public/Bundle';
27
29
  import PluginOptions from '../public/PluginOptions';
@@ -66,6 +68,160 @@ export function validateBundles(bundleGraph: InternalBundleGraph): void {
66
68
  );
67
69
  }
68
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
+ export function dumpBundleGraphSnapshot(
78
+ bundleGraph: InternalBundleGraph,
79
+ variant: 'js' | 'rust',
80
+ ): void {
81
+ let outDir = process.env.ATLASPACK_DUMP_BUNDLE_GRAPH;
82
+ if (!outDir) return;
83
+
84
+ let filename =
85
+ variant === 'js' ? 'bundle-graph-js.json' : 'bundle-graph-rust.json';
86
+ let outPath = path.join(outDir, filename);
87
+
88
+ fs.mkdirSync(outDir, {recursive: true});
89
+
90
+ let bundles = bundleGraph.getBundles();
91
+ let bundlesSnapshot = bundles
92
+ .map((bundle) => {
93
+ let bundleNodeId = bundleGraph._graph.getNodeIdByContentKey(bundle.id);
94
+ let containedAssetNodeIds = bundleGraph._graph.getNodeIdsConnectedFrom(
95
+ bundleNodeId,
96
+ bundleGraphEdgeTypes.contains,
97
+ );
98
+ let containedAssets = containedAssetNodeIds
99
+ .map((nodeId) => bundleGraph._graph.getNode(nodeId))
100
+ .flatMap((node) => {
101
+ if (node?.type !== 'asset') return [];
102
+ return [
103
+ {
104
+ id: node.value.id,
105
+ filePath: fromProjectPathRelative(node.value.filePath),
106
+ },
107
+ ];
108
+ })
109
+ .sort((a, b) => a.filePath.localeCompare(b.filePath));
110
+
111
+ // Resolve mainEntry and entry asset file paths
112
+ let mainEntryPath: string | null = null;
113
+ let entryAssetPaths: string[] = [];
114
+ if (bundle.mainEntryId) {
115
+ let mainEntryNodeId = bundleGraph._graph.getNodeIdByContentKey(
116
+ bundle.mainEntryId,
117
+ );
118
+ let mainEntryNode = bundleGraph._graph.getNode(mainEntryNodeId);
119
+ if (mainEntryNode?.type === 'asset') {
120
+ mainEntryPath = fromProjectPathRelative(mainEntryNode.value.filePath);
121
+ }
122
+ }
123
+ for (let entryId of bundle.entryAssetIds) {
124
+ let entryNodeId = bundleGraph._graph.getNodeIdByContentKey(entryId);
125
+ let entryNode = bundleGraph._graph.getNode(entryNodeId);
126
+ if (entryNode?.type === 'asset') {
127
+ entryAssetPaths.push(
128
+ fromProjectPathRelative(entryNode.value.filePath),
129
+ );
130
+ }
131
+ }
132
+ entryAssetPaths.sort();
133
+
134
+ return {
135
+ id: bundle.id,
136
+ type: bundle.type,
137
+ bundleBehavior: bundle.bundleBehavior ?? null,
138
+ needsStableName: bundle.needsStableName,
139
+ isSplittable: bundle.isSplittable,
140
+ isPlaceholder: bundle.isPlaceholder,
141
+ mainEntryPath,
142
+ entryAssetPaths,
143
+ assets: containedAssets.map((a) => a.filePath),
144
+ };
145
+ })
146
+ .sort((a, b) => {
147
+ // Sort by mainEntryPath first, then by sorted assets as tiebreaker
148
+ let aKey = a.mainEntryPath || a.assets.join(',');
149
+ let bKey = b.mainEntryPath || b.assets.join(',');
150
+ return aKey.localeCompare(bKey);
151
+ });
152
+
153
+ let bundleGroupsSnapshot = bundleGraph._graph.nodes
154
+ .flatMap((node) => {
155
+ if (node?.type !== 'bundle_group') return [];
156
+
157
+ let bundleGroup = node.value;
158
+
159
+ // Resolve entry asset file path
160
+ let entryAssetPath: string | null = null;
161
+ try {
162
+ let entryNodeId = bundleGraph._graph.getNodeIdByContentKey(
163
+ bundleGroup.entryAssetId,
164
+ );
165
+ let entryNode = bundleGraph._graph.getNode(entryNodeId);
166
+ if (entryNode?.type === 'asset') {
167
+ entryAssetPath = fromProjectPathRelative(entryNode.value.filePath);
168
+ }
169
+ } catch {
170
+ // Content key not found
171
+ }
172
+
173
+ let bundlesInGroup = bundleGraph.getBundlesInBundleGroup(bundleGroup);
174
+ let bundlePaths = bundlesInGroup
175
+ .map((b) => {
176
+ // Use mainEntry file path if available, otherwise bundle id as fallback
177
+ if (b.mainEntryId) {
178
+ try {
179
+ let nodeId = bundleGraph._graph.getNodeIdByContentKey(
180
+ b.mainEntryId,
181
+ );
182
+ let node = bundleGraph._graph.getNode(nodeId);
183
+ if (node?.type === 'asset') {
184
+ return fromProjectPathRelative(node.value.filePath);
185
+ }
186
+ } catch {
187
+ // fallback
188
+ }
189
+ }
190
+ return `[bundle:${b.id}]`;
191
+ })
192
+ .sort();
193
+
194
+ return [
195
+ {
196
+ entryAssetPath:
197
+ entryAssetPath ?? `[unknown:${bundleGroup.entryAssetId}]`,
198
+ bundlePaths,
199
+ },
200
+ ];
201
+ })
202
+ .sort((a, b) => a.entryAssetPath.localeCompare(b.entryAssetPath));
203
+
204
+ let totalAssets = bundleGraph._graph.nodes.filter(
205
+ (node) => node?.type === 'asset',
206
+ ).length;
207
+
208
+ let snapshot = {
209
+ version: 1,
210
+ variant,
211
+ stats: {
212
+ totalBundles: bundlesSnapshot.length,
213
+ totalBundleGroups: bundleGroupsSnapshot.length,
214
+ totalAssets,
215
+ },
216
+ bundles: bundlesSnapshot,
217
+ bundleGroups: bundleGroupsSnapshot,
218
+ };
219
+
220
+ fs.writeFileSync(outPath, JSON.stringify(snapshot, null, 2), 'utf8');
221
+ // eslint-disable-next-line no-console
222
+ console.log(`[BundleGraphSnapshot] Wrote ${variant} snapshot to ${outPath}`);
223
+ }
224
+
69
225
  /**
70
226
  * Names a bundle by running through the configured namers until one returns a name.
71
227
  */
@@ -72,7 +72,7 @@ async function run({input, api, farm, rustAtlaspack}: RunInput<BundleInfo>) {
72
72
  bundle.type === 'js'
73
73
  ) {
74
74
  // Once this actually does something, the code below will be in an `else` block (i.e. we'll only run one or the other)
75
- let result = await rustAtlaspack.package(bundle.id);
75
+ let result = await rustAtlaspack.package(bundle.id, {inlineRequires: true});
76
76
  let error: Diagnostic | null = null;
77
77
  [packagingResult, error] = result;
78
78
  if (error) {
@@ -332,6 +332,7 @@ export class TargetResolver {
332
332
  publicUrl:
333
333
  descriptor.publicUrl ??
334
334
  this.options.defaultTargetOptions.publicUrl,
335
+ inlineRequires: descriptor.inlineRequires ?? false,
335
336
  env: createEnvironment({
336
337
  engines: descriptor.engines,
337
338
  context: descriptor.context,
@@ -426,6 +427,7 @@ export class TargetResolver {
426
427
  this.options.serveOptions.distDir,
427
428
  ),
428
429
  publicUrl: this.options.defaultTargetOptions.publicUrl ?? '/',
430
+ inlineRequires: false,
429
431
  env: createEnvironment({
430
432
  context: 'browser',
431
433
  engines: {
@@ -930,6 +932,7 @@ export class TargetResolver {
930
932
  distEntry,
931
933
  publicUrl:
932
934
  descriptor.publicUrl ?? this.options.defaultTargetOptions.publicUrl,
935
+ inlineRequires: descriptor.inlineRequires ?? false,
933
936
  env: createEnvironment({
934
937
  engines: descriptor.engines ?? pkgEngines,
935
938
  // @ts-expect-error TS2322
@@ -1131,6 +1134,7 @@ export class TargetResolver {
1131
1134
  distEntry,
1132
1135
  publicUrl:
1133
1136
  descriptor.publicUrl ?? this.options.defaultTargetOptions.publicUrl,
1137
+ inlineRequires: descriptor.inlineRequires ?? false,
1134
1138
  env: createEnvironment({
1135
1139
  engines: descriptor.engines ?? pkgEngines,
1136
1140
  context: descriptor.context,
@@ -1205,6 +1209,7 @@ export class TargetResolver {
1205
1209
  path.join(pkgDir, DEFAULT_DIST_DIRNAME),
1206
1210
  ),
1207
1211
  publicUrl: this.options.defaultTargetOptions.publicUrl,
1212
+ inlineRequires: false,
1208
1213
  env: createEnvironment({
1209
1214
  engines: pkgEngines,
1210
1215
  // @ts-expect-error TS2322