@atlaspack/core 2.32.0 → 2.33.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 +50 -0
- package/dist/BundleGraph.js +78 -8
- package/dist/atlaspack-v3/AtlaspackV3.js +7 -4
- package/dist/atlaspack-v3/worker/worker.js +1 -0
- package/dist/requests/AtlaspackBuildRequest.js +12 -5
- package/dist/requests/BundleGraphRequest.js +15 -78
- package/dist/requests/BundleGraphRequestRust.js +320 -0
- package/dist/requests/BundleGraphRequestUtils.js +131 -0
- package/dist/requests/PackageRequest.js +27 -10
- package/lib/BundleGraph.js +85 -8
- package/lib/atlaspack-v3/AtlaspackV3.js +9 -4
- package/lib/atlaspack-v3/worker/worker.js +2 -1
- package/lib/requests/AtlaspackBuildRequest.js +6 -1
- package/lib/requests/BundleGraphRequest.js +15 -87
- package/lib/requests/BundleGraphRequestRust.js +378 -0
- package/lib/requests/BundleGraphRequestUtils.js +151 -0
- package/lib/requests/PackageRequest.js +38 -10
- package/lib/types/BundleGraph.d.ts +34 -4
- package/lib/types/atlaspack-v3/AtlaspackV3.d.ts +4 -1
- package/lib/types/atlaspack-v3/worker/worker.d.ts +1 -0
- package/lib/types/requests/BundleGraphRequestRust.d.ts +34 -0
- package/lib/types/requests/BundleGraphRequestUtils.d.ts +31 -0
- package/package.json +15 -15
- package/src/BundleGraph.ts +83 -8
- package/src/atlaspack-v3/AtlaspackV3.ts +17 -5
- package/src/atlaspack-v3/worker/worker.ts +1 -0
- package/src/requests/AtlaspackBuildRequest.ts +13 -5
- package/src/requests/BundleGraphRequest.ts +25 -100
- package/src/requests/BundleGraphRequestRust.ts +464 -0
- package/src/requests/BundleGraphRequestUtils.ts +167 -0
- package/src/requests/PackageRequest.ts +20 -5
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = createAtlaspackBuildRequest;
|
|
7
7
|
var _BundleGraphRequest = _interopRequireDefault(require("./BundleGraphRequest"));
|
|
8
|
+
var _BundleGraphRequestRust = _interopRequireDefault(require("./BundleGraphRequestRust"));
|
|
8
9
|
var _WriteBundlesRequest = _interopRequireDefault(require("./WriteBundlesRequest"));
|
|
9
10
|
var _utils = require("../utils");
|
|
10
11
|
var _dumpGraphToGraphViz = _interopRequireDefault(require("../dumpGraphToGraphViz"));
|
|
@@ -49,7 +50,11 @@ async function run({
|
|
|
49
50
|
requestedAssetIds,
|
|
50
51
|
signal
|
|
51
52
|
} = input;
|
|
52
|
-
let bundleGraphRequest = (0,
|
|
53
|
+
let bundleGraphRequest = (0, _featureFlags().getFeatureFlag)('nativeBundling') && rustAtlaspack ? (0, _BundleGraphRequestRust.default)({
|
|
54
|
+
optionsRef,
|
|
55
|
+
requestedAssetIds,
|
|
56
|
+
signal
|
|
57
|
+
}) : (0, _BundleGraphRequest.default)({
|
|
53
58
|
optionsRef,
|
|
54
59
|
requestedAssetIds,
|
|
55
60
|
signal
|
|
@@ -46,19 +46,10 @@ function _diagnostic() {
|
|
|
46
46
|
};
|
|
47
47
|
return data;
|
|
48
48
|
}
|
|
49
|
-
var _BundleGraph =
|
|
50
|
-
var _BundleGraph2 = _interopRequireWildcard(require("../BundleGraph"));
|
|
49
|
+
var _BundleGraph = _interopRequireWildcard(require("../BundleGraph"));
|
|
51
50
|
var _MutableBundleGraph = _interopRequireDefault(require("../public/MutableBundleGraph"));
|
|
52
|
-
var _Bundle = require("../public/Bundle");
|
|
53
51
|
var _ReporterRunner = require("../ReporterRunner");
|
|
54
52
|
var _dumpGraphToGraphViz = _interopRequireDefault(require("../dumpGraphToGraphViz"));
|
|
55
|
-
function _utils() {
|
|
56
|
-
const data = require("@atlaspack/utils");
|
|
57
|
-
_utils = function () {
|
|
58
|
-
return data;
|
|
59
|
-
};
|
|
60
|
-
return data;
|
|
61
|
-
}
|
|
62
53
|
function _rust() {
|
|
63
54
|
const data = require("@atlaspack/rust");
|
|
64
55
|
_rust = function () {
|
|
@@ -69,12 +60,11 @@ function _rust() {
|
|
|
69
60
|
var _PluginOptions = _interopRequireDefault(require("../public/PluginOptions"));
|
|
70
61
|
var _applyRuntimes = _interopRequireDefault(require("../applyRuntimes"));
|
|
71
62
|
var _constants = require("../constants");
|
|
72
|
-
var
|
|
63
|
+
var _utils = require("../utils");
|
|
73
64
|
var _AtlaspackConfigRequest = _interopRequireWildcard(require("./AtlaspackConfigRequest"));
|
|
74
65
|
var _DevDepRequest = require("./DevDepRequest");
|
|
75
|
-
var _InternalConfig = require("../InternalConfig");
|
|
76
|
-
var _ConfigRequest = require("./ConfigRequest");
|
|
77
66
|
var _projectPath = require("../projectPath");
|
|
67
|
+
var _BundleGraphRequestUtils = require("./BundleGraphRequestUtils");
|
|
78
68
|
var _AssetGraphRequest = _interopRequireDefault(require("./AssetGraphRequest"));
|
|
79
69
|
var _AssetGraphRequestRust = require("./AssetGraphRequestRust");
|
|
80
70
|
function _profiler() {
|
|
@@ -188,7 +178,7 @@ function createBundleGraphRequest(input) {
|
|
|
188
178
|
// }
|
|
189
179
|
|
|
190
180
|
measurement && measurement.end();
|
|
191
|
-
(0,
|
|
181
|
+
(0, _utils.assertSignalNotAborted)(signal);
|
|
192
182
|
|
|
193
183
|
// If any subrequests are invalid (e.g. dev dep requests or config requests),
|
|
194
184
|
// bail on incremental bundling. We also need to invalidate for option changes,
|
|
@@ -199,7 +189,7 @@ function createBundleGraphRequest(input) {
|
|
|
199
189
|
assetGraph.setNeedsBundling();
|
|
200
190
|
}
|
|
201
191
|
let configResult = (0, _nullthrows().default)(await input.api.runRequest((0, _AtlaspackConfigRequest.default)()));
|
|
202
|
-
(0,
|
|
192
|
+
(0, _utils.assertSignalNotAborted)(signal);
|
|
203
193
|
let atlaspackConfig = (0, _AtlaspackConfigRequest.getCachedAtlaspackConfig)(configResult, input.options);
|
|
204
194
|
let {
|
|
205
195
|
devDeps,
|
|
@@ -219,7 +209,7 @@ function createBundleGraphRequest(input) {
|
|
|
219
209
|
}
|
|
220
210
|
await (0, _dumpGraphToGraphViz.default)(
|
|
221
211
|
// @ts-expect-error TS2345
|
|
222
|
-
res.bundleGraph._graph, 'BundleGraph',
|
|
212
|
+
res.bundleGraph._graph, 'BundleGraph', _BundleGraph.bundleGraphEdgeTypes);
|
|
223
213
|
return res;
|
|
224
214
|
},
|
|
225
215
|
input
|
|
@@ -238,7 +228,7 @@ class BundlerRunner {
|
|
|
238
228
|
this.previousDevDeps = previousDevDeps;
|
|
239
229
|
this.devDepRequests = new Map();
|
|
240
230
|
this.configs = new Map();
|
|
241
|
-
this.pluginOptions = new _PluginOptions.default((0,
|
|
231
|
+
this.pluginOptions = new _PluginOptions.default((0, _utils.optionsProxy)(this.options, api.invalidateOnOptionChange));
|
|
242
232
|
if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
|
|
243
233
|
const key = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`);
|
|
244
234
|
this.cacheKey = `BundleGraph/${_constants.ATLASPACK_VERSION}/${options.mode}/${key}`;
|
|
@@ -260,26 +250,10 @@ class BundlerRunner {
|
|
|
260
250
|
}
|
|
261
251
|
}
|
|
262
252
|
async loadConfig(plugin) {
|
|
263
|
-
|
|
264
|
-
plugin: plugin.name,
|
|
265
|
-
searchPath: (0, _projectPath.toProjectPathUnsafe)('index')
|
|
266
|
-
});
|
|
267
|
-
await (0, _ConfigRequest.loadPluginConfig)(plugin, config, this.options);
|
|
268
|
-
await (0, _ConfigRequest.runConfigRequest)(this.api, config);
|
|
269
|
-
for (let devDep of config.devDeps) {
|
|
270
|
-
let devDepRequest = await (0, _DevDepRequest.createDevDependency)(devDep, this.previousDevDeps, this.options);
|
|
271
|
-
await this.runDevDepRequest(devDepRequest);
|
|
272
|
-
}
|
|
273
|
-
this.configs.set(plugin.name, config);
|
|
253
|
+
await (0, _BundleGraphRequestUtils.loadPluginConfigWithDevDeps)(plugin, this.options, this.api, this.previousDevDeps, this.devDepRequests, this.configs);
|
|
274
254
|
}
|
|
275
255
|
async runDevDepRequest(devDepRequest) {
|
|
276
|
-
|
|
277
|
-
specifier,
|
|
278
|
-
resolveFrom
|
|
279
|
-
} = devDepRequest;
|
|
280
|
-
let key = `${specifier}:${(0, _projectPath.fromProjectPathRelative)(resolveFrom)}`;
|
|
281
|
-
this.devDepRequests.set(key, devDepRequest);
|
|
282
|
-
await (0, _DevDepRequest.runDevDepRequest)(this.api, devDepRequest);
|
|
256
|
+
await (0, _BundleGraphRequestUtils.runDevDepRequest)(this.api, devDepRequest, this.devDepRequests);
|
|
283
257
|
}
|
|
284
258
|
async bundle({
|
|
285
259
|
graph,
|
|
@@ -324,12 +298,12 @@ class BundlerRunner {
|
|
|
324
298
|
}
|
|
325
299
|
} else {
|
|
326
300
|
var _this$configs$get;
|
|
327
|
-
internalBundleGraph =
|
|
301
|
+
internalBundleGraph = _BundleGraph.default.fromAssetGraph(graph, this.options.mode === 'production');
|
|
328
302
|
(0, _assert().default)(internalBundleGraph != null); // ensures the graph was created
|
|
329
303
|
|
|
330
304
|
await (0, _dumpGraphToGraphViz.default)(
|
|
331
305
|
// @ts-expect-error TS2345
|
|
332
|
-
internalBundleGraph._graph, 'before_bundle',
|
|
306
|
+
internalBundleGraph._graph, 'before_bundle', _BundleGraph.bundleGraphEdgeTypes);
|
|
333
307
|
let mutableBundleGraph = new _MutableBundleGraph.default(internalBundleGraph, this.options);
|
|
334
308
|
let measurement;
|
|
335
309
|
let measurementFilename;
|
|
@@ -400,7 +374,7 @@ class BundlerRunner {
|
|
|
400
374
|
if (internalBundleGraph != null) {
|
|
401
375
|
await (0, _dumpGraphToGraphViz.default)(
|
|
402
376
|
// @ts-expect-error TS2345
|
|
403
|
-
internalBundleGraph._graph, 'after_bundle',
|
|
377
|
+
internalBundleGraph._graph, 'after_bundle', _BundleGraph.bundleGraphEdgeTypes);
|
|
404
378
|
}
|
|
405
379
|
}
|
|
406
380
|
let changedRuntimes = new Map();
|
|
@@ -411,7 +385,7 @@ class BundlerRunner {
|
|
|
411
385
|
let bundles = internalBundleGraph.getBundles({
|
|
412
386
|
includeInline: true
|
|
413
387
|
});
|
|
414
|
-
await Promise.all(bundles.map(bundle =>
|
|
388
|
+
await Promise.all(bundles.map(bundle => (0, _BundleGraphRequestUtils.nameBundle)(namers, bundle, internalBundleGraph, this.options, this.pluginOptions, this.configs)));
|
|
415
389
|
changedRuntimes = await (0, _logger().instrumentAsync)('applyRuntimes', () => (0, _applyRuntimes.default)({
|
|
416
390
|
bundleGraph: internalBundleGraph,
|
|
417
391
|
api: this.api,
|
|
@@ -432,14 +406,14 @@ class BundlerRunner {
|
|
|
432
406
|
}, this.previousDevDeps, this.options);
|
|
433
407
|
await this.runDevDepRequest(devDepRequest);
|
|
434
408
|
}
|
|
435
|
-
|
|
409
|
+
(0, _BundleGraphRequestUtils.validateBundles)(internalBundleGraph);
|
|
436
410
|
|
|
437
411
|
// Pre-compute the hashes for each bundle so they are only computed once and shared between workers.
|
|
438
412
|
internalBundleGraph.getBundleGraphHash();
|
|
439
413
|
}
|
|
440
414
|
await (0, _dumpGraphToGraphViz.default)(
|
|
441
415
|
// @ts-expect-error TS2345
|
|
442
|
-
internalBundleGraph._graph, 'after_runtimes',
|
|
416
|
+
internalBundleGraph._graph, 'after_runtimes', _BundleGraph.bundleGraphEdgeTypes);
|
|
443
417
|
this.api.storeResult({
|
|
444
418
|
bundleGraph: internalBundleGraph,
|
|
445
419
|
assetGraphBundlingVersion: graph.getBundlingVersion(),
|
|
@@ -453,50 +427,4 @@ class BundlerRunner {
|
|
|
453
427
|
assetRequests
|
|
454
428
|
};
|
|
455
429
|
}
|
|
456
|
-
validateBundles(bundleGraph) {
|
|
457
|
-
let bundles = bundleGraph.getBundles();
|
|
458
|
-
let bundleNames = bundles.map(b => (0, _projectPath.joinProjectPath)(b.target.distDir, (0, _nullthrows().default)(b.name)));
|
|
459
|
-
_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());
|
|
460
|
-
}
|
|
461
|
-
async nameBundle(namers, internalBundle, internalBundleGraph) {
|
|
462
|
-
let bundle = _Bundle.Bundle.get(internalBundle, internalBundleGraph, this.options);
|
|
463
|
-
let bundleGraph = new _BundleGraph.default(internalBundleGraph, _Bundle.NamedBundle.get.bind(_Bundle.NamedBundle), this.options);
|
|
464
|
-
for (let namer of namers) {
|
|
465
|
-
let measurement;
|
|
466
|
-
try {
|
|
467
|
-
var _this$configs$get3;
|
|
468
|
-
measurement = _profiler().tracer.createMeasurement(namer.name, 'namer', bundle.id);
|
|
469
|
-
let name = await namer.plugin.name({
|
|
470
|
-
bundle,
|
|
471
|
-
bundleGraph,
|
|
472
|
-
config: (_this$configs$get3 = this.configs.get(namer.name)) === null || _this$configs$get3 === void 0 ? void 0 : _this$configs$get3.result,
|
|
473
|
-
options: this.pluginOptions,
|
|
474
|
-
logger: new (_logger().PluginLogger)({
|
|
475
|
-
origin: namer.name
|
|
476
|
-
}),
|
|
477
|
-
tracer: new (_profiler().PluginTracer)({
|
|
478
|
-
origin: namer.name,
|
|
479
|
-
category: 'namer'
|
|
480
|
-
})
|
|
481
|
-
});
|
|
482
|
-
if (name != null) {
|
|
483
|
-
internalBundle.name = name;
|
|
484
|
-
let {
|
|
485
|
-
hashReference
|
|
486
|
-
} = internalBundle;
|
|
487
|
-
internalBundle.displayName = name.includes(hashReference) ? name.replace(hashReference, '[hash]') : name;
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
} catch (e) {
|
|
491
|
-
throw new (_diagnostic().default)({
|
|
492
|
-
diagnostic: (0, _diagnostic().errorToDiagnostic)(e, {
|
|
493
|
-
origin: namer.name
|
|
494
|
-
})
|
|
495
|
-
});
|
|
496
|
-
} finally {
|
|
497
|
-
measurement && measurement.end();
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
throw new Error('Unable to name bundle');
|
|
501
|
-
}
|
|
502
430
|
}
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = createBundleGraphRequestRust;
|
|
7
|
+
exports.getBundleGraph = getBundleGraph;
|
|
8
|
+
function _assert() {
|
|
9
|
+
const data = _interopRequireDefault(require("assert"));
|
|
10
|
+
_assert = function () {
|
|
11
|
+
return data;
|
|
12
|
+
};
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
function _diagnostic() {
|
|
16
|
+
const data = _interopRequireDefault(require("@atlaspack/diagnostic"));
|
|
17
|
+
_diagnostic = function () {
|
|
18
|
+
return data;
|
|
19
|
+
};
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
function _graph() {
|
|
23
|
+
const data = require("@atlaspack/graph");
|
|
24
|
+
_graph = function () {
|
|
25
|
+
return data;
|
|
26
|
+
};
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
function _logger() {
|
|
30
|
+
const data = require("@atlaspack/logger");
|
|
31
|
+
_logger = function () {
|
|
32
|
+
return data;
|
|
33
|
+
};
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
function _featureFlags() {
|
|
37
|
+
const data = require("@atlaspack/feature-flags");
|
|
38
|
+
_featureFlags = function () {
|
|
39
|
+
return data;
|
|
40
|
+
};
|
|
41
|
+
return data;
|
|
42
|
+
}
|
|
43
|
+
var _BundleGraph = _interopRequireWildcard(require("../BundleGraph"));
|
|
44
|
+
var _dumpGraphToGraphViz = _interopRequireDefault(require("../dumpGraphToGraphViz"));
|
|
45
|
+
function _nullthrows() {
|
|
46
|
+
const data = _interopRequireDefault(require("nullthrows"));
|
|
47
|
+
_nullthrows = function () {
|
|
48
|
+
return data;
|
|
49
|
+
};
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
function _rust() {
|
|
53
|
+
const data = require("@atlaspack/rust");
|
|
54
|
+
_rust = function () {
|
|
55
|
+
return data;
|
|
56
|
+
};
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
var _PluginOptions = _interopRequireDefault(require("../public/PluginOptions"));
|
|
60
|
+
var _applyRuntimes = _interopRequireDefault(require("../applyRuntimes"));
|
|
61
|
+
var _constants = require("../constants");
|
|
62
|
+
var _utils = require("../utils");
|
|
63
|
+
var _DevDepRequest = require("./DevDepRequest");
|
|
64
|
+
var _RequestTracker = require("../RequestTracker");
|
|
65
|
+
var _AtlaspackConfigRequest = _interopRequireWildcard(require("./AtlaspackConfigRequest"));
|
|
66
|
+
var _BundleGraphRequestUtils = require("./BundleGraphRequestUtils");
|
|
67
|
+
var _EnvironmentManager = require("../EnvironmentManager");
|
|
68
|
+
var _Environment = require("../Environment");
|
|
69
|
+
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); }
|
|
70
|
+
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; }
|
|
71
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
72
|
+
function createBundleGraphRequestRust(input) {
|
|
73
|
+
return {
|
|
74
|
+
type: _RequestTracker.requestTypes.bundle_graph_request,
|
|
75
|
+
id: 'BundleGraphRust',
|
|
76
|
+
run: async runInput => {
|
|
77
|
+
const {
|
|
78
|
+
api,
|
|
79
|
+
options,
|
|
80
|
+
rustAtlaspack
|
|
81
|
+
} = runInput;
|
|
82
|
+
(0, _assert().default)(rustAtlaspack, 'BundleGraphRequestRust requires rustAtlaspack');
|
|
83
|
+
let {
|
|
84
|
+
bundleGraphPromise,
|
|
85
|
+
commitPromise
|
|
86
|
+
} = await rustAtlaspack.buildBundleGraph();
|
|
87
|
+
let [serializedBundleGraph, bundleGraphError] = await bundleGraphPromise;
|
|
88
|
+
if (bundleGraphError) {
|
|
89
|
+
throw new (_diagnostic().default)({
|
|
90
|
+
diagnostic: bundleGraphError
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Don’t reuse previous JS result yet; we just rebuild from scratch.
|
|
95
|
+
let {
|
|
96
|
+
bundleGraph,
|
|
97
|
+
changedAssets
|
|
98
|
+
} = (0, _logger().instrument)('atlaspack_v3_getBundleGraph', () => getBundleGraph(serializedBundleGraph));
|
|
99
|
+
const runner = new NativeBundlerRunner({
|
|
100
|
+
api,
|
|
101
|
+
options
|
|
102
|
+
}, input.optionsRef);
|
|
103
|
+
await runner.loadConfigs();
|
|
104
|
+
|
|
105
|
+
// Name all bundles
|
|
106
|
+
const namers = await runner.config.getNamers();
|
|
107
|
+
const bundles = bundleGraph.getBundles({
|
|
108
|
+
includeInline: true
|
|
109
|
+
});
|
|
110
|
+
await Promise.all(bundles.map(b => (0, _BundleGraphRequestUtils.nameBundle)(namers, b, bundleGraph, options, runner.pluginOptions, runner.configs)));
|
|
111
|
+
|
|
112
|
+
// Apply runtimes
|
|
113
|
+
const changedRuntimes = await (0, _logger().instrumentAsync)('applyRuntimes', () => (0, _applyRuntimes.default)({
|
|
114
|
+
bundleGraph,
|
|
115
|
+
api,
|
|
116
|
+
config: runner.config,
|
|
117
|
+
options,
|
|
118
|
+
optionsRef: input.optionsRef,
|
|
119
|
+
pluginOptions: runner.pluginOptions,
|
|
120
|
+
previousDevDeps: runner.previousDevDeps,
|
|
121
|
+
devDepRequests: runner.devDepRequests,
|
|
122
|
+
configs: runner.configs
|
|
123
|
+
}));
|
|
124
|
+
|
|
125
|
+
// Add dev deps for namers
|
|
126
|
+
for (const namer of namers) {
|
|
127
|
+
const devDepRequest = await (0, _DevDepRequest.createDevDependency)({
|
|
128
|
+
specifier: namer.name,
|
|
129
|
+
resolveFrom: namer.resolveFrom
|
|
130
|
+
}, runner.previousDevDeps, options);
|
|
131
|
+
await (0, _BundleGraphRequestUtils.runDevDepRequest)(api, devDepRequest, runner.devDepRequests);
|
|
132
|
+
}
|
|
133
|
+
(0, _BundleGraphRequestUtils.validateBundles)(bundleGraph);
|
|
134
|
+
bundleGraph.getBundleGraphHash();
|
|
135
|
+
await (0, _dumpGraphToGraphViz.default)(
|
|
136
|
+
// @ts-expect-error Accessing internal graph for debug output
|
|
137
|
+
bundleGraph._graph, 'after_runtimes_native', _BundleGraph.bundleGraphEdgeTypes);
|
|
138
|
+
let [_commitResult, commitError] = await commitPromise;
|
|
139
|
+
if (commitError) {
|
|
140
|
+
throw new (_diagnostic().default)({
|
|
141
|
+
diagnostic: {
|
|
142
|
+
message: 'Error committing bundle graph in Rust: ' + commitError.message
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
bundleGraph,
|
|
148
|
+
// Not accurate yet — ok for now.
|
|
149
|
+
assetGraphBundlingVersion: 0,
|
|
150
|
+
changedAssets: changedRuntimes,
|
|
151
|
+
assetRequests: []
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
input
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function mapSymbols({
|
|
158
|
+
exported,
|
|
159
|
+
...symbol
|
|
160
|
+
}) {
|
|
161
|
+
let jsSymbol = {
|
|
162
|
+
local: symbol.local ?? undefined,
|
|
163
|
+
loc: symbol.loc ?? undefined,
|
|
164
|
+
isWeak: symbol.isWeak,
|
|
165
|
+
meta: {
|
|
166
|
+
isEsm: symbol.isEsmExport,
|
|
167
|
+
isStaticBindingSafe: symbol.isStaticBindingSafe
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
if (symbol.exported) {
|
|
171
|
+
jsSymbol.exported = symbol.exported;
|
|
172
|
+
}
|
|
173
|
+
return [exported, jsSymbol];
|
|
174
|
+
}
|
|
175
|
+
function normalizeEnv(env) {
|
|
176
|
+
if (!env) return env;
|
|
177
|
+
env.id = env.id || (0, _Environment.getEnvironmentHash)(env);
|
|
178
|
+
return (0, _EnvironmentManager.toEnvironmentRef)(env);
|
|
179
|
+
}
|
|
180
|
+
function getBundleGraph(serializedGraph) {
|
|
181
|
+
// Build a fresh internal bundle graph.
|
|
182
|
+
const publicIdByAssetId = new Map(Object.entries(serializedGraph.publicIdByAssetId ?? {}));
|
|
183
|
+
const assetPublicIds = new Set(serializedGraph.assetPublicIds ?? []);
|
|
184
|
+
|
|
185
|
+
// BundleGraph constructor expects a ContentGraph under `_graph`.
|
|
186
|
+
// We reuse the internal graph class by creating an empty instance and then adding nodes.
|
|
187
|
+
const graph = new _BundleGraph.default({
|
|
188
|
+
// We intentionally start with an empty graph and add nodes/edges from the Rust payload.
|
|
189
|
+
// `ContentGraph` will allocate as needed.
|
|
190
|
+
graph: new (_graph().ContentGraph)(),
|
|
191
|
+
bundleContentHashes: new Map(),
|
|
192
|
+
publicIdByAssetId,
|
|
193
|
+
assetPublicIds,
|
|
194
|
+
conditions: new Map()
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// Root must exist at node id 0.
|
|
198
|
+
const rootNodeId = graph._graph.addNodeByContentKey('@@root', {
|
|
199
|
+
id: '@@root',
|
|
200
|
+
type: 'root',
|
|
201
|
+
value: null
|
|
202
|
+
});
|
|
203
|
+
graph._graph.setRootNodeId(rootNodeId);
|
|
204
|
+
let entry = 0;
|
|
205
|
+
const changedAssets = new Map();
|
|
206
|
+
const decoder = new TextDecoder();
|
|
207
|
+
|
|
208
|
+
// Create nodes in order.
|
|
209
|
+
for (let i = 0; i < serializedGraph.nodes.length; i++) {
|
|
210
|
+
// Nodes come back as buffers (same as AssetGraphRequestRust)
|
|
211
|
+
let node = JSON.parse(decoder.decode(serializedGraph.nodes[i]));
|
|
212
|
+
if (node.type === 'root') {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (node.type === 'entry') {
|
|
216
|
+
let id = 'entry:' + ++entry;
|
|
217
|
+
graph._graph.addNodeByContentKey(id, {
|
|
218
|
+
id,
|
|
219
|
+
type: 'root',
|
|
220
|
+
value: null
|
|
221
|
+
});
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
if (node.type === 'asset') {
|
|
225
|
+
let asset = node.value;
|
|
226
|
+
let id = asset.id;
|
|
227
|
+
asset.committed = true;
|
|
228
|
+
asset.contentKey = id;
|
|
229
|
+
asset.env = {
|
|
230
|
+
...asset.env
|
|
231
|
+
};
|
|
232
|
+
asset.env.id = (0, _featureFlags().getFeatureFlag)('environmentDeduplication') ? (0, _Environment.getEnvironmentHash)(asset.env) : (0, _Environment.getEnvironmentHash)(asset.env);
|
|
233
|
+
asset.env = normalizeEnv(asset.env);
|
|
234
|
+
asset.mapKey = `map:${asset.id}`;
|
|
235
|
+
asset.dependencies = new Map();
|
|
236
|
+
asset.meta.isV3 = true;
|
|
237
|
+
if (asset.symbols != null) {
|
|
238
|
+
asset.symbols = new Map(asset.symbols.map(mapSymbols));
|
|
239
|
+
}
|
|
240
|
+
changedAssets.set(id, asset);
|
|
241
|
+
const assetNode = {
|
|
242
|
+
id,
|
|
243
|
+
type: 'asset',
|
|
244
|
+
usedSymbols: new Set(),
|
|
245
|
+
usedSymbolsDownDirty: true,
|
|
246
|
+
usedSymbolsUpDirty: true,
|
|
247
|
+
value: asset
|
|
248
|
+
};
|
|
249
|
+
graph._graph.addNodeByContentKey(id, assetNode);
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
if (node.type === 'dependency') {
|
|
253
|
+
let {
|
|
254
|
+
dependency,
|
|
255
|
+
id
|
|
256
|
+
} = node.value;
|
|
257
|
+
dependency.id = id;
|
|
258
|
+
dependency.env = {
|
|
259
|
+
...dependency.env
|
|
260
|
+
};
|
|
261
|
+
dependency.env.id = (0, _Environment.getEnvironmentHash)(dependency.env);
|
|
262
|
+
dependency.env = normalizeEnv(dependency.env);
|
|
263
|
+
if (dependency.symbols != null) {
|
|
264
|
+
var _dependency$symbols;
|
|
265
|
+
dependency.symbols = new Map((_dependency$symbols = dependency.symbols) === null || _dependency$symbols === void 0 ? void 0 : _dependency$symbols.map(mapSymbols));
|
|
266
|
+
}
|
|
267
|
+
let usedSymbolsDown = new Set();
|
|
268
|
+
let usedSymbolsUp = new Map();
|
|
269
|
+
if (dependency.isEntry && dependency.isLibrary) {
|
|
270
|
+
usedSymbolsDown.add('*');
|
|
271
|
+
usedSymbolsUp.set('*', undefined);
|
|
272
|
+
}
|
|
273
|
+
const depNode = {
|
|
274
|
+
id,
|
|
275
|
+
type: 'dependency',
|
|
276
|
+
deferred: false,
|
|
277
|
+
excluded: false,
|
|
278
|
+
hasDeferred: node.has_deferred,
|
|
279
|
+
// @ts-expect-error Flow types expect a more specific symbol set type
|
|
280
|
+
usedSymbolsDown,
|
|
281
|
+
usedSymbolsDownDirty: true,
|
|
282
|
+
usedSymbolsUp,
|
|
283
|
+
usedSymbolsUpDirtyDown: true,
|
|
284
|
+
usedSymbolsUpDirtyUp: true,
|
|
285
|
+
value: dependency
|
|
286
|
+
};
|
|
287
|
+
graph._graph.addNodeByContentKey(id, depNode);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
if (node.type === 'bundle') {
|
|
291
|
+
node.value.env = normalizeEnv(node.value.env);
|
|
292
|
+
node.value.target.env = normalizeEnv(node.value.target.env);
|
|
293
|
+
graph._graph.addNodeByContentKey(node.id, node);
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
if (node.type === 'bundle_group' || node.type === 'bundleGroup') {
|
|
297
|
+
// Rust serializer may emit bundleGroup nodes either as `{id,type,value:{...}}`
|
|
298
|
+
// or as `{type:"bundleGroup", id, target, entryAssetId}`.
|
|
299
|
+
if (node.value == null) {
|
|
300
|
+
node.value = {
|
|
301
|
+
target: node.target,
|
|
302
|
+
entryAssetId: node.entryAssetId ?? node.entry_asset_id
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Normalize entry asset id field naming
|
|
307
|
+
if (node.value.entryAssetId == null && node.value.entry_asset_id != null) {
|
|
308
|
+
node.value.entryAssetId = node.value.entry_asset_id;
|
|
309
|
+
}
|
|
310
|
+
node.value.target.env = normalizeEnv(node.value.target.env);
|
|
311
|
+
// Normalise to the expected snake_case type
|
|
312
|
+
node.type = 'bundle_group';
|
|
313
|
+
graph._graph.addNodeByContentKey(node.id, node);
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Apply edges
|
|
319
|
+
for (let i = 0; i < serializedGraph.edges.length; i += 3) {
|
|
320
|
+
const from = serializedGraph.edges[i];
|
|
321
|
+
const to = serializedGraph.edges[i + 1];
|
|
322
|
+
const type = serializedGraph.edges[i + 2];
|
|
323
|
+
const fromNode = graph._graph.getNode(from);
|
|
324
|
+
const toNode = graph._graph.getNode(to);
|
|
325
|
+
if ((fromNode === null || fromNode === void 0 ? void 0 : fromNode.type) === 'asset' && (toNode === null || toNode === void 0 ? void 0 : toNode.type) === 'dependency') {
|
|
326
|
+
fromNode.value.dependencies.set(toNode.value.id, toNode.value);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// If we are adding a references edge, remove existing null edge.
|
|
330
|
+
if (type === _BundleGraph.bundleGraphEdgeTypes.references && graph._graph.hasEdge(from, to, _BundleGraph.bundleGraphEdgeTypes.null)) {
|
|
331
|
+
graph._graph.removeEdge(from, to, _BundleGraph.bundleGraphEdgeTypes.null);
|
|
332
|
+
}
|
|
333
|
+
graph._graph.addEdge(from, to, type);
|
|
334
|
+
}
|
|
335
|
+
return {
|
|
336
|
+
bundleGraph: graph,
|
|
337
|
+
changedAssets
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
class NativeBundlerRunner {
|
|
341
|
+
constructor({
|
|
342
|
+
api,
|
|
343
|
+
options
|
|
344
|
+
}, optionsRef) {
|
|
345
|
+
this.options = options;
|
|
346
|
+
this.api = api;
|
|
347
|
+
this.optionsRef = optionsRef;
|
|
348
|
+
this.previousDevDeps = new Map();
|
|
349
|
+
this.devDepRequests = new Map();
|
|
350
|
+
this.configs = new Map();
|
|
351
|
+
this.pluginOptions = new _PluginOptions.default((0, _utils.optionsProxy)(this.options, api.invalidateOnOptionChange));
|
|
352
|
+
const key = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`);
|
|
353
|
+
this.cacheKey = `BundleGraph/${_constants.ATLASPACK_VERSION}/${options.mode}/${key}`;
|
|
354
|
+
}
|
|
355
|
+
async loadConfigs() {
|
|
356
|
+
const configResult = (0, _nullthrows().default)(await this.api.runRequest((0, _AtlaspackConfigRequest.default)()));
|
|
357
|
+
this.config = (0, _AtlaspackConfigRequest.getCachedAtlaspackConfig)(configResult, this.options);
|
|
358
|
+
const {
|
|
359
|
+
devDeps,
|
|
360
|
+
invalidDevDeps
|
|
361
|
+
} = await (0, _DevDepRequest.getDevDepRequests)(this.api);
|
|
362
|
+
this.previousDevDeps = devDeps;
|
|
363
|
+
(0, _DevDepRequest.invalidateDevDeps)(invalidDevDeps, this.options, this.config);
|
|
364
|
+
const bundler = await this.config.getBundler();
|
|
365
|
+
await this.loadPluginConfig(bundler);
|
|
366
|
+
const namers = await this.config.getNamers();
|
|
367
|
+
for (const namer of namers) {
|
|
368
|
+
await this.loadPluginConfig(namer);
|
|
369
|
+
}
|
|
370
|
+
const runtimes = await this.config.getRuntimes();
|
|
371
|
+
for (const runtime of runtimes) {
|
|
372
|
+
await this.loadPluginConfig(runtime);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
async loadPluginConfig(plugin) {
|
|
376
|
+
await (0, _BundleGraphRequestUtils.loadPluginConfigWithDevDeps)(plugin, this.options, this.api, this.previousDevDeps, this.devDepRequests, this.configs);
|
|
377
|
+
}
|
|
378
|
+
}
|