@atlaspack/core 2.16.2-dev.14 → 2.16.2-dev.55

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 (37) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/lib/Atlaspack.js +10 -2
  3. package/lib/AtlaspackConfig.schema.js +7 -1
  4. package/lib/BundleGraph.js +2 -100
  5. package/lib/PackagerRunner.js +44 -9
  6. package/lib/RequestTracker.js +326 -121
  7. package/lib/Transformation.js +2 -2
  8. package/lib/UncommittedAsset.js +17 -0
  9. package/lib/atlaspack-v3/worker/compat/environment.js +2 -2
  10. package/lib/atlaspack-v3/worker/compat/mutable-asset.js +6 -6
  11. package/lib/atlaspack-v3/worker/compat/plugin-config.js +5 -5
  12. package/lib/atlaspack-v3/worker/index.js +3 -0
  13. package/lib/atlaspack-v3/worker/worker.js +8 -0
  14. package/lib/dumpGraphToGraphViz.js +1 -1
  15. package/lib/public/BundleGraph.js +21 -8
  16. package/lib/public/Config.js +28 -0
  17. package/lib/requests/AssetGraphRequest.js +13 -1
  18. package/lib/requests/BundleGraphRequest.js +13 -1
  19. package/lib/requests/WriteBundleRequest.js +11 -2
  20. package/lib/resolveOptions.js +7 -4
  21. package/lib/worker.js +18 -1
  22. package/package.json +23 -19
  23. package/src/Atlaspack.js +13 -5
  24. package/src/BundleGraph.js +0 -167
  25. package/src/PackagerRunner.js +60 -9
  26. package/src/RequestTracker.js +491 -137
  27. package/src/UncommittedAsset.js +16 -1
  28. package/src/atlaspack-v3/worker/compat/plugin-config.js +9 -5
  29. package/src/atlaspack-v3/worker/worker.js +7 -0
  30. package/src/public/BundleGraph.js +22 -15
  31. package/src/public/Config.js +39 -5
  32. package/src/requests/AssetGraphRequest.js +13 -3
  33. package/src/requests/BundleGraphRequest.js +13 -3
  34. package/src/requests/WriteBundleRequest.js +9 -2
  35. package/src/resolveOptions.js +4 -2
  36. package/test/RequestTracker.test.js +120 -5
  37. package/test/test-utils.js +1 -7
@@ -1284,143 +1284,6 @@ export default class BundleGraph {
1284
1284
  );
1285
1285
  }
1286
1286
 
1287
- getReferencedAssets(
1288
- bundle: Bundle,
1289
- cache: Map<Bundle, Set<string>>,
1290
- ): Set<string> {
1291
- const result = new Set();
1292
-
1293
- const siblingBundles = new Set(
1294
- this.getBundleGroupsContainingBundle(bundle).flatMap((bundleGroup) =>
1295
- this.getBundlesInBundleGroup(bundleGroup, {includeInline: true}),
1296
- ),
1297
- );
1298
-
1299
- const candidates = new Map();
1300
-
1301
- this.traverseAssets(bundle, (asset) => {
1302
- // If the asset is available in multiple bundles in the same target, it's referenced.
1303
- const bundlesWithAsset = this.getBundlesWithAsset(asset);
1304
- if (
1305
- bundlesWithAsset.filter(
1306
- (b) =>
1307
- b.target.name === bundle.target.name &&
1308
- b.target.distDir === bundle.target.distDir,
1309
- ).length > 1
1310
- ) {
1311
- result.add(asset.id);
1312
- return;
1313
- }
1314
-
1315
- const assetNodeId = nullthrows(
1316
- this._graph.getNodeIdByContentKey(asset.id),
1317
- );
1318
-
1319
- if (
1320
- this._graph
1321
- .getNodeIdsConnectedTo(assetNodeId, bundleGraphEdgeTypes.references)
1322
- .map((id) => this._graph.getNode(id))
1323
- .some(
1324
- (node) =>
1325
- node?.type === 'dependency' &&
1326
- (node.value.priority === Priority.lazy ||
1327
- node.value.priority === Priority.conditional) &&
1328
- node.value.specifierType !== SpecifierType.url,
1329
- )
1330
- ) {
1331
- // If this asset is referenced by any async dependency, it's referenced.
1332
- result.add(asset.id);
1333
- return;
1334
- }
1335
-
1336
- const dependencies = this._graph
1337
- .getNodeIdsConnectedTo(assetNodeId)
1338
- .map((id) => nullthrows(this._graph.getNode(id)))
1339
- .filter((node) => node.type === 'dependency')
1340
- .map((node) => {
1341
- invariant(node.type === 'dependency');
1342
- return node.value;
1343
- });
1344
-
1345
- candidates.set(asset.id, {
1346
- asset,
1347
- dependencies,
1348
- bundlesWithAsset,
1349
- });
1350
- });
1351
-
1352
- const visitedBundles: Set<Bundle> = new Set();
1353
-
1354
- // Check if any of this bundle's descendants, referencers, bundles referenced
1355
- // by referencers, or descendants of its referencers use the asset without
1356
- // an explicit reference edge. This can happen if e.g. the asset has been
1357
- // deduplicated.
1358
- [...siblingBundles].forEach((referencer) => {
1359
- this.traverseBundles((descendant, _, actions) => {
1360
- if (descendant.id === bundle.id) {
1361
- return;
1362
- }
1363
-
1364
- if (visitedBundles.has(descendant)) {
1365
- actions.skipChildren();
1366
- return;
1367
- }
1368
-
1369
- visitedBundles.add(descendant);
1370
-
1371
- if (
1372
- descendant.type !== bundle.type ||
1373
- descendant.env.context !== bundle.env.context
1374
- ) {
1375
- actions.skipChildren();
1376
- return;
1377
- }
1378
-
1379
- for (let assetId of this.getBundleDirectReferences(descendant, cache)) {
1380
- if (candidates.has(assetId)) {
1381
- result.add(assetId);
1382
- }
1383
- }
1384
- }, referencer);
1385
- });
1386
-
1387
- return result;
1388
- }
1389
-
1390
- getBundleDirectReferences(
1391
- bundle: Bundle,
1392
- cache: Map<Bundle, Set<string>>,
1393
- ): Set<string> {
1394
- const cachedResult = cache.get(bundle);
1395
- if (cachedResult != null) {
1396
- return cachedResult;
1397
- }
1398
-
1399
- const directReferences = new Set();
1400
- const bundleAssets = this.getBundleContainedAssets(bundle);
1401
- const bundleDependencies = this.getBundleContainedDependencies(bundle);
1402
-
1403
- for (const dependency of bundleDependencies) {
1404
- this._graph.forEachNodeIdConnectedFrom(
1405
- this._graph.getNodeIdByContentKey(dependency),
1406
- (assetId) => {
1407
- const asset = nullthrows(this._graph.getNode(assetId));
1408
- if (asset.type !== 'asset') {
1409
- return;
1410
- }
1411
-
1412
- if (!bundleAssets.has(asset.id)) {
1413
- directReferences.add(asset.id);
1414
- }
1415
- },
1416
- );
1417
- }
1418
-
1419
- cache.set(bundle, directReferences);
1420
-
1421
- return directReferences;
1422
- }
1423
-
1424
1287
  isAssetReferenced(bundle: Bundle, asset: Asset): boolean {
1425
1288
  // If the asset is available in multiple bundles in the same target, it's referenced.
1426
1289
  if (
@@ -1952,36 +1815,6 @@ export default class BundleGraph {
1952
1815
  );
1953
1816
  }
1954
1817
 
1955
- getBundleContainedAssets(bundle: Bundle): Set<string> {
1956
- const assets = new Set();
1957
- this._graph.forEachNodeIdConnectedFrom(
1958
- this._graph.getNodeIdByContentKey(bundle.id),
1959
- (nodeId) => {
1960
- const node = nullthrows(this._graph.getNode(nodeId));
1961
- if (node.type === 'asset') {
1962
- assets.add(node.value.id);
1963
- }
1964
- },
1965
- bundleGraphEdgeTypes.contains,
1966
- );
1967
- return assets;
1968
- }
1969
-
1970
- getBundleContainedDependencies(bundle: Bundle): Set<string> {
1971
- const dependencies = new Set();
1972
- this._graph.forEachNodeIdConnectedFrom(
1973
- this._graph.getNodeIdByContentKey(bundle.id),
1974
- (nodeId) => {
1975
- const node = nullthrows(this._graph.getNode(nodeId));
1976
- if (node.type === 'dependency') {
1977
- dependencies.add(node.value.id);
1978
- }
1979
- },
1980
- bundleGraphEdgeTypes.contains,
1981
- );
1982
- return dependencies;
1983
- }
1984
-
1985
1818
  filteredTraverse<TValue, TContext>(
1986
1819
  bundleNodeId: NodeId,
1987
1820
  filter: (NodeId, TraversalActions) => ?TValue,
@@ -63,6 +63,7 @@ import {getInvalidationId, getInvalidationHash} from './assetUtils';
63
63
  import {optionsProxy} from './utils';
64
64
  import {invalidateDevDeps} from './requests/DevDepRequest';
65
65
  import {tracer, PluginTracer} from '@atlaspack/profiler';
66
+ import {getFeatureFlag} from '@atlaspack/feature-flags';
66
67
 
67
68
  type Opts = {|
68
69
  config: AtlaspackConfig,
@@ -658,6 +659,21 @@ export default class PackagerRunner {
658
659
  this.options,
659
660
  );
660
661
 
662
+ if (getFeatureFlag('cachePerformanceImprovements')) {
663
+ const hash = hashString(
664
+ ATLASPACK_VERSION +
665
+ devDepHashes +
666
+ invalidationHash +
667
+ bundle.target.publicUrl +
668
+ bundleGraph.getHash(bundle) +
669
+ JSON.stringify(configResults) +
670
+ JSON.stringify(globalInfoResults) +
671
+ this.options.mode +
672
+ (this.options.shouldBuildLazily ? 'lazy' : 'eager'),
673
+ );
674
+ return path.join(bundle.displayName ?? bundle.name ?? bundle.id, hash);
675
+ }
676
+
661
677
  return hashString(
662
678
  ATLASPACK_VERSION +
663
679
  devDepHashes +
@@ -700,20 +716,27 @@ export default class PackagerRunner {
700
716
  let mapKey = PackagerRunner.getMapKey(cacheKey);
701
717
 
702
718
  let isLargeBlob = await this.options.cache.hasLargeBlob(contentKey);
703
- let contentExists =
704
- isLargeBlob || (await this.options.cache.has(contentKey));
719
+ let contentExists = getFeatureFlag('cachePerformanceImprovements')
720
+ ? isLargeBlob
721
+ : isLargeBlob || (await this.options.cache.has(contentKey));
705
722
  if (!contentExists) {
706
723
  return null;
707
724
  }
708
725
 
709
- let mapExists = await this.options.cache.has(mapKey);
726
+ let mapExists = getFeatureFlag('cachePerformanceImprovements')
727
+ ? await this.options.cache.hasLargeBlob(mapKey)
728
+ : await this.options.cache.has(mapKey);
710
729
 
711
730
  return {
712
731
  contents: isLargeBlob
713
732
  ? this.options.cache.getStream(contentKey)
714
733
  : blobToStream(await this.options.cache.getBlob(contentKey)),
715
734
  map: mapExists
716
- ? blobToStream(await this.options.cache.getBlob(mapKey))
735
+ ? blobToStream(
736
+ getFeatureFlag('cachePerformanceImprovements')
737
+ ? await this.options.cache.getLargeBlob(mapKey)
738
+ : await this.options.cache.getBlob(mapKey),
739
+ )
717
740
  : null,
718
741
  };
719
742
  }
@@ -727,11 +750,14 @@ export default class PackagerRunner {
727
750
  let size = 0;
728
751
  let hash;
729
752
  let hashReferences = [];
730
- let isLargeBlob = false;
753
+ let isLargeBlob = getFeatureFlag('cachePerformanceImprovements');
731
754
 
732
755
  // TODO: don't replace hash references in binary files??
733
756
  if (contents instanceof Readable) {
734
- isLargeBlob = true;
757
+ if (!getFeatureFlag('cachePerformanceImprovements')) {
758
+ isLargeBlob = true;
759
+ }
760
+
735
761
  let boundaryStr = '';
736
762
  let h = new Hash();
737
763
  await this.options.cache.setStream(
@@ -754,17 +780,32 @@ export default class PackagerRunner {
754
780
  size = buffer.byteLength;
755
781
  hash = hashBuffer(buffer);
756
782
  hashReferences = contents.match(HASH_REF_REGEX) ?? [];
757
- await this.options.cache.setBlob(cacheKeys.content, buffer);
783
+
784
+ if (getFeatureFlag('cachePerformanceImprovements')) {
785
+ await this.options.cache.setLargeBlob(cacheKeys.content, buffer);
786
+ } else {
787
+ await this.options.cache.setBlob(cacheKeys.content, buffer);
788
+ }
758
789
  } else {
759
790
  size = contents.length;
760
791
  hash = hashBuffer(contents);
761
792
  hashReferences = contents.toString().match(HASH_REF_REGEX) ?? [];
762
- await this.options.cache.setBlob(cacheKeys.content, contents);
793
+
794
+ if (getFeatureFlag('cachePerformanceImprovements')) {
795
+ await this.options.cache.setLargeBlob(cacheKeys.content, contents);
796
+ } else {
797
+ await this.options.cache.setBlob(cacheKeys.content, contents);
798
+ }
763
799
  }
764
800
 
765
801
  if (map != null) {
766
- await this.options.cache.setBlob(cacheKeys.map, map);
802
+ if (getFeatureFlag('cachePerformanceImprovements')) {
803
+ await this.options.cache.setLargeBlob(cacheKeys.map, map);
804
+ } else {
805
+ await this.options.cache.setBlob(cacheKeys.map, map);
806
+ }
767
807
  }
808
+
768
809
  let info = {
769
810
  type,
770
811
  size,
@@ -773,19 +814,29 @@ export default class PackagerRunner {
773
814
  cacheKeys,
774
815
  isLargeBlob,
775
816
  };
817
+
776
818
  await this.options.cache.set(cacheKeys.info, info);
777
819
  return info;
778
820
  }
779
821
 
780
822
  static getContentKey(cacheKey: string): string {
823
+ if (getFeatureFlag('cachePerformanceImprovements')) {
824
+ return `PackagerRunner/${ATLASPACK_VERSION}/${cacheKey}/content`;
825
+ }
781
826
  return hashString(`${cacheKey}:content`);
782
827
  }
783
828
 
784
829
  static getMapKey(cacheKey: string): string {
830
+ if (getFeatureFlag('cachePerformanceImprovements')) {
831
+ return `PackagerRunner/${ATLASPACK_VERSION}/${cacheKey}/map`;
832
+ }
785
833
  return hashString(`${cacheKey}:map`);
786
834
  }
787
835
 
788
836
  static getInfoKey(cacheKey: string): string {
837
+ if (getFeatureFlag('cachePerformanceImprovements')) {
838
+ return `PackagerRunner/${ATLASPACK_VERSION}/${cacheKey}/info`;
839
+ }
789
840
  return hashString(`${cacheKey}:info`);
790
841
  }
791
842
  }