@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
|
@@ -203,14 +203,58 @@ function getAssetGraph(serializedGraph, prevAssetGraph) {
|
|
|
203
203
|
}
|
|
204
204
|
return envId;
|
|
205
205
|
};
|
|
206
|
-
function
|
|
206
|
+
function describeNode(node) {
|
|
207
|
+
const base = { type: node.type, id: node.id };
|
|
208
|
+
if (node.type === 'asset') {
|
|
209
|
+
return {
|
|
210
|
+
...base,
|
|
211
|
+
filePath: node.value.filePath,
|
|
212
|
+
fileType: node.value.type,
|
|
213
|
+
pipeline: node.value.pipeline,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
else if (node.type === 'dependency') {
|
|
217
|
+
return {
|
|
218
|
+
...base,
|
|
219
|
+
specifier: node.value.specifier,
|
|
220
|
+
specifierType: node.value.specifierType,
|
|
221
|
+
sourceAssetId: node.value.sourceAssetId,
|
|
222
|
+
sourcePath: node.value.sourcePath,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
return base;
|
|
226
|
+
}
|
|
227
|
+
function updateNode(newNode, isUpdateNode, index) {
|
|
207
228
|
if (isUpdateNode) {
|
|
208
229
|
let existingNode = graph.getNodeByContentKey(newNode.id);
|
|
209
230
|
(0, assert_2.default)(existingNode && existingNode.type === newNode.type);
|
|
210
231
|
Object.assign(existingNode, newNode);
|
|
211
232
|
}
|
|
212
233
|
else {
|
|
213
|
-
|
|
234
|
+
try {
|
|
235
|
+
graph.addNodeByContentKey(newNode.id, newNode);
|
|
236
|
+
}
|
|
237
|
+
catch (e) {
|
|
238
|
+
if (e instanceof Error &&
|
|
239
|
+
e.message.includes('already has content key')) {
|
|
240
|
+
let existingNode = graph.getNodeByContentKey(newNode.id);
|
|
241
|
+
let diagnostics = {
|
|
242
|
+
contentKey: newNode.id,
|
|
243
|
+
newNode: describeNode(newNode),
|
|
244
|
+
existingNode: existingNode ? describeNode(existingNode) : null,
|
|
245
|
+
iterationIndex: index,
|
|
246
|
+
totalSerializedNodes: nodesCount,
|
|
247
|
+
newNodesCount: serializedGraph.nodes.length,
|
|
248
|
+
updatesCount: serializedGraph.updates.length,
|
|
249
|
+
edgesCount: serializedGraph.edges.length,
|
|
250
|
+
hadPreviousGraph: !!prevAssetGraph,
|
|
251
|
+
safeToSkipBundling: serializedGraph.safeToSkipBundling,
|
|
252
|
+
graphNodeCount: graph._contentKeyToNodeId.size,
|
|
253
|
+
};
|
|
254
|
+
throw new Error(`Graph already has content key '${newNode.id}'. Diagnostics: ${JSON.stringify(diagnostics, null, 2)}`);
|
|
255
|
+
}
|
|
256
|
+
throw e;
|
|
257
|
+
}
|
|
214
258
|
}
|
|
215
259
|
}
|
|
216
260
|
let nodeTypeSwitchoverIndex = serializedGraph.nodes.length;
|
|
@@ -257,7 +301,7 @@ function getAssetGraph(serializedGraph, prevAssetGraph) {
|
|
|
257
301
|
usedSymbolsUpDirty: true,
|
|
258
302
|
value: asset,
|
|
259
303
|
};
|
|
260
|
-
updateNode(assetNode, isUpdateNode);
|
|
304
|
+
updateNode(assetNode, isUpdateNode, index);
|
|
261
305
|
}
|
|
262
306
|
else if (node.type === 'dependency') {
|
|
263
307
|
let { dependency, id } = node.value;
|
|
@@ -274,12 +318,12 @@ function getAssetGraph(serializedGraph, prevAssetGraph) {
|
|
|
274
318
|
let usedSymbolsUp = new Map();
|
|
275
319
|
if (node.used_symbols_up) {
|
|
276
320
|
for (let usedSymbol of node.used_symbols_up) {
|
|
277
|
-
// Transform Rust UsedSymbol { symbol: Symbol, asset: string }
|
|
278
|
-
// to JS format { symbol: string, asset: string } where symbol is the
|
|
321
|
+
// Transform Rust UsedSymbol { symbol: Symbol, asset: string, resolved_symbol: string }
|
|
322
|
+
// to JS format { symbol: string, asset: string } where symbol is the resolved name
|
|
279
323
|
const exportedName = usedSymbol.symbol.exported;
|
|
280
324
|
usedSymbolsUp.set(exportedName, {
|
|
281
325
|
asset: usedSymbol.asset,
|
|
282
|
-
symbol: exportedName,
|
|
326
|
+
symbol: usedSymbol.resolved_symbol ?? exportedName,
|
|
283
327
|
});
|
|
284
328
|
}
|
|
285
329
|
}
|
|
@@ -301,7 +345,7 @@ function getAssetGraph(serializedGraph, prevAssetGraph) {
|
|
|
301
345
|
usedSymbolsUpDirtyUp: true,
|
|
302
346
|
value: dependency,
|
|
303
347
|
};
|
|
304
|
-
updateNode(depNode, isUpdateNode);
|
|
348
|
+
updateNode(depNode, isUpdateNode, index);
|
|
305
349
|
}
|
|
306
350
|
}
|
|
307
351
|
if (!reuseEdges) {
|
|
@@ -39,7 +39,7 @@ async function run({ input, api, options, rustAtlaspack, }) {
|
|
|
39
39
|
requestedAssetIds,
|
|
40
40
|
signal,
|
|
41
41
|
});
|
|
42
|
-
let { bundleGraph, changedAssets, assetRequests } = await api.runRequest(bundleGraphRequest, {
|
|
42
|
+
let { bundleGraph, changedAssets, assetRequests, didIncrementallyBundle, } = await api.runRequest(bundleGraphRequest, {
|
|
43
43
|
force: Boolean(rustAtlaspack) ||
|
|
44
44
|
(options.shouldBuildLazily && requestedAssetIds.size > 0),
|
|
45
45
|
});
|
|
@@ -55,7 +55,13 @@ async function run({ input, api, options, rustAtlaspack, }) {
|
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
if (hasSupportedTarget) {
|
|
58
|
-
|
|
58
|
+
if (didIncrementallyBundle) {
|
|
59
|
+
const changedAssetIds = Array.from(changedAssets.keys());
|
|
60
|
+
await rustAtlaspack.updateBundleGraph(bundleGraph, changedAssetIds);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
await rustAtlaspack.loadBundleGraph(bundleGraph);
|
|
64
|
+
}
|
|
59
65
|
}
|
|
60
66
|
}
|
|
61
67
|
// @ts-expect-error TS2345
|
|
@@ -157,7 +157,6 @@ function createBundleGraphRequest(input) {
|
|
|
157
157
|
.some((req) => !input.api.canSkipSubrequest(req.id));
|
|
158
158
|
if (subRequestsInvalid) {
|
|
159
159
|
assetGraph.safeToIncrementallyBundle = false;
|
|
160
|
-
assetGraph.setNeedsBundling();
|
|
161
160
|
}
|
|
162
161
|
let configResult = (0, nullthrows_1.default)(await input.api.runRequest((0, AtlaspackConfigRequest_1.default)()));
|
|
163
162
|
(0, utils_1.assertSignalNotAborted)(signal);
|
|
@@ -193,14 +192,8 @@ class BundlerRunner {
|
|
|
193
192
|
this.devDepRequests = new Map();
|
|
194
193
|
this.configs = new Map();
|
|
195
194
|
this.pluginOptions = new PluginOptions_1.default((0, utils_1.optionsProxy)(this.options, api.invalidateOnOptionChange));
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
this.cacheKey = `BundleGraph/${constants_1.ATLASPACK_VERSION}/${options.mode}/${key}`;
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
this.cacheKey =
|
|
202
|
-
(0, rust_1.hashString)(`${constants_1.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-BundleGraph';
|
|
203
|
-
}
|
|
195
|
+
this.cacheKey =
|
|
196
|
+
(0, rust_1.hashString)(`${constants_1.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-BundleGraph';
|
|
204
197
|
}
|
|
205
198
|
async loadConfigs() {
|
|
206
199
|
// Load all configs up front so we can use them in the cache key
|
|
@@ -226,16 +219,15 @@ class BundlerRunner {
|
|
|
226
219
|
type: 'buildProgress',
|
|
227
220
|
phase: 'bundling',
|
|
228
221
|
});
|
|
222
|
+
let didIncrementallyBundle = false;
|
|
229
223
|
await this.loadConfigs();
|
|
230
224
|
let plugin = await this.config.getBundler();
|
|
231
225
|
let { plugin: bundler, name, resolveFrom } = plugin;
|
|
232
226
|
// if a previous asset graph hash is passed in, check if the bundle graph is also available
|
|
233
227
|
const previousBundleGraphResult = await this.api.getPreviousResult();
|
|
234
|
-
const canIncrementallyBundle = previousBundleGraphResult
|
|
235
|
-
graph.canIncrementallyBundle(previousBundleGraphResult.assetGraphBundlingVersion);
|
|
228
|
+
const canIncrementallyBundle = previousBundleGraphResult != null && graph.canIncrementallyBundle();
|
|
236
229
|
if (graph.safeToIncrementallyBundle && previousBundleGraphResult == null) {
|
|
237
230
|
graph.safeToIncrementallyBundle = false;
|
|
238
|
-
graph.setNeedsBundling();
|
|
239
231
|
}
|
|
240
232
|
let internalBundleGraph;
|
|
241
233
|
let logger = new logger_1.PluginLogger({ origin: name });
|
|
@@ -252,6 +244,7 @@ class BundlerRunner {
|
|
|
252
244
|
(0, assert_1.default)(changedAssetNode.type === 'asset');
|
|
253
245
|
internalBundleGraph.updateAsset(changedAssetNode);
|
|
254
246
|
}
|
|
247
|
+
didIncrementallyBundle = true;
|
|
255
248
|
}
|
|
256
249
|
else {
|
|
257
250
|
internalBundleGraph = BundleGraph_1.default.fromAssetGraph(graph, this.options.mode === 'production');
|
|
@@ -318,9 +311,9 @@ class BundlerRunner {
|
|
|
318
311
|
if (internalBundleGraph != null) {
|
|
319
312
|
this.api.storeResult({
|
|
320
313
|
bundleGraph: internalBundleGraph,
|
|
321
|
-
assetGraphBundlingVersion: graph.getBundlingVersion(),
|
|
322
314
|
changedAssets: new Map(),
|
|
323
315
|
assetRequests: [],
|
|
316
|
+
didIncrementallyBundle,
|
|
324
317
|
}, this.cacheKey);
|
|
325
318
|
}
|
|
326
319
|
throw new diagnostic_1.default({
|
|
@@ -371,15 +364,15 @@ class BundlerRunner {
|
|
|
371
364
|
internalBundleGraph._graph, 'after_runtimes', BundleGraph_1.bundleGraphEdgeTypes);
|
|
372
365
|
this.api.storeResult({
|
|
373
366
|
bundleGraph: internalBundleGraph,
|
|
374
|
-
assetGraphBundlingVersion: graph.getBundlingVersion(),
|
|
375
367
|
changedAssets: new Map(),
|
|
376
368
|
assetRequests: [],
|
|
369
|
+
didIncrementallyBundle,
|
|
377
370
|
}, this.cacheKey);
|
|
378
371
|
return {
|
|
379
372
|
bundleGraph: internalBundleGraph,
|
|
380
|
-
assetGraphBundlingVersion: graph.getBundlingVersion(),
|
|
381
373
|
changedAssets: changedRuntimes,
|
|
382
374
|
assetRequests,
|
|
375
|
+
didIncrementallyBundle,
|
|
383
376
|
};
|
|
384
377
|
}
|
|
385
378
|
}
|
|
@@ -112,10 +112,9 @@ function createBundleGraphRequestRust(input) {
|
|
|
112
112
|
}
|
|
113
113
|
return {
|
|
114
114
|
bundleGraph,
|
|
115
|
-
// Not accurate yet — ok for now.
|
|
116
|
-
assetGraphBundlingVersion: 0,
|
|
117
115
|
changedAssets: changedRuntimes,
|
|
118
116
|
assetRequests: [],
|
|
117
|
+
didIncrementallyBundle: false,
|
|
119
118
|
};
|
|
120
119
|
},
|
|
121
120
|
input,
|
|
@@ -34,7 +34,7 @@ async function run({ input, api, farm, rustAtlaspack }) {
|
|
|
34
34
|
(0, EnvironmentManager_1.fromEnvironmentId)(bundle.env).context === 'tesseract' &&
|
|
35
35
|
bundle.type === 'js') {
|
|
36
36
|
// Once this actually does something, the code below will be in an `else` block (i.e. we'll only run one or the other)
|
|
37
|
-
let result = await rustAtlaspack.package(bundle.id);
|
|
37
|
+
let result = await rustAtlaspack.package(bundle.id, { inlineRequires: true });
|
|
38
38
|
let error = null;
|
|
39
39
|
[packagingResult, error] = result;
|
|
40
40
|
if (error) {
|
|
@@ -227,6 +227,7 @@ class TargetResolver {
|
|
|
227
227
|
distDir: (0, projectPath_1.toProjectPath)(this.options.projectRoot, path_1.default.resolve(this.fs.cwd(), distDir)),
|
|
228
228
|
publicUrl: descriptor.publicUrl ??
|
|
229
229
|
this.options.defaultTargetOptions.publicUrl,
|
|
230
|
+
inlineRequires: descriptor.inlineRequires ?? false,
|
|
230
231
|
env: (0, Environment_1.createEnvironment)({
|
|
231
232
|
engines: descriptor.engines,
|
|
232
233
|
context: descriptor.context,
|
|
@@ -299,6 +300,7 @@ class TargetResolver {
|
|
|
299
300
|
name: 'default',
|
|
300
301
|
distDir: (0, projectPath_1.toProjectPath)(this.options.projectRoot, this.options.serveOptions.distDir),
|
|
301
302
|
publicUrl: this.options.defaultTargetOptions.publicUrl ?? '/',
|
|
303
|
+
inlineRequires: false,
|
|
302
304
|
env: (0, Environment_1.createEnvironment)({
|
|
303
305
|
context: 'browser',
|
|
304
306
|
engines: {
|
|
@@ -705,6 +707,7 @@ class TargetResolver {
|
|
|
705
707
|
distDir,
|
|
706
708
|
distEntry,
|
|
707
709
|
publicUrl: descriptor.publicUrl ?? this.options.defaultTargetOptions.publicUrl,
|
|
710
|
+
inlineRequires: descriptor.inlineRequires ?? false,
|
|
708
711
|
env: (0, Environment_1.createEnvironment)({
|
|
709
712
|
engines: descriptor.engines ?? pkgEngines,
|
|
710
713
|
// @ts-expect-error TS2322
|
|
@@ -870,6 +873,7 @@ class TargetResolver {
|
|
|
870
873
|
: distDir),
|
|
871
874
|
distEntry,
|
|
872
875
|
publicUrl: descriptor.publicUrl ?? this.options.defaultTargetOptions.publicUrl,
|
|
876
|
+
inlineRequires: descriptor.inlineRequires ?? false,
|
|
873
877
|
env: (0, Environment_1.createEnvironment)({
|
|
874
878
|
engines: descriptor.engines ?? pkgEngines,
|
|
875
879
|
context: descriptor.context,
|
|
@@ -932,6 +936,7 @@ class TargetResolver {
|
|
|
932
936
|
distDir: this.options.defaultTargetOptions.distDir ??
|
|
933
937
|
(0, projectPath_1.toProjectPath)(this.options.projectRoot, path_1.default.join(pkgDir, DEFAULT_DIST_DIRNAME)),
|
|
934
938
|
publicUrl: this.options.defaultTargetOptions.publicUrl,
|
|
939
|
+
inlineRequires: false,
|
|
935
940
|
env: (0, Environment_1.createEnvironment)({
|
|
936
941
|
engines: pkgEngines,
|
|
937
942
|
// @ts-expect-error TS2322
|
|
@@ -134,17 +134,13 @@ async function run({ input, options, api }) {
|
|
|
134
134
|
? []
|
|
135
135
|
: undefined;
|
|
136
136
|
await writeFiles(contentStream, info, hashRefToNameHash, options, config, outputFS, filePath, writeOptions, devDeps, api, bundleReplacements);
|
|
137
|
-
const hasSourceMap =
|
|
138
|
-
? await options.cache.hasLargeBlob(mapKey)
|
|
139
|
-
: await options.cache.has(mapKey);
|
|
137
|
+
const hasSourceMap = await options.cache.has(mapKey);
|
|
140
138
|
if (mapKey && env.sourceMap && !env.sourceMap.inline && hasSourceMap) {
|
|
141
139
|
let mapStream;
|
|
142
140
|
if ((0, feature_flags_1.getFeatureFlag)('fixSourceMapHashRefs') &&
|
|
143
141
|
bundleReplacements &&
|
|
144
142
|
bundleReplacements.length > 0) {
|
|
145
|
-
const mapEntry =
|
|
146
|
-
? await options.cache.getLargeBlob(mapKey)
|
|
147
|
-
: await options.cache.getBlob(mapKey);
|
|
143
|
+
const mapEntry = await options.cache.getBlob(mapKey);
|
|
148
144
|
const mapBuffer = Buffer.isBuffer(mapEntry)
|
|
149
145
|
? mapEntry
|
|
150
146
|
: Buffer.from(mapEntry);
|
|
@@ -161,9 +157,7 @@ async function run({ input, options, api }) {
|
|
|
161
157
|
mapStream = (0, utils_1.blobToStream)(Buffer.from(typeof mapJson === 'string' ? mapJson : JSON.stringify(mapJson), 'utf8'));
|
|
162
158
|
}
|
|
163
159
|
else {
|
|
164
|
-
const mapEntry =
|
|
165
|
-
? await options.cache.getLargeBlob(mapKey)
|
|
166
|
-
: await options.cache.getBlob(mapKey);
|
|
160
|
+
const mapEntry = await options.cache.getBlob(mapKey);
|
|
167
161
|
mapStream = (0, utils_1.blobToStream)(mapEntry);
|
|
168
162
|
}
|
|
169
163
|
await writeFiles(mapStream, info, hashRefToNameHash, options, config, outputFS, (0, projectPath_1.toProjectPathUnsafe)((0, projectPath_1.fromProjectPathRelative)(filePath) + '.map'), writeOptions, devDeps, api);
|
package/dist/resolveOptions.js
CHANGED
|
@@ -133,10 +133,8 @@ async function resolveOptions(initialOptions) {
|
|
|
133
133
|
return initialOptions.cache;
|
|
134
134
|
}
|
|
135
135
|
const needsRustLmdbCache = (0, feature_flags_1.getFeatureFlag)('atlaspackV3') || (0, feature_flags_1.getFeatureFlag)('nativePackager');
|
|
136
|
-
if (!(
|
|
137
|
-
|
|
138
|
-
return new cache_1.FSCache(outputFS, cacheDir);
|
|
139
|
-
}
|
|
136
|
+
if (!needsRustLmdbCache && !(outputFS instanceof fs_1.NodeFS)) {
|
|
137
|
+
return new cache_1.FSCache(outputFS, cacheDir);
|
|
140
138
|
}
|
|
141
139
|
return new cache_1.LMDBLiteCache(cacheDir);
|
|
142
140
|
}
|
package/lib/AssetGraph.js
CHANGED
|
@@ -108,32 +108,16 @@ function nodeFromEntryFile(entry) {
|
|
|
108
108
|
|
|
109
109
|
// @ts-expect-error TS2417
|
|
110
110
|
class AssetGraph extends _graph().ContentGraph {
|
|
111
|
-
/**
|
|
112
|
-
* Incremented when the asset graph is modified such that it requires a bundling pass.
|
|
113
|
-
*/
|
|
114
|
-
#bundlingVersion = 0;
|
|
115
|
-
/**
|
|
116
|
-
* Force incremental bundling to be disabled.
|
|
117
|
-
*/
|
|
118
|
-
#disableIncrementalBundling = false;
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* @deprecated
|
|
122
|
-
*/
|
|
123
111
|
safeToIncrementallyBundle = true;
|
|
124
112
|
constructor(opts) {
|
|
125
113
|
if (opts) {
|
|
126
114
|
let {
|
|
127
115
|
hash,
|
|
128
|
-
bundlingVersion,
|
|
129
|
-
disableIncrementalBundling,
|
|
130
116
|
...rest
|
|
131
117
|
} = opts;
|
|
132
118
|
// @ts-expect-error TS2345
|
|
133
119
|
super(rest);
|
|
134
120
|
this.hash = hash;
|
|
135
|
-
this.#bundlingVersion = bundlingVersion ?? 0;
|
|
136
|
-
this.#disableIncrementalBundling = disableIncrementalBundling ?? false;
|
|
137
121
|
} else {
|
|
138
122
|
super();
|
|
139
123
|
this.setRootNodeId(this.addNode({
|
|
@@ -151,57 +135,16 @@ class AssetGraph extends _graph().ContentGraph {
|
|
|
151
135
|
serialize() {
|
|
152
136
|
return {
|
|
153
137
|
...super.serialize(),
|
|
154
|
-
bundlingVersion: this.#bundlingVersion,
|
|
155
|
-
disableIncrementalBundling: this.#disableIncrementalBundling,
|
|
156
138
|
hash: this.hash
|
|
157
139
|
};
|
|
158
140
|
}
|
|
159
141
|
|
|
160
142
|
/**
|
|
161
|
-
*
|
|
162
|
-
*/
|
|
163
|
-
setDisableIncrementalBundling(disable) {
|
|
164
|
-
this.#disableIncrementalBundling = disable;
|
|
165
|
-
}
|
|
166
|
-
testing_getDisableIncrementalBundling() {
|
|
167
|
-
return this.#disableIncrementalBundling;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Make sure this asset graph is marked as needing a full bundling pass.
|
|
172
|
-
*/
|
|
173
|
-
setNeedsBundling() {
|
|
174
|
-
if (!(0, _featureFlags().getFeatureFlag)('incrementalBundlingVersioning')) {
|
|
175
|
-
// In legacy mode, we rely solely on safeToIncrementallyBundle to
|
|
176
|
-
// invalidate incremental bundling, so we skip bumping the version.
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
this.#bundlingVersion += 1;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Get the current bundling version.
|
|
184
|
-
*
|
|
185
|
-
* Each bundle pass should keep this version around. Whenever an asset graph has a new version,
|
|
186
|
-
* bundling should be re-run.
|
|
187
|
-
*/
|
|
188
|
-
getBundlingVersion() {
|
|
189
|
-
if (!(0, _featureFlags().getFeatureFlag)('incrementalBundlingVersioning')) {
|
|
190
|
-
return 0;
|
|
191
|
-
}
|
|
192
|
-
return this.#bundlingVersion;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* If the `bundlingVersion` has not changed since the last bundling pass,
|
|
197
|
-
* we can incrementally bundle, which will not require a full bundling pass
|
|
143
|
+
* Determine if we can incrementally bundle, which will not require a full bundling pass
|
|
198
144
|
* but just update assets into the bundle graph output.
|
|
199
145
|
*/
|
|
200
|
-
canIncrementallyBundle(
|
|
201
|
-
|
|
202
|
-
return this.safeToIncrementallyBundle && !this.#disableIncrementalBundling;
|
|
203
|
-
}
|
|
204
|
-
return this.safeToIncrementallyBundle && this.#bundlingVersion === lastVersion && !this.#disableIncrementalBundling;
|
|
146
|
+
canIncrementallyBundle() {
|
|
147
|
+
return this.safeToIncrementallyBundle;
|
|
205
148
|
}
|
|
206
149
|
|
|
207
150
|
// Deduplicates Environments by making them referentially equal
|
|
@@ -381,13 +324,11 @@ class AssetGraph extends _graph().ContentGraph {
|
|
|
381
324
|
// @ts-expect-error TS2339
|
|
382
325
|
if (!(ctx !== null && ctx !== void 0 && ctx.hasDeferred)) {
|
|
383
326
|
this.safeToIncrementallyBundle = false;
|
|
384
|
-
this.setNeedsBundling();
|
|
385
327
|
delete traversedNode.hasDeferred;
|
|
386
328
|
}
|
|
387
329
|
actions.skipChildren();
|
|
388
330
|
} else if (traversedNode.type === 'dependency') {
|
|
389
331
|
this.safeToIncrementallyBundle = false;
|
|
390
|
-
this.setNeedsBundling();
|
|
391
332
|
traversedNode.hasDeferred = false;
|
|
392
333
|
} else if (nodeId !== traversedNodeId) {
|
|
393
334
|
actions.skipChildren();
|
package/lib/BundleGraph.js
CHANGED
|
@@ -516,6 +516,44 @@ class BundleGraph {
|
|
|
516
516
|
};
|
|
517
517
|
}
|
|
518
518
|
|
|
519
|
+
/**
|
|
520
|
+
* Serialize only the given asset nodes for native incremental update.
|
|
521
|
+
* Same node shape and env/omit logic as serializeForNative.
|
|
522
|
+
*/
|
|
523
|
+
serializeAssetNodesForNative(assetIds) {
|
|
524
|
+
const start = performance.now();
|
|
525
|
+
if (assetIds.length === 0) {
|
|
526
|
+
return '[]';
|
|
527
|
+
}
|
|
528
|
+
const nodes = [];
|
|
529
|
+
for (const assetId of assetIds) {
|
|
530
|
+
var _node$value4;
|
|
531
|
+
const node = this._graph.getNodeByContentKey(assetId);
|
|
532
|
+
if ((node === null || node === void 0 ? void 0 : node.type) !== 'asset') {
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
535
|
+
const processedNode = {
|
|
536
|
+
...node
|
|
537
|
+
};
|
|
538
|
+
if ((_node$value4 = node.value) !== null && _node$value4 !== void 0 && _node$value4.env) {
|
|
539
|
+
processedNode.value = {
|
|
540
|
+
...node.value,
|
|
541
|
+
env: (0, _EnvironmentManager.fromEnvironmentId)(node.value.env).id
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
nodes.push(processedNode);
|
|
545
|
+
}
|
|
546
|
+
const optimizedNodes = nodes.map(node => this._omitNulls(node));
|
|
547
|
+
const nodesJson = JSON.stringify(optimizedNodes);
|
|
548
|
+
const duration = performance.now() - start;
|
|
549
|
+
const nodesSizeMB = (nodesJson.length / (1024 * 1024)).toFixed(2);
|
|
550
|
+
_logger().default.verbose({
|
|
551
|
+
origin: '@atlaspack/core',
|
|
552
|
+
message: `serializeAssetNodesForNative: ${duration.toFixed(1)}ms, ${nodesSizeMB}MB nodes, ${nodes.length} nodes`
|
|
553
|
+
});
|
|
554
|
+
return nodesJson;
|
|
555
|
+
}
|
|
556
|
+
|
|
519
557
|
/**
|
|
520
558
|
* Remove null and undefined values from an object to reduce JSON size.
|
|
521
559
|
* Preserves false, 0, empty strings, and arrays.
|
package/lib/PackagerRunner.js
CHANGED
|
@@ -87,13 +87,6 @@ function _profiler() {
|
|
|
87
87
|
return data;
|
|
88
88
|
}
|
|
89
89
|
var _EnvironmentManager = require("./EnvironmentManager");
|
|
90
|
-
function _featureFlags() {
|
|
91
|
-
const data = require("@atlaspack/feature-flags");
|
|
92
|
-
_featureFlags = function () {
|
|
93
|
-
return data;
|
|
94
|
-
};
|
|
95
|
-
return data;
|
|
96
|
-
}
|
|
97
90
|
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); }
|
|
98
91
|
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; }
|
|
99
92
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -437,10 +430,6 @@ class PackagerRunner {
|
|
|
437
430
|
devDepHashes += await this.getDevDepHashes(inlineBundle);
|
|
438
431
|
}
|
|
439
432
|
let invalidationHash = await (0, _assetUtils.getInvalidationHash)(invalidations, this.options);
|
|
440
|
-
if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
|
|
441
|
-
const hash = (0, _rust().hashString)(_constants.ATLASPACK_VERSION + devDepHashes + invalidationHash + bundle.target.publicUrl + bundleGraph.getHash(bundle) + JSON.stringify(configResults) + JSON.stringify(globalInfoResults) + this.options.mode + (this.options.shouldBuildLazily ? 'lazy' : 'eager'));
|
|
442
|
-
return _path().default.join(bundle.displayName ?? bundle.name ?? bundle.id, hash);
|
|
443
|
-
}
|
|
444
433
|
return (0, _rust().hashString)(_constants.ATLASPACK_VERSION + devDepHashes + invalidationHash + bundle.target.publicUrl + bundleGraph.getHash(bundle) + JSON.stringify(configResults) + JSON.stringify(globalInfoResults) + this.options.mode + (this.options.shouldBuildLazily ? 'lazy' : 'eager'));
|
|
445
434
|
}
|
|
446
435
|
async getDevDepHashes(bundle) {
|
|
@@ -464,14 +453,14 @@ class PackagerRunner {
|
|
|
464
453
|
let contentKey = PackagerRunner.getContentKey(cacheKey);
|
|
465
454
|
let mapKey = PackagerRunner.getMapKey(cacheKey);
|
|
466
455
|
let isLargeBlob = await this.options.cache.hasLargeBlob(contentKey);
|
|
467
|
-
let contentExists =
|
|
456
|
+
let contentExists = isLargeBlob || (await this.options.cache.has(contentKey));
|
|
468
457
|
if (!contentExists) {
|
|
469
458
|
return null;
|
|
470
459
|
}
|
|
471
|
-
let mapExists =
|
|
460
|
+
let mapExists = await this.options.cache.has(mapKey);
|
|
472
461
|
return {
|
|
473
462
|
contents: isLargeBlob ? this.options.cache.getStream(contentKey) : (0, _utils().blobToStream)(await this.options.cache.getBlob(contentKey)),
|
|
474
|
-
map: mapExists ? (0, _utils().blobToStream)(
|
|
463
|
+
map: mapExists ? (0, _utils().blobToStream)(await this.options.cache.getBlob(mapKey)) : null
|
|
475
464
|
};
|
|
476
465
|
}
|
|
477
466
|
async writeToCache(cacheKeys, type, contents, map) {
|
|
@@ -479,13 +468,11 @@ class PackagerRunner {
|
|
|
479
468
|
let hash;
|
|
480
469
|
// @ts-expect-error TS2702
|
|
481
470
|
let hashReferences = [];
|
|
482
|
-
let isLargeBlob =
|
|
471
|
+
let isLargeBlob = false;
|
|
483
472
|
|
|
484
473
|
// TODO: don't replace hash references in binary files??
|
|
485
474
|
if (contents instanceof _stream().Readable) {
|
|
486
|
-
|
|
487
|
-
isLargeBlob = true;
|
|
488
|
-
}
|
|
475
|
+
isLargeBlob = true;
|
|
489
476
|
let boundaryStr = '';
|
|
490
477
|
let h = new (_rust().Hash)();
|
|
491
478
|
await this.options.cache.setStream(cacheKeys.content, (0, _utils().blobToStream)(contents).pipe(
|
|
@@ -503,27 +490,15 @@ class PackagerRunner {
|
|
|
503
490
|
size = buffer.byteLength;
|
|
504
491
|
hash = (0, _rust().hashBuffer)(buffer);
|
|
505
492
|
hashReferences = contents.match(_constants.HASH_REF_REGEX) ?? [];
|
|
506
|
-
|
|
507
|
-
await this.options.cache.setLargeBlob(cacheKeys.content, buffer);
|
|
508
|
-
} else {
|
|
509
|
-
await this.options.cache.setBlob(cacheKeys.content, buffer);
|
|
510
|
-
}
|
|
493
|
+
await this.options.cache.setBlob(cacheKeys.content, buffer);
|
|
511
494
|
} else {
|
|
512
495
|
size = contents.length;
|
|
513
496
|
hash = (0, _rust().hashBuffer)(contents);
|
|
514
497
|
hashReferences = contents.toString().match(_constants.HASH_REF_REGEX) ?? [];
|
|
515
|
-
|
|
516
|
-
await this.options.cache.setLargeBlob(cacheKeys.content, contents);
|
|
517
|
-
} else {
|
|
518
|
-
await this.options.cache.setBlob(cacheKeys.content, contents);
|
|
519
|
-
}
|
|
498
|
+
await this.options.cache.setBlob(cacheKeys.content, contents);
|
|
520
499
|
}
|
|
521
500
|
if (map != null) {
|
|
522
|
-
|
|
523
|
-
await this.options.cache.setLargeBlob(cacheKeys.map, map);
|
|
524
|
-
} else {
|
|
525
|
-
await this.options.cache.setBlob(cacheKeys.map, map);
|
|
526
|
-
}
|
|
501
|
+
await this.options.cache.setBlob(cacheKeys.map, map);
|
|
527
502
|
}
|
|
528
503
|
let info = {
|
|
529
504
|
type,
|
|
@@ -537,21 +512,12 @@ class PackagerRunner {
|
|
|
537
512
|
return info;
|
|
538
513
|
}
|
|
539
514
|
static getContentKey(cacheKey) {
|
|
540
|
-
if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
|
|
541
|
-
return `PackagerRunner/${_constants.ATLASPACK_VERSION}/${cacheKey}/content`;
|
|
542
|
-
}
|
|
543
515
|
return (0, _rust().hashString)(`${cacheKey}:content`);
|
|
544
516
|
}
|
|
545
517
|
static getMapKey(cacheKey) {
|
|
546
|
-
if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
|
|
547
|
-
return `PackagerRunner/${_constants.ATLASPACK_VERSION}/${cacheKey}/map`;
|
|
548
|
-
}
|
|
549
518
|
return (0, _rust().hashString)(`${cacheKey}:map`);
|
|
550
519
|
}
|
|
551
520
|
static getInfoKey(cacheKey) {
|
|
552
|
-
if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
|
|
553
|
-
return `PackagerRunner/${_constants.ATLASPACK_VERSION}/${cacheKey}/info`;
|
|
554
|
-
}
|
|
555
521
|
return (0, _rust().hashString)(`${cacheKey}:info`);
|
|
556
522
|
}
|
|
557
523
|
}
|