@atlaspack/core 2.13.2-dev.3689 → 2.14.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.
Files changed (85) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/package.json +20 -20
  3. package/src/Atlaspack.js +3 -2
  4. package/src/atlaspack-v3/AtlaspackV3.js +25 -9
  5. package/src/requests/WriteBundlesRequest.js +31 -22
  6. package/LICENSE +0 -201
  7. package/lib/AssetGraph.js +0 -521
  8. package/lib/Atlaspack.js +0 -676
  9. package/lib/AtlaspackConfig.js +0 -298
  10. package/lib/AtlaspackConfig.schema.js +0 -103
  11. package/lib/BundleGraph.js +0 -1527
  12. package/lib/CommittedAsset.js +0 -155
  13. package/lib/Dependency.js +0 -136
  14. package/lib/Environment.js +0 -144
  15. package/lib/IdentifierRegistry.js +0 -36
  16. package/lib/InternalConfig.js +0 -56
  17. package/lib/PackagerRunner.js +0 -525
  18. package/lib/ReporterRunner.js +0 -151
  19. package/lib/RequestTracker.js +0 -1178
  20. package/lib/SymbolPropagation.js +0 -618
  21. package/lib/TargetDescriptor.schema.js +0 -118
  22. package/lib/Transformation.js +0 -522
  23. package/lib/UncommittedAsset.js +0 -348
  24. package/lib/Validation.js +0 -203
  25. package/lib/applyRuntimes.js +0 -355
  26. package/lib/assetUtils.js +0 -205
  27. package/lib/atlaspack-v3/AtlaspackV3.js +0 -57
  28. package/lib/atlaspack-v3/NapiWorkerPool.js +0 -71
  29. package/lib/atlaspack-v3/fs.js +0 -39
  30. package/lib/atlaspack-v3/index.js +0 -26
  31. package/lib/atlaspack-v3/jsCallable.js +0 -20
  32. package/lib/atlaspack-v3/worker/compat/asset-symbols.js +0 -197
  33. package/lib/atlaspack-v3/worker/compat/bitflags.js +0 -84
  34. package/lib/atlaspack-v3/worker/compat/dependency.js +0 -44
  35. package/lib/atlaspack-v3/worker/compat/environment.js +0 -57
  36. package/lib/atlaspack-v3/worker/compat/index.js +0 -104
  37. package/lib/atlaspack-v3/worker/compat/mutable-asset.js +0 -164
  38. package/lib/atlaspack-v3/worker/compat/plugin-config.js +0 -78
  39. package/lib/atlaspack-v3/worker/compat/plugin-logger.js +0 -29
  40. package/lib/atlaspack-v3/worker/compat/plugin-options.js +0 -113
  41. package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +0 -12
  42. package/lib/atlaspack-v3/worker/compat/target.js +0 -17
  43. package/lib/atlaspack-v3/worker/index.js +0 -3
  44. package/lib/atlaspack-v3/worker/worker.js +0 -280
  45. package/lib/constants.js +0 -21
  46. package/lib/dumpGraphToGraphViz.js +0 -206
  47. package/lib/index.js +0 -70
  48. package/lib/loadAtlaspackPlugin.js +0 -115
  49. package/lib/loadDotEnv.js +0 -54
  50. package/lib/projectPath.js +0 -112
  51. package/lib/public/Asset.js +0 -259
  52. package/lib/public/Bundle.js +0 -236
  53. package/lib/public/BundleGraph.js +0 -279
  54. package/lib/public/BundleGroup.js +0 -50
  55. package/lib/public/Config.js +0 -202
  56. package/lib/public/Dependency.js +0 -131
  57. package/lib/public/Environment.js +0 -247
  58. package/lib/public/MutableBundleGraph.js +0 -204
  59. package/lib/public/PluginOptions.js +0 -71
  60. package/lib/public/Symbols.js +0 -247
  61. package/lib/public/Target.js +0 -64
  62. package/lib/registerCoreWithSerializer.js +0 -51
  63. package/lib/requests/AssetGraphRequest.js +0 -432
  64. package/lib/requests/AssetGraphRequestRust.js +0 -220
  65. package/lib/requests/AssetRequest.js +0 -132
  66. package/lib/requests/AtlaspackBuildRequest.js +0 -79
  67. package/lib/requests/AtlaspackConfigRequest.js +0 -479
  68. package/lib/requests/BundleGraphRequest.js +0 -485
  69. package/lib/requests/ConfigRequest.js +0 -203
  70. package/lib/requests/DevDepRequest.js +0 -193
  71. package/lib/requests/EntryRequest.js +0 -295
  72. package/lib/requests/PackageRequest.js +0 -88
  73. package/lib/requests/PathRequest.js +0 -357
  74. package/lib/requests/TargetRequest.js +0 -1179
  75. package/lib/requests/ValidationRequest.js +0 -66
  76. package/lib/requests/WriteBundleRequest.js +0 -252
  77. package/lib/requests/WriteBundlesRequest.js +0 -153
  78. package/lib/requests/asset-graph-diff.js +0 -128
  79. package/lib/requests/asset-graph-dot.js +0 -131
  80. package/lib/resolveOptions.js +0 -265
  81. package/lib/serializerCore.browser.js +0 -29
  82. package/lib/summarizeRequest.js +0 -55
  83. package/lib/types.js +0 -35
  84. package/lib/utils.js +0 -160
  85. package/lib/worker.js +0 -184
@@ -1,485 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = createBundleGraphRequest;
7
- function _fs() {
8
- const data = _interopRequireDefault(require("fs"));
9
- _fs = function () {
10
- return data;
11
- };
12
- return data;
13
- }
14
- function _assert() {
15
- const data = _interopRequireDefault(require("assert"));
16
- _assert = function () {
17
- return data;
18
- };
19
- return data;
20
- }
21
- function _nullthrows() {
22
- const data = _interopRequireDefault(require("nullthrows"));
23
- _nullthrows = function () {
24
- return data;
25
- };
26
- return data;
27
- }
28
- function _logger() {
29
- const data = require("@atlaspack/logger");
30
- _logger = function () {
31
- return data;
32
- };
33
- return data;
34
- }
35
- function _diagnostic() {
36
- const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
37
- _diagnostic = function () {
38
- return data;
39
- };
40
- return data;
41
- }
42
- var _AssetGraph = _interopRequireDefault(require("../AssetGraph"));
43
- var _BundleGraph = _interopRequireDefault(require("../public/BundleGraph"));
44
- var _BundleGraph2 = _interopRequireWildcard(require("../BundleGraph"));
45
- var _MutableBundleGraph = _interopRequireDefault(require("../public/MutableBundleGraph"));
46
- var _Bundle = require("../public/Bundle");
47
- var _ReporterRunner = require("../ReporterRunner");
48
- var _dumpGraphToGraphViz = _interopRequireDefault(require("../dumpGraphToGraphViz"));
49
- function _utils() {
50
- const data = require("@atlaspack/utils");
51
- _utils = function () {
52
- return data;
53
- };
54
- return data;
55
- }
56
- function _rust() {
57
- const data = require("@atlaspack/rust");
58
- _rust = function () {
59
- return data;
60
- };
61
- return data;
62
- }
63
- var _PluginOptions = _interopRequireDefault(require("../public/PluginOptions"));
64
- var _applyRuntimes = _interopRequireDefault(require("../applyRuntimes"));
65
- var _constants = require("../constants");
66
- var _utils2 = require("../utils");
67
- var _AtlaspackConfigRequest = _interopRequireWildcard(require("./AtlaspackConfigRequest"));
68
- var _DevDepRequest = require("./DevDepRequest");
69
- var _InternalConfig = require("../InternalConfig");
70
- var _ConfigRequest = require("./ConfigRequest");
71
- var _projectPath = require("../projectPath");
72
- var _AssetGraphRequest = _interopRequireDefault(require("./AssetGraphRequest"));
73
- var _AssetGraphRequestRust = require("./AssetGraphRequestRust");
74
- function _profiler() {
75
- const data = require("@atlaspack/profiler");
76
- _profiler = function () {
77
- return data;
78
- };
79
- return data;
80
- }
81
- var _RequestTracker = require("../RequestTracker");
82
- var _assetGraphDot = require("./asset-graph-dot");
83
- var _types = require("../types");
84
- 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); }
85
- 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; }
86
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
87
- // TODO: Rename to BundleGraphRequestResult
88
- function applySideEffectsForLoadableImports(assetGraph) {
89
- // Avoid revisiting nodes
90
- let updatedAssetIds = new Set();
91
- assetGraph.traverse(nodeId => {
92
- let node = (0, _nullthrows().default)(assetGraph.getNode(nodeId));
93
- if (node.type !== 'dependency' || node.value.specifier.indexOf('@confluence/loadable') === -1) {
94
- return;
95
- }
96
- assetGraph.traverseAncestors(nodeId, (ancestorNodeId, _, actions) => {
97
- if (updatedAssetIds.has(ancestorNodeId)) {
98
- actions.skipChildren();
99
- return;
100
- }
101
- let ancestorNode = (0, _nullthrows().default)(assetGraph.getNode(ancestorNodeId));
102
-
103
- // Async boundaries will catch the side effects
104
- if (ancestorNode.type === 'dependency' && ancestorNode.value.priority !== _types.Priority.sync) {
105
- actions.skipChildren();
106
- }
107
-
108
- // inline-requires optimizer is only checking assets
109
- if (ancestorNode.type !== 'asset') {
110
- return;
111
- }
112
- updatedAssetIds.add(ancestorNodeId);
113
- ancestorNode.value.sideEffects = true;
114
- });
115
- }, assetGraph.rootNodeId);
116
- }
117
- function createBundleGraphRequest(input) {
118
- return {
119
- type: _RequestTracker.requestTypes.bundle_graph_request,
120
- id: 'BundleGraph',
121
- run: async input => {
122
- var _input$options$featur;
123
- let {
124
- options,
125
- api,
126
- invalidateReason
127
- } = input;
128
- let {
129
- optionsRef,
130
- requestedAssetIds,
131
- signal
132
- } = input.input;
133
- let measurement = _profiler().tracer.createMeasurement('building');
134
- let createAssetGraphRequest = input.rustAtlaspack ? (0, _AssetGraphRequestRust.createAssetGraphRequestRust)(input.rustAtlaspack) : _AssetGraphRequest.default;
135
- let request = createAssetGraphRequest({
136
- name: 'Main',
137
- entries: options.entries,
138
- optionsRef,
139
- shouldBuildLazily: options.shouldBuildLazily,
140
- lazyIncludes: options.lazyIncludes,
141
- lazyExcludes: options.lazyExcludes,
142
- requestedAssetIds
143
- });
144
- let {
145
- assetGraph,
146
- changedAssets,
147
- assetRequests
148
- } = await api.runRequest(request, {
149
- force: Boolean(input.rustAtlaspack) || options.shouldBuildLazily && requestedAssetIds.size > 0
150
- });
151
- if ((_input$options$featur = input.options.featureFlags) !== null && _input$options$featur !== void 0 && _input$options$featur.loadableSideEffects) {
152
- applySideEffectsForLoadableImports(assetGraph);
153
- }
154
- let debugAssetGraphDotPath = (0, _assetGraphDot.getDebugAssetGraphDotPath)();
155
- if (debugAssetGraphDotPath !== null) {
156
- await _fs().default.promises.writeFile(debugAssetGraphDotPath, (0, _assetGraphDot.assetGraphToDot)(assetGraph, (0, _assetGraphDot.getDebugAssetGraphDotOptions)()), 'utf8');
157
- }
158
-
159
- // if (input.rustAtlaspack && process.env.NATIVE_COMPARE === 'true') {
160
- // let {assetGraph: jsAssetGraph} = await api.runRequest(
161
- // createAssetGraphRequestJS({
162
- // name: 'Main',
163
- // entries: options.entries,
164
- // optionsRef,
165
- // shouldBuildLazily: options.shouldBuildLazily,
166
- // lazyIncludes: options.lazyIncludes,
167
- // lazyExcludes: options.lazyExcludes,
168
- // requestedAssetIds,
169
- // }),
170
- // {
171
- // force: true,
172
- // },
173
- // );
174
- // require('./asset-graph-diff.js')(jsAssetGraph, assetGraph);
175
- // }
176
-
177
- measurement && measurement.end();
178
- (0, _utils2.assertSignalNotAborted)(signal);
179
-
180
- // If any subrequests are invalid (e.g. dev dep requests or config requests),
181
- // bail on incremental bundling. We also need to invalidate for option changes,
182
- // which are hoisted to direct invalidations on the bundle graph request.
183
- let subRequestsInvalid = Boolean(invalidateReason & _constants.OPTION_CHANGE) || input.api.getSubRequests().some(req => !input.api.canSkipSubrequest(req.id));
184
- if (subRequestsInvalid) {
185
- assetGraph.safeToIncrementallyBundle = false;
186
- }
187
- let configResult = (0, _nullthrows().default)(await input.api.runRequest((0, _AtlaspackConfigRequest.default)()));
188
- (0, _utils2.assertSignalNotAborted)(signal);
189
- let atlaspackConfig = (0, _AtlaspackConfigRequest.getCachedAtlaspackConfig)(configResult, input.options);
190
- let {
191
- devDeps,
192
- invalidDevDeps
193
- } = await (0, _DevDepRequest.getDevDepRequests)(input.api);
194
- (0, _DevDepRequest.invalidateDevDeps)(invalidDevDeps, input.options, atlaspackConfig);
195
- let bundlingMeasurement = _profiler().tracer.createMeasurement('bundling');
196
- let builder = new BundlerRunner(input, atlaspackConfig, devDeps);
197
- let res = await builder.bundle({
198
- graph: assetGraph,
199
- changedAssets: changedAssets,
200
- assetRequests
201
- });
202
- bundlingMeasurement && bundlingMeasurement.end();
203
- for (let [id, asset] of changedAssets) {
204
- res.changedAssets.set(id, asset);
205
- }
206
- await (0, _dumpGraphToGraphViz.default)(
207
- // $FlowFixMe Added in Flow 0.121.0 upgrade in #4381 (Windows only)
208
- res.bundleGraph._graph, 'BundleGraph', _BundleGraph2.bundleGraphEdgeTypes);
209
- return res;
210
- },
211
- input
212
- };
213
- }
214
- class BundlerRunner {
215
- constructor({
216
- input,
217
- api,
218
- options
219
- }, config, previousDevDeps) {
220
- this.options = options;
221
- this.api = api;
222
- this.optionsRef = input.optionsRef;
223
- this.config = config;
224
- this.previousDevDeps = previousDevDeps;
225
- this.devDepRequests = new Map();
226
- this.configs = new Map();
227
- this.pluginOptions = new _PluginOptions.default((0, _utils2.optionsProxy)(this.options, api.invalidateOnOptionChange));
228
- this.cacheKey = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-BundleGraph';
229
- }
230
- async loadConfigs() {
231
- // Load all configs up front so we can use them in the cache key
232
- let bundler = await this.config.getBundler();
233
- await this.loadConfig(bundler);
234
- let namers = await this.config.getNamers();
235
- for (let namer of namers) {
236
- await this.loadConfig(namer);
237
- }
238
- let runtimes = await this.config.getRuntimes();
239
- for (let runtime of runtimes) {
240
- await this.loadConfig(runtime);
241
- }
242
- }
243
- async loadConfig(plugin) {
244
- let config = (0, _InternalConfig.createConfig)({
245
- plugin: plugin.name,
246
- searchPath: (0, _projectPath.toProjectPathUnsafe)('index')
247
- });
248
- await (0, _ConfigRequest.loadPluginConfig)(plugin, config, this.options);
249
- await (0, _ConfigRequest.runConfigRequest)(this.api, config);
250
- for (let devDep of config.devDeps) {
251
- let devDepRequest = await (0, _DevDepRequest.createDevDependency)(devDep, this.previousDevDeps, this.options);
252
- await this.runDevDepRequest(devDepRequest);
253
- }
254
- this.configs.set(plugin.name, config);
255
- }
256
- async runDevDepRequest(devDepRequest) {
257
- let {
258
- specifier,
259
- resolveFrom
260
- } = devDepRequest;
261
- let key = `${specifier}:${(0, _projectPath.fromProjectPathRelative)(resolveFrom)}`;
262
- this.devDepRequests.set(key, devDepRequest);
263
- await (0, _DevDepRequest.runDevDepRequest)(this.api, devDepRequest);
264
- }
265
- async bundle({
266
- graph,
267
- changedAssets,
268
- assetRequests
269
- }) {
270
- (0, _ReporterRunner.report)({
271
- type: 'buildProgress',
272
- phase: 'bundling'
273
- });
274
- await this.loadConfigs();
275
- let plugin = await this.config.getBundler();
276
- let {
277
- plugin: bundler,
278
- name,
279
- resolveFrom
280
- } = plugin;
281
-
282
- // if a previous asset graph hash is passed in, check if the bundle graph is also available
283
- let previousBundleGraphResult;
284
- if (graph.safeToIncrementallyBundle) {
285
- try {
286
- previousBundleGraphResult = await this.api.getPreviousResult();
287
- } catch {
288
- // if the bundle graph had an error or was removed, don't fail the build
289
- }
290
- }
291
- if (previousBundleGraphResult == null) {
292
- graph.safeToIncrementallyBundle = false;
293
- }
294
- let internalBundleGraph;
295
- let logger = new (_logger().PluginLogger)({
296
- origin: name
297
- });
298
- let tracer = new (_profiler().PluginTracer)({
299
- origin: name,
300
- category: 'bundle'
301
- });
302
- try {
303
- if (previousBundleGraphResult) {
304
- internalBundleGraph = previousBundleGraphResult.bundleGraph;
305
- for (let changedAssetId of changedAssets.keys()) {
306
- // Copy over the whole node to also have correct symbol data
307
- let changedAssetNode = (0, _nullthrows().default)(graph.getNodeByContentKey(changedAssetId));
308
- (0, _assert().default)(changedAssetNode.type === 'asset');
309
- internalBundleGraph.updateAsset(changedAssetNode);
310
- }
311
- } else {
312
- var _this$configs$get;
313
- internalBundleGraph = _BundleGraph2.default.fromAssetGraph(graph, this.options.mode === 'production');
314
- (0, _assert().default)(internalBundleGraph != null); // ensures the graph was created
315
-
316
- await (0, _dumpGraphToGraphViz.default)(
317
- // $FlowFixMe
318
- internalBundleGraph._graph, 'before_bundle', _BundleGraph2.bundleGraphEdgeTypes);
319
- let mutableBundleGraph = new _MutableBundleGraph.default(internalBundleGraph, this.options);
320
- let measurement;
321
- let measurementFilename;
322
- if (tracer.enabled) {
323
- measurementFilename = graph.getEntryAssets().map(asset => (0, _projectPath.fromProjectPathRelative)(asset.filePath)).join(', ');
324
- measurement = tracer.createMeasurement(plugin.name, 'bundling:bundle', measurementFilename);
325
- }
326
-
327
- // this the normal bundle workflow (bundle, optimizing, run-times, naming)
328
- await bundler.bundle({
329
- bundleGraph: mutableBundleGraph,
330
- config: (_this$configs$get = this.configs.get(plugin.name)) === null || _this$configs$get === void 0 ? void 0 : _this$configs$get.result,
331
- options: this.pluginOptions,
332
- logger,
333
- tracer
334
- });
335
- measurement && measurement.end();
336
- if (this.pluginOptions.mode === 'production') {
337
- let optimizeMeasurement;
338
- try {
339
- var _this$configs$get2;
340
- if (tracer.enabled) {
341
- optimizeMeasurement = tracer.createMeasurement(plugin.name, 'bundling:optimize', (0, _nullthrows().default)(measurementFilename));
342
- }
343
- await bundler.optimize({
344
- bundleGraph: mutableBundleGraph,
345
- config: (_this$configs$get2 = this.configs.get(plugin.name)) === null || _this$configs$get2 === void 0 ? void 0 : _this$configs$get2.result,
346
- options: this.pluginOptions,
347
- logger
348
- });
349
- } catch (e) {
350
- throw new (_diagnostic().default)({
351
- diagnostic: (0, _diagnostic().errorToDiagnostic)(e, {
352
- origin: plugin.name
353
- })
354
- });
355
- } finally {
356
- optimizeMeasurement && optimizeMeasurement.end();
357
- await (0, _dumpGraphToGraphViz.default)(
358
- // $FlowFixMe[incompatible-call]
359
- internalBundleGraph._graph, 'after_optimize');
360
- }
361
- }
362
-
363
- // Add dev dependency for the bundler. This must be done AFTER running it due to
364
- // the potential for lazy require() that aren't executed until the request runs.
365
- let devDepRequest = await (0, _DevDepRequest.createDevDependency)({
366
- specifier: name,
367
- resolveFrom
368
- }, this.previousDevDeps, this.options);
369
- await this.runDevDepRequest(devDepRequest);
370
- }
371
- } catch (e) {
372
- if (internalBundleGraph != null) {
373
- this.api.storeResult({
374
- bundleGraph: internalBundleGraph,
375
- changedAssets: new Map(),
376
- assetRequests: []
377
- }, this.cacheKey);
378
- }
379
- throw new (_diagnostic().default)({
380
- diagnostic: (0, _diagnostic().errorToDiagnostic)(e, {
381
- origin: name
382
- })
383
- });
384
- } finally {
385
- if (internalBundleGraph != null) {
386
- await (0, _dumpGraphToGraphViz.default)(
387
- // $FlowFixMe[incompatible-call]
388
- internalBundleGraph._graph, 'after_bundle', _BundleGraph2.bundleGraphEdgeTypes);
389
- }
390
- }
391
- let changedRuntimes = new Map();
392
- if (!previousBundleGraphResult) {
393
- let namers = await this.config.getNamers();
394
- // inline bundles must still be named so the PackagerRunner
395
- // can match them to the correct packager/optimizer plugins.
396
- let bundles = internalBundleGraph.getBundles({
397
- includeInline: true
398
- });
399
- await Promise.all(bundles.map(bundle => this.nameBundle(namers, bundle, internalBundleGraph)));
400
- changedRuntimes = await (0, _applyRuntimes.default)({
401
- bundleGraph: internalBundleGraph,
402
- api: this.api,
403
- config: this.config,
404
- options: this.options,
405
- optionsRef: this.optionsRef,
406
- pluginOptions: this.pluginOptions,
407
- previousDevDeps: this.previousDevDeps,
408
- devDepRequests: this.devDepRequests,
409
- configs: this.configs
410
- });
411
-
412
- // Add dev deps for namers, AFTER running them to account for lazy require().
413
- for (let namer of namers) {
414
- let devDepRequest = await (0, _DevDepRequest.createDevDependency)({
415
- specifier: namer.name,
416
- resolveFrom: namer.resolveFrom
417
- }, this.previousDevDeps, this.options);
418
- await this.runDevDepRequest(devDepRequest);
419
- }
420
- this.validateBundles(internalBundleGraph);
421
-
422
- // Pre-compute the hashes for each bundle so they are only computed once and shared between workers.
423
- internalBundleGraph.getBundleGraphHash();
424
- }
425
- await (0, _dumpGraphToGraphViz.default)(
426
- // $FlowFixMe
427
- internalBundleGraph._graph, 'after_runtimes', _BundleGraph2.bundleGraphEdgeTypes);
428
- this.api.storeResult({
429
- bundleGraph: internalBundleGraph,
430
- changedAssets: new Map(),
431
- assetRequests: []
432
- }, this.cacheKey);
433
- return {
434
- bundleGraph: internalBundleGraph,
435
- changedAssets: changedRuntimes,
436
- assetRequests
437
- };
438
- }
439
- validateBundles(bundleGraph) {
440
- let bundles = bundleGraph.getBundles();
441
- let bundleNames = bundles.map(b => (0, _projectPath.joinProjectPath)(b.target.distDir, (0, _nullthrows().default)(b.name)));
442
- _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());
443
- }
444
- async nameBundle(namers, internalBundle, internalBundleGraph) {
445
- let bundle = _Bundle.Bundle.get(internalBundle, internalBundleGraph, this.options);
446
- let bundleGraph = new _BundleGraph.default(internalBundleGraph, _Bundle.NamedBundle.get.bind(_Bundle.NamedBundle), this.options);
447
- for (let namer of namers) {
448
- let measurement;
449
- try {
450
- var _this$configs$get3;
451
- measurement = _profiler().tracer.createMeasurement(namer.name, 'namer', bundle.id);
452
- let name = await namer.plugin.name({
453
- bundle,
454
- bundleGraph,
455
- config: (_this$configs$get3 = this.configs.get(namer.name)) === null || _this$configs$get3 === void 0 ? void 0 : _this$configs$get3.result,
456
- options: this.pluginOptions,
457
- logger: new (_logger().PluginLogger)({
458
- origin: namer.name
459
- }),
460
- tracer: new (_profiler().PluginTracer)({
461
- origin: namer.name,
462
- category: 'namer'
463
- })
464
- });
465
- if (name != null) {
466
- internalBundle.name = name;
467
- let {
468
- hashReference
469
- } = internalBundle;
470
- internalBundle.displayName = name.includes(hashReference) ? name.replace(hashReference, '[hash]') : name;
471
- return;
472
- }
473
- } catch (e) {
474
- throw new (_diagnostic().default)({
475
- diagnostic: (0, _diagnostic().errorToDiagnostic)(e, {
476
- origin: namer.name
477
- })
478
- });
479
- } finally {
480
- measurement && measurement.end();
481
- }
482
- }
483
- throw new Error('Unable to name bundle');
484
- }
485
- }
@@ -1,203 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getConfigHash = getConfigHash;
7
- exports.getConfigKeyContentHash = getConfigKeyContentHash;
8
- exports.getConfigRequests = getConfigRequests;
9
- exports.loadPluginConfig = loadPluginConfig;
10
- exports.runConfigRequest = runConfigRequest;
11
- function _utils() {
12
- const data = require("@atlaspack/utils");
13
- _utils = function () {
14
- return data;
15
- };
16
- return data;
17
- }
18
- function _buildCache() {
19
- const data = require("@atlaspack/build-cache");
20
- _buildCache = function () {
21
- return data;
22
- };
23
- return data;
24
- }
25
- function _logger() {
26
- const data = require("@atlaspack/logger");
27
- _logger = function () {
28
- return data;
29
- };
30
- return data;
31
- }
32
- var _PluginOptions = _interopRequireDefault(require("../public/PluginOptions"));
33
- function _diagnostic() {
34
- const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
35
- _diagnostic = function () {
36
- return data;
37
- };
38
- return data;
39
- }
40
- var _Config = _interopRequireDefault(require("../public/Config"));
41
- var _utils2 = require("../utils");
42
- var _assetUtils = require("../assetUtils");
43
- function _rust() {
44
- const data = require("@atlaspack/rust");
45
- _rust = function () {
46
- return data;
47
- };
48
- return data;
49
- }
50
- function _profiler() {
51
- const data = require("@atlaspack/profiler");
52
- _profiler = function () {
53
- return data;
54
- };
55
- return data;
56
- }
57
- var _RequestTracker = require("../RequestTracker");
58
- var _projectPath = require("../projectPath");
59
- 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); }
60
- 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; }
61
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
62
- async function loadPluginConfig(loadedPlugin, config, options) {
63
- let loadConfig = loadedPlugin.plugin.loadConfig;
64
- if (!loadConfig) {
65
- return;
66
- }
67
- try {
68
- config.result = await loadConfig({
69
- config: new _Config.default(config, options),
70
- options: new _PluginOptions.default((0, _utils2.optionsProxy)(options, option => {
71
- config.invalidateOnOptionChange.add(option);
72
- })),
73
- logger: new (_logger().PluginLogger)({
74
- origin: loadedPlugin.name
75
- }),
76
- tracer: new (_profiler().PluginTracer)({
77
- origin: loadedPlugin.name,
78
- category: 'loadConfig'
79
- })
80
- });
81
- } catch (e) {
82
- throw new (_diagnostic().default)({
83
- diagnostic: (0, _diagnostic().errorToDiagnostic)(e, {
84
- origin: loadedPlugin.name
85
- })
86
- });
87
- }
88
- }
89
- const configKeyCache = (0, _buildCache().createBuildCache)();
90
- async function getConfigKeyContentHash(filePath, configKey, options) {
91
- let cacheKey = `${(0, _projectPath.fromProjectPathRelative)(filePath)}:${configKey}`;
92
- let cachedValue = configKeyCache.get(cacheKey);
93
- if (cachedValue) {
94
- return cachedValue;
95
- }
96
- let conf = await (0, _utils().readConfig)(options.inputFS, (0, _projectPath.fromProjectPath)(options.projectRoot, filePath));
97
- if (conf == null || conf.config[configKey] == null) {
98
- // This can occur when a config key has been removed entirely during `respondToFSEvents`
99
- return '';
100
- }
101
- let contentHash = typeof conf.config[configKey] === 'object' ? (0, _utils().hashObject)(conf.config[configKey]) : (0, _rust().hashString)(JSON.stringify(conf.config[configKey]));
102
- configKeyCache.set(cacheKey, contentHash);
103
- return contentHash;
104
- }
105
- async function runConfigRequest(api, configRequest) {
106
- let {
107
- invalidateOnFileChange,
108
- invalidateOnConfigKeyChange,
109
- invalidateOnFileCreate,
110
- invalidateOnEnvChange,
111
- invalidateOnOptionChange,
112
- invalidateOnStartup,
113
- invalidateOnBuild
114
- } = configRequest;
115
-
116
- // If there are no invalidations, then no need to create a node.
117
- if (invalidateOnFileChange.size === 0 && invalidateOnConfigKeyChange.length === 0 && invalidateOnFileCreate.length === 0 && invalidateOnOptionChange.size === 0 && invalidateOnEnvChange.size === 0 && !invalidateOnStartup && !invalidateOnBuild) {
118
- return;
119
- }
120
- await api.runRequest({
121
- id: 'config_request:' + configRequest.id,
122
- type: _RequestTracker.requestTypes.config_request,
123
- run: async ({
124
- api,
125
- options
126
- }) => {
127
- for (let filePath of invalidateOnFileChange) {
128
- api.invalidateOnFileUpdate(filePath);
129
- api.invalidateOnFileDelete(filePath);
130
- }
131
- for (let {
132
- filePath,
133
- configKey
134
- } of invalidateOnConfigKeyChange) {
135
- let contentHash = await getConfigKeyContentHash(filePath, configKey, options);
136
- api.invalidateOnConfigKeyChange(filePath, configKey, contentHash);
137
- }
138
- for (let invalidation of invalidateOnFileCreate) {
139
- api.invalidateOnFileCreate(invalidation);
140
- }
141
- for (let env of invalidateOnEnvChange) {
142
- api.invalidateOnEnvChange(env);
143
- }
144
- for (let option of invalidateOnOptionChange) {
145
- api.invalidateOnOptionChange(option);
146
- }
147
- if (invalidateOnStartup) {
148
- api.invalidateOnStartup();
149
- }
150
- if (invalidateOnBuild) {
151
- api.invalidateOnBuild();
152
- }
153
- },
154
- input: null
155
- });
156
- }
157
- async function getConfigHash(config, pluginName, options) {
158
- if (config.result == null) {
159
- return '';
160
- }
161
- let hash = new (_rust().Hash)();
162
- hash.writeString(config.id);
163
-
164
- // If there is no result hash set by the transformer, default to hashing the included
165
- // files if any, otherwise try to hash the config result itself.
166
- if (config.cacheKey == null) {
167
- if (config.invalidateOnFileChange.size > 0) {
168
- hash.writeString(await (0, _assetUtils.getInvalidationHash)([...config.invalidateOnFileChange].map(filePath => ({
169
- type: 'file',
170
- filePath
171
- })), options));
172
- } else if (config.result != null) {
173
- try {
174
- hash.writeBuffer((0, _buildCache().serializeRaw)(config.result));
175
- } catch (err) {
176
- throw new (_diagnostic().default)({
177
- diagnostic: {
178
- message: 'Config result is not hashable because it contains non-serializable objects. Please use config.setCacheKey to set the hash manually.',
179
- origin: pluginName
180
- }
181
- });
182
- }
183
- }
184
- } else {
185
- hash.writeString(config.cacheKey ?? '');
186
- }
187
- return hash.finish();
188
- }
189
- function getConfigRequests(configs) {
190
- return configs.filter(config => {
191
- // No need to send to the graph if there are no invalidations.
192
- return config.invalidateOnFileChange.size > 0 || config.invalidateOnConfigKeyChange.length > 0 || config.invalidateOnFileCreate.length > 0 || config.invalidateOnEnvChange.size > 0 || config.invalidateOnOptionChange.size > 0 || config.invalidateOnStartup || config.invalidateOnBuild;
193
- }).map(config => ({
194
- id: config.id,
195
- invalidateOnFileChange: config.invalidateOnFileChange,
196
- invalidateOnConfigKeyChange: config.invalidateOnConfigKeyChange,
197
- invalidateOnFileCreate: config.invalidateOnFileCreate,
198
- invalidateOnEnvChange: config.invalidateOnEnvChange,
199
- invalidateOnOptionChange: config.invalidateOnOptionChange,
200
- invalidateOnStartup: config.invalidateOnStartup,
201
- invalidateOnBuild: config.invalidateOnBuild
202
- }));
203
- }