@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
package/lib/RequestTracker.js
CHANGED
|
@@ -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 =
|
|
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
|
-
|
|
835
|
-
|
|
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 =
|
|
1018
|
-
let snapshotKey =
|
|
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
|
|
1045
|
-
|
|
1046
|
-
|
|
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
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
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 =
|
|
1156
|
+
let requestGraphKey = `requestGraph-${cacheKey}`;
|
|
1211
1157
|
let timeout;
|
|
1212
|
-
const snapshotKey =
|
|
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 =
|
|
1181
|
+
const hasRequestGraphInCache = await options.cache.hasLargeBlob(requestGraphKey);
|
|
1236
1182
|
if (hasRequestGraphInCache) {
|
|
1237
1183
|
try {
|
|
1238
1184
|
let {
|
package/lib/UncommittedAsset.js
CHANGED
|
@@ -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
|
-
|
|
88
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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,6 +291,7 @@ class BundlerRunner {
|
|
|
297
291
|
(0, _assert().default)(changedAssetNode.type === 'asset');
|
|
298
292
|
internalBundleGraph.updateAsset(changedAssetNode);
|
|
299
293
|
}
|
|
294
|
+
didIncrementallyBundle = true;
|
|
300
295
|
} else {
|
|
301
296
|
var _this$configs$get;
|
|
302
297
|
internalBundleGraph = _BundleGraph.default.fromAssetGraph(graph, this.options.mode === 'production');
|
|
@@ -361,9 +356,9 @@ class BundlerRunner {
|
|
|
361
356
|
if (internalBundleGraph != null) {
|
|
362
357
|
this.api.storeResult({
|
|
363
358
|
bundleGraph: internalBundleGraph,
|
|
364
|
-
assetGraphBundlingVersion: graph.getBundlingVersion(),
|
|
365
359
|
changedAssets: new Map(),
|
|
366
|
-
assetRequests: []
|
|
360
|
+
assetRequests: [],
|
|
361
|
+
didIncrementallyBundle
|
|
367
362
|
}, this.cacheKey);
|
|
368
363
|
}
|
|
369
364
|
throw new (_diagnostic().default)({
|
|
@@ -417,15 +412,15 @@ class BundlerRunner {
|
|
|
417
412
|
internalBundleGraph._graph, 'after_runtimes', _BundleGraph.bundleGraphEdgeTypes);
|
|
418
413
|
this.api.storeResult({
|
|
419
414
|
bundleGraph: internalBundleGraph,
|
|
420
|
-
assetGraphBundlingVersion: graph.getBundlingVersion(),
|
|
421
415
|
changedAssets: new Map(),
|
|
422
|
-
assetRequests: []
|
|
416
|
+
assetRequests: [],
|
|
417
|
+
didIncrementallyBundle
|
|
423
418
|
}, this.cacheKey);
|
|
424
419
|
return {
|
|
425
420
|
bundleGraph: internalBundleGraph,
|
|
426
|
-
assetGraphBundlingVersion: graph.getBundlingVersion(),
|
|
427
421
|
changedAssets: changedRuntimes,
|
|
428
|
-
assetRequests
|
|
422
|
+
assetRequests,
|
|
423
|
+
didIncrementallyBundle
|
|
429
424
|
};
|
|
430
425
|
}
|
|
431
426
|
}
|
|
@@ -145,10 +145,9 @@ function createBundleGraphRequestRust(input) {
|
|
|
145
145
|
}
|
|
146
146
|
return {
|
|
147
147
|
bundleGraph,
|
|
148
|
-
// Not accurate yet — ok for now.
|
|
149
|
-
assetGraphBundlingVersion: 0,
|
|
150
148
|
changedAssets: changedRuntimes,
|
|
151
|
-
assetRequests: []
|
|
149
|
+
assetRequests: [],
|
|
150
|
+
didIncrementallyBundle: false
|
|
152
151
|
};
|
|
153
152
|
},
|
|
154
153
|
input
|
|
@@ -70,7 +70,9 @@ async function run({
|
|
|
70
70
|
let packagingResult;
|
|
71
71
|
if ((0, _featureFlags().getFeatureFlag)('nativePackager') && (0, _featureFlags().getFeatureFlag)('nativePackagerSSRDev') && rustAtlaspack && (0, _EnvironmentManager.fromEnvironmentId)(bundle.env).context === 'tesseract' && bundle.type === 'js') {
|
|
72
72
|
// Once this actually does something, the code below will be in an `else` block (i.e. we'll only run one or the other)
|
|
73
|
-
let result = await rustAtlaspack.package(bundle.id
|
|
73
|
+
let result = await rustAtlaspack.package(bundle.id, {
|
|
74
|
+
inlineRequires: true
|
|
75
|
+
});
|
|
74
76
|
let error = null;
|
|
75
77
|
[packagingResult, error] = result;
|
|
76
78
|
if (error) {
|
|
@@ -247,6 +247,7 @@ class TargetResolver {
|
|
|
247
247
|
name,
|
|
248
248
|
distDir: (0, _projectPath.toProjectPath)(this.options.projectRoot, _path().default.resolve(this.fs.cwd(), distDir)),
|
|
249
249
|
publicUrl: descriptor.publicUrl ?? this.options.defaultTargetOptions.publicUrl,
|
|
250
|
+
inlineRequires: descriptor.inlineRequires ?? false,
|
|
250
251
|
env: (0, _Environment.createEnvironment)({
|
|
251
252
|
engines: descriptor.engines,
|
|
252
253
|
context: descriptor.context,
|
|
@@ -311,6 +312,7 @@ class TargetResolver {
|
|
|
311
312
|
name: 'default',
|
|
312
313
|
distDir: (0, _projectPath.toProjectPath)(this.options.projectRoot, this.options.serveOptions.distDir),
|
|
313
314
|
publicUrl: this.options.defaultTargetOptions.publicUrl ?? '/',
|
|
315
|
+
inlineRequires: false,
|
|
314
316
|
env: (0, _Environment.createEnvironment)({
|
|
315
317
|
context: 'browser',
|
|
316
318
|
engines: {
|
|
@@ -670,6 +672,7 @@ class TargetResolver {
|
|
|
670
672
|
distDir,
|
|
671
673
|
distEntry,
|
|
672
674
|
publicUrl: descriptor.publicUrl ?? this.options.defaultTargetOptions.publicUrl,
|
|
675
|
+
inlineRequires: descriptor.inlineRequires ?? false,
|
|
673
676
|
env: (0, _Environment.createEnvironment)({
|
|
674
677
|
engines: descriptor.engines ?? pkgEngines,
|
|
675
678
|
// @ts-expect-error TS2322
|
|
@@ -819,6 +822,7 @@ class TargetResolver {
|
|
|
819
822
|
distDir: (0, _projectPath.toProjectPath)(this.options.projectRoot, descriptor.distDir != null ? _path().default.resolve(pkgDir, descriptor.distDir) : distDir),
|
|
820
823
|
distEntry,
|
|
821
824
|
publicUrl: descriptor.publicUrl ?? this.options.defaultTargetOptions.publicUrl,
|
|
825
|
+
inlineRequires: descriptor.inlineRequires ?? false,
|
|
822
826
|
env: (0, _Environment.createEnvironment)({
|
|
823
827
|
engines: descriptor.engines ?? pkgEngines,
|
|
824
828
|
context: descriptor.context,
|
|
@@ -889,6 +893,7 @@ class TargetResolver {
|
|
|
889
893
|
name: 'default',
|
|
890
894
|
distDir: this.options.defaultTargetOptions.distDir ?? (0, _projectPath.toProjectPath)(this.options.projectRoot, _path().default.join(pkgDir, DEFAULT_DIST_DIRNAME)),
|
|
891
895
|
publicUrl: this.options.defaultTargetOptions.publicUrl,
|
|
896
|
+
inlineRequires: false,
|
|
892
897
|
env: (0, _Environment.createEnvironment)({
|
|
893
898
|
engines: pkgEngines,
|
|
894
899
|
// @ts-expect-error TS2322
|
|
@@ -177,11 +177,11 @@ async function run({
|
|
|
177
177
|
(0, _DevDepRequest.invalidateDevDeps)(invalidDevDeps, options, config);
|
|
178
178
|
const bundleReplacements = (0, _featureFlags().getFeatureFlag)('fixSourceMapHashRefs') ? [] : undefined;
|
|
179
179
|
await writeFiles(contentStream, info, hashRefToNameHash, options, config, outputFS, filePath, writeOptions, devDeps, api, bundleReplacements);
|
|
180
|
-
const hasSourceMap =
|
|
180
|
+
const hasSourceMap = await options.cache.has(mapKey);
|
|
181
181
|
if (mapKey && env.sourceMap && !env.sourceMap.inline && hasSourceMap) {
|
|
182
182
|
let mapStream;
|
|
183
183
|
if ((0, _featureFlags().getFeatureFlag)('fixSourceMapHashRefs') && bundleReplacements && bundleReplacements.length > 0) {
|
|
184
|
-
const mapEntry =
|
|
184
|
+
const mapEntry = await options.cache.getBlob(mapKey);
|
|
185
185
|
const mapBuffer = Buffer.isBuffer(mapEntry) ? mapEntry : Buffer.from(mapEntry);
|
|
186
186
|
const projectRoot = typeof options.projectRoot === 'string' ? options.projectRoot : String(options.projectRoot);
|
|
187
187
|
const sourceMap = new (_sourceMap().default)(projectRoot, mapBuffer);
|
|
@@ -193,7 +193,7 @@ async function run({
|
|
|
193
193
|
});
|
|
194
194
|
mapStream = (0, _utils().blobToStream)(Buffer.from(typeof mapJson === 'string' ? mapJson : JSON.stringify(mapJson), 'utf8'));
|
|
195
195
|
} else {
|
|
196
|
-
const mapEntry =
|
|
196
|
+
const mapEntry = await options.cache.getBlob(mapKey);
|
|
197
197
|
mapStream = (0, _utils().blobToStream)(mapEntry);
|
|
198
198
|
}
|
|
199
199
|
await writeFiles(mapStream, info, hashRefToNameHash, options, config, outputFS, (0, _projectPath.toProjectPathUnsafe)((0, _projectPath.fromProjectPathRelative)(filePath) + '.map'), writeOptions, devDeps, api);
|
package/lib/resolveOptions.js
CHANGED
|
@@ -167,10 +167,8 @@ async function resolveOptions(initialOptions) {
|
|
|
167
167
|
return initialOptions.cache;
|
|
168
168
|
}
|
|
169
169
|
const needsRustLmdbCache = (0, _featureFlags().getFeatureFlag)('atlaspackV3') || (0, _featureFlags().getFeatureFlag)('nativePackager');
|
|
170
|
-
if (!(
|
|
171
|
-
|
|
172
|
-
return new (_cache().FSCache)(outputFS, cacheDir);
|
|
173
|
-
}
|
|
170
|
+
if (!needsRustLmdbCache && !(outputFS instanceof _fs().NodeFS)) {
|
|
171
|
+
return new (_cache().FSCache)(outputFS, cacheDir);
|
|
174
172
|
}
|
|
175
173
|
return new (_cache().LMDBLiteCache)(cacheDir);
|
|
176
174
|
}
|
|
@@ -9,13 +9,9 @@ type InitOpts = {
|
|
|
9
9
|
assetGroups?: Array<AssetGroup>;
|
|
10
10
|
};
|
|
11
11
|
type AssetGraphOpts = ContentGraphOpts<AssetGraphNode> & {
|
|
12
|
-
bundlingVersion?: number;
|
|
13
|
-
disableIncrementalBundling?: boolean;
|
|
14
12
|
hash?: string | null | undefined;
|
|
15
13
|
};
|
|
16
14
|
type SerializedAssetGraph = SerializedContentGraph<AssetGraphNode> & {
|
|
17
|
-
bundlingVersion: number;
|
|
18
|
-
disableIncrementalBundling: boolean;
|
|
19
15
|
hash?: string | null | undefined;
|
|
20
16
|
};
|
|
21
17
|
export declare function nodeFromDep(dep: Dependency): DependencyNode;
|
|
@@ -24,40 +20,19 @@ export declare function nodeFromAsset(asset: Asset): AssetNode;
|
|
|
24
20
|
export declare function nodeFromEntrySpecifier(entry: ProjectPath): EntrySpecifierNode;
|
|
25
21
|
export declare function nodeFromEntryFile(entry: Entry): EntryFileNode;
|
|
26
22
|
export default class AssetGraph extends ContentGraph<AssetGraphNode> {
|
|
27
|
-
#private;
|
|
28
23
|
onNodeRemoved: ((nodeId: NodeId) => unknown) | null | undefined;
|
|
29
24
|
hash: string | null | undefined;
|
|
30
25
|
envCache: Map<string, Environment>;
|
|
31
|
-
/**
|
|
32
|
-
* @deprecated
|
|
33
|
-
*/
|
|
34
26
|
safeToIncrementallyBundle: boolean;
|
|
35
27
|
undeferredDependencies: Set<Dependency>;
|
|
36
28
|
constructor(opts?: AssetGraphOpts | null);
|
|
37
29
|
static deserialize(opts: AssetGraphOpts): AssetGraph;
|
|
38
30
|
serialize(): SerializedAssetGraph;
|
|
39
31
|
/**
|
|
40
|
-
*
|
|
41
|
-
*/
|
|
42
|
-
setDisableIncrementalBundling(disable: boolean): void;
|
|
43
|
-
testing_getDisableIncrementalBundling(): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Make sure this asset graph is marked as needing a full bundling pass.
|
|
46
|
-
*/
|
|
47
|
-
setNeedsBundling(): void;
|
|
48
|
-
/**
|
|
49
|
-
* Get the current bundling version.
|
|
50
|
-
*
|
|
51
|
-
* Each bundle pass should keep this version around. Whenever an asset graph has a new version,
|
|
52
|
-
* bundling should be re-run.
|
|
53
|
-
*/
|
|
54
|
-
getBundlingVersion(): number;
|
|
55
|
-
/**
|
|
56
|
-
* If the `bundlingVersion` has not changed since the last bundling pass,
|
|
57
|
-
* we can incrementally bundle, which will not require a full bundling pass
|
|
32
|
+
* Determine if we can incrementally bundle, which will not require a full bundling pass
|
|
58
33
|
* but just update assets into the bundle graph output.
|
|
59
34
|
*/
|
|
60
|
-
canIncrementallyBundle(
|
|
35
|
+
canIncrementallyBundle(): boolean;
|
|
61
36
|
normalizeEnvironment(input: Asset | Dependency | AssetGroup): void;
|
|
62
37
|
setRootConnections({ entries, assetGroups }: InitOpts): void;
|
|
63
38
|
addNode(node: AssetGraphNode): NodeId;
|
|
@@ -87,6 +87,11 @@ export default class BundleGraph {
|
|
|
87
87
|
publicIdByAssetId: Record<string, string>;
|
|
88
88
|
environmentsJson: string;
|
|
89
89
|
};
|
|
90
|
+
/**
|
|
91
|
+
* Serialize only the given asset nodes for native incremental update.
|
|
92
|
+
* Same node shape and env/omit logic as serializeForNative.
|
|
93
|
+
*/
|
|
94
|
+
serializeAssetNodesForNative(assetIds: Array<string>): string;
|
|
90
95
|
/**
|
|
91
96
|
* Remove null and undefined values from an object to reduce JSON size.
|
|
92
97
|
* Preserves false, 0, empty strings, and arrays.
|