@atlaspack/core 2.32.1 → 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 CHANGED
@@ -1,5 +1,31 @@
1
1
  # @atlaspack/core
2
2
 
3
+ ## 2.33.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#993](https://github.com/atlassian-labs/atlaspack/pull/993) [`e058f0e`](https://github.com/atlassian-labs/atlaspack/commit/e058f0e7a0423ba9373e85a7dbd5c1dd43b47916) Thanks [@matt-koko](https://github.com/matt-koko)! - Add disableCache option to TransformerSetup API
8
+
9
+ ### Patch Changes
10
+
11
+ - [#998](https://github.com/atlassian-labs/atlaspack/pull/998) [`349b19c`](https://github.com/atlassian-labs/atlaspack/commit/349b19c3aca2ccb1ffb5cdcdc74890f4b62228be) Thanks [@mattcompiles](https://github.com/mattcompiles)! - Add initial native bundler boilerplate and single file bundler
12
+
13
+ - Updated dependencies [[`e058f0e`](https://github.com/atlassian-labs/atlaspack/commit/e058f0e7a0423ba9373e85a7dbd5c1dd43b47916), [`053e375`](https://github.com/atlassian-labs/atlaspack/commit/053e3754c08c5b5dc239e9f7267df289cbbf31ab), [`25c976e`](https://github.com/atlassian-labs/atlaspack/commit/25c976e01c30e536fb1027eab5b17594c604efff), [`1a86b65`](https://github.com/atlassian-labs/atlaspack/commit/1a86b657868ee881ca5acc68661cca208ac37779), [`349b19c`](https://github.com/atlassian-labs/atlaspack/commit/349b19c3aca2ccb1ffb5cdcdc74890f4b62228be), [`9959efe`](https://github.com/atlassian-labs/atlaspack/commit/9959efe30699a2de3b69275be7ecb47afe81c0b6)]:
14
+ - @atlaspack/rust@3.22.0
15
+ - @atlaspack/feature-flags@2.29.0
16
+ - @atlaspack/fs@2.15.47
17
+ - @atlaspack/graph@3.6.14
18
+ - @atlaspack/logger@2.14.44
19
+ - @atlaspack/plugin@2.14.52
20
+ - @atlaspack/profiler@2.15.13
21
+ - @atlaspack/types@2.15.42
22
+ - @atlaspack/utils@3.3.4
23
+ - @atlaspack/workers@2.14.52
24
+ - @atlaspack/cache@3.2.47
25
+ - @atlaspack/source-map@3.2.7
26
+ - @atlaspack/build-cache@2.13.10
27
+ - @atlaspack/package-manager@2.14.52
28
+
3
29
  ## 2.32.1
4
30
 
5
31
  ### Patch Changes
@@ -51,6 +51,9 @@ class AtlaspackV3 {
51
51
  buildAssetGraph() {
52
52
  return (0, rust_1.atlaspackNapiBuildAssetGraph)(this._atlaspack_napi);
53
53
  }
54
+ buildBundleGraph() {
55
+ return (0, rust_1.atlaspackNapiBuildBundleGraph)(this._atlaspack_napi);
56
+ }
54
57
  loadBundleGraph(bundleGraph) {
55
58
  const { nodesJson, edges, publicIdByAssetId, environmentsJson } = bundleGraph.serializeForNative();
56
59
  return (0, rust_1.atlaspackNapiLoadBundleGraph)(this._atlaspack_napi, nodesJson, edges, publicIdByAssetId, environmentsJson);
@@ -355,6 +355,7 @@ class AtlaspackWorker {
355
355
  conditions: setupResult?.conditions,
356
356
  config,
357
357
  env: allowedEnv,
358
+ disableCache: setupResult?.disableCache,
358
359
  };
359
360
  }
360
361
  __classPrivateFieldGet(this, _AtlaspackWorker_transformers, "f").set(specifier, {
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.default = createAtlaspackBuildRequest;
7
7
  const BundleGraphRequest_1 = __importDefault(require("./BundleGraphRequest"));
8
+ const BundleGraphRequestRust_1 = __importDefault(require("./BundleGraphRequestRust"));
8
9
  const WriteBundlesRequest_1 = __importDefault(require("./WriteBundlesRequest"));
9
10
  const utils_1 = require("../utils");
10
11
  const dumpGraphToGraphViz_1 = __importDefault(require("../dumpGraphToGraphViz"));
@@ -27,11 +28,17 @@ function createAtlaspackBuildRequest(input) {
27
28
  }
28
29
  async function run({ input, api, options, rustAtlaspack, }) {
29
30
  let { optionsRef, requestedAssetIds, signal } = input;
30
- let bundleGraphRequest = (0, BundleGraphRequest_1.default)({
31
- optionsRef,
32
- requestedAssetIds,
33
- signal,
34
- });
31
+ let bundleGraphRequest = (0, feature_flags_1.getFeatureFlag)('nativeBundling') && rustAtlaspack
32
+ ? (0, BundleGraphRequestRust_1.default)({
33
+ optionsRef,
34
+ requestedAssetIds,
35
+ signal,
36
+ })
37
+ : (0, BundleGraphRequest_1.default)({
38
+ optionsRef,
39
+ requestedAssetIds,
40
+ signal,
41
+ });
35
42
  let { bundleGraph, changedAssets, assetRequests } = await api.runRequest(bundleGraphRequest, {
36
43
  force: Boolean(rustAtlaspack) ||
37
44
  (options.shouldBuildLazily && requestedAssetIds.size > 0),
@@ -39,28 +39,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.default = createBundleGraphRequest;
40
40
  const fs_1 = __importDefault(require("fs"));
41
41
  const assert_1 = __importDefault(require("assert"));
42
- const assert_2 = __importDefault(require("assert"));
43
42
  const nullthrows_1 = __importDefault(require("nullthrows"));
44
43
  const logger_1 = require("@atlaspack/logger");
45
44
  const feature_flags_1 = require("@atlaspack/feature-flags");
46
45
  const diagnostic_1 = __importStar(require("@atlaspack/diagnostic"));
47
- const BundleGraph_1 = __importDefault(require("../public/BundleGraph"));
48
- const BundleGraph_2 = __importStar(require("../BundleGraph"));
46
+ const BundleGraph_1 = __importStar(require("../BundleGraph"));
49
47
  const MutableBundleGraph_1 = __importDefault(require("../public/MutableBundleGraph"));
50
- const Bundle_1 = require("../public/Bundle");
51
48
  const ReporterRunner_1 = require("../ReporterRunner");
52
49
  const dumpGraphToGraphViz_1 = __importDefault(require("../dumpGraphToGraphViz"));
53
- const utils_1 = require("@atlaspack/utils");
54
50
  const rust_1 = require("@atlaspack/rust");
55
51
  const PluginOptions_1 = __importDefault(require("../public/PluginOptions"));
56
52
  const applyRuntimes_1 = __importDefault(require("../applyRuntimes"));
57
53
  const constants_1 = require("../constants");
58
- const utils_2 = require("../utils");
54
+ const utils_1 = require("../utils");
59
55
  const AtlaspackConfigRequest_1 = __importStar(require("./AtlaspackConfigRequest"));
60
56
  const DevDepRequest_1 = require("./DevDepRequest");
61
- const InternalConfig_1 = require("../InternalConfig");
62
- const ConfigRequest_1 = require("./ConfigRequest");
63
57
  const projectPath_1 = require("../projectPath");
58
+ const BundleGraphRequestUtils_1 = require("./BundleGraphRequestUtils");
64
59
  const AssetGraphRequest_1 = __importDefault(require("./AssetGraphRequest"));
65
60
  const AssetGraphRequestRust_1 = require("./AssetGraphRequestRust");
66
61
  const profiler_1 = require("@atlaspack/profiler");
@@ -151,7 +146,7 @@ function createBundleGraphRequest(input) {
151
146
  // );
152
147
  // }
153
148
  measurement && measurement.end();
154
- (0, utils_2.assertSignalNotAborted)(signal);
149
+ (0, utils_1.assertSignalNotAborted)(signal);
155
150
  // If any subrequests are invalid (e.g. dev dep requests or config requests),
156
151
  // bail on incremental bundling. We also need to invalidate for option changes,
157
152
  // which are hoisted to direct invalidations on the bundle graph request.
@@ -164,7 +159,7 @@ function createBundleGraphRequest(input) {
164
159
  assetGraph.setNeedsBundling();
165
160
  }
166
161
  let configResult = (0, nullthrows_1.default)(await input.api.runRequest((0, AtlaspackConfigRequest_1.default)()));
167
- (0, utils_2.assertSignalNotAborted)(signal);
162
+ (0, utils_1.assertSignalNotAborted)(signal);
168
163
  let atlaspackConfig = (0, AtlaspackConfigRequest_1.getCachedAtlaspackConfig)(configResult, input.options);
169
164
  let { devDeps, invalidDevDeps } = await (0, DevDepRequest_1.getDevDepRequests)(input.api);
170
165
  (0, DevDepRequest_1.invalidateDevDeps)(invalidDevDeps, input.options, atlaspackConfig);
@@ -181,7 +176,7 @@ function createBundleGraphRequest(input) {
181
176
  }
182
177
  await (0, dumpGraphToGraphViz_1.default)(
183
178
  // @ts-expect-error TS2345
184
- res.bundleGraph._graph, 'BundleGraph', BundleGraph_2.bundleGraphEdgeTypes);
179
+ res.bundleGraph._graph, 'BundleGraph', BundleGraph_1.bundleGraphEdgeTypes);
185
180
  return res;
186
181
  },
187
182
  input,
@@ -196,7 +191,7 @@ class BundlerRunner {
196
191
  this.previousDevDeps = previousDevDeps;
197
192
  this.devDepRequests = new Map();
198
193
  this.configs = new Map();
199
- this.pluginOptions = new PluginOptions_1.default((0, utils_2.optionsProxy)(this.options, api.invalidateOnOptionChange));
194
+ this.pluginOptions = new PluginOptions_1.default((0, utils_1.optionsProxy)(this.options, api.invalidateOnOptionChange));
200
195
  if ((0, feature_flags_1.getFeatureFlag)('cachePerformanceImprovements')) {
201
196
  const key = (0, rust_1.hashString)(`${constants_1.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`);
202
197
  this.cacheKey = `BundleGraph/${constants_1.ATLASPACK_VERSION}/${options.mode}/${key}`;
@@ -220,23 +215,10 @@ class BundlerRunner {
220
215
  }
221
216
  }
222
217
  async loadConfig(plugin) {
223
- let config = (0, InternalConfig_1.createConfig)({
224
- plugin: plugin.name,
225
- searchPath: (0, projectPath_1.toProjectPathUnsafe)('index'),
226
- });
227
- await (0, ConfigRequest_1.loadPluginConfig)(plugin, config, this.options);
228
- await (0, ConfigRequest_1.runConfigRequest)(this.api, config);
229
- for (let devDep of config.devDeps) {
230
- let devDepRequest = await (0, DevDepRequest_1.createDevDependency)(devDep, this.previousDevDeps, this.options);
231
- await this.runDevDepRequest(devDepRequest);
232
- }
233
- this.configs.set(plugin.name, config);
218
+ await (0, BundleGraphRequestUtils_1.loadPluginConfigWithDevDeps)(plugin, this.options, this.api, this.previousDevDeps, this.devDepRequests, this.configs);
234
219
  }
235
220
  async runDevDepRequest(devDepRequest) {
236
- let { specifier, resolveFrom } = devDepRequest;
237
- let key = `${specifier}:${(0, projectPath_1.fromProjectPathRelative)(resolveFrom)}`;
238
- this.devDepRequests.set(key, devDepRequest);
239
- await (0, DevDepRequest_1.runDevDepRequest)(this.api, devDepRequest);
221
+ await (0, BundleGraphRequestUtils_1.runDevDepRequest)(this.api, devDepRequest, this.devDepRequests);
240
222
  }
241
223
  async bundle({ graph, changedAssets, assetRequests, }) {
242
224
  (0, ReporterRunner_1.report)({
@@ -271,11 +253,11 @@ class BundlerRunner {
271
253
  }
272
254
  }
273
255
  else {
274
- internalBundleGraph = BundleGraph_2.default.fromAssetGraph(graph, this.options.mode === 'production');
256
+ internalBundleGraph = BundleGraph_1.default.fromAssetGraph(graph, this.options.mode === 'production');
275
257
  (0, assert_1.default)(internalBundleGraph != null); // ensures the graph was created
276
258
  await (0, dumpGraphToGraphViz_1.default)(
277
259
  // @ts-expect-error TS2345
278
- internalBundleGraph._graph, 'before_bundle', BundleGraph_2.bundleGraphEdgeTypes);
260
+ internalBundleGraph._graph, 'before_bundle', BundleGraph_1.bundleGraphEdgeTypes);
279
261
  let mutableBundleGraph = new MutableBundleGraph_1.default(internalBundleGraph, this.options);
280
262
  let measurement;
281
263
  let measurementFilename;
@@ -350,7 +332,7 @@ class BundlerRunner {
350
332
  if (internalBundleGraph != null) {
351
333
  await (0, dumpGraphToGraphViz_1.default)(
352
334
  // @ts-expect-error TS2345
353
- internalBundleGraph._graph, 'after_bundle', BundleGraph_2.bundleGraphEdgeTypes);
335
+ internalBundleGraph._graph, 'after_bundle', BundleGraph_1.bundleGraphEdgeTypes);
354
336
  }
355
337
  }
356
338
  let changedRuntimes = new Map();
@@ -359,7 +341,7 @@ class BundlerRunner {
359
341
  // inline bundles must still be named so the PackagerRunner
360
342
  // can match them to the correct packager/optimizer plugins.
361
343
  let bundles = internalBundleGraph.getBundles({ includeInline: true });
362
- await Promise.all(bundles.map((bundle) => this.nameBundle(namers, bundle, internalBundleGraph)));
344
+ await Promise.all(bundles.map((bundle) => (0, BundleGraphRequestUtils_1.nameBundle)(namers, bundle, internalBundleGraph, this.options, this.pluginOptions, this.configs)));
363
345
  changedRuntimes = await (0, logger_1.instrumentAsync)('applyRuntimes', () => (0, applyRuntimes_1.default)({
364
346
  bundleGraph: internalBundleGraph,
365
347
  api: this.api,
@@ -379,13 +361,13 @@ class BundlerRunner {
379
361
  }, this.previousDevDeps, this.options);
380
362
  await this.runDevDepRequest(devDepRequest);
381
363
  }
382
- this.validateBundles(internalBundleGraph);
364
+ (0, BundleGraphRequestUtils_1.validateBundles)(internalBundleGraph);
383
365
  // Pre-compute the hashes for each bundle so they are only computed once and shared between workers.
384
366
  internalBundleGraph.getBundleGraphHash();
385
367
  }
386
368
  await (0, dumpGraphToGraphViz_1.default)(
387
369
  // @ts-expect-error TS2345
388
- internalBundleGraph._graph, 'after_runtimes', BundleGraph_2.bundleGraphEdgeTypes);
370
+ internalBundleGraph._graph, 'after_runtimes', BundleGraph_1.bundleGraphEdgeTypes);
389
371
  this.api.storeResult({
390
372
  bundleGraph: internalBundleGraph,
391
373
  assetGraphBundlingVersion: graph.getBundlingVersion(),
@@ -399,49 +381,4 @@ class BundlerRunner {
399
381
  assetRequests,
400
382
  };
401
383
  }
402
- validateBundles(bundleGraph) {
403
- let bundles = bundleGraph.getBundles();
404
- let bundleNames = bundles.map((b) => (0, projectPath_1.joinProjectPath)(b.target.distDir, (0, nullthrows_1.default)(b.name)));
405
- assert_2.default.deepEqual(bundleNames, (0, utils_1.unique)(bundleNames), 'Bundles must have unique name. Conflicting names: ' +
406
- [
407
- ...(0, utils_1.setSymmetricDifference)(new Set(bundleNames), new Set((0, utils_1.unique)(bundleNames))),
408
- ].join());
409
- }
410
- async nameBundle(namers, internalBundle, internalBundleGraph) {
411
- let bundle = Bundle_1.Bundle.get(internalBundle, internalBundleGraph, this.options);
412
- let bundleGraph = new BundleGraph_1.default(internalBundleGraph, Bundle_1.NamedBundle.get.bind(Bundle_1.NamedBundle), this.options);
413
- for (let namer of namers) {
414
- let measurement;
415
- try {
416
- measurement = profiler_1.tracer.createMeasurement(namer.name, 'namer', bundle.id);
417
- let name = await namer.plugin.name({
418
- bundle,
419
- bundleGraph,
420
- config: this.configs.get(namer.name)?.result,
421
- options: this.pluginOptions,
422
- logger: new logger_1.PluginLogger({ origin: namer.name }),
423
- tracer: new profiler_1.PluginTracer({ origin: namer.name, category: 'namer' }),
424
- });
425
- if (name != null) {
426
- internalBundle.name = name;
427
- let { hashReference } = internalBundle;
428
- internalBundle.displayName = name.includes(hashReference)
429
- ? name.replace(hashReference, '[hash]')
430
- : name;
431
- return;
432
- }
433
- }
434
- catch (e) {
435
- throw new diagnostic_1.default({
436
- diagnostic: (0, diagnostic_1.errorToDiagnostic)(e, {
437
- origin: namer.name,
438
- }),
439
- });
440
- }
441
- finally {
442
- measurement && measurement.end();
443
- }
444
- }
445
- throw new Error('Unable to name bundle');
446
- }
447
384
  }
@@ -0,0 +1,320 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.default = createBundleGraphRequestRust;
40
+ exports.getBundleGraph = getBundleGraph;
41
+ const assert_1 = __importDefault(require("assert"));
42
+ const diagnostic_1 = __importDefault(require("@atlaspack/diagnostic"));
43
+ const graph_1 = require("@atlaspack/graph");
44
+ const logger_1 = require("@atlaspack/logger");
45
+ const feature_flags_1 = require("@atlaspack/feature-flags");
46
+ const BundleGraph_1 = __importStar(require("../BundleGraph"));
47
+ const dumpGraphToGraphViz_1 = __importDefault(require("../dumpGraphToGraphViz"));
48
+ const nullthrows_1 = __importDefault(require("nullthrows"));
49
+ const rust_1 = require("@atlaspack/rust");
50
+ const PluginOptions_1 = __importDefault(require("../public/PluginOptions"));
51
+ const applyRuntimes_1 = __importDefault(require("../applyRuntimes"));
52
+ const constants_1 = require("../constants");
53
+ const utils_1 = require("../utils");
54
+ const DevDepRequest_1 = require("./DevDepRequest");
55
+ const RequestTracker_1 = require("../RequestTracker");
56
+ const AtlaspackConfigRequest_1 = __importStar(require("./AtlaspackConfigRequest"));
57
+ const BundleGraphRequestUtils_1 = require("./BundleGraphRequestUtils");
58
+ const EnvironmentManager_1 = require("../EnvironmentManager");
59
+ const Environment_1 = require("../Environment");
60
+ function createBundleGraphRequestRust(input) {
61
+ return {
62
+ type: RequestTracker_1.requestTypes.bundle_graph_request,
63
+ id: 'BundleGraphRust',
64
+ run: async (runInput) => {
65
+ const { api, options, rustAtlaspack } = runInput;
66
+ (0, assert_1.default)(rustAtlaspack, 'BundleGraphRequestRust requires rustAtlaspack');
67
+ let { bundleGraphPromise, commitPromise } = await rustAtlaspack.buildBundleGraph();
68
+ let [serializedBundleGraph, bundleGraphError] = (await bundleGraphPromise);
69
+ if (bundleGraphError) {
70
+ throw new diagnostic_1.default({ diagnostic: bundleGraphError });
71
+ }
72
+ // Don’t reuse previous JS result yet; we just rebuild from scratch.
73
+ let { bundleGraph, changedAssets } = (0, logger_1.instrument)('atlaspack_v3_getBundleGraph', () => getBundleGraph(serializedBundleGraph));
74
+ const runner = new NativeBundlerRunner({ api, options }, input.optionsRef);
75
+ await runner.loadConfigs();
76
+ // Name all bundles
77
+ const namers = await runner.config.getNamers();
78
+ const bundles = bundleGraph.getBundles({ includeInline: true });
79
+ await Promise.all(bundles.map((b) => (0, BundleGraphRequestUtils_1.nameBundle)(namers, b, bundleGraph, options, runner.pluginOptions, runner.configs)));
80
+ // Apply runtimes
81
+ const changedRuntimes = await (0, logger_1.instrumentAsync)('applyRuntimes', () => (0, applyRuntimes_1.default)({
82
+ bundleGraph,
83
+ api,
84
+ config: runner.config,
85
+ options,
86
+ optionsRef: input.optionsRef,
87
+ pluginOptions: runner.pluginOptions,
88
+ previousDevDeps: runner.previousDevDeps,
89
+ devDepRequests: runner.devDepRequests,
90
+ configs: runner.configs,
91
+ }));
92
+ // Add dev deps for namers
93
+ for (const namer of namers) {
94
+ const devDepRequest = await (0, DevDepRequest_1.createDevDependency)({
95
+ specifier: namer.name,
96
+ resolveFrom: namer.resolveFrom,
97
+ }, runner.previousDevDeps, options);
98
+ await (0, BundleGraphRequestUtils_1.runDevDepRequest)(api, devDepRequest, runner.devDepRequests);
99
+ }
100
+ (0, BundleGraphRequestUtils_1.validateBundles)(bundleGraph);
101
+ bundleGraph.getBundleGraphHash();
102
+ await (0, dumpGraphToGraphViz_1.default)(
103
+ // @ts-expect-error Accessing internal graph for debug output
104
+ bundleGraph._graph, 'after_runtimes_native', BundleGraph_1.bundleGraphEdgeTypes);
105
+ let [_commitResult, commitError] = await commitPromise;
106
+ if (commitError) {
107
+ throw new diagnostic_1.default({
108
+ diagnostic: {
109
+ message: 'Error committing bundle graph in Rust: ' + commitError.message,
110
+ },
111
+ });
112
+ }
113
+ return {
114
+ bundleGraph,
115
+ // Not accurate yet — ok for now.
116
+ assetGraphBundlingVersion: 0,
117
+ changedAssets: changedRuntimes,
118
+ assetRequests: [],
119
+ };
120
+ },
121
+ input,
122
+ };
123
+ }
124
+ function mapSymbols({ exported, ...symbol }) {
125
+ let jsSymbol = {
126
+ local: symbol.local ?? undefined,
127
+ loc: symbol.loc ?? undefined,
128
+ isWeak: symbol.isWeak,
129
+ meta: {
130
+ isEsm: symbol.isEsmExport,
131
+ isStaticBindingSafe: symbol.isStaticBindingSafe,
132
+ },
133
+ };
134
+ if (symbol.exported) {
135
+ jsSymbol.exported = symbol.exported;
136
+ }
137
+ return [exported, jsSymbol];
138
+ }
139
+ function normalizeEnv(env) {
140
+ if (!env)
141
+ return env;
142
+ env.id = env.id || (0, Environment_1.getEnvironmentHash)(env);
143
+ return (0, EnvironmentManager_1.toEnvironmentRef)(env);
144
+ }
145
+ function getBundleGraph(serializedGraph) {
146
+ // Build a fresh internal bundle graph.
147
+ const publicIdByAssetId = new Map(Object.entries(serializedGraph.publicIdByAssetId ?? {}));
148
+ const assetPublicIds = new Set(serializedGraph.assetPublicIds ?? []);
149
+ // BundleGraph constructor expects a ContentGraph under `_graph`.
150
+ // We reuse the internal graph class by creating an empty instance and then adding nodes.
151
+ const graph = new BundleGraph_1.default({
152
+ // We intentionally start with an empty graph and add nodes/edges from the Rust payload.
153
+ // `ContentGraph` will allocate as needed.
154
+ graph: new graph_1.ContentGraph(),
155
+ bundleContentHashes: new Map(),
156
+ publicIdByAssetId,
157
+ assetPublicIds,
158
+ conditions: new Map(),
159
+ });
160
+ // Root must exist at node id 0.
161
+ const rootNodeId = graph._graph.addNodeByContentKey('@@root', {
162
+ id: '@@root',
163
+ type: 'root',
164
+ value: null,
165
+ });
166
+ graph._graph.setRootNodeId(rootNodeId);
167
+ let entry = 0;
168
+ const changedAssets = new Map();
169
+ const decoder = new TextDecoder();
170
+ // Create nodes in order.
171
+ for (let i = 0; i < serializedGraph.nodes.length; i++) {
172
+ // Nodes come back as buffers (same as AssetGraphRequestRust)
173
+ let node = JSON.parse(decoder.decode(serializedGraph.nodes[i]));
174
+ if (node.type === 'root') {
175
+ continue;
176
+ }
177
+ if (node.type === 'entry') {
178
+ let id = 'entry:' + ++entry;
179
+ graph._graph.addNodeByContentKey(id, { id, type: 'root', value: null });
180
+ continue;
181
+ }
182
+ if (node.type === 'asset') {
183
+ let asset = node.value;
184
+ let id = asset.id;
185
+ asset.committed = true;
186
+ asset.contentKey = id;
187
+ asset.env = { ...asset.env };
188
+ asset.env.id = (0, feature_flags_1.getFeatureFlag)('environmentDeduplication')
189
+ ? (0, Environment_1.getEnvironmentHash)(asset.env)
190
+ : (0, Environment_1.getEnvironmentHash)(asset.env);
191
+ asset.env = normalizeEnv(asset.env);
192
+ asset.mapKey = `map:${asset.id}`;
193
+ asset.dependencies = new Map();
194
+ asset.meta.isV3 = true;
195
+ if (asset.symbols != null) {
196
+ asset.symbols = new Map(asset.symbols.map(mapSymbols));
197
+ }
198
+ changedAssets.set(id, asset);
199
+ const assetNode = {
200
+ id,
201
+ type: 'asset',
202
+ usedSymbols: new Set(),
203
+ usedSymbolsDownDirty: true,
204
+ usedSymbolsUpDirty: true,
205
+ value: asset,
206
+ };
207
+ graph._graph.addNodeByContentKey(id, assetNode);
208
+ continue;
209
+ }
210
+ if (node.type === 'dependency') {
211
+ let { dependency, id } = node.value;
212
+ dependency.id = id;
213
+ dependency.env = { ...dependency.env };
214
+ dependency.env.id = (0, Environment_1.getEnvironmentHash)(dependency.env);
215
+ dependency.env = normalizeEnv(dependency.env);
216
+ if (dependency.symbols != null) {
217
+ dependency.symbols = new Map(dependency.symbols?.map(mapSymbols));
218
+ }
219
+ let usedSymbolsDown = new Set();
220
+ let usedSymbolsUp = new Map();
221
+ if (dependency.isEntry && dependency.isLibrary) {
222
+ usedSymbolsDown.add('*');
223
+ usedSymbolsUp.set('*', undefined);
224
+ }
225
+ const depNode = {
226
+ id,
227
+ type: 'dependency',
228
+ deferred: false,
229
+ excluded: false,
230
+ hasDeferred: node.has_deferred,
231
+ // @ts-expect-error Flow types expect a more specific symbol set type
232
+ usedSymbolsDown,
233
+ usedSymbolsDownDirty: true,
234
+ usedSymbolsUp,
235
+ usedSymbolsUpDirtyDown: true,
236
+ usedSymbolsUpDirtyUp: true,
237
+ value: dependency,
238
+ };
239
+ graph._graph.addNodeByContentKey(id, depNode);
240
+ continue;
241
+ }
242
+ if (node.type === 'bundle') {
243
+ node.value.env = normalizeEnv(node.value.env);
244
+ node.value.target.env = normalizeEnv(node.value.target.env);
245
+ graph._graph.addNodeByContentKey(node.id, node);
246
+ continue;
247
+ }
248
+ if (node.type === 'bundle_group' || node.type === 'bundleGroup') {
249
+ // Rust serializer may emit bundleGroup nodes either as `{id,type,value:{...}}`
250
+ // or as `{type:"bundleGroup", id, target, entryAssetId}`.
251
+ if (node.value == null) {
252
+ node.value = {
253
+ target: node.target,
254
+ entryAssetId: node.entryAssetId ?? node.entry_asset_id,
255
+ };
256
+ }
257
+ // Normalize entry asset id field naming
258
+ if (node.value.entryAssetId == null &&
259
+ node.value.entry_asset_id != null) {
260
+ node.value.entryAssetId = node.value.entry_asset_id;
261
+ }
262
+ node.value.target.env = normalizeEnv(node.value.target.env);
263
+ // Normalise to the expected snake_case type
264
+ node.type = 'bundle_group';
265
+ graph._graph.addNodeByContentKey(node.id, node);
266
+ continue;
267
+ }
268
+ }
269
+ // Apply edges
270
+ for (let i = 0; i < serializedGraph.edges.length; i += 3) {
271
+ const from = serializedGraph.edges[i];
272
+ const to = serializedGraph.edges[i + 1];
273
+ const type = serializedGraph.edges[i + 2];
274
+ const fromNode = graph._graph.getNode(from);
275
+ const toNode = graph._graph.getNode(to);
276
+ if (fromNode?.type === 'asset' && toNode?.type === 'dependency') {
277
+ fromNode.value.dependencies.set(toNode.value.id, toNode.value);
278
+ }
279
+ // If we are adding a references edge, remove existing null edge.
280
+ if (type === BundleGraph_1.bundleGraphEdgeTypes.references &&
281
+ graph._graph.hasEdge(from, to, BundleGraph_1.bundleGraphEdgeTypes.null)) {
282
+ graph._graph.removeEdge(from, to, BundleGraph_1.bundleGraphEdgeTypes.null);
283
+ }
284
+ graph._graph.addEdge(from, to, type);
285
+ }
286
+ return { bundleGraph: graph, changedAssets };
287
+ }
288
+ class NativeBundlerRunner {
289
+ constructor({ api, options }, optionsRef) {
290
+ this.options = options;
291
+ this.api = api;
292
+ this.optionsRef = optionsRef;
293
+ this.previousDevDeps = new Map();
294
+ this.devDepRequests = new Map();
295
+ this.configs = new Map();
296
+ this.pluginOptions = new PluginOptions_1.default((0, utils_1.optionsProxy)(this.options, api.invalidateOnOptionChange));
297
+ const key = (0, rust_1.hashString)(`${constants_1.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`);
298
+ this.cacheKey = `BundleGraph/${constants_1.ATLASPACK_VERSION}/${options.mode}/${key}`;
299
+ }
300
+ async loadConfigs() {
301
+ const configResult = (0, nullthrows_1.default)(await this.api.runRequest((0, AtlaspackConfigRequest_1.default)()));
302
+ this.config = (0, AtlaspackConfigRequest_1.getCachedAtlaspackConfig)(configResult, this.options);
303
+ const { devDeps, invalidDevDeps } = await (0, DevDepRequest_1.getDevDepRequests)(this.api);
304
+ this.previousDevDeps = devDeps;
305
+ (0, DevDepRequest_1.invalidateDevDeps)(invalidDevDeps, this.options, this.config);
306
+ const bundler = await this.config.getBundler();
307
+ await this.loadPluginConfig(bundler);
308
+ const namers = await this.config.getNamers();
309
+ for (const namer of namers) {
310
+ await this.loadPluginConfig(namer);
311
+ }
312
+ const runtimes = await this.config.getRuntimes();
313
+ for (const runtime of runtimes) {
314
+ await this.loadPluginConfig(runtime);
315
+ }
316
+ }
317
+ async loadPluginConfig(plugin) {
318
+ await (0, BundleGraphRequestUtils_1.loadPluginConfigWithDevDeps)(plugin, this.options, this.api, this.previousDevDeps, this.devDepRequests, this.configs);
319
+ }
320
+ }