@atlaspack/core 2.35.0 → 2.38.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 +107 -0
- package/dist/Atlaspack.js +41 -6
- package/dist/atlaspack-v3/AtlaspackV3.js +7 -4
- package/dist/atlaspack-v3/fs.js +1 -0
- package/dist/atlaspack-v3/worker/worker.js +11 -2
- package/dist/requests/AssetGraphRequestRust.js +5 -1
- package/dist/requests/AtlaspackBuildRequest.js +3 -0
- package/dist/requests/BundleGraphRequest.js +9 -6
- package/dist/requests/BundleGraphRequestRust.js +6 -1
- package/dist/requests/BundleGraphRequestUtils.js +133 -2
- package/dist/requests/WriteBundleRequest.js +168 -17
- package/lib/Atlaspack.js +47 -15
- package/lib/atlaspack-v3/AtlaspackV3.js +7 -4
- package/lib/atlaspack-v3/fs.js +1 -0
- package/lib/atlaspack-v3/worker/worker.js +13 -2
- package/lib/requests/AssetGraphRequestRust.js +5 -1
- package/lib/requests/AtlaspackBuildRequest.js +9 -0
- package/lib/requests/BundleGraphRequest.js +10 -7
- package/lib/requests/BundleGraphRequestRust.js +6 -1
- package/lib/requests/BundleGraphRequestUtils.js +132 -2
- package/lib/requests/WriteBundleRequest.js +181 -13
- package/lib/types/atlaspack-v3/AtlaspackV3.d.ts +3 -2
- package/lib/types/atlaspack-v3/fs.d.ts +1 -0
- package/lib/types/requests/BundleGraphRequestUtils.d.ts +7 -0
- package/lib/types/requests/WriteBundleRequest.d.ts +33 -0
- package/package.json +15 -15
- package/src/Atlaspack.ts +54 -12
- package/src/atlaspack-v3/AtlaspackV3.ts +22 -4
- package/src/atlaspack-v3/fs.ts +5 -0
- package/src/atlaspack-v3/worker/worker.ts +11 -2
- package/src/requests/AssetGraphRequestRust.ts +5 -1
- package/src/requests/AtlaspackBuildRequest.ts +4 -0
- package/src/requests/BundleGraphRequest.ts +11 -6
- package/src/requests/BundleGraphRequestRust.ts +8 -1
- package/src/requests/BundleGraphRequestUtils.ts +157 -1
- package/src/requests/WriteBundleRequest.ts +202 -22
- package/test/requests/WriteBundleRequest.test.ts +363 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -36,8 +36,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.SourceMapHashRefRewriteStream = void 0;
|
|
39
40
|
exports.default = createWriteBundleRequest;
|
|
40
41
|
exports.applyReplacementsToSourceMap = applyReplacementsToSourceMap;
|
|
42
|
+
exports.applyReplacementsToVLQMappings = applyReplacementsToVLQMappings;
|
|
41
43
|
exports.computeSourceMapRoot = computeSourceMapRoot;
|
|
42
44
|
const constants_1 = require("../constants");
|
|
43
45
|
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
@@ -56,10 +58,12 @@ const profiler_1 = require("@atlaspack/profiler");
|
|
|
56
58
|
const RequestTracker_1 = require("../RequestTracker");
|
|
57
59
|
const feature_flags_1 = require("@atlaspack/feature-flags");
|
|
58
60
|
const EnvironmentManager_1 = require("../EnvironmentManager");
|
|
59
|
-
const source_map_1 =
|
|
61
|
+
const source_map_1 = require("@atlaspack/source-map");
|
|
60
62
|
const HASH_REF_PREFIX_LEN = constants_1.HASH_REF_PREFIX.length;
|
|
61
63
|
const BOUNDARY_LENGTH = constants_1.HASH_REF_PREFIX.length + 32 - 1;
|
|
62
64
|
const HASH_REF_PLACEHOLDER_LEN = HASH_REF_PREFIX_LEN + constants_1.HASH_REF_HASH_LEN;
|
|
65
|
+
// The JSON key prefix we scan for in the source map stream.
|
|
66
|
+
const MAPPINGS_KEY_BUF = Buffer.from('"mappings":"');
|
|
63
67
|
/**
|
|
64
68
|
* Writes a bundle to the dist directory, replacing hash references with the final content hashes.
|
|
65
69
|
*/
|
|
@@ -136,28 +140,14 @@ async function run({ input, options, api }) {
|
|
|
136
140
|
await writeFiles(contentStream, info, hashRefToNameHash, options, config, outputFS, filePath, writeOptions, devDeps, api, bundleReplacements);
|
|
137
141
|
const hasSourceMap = await options.cache.has(mapKey);
|
|
138
142
|
if (mapKey && env.sourceMap && !env.sourceMap.inline && hasSourceMap) {
|
|
143
|
+
const mapEntry = await options.cache.getBlob(mapKey);
|
|
139
144
|
let mapStream;
|
|
140
145
|
if ((0, feature_flags_1.getFeatureFlag)('fixSourceMapHashRefs') &&
|
|
141
146
|
bundleReplacements &&
|
|
142
147
|
bundleReplacements.length > 0) {
|
|
143
|
-
|
|
144
|
-
const mapBuffer = Buffer.isBuffer(mapEntry)
|
|
145
|
-
? mapEntry
|
|
146
|
-
: Buffer.from(mapEntry);
|
|
147
|
-
const projectRoot = typeof options.projectRoot === 'string'
|
|
148
|
-
? options.projectRoot
|
|
149
|
-
: String(options.projectRoot);
|
|
150
|
-
const sourceMap = new source_map_1.default(projectRoot, mapBuffer);
|
|
151
|
-
applyReplacementsToSourceMap(sourceMap, bundleReplacements);
|
|
152
|
-
const mapJson = await sourceMap.stringify({
|
|
153
|
-
format: 'string',
|
|
154
|
-
file: name,
|
|
155
|
-
sourceRoot: computeSourceMapRoot(bundle, options),
|
|
156
|
-
});
|
|
157
|
-
mapStream = (0, utils_1.blobToStream)(Buffer.from(typeof mapJson === 'string' ? mapJson : JSON.stringify(mapJson), 'utf8'));
|
|
148
|
+
mapStream = (0, utils_1.blobToStream)(mapEntry).pipe(new SourceMapHashRefRewriteStream(bundleReplacements));
|
|
158
149
|
}
|
|
159
150
|
else {
|
|
160
|
-
const mapEntry = await options.cache.getBlob(mapKey);
|
|
161
151
|
mapStream = (0, utils_1.blobToStream)(mapEntry);
|
|
162
152
|
}
|
|
163
153
|
await writeFiles(mapStream, info, hashRefToNameHash, options, config, outputFS, (0, projectPath_1.toProjectPathUnsafe)((0, projectPath_1.fromProjectPathRelative)(filePath) + '.map'), writeOptions, devDeps, api);
|
|
@@ -192,6 +182,167 @@ function applyReplacementsToSourceMap(sourceMap, replacements) {
|
|
|
192
182
|
}
|
|
193
183
|
}
|
|
194
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Applies hash-ref replacement column offsets directly to a VLQ mappings
|
|
187
|
+
* string without deserializing the full source map into a native struct.
|
|
188
|
+
*
|
|
189
|
+
* Each replacement r describes a hash-ref that was substituted in the output
|
|
190
|
+
* file. r.column is in the progressively-shifted post-replacement coordinate
|
|
191
|
+
* space (matching the already-shifted source map state after all previous
|
|
192
|
+
* offsetColumns calls), so thresholds are applied sequentially against the
|
|
193
|
+
* running absCol values exactly as the native offsetColumns implementation does.
|
|
194
|
+
*/
|
|
195
|
+
function applyReplacementsToVLQMappings(mappings, replacements) {
|
|
196
|
+
if (replacements.length === 0)
|
|
197
|
+
return mappings;
|
|
198
|
+
// Group replacements by line (0-indexed), sorted by column ascending.
|
|
199
|
+
const byLine = new Map();
|
|
200
|
+
for (const r of replacements) {
|
|
201
|
+
let arr = byLine.get(r.line);
|
|
202
|
+
if (!arr) {
|
|
203
|
+
arr = [];
|
|
204
|
+
byLine.set(r.line, arr);
|
|
205
|
+
}
|
|
206
|
+
arr.push(r);
|
|
207
|
+
}
|
|
208
|
+
for (const arr of byLine.values()) {
|
|
209
|
+
arr.sort((a, b) => a.column - b.column);
|
|
210
|
+
}
|
|
211
|
+
const lines = mappings.split(';');
|
|
212
|
+
const resultLines = [];
|
|
213
|
+
for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
|
|
214
|
+
const lineReps = byLine.get(lineIdx);
|
|
215
|
+
if (!lineReps || lineReps.length === 0) {
|
|
216
|
+
resultLines.push(lines[lineIdx]);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
const line = lines[lineIdx];
|
|
220
|
+
if (!line) {
|
|
221
|
+
resultLines.push('');
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
// Decode segment column deltas to absolute columns.
|
|
225
|
+
const segments = line.split(',');
|
|
226
|
+
const colVlqEnds = [];
|
|
227
|
+
const absCols = [];
|
|
228
|
+
let absCol = 0;
|
|
229
|
+
for (const seg of segments) {
|
|
230
|
+
const { value: colDelta, nextPos } = (0, source_map_1.decodeVLQ)(seg, 0);
|
|
231
|
+
absCol += colDelta;
|
|
232
|
+
colVlqEnds.push(nextPos);
|
|
233
|
+
absCols.push(absCol);
|
|
234
|
+
}
|
|
235
|
+
// Apply each replacement's column shift sequentially against the
|
|
236
|
+
// current absCol values (which have already been adjusted by previous
|
|
237
|
+
// replacements on this line), mirroring the sequential offsetColumns calls.
|
|
238
|
+
for (const r of lineReps) {
|
|
239
|
+
const delta = r.newLength - r.originalLength;
|
|
240
|
+
if (delta === 0)
|
|
241
|
+
continue;
|
|
242
|
+
const threshold = r.column + r.originalLength;
|
|
243
|
+
for (let i = 0; i < absCols.length; i++) {
|
|
244
|
+
if (absCols[i] >= threshold) {
|
|
245
|
+
absCols[i] += delta;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
// Re-encode with updated absolute columns; only the leading column VLQ
|
|
250
|
+
// field of each segment changes – the tail bytes are sliced unchanged.
|
|
251
|
+
const resultSegments = [];
|
|
252
|
+
let prevAbsCol = 0;
|
|
253
|
+
for (let i = 0; i < segments.length; i++) {
|
|
254
|
+
const newDelta = absCols[i] - prevAbsCol;
|
|
255
|
+
prevAbsCol = absCols[i];
|
|
256
|
+
resultSegments.push((0, source_map_1.encodeVLQ)(newDelta) + segments[i].slice(colVlqEnds[i]));
|
|
257
|
+
}
|
|
258
|
+
resultLines.push(resultSegments.join(','));
|
|
259
|
+
}
|
|
260
|
+
return resultLines.join(';');
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* A Transform stream that rewrites the "mappings" VLQ field of a source map
|
|
264
|
+
* JSON to account for hash-ref replacements, without ever loading the full
|
|
265
|
+
* JSON object or the native Rust SourceMapInner into memory.
|
|
266
|
+
*
|
|
267
|
+
* Field order in cached source maps (from partialVlqMapToSourceMap / toVLQ):
|
|
268
|
+
* mappings → sources → sourcesContent → names → version → file → sourceRoot
|
|
269
|
+
*
|
|
270
|
+
* "mappings" is the very first field, so we scan only a tiny header before
|
|
271
|
+
* switching to zero-copy passthrough for the bulk sourcesContent bytes.
|
|
272
|
+
*/
|
|
273
|
+
class SourceMapHashRefRewriteStream extends stream_1.Transform {
|
|
274
|
+
constructor(replacements) {
|
|
275
|
+
super();
|
|
276
|
+
this.replacements = replacements;
|
|
277
|
+
this.state = 'scanning';
|
|
278
|
+
this.scanBuf = Buffer.alloc(0);
|
|
279
|
+
this.mappingsBufs = [];
|
|
280
|
+
}
|
|
281
|
+
// @ts-expect-error TS7006
|
|
282
|
+
_transform(chunk, _encoding, cb) {
|
|
283
|
+
if (this.state === 'passthrough') {
|
|
284
|
+
this.push(chunk);
|
|
285
|
+
cb();
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (this.state === 'scanning') {
|
|
289
|
+
const combined = Buffer.concat([this.scanBuf, chunk]);
|
|
290
|
+
const idx = combined.indexOf(MAPPINGS_KEY_BUF);
|
|
291
|
+
if (idx === -1) {
|
|
292
|
+
// Key not yet found – hold back enough bytes to handle a split key.
|
|
293
|
+
const keepLen = Math.min(combined.length, MAPPINGS_KEY_BUF.length - 1);
|
|
294
|
+
if (combined.length > keepLen) {
|
|
295
|
+
this.push(combined.slice(0, combined.length - keepLen));
|
|
296
|
+
}
|
|
297
|
+
this.scanBuf = combined.slice(combined.length - keepLen);
|
|
298
|
+
cb();
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
// Emit everything up to and including the key.
|
|
302
|
+
const keyEnd = idx + MAPPINGS_KEY_BUF.length;
|
|
303
|
+
this.push(combined.slice(0, keyEnd));
|
|
304
|
+
this.scanBuf = Buffer.alloc(0);
|
|
305
|
+
this.state = 'buffering';
|
|
306
|
+
this._bufferingTransform(combined.slice(keyEnd), cb);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
// state === 'buffering'
|
|
310
|
+
this._bufferingTransform(chunk, cb);
|
|
311
|
+
}
|
|
312
|
+
// @ts-expect-error TS7006
|
|
313
|
+
_bufferingTransform(chunk, cb) {
|
|
314
|
+
// Mappings values contain only base64 chars, ';', and ',' – no escaping –
|
|
315
|
+
// so scanning for the closing '"' (0x22) is safe.
|
|
316
|
+
const closeIdx = chunk.indexOf(0x22);
|
|
317
|
+
if (closeIdx === -1) {
|
|
318
|
+
this.mappingsBufs.push(chunk);
|
|
319
|
+
cb();
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
this.mappingsBufs.push(chunk.slice(0, closeIdx));
|
|
323
|
+
// VLQ chars are all ASCII (<128), so latin1 round-trips without loss.
|
|
324
|
+
const mappingsStr = Buffer.concat(this.mappingsBufs).toString('latin1');
|
|
325
|
+
const rewritten = applyReplacementsToVLQMappings(mappingsStr, this.replacements);
|
|
326
|
+
this.push(Buffer.from(rewritten, 'latin1'));
|
|
327
|
+
// Emit the closing '"' and everything remaining in one push.
|
|
328
|
+
this.push(chunk.slice(closeIdx));
|
|
329
|
+
this.state = 'passthrough';
|
|
330
|
+
this.mappingsBufs = [];
|
|
331
|
+
cb();
|
|
332
|
+
}
|
|
333
|
+
// @ts-expect-error TS7006
|
|
334
|
+
_flush(cb) {
|
|
335
|
+
if (this.state === 'scanning' && this.scanBuf.length > 0) {
|
|
336
|
+
this.push(this.scanBuf);
|
|
337
|
+
}
|
|
338
|
+
else if (this.state === 'buffering') {
|
|
339
|
+
// Malformed JSON – flush whatever we buffered as-is.
|
|
340
|
+
this.push(Buffer.concat(this.mappingsBufs));
|
|
341
|
+
}
|
|
342
|
+
cb();
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
exports.SourceMapHashRefRewriteStream = SourceMapHashRefRewriteStream;
|
|
195
346
|
/**
|
|
196
347
|
* Computes the sourceRoot for a source map file. This is the relative path from
|
|
197
348
|
* the output directory back to the project root, so that source paths (stored
|
package/lib/Atlaspack.js
CHANGED
|
@@ -118,6 +118,7 @@ function _featureFlags() {
|
|
|
118
118
|
var _atlaspackV = require("./atlaspack-v3");
|
|
119
119
|
var _AssetGraphRequest = _interopRequireDefault(require("./requests/AssetGraphRequest"));
|
|
120
120
|
var _AssetGraphRequestRust = require("./requests/AssetGraphRequestRust");
|
|
121
|
+
var _BundleGraphRequestRust = require("./requests/BundleGraphRequestRust");
|
|
121
122
|
var _rustWorkerThreadDylibHack = require("./rustWorkerThreadDylibHack");
|
|
122
123
|
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); }
|
|
123
124
|
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; }
|
|
@@ -197,7 +198,7 @@ class Atlaspack {
|
|
|
197
198
|
});
|
|
198
199
|
this.#resolvedOptions = resolvedOptions;
|
|
199
200
|
let rustAtlaspack;
|
|
200
|
-
if (resolvedOptions.featureFlags.atlaspackV3 || resolvedOptions.featureFlags.nativePackager) {
|
|
201
|
+
if (resolvedOptions.featureFlags.atlaspackV3 || resolvedOptions.featureFlags.fullNative || resolvedOptions.featureFlags.nativePackager) {
|
|
201
202
|
// eslint-disable-next-line no-unused-vars
|
|
202
203
|
let {
|
|
203
204
|
entries,
|
|
@@ -428,20 +429,51 @@ class Atlaspack {
|
|
|
428
429
|
type: 'buildStart'
|
|
429
430
|
});
|
|
430
431
|
this.#requestTracker.graph.invalidateOnBuildNodes();
|
|
431
|
-
let
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
432
|
+
let bundleGraph;
|
|
433
|
+
let bundleInfo;
|
|
434
|
+
let changedAssets;
|
|
435
|
+
let assetRequests;
|
|
436
|
+
let scopeHoistingStats;
|
|
437
|
+
if ((0, _featureFlags().getFeatureFlag)('fullNative') && this.rustAtlaspack) {
|
|
438
|
+
let [result, error] = await this.rustAtlaspack.build(eventJson => {
|
|
439
|
+
let event = JSON.parse(eventJson);
|
|
440
|
+
this.#reporterRunner.report(event);
|
|
441
|
+
});
|
|
442
|
+
if (error) {
|
|
443
|
+
throw new (_diagnostic().default)({
|
|
444
|
+
diagnostic: error
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
({
|
|
448
|
+
bundleGraph,
|
|
449
|
+
changedAssets
|
|
450
|
+
} = (0, _BundleGraphRequestRust.getBundleGraph)(result));
|
|
451
|
+
bundleInfo = new Map((result.bundleInfo ?? []).map(info => [info.bundleId, {
|
|
452
|
+
filePath: (0, _projectPath.toProjectPath)(options.projectRoot, info.filePath),
|
|
453
|
+
bundleId: info.bundleId,
|
|
454
|
+
type: info.type,
|
|
455
|
+
stats: {
|
|
456
|
+
size: info.size,
|
|
457
|
+
time: info.time
|
|
458
|
+
}
|
|
459
|
+
}]));
|
|
460
|
+
assetRequests = result.assetRequests ?? [];
|
|
461
|
+
} else {
|
|
462
|
+
let request = (0, _AtlaspackBuildRequest.default)({
|
|
463
|
+
optionsRef: this.#optionsRef,
|
|
464
|
+
requestedAssetIds: this.#requestedAssetIds,
|
|
465
|
+
signal
|
|
466
|
+
});
|
|
467
|
+
({
|
|
468
|
+
bundleGraph,
|
|
469
|
+
bundleInfo,
|
|
470
|
+
changedAssets,
|
|
471
|
+
assetRequests,
|
|
472
|
+
scopeHoistingStats
|
|
473
|
+
} = await this.#requestTracker.runRequest(request, {
|
|
474
|
+
force: true
|
|
475
|
+
}));
|
|
476
|
+
}
|
|
445
477
|
this.#requestedAssetIds.clear();
|
|
446
478
|
await (0, _dumpGraphToGraphViz.default)(
|
|
447
479
|
// @ts-expect-error TS2345
|
|
@@ -69,11 +69,14 @@ class AtlaspackV3 {
|
|
|
69
69
|
this._napiWorkerPool.shutdown();
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
buildAssetGraph() {
|
|
73
|
-
return (0, _rust().atlaspackNapiBuildAssetGraph)(this._atlaspack_napi);
|
|
72
|
+
buildAssetGraph(progressCallback) {
|
|
73
|
+
return (0, _rust().atlaspackNapiBuildAssetGraph)(this._atlaspack_napi, progressCallback);
|
|
74
74
|
}
|
|
75
|
-
buildBundleGraph() {
|
|
76
|
-
return (0, _rust().atlaspackNapiBuildBundleGraph)(this._atlaspack_napi);
|
|
75
|
+
buildBundleGraph(progressCallback) {
|
|
76
|
+
return (0, _rust().atlaspackNapiBuildBundleGraph)(this._atlaspack_napi, progressCallback);
|
|
77
|
+
}
|
|
78
|
+
build(progressCallback) {
|
|
79
|
+
return (0, _rust().atlaspackNapiBuild)(this._atlaspack_napi, progressCallback);
|
|
77
80
|
}
|
|
78
81
|
loadBundleGraph(bundleGraph) {
|
|
79
82
|
const {
|
package/lib/atlaspack-v3/fs.js
CHANGED
|
@@ -186,14 +186,25 @@ class AtlaspackWorker {
|
|
|
186
186
|
}
|
|
187
187
|
};
|
|
188
188
|
}
|
|
189
|
+
// A resolver may return a result without filePath to indicate it didn't
|
|
190
|
+
// resolve the dependency (equivalent to returning null). The JS-side
|
|
191
|
+
// PathRequest treats this as "try the next resolver".
|
|
192
|
+
if (!result.filePath) {
|
|
193
|
+
return {
|
|
194
|
+
invalidations: [],
|
|
195
|
+
resolution: {
|
|
196
|
+
type: 'unresolved'
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
189
200
|
return {
|
|
190
201
|
invalidations: [],
|
|
191
202
|
resolution: {
|
|
192
203
|
type: 'resolved',
|
|
193
|
-
filePath: result.filePath
|
|
204
|
+
filePath: result.filePath,
|
|
194
205
|
canDefer: result.canDefer || false,
|
|
195
206
|
sideEffects: result.sideEffects ?? true,
|
|
196
|
-
code: result.code
|
|
207
|
+
code: result.code ?? undefined,
|
|
197
208
|
meta: result.meta || undefined,
|
|
198
209
|
pipeline: result.pipeline || undefined,
|
|
199
210
|
priority: _compat.dependencyPriorityMap.intoNullable(result.priority),
|
|
@@ -34,6 +34,7 @@ function _featureFlags() {
|
|
|
34
34
|
return data;
|
|
35
35
|
}
|
|
36
36
|
var _AssetGraph = _interopRequireDefault(require("../AssetGraph"));
|
|
37
|
+
var _ReporterRunner = require("../ReporterRunner");
|
|
37
38
|
var _RequestTracker = require("../RequestTracker");
|
|
38
39
|
var _SymbolPropagation = require("../SymbolPropagation");
|
|
39
40
|
var _EnvironmentManager = require("../EnvironmentManager");
|
|
@@ -51,7 +52,10 @@ function createAssetGraphRequestRust(rustAtlaspack) {
|
|
|
51
52
|
let {
|
|
52
53
|
assetGraphPromise,
|
|
53
54
|
commitPromise
|
|
54
|
-
} = await rustAtlaspack.buildAssetGraph(
|
|
55
|
+
} = await rustAtlaspack.buildAssetGraph(eventJson => {
|
|
56
|
+
let event = JSON.parse(eventJson);
|
|
57
|
+
(0, _ReporterRunner.report)(event);
|
|
58
|
+
});
|
|
55
59
|
let [serializedAssetGraph, assetGraphError] = await assetGraphPromise;
|
|
56
60
|
if (assetGraphError) {
|
|
57
61
|
throw new (_diagnostic().default)({
|
|
@@ -30,6 +30,13 @@ function _featureFlags() {
|
|
|
30
30
|
return data;
|
|
31
31
|
}
|
|
32
32
|
var _EnvironmentManager = require("../EnvironmentManager");
|
|
33
|
+
function _logger() {
|
|
34
|
+
const data = require("@atlaspack/logger");
|
|
35
|
+
_logger = function () {
|
|
36
|
+
return data;
|
|
37
|
+
};
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
33
40
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
34
41
|
function createAtlaspackBuildRequest(input) {
|
|
35
42
|
return {
|
|
@@ -96,6 +103,7 @@ async function run({
|
|
|
96
103
|
changedAssets: new Map(Array.from(changedAssets).map(([id, asset]) => [id, (0, _Asset.assetFromValue)(asset, options)]))
|
|
97
104
|
});
|
|
98
105
|
let packagingMeasurement = _profiler().tracer.createMeasurement('packaging');
|
|
106
|
+
const span = _logger().tracer.enter('writeBundles');
|
|
99
107
|
let writeBundlesRequest = (0, _WriteBundlesRequest.default)({
|
|
100
108
|
bundleGraph,
|
|
101
109
|
optionsRef
|
|
@@ -105,6 +113,7 @@ async function run({
|
|
|
105
113
|
scopeHoistingStats
|
|
106
114
|
} = await api.runRequest(writeBundlesRequest);
|
|
107
115
|
packagingMeasurement && packagingMeasurement.end();
|
|
116
|
+
_logger().tracer.exit(span);
|
|
108
117
|
(0, _utils.assertSignalNotAborted)(signal);
|
|
109
118
|
return {
|
|
110
119
|
bundleGraph,
|
|
@@ -293,7 +293,6 @@ class BundlerRunner {
|
|
|
293
293
|
}
|
|
294
294
|
didIncrementallyBundle = true;
|
|
295
295
|
} else {
|
|
296
|
-
var _this$configs$get;
|
|
297
296
|
internalBundleGraph = _BundleGraph.default.fromAssetGraph(graph, this.options.mode === 'production');
|
|
298
297
|
(0, _assert().default)(internalBundleGraph != null); // ensures the graph was created
|
|
299
298
|
|
|
@@ -309,14 +308,18 @@ class BundlerRunner {
|
|
|
309
308
|
}
|
|
310
309
|
|
|
311
310
|
// this the normal bundle workflow (bundle, optimizing, run-times, naming)
|
|
312
|
-
await
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
311
|
+
await (0, _logger().instrumentAsync)('bundle (V2)', async () => {
|
|
312
|
+
var _this$configs$get;
|
|
313
|
+
await bundler.bundle({
|
|
314
|
+
bundleGraph: mutableBundleGraph,
|
|
315
|
+
config: (_this$configs$get = this.configs.get(plugin.name)) === null || _this$configs$get === void 0 ? void 0 : _this$configs$get.result,
|
|
316
|
+
options: this.pluginOptions,
|
|
317
|
+
logger,
|
|
318
|
+
tracer
|
|
319
|
+
});
|
|
318
320
|
});
|
|
319
321
|
measurement && measurement.end();
|
|
322
|
+
(0, _BundleGraphRequestUtils.dumpBundleGraphSnapshot)(internalBundleGraph, 'js');
|
|
320
323
|
if (this.pluginOptions.mode === 'production') {
|
|
321
324
|
let optimizeMeasurement;
|
|
322
325
|
try {
|
|
@@ -41,6 +41,7 @@ function _featureFlags() {
|
|
|
41
41
|
return data;
|
|
42
42
|
}
|
|
43
43
|
var _BundleGraph = _interopRequireWildcard(require("../BundleGraph"));
|
|
44
|
+
var _ReporterRunner = require("../ReporterRunner");
|
|
44
45
|
var _dumpGraphToGraphViz = _interopRequireDefault(require("../dumpGraphToGraphViz"));
|
|
45
46
|
function _nullthrows() {
|
|
46
47
|
const data = _interopRequireDefault(require("nullthrows"));
|
|
@@ -83,7 +84,10 @@ function createBundleGraphRequestRust(input) {
|
|
|
83
84
|
let {
|
|
84
85
|
bundleGraphPromise,
|
|
85
86
|
commitPromise
|
|
86
|
-
} = await rustAtlaspack.buildBundleGraph(
|
|
87
|
+
} = await rustAtlaspack.buildBundleGraph(eventJson => {
|
|
88
|
+
let event = JSON.parse(eventJson);
|
|
89
|
+
(0, _ReporterRunner.report)(event);
|
|
90
|
+
});
|
|
87
91
|
let [serializedBundleGraph, bundleGraphError] = await bundleGraphPromise;
|
|
88
92
|
if (bundleGraphError) {
|
|
89
93
|
throw new (_diagnostic().default)({
|
|
@@ -96,6 +100,7 @@ function createBundleGraphRequestRust(input) {
|
|
|
96
100
|
bundleGraph,
|
|
97
101
|
changedAssets
|
|
98
102
|
} = (0, _logger().instrument)('atlaspack_v3_getBundleGraph', () => getBundleGraph(serializedBundleGraph));
|
|
103
|
+
(0, _BundleGraphRequestUtils.dumpBundleGraphSnapshot)(bundleGraph, 'rust');
|
|
99
104
|
const runner = new NativeBundlerRunner({
|
|
100
105
|
api,
|
|
101
106
|
options
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.dumpBundleGraphSnapshot = dumpBundleGraphSnapshot;
|
|
6
7
|
exports.loadPluginConfigWithDevDeps = loadPluginConfigWithDevDeps;
|
|
7
8
|
exports.nameBundle = nameBundle;
|
|
8
9
|
exports.runDevDepRequest = runDevDepRequest;
|
|
@@ -14,6 +15,13 @@ function _assert() {
|
|
|
14
15
|
};
|
|
15
16
|
return data;
|
|
16
17
|
}
|
|
18
|
+
function _fs() {
|
|
19
|
+
const data = _interopRequireDefault(require("fs"));
|
|
20
|
+
_fs = function () {
|
|
21
|
+
return data;
|
|
22
|
+
};
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
17
25
|
function _nullthrows() {
|
|
18
26
|
const data = _interopRequireDefault(require("nullthrows"));
|
|
19
27
|
_nullthrows = function () {
|
|
@@ -21,6 +29,13 @@ function _nullthrows() {
|
|
|
21
29
|
};
|
|
22
30
|
return data;
|
|
23
31
|
}
|
|
32
|
+
function _path() {
|
|
33
|
+
const data = _interopRequireDefault(require("path"));
|
|
34
|
+
_path = function () {
|
|
35
|
+
return data;
|
|
36
|
+
};
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
24
39
|
function _logger() {
|
|
25
40
|
const data = require("@atlaspack/logger");
|
|
26
41
|
_logger = function () {
|
|
@@ -42,7 +57,8 @@ function _utils() {
|
|
|
42
57
|
};
|
|
43
58
|
return data;
|
|
44
59
|
}
|
|
45
|
-
var _BundleGraph =
|
|
60
|
+
var _BundleGraph = require("../BundleGraph");
|
|
61
|
+
var _BundleGraph2 = _interopRequireDefault(require("../public/BundleGraph"));
|
|
46
62
|
var _Bundle = require("../public/Bundle");
|
|
47
63
|
var _InternalConfig = require("../InternalConfig");
|
|
48
64
|
var _DevDepRequest = require("./DevDepRequest");
|
|
@@ -75,12 +91,126 @@ function validateBundles(bundleGraph) {
|
|
|
75
91
|
_assert().default.deepEqual(bundleNames, (0, _utils().unique)(bundleNames), 'Bundles must have unique name. Conflicting names: ' + [...(0, _utils().setSymmetricDifference)(new Set(bundleNames), new Set((0, _utils().unique)(bundleNames)))].join());
|
|
76
92
|
}
|
|
77
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Dump a canonical JSON snapshot of the bundle graph for parity comparison.
|
|
96
|
+
* Gated by ATLASPACK_DUMP_BUNDLE_GRAPH environment variable which specifies the output directory.
|
|
97
|
+
* The snapshot captures bundle identity, type, contained assets, and bundle group structure
|
|
98
|
+
* in a deterministic, sorted format suitable for diffing.
|
|
99
|
+
*/
|
|
100
|
+
function dumpBundleGraphSnapshot(bundleGraph, variant) {
|
|
101
|
+
let outDir = process.env.ATLASPACK_DUMP_BUNDLE_GRAPH;
|
|
102
|
+
if (!outDir) return;
|
|
103
|
+
let filename = variant === 'js' ? 'bundle-graph-js.json' : 'bundle-graph-rust.json';
|
|
104
|
+
let outPath = _path().default.join(outDir, filename);
|
|
105
|
+
_fs().default.mkdirSync(outDir, {
|
|
106
|
+
recursive: true
|
|
107
|
+
});
|
|
108
|
+
let bundles = bundleGraph.getBundles();
|
|
109
|
+
let bundlesSnapshot = bundles.map(bundle => {
|
|
110
|
+
let bundleNodeId = bundleGraph._graph.getNodeIdByContentKey(bundle.id);
|
|
111
|
+
let containedAssetNodeIds = bundleGraph._graph.getNodeIdsConnectedFrom(bundleNodeId, _BundleGraph.bundleGraphEdgeTypes.contains);
|
|
112
|
+
let containedAssets = containedAssetNodeIds.map(nodeId => bundleGraph._graph.getNode(nodeId)).flatMap(node => {
|
|
113
|
+
if ((node === null || node === void 0 ? void 0 : node.type) !== 'asset') return [];
|
|
114
|
+
return [{
|
|
115
|
+
id: node.value.id,
|
|
116
|
+
filePath: (0, _projectPath.fromProjectPathRelative)(node.value.filePath)
|
|
117
|
+
}];
|
|
118
|
+
}).sort((a, b) => a.filePath.localeCompare(b.filePath));
|
|
119
|
+
|
|
120
|
+
// Resolve mainEntry and entry asset file paths
|
|
121
|
+
let mainEntryPath = null;
|
|
122
|
+
let entryAssetPaths = [];
|
|
123
|
+
if (bundle.mainEntryId) {
|
|
124
|
+
let mainEntryNodeId = bundleGraph._graph.getNodeIdByContentKey(bundle.mainEntryId);
|
|
125
|
+
let mainEntryNode = bundleGraph._graph.getNode(mainEntryNodeId);
|
|
126
|
+
if ((mainEntryNode === null || mainEntryNode === void 0 ? void 0 : mainEntryNode.type) === 'asset') {
|
|
127
|
+
mainEntryPath = (0, _projectPath.fromProjectPathRelative)(mainEntryNode.value.filePath);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
for (let entryId of bundle.entryAssetIds) {
|
|
131
|
+
let entryNodeId = bundleGraph._graph.getNodeIdByContentKey(entryId);
|
|
132
|
+
let entryNode = bundleGraph._graph.getNode(entryNodeId);
|
|
133
|
+
if ((entryNode === null || entryNode === void 0 ? void 0 : entryNode.type) === 'asset') {
|
|
134
|
+
entryAssetPaths.push((0, _projectPath.fromProjectPathRelative)(entryNode.value.filePath));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
entryAssetPaths.sort();
|
|
138
|
+
return {
|
|
139
|
+
id: bundle.id,
|
|
140
|
+
type: bundle.type,
|
|
141
|
+
bundleBehavior: bundle.bundleBehavior ?? null,
|
|
142
|
+
needsStableName: bundle.needsStableName,
|
|
143
|
+
isSplittable: bundle.isSplittable,
|
|
144
|
+
isPlaceholder: bundle.isPlaceholder,
|
|
145
|
+
mainEntryPath,
|
|
146
|
+
entryAssetPaths,
|
|
147
|
+
assets: containedAssets.map(a => a.filePath)
|
|
148
|
+
};
|
|
149
|
+
}).sort((a, b) => {
|
|
150
|
+
// Sort by mainEntryPath first, then by sorted assets as tiebreaker
|
|
151
|
+
let aKey = a.mainEntryPath || a.assets.join(',');
|
|
152
|
+
let bKey = b.mainEntryPath || b.assets.join(',');
|
|
153
|
+
return aKey.localeCompare(bKey);
|
|
154
|
+
});
|
|
155
|
+
let bundleGroupsSnapshot = bundleGraph._graph.nodes.flatMap(node => {
|
|
156
|
+
if ((node === null || node === void 0 ? void 0 : node.type) !== 'bundle_group') return [];
|
|
157
|
+
let bundleGroup = node.value;
|
|
158
|
+
|
|
159
|
+
// Resolve entry asset file path
|
|
160
|
+
let entryAssetPath = null;
|
|
161
|
+
try {
|
|
162
|
+
let entryNodeId = bundleGraph._graph.getNodeIdByContentKey(bundleGroup.entryAssetId);
|
|
163
|
+
let entryNode = bundleGraph._graph.getNode(entryNodeId);
|
|
164
|
+
if ((entryNode === null || entryNode === void 0 ? void 0 : entryNode.type) === 'asset') {
|
|
165
|
+
entryAssetPath = (0, _projectPath.fromProjectPathRelative)(entryNode.value.filePath);
|
|
166
|
+
}
|
|
167
|
+
} catch {
|
|
168
|
+
// Content key not found
|
|
169
|
+
}
|
|
170
|
+
let bundlesInGroup = bundleGraph.getBundlesInBundleGroup(bundleGroup);
|
|
171
|
+
let bundlePaths = bundlesInGroup.map(b => {
|
|
172
|
+
// Use mainEntry file path if available, otherwise bundle id as fallback
|
|
173
|
+
if (b.mainEntryId) {
|
|
174
|
+
try {
|
|
175
|
+
let nodeId = bundleGraph._graph.getNodeIdByContentKey(b.mainEntryId);
|
|
176
|
+
let node = bundleGraph._graph.getNode(nodeId);
|
|
177
|
+
if ((node === null || node === void 0 ? void 0 : node.type) === 'asset') {
|
|
178
|
+
return (0, _projectPath.fromProjectPathRelative)(node.value.filePath);
|
|
179
|
+
}
|
|
180
|
+
} catch {
|
|
181
|
+
// fallback
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return `[bundle:${b.id}]`;
|
|
185
|
+
}).sort();
|
|
186
|
+
return [{
|
|
187
|
+
entryAssetPath: entryAssetPath ?? `[unknown:${bundleGroup.entryAssetId}]`,
|
|
188
|
+
bundlePaths
|
|
189
|
+
}];
|
|
190
|
+
}).sort((a, b) => a.entryAssetPath.localeCompare(b.entryAssetPath));
|
|
191
|
+
let totalAssets = bundleGraph._graph.nodes.filter(node => (node === null || node === void 0 ? void 0 : node.type) === 'asset').length;
|
|
192
|
+
let snapshot = {
|
|
193
|
+
version: 1,
|
|
194
|
+
variant,
|
|
195
|
+
stats: {
|
|
196
|
+
totalBundles: bundlesSnapshot.length,
|
|
197
|
+
totalBundleGroups: bundleGroupsSnapshot.length,
|
|
198
|
+
totalAssets
|
|
199
|
+
},
|
|
200
|
+
bundles: bundlesSnapshot,
|
|
201
|
+
bundleGroups: bundleGroupsSnapshot
|
|
202
|
+
};
|
|
203
|
+
_fs().default.writeFileSync(outPath, JSON.stringify(snapshot, null, 2), 'utf8');
|
|
204
|
+
// eslint-disable-next-line no-console
|
|
205
|
+
console.log(`[BundleGraphSnapshot] Wrote ${variant} snapshot to ${outPath}`);
|
|
206
|
+
}
|
|
207
|
+
|
|
78
208
|
/**
|
|
79
209
|
* Names a bundle by running through the configured namers until one returns a name.
|
|
80
210
|
*/
|
|
81
211
|
async function nameBundle(namers, internalBundle, internalBundleGraph, options, pluginOptions, configs) {
|
|
82
212
|
const bundle = _Bundle.Bundle.get(internalBundle, internalBundleGraph, options);
|
|
83
|
-
const bundleGraph = new
|
|
213
|
+
const bundleGraph = new _BundleGraph2.default(internalBundleGraph, _Bundle.NamedBundle.get.bind(_Bundle.NamedBundle), options);
|
|
84
214
|
for (const namer of namers) {
|
|
85
215
|
let measurement;
|
|
86
216
|
try {
|