@atlaspack/core 2.16.2-canary.9 → 2.16.2-dev.14

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 CHANGED
@@ -1,5 +1,31 @@
1
1
  # @atlaspack/core
2
2
 
3
+ ## 2.17.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#541](https://github.com/atlassian-labs/atlaspack/pull/541) [`e2ba0f6`](https://github.com/atlassian-labs/atlaspack/commit/e2ba0f69702656f3d1ce95ab1454e35062b13b39) Thanks [@yamadapc](https://github.com/yamadapc)! - Add database compaction debug command
8
+
9
+ ### Patch Changes
10
+
11
+ - [#530](https://github.com/atlassian-labs/atlaspack/pull/530) [`2e90c9b`](https://github.com/atlassian-labs/atlaspack/commit/2e90c9bd07d7eb52645f9d84ccbb7f82685cbc8c) Thanks [@yamadapc](https://github.com/yamadapc)! - Write metadata about the cache in a new entry
12
+
13
+ - [#511](https://github.com/atlassian-labs/atlaspack/pull/511) [`11d6f16`](https://github.com/atlassian-labs/atlaspack/commit/11d6f16b6397dee2f217167e5c98b39edb63f7a7) Thanks [@yamadapc](https://github.com/yamadapc)! - Clean-up dylib worker threads segmentation fault bug fix feature-flag
14
+
15
+ - Updated dependencies [[`11d6f16`](https://github.com/atlassian-labs/atlaspack/commit/11d6f16b6397dee2f217167e5c98b39edb63f7a7), [`e2ba0f6`](https://github.com/atlassian-labs/atlaspack/commit/e2ba0f69702656f3d1ce95ab1454e35062b13b39), [`d2c50c2`](https://github.com/atlassian-labs/atlaspack/commit/d2c50c2c020888b33bb25b8690d9320c2b69e2a6), [`46a90dc`](https://github.com/atlassian-labs/atlaspack/commit/46a90dccd019a26b222c878a92d23acc75dc67c5), [`4c17141`](https://github.com/atlassian-labs/atlaspack/commit/4c1714103dab2aa9039c488f381551d2b65d1d01)]:
16
+ - @atlaspack/feature-flags@2.14.3
17
+ - @atlaspack/rust@3.3.0
18
+ - @atlaspack/cache@3.2.0
19
+ - @atlaspack/fs@2.15.0
20
+ - @atlaspack/graph@3.4.3
21
+ - @atlaspack/utils@2.14.5
22
+ - @atlaspack/logger@2.14.5
23
+ - @atlaspack/package-manager@2.14.5
24
+ - @atlaspack/profiler@2.14.3
25
+ - @atlaspack/types@2.14.5
26
+ - @atlaspack/workers@2.14.5
27
+ - @atlaspack/plugin@2.14.5
28
+
3
29
  ## 2.16.1
4
30
 
5
31
  ### Patch Changes
package/lib/Atlaspack.js CHANGED
@@ -601,6 +601,19 @@ class Atlaspack {
601
601
  }
602
602
  return result;
603
603
  }
604
+
605
+ /**
606
+ * Copy the cache to a new directory and compact it.
607
+ */
608
+ async unstable_compactCache() {
609
+ await this._init();
610
+ const cache = (0, _nullthrows().default)(this.#resolvedOptions).cache;
611
+ if (cache instanceof _cache().LMDBLiteCache) {
612
+ await cache.compact('parcel-cache-compacted');
613
+ } else {
614
+ throw new Error('Cache is not an LMDBLiteCache');
615
+ }
616
+ }
604
617
  async unstable_transform(options) {
605
618
  var _options$env;
606
619
  if (!this.#initialized) {
@@ -822,6 +822,86 @@ class BundleGraph {
822
822
  traverseAssets(bundle, visit, startAsset) {
823
823
  return this.traverseBundle(bundle, (0, _graph().mapVisitor)(node => node.type === 'asset' ? node.value : null, visit), startAsset);
824
824
  }
825
+ getReferencedAssets(bundle, cache) {
826
+ const result = new Set();
827
+ const siblingBundles = new Set(this.getBundleGroupsContainingBundle(bundle).flatMap(bundleGroup => this.getBundlesInBundleGroup(bundleGroup, {
828
+ includeInline: true
829
+ })));
830
+ const candidates = new Map();
831
+ this.traverseAssets(bundle, asset => {
832
+ // If the asset is available in multiple bundles in the same target, it's referenced.
833
+ const bundlesWithAsset = this.getBundlesWithAsset(asset);
834
+ if (bundlesWithAsset.filter(b => b.target.name === bundle.target.name && b.target.distDir === bundle.target.distDir).length > 1) {
835
+ result.add(asset.id);
836
+ return;
837
+ }
838
+ const assetNodeId = (0, _nullthrows().default)(this._graph.getNodeIdByContentKey(asset.id));
839
+ if (this._graph.getNodeIdsConnectedTo(assetNodeId, bundleGraphEdgeTypes.references).map(id => this._graph.getNode(id)).some(node => (node === null || node === void 0 ? void 0 : node.type) === 'dependency' && (node.value.priority === _types.Priority.lazy || node.value.priority === _types.Priority.conditional) && node.value.specifierType !== _types.SpecifierType.url)) {
840
+ // If this asset is referenced by any async dependency, it's referenced.
841
+ result.add(asset.id);
842
+ return;
843
+ }
844
+ const dependencies = this._graph.getNodeIdsConnectedTo(assetNodeId).map(id => (0, _nullthrows().default)(this._graph.getNode(id))).filter(node => node.type === 'dependency').map(node => {
845
+ (0, _assert().default)(node.type === 'dependency');
846
+ return node.value;
847
+ });
848
+ candidates.set(asset.id, {
849
+ asset,
850
+ dependencies,
851
+ bundlesWithAsset
852
+ });
853
+ });
854
+ const visitedBundles = new Set();
855
+
856
+ // Check if any of this bundle's descendants, referencers, bundles referenced
857
+ // by referencers, or descendants of its referencers use the asset without
858
+ // an explicit reference edge. This can happen if e.g. the asset has been
859
+ // deduplicated.
860
+ [...siblingBundles].forEach(referencer => {
861
+ this.traverseBundles((descendant, _, actions) => {
862
+ if (descendant.id === bundle.id) {
863
+ return;
864
+ }
865
+ if (visitedBundles.has(descendant)) {
866
+ actions.skipChildren();
867
+ return;
868
+ }
869
+ visitedBundles.add(descendant);
870
+ if (descendant.type !== bundle.type || descendant.env.context !== bundle.env.context) {
871
+ actions.skipChildren();
872
+ return;
873
+ }
874
+ for (let assetId of this.getBundleDirectReferences(descendant, cache)) {
875
+ if (candidates.has(assetId)) {
876
+ result.add(assetId);
877
+ }
878
+ }
879
+ }, referencer);
880
+ });
881
+ return result;
882
+ }
883
+ getBundleDirectReferences(bundle, cache) {
884
+ const cachedResult = cache.get(bundle);
885
+ if (cachedResult != null) {
886
+ return cachedResult;
887
+ }
888
+ const directReferences = new Set();
889
+ const bundleAssets = this.getBundleContainedAssets(bundle);
890
+ const bundleDependencies = this.getBundleContainedDependencies(bundle);
891
+ for (const dependency of bundleDependencies) {
892
+ this._graph.forEachNodeIdConnectedFrom(this._graph.getNodeIdByContentKey(dependency), assetId => {
893
+ const asset = (0, _nullthrows().default)(this._graph.getNode(assetId));
894
+ if (asset.type !== 'asset') {
895
+ return;
896
+ }
897
+ if (!bundleAssets.has(asset.id)) {
898
+ directReferences.add(asset.id);
899
+ }
900
+ });
901
+ }
902
+ cache.set(bundle, directReferences);
903
+ return directReferences;
904
+ }
825
905
  isAssetReferenced(bundle, asset) {
826
906
  // If the asset is available in multiple bundles in the same target, it's referenced.
827
907
  if (this.getBundlesWithAsset(asset).filter(b => b.target.name === bundle.target.name && b.target.distDir === bundle.target.distDir).length > 1) {
@@ -1140,6 +1220,26 @@ class BundleGraph {
1140
1220
  let dependencyNodeId = this._graph.getNodeIdByContentKey(dependency.id);
1141
1221
  return this._graph.hasEdge(bundleNodeId, dependencyNodeId, bundleGraphEdgeTypes.contains);
1142
1222
  }
1223
+ getBundleContainedAssets(bundle) {
1224
+ const assets = new Set();
1225
+ this._graph.forEachNodeIdConnectedFrom(this._graph.getNodeIdByContentKey(bundle.id), nodeId => {
1226
+ const node = (0, _nullthrows().default)(this._graph.getNode(nodeId));
1227
+ if (node.type === 'asset') {
1228
+ assets.add(node.value.id);
1229
+ }
1230
+ }, bundleGraphEdgeTypes.contains);
1231
+ return assets;
1232
+ }
1233
+ getBundleContainedDependencies(bundle) {
1234
+ const dependencies = new Set();
1235
+ this._graph.forEachNodeIdConnectedFrom(this._graph.getNodeIdByContentKey(bundle.id), nodeId => {
1236
+ const node = (0, _nullthrows().default)(this._graph.getNode(nodeId));
1237
+ if (node.type === 'dependency') {
1238
+ dependencies.add(node.value.id);
1239
+ }
1240
+ }, bundleGraphEdgeTypes.contains);
1241
+ return dependencies;
1242
+ }
1143
1243
  filteredTraverse(bundleNodeId, filter, visit) {
1144
1244
  return this._graph.filteredTraverse(filter, visit, bundleNodeId);
1145
1245
  }
@@ -115,6 +115,9 @@ class BundleGraph {
115
115
  isAssetReferenced(bundle, asset) {
116
116
  return this.#graph.isAssetReferenced((0, _Bundle.bundleToInternalBundle)(bundle), (0, _Asset.assetToAssetValue)(asset));
117
117
  }
118
+ getReferencedAssets(bundle, cache) {
119
+ return this.#graph.getReferencedAssets((0, _Bundle.bundleToInternalBundle)(bundle), cache);
120
+ }
118
121
  hasParentBundleOfType(bundle, type) {
119
122
  return this.#graph.hasParentBundleOfType((0, _Bundle.bundleToInternalBundle)(bundle), type);
120
123
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/core",
3
- "version": "2.16.2-canary.9+4c1714103",
3
+ "version": "2.16.2-dev.14+8c369e38c",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -20,21 +20,21 @@
20
20
  "check-ts": "tsc --noEmit index.d.ts"
21
21
  },
22
22
  "dependencies": {
23
- "@atlaspack/build-cache": "2.13.3-canary.77+4c1714103",
24
- "@atlaspack/cache": "3.1.1-canary.9+4c1714103",
25
- "@atlaspack/diagnostic": "2.14.1-canary.77+4c1714103",
26
- "@atlaspack/events": "2.14.1-canary.77+4c1714103",
27
- "@atlaspack/feature-flags": "2.14.1-canary.77+4c1714103",
28
- "@atlaspack/fs": "2.14.5-canary.9+4c1714103",
29
- "@atlaspack/graph": "3.4.1-canary.77+4c1714103",
30
- "@atlaspack/logger": "2.14.5-canary.9+4c1714103",
31
- "@atlaspack/package-manager": "2.14.5-canary.9+4c1714103",
32
- "@atlaspack/plugin": "2.14.5-canary.9+4c1714103",
33
- "@atlaspack/profiler": "2.14.1-canary.77+4c1714103",
34
- "@atlaspack/rust": "3.2.1-canary.9+4c1714103",
35
- "@atlaspack/types": "2.14.5-canary.9+4c1714103",
36
- "@atlaspack/utils": "2.14.5-canary.9+4c1714103",
37
- "@atlaspack/workers": "2.14.5-canary.9+4c1714103",
23
+ "@atlaspack/build-cache": "2.13.3-dev.82+8c369e38c",
24
+ "@atlaspack/cache": "3.1.1-dev.14+8c369e38c",
25
+ "@atlaspack/diagnostic": "2.14.1-dev.82+8c369e38c",
26
+ "@atlaspack/events": "2.14.1-dev.82+8c369e38c",
27
+ "@atlaspack/feature-flags": "2.14.1-dev.82+8c369e38c",
28
+ "@atlaspack/fs": "2.14.5-dev.14+8c369e38c",
29
+ "@atlaspack/graph": "3.4.1-dev.82+8c369e38c",
30
+ "@atlaspack/logger": "2.14.5-dev.14+8c369e38c",
31
+ "@atlaspack/package-manager": "2.14.5-dev.14+8c369e38c",
32
+ "@atlaspack/plugin": "2.14.5-dev.14+8c369e38c",
33
+ "@atlaspack/profiler": "2.14.1-dev.82+8c369e38c",
34
+ "@atlaspack/rust": "3.2.1-dev.14+8c369e38c",
35
+ "@atlaspack/types": "2.14.5-dev.14+8c369e38c",
36
+ "@atlaspack/utils": "2.14.5-dev.14+8c369e38c",
37
+ "@atlaspack/workers": "2.14.5-dev.14+8c369e38c",
38
38
  "@mischnic/json-sourcemap": "^0.1.0",
39
39
  "@parcel/source-map": "^2.1.1",
40
40
  "base-x": "^3.0.8",
@@ -67,5 +67,5 @@
67
67
  "./src/serializerCore.js": "./src/serializerCore.browser.js"
68
68
  },
69
69
  "type": "commonjs",
70
- "gitHead": "4c1714103dab2aa9039c488f381551d2b65d1d01"
70
+ "gitHead": "8c369e38ccd428409811114aebd6044c27f90705"
71
71
  }
package/src/Atlaspack.js CHANGED
@@ -639,6 +639,20 @@ export default class Atlaspack {
639
639
  return result;
640
640
  }
641
641
 
642
+ /**
643
+ * Copy the cache to a new directory and compact it.
644
+ */
645
+ async unstable_compactCache(): Promise<void> {
646
+ await this._init();
647
+
648
+ const cache = nullthrows(this.#resolvedOptions).cache;
649
+ if (cache instanceof LMDBLiteCache) {
650
+ await cache.compact('parcel-cache-compacted');
651
+ } else {
652
+ throw new Error('Cache is not an LMDBLiteCache');
653
+ }
654
+ }
655
+
642
656
  async unstable_transform(
643
657
  options: AtlaspackTransformOptions,
644
658
  ): Promise<Array<Asset>> {
@@ -1284,6 +1284,143 @@ 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
+
1287
1424
  isAssetReferenced(bundle: Bundle, asset: Asset): boolean {
1288
1425
  // If the asset is available in multiple bundles in the same target, it's referenced.
1289
1426
  if (
@@ -1815,6 +1952,36 @@ export default class BundleGraph {
1815
1952
  );
1816
1953
  }
1817
1954
 
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
+
1818
1985
  filteredTraverse<TValue, TContext>(
1819
1986
  bundleNodeId: NodeId,
1820
1987
  filter: (NodeId, TraversalActions) => ?TValue,
@@ -185,6 +185,16 @@ export default class BundleGraph<TBundle: IBundle>
185
185
  );
186
186
  }
187
187
 
188
+ getReferencedAssets(
189
+ bundle: IBundle,
190
+ cache: Map<Bundle, Set<string>>,
191
+ ): Set<string> {
192
+ return this.#graph.getReferencedAssets(
193
+ bundleToInternalBundle(bundle),
194
+ cache,
195
+ );
196
+ }
197
+
188
198
  hasParentBundleOfType(bundle: IBundle, type: string): boolean {
189
199
  return this.#graph.hasParentBundleOfType(
190
200
  bundleToInternalBundle(bundle),