@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
@@ -34,13 +34,6 @@ function _buildCache() {
34
34
  };
35
35
  return data;
36
36
  }
37
- function _cache() {
38
- const data = require("@atlaspack/cache");
39
- _cache = function () {
40
- return data;
41
- };
42
- return data;
43
- }
44
37
  function _featureFlags() {
45
38
  const data = require("@atlaspack/feature-flags");
46
39
  _featureFlags = function () {
@@ -56,7 +49,7 @@ function _graph() {
56
49
  return data;
57
50
  }
58
51
  function _logger() {
59
- const data = _interopRequireWildcard(require("@atlaspack/logger"));
52
+ const data = _interopRequireDefault(require("@atlaspack/logger"));
60
53
  _logger = function () {
61
54
  return data;
62
55
  };
@@ -831,10 +824,8 @@ class RequestTracker {
831
824
  return result;
832
825
  } else if (node.resultCacheKey != null && ifMatch == null) {
833
826
  let key = node.resultCacheKey;
834
- if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
835
- (0, _assert().default)(this.options.cache.hasLargeBlob(key));
836
- }
837
- let cachedResult = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? (0, _nullthrows().default)(await this.options.cache.get(key)) : (0, _buildCache().deserialize)(await this.options.cache.getLargeBlob(key));
827
+ (0, _assert().default)(this.options.cache.hasLargeBlob(key));
828
+ let cachedResult = (0, _buildCache().deserialize)(await this.options.cache.getLargeBlob(key));
838
829
  node.result = cachedResult;
839
830
  return cachedResult;
840
831
  }
@@ -1002,27 +993,13 @@ class RequestTracker {
1002
993
  };
1003
994
  }
1004
995
  async writeToCache(signal) {
1005
- const options = this.options;
1006
- async function runCacheImprovements(newPath, oldPath) {
1007
- if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
1008
- (0, _assert().default)(options.cache instanceof _cache().LMDBLiteCache);
1009
- const result = await newPath(options.cache);
1010
- return result;
1011
- } else {
1012
- const result = await oldPath();
1013
- return result;
1014
- }
1015
- }
1016
996
  let cacheKey = getCacheKey(this.options);
1017
- let requestGraphKey = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? `${cacheKey}/RequestGraph` : `requestGraph-${cacheKey}`;
1018
- let snapshotKey = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? `${cacheKey}/snapshot` : `snapshot-${cacheKey}`;
997
+ let requestGraphKey = `requestGraph-${cacheKey}`;
998
+ let snapshotKey = `snapshot-${cacheKey}`;
1019
999
  if (this.options.shouldDisableCache) {
1020
1000
  return;
1021
1001
  }
1022
1002
  let total = 0;
1023
- await runCacheImprovements(async cache => {
1024
- await cache.getNativeRef().startWriteTransaction();
1025
- }, () => Promise.resolve());
1026
1003
  try {
1027
1004
  (0, _ReporterRunner.report)({
1028
1005
  type: 'cache',
@@ -1031,7 +1008,7 @@ class RequestTracker {
1031
1008
  size: this.graph.nodes.length
1032
1009
  });
1033
1010
  if ((0, _featureFlags().getFeatureFlag)('environmentDeduplication')) {
1034
- await (0, _EnvironmentManager.writeEnvironmentsToCache)(options.cache);
1011
+ await (0, _EnvironmentManager.writeEnvironmentsToCache)(this.options.cache);
1035
1012
  }
1036
1013
  let serialisedGraph = this.graph.serialize();
1037
1014
 
@@ -1041,16 +1018,9 @@ class RequestTracker {
1041
1018
  if (signal !== null && signal !== void 0 && signal.aborted) {
1042
1019
  throw new Error('Serialization was aborted');
1043
1020
  }
1044
- await runCacheImprovements(cache => {
1045
- (0, _logger().instrument)(`RequestTracker::writeToCache::cache.put(${key})`, () => {
1046
- cache.getNativeRef().putNoConfirm(key, (0, _buildCache().serialize)(contents));
1047
- });
1048
- return Promise.resolve();
1049
- }, async () => {
1050
- await this.options.cache.setLargeBlob(key, (0, _buildCache().serialize)(contents), signal ? {
1051
- signal: signal
1052
- } : undefined);
1053
- });
1021
+ await this.options.cache.setLargeBlob(key, (0, _buildCache().serialize)(contents), signal ? {
1022
+ signal: signal
1023
+ } : undefined);
1054
1024
  total += 1;
1055
1025
  (0, _ReporterRunner.report)({
1056
1026
  type: 'cache',
@@ -1105,23 +1075,12 @@ class RequestTracker {
1105
1075
  nodeCountsPerBlob,
1106
1076
  nodes: undefined
1107
1077
  });
1108
- await runCacheImprovements(() => serialiseAndSet(`${cacheKey}/cache_metadata`, {
1109
- version: _constants.ATLASPACK_VERSION,
1110
- entries: this.options.entries,
1111
- mode: this.options.mode,
1112
- shouldBuildLazily: this.options.shouldBuildLazily,
1113
- watchBackend: this.options.watchBackend
1114
- }), () => Promise.resolve());
1115
1078
  let opts = getWatcherOptions(this.options);
1116
1079
  let snapshotPath = _path2().default.join(this.options.cacheDir, snapshotKey + '.txt');
1117
1080
  await this.options.outputFS.writeSnapshot(this.options.watchDir, snapshotPath, opts);
1118
1081
  } catch (err) {
1119
1082
  // If we have aborted, ignore the error and continue
1120
1083
  if (!(signal !== null && signal !== void 0 && signal.aborted)) throw err;
1121
- } finally {
1122
- await runCacheImprovements(async cache => {
1123
- await cache.getNativeRef().commitWriteTransaction();
1124
- }, () => Promise.resolve());
1125
1084
  }
1126
1085
  (0, _ReporterRunner.report)({
1127
1086
  type: 'cache',
@@ -1160,30 +1119,17 @@ function getWatcherOptions({
1160
1119
  };
1161
1120
  }
1162
1121
  function getCacheKey(options) {
1163
- if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
1164
- const hash = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:${JSON.stringify(options.entries)}:${options.mode}:${options.shouldBuildLazily ? 'lazy' : 'eager'}:${options.watchBackend ?? ''}`);
1165
- return `RequestTracker/${_constants.ATLASPACK_VERSION}/${hash}`;
1166
- }
1167
1122
  return (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:${JSON.stringify(options.entries)}:${options.mode}:${options.shouldBuildLazily ? 'lazy' : 'eager'}:${options.watchBackend ?? ''}`);
1168
1123
  }
1169
1124
  function getRequestGraphNodeKey(index, cacheKey) {
1170
- if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
1171
- return `${cacheKey}/RequestGraph/nodes/${index}`;
1172
- }
1173
1125
  return `requestGraph-nodes-${index}-${cacheKey}`;
1174
1126
  }
1175
1127
  async function readAndDeserializeRequestGraph(cache, requestGraphKey, cacheKey) {
1176
1128
  let bufferLength = 0;
1177
1129
  const getAndDeserialize = async key => {
1178
- if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
1179
- const buffer = await cache.getBlob(key);
1180
- bufferLength += Buffer.byteLength(buffer);
1181
- return (0, _buildCache().deserialize)(buffer);
1182
- } else {
1183
- const buffer = await cache.getLargeBlob(key);
1184
- bufferLength += Buffer.byteLength(buffer);
1185
- return (0, _buildCache().deserialize)(buffer);
1186
- }
1130
+ const buffer = await cache.getLargeBlob(key);
1131
+ bufferLength += Buffer.byteLength(buffer);
1132
+ return (0, _buildCache().deserialize)(buffer);
1187
1133
  };
1188
1134
  let serializedRequestGraph = await getAndDeserialize(requestGraphKey);
1189
1135
  let nodePromises = serializedRequestGraph.nodeCountsPerBlob.map(
@@ -1207,9 +1153,9 @@ async function loadRequestGraph(options) {
1207
1153
  return new RequestGraph();
1208
1154
  }
1209
1155
  let cacheKey = getCacheKey(options);
1210
- let requestGraphKey = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? `${cacheKey}/RequestGraph` : `requestGraph-${cacheKey}`;
1156
+ let requestGraphKey = `requestGraph-${cacheKey}`;
1211
1157
  let timeout;
1212
- const snapshotKey = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? `${cacheKey}/snapshot` : `snapshot-${cacheKey}`;
1158
+ const snapshotKey = `snapshot-${cacheKey}`;
1213
1159
  const snapshotPath = _path2().default.join(options.cacheDir, snapshotKey + '.txt');
1214
1160
  const commonMeta = {
1215
1161
  cacheKey,
@@ -1232,7 +1178,7 @@ async function loadRequestGraph(options) {
1232
1178
  if ((0, _featureFlags().getFeatureFlag)('environmentDeduplication')) {
1233
1179
  await (0, _EnvironmentManager.loadEnvironmentsFromCache)(options.cache);
1234
1180
  }
1235
- const hasRequestGraphInCache = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? await options.cache.has(requestGraphKey) : await options.cache.hasLargeBlob(requestGraphKey);
1181
+ const hasRequestGraphInCache = await options.cache.hasLargeBlob(requestGraphKey);
1236
1182
  if (hasRequestGraphInCache) {
1237
1183
  try {
1238
1184
  let {
@@ -104,6 +104,9 @@ const PACKAGE_DESCRIPTOR_SCHEMA = exports.PACKAGE_DESCRIPTOR_SCHEMA = {
104
104
  additionalProperties: {
105
105
  type: 'string'
106
106
  }
107
+ },
108
+ inlineRequires: {
109
+ type: 'boolean'
107
110
  }
108
111
  },
109
112
  additionalProperties: false
@@ -53,13 +53,6 @@ var _assetUtils = require("./assetUtils");
53
53
  var _types = require("./types");
54
54
  var _utils2 = require("./utils");
55
55
  var _projectPath = require("./projectPath");
56
- function _featureFlags() {
57
- const data = require("@atlaspack/feature-flags");
58
- _featureFlags = function () {
59
- return data;
60
- };
61
- return data;
62
- }
63
56
  var _EnvironmentManager = require("./EnvironmentManager");
64
57
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
65
58
  class UncommittedAsset {
@@ -265,10 +258,6 @@ class UncommittedAsset {
265
258
  this.value.astGenerator = null;
266
259
  }
267
260
  getCacheKey(key) {
268
- if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
269
- const filePath = (0, _projectPath.fromProjectPathRelative)(this.value.filePath);
270
- return `Asset/${_constants.ATLASPACK_VERSION}/${filePath}/${this.value.id}/${key}`;
271
- }
272
261
  return (0, _rust().hashString)(_constants.ATLASPACK_VERSION + key + this.value.id);
273
262
  }
274
263
  addDependency(opts) {
@@ -84,8 +84,12 @@ class AtlaspackV3 {
84
84
  } = bundleGraph.serializeForNative();
85
85
  return (0, _rust().atlaspackNapiLoadBundleGraph)(this._atlaspack_napi, nodesJson, edges, publicIdByAssetId, environmentsJson);
86
86
  }
87
- package(bundleId) {
88
- return (0, _rust().atlaspackNapiPackage)(this._atlaspack_napi, bundleId);
87
+ updateBundleGraph(bundleGraph, changedAssetIds) {
88
+ const nodesJson = bundleGraph.serializeAssetNodesForNative(changedAssetIds);
89
+ return (0, _rust().atlaspackNapiUpdateBundleGraph)(this._atlaspack_napi, nodesJson);
90
+ }
91
+ package(bundleId, options) {
92
+ return (0, _rust().atlaspackNapiPackage)(this._atlaspack_napi, bundleId, options);
89
93
  }
90
94
  async respondToFsEvents(events) {
91
95
  // @ts-expect-error TS2488
@@ -26,13 +26,6 @@ function _nullthrows() {
26
26
  };
27
27
  return data;
28
28
  }
29
- function _featureFlags() {
30
- const data = require("@atlaspack/feature-flags");
31
- _featureFlags = function () {
32
- return data;
33
- };
34
- return data;
35
- }
36
29
  function _utils() {
37
30
  const data = require("@atlaspack/utils");
38
31
  _utils = function () {
@@ -76,7 +69,9 @@ function createAssetGraphRequest(requestInput) {
76
69
  let assetGraphRequest = await builder.build();
77
70
 
78
71
  // early break for incremental bundling if production or flag is off;
79
- assetGraphRequest.assetGraph.setDisableIncrementalBundling(!input.options.shouldBundleIncrementally || input.options.mode === 'production');
72
+ if (!input.options.shouldBundleIncrementally || input.options.mode === 'production') {
73
+ assetGraphRequest.assetGraph.safeToIncrementallyBundle = false;
74
+ }
80
75
  if (!input.options.shouldBundleIncrementally || input.options.mode === 'production') {
81
76
  assetGraphRequest.assetGraph.safeToIncrementallyBundle = false;
82
77
  }
@@ -125,12 +120,7 @@ class AssetGraphBuilder {
125
120
  this.lazyIncludes = lazyIncludes ?? [];
126
121
  this.lazyExcludes = lazyExcludes ?? [];
127
122
  this.skipSymbolProp = input.skipSymbolProp ?? false;
128
- if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
129
- const key = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}${name}${JSON.stringify(entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`);
130
- this.cacheKey = `AssetGraph/${_constants.ATLASPACK_VERSION}/${options.mode}/${key}`;
131
- } else {
132
- this.cacheKey = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}${name}${JSON.stringify(entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-AssetGraph';
133
- }
123
+ this.cacheKey = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}${name}${JSON.stringify(entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-AssetGraph';
134
124
  this.isSingleChangeRebuild = api.getInvalidSubRequests()
135
125
  // @ts-expect-error TS2367
136
126
  .filter(req => req.requestType === 'asset_request').length === 1;
@@ -390,7 +380,6 @@ class AssetGraphBuilder {
390
380
  let didEntriesChange = prevEntries.length !== currentEntries.length || prevEntries.every((entryId, index) => entryId === currentEntries[index]);
391
381
  if (didEntriesChange) {
392
382
  this.assetGraph.safeToIncrementallyBundle = false;
393
- this.assetGraph.setNeedsBundling();
394
383
  }
395
384
  }
396
385
  }
@@ -439,12 +428,10 @@ class AssetGraphBuilder {
439
428
  (0, _assert().default)(otherAsset.type === 'asset');
440
429
  if (!this._areDependenciesEqualForAssets(asset, otherAsset.value)) {
441
430
  this.assetGraph.safeToIncrementallyBundle = false;
442
- this.assetGraph.setNeedsBundling();
443
431
  }
444
432
  } else {
445
433
  // adding a new entry or dependency
446
434
  this.assetGraph.safeToIncrementallyBundle = false;
447
- this.assetGraph.setNeedsBundling();
448
435
  }
449
436
  }
450
437
  this.changedAssets.set(asset.id, asset);
@@ -453,7 +440,6 @@ class AssetGraphBuilder {
453
440
  this.assetGraph.resolveAssetGroup(input, assets, request.id);
454
441
  } else {
455
442
  this.assetGraph.safeToIncrementallyBundle = false;
456
- this.assetGraph.setNeedsBundling();
457
443
  }
458
444
  this.isSingleChangeRebuild = false;
459
445
  }
@@ -195,13 +195,57 @@ function getAssetGraph(serializedGraph, prevAssetGraph) {
195
195
  }
196
196
  return envId;
197
197
  };
198
- function updateNode(newNode, isUpdateNode) {
198
+ function describeNode(node) {
199
+ const base = {
200
+ type: node.type,
201
+ id: node.id
202
+ };
203
+ if (node.type === 'asset') {
204
+ return {
205
+ ...base,
206
+ filePath: node.value.filePath,
207
+ fileType: node.value.type,
208
+ pipeline: node.value.pipeline
209
+ };
210
+ } else if (node.type === 'dependency') {
211
+ return {
212
+ ...base,
213
+ specifier: node.value.specifier,
214
+ specifierType: node.value.specifierType,
215
+ sourceAssetId: node.value.sourceAssetId,
216
+ sourcePath: node.value.sourcePath
217
+ };
218
+ }
219
+ return base;
220
+ }
221
+ function updateNode(newNode, isUpdateNode, index) {
199
222
  if (isUpdateNode) {
200
223
  let existingNode = graph.getNodeByContentKey(newNode.id);
201
224
  (0, _assert().default)(existingNode && existingNode.type === newNode.type);
202
225
  Object.assign(existingNode, newNode);
203
226
  } else {
204
- graph.addNodeByContentKey(newNode.id, newNode);
227
+ try {
228
+ graph.addNodeByContentKey(newNode.id, newNode);
229
+ } catch (e) {
230
+ if (e instanceof Error && e.message.includes('already has content key')) {
231
+ let existingNode = graph.getNodeByContentKey(newNode.id);
232
+ let diagnostics = {
233
+ contentKey: newNode.id,
234
+ newNode: describeNode(newNode),
235
+ existingNode: existingNode ? describeNode(existingNode) : null,
236
+ iterationIndex: index,
237
+ totalSerializedNodes: nodesCount,
238
+ newNodesCount: serializedGraph.nodes.length,
239
+ updatesCount: serializedGraph.updates.length,
240
+ edgesCount: serializedGraph.edges.length,
241
+ hadPreviousGraph: !!prevAssetGraph,
242
+ safeToSkipBundling: serializedGraph.safeToSkipBundling,
243
+ graphNodeCount: graph._contentKeyToNodeId.size
244
+ };
245
+ throw new Error(`Graph already has content key '${newNode.id}'. Diagnostics: ${JSON.stringify(diagnostics, null, 2)}`);
246
+ }
247
+ throw e;
248
+ }
205
249
  }
206
250
  }
207
251
  let nodeTypeSwitchoverIndex = serializedGraph.nodes.length;
@@ -246,7 +290,7 @@ function getAssetGraph(serializedGraph, prevAssetGraph) {
246
290
  usedSymbolsUpDirty: true,
247
291
  value: asset
248
292
  };
249
- updateNode(assetNode, isUpdateNode);
293
+ updateNode(assetNode, isUpdateNode, index);
250
294
  } else if (node.type === 'dependency') {
251
295
  let {
252
296
  dependency,
@@ -265,12 +309,12 @@ function getAssetGraph(serializedGraph, prevAssetGraph) {
265
309
  let usedSymbolsUp = new Map();
266
310
  if (node.used_symbols_up) {
267
311
  for (let usedSymbol of node.used_symbols_up) {
268
- // Transform Rust UsedSymbol { symbol: Symbol, asset: string }
269
- // to JS format { symbol: string, asset: string } where symbol is the exported name
312
+ // Transform Rust UsedSymbol { symbol: Symbol, asset: string, resolved_symbol: string }
313
+ // to JS format { symbol: string, asset: string } where symbol is the resolved name
270
314
  const exportedName = usedSymbol.symbol.exported;
271
315
  usedSymbolsUp.set(exportedName, {
272
316
  asset: usedSymbol.asset,
273
- symbol: exportedName
317
+ symbol: usedSymbol.resolved_symbol ?? exportedName
274
318
  });
275
319
  }
276
320
  }
@@ -292,7 +336,7 @@ function getAssetGraph(serializedGraph, prevAssetGraph) {
292
336
  usedSymbolsUpDirtyUp: true,
293
337
  value: dependency
294
338
  };
295
- updateNode(depNode, isUpdateNode);
339
+ updateNode(depNode, isUpdateNode, index);
296
340
  }
297
341
  }
298
342
  if (!reuseEdges) {
@@ -62,7 +62,8 @@ async function run({
62
62
  let {
63
63
  bundleGraph,
64
64
  changedAssets,
65
- assetRequests
65
+ assetRequests,
66
+ didIncrementallyBundle
66
67
  } = await api.runRequest(bundleGraphRequest, {
67
68
  force: Boolean(rustAtlaspack) || options.shouldBuildLazily && requestedAssetIds.size > 0
68
69
  });
@@ -75,7 +76,12 @@ async function run({
75
76
  }
76
77
  });
77
78
  if (hasSupportedTarget) {
78
- await rustAtlaspack.loadBundleGraph(bundleGraph);
79
+ if (didIncrementallyBundle) {
80
+ const changedAssetIds = Array.from(changedAssets.keys());
81
+ await rustAtlaspack.updateBundleGraph(bundleGraph, changedAssetIds);
82
+ } else {
83
+ await rustAtlaspack.loadBundleGraph(bundleGraph);
84
+ }
79
85
  }
80
86
  }
81
87
 
@@ -187,7 +187,6 @@ function createBundleGraphRequest(input) {
187
187
  let subRequestsInvalid = Boolean(invalidateReason & _constants.OPTION_CHANGE) || input.api.getSubRequests().some(req => !input.api.canSkipSubrequest(req.id));
188
188
  if (subRequestsInvalid) {
189
189
  assetGraph.safeToIncrementallyBundle = false;
190
- assetGraph.setNeedsBundling();
191
190
  }
192
191
  let configResult = (0, _nullthrows().default)(await input.api.runRequest((0, _AtlaspackConfigRequest.default)()));
193
192
  (0, _utils.assertSignalNotAborted)(signal);
@@ -230,12 +229,7 @@ class BundlerRunner {
230
229
  this.devDepRequests = new Map();
231
230
  this.configs = new Map();
232
231
  this.pluginOptions = new _PluginOptions.default((0, _utils.optionsProxy)(this.options, api.invalidateOnOptionChange));
233
- if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
234
- const key = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`);
235
- this.cacheKey = `BundleGraph/${_constants.ATLASPACK_VERSION}/${options.mode}/${key}`;
236
- } else {
237
- this.cacheKey = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-BundleGraph';
238
- }
232
+ this.cacheKey = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-BundleGraph';
239
233
  }
240
234
  async loadConfigs() {
241
235
  // Load all configs up front so we can use them in the cache key
@@ -265,6 +259,7 @@ class BundlerRunner {
265
259
  type: 'buildProgress',
266
260
  phase: 'bundling'
267
261
  });
262
+ let didIncrementallyBundle = false;
268
263
  await this.loadConfigs();
269
264
  let plugin = await this.config.getBundler();
270
265
  let {
@@ -275,10 +270,9 @@ class BundlerRunner {
275
270
 
276
271
  // if a previous asset graph hash is passed in, check if the bundle graph is also available
277
272
  const previousBundleGraphResult = await this.api.getPreviousResult();
278
- const canIncrementallyBundle = (previousBundleGraphResult === null || previousBundleGraphResult === void 0 ? void 0 : previousBundleGraphResult.assetGraphBundlingVersion) != null && graph.canIncrementallyBundle(previousBundleGraphResult.assetGraphBundlingVersion);
273
+ const canIncrementallyBundle = previousBundleGraphResult != null && graph.canIncrementallyBundle();
279
274
  if (graph.safeToIncrementallyBundle && previousBundleGraphResult == null) {
280
275
  graph.safeToIncrementallyBundle = false;
281
- graph.setNeedsBundling();
282
276
  }
283
277
  let internalBundleGraph;
284
278
  let logger = new (_logger().PluginLogger)({
@@ -297,8 +291,8 @@ class BundlerRunner {
297
291
  (0, _assert().default)(changedAssetNode.type === 'asset');
298
292
  internalBundleGraph.updateAsset(changedAssetNode);
299
293
  }
294
+ didIncrementallyBundle = true;
300
295
  } else {
301
- var _this$configs$get;
302
296
  internalBundleGraph = _BundleGraph.default.fromAssetGraph(graph, this.options.mode === 'production');
303
297
  (0, _assert().default)(internalBundleGraph != null); // ensures the graph was created
304
298
 
@@ -314,14 +308,18 @@ class BundlerRunner {
314
308
  }
315
309
 
316
310
  // this the normal bundle workflow (bundle, optimizing, run-times, naming)
317
- await bundler.bundle({
318
- bundleGraph: mutableBundleGraph,
319
- config: (_this$configs$get = this.configs.get(plugin.name)) === null || _this$configs$get === void 0 ? void 0 : _this$configs$get.result,
320
- options: this.pluginOptions,
321
- logger,
322
- tracer
311
+ await (0, _logger().instrumentAsync)('bundle (V2)', async () => {
312
+ var _this$configs$get;
313
+ await bundler.bundle({
314
+ bundleGraph: mutableBundleGraph,
315
+ config: (_this$configs$get = this.configs.get(plugin.name)) === null || _this$configs$get === void 0 ? void 0 : _this$configs$get.result,
316
+ options: this.pluginOptions,
317
+ logger,
318
+ tracer
319
+ });
323
320
  });
324
321
  measurement && measurement.end();
322
+ (0, _BundleGraphRequestUtils.dumpBundleGraphSnapshot)(internalBundleGraph, 'js');
325
323
  if (this.pluginOptions.mode === 'production') {
326
324
  let optimizeMeasurement;
327
325
  try {
@@ -361,9 +359,9 @@ class BundlerRunner {
361
359
  if (internalBundleGraph != null) {
362
360
  this.api.storeResult({
363
361
  bundleGraph: internalBundleGraph,
364
- assetGraphBundlingVersion: graph.getBundlingVersion(),
365
362
  changedAssets: new Map(),
366
- assetRequests: []
363
+ assetRequests: [],
364
+ didIncrementallyBundle
367
365
  }, this.cacheKey);
368
366
  }
369
367
  throw new (_diagnostic().default)({
@@ -417,15 +415,15 @@ class BundlerRunner {
417
415
  internalBundleGraph._graph, 'after_runtimes', _BundleGraph.bundleGraphEdgeTypes);
418
416
  this.api.storeResult({
419
417
  bundleGraph: internalBundleGraph,
420
- assetGraphBundlingVersion: graph.getBundlingVersion(),
421
418
  changedAssets: new Map(),
422
- assetRequests: []
419
+ assetRequests: [],
420
+ didIncrementallyBundle
423
421
  }, this.cacheKey);
424
422
  return {
425
423
  bundleGraph: internalBundleGraph,
426
- assetGraphBundlingVersion: graph.getBundlingVersion(),
427
424
  changedAssets: changedRuntimes,
428
- assetRequests
425
+ assetRequests,
426
+ didIncrementallyBundle
429
427
  };
430
428
  }
431
429
  }
@@ -96,6 +96,7 @@ function createBundleGraphRequestRust(input) {
96
96
  bundleGraph,
97
97
  changedAssets
98
98
  } = (0, _logger().instrument)('atlaspack_v3_getBundleGraph', () => getBundleGraph(serializedBundleGraph));
99
+ (0, _BundleGraphRequestUtils.dumpBundleGraphSnapshot)(bundleGraph, 'rust');
99
100
  const runner = new NativeBundlerRunner({
100
101
  api,
101
102
  options
@@ -145,10 +146,9 @@ function createBundleGraphRequestRust(input) {
145
146
  }
146
147
  return {
147
148
  bundleGraph,
148
- // Not accurate yet — ok for now.
149
- assetGraphBundlingVersion: 0,
150
149
  changedAssets: changedRuntimes,
151
- assetRequests: []
150
+ assetRequests: [],
151
+ didIncrementallyBundle: false
152
152
  };
153
153
  },
154
154
  input