@atlaspack/core 2.34.0 → 2.35.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 +46 -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 +8 -15
- package/dist/requests/BundleGraphRequestRust.js +1 -2
- package/dist/requests/PackageRequest.js +1 -1
- package/dist/requests/TargetRequest.js +5 -0
- package/dist/requests/WriteBundleRequest.js +3 -9
- 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 +10 -15
- package/lib/requests/BundleGraphRequestRust.js +2 -3
- package/lib/requests/PackageRequest.js +3 -1
- package/lib/requests/TargetRequest.js +5 -0
- package/lib/requests/WriteBundleRequest.js +3 -3
- 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/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 +11 -30
- package/src/requests/BundleGraphRequestRust.ts +1 -2
- package/src/requests/PackageRequest.ts +1 -1
- package/src/requests/TargetRequest.ts +5 -0
- package/src/requests/WriteBundleRequest.ts +3 -9
- 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/tsconfig.tsbuildinfo +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AtlaspackNapi, Lmdb, AtlaspackNapiOptions, CacheStats } from '@atlaspack/rust';
|
|
1
|
+
import { AtlaspackNapi, Lmdb, AtlaspackNapiOptions, CacheStats, PackageOptions } from '@atlaspack/rust';
|
|
2
2
|
import { Diagnostic } from '@atlaspack/diagnostic';
|
|
3
3
|
import type { Event } from '@parcel/watcher';
|
|
4
4
|
import type { NapiWorkerPool as INapiWorkerPool } from '@atlaspack/types';
|
|
@@ -27,7 +27,8 @@ export declare class AtlaspackV3 {
|
|
|
27
27
|
buildAssetGraph(): Promise<any>;
|
|
28
28
|
buildBundleGraph(): Promise<any>;
|
|
29
29
|
loadBundleGraph(bundleGraph: BundleGraph): Promise<void>;
|
|
30
|
-
|
|
30
|
+
updateBundleGraph(bundleGraph: BundleGraph, changedAssetIds: string[]): Promise<void>;
|
|
31
|
+
package(bundleId: string, options?: PackageOptions): Promise<[RunPackagerRunnerResult, Diagnostic | null]>;
|
|
31
32
|
respondToFsEvents(events: Array<Event>): Promise<boolean>;
|
|
32
33
|
completeCacheSession(): Promise<CacheStats>;
|
|
33
34
|
}
|
|
@@ -14,9 +14,9 @@ type RunInput = {
|
|
|
14
14
|
} & StaticRunOpts<BundleGraphResult>;
|
|
15
15
|
export type BundleGraphResult = {
|
|
16
16
|
bundleGraph: InternalBundleGraph;
|
|
17
|
-
assetGraphBundlingVersion: number;
|
|
18
17
|
changedAssets: Map<string, Asset>;
|
|
19
18
|
assetRequests: Array<AssetGroup>;
|
|
19
|
+
didIncrementallyBundle: boolean;
|
|
20
20
|
};
|
|
21
21
|
type BundleGraphRequest = {
|
|
22
22
|
id: string;
|
package/lib/types/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.35.0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -23,22 +23,22 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@mischnic/json-sourcemap": "^0.1.0",
|
|
26
|
-
"@atlaspack/build-cache": "2.13.
|
|
27
|
-
"@atlaspack/cache": "3.2.
|
|
26
|
+
"@atlaspack/build-cache": "2.13.13",
|
|
27
|
+
"@atlaspack/cache": "3.2.50",
|
|
28
28
|
"@atlaspack/diagnostic": "2.14.4",
|
|
29
29
|
"@atlaspack/events": "2.14.4",
|
|
30
|
-
"@atlaspack/feature-flags": "2.30.
|
|
31
|
-
"@atlaspack/fs": "2.15.
|
|
32
|
-
"@atlaspack/graph": "3.6.
|
|
33
|
-
"@atlaspack/logger": "2.14.
|
|
34
|
-
"@atlaspack/package-manager": "2.14.
|
|
35
|
-
"@atlaspack/plugin": "2.14.
|
|
36
|
-
"@atlaspack/profiler": "2.15.
|
|
37
|
-
"@atlaspack/rust": "3.
|
|
38
|
-
"@atlaspack/types": "2.15.
|
|
39
|
-
"@atlaspack/utils": "3.3.
|
|
40
|
-
"@atlaspack/workers": "2.14.
|
|
41
|
-
"@atlaspack/source-map": "3.2.
|
|
30
|
+
"@atlaspack/feature-flags": "2.30.1",
|
|
31
|
+
"@atlaspack/fs": "2.15.50",
|
|
32
|
+
"@atlaspack/graph": "3.6.17",
|
|
33
|
+
"@atlaspack/logger": "2.14.47",
|
|
34
|
+
"@atlaspack/package-manager": "2.14.55",
|
|
35
|
+
"@atlaspack/plugin": "2.14.55",
|
|
36
|
+
"@atlaspack/profiler": "2.15.16",
|
|
37
|
+
"@atlaspack/rust": "3.24.0",
|
|
38
|
+
"@atlaspack/types": "2.15.45",
|
|
39
|
+
"@atlaspack/utils": "3.3.7",
|
|
40
|
+
"@atlaspack/workers": "2.14.55",
|
|
41
|
+
"@atlaspack/source-map": "3.2.10",
|
|
42
42
|
"base-x": "^3.0.8",
|
|
43
43
|
"browserslist": "^4.6.6",
|
|
44
44
|
"clone": "^2.1.1",
|
package/src/AssetGraph.ts
CHANGED
|
@@ -41,14 +41,10 @@ type InitOpts = {
|
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
type AssetGraphOpts = ContentGraphOpts<AssetGraphNode> & {
|
|
44
|
-
bundlingVersion?: number;
|
|
45
|
-
disableIncrementalBundling?: boolean;
|
|
46
44
|
hash?: string | null | undefined;
|
|
47
45
|
};
|
|
48
46
|
|
|
49
47
|
type SerializedAssetGraph = SerializedContentGraph<AssetGraphNode> & {
|
|
50
|
-
bundlingVersion: number;
|
|
51
|
-
disableIncrementalBundling: boolean;
|
|
52
48
|
hash?: string | null | undefined;
|
|
53
49
|
};
|
|
54
50
|
|
|
@@ -121,30 +117,16 @@ export default class AssetGraph extends ContentGraph<AssetGraphNode> {
|
|
|
121
117
|
hash: string | null | undefined;
|
|
122
118
|
envCache: Map<string, Environment>;
|
|
123
119
|
|
|
124
|
-
/**
|
|
125
|
-
* Incremented when the asset graph is modified such that it requires a bundling pass.
|
|
126
|
-
*/
|
|
127
|
-
#bundlingVersion: number = 0;
|
|
128
|
-
/**
|
|
129
|
-
* Force incremental bundling to be disabled.
|
|
130
|
-
*/
|
|
131
|
-
#disableIncrementalBundling: boolean = false;
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* @deprecated
|
|
135
|
-
*/
|
|
136
120
|
safeToIncrementallyBundle: boolean = true;
|
|
137
121
|
|
|
138
122
|
undeferredDependencies: Set<Dependency>;
|
|
139
123
|
|
|
140
124
|
constructor(opts?: AssetGraphOpts | null) {
|
|
141
125
|
if (opts) {
|
|
142
|
-
let {hash,
|
|
126
|
+
let {hash, ...rest} = opts;
|
|
143
127
|
// @ts-expect-error TS2345
|
|
144
128
|
super(rest);
|
|
145
129
|
this.hash = hash;
|
|
146
|
-
this.#bundlingVersion = bundlingVersion ?? 0;
|
|
147
|
-
this.#disableIncrementalBundling = disableIncrementalBundling ?? false;
|
|
148
130
|
} else {
|
|
149
131
|
super();
|
|
150
132
|
this.setRootNodeId(
|
|
@@ -167,64 +149,16 @@ export default class AssetGraph extends ContentGraph<AssetGraphNode> {
|
|
|
167
149
|
serialize(): SerializedAssetGraph {
|
|
168
150
|
return {
|
|
169
151
|
...super.serialize(),
|
|
170
|
-
bundlingVersion: this.#bundlingVersion,
|
|
171
|
-
disableIncrementalBundling: this.#disableIncrementalBundling,
|
|
172
152
|
hash: this.hash,
|
|
173
153
|
};
|
|
174
154
|
}
|
|
175
155
|
|
|
176
156
|
/**
|
|
177
|
-
*
|
|
178
|
-
*/
|
|
179
|
-
setDisableIncrementalBundling(disable: boolean) {
|
|
180
|
-
this.#disableIncrementalBundling = disable;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
testing_getDisableIncrementalBundling(): boolean {
|
|
184
|
-
return this.#disableIncrementalBundling;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Make sure this asset graph is marked as needing a full bundling pass.
|
|
189
|
-
*/
|
|
190
|
-
setNeedsBundling() {
|
|
191
|
-
if (!getFeatureFlag('incrementalBundlingVersioning')) {
|
|
192
|
-
// In legacy mode, we rely solely on safeToIncrementallyBundle to
|
|
193
|
-
// invalidate incremental bundling, so we skip bumping the version.
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
this.#bundlingVersion += 1;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Get the current bundling version.
|
|
201
|
-
*
|
|
202
|
-
* Each bundle pass should keep this version around. Whenever an asset graph has a new version,
|
|
203
|
-
* bundling should be re-run.
|
|
204
|
-
*/
|
|
205
|
-
getBundlingVersion(): number {
|
|
206
|
-
if (!getFeatureFlag('incrementalBundlingVersioning')) {
|
|
207
|
-
return 0;
|
|
208
|
-
}
|
|
209
|
-
return this.#bundlingVersion;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* If the `bundlingVersion` has not changed since the last bundling pass,
|
|
214
|
-
* we can incrementally bundle, which will not require a full bundling pass
|
|
157
|
+
* Determine if we can incrementally bundle, which will not require a full bundling pass
|
|
215
158
|
* but just update assets into the bundle graph output.
|
|
216
159
|
*/
|
|
217
|
-
canIncrementallyBundle(
|
|
218
|
-
|
|
219
|
-
return (
|
|
220
|
-
this.safeToIncrementallyBundle && !this.#disableIncrementalBundling
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
return (
|
|
224
|
-
this.safeToIncrementallyBundle &&
|
|
225
|
-
this.#bundlingVersion === lastVersion &&
|
|
226
|
-
!this.#disableIncrementalBundling
|
|
227
|
-
);
|
|
160
|
+
canIncrementallyBundle(): boolean {
|
|
161
|
+
return this.safeToIncrementallyBundle;
|
|
228
162
|
}
|
|
229
163
|
|
|
230
164
|
// Deduplicates Environments by making them referentially equal
|
|
@@ -447,13 +381,11 @@ export default class AssetGraph extends ContentGraph<AssetGraphNode> {
|
|
|
447
381
|
// @ts-expect-error TS2339
|
|
448
382
|
if (!ctx?.hasDeferred) {
|
|
449
383
|
this.safeToIncrementallyBundle = false;
|
|
450
|
-
this.setNeedsBundling();
|
|
451
384
|
delete traversedNode.hasDeferred;
|
|
452
385
|
}
|
|
453
386
|
actions.skipChildren();
|
|
454
387
|
} else if (traversedNode.type === 'dependency') {
|
|
455
388
|
this.safeToIncrementallyBundle = false;
|
|
456
|
-
this.setNeedsBundling();
|
|
457
389
|
traversedNode.hasDeferred = false;
|
|
458
390
|
} else if (nodeId !== traversedNodeId) {
|
|
459
391
|
actions.skipChildren();
|
package/src/BundleGraph.ts
CHANGED
|
@@ -654,6 +654,45 @@ export default class BundleGraph {
|
|
|
654
654
|
return {nodesJson, edges, publicIdByAssetId, environmentsJson};
|
|
655
655
|
}
|
|
656
656
|
|
|
657
|
+
/**
|
|
658
|
+
* Serialize only the given asset nodes for native incremental update.
|
|
659
|
+
* Same node shape and env/omit logic as serializeForNative.
|
|
660
|
+
*/
|
|
661
|
+
serializeAssetNodesForNative(assetIds: Array<string>): string {
|
|
662
|
+
const start = performance.now();
|
|
663
|
+
|
|
664
|
+
if (assetIds.length === 0) {
|
|
665
|
+
return '[]';
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
const nodes: Array<BundleGraphNode> = [];
|
|
669
|
+
for (const assetId of assetIds) {
|
|
670
|
+
const node = this._graph.getNodeByContentKey(assetId);
|
|
671
|
+
if (node?.type !== 'asset') {
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
674
|
+
const processedNode = {...node};
|
|
675
|
+
if (node.value?.env) {
|
|
676
|
+
processedNode.value = {
|
|
677
|
+
...node.value,
|
|
678
|
+
env: fromEnvironmentId(node.value.env).id,
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
nodes.push(processedNode);
|
|
682
|
+
}
|
|
683
|
+
const optimizedNodes = nodes.map((node) => this._omitNulls(node));
|
|
684
|
+
const nodesJson = JSON.stringify(optimizedNodes);
|
|
685
|
+
|
|
686
|
+
const duration = performance.now() - start;
|
|
687
|
+
const nodesSizeMB = (nodesJson.length / (1024 * 1024)).toFixed(2);
|
|
688
|
+
|
|
689
|
+
logger.verbose({
|
|
690
|
+
origin: '@atlaspack/core',
|
|
691
|
+
message: `serializeAssetNodesForNative: ${duration.toFixed(1)}ms, ${nodesSizeMB}MB nodes, ${nodes.length} nodes`,
|
|
692
|
+
});
|
|
693
|
+
return nodesJson;
|
|
694
|
+
}
|
|
695
|
+
|
|
657
696
|
/**
|
|
658
697
|
* Remove null and undefined values from an object to reduce JSON size.
|
|
659
698
|
* Preserves false, 0, empty strings, and arrays.
|
package/src/PackagerRunner.ts
CHANGED
|
@@ -62,7 +62,6 @@ import {invalidateDevDeps} from './requests/DevDepRequest';
|
|
|
62
62
|
import {computeSourceMapRoot} from './requests/WriteBundleRequest';
|
|
63
63
|
import {tracer, PluginTracer} from '@atlaspack/profiler';
|
|
64
64
|
import {fromEnvironmentId} from './EnvironmentManager';
|
|
65
|
-
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
66
65
|
|
|
67
66
|
type Opts = {
|
|
68
67
|
config: AtlaspackConfig;
|
|
@@ -654,21 +653,6 @@ export default class PackagerRunner {
|
|
|
654
653
|
this.options,
|
|
655
654
|
);
|
|
656
655
|
|
|
657
|
-
if (getFeatureFlag('cachePerformanceImprovements')) {
|
|
658
|
-
const hash = hashString(
|
|
659
|
-
ATLASPACK_VERSION +
|
|
660
|
-
devDepHashes +
|
|
661
|
-
invalidationHash +
|
|
662
|
-
bundle.target.publicUrl +
|
|
663
|
-
bundleGraph.getHash(bundle) +
|
|
664
|
-
JSON.stringify(configResults) +
|
|
665
|
-
JSON.stringify(globalInfoResults) +
|
|
666
|
-
this.options.mode +
|
|
667
|
-
(this.options.shouldBuildLazily ? 'lazy' : 'eager'),
|
|
668
|
-
);
|
|
669
|
-
return path.join(bundle.displayName ?? bundle.name ?? bundle.id, hash);
|
|
670
|
-
}
|
|
671
|
-
|
|
672
656
|
return hashString(
|
|
673
657
|
ATLASPACK_VERSION +
|
|
674
658
|
devDepHashes +
|
|
@@ -715,27 +699,20 @@ export default class PackagerRunner {
|
|
|
715
699
|
let mapKey = PackagerRunner.getMapKey(cacheKey);
|
|
716
700
|
|
|
717
701
|
let isLargeBlob = await this.options.cache.hasLargeBlob(contentKey);
|
|
718
|
-
let contentExists =
|
|
719
|
-
|
|
720
|
-
: isLargeBlob || (await this.options.cache.has(contentKey));
|
|
702
|
+
let contentExists =
|
|
703
|
+
isLargeBlob || (await this.options.cache.has(contentKey));
|
|
721
704
|
if (!contentExists) {
|
|
722
705
|
return null;
|
|
723
706
|
}
|
|
724
707
|
|
|
725
|
-
let mapExists =
|
|
726
|
-
? await this.options.cache.hasLargeBlob(mapKey)
|
|
727
|
-
: await this.options.cache.has(mapKey);
|
|
708
|
+
let mapExists = await this.options.cache.has(mapKey);
|
|
728
709
|
|
|
729
710
|
return {
|
|
730
711
|
contents: isLargeBlob
|
|
731
712
|
? this.options.cache.getStream(contentKey)
|
|
732
713
|
: blobToStream(await this.options.cache.getBlob(contentKey)),
|
|
733
714
|
map: mapExists
|
|
734
|
-
? blobToStream(
|
|
735
|
-
getFeatureFlag('cachePerformanceImprovements')
|
|
736
|
-
? await this.options.cache.getLargeBlob(mapKey)
|
|
737
|
-
: await this.options.cache.getBlob(mapKey),
|
|
738
|
-
)
|
|
715
|
+
? blobToStream(await this.options.cache.getBlob(mapKey))
|
|
739
716
|
: null,
|
|
740
717
|
};
|
|
741
718
|
}
|
|
@@ -750,13 +727,11 @@ export default class PackagerRunner {
|
|
|
750
727
|
let hash;
|
|
751
728
|
// @ts-expect-error TS2702
|
|
752
729
|
let hashReferences: RegExp.matchResult | Array<string> = [];
|
|
753
|
-
let isLargeBlob =
|
|
730
|
+
let isLargeBlob = false;
|
|
754
731
|
|
|
755
732
|
// TODO: don't replace hash references in binary files??
|
|
756
733
|
if (contents instanceof Readable) {
|
|
757
|
-
|
|
758
|
-
isLargeBlob = true;
|
|
759
|
-
}
|
|
734
|
+
isLargeBlob = true;
|
|
760
735
|
|
|
761
736
|
let boundaryStr = '';
|
|
762
737
|
let h = new Hash();
|
|
@@ -782,29 +757,17 @@ export default class PackagerRunner {
|
|
|
782
757
|
hash = hashBuffer(buffer);
|
|
783
758
|
hashReferences = contents.match(HASH_REF_REGEX) ?? [];
|
|
784
759
|
|
|
785
|
-
|
|
786
|
-
await this.options.cache.setLargeBlob(cacheKeys.content, buffer);
|
|
787
|
-
} else {
|
|
788
|
-
await this.options.cache.setBlob(cacheKeys.content, buffer);
|
|
789
|
-
}
|
|
760
|
+
await this.options.cache.setBlob(cacheKeys.content, buffer);
|
|
790
761
|
} else {
|
|
791
762
|
size = contents.length;
|
|
792
763
|
hash = hashBuffer(contents);
|
|
793
764
|
hashReferences = contents.toString().match(HASH_REF_REGEX) ?? [];
|
|
794
765
|
|
|
795
|
-
|
|
796
|
-
await this.options.cache.setLargeBlob(cacheKeys.content, contents);
|
|
797
|
-
} else {
|
|
798
|
-
await this.options.cache.setBlob(cacheKeys.content, contents);
|
|
799
|
-
}
|
|
766
|
+
await this.options.cache.setBlob(cacheKeys.content, contents);
|
|
800
767
|
}
|
|
801
768
|
|
|
802
769
|
if (map != null) {
|
|
803
|
-
|
|
804
|
-
await this.options.cache.setLargeBlob(cacheKeys.map, map);
|
|
805
|
-
} else {
|
|
806
|
-
await this.options.cache.setBlob(cacheKeys.map, map);
|
|
807
|
-
}
|
|
770
|
+
await this.options.cache.setBlob(cacheKeys.map, map);
|
|
808
771
|
}
|
|
809
772
|
|
|
810
773
|
let info = {
|
|
@@ -821,23 +784,14 @@ export default class PackagerRunner {
|
|
|
821
784
|
}
|
|
822
785
|
|
|
823
786
|
static getContentKey(cacheKey: string): string {
|
|
824
|
-
if (getFeatureFlag('cachePerformanceImprovements')) {
|
|
825
|
-
return `PackagerRunner/${ATLASPACK_VERSION}/${cacheKey}/content`;
|
|
826
|
-
}
|
|
827
787
|
return hashString(`${cacheKey}:content`);
|
|
828
788
|
}
|
|
829
789
|
|
|
830
790
|
static getMapKey(cacheKey: string): string {
|
|
831
|
-
if (getFeatureFlag('cachePerformanceImprovements')) {
|
|
832
|
-
return `PackagerRunner/${ATLASPACK_VERSION}/${cacheKey}/map`;
|
|
833
|
-
}
|
|
834
791
|
return hashString(`${cacheKey}:map`);
|
|
835
792
|
}
|
|
836
793
|
|
|
837
794
|
static getInfoKey(cacheKey: string): string {
|
|
838
|
-
if (getFeatureFlag('cachePerformanceImprovements')) {
|
|
839
|
-
return `PackagerRunner/${ATLASPACK_VERSION}/${cacheKey}/info`;
|
|
840
|
-
}
|
|
841
795
|
return hashString(`${cacheKey}:info`);
|
|
842
796
|
}
|
|
843
797
|
}
|
package/src/RequestTracker.ts
CHANGED
|
@@ -2,7 +2,7 @@ import invariant, {AssertionError} from 'assert';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
|
|
4
4
|
import {deserialize, serialize} from '@atlaspack/build-cache';
|
|
5
|
-
import {
|
|
5
|
+
import {Cache} from '@atlaspack/cache';
|
|
6
6
|
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
7
7
|
import {ContentGraph} from '@atlaspack/graph';
|
|
8
8
|
import type {
|
|
@@ -12,7 +12,7 @@ import type {
|
|
|
12
12
|
SerializedContentGraph,
|
|
13
13
|
Graph,
|
|
14
14
|
} from '@atlaspack/graph';
|
|
15
|
-
import logger
|
|
15
|
+
import logger from '@atlaspack/logger';
|
|
16
16
|
import {hashString} from '@atlaspack/rust';
|
|
17
17
|
import type {Async, EnvMap} from '@atlaspack/types';
|
|
18
18
|
import {
|
|
@@ -1315,13 +1315,11 @@ export default class RequestTracker {
|
|
|
1315
1315
|
return result;
|
|
1316
1316
|
} else if (node.resultCacheKey != null && ifMatch == null) {
|
|
1317
1317
|
let key = node.resultCacheKey;
|
|
1318
|
-
|
|
1319
|
-
invariant(this.options.cache.hasLargeBlob(key));
|
|
1320
|
-
}
|
|
1318
|
+
invariant(this.options.cache.hasLargeBlob(key));
|
|
1321
1319
|
|
|
1322
|
-
let cachedResult: T =
|
|
1323
|
-
|
|
1324
|
-
|
|
1320
|
+
let cachedResult: T = deserialize(
|
|
1321
|
+
await this.options.cache.getLargeBlob(key),
|
|
1322
|
+
);
|
|
1325
1323
|
node.result = cachedResult;
|
|
1326
1324
|
return cachedResult;
|
|
1327
1325
|
}
|
|
@@ -1559,40 +1557,15 @@ export default class RequestTracker {
|
|
|
1559
1557
|
}
|
|
1560
1558
|
|
|
1561
1559
|
async writeToCache(signal?: AbortSignal) {
|
|
1562
|
-
const options = this.options;
|
|
1563
|
-
async function runCacheImprovements<T>(
|
|
1564
|
-
newPath: (cache: LMDBLiteCache) => Promise<T>,
|
|
1565
|
-
oldPath: () => Promise<T>,
|
|
1566
|
-
): Promise<T> {
|
|
1567
|
-
if (getFeatureFlag('cachePerformanceImprovements')) {
|
|
1568
|
-
invariant(options.cache instanceof LMDBLiteCache);
|
|
1569
|
-
const result = await newPath(options.cache);
|
|
1570
|
-
return result;
|
|
1571
|
-
} else {
|
|
1572
|
-
const result = await oldPath();
|
|
1573
|
-
return result;
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
|
|
1577
1560
|
let cacheKey = getCacheKey(this.options);
|
|
1578
|
-
let requestGraphKey =
|
|
1579
|
-
|
|
1580
|
-
: `requestGraph-${cacheKey}`;
|
|
1581
|
-
let snapshotKey = getFeatureFlag('cachePerformanceImprovements')
|
|
1582
|
-
? `${cacheKey}/snapshot`
|
|
1583
|
-
: `snapshot-${cacheKey}`;
|
|
1561
|
+
let requestGraphKey = `requestGraph-${cacheKey}`;
|
|
1562
|
+
let snapshotKey = `snapshot-${cacheKey}`;
|
|
1584
1563
|
|
|
1585
1564
|
if (this.options.shouldDisableCache) {
|
|
1586
1565
|
return;
|
|
1587
1566
|
}
|
|
1588
1567
|
|
|
1589
1568
|
let total = 0;
|
|
1590
|
-
await runCacheImprovements(
|
|
1591
|
-
async (cache) => {
|
|
1592
|
-
await cache.getNativeRef().startWriteTransaction();
|
|
1593
|
-
},
|
|
1594
|
-
() => Promise.resolve(),
|
|
1595
|
-
);
|
|
1596
1569
|
try {
|
|
1597
1570
|
report({
|
|
1598
1571
|
type: 'cache',
|
|
@@ -1602,7 +1575,7 @@ export default class RequestTracker {
|
|
|
1602
1575
|
});
|
|
1603
1576
|
|
|
1604
1577
|
if (getFeatureFlag('environmentDeduplication')) {
|
|
1605
|
-
await writeEnvironmentsToCache(options.cache);
|
|
1578
|
+
await writeEnvironmentsToCache(this.options.cache);
|
|
1606
1579
|
}
|
|
1607
1580
|
|
|
1608
1581
|
let serialisedGraph = this.graph.serialize();
|
|
@@ -1618,27 +1591,14 @@ export default class RequestTracker {
|
|
|
1618
1591
|
throw new Error('Serialization was aborted');
|
|
1619
1592
|
}
|
|
1620
1593
|
|
|
1621
|
-
await
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
}
|
|
1628
|
-
|
|
1629
|
-
return Promise.resolve();
|
|
1630
|
-
},
|
|
1631
|
-
async () => {
|
|
1632
|
-
await this.options.cache.setLargeBlob(
|
|
1633
|
-
key,
|
|
1634
|
-
serialize(contents),
|
|
1635
|
-
signal
|
|
1636
|
-
? {
|
|
1637
|
-
signal: signal,
|
|
1638
|
-
}
|
|
1639
|
-
: undefined,
|
|
1640
|
-
);
|
|
1641
|
-
},
|
|
1594
|
+
await this.options.cache.setLargeBlob(
|
|
1595
|
+
key,
|
|
1596
|
+
serialize(contents),
|
|
1597
|
+
signal
|
|
1598
|
+
? {
|
|
1599
|
+
signal: signal,
|
|
1600
|
+
}
|
|
1601
|
+
: undefined,
|
|
1642
1602
|
);
|
|
1643
1603
|
|
|
1644
1604
|
total += 1;
|
|
@@ -1720,18 +1680,6 @@ export default class RequestTracker {
|
|
|
1720
1680
|
nodes: undefined,
|
|
1721
1681
|
});
|
|
1722
1682
|
|
|
1723
|
-
await runCacheImprovements(
|
|
1724
|
-
() =>
|
|
1725
|
-
serialiseAndSet(`${cacheKey}/cache_metadata`, {
|
|
1726
|
-
version: ATLASPACK_VERSION,
|
|
1727
|
-
entries: this.options.entries,
|
|
1728
|
-
mode: this.options.mode,
|
|
1729
|
-
shouldBuildLazily: this.options.shouldBuildLazily,
|
|
1730
|
-
watchBackend: this.options.watchBackend,
|
|
1731
|
-
}),
|
|
1732
|
-
() => Promise.resolve(),
|
|
1733
|
-
);
|
|
1734
|
-
|
|
1735
1683
|
let opts = getWatcherOptions(this.options);
|
|
1736
1684
|
let snapshotPath = path.join(this.options.cacheDir, snapshotKey + '.txt');
|
|
1737
1685
|
|
|
@@ -1743,13 +1691,6 @@ export default class RequestTracker {
|
|
|
1743
1691
|
} catch (err: any) {
|
|
1744
1692
|
// If we have aborted, ignore the error and continue
|
|
1745
1693
|
if (!signal?.aborted) throw err;
|
|
1746
|
-
} finally {
|
|
1747
|
-
await runCacheImprovements(
|
|
1748
|
-
async (cache) => {
|
|
1749
|
-
await cache.getNativeRef().commitWriteTransaction();
|
|
1750
|
-
},
|
|
1751
|
-
() => Promise.resolve(),
|
|
1752
|
-
);
|
|
1753
1694
|
}
|
|
1754
1695
|
|
|
1755
1696
|
report({type: 'cache', phase: 'end', total, size: this.graph.nodes.length});
|
|
@@ -1783,18 +1724,6 @@ export function getWatcherOptions({
|
|
|
1783
1724
|
}
|
|
1784
1725
|
|
|
1785
1726
|
function getCacheKey(options: AtlaspackOptions) {
|
|
1786
|
-
if (getFeatureFlag('cachePerformanceImprovements')) {
|
|
1787
|
-
const hash = hashString(
|
|
1788
|
-
`${ATLASPACK_VERSION}:${JSON.stringify(options.entries)}:${
|
|
1789
|
-
options.mode
|
|
1790
|
-
}:${options.shouldBuildLazily ? 'lazy' : 'eager'}:${
|
|
1791
|
-
options.watchBackend ?? ''
|
|
1792
|
-
}`,
|
|
1793
|
-
);
|
|
1794
|
-
|
|
1795
|
-
return `RequestTracker/${ATLASPACK_VERSION}/${hash}`;
|
|
1796
|
-
}
|
|
1797
|
-
|
|
1798
1727
|
return hashString(
|
|
1799
1728
|
`${ATLASPACK_VERSION}:${JSON.stringify(options.entries)}:${options.mode}:${
|
|
1800
1729
|
options.shouldBuildLazily ? 'lazy' : 'eager'
|
|
@@ -1803,10 +1732,6 @@ function getCacheKey(options: AtlaspackOptions) {
|
|
|
1803
1732
|
}
|
|
1804
1733
|
|
|
1805
1734
|
function getRequestGraphNodeKey(index: number, cacheKey: string) {
|
|
1806
|
-
if (getFeatureFlag('cachePerformanceImprovements')) {
|
|
1807
|
-
return `${cacheKey}/RequestGraph/nodes/${index}`;
|
|
1808
|
-
}
|
|
1809
|
-
|
|
1810
1735
|
return `requestGraph-nodes-${index}-${cacheKey}`;
|
|
1811
1736
|
}
|
|
1812
1737
|
|
|
@@ -1823,15 +1748,9 @@ export async function readAndDeserializeRequestGraph(
|
|
|
1823
1748
|
let bufferLength = 0;
|
|
1824
1749
|
|
|
1825
1750
|
const getAndDeserialize = async (key: string) => {
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
return deserialize(buffer);
|
|
1830
|
-
} else {
|
|
1831
|
-
const buffer = await cache.getLargeBlob(key);
|
|
1832
|
-
bufferLength += Buffer.byteLength(buffer);
|
|
1833
|
-
return deserialize(buffer);
|
|
1834
|
-
}
|
|
1751
|
+
const buffer = await cache.getLargeBlob(key);
|
|
1752
|
+
bufferLength += Buffer.byteLength(buffer);
|
|
1753
|
+
return deserialize(buffer);
|
|
1835
1754
|
};
|
|
1836
1755
|
|
|
1837
1756
|
let serializedRequestGraph = await getAndDeserialize(requestGraphKey);
|
|
@@ -1867,14 +1786,10 @@ async function loadRequestGraph(
|
|
|
1867
1786
|
}
|
|
1868
1787
|
|
|
1869
1788
|
let cacheKey = getCacheKey(options);
|
|
1870
|
-
let requestGraphKey =
|
|
1871
|
-
? `${cacheKey}/RequestGraph`
|
|
1872
|
-
: `requestGraph-${cacheKey}`;
|
|
1789
|
+
let requestGraphKey = `requestGraph-${cacheKey}`;
|
|
1873
1790
|
|
|
1874
1791
|
let timeout;
|
|
1875
|
-
const snapshotKey =
|
|
1876
|
-
? `${cacheKey}/snapshot`
|
|
1877
|
-
: `snapshot-${cacheKey}`;
|
|
1792
|
+
const snapshotKey = `snapshot-${cacheKey}`;
|
|
1878
1793
|
const snapshotPath = path.join(options.cacheDir, snapshotKey + '.txt');
|
|
1879
1794
|
|
|
1880
1795
|
const commonMeta = {
|
|
@@ -1901,9 +1816,8 @@ async function loadRequestGraph(
|
|
|
1901
1816
|
await loadEnvironmentsFromCache(options.cache);
|
|
1902
1817
|
}
|
|
1903
1818
|
|
|
1904
|
-
const hasRequestGraphInCache =
|
|
1905
|
-
|
|
1906
|
-
: await options.cache.hasLargeBlob(requestGraphKey);
|
|
1819
|
+
const hasRequestGraphInCache =
|
|
1820
|
+
await options.cache.hasLargeBlob(requestGraphKey);
|
|
1907
1821
|
|
|
1908
1822
|
if (hasRequestGraphInCache) {
|
|
1909
1823
|
try {
|
package/src/UncommittedAsset.ts
CHANGED
|
@@ -28,12 +28,7 @@ import {ATLASPACK_VERSION} from './constants';
|
|
|
28
28
|
import {createAsset, createAssetIdFromOptions} from './assetUtils';
|
|
29
29
|
import {BundleBehaviorNames} from './types';
|
|
30
30
|
import {invalidateOnFileCreateToInternal, createInvalidations} from './utils';
|
|
31
|
-
import {
|
|
32
|
-
ProjectPath,
|
|
33
|
-
fromProjectPath,
|
|
34
|
-
fromProjectPathRelative,
|
|
35
|
-
} from './projectPath';
|
|
36
|
-
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
31
|
+
import {ProjectPath, fromProjectPath} from './projectPath';
|
|
37
32
|
import {fromEnvironmentId} from './EnvironmentManager';
|
|
38
33
|
|
|
39
34
|
type UncommittedAssetOptions = {
|
|
@@ -308,11 +303,6 @@ export default class UncommittedAsset {
|
|
|
308
303
|
}
|
|
309
304
|
|
|
310
305
|
getCacheKey(key: string): string {
|
|
311
|
-
if (getFeatureFlag('cachePerformanceImprovements')) {
|
|
312
|
-
const filePath = fromProjectPathRelative(this.value.filePath);
|
|
313
|
-
return `Asset/${ATLASPACK_VERSION}/${filePath}/${this.value.id}/${key}`;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
306
|
return hashString(ATLASPACK_VERSION + key + this.value.id);
|
|
317
307
|
}
|
|
318
308
|
|