@atlaspack/core 2.33.1 → 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 +72 -0
- package/dist/AssetGraph.js +4 -72
- package/dist/BundleGraph.js +34 -0
- package/dist/PackagerRunner.js +13 -88
- package/dist/RequestTracker.js +17 -80
- package/dist/TargetDescriptor.schema.js +3 -0
- package/dist/UncommittedAsset.js +0 -5
- package/dist/applyRuntimes.js +2 -1
- package/dist/atlaspack-v3/AtlaspackV3.js +6 -2
- package/dist/requests/AssetGraphRequest.js +6 -15
- package/dist/requests/AssetGraphRequestRust.js +119 -22
- package/dist/requests/AtlaspackBuildRequest.js +8 -2
- package/dist/requests/BundleGraphRequest.js +9 -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 +129 -12
- package/dist/requests/WriteBundlesRequest.js +15 -9
- package/dist/resolveOptions.js +2 -4
- package/lib/AssetGraph.js +3 -62
- package/lib/BundleGraph.js +38 -0
- package/lib/PackagerRunner.js +13 -77
- package/lib/RequestTracker.js +15 -69
- package/lib/TargetDescriptor.schema.js +3 -0
- package/lib/UncommittedAsset.js +0 -11
- package/lib/applyRuntimes.js +1 -1
- package/lib/atlaspack-v3/AtlaspackV3.js +6 -2
- package/lib/requests/AssetGraphRequest.js +4 -18
- package/lib/requests/AssetGraphRequestRust.js +88 -23
- package/lib/requests/AtlaspackBuildRequest.js +8 -2
- package/lib/requests/BundleGraphRequest.js +12 -16
- 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 +131 -8
- package/lib/requests/WriteBundlesRequest.js +12 -5
- 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/requests/WriteBundleRequest.d.ts +20 -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 +15 -101
- package/src/RequestTracker.ts +24 -110
- package/src/TargetDescriptor.schema.ts +3 -0
- package/src/UncommittedAsset.ts +1 -11
- package/src/applyRuntimes.ts +3 -1
- package/src/atlaspack-v3/AtlaspackV3.ts +19 -3
- package/src/requests/AssetGraphRequest.ts +8 -20
- package/src/requests/AssetGraphRequestRust.ts +96 -23
- package/src/requests/AtlaspackBuildRequest.ts +16 -8
- package/src/requests/BundleGraphRequest.ts +12 -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 +177 -13
- package/src/requests/WriteBundlesRequest.ts +25 -13
- 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/test/requests/WriteBundleRequest.test.ts +239 -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) {
|
package/lib/applyRuntimes.js
CHANGED
|
@@ -437,7 +437,7 @@ function reconcileNewRuntimes(api, connections, optionsRef) {
|
|
|
437
437
|
name: 'Runtimes',
|
|
438
438
|
assetGroups,
|
|
439
439
|
optionsRef,
|
|
440
|
-
skipSymbolProp: (0, _featureFlags().getFeatureFlag)('skipRuntimeSymbolProp')
|
|
440
|
+
skipSymbolProp: (0, _featureFlags().getFeatureFlag)('skipRuntimeSymbolProp') || (0, _featureFlags().getFeatureFlag)('rustSymbolTracker')
|
|
441
441
|
});
|
|
442
442
|
|
|
443
443
|
// rebuild the graph
|
|
@@ -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
|
}
|
|
@@ -20,7 +20,7 @@ function _diagnostic() {
|
|
|
20
20
|
return data;
|
|
21
21
|
}
|
|
22
22
|
function _logger() {
|
|
23
|
-
const data = require("@atlaspack/logger");
|
|
23
|
+
const data = _interopRequireWildcard(require("@atlaspack/logger"));
|
|
24
24
|
_logger = function () {
|
|
25
25
|
return data;
|
|
26
26
|
};
|
|
@@ -39,13 +39,15 @@ var _SymbolPropagation = require("../SymbolPropagation");
|
|
|
39
39
|
var _EnvironmentManager = require("../EnvironmentManager");
|
|
40
40
|
var _Environment = require("../Environment");
|
|
41
41
|
var _dumpGraphToGraphViz = _interopRequireDefault(require("../dumpGraphToGraphViz"));
|
|
42
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
43
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
42
44
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
43
45
|
function createAssetGraphRequestRust(rustAtlaspack) {
|
|
44
46
|
return input => ({
|
|
45
47
|
type: _RequestTracker.requestTypes.asset_graph_request,
|
|
46
48
|
id: input.name,
|
|
47
|
-
run: async
|
|
48
|
-
let options =
|
|
49
|
+
run: async runInput => {
|
|
50
|
+
let options = runInput.options;
|
|
49
51
|
let {
|
|
50
52
|
assetGraphPromise,
|
|
51
53
|
commitPromise
|
|
@@ -60,7 +62,7 @@ function createAssetGraphRequestRust(rustAtlaspack) {
|
|
|
60
62
|
// Don't reuse a previous asset graph result if Rust didn't have one too
|
|
61
63
|
let prevResult = null;
|
|
62
64
|
if (serializedAssetGraph.hadPreviousGraph) {
|
|
63
|
-
prevResult = await
|
|
65
|
+
prevResult = await runInput.api.getPreviousResult();
|
|
64
66
|
}
|
|
65
67
|
let {
|
|
66
68
|
assetGraph,
|
|
@@ -70,20 +72,28 @@ function createAssetGraphRequestRust(rustAtlaspack) {
|
|
|
70
72
|
return getAssetGraph(serializedAssetGraph, (_prevResult = prevResult) === null || _prevResult === void 0 ? void 0 : _prevResult.assetGraph);
|
|
71
73
|
});
|
|
72
74
|
let changedAssetsPropagation = new Set(changedAssets.keys());
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
previousErrors: new Map() //this.previousSymbolPropagationErrors,
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
if (errors.size > 0) {
|
|
82
|
-
// Just throw the first error. Since errors can bubble (e.g. reexporting a reexported symbol also fails),
|
|
83
|
-
// determining which failing export is the root cause is nontrivial (because of circular dependencies).
|
|
84
|
-
throw new (_diagnostic().default)({
|
|
85
|
-
diagnostic: [...errors.values()][0]
|
|
75
|
+
// Skip symbol propagation for runtime assets - they have pre-computed symbol data
|
|
76
|
+
if (input.skipSymbolProp) {
|
|
77
|
+
_logger().default.verbose({
|
|
78
|
+
origin: '@atlaspack/core',
|
|
79
|
+
message: 'Skipping symbol propagation for runtime asset graph'
|
|
86
80
|
});
|
|
81
|
+
} else {
|
|
82
|
+
let errors = (0, _SymbolPropagation.propagateSymbols)({
|
|
83
|
+
options,
|
|
84
|
+
assetGraph,
|
|
85
|
+
changedAssetsPropagation,
|
|
86
|
+
assetGroupsWithRemovedParents: new Set(),
|
|
87
|
+
previousErrors: new Map() //this.previousSymbolPropagationErrors,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
if (errors.size > 0) {
|
|
91
|
+
// Just throw the first error. Since errors can bubble (e.g. reexporting a reexported symbol also fails),
|
|
92
|
+
// determining which failing export is the root cause is nontrivial (because of circular dependencies).
|
|
93
|
+
throw new (_diagnostic().default)({
|
|
94
|
+
diagnostic: [...errors.values()][0]
|
|
95
|
+
});
|
|
96
|
+
}
|
|
87
97
|
}
|
|
88
98
|
await (0, _dumpGraphToGraphViz.default)(assetGraph, 'AssetGraphV3');
|
|
89
99
|
let result = {
|
|
@@ -102,8 +112,8 @@ function createAssetGraphRequestRust(rustAtlaspack) {
|
|
|
102
112
|
}
|
|
103
113
|
});
|
|
104
114
|
}
|
|
105
|
-
await
|
|
106
|
-
|
|
115
|
+
await runInput.api.storeResult(result);
|
|
116
|
+
runInput.api.invalidateOnBuild();
|
|
107
117
|
return result;
|
|
108
118
|
},
|
|
109
119
|
input
|
|
@@ -185,13 +195,57 @@ function getAssetGraph(serializedGraph, prevAssetGraph) {
|
|
|
185
195
|
}
|
|
186
196
|
return envId;
|
|
187
197
|
};
|
|
188
|
-
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) {
|
|
189
222
|
if (isUpdateNode) {
|
|
190
223
|
let existingNode = graph.getNodeByContentKey(newNode.id);
|
|
191
224
|
(0, _assert().default)(existingNode && existingNode.type === newNode.type);
|
|
192
225
|
Object.assign(existingNode, newNode);
|
|
193
226
|
} else {
|
|
194
|
-
|
|
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
|
+
}
|
|
195
249
|
}
|
|
196
250
|
}
|
|
197
251
|
let nodeTypeSwitchoverIndex = serializedGraph.nodes.length;
|
|
@@ -236,7 +290,7 @@ function getAssetGraph(serializedGraph, prevAssetGraph) {
|
|
|
236
290
|
usedSymbolsUpDirty: true,
|
|
237
291
|
value: asset
|
|
238
292
|
};
|
|
239
|
-
updateNode(assetNode, isUpdateNode);
|
|
293
|
+
updateNode(assetNode, isUpdateNode, index);
|
|
240
294
|
} else if (node.type === 'dependency') {
|
|
241
295
|
let {
|
|
242
296
|
dependency,
|
|
@@ -253,6 +307,17 @@ function getAssetGraph(serializedGraph, prevAssetGraph) {
|
|
|
253
307
|
}
|
|
254
308
|
let usedSymbolsDown = new Set();
|
|
255
309
|
let usedSymbolsUp = new Map();
|
|
310
|
+
if (node.used_symbols_up) {
|
|
311
|
+
for (let usedSymbol of node.used_symbols_up) {
|
|
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
|
|
314
|
+
const exportedName = usedSymbol.symbol.exported;
|
|
315
|
+
usedSymbolsUp.set(exportedName, {
|
|
316
|
+
asset: usedSymbol.asset,
|
|
317
|
+
symbol: usedSymbol.resolved_symbol ?? exportedName
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
}
|
|
256
321
|
if (dependency.isEntry && dependency.isLibrary) {
|
|
257
322
|
usedSymbolsDown.add('*');
|
|
258
323
|
usedSymbolsUp.set('*', undefined);
|
|
@@ -271,7 +336,7 @@ function getAssetGraph(serializedGraph, prevAssetGraph) {
|
|
|
271
336
|
usedSymbolsUpDirtyUp: true,
|
|
272
337
|
value: dependency
|
|
273
338
|
};
|
|
274
|
-
updateNode(depNode, isUpdateNode);
|
|
339
|
+
updateNode(depNode, isUpdateNode, index);
|
|
275
340
|
}
|
|
276
341
|
}
|
|
277
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
|
|
|
@@ -136,7 +136,8 @@ function createBundleGraphRequest(input) {
|
|
|
136
136
|
shouldBuildLazily: options.shouldBuildLazily,
|
|
137
137
|
lazyIncludes: options.lazyIncludes,
|
|
138
138
|
lazyExcludes: options.lazyExcludes,
|
|
139
|
-
requestedAssetIds
|
|
139
|
+
requestedAssetIds,
|
|
140
|
+
skipSymbolProp: (0, _featureFlags().getFeatureFlag)('rustSymbolTracker')
|
|
140
141
|
});
|
|
141
142
|
let {
|
|
142
143
|
assetGraph,
|
|
@@ -186,7 +187,6 @@ function createBundleGraphRequest(input) {
|
|
|
186
187
|
let subRequestsInvalid = Boolean(invalidateReason & _constants.OPTION_CHANGE) || input.api.getSubRequests().some(req => !input.api.canSkipSubrequest(req.id));
|
|
187
188
|
if (subRequestsInvalid) {
|
|
188
189
|
assetGraph.safeToIncrementallyBundle = false;
|
|
189
|
-
assetGraph.setNeedsBundling();
|
|
190
190
|
}
|
|
191
191
|
let configResult = (0, _nullthrows().default)(await input.api.runRequest((0, _AtlaspackConfigRequest.default)()));
|
|
192
192
|
(0, _utils.assertSignalNotAborted)(signal);
|
|
@@ -229,12 +229,7 @@ class BundlerRunner {
|
|
|
229
229
|
this.devDepRequests = new Map();
|
|
230
230
|
this.configs = new Map();
|
|
231
231
|
this.pluginOptions = new _PluginOptions.default((0, _utils.optionsProxy)(this.options, api.invalidateOnOptionChange));
|
|
232
|
-
|
|
233
|
-
const key = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`);
|
|
234
|
-
this.cacheKey = `BundleGraph/${_constants.ATLASPACK_VERSION}/${options.mode}/${key}`;
|
|
235
|
-
} else {
|
|
236
|
-
this.cacheKey = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-BundleGraph';
|
|
237
|
-
}
|
|
232
|
+
this.cacheKey = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-BundleGraph';
|
|
238
233
|
}
|
|
239
234
|
async loadConfigs() {
|
|
240
235
|
// Load all configs up front so we can use them in the cache key
|
|
@@ -264,6 +259,7 @@ class BundlerRunner {
|
|
|
264
259
|
type: 'buildProgress',
|
|
265
260
|
phase: 'bundling'
|
|
266
261
|
});
|
|
262
|
+
let didIncrementallyBundle = false;
|
|
267
263
|
await this.loadConfigs();
|
|
268
264
|
let plugin = await this.config.getBundler();
|
|
269
265
|
let {
|
|
@@ -274,10 +270,9 @@ class BundlerRunner {
|
|
|
274
270
|
|
|
275
271
|
// if a previous asset graph hash is passed in, check if the bundle graph is also available
|
|
276
272
|
const previousBundleGraphResult = await this.api.getPreviousResult();
|
|
277
|
-
const canIncrementallyBundle =
|
|
273
|
+
const canIncrementallyBundle = previousBundleGraphResult != null && graph.canIncrementallyBundle();
|
|
278
274
|
if (graph.safeToIncrementallyBundle && previousBundleGraphResult == null) {
|
|
279
275
|
graph.safeToIncrementallyBundle = false;
|
|
280
|
-
graph.setNeedsBundling();
|
|
281
276
|
}
|
|
282
277
|
let internalBundleGraph;
|
|
283
278
|
let logger = new (_logger().PluginLogger)({
|
|
@@ -296,6 +291,7 @@ class BundlerRunner {
|
|
|
296
291
|
(0, _assert().default)(changedAssetNode.type === 'asset');
|
|
297
292
|
internalBundleGraph.updateAsset(changedAssetNode);
|
|
298
293
|
}
|
|
294
|
+
didIncrementallyBundle = true;
|
|
299
295
|
} else {
|
|
300
296
|
var _this$configs$get;
|
|
301
297
|
internalBundleGraph = _BundleGraph.default.fromAssetGraph(graph, this.options.mode === 'production');
|
|
@@ -360,9 +356,9 @@ class BundlerRunner {
|
|
|
360
356
|
if (internalBundleGraph != null) {
|
|
361
357
|
this.api.storeResult({
|
|
362
358
|
bundleGraph: internalBundleGraph,
|
|
363
|
-
assetGraphBundlingVersion: graph.getBundlingVersion(),
|
|
364
359
|
changedAssets: new Map(),
|
|
365
|
-
assetRequests: []
|
|
360
|
+
assetRequests: [],
|
|
361
|
+
didIncrementallyBundle
|
|
366
362
|
}, this.cacheKey);
|
|
367
363
|
}
|
|
368
364
|
throw new (_diagnostic().default)({
|
|
@@ -416,15 +412,15 @@ class BundlerRunner {
|
|
|
416
412
|
internalBundleGraph._graph, 'after_runtimes', _BundleGraph.bundleGraphEdgeTypes);
|
|
417
413
|
this.api.storeResult({
|
|
418
414
|
bundleGraph: internalBundleGraph,
|
|
419
|
-
assetGraphBundlingVersion: graph.getBundlingVersion(),
|
|
420
415
|
changedAssets: new Map(),
|
|
421
|
-
assetRequests: []
|
|
416
|
+
assetRequests: [],
|
|
417
|
+
didIncrementallyBundle
|
|
422
418
|
}, this.cacheKey);
|
|
423
419
|
return {
|
|
424
420
|
bundleGraph: internalBundleGraph,
|
|
425
|
-
assetGraphBundlingVersion: graph.getBundlingVersion(),
|
|
426
421
|
changedAssets: changedRuntimes,
|
|
427
|
-
assetRequests
|
|
422
|
+
assetRequests,
|
|
423
|
+
didIncrementallyBundle
|
|
428
424
|
};
|
|
429
425
|
}
|
|
430
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
|