@atlaspack/core 2.13.2-dev.3682 → 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 (87) 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 +24 -8
  5. package/src/loadAtlaspackPlugin.js +26 -71
  6. package/src/projectPath.js +14 -1
  7. package/src/requests/WriteBundlesRequest.js +31 -22
  8. package/LICENSE +0 -201
  9. package/lib/AssetGraph.js +0 -521
  10. package/lib/Atlaspack.js +0 -676
  11. package/lib/AtlaspackConfig.js +0 -298
  12. package/lib/AtlaspackConfig.schema.js +0 -103
  13. package/lib/BundleGraph.js +0 -1527
  14. package/lib/CommittedAsset.js +0 -155
  15. package/lib/Dependency.js +0 -136
  16. package/lib/Environment.js +0 -144
  17. package/lib/IdentifierRegistry.js +0 -36
  18. package/lib/InternalConfig.js +0 -56
  19. package/lib/PackagerRunner.js +0 -525
  20. package/lib/ReporterRunner.js +0 -151
  21. package/lib/RequestTracker.js +0 -1178
  22. package/lib/SymbolPropagation.js +0 -618
  23. package/lib/TargetDescriptor.schema.js +0 -118
  24. package/lib/Transformation.js +0 -522
  25. package/lib/UncommittedAsset.js +0 -348
  26. package/lib/Validation.js +0 -203
  27. package/lib/applyRuntimes.js +0 -355
  28. package/lib/assetUtils.js +0 -205
  29. package/lib/atlaspack-v3/AtlaspackV3.js +0 -57
  30. package/lib/atlaspack-v3/NapiWorkerPool.js +0 -71
  31. package/lib/atlaspack-v3/fs.js +0 -39
  32. package/lib/atlaspack-v3/index.js +0 -26
  33. package/lib/atlaspack-v3/jsCallable.js +0 -20
  34. package/lib/atlaspack-v3/worker/compat/asset-symbols.js +0 -197
  35. package/lib/atlaspack-v3/worker/compat/bitflags.js +0 -84
  36. package/lib/atlaspack-v3/worker/compat/dependency.js +0 -44
  37. package/lib/atlaspack-v3/worker/compat/environment.js +0 -57
  38. package/lib/atlaspack-v3/worker/compat/index.js +0 -104
  39. package/lib/atlaspack-v3/worker/compat/mutable-asset.js +0 -164
  40. package/lib/atlaspack-v3/worker/compat/plugin-config.js +0 -78
  41. package/lib/atlaspack-v3/worker/compat/plugin-logger.js +0 -29
  42. package/lib/atlaspack-v3/worker/compat/plugin-options.js +0 -113
  43. package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +0 -12
  44. package/lib/atlaspack-v3/worker/compat/target.js +0 -17
  45. package/lib/atlaspack-v3/worker/index.js +0 -3
  46. package/lib/atlaspack-v3/worker/worker.js +0 -280
  47. package/lib/constants.js +0 -21
  48. package/lib/dumpGraphToGraphViz.js +0 -206
  49. package/lib/index.js +0 -70
  50. package/lib/loadAtlaspackPlugin.js +0 -136
  51. package/lib/loadDotEnv.js +0 -54
  52. package/lib/projectPath.js +0 -94
  53. package/lib/public/Asset.js +0 -259
  54. package/lib/public/Bundle.js +0 -236
  55. package/lib/public/BundleGraph.js +0 -279
  56. package/lib/public/BundleGroup.js +0 -50
  57. package/lib/public/Config.js +0 -202
  58. package/lib/public/Dependency.js +0 -131
  59. package/lib/public/Environment.js +0 -247
  60. package/lib/public/MutableBundleGraph.js +0 -204
  61. package/lib/public/PluginOptions.js +0 -71
  62. package/lib/public/Symbols.js +0 -247
  63. package/lib/public/Target.js +0 -64
  64. package/lib/registerCoreWithSerializer.js +0 -51
  65. package/lib/requests/AssetGraphRequest.js +0 -432
  66. package/lib/requests/AssetGraphRequestRust.js +0 -220
  67. package/lib/requests/AssetRequest.js +0 -132
  68. package/lib/requests/AtlaspackBuildRequest.js +0 -79
  69. package/lib/requests/AtlaspackConfigRequest.js +0 -479
  70. package/lib/requests/BundleGraphRequest.js +0 -485
  71. package/lib/requests/ConfigRequest.js +0 -203
  72. package/lib/requests/DevDepRequest.js +0 -193
  73. package/lib/requests/EntryRequest.js +0 -295
  74. package/lib/requests/PackageRequest.js +0 -88
  75. package/lib/requests/PathRequest.js +0 -357
  76. package/lib/requests/TargetRequest.js +0 -1179
  77. package/lib/requests/ValidationRequest.js +0 -66
  78. package/lib/requests/WriteBundleRequest.js +0 -252
  79. package/lib/requests/WriteBundlesRequest.js +0 -153
  80. package/lib/requests/asset-graph-diff.js +0 -128
  81. package/lib/requests/asset-graph-dot.js +0 -131
  82. package/lib/resolveOptions.js +0 -265
  83. package/lib/serializerCore.browser.js +0 -29
  84. package/lib/summarizeRequest.js +0 -55
  85. package/lib/types.js +0 -35
  86. package/lib/utils.js +0 -160
  87. package/lib/worker.js +0 -184
package/lib/Atlaspack.js DELETED
@@ -1,676 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.INTERNAL_TRANSFORM = exports.INTERNAL_RESOLVE = exports.BuildError = void 0;
7
- exports.createWorkerFarm = createWorkerFarm;
8
- exports.default = void 0;
9
- function _path() {
10
- const data = _interopRequireDefault(require("path"));
11
- _path = function () {
12
- return data;
13
- };
14
- return data;
15
- }
16
- function _assert() {
17
- const data = _interopRequireDefault(require("assert"));
18
- _assert = function () {
19
- return data;
20
- };
21
- return data;
22
- }
23
- function _diagnostic() {
24
- const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
25
- _diagnostic = function () {
26
- return data;
27
- };
28
- return data;
29
- }
30
- var _Asset = require("./public/Asset");
31
- var _Bundle = require("./public/Bundle");
32
- var _BundleGraph = _interopRequireDefault(require("./public/BundleGraph"));
33
- function _workers() {
34
- const data = _interopRequireDefault(require("@atlaspack/workers"));
35
- _workers = function () {
36
- return data;
37
- };
38
- return data;
39
- }
40
- function _nullthrows() {
41
- const data = _interopRequireDefault(require("nullthrows"));
42
- _nullthrows = function () {
43
- return data;
44
- };
45
- return data;
46
- }
47
- var _utils = require("./utils");
48
- var _AtlaspackConfigRequest = require("./requests/AtlaspackConfigRequest");
49
- var _ReporterRunner = _interopRequireDefault(require("./ReporterRunner"));
50
- var _dumpGraphToGraphViz = _interopRequireDefault(require("./dumpGraphToGraphViz"));
51
- var _resolveOptions = _interopRequireDefault(require("./resolveOptions"));
52
- function _events() {
53
- const data = require("@atlaspack/events");
54
- _events = function () {
55
- return data;
56
- };
57
- return data;
58
- }
59
- var _registerCoreWithSerializer = require("./registerCoreWithSerializer");
60
- function _utils2() {
61
- const data = require("@atlaspack/utils");
62
- _utils2 = function () {
63
- return data;
64
- };
65
- return data;
66
- }
67
- var _AtlaspackConfig = require("./AtlaspackConfig");
68
- function _logger() {
69
- const data = _interopRequireDefault(require("@atlaspack/logger"));
70
- _logger = function () {
71
- return data;
72
- };
73
- return data;
74
- }
75
- var _RequestTracker = _interopRequireWildcard(require("./RequestTracker"));
76
- var _ValidationRequest = _interopRequireDefault(require("./requests/ValidationRequest"));
77
- var _AtlaspackBuildRequest = _interopRequireDefault(require("./requests/AtlaspackBuildRequest"));
78
- var _AssetRequest = _interopRequireDefault(require("./requests/AssetRequest"));
79
- var _PathRequest = _interopRequireDefault(require("./requests/PathRequest"));
80
- var _Environment = require("./Environment");
81
- var _Dependency = require("./Dependency");
82
- function _sourceMap() {
83
- const data = require("@parcel/source-map");
84
- _sourceMap = function () {
85
- return data;
86
- };
87
- return data;
88
- }
89
- function _cache() {
90
- const data = require("@atlaspack/cache");
91
- _cache = function () {
92
- return data;
93
- };
94
- return data;
95
- }
96
- function _rust() {
97
- const data = require("@atlaspack/rust");
98
- _rust = function () {
99
- return data;
100
- };
101
- return data;
102
- }
103
- var _projectPath = require("./projectPath");
104
- function _profiler() {
105
- const data = require("@atlaspack/profiler");
106
- _profiler = function () {
107
- return data;
108
- };
109
- return data;
110
- }
111
- function _featureFlags() {
112
- const data = require("@atlaspack/feature-flags");
113
- _featureFlags = function () {
114
- return data;
115
- };
116
- return data;
117
- }
118
- var _atlaspackV = require("./atlaspack-v3");
119
- var _AssetGraphRequest = _interopRequireDefault(require("./requests/AssetGraphRequest"));
120
- var _AssetGraphRequestRust = require("./requests/AssetGraphRequestRust");
121
- 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); }
122
- 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; }
123
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
124
- // eslint-disable-next-line no-unused-vars
125
- (0, _registerCoreWithSerializer.registerCoreWithSerializer)();
126
- const INTERNAL_TRANSFORM = exports.INTERNAL_TRANSFORM = Symbol('internal_transform');
127
- const INTERNAL_RESOLVE = exports.INTERNAL_RESOLVE = Symbol('internal_resolve');
128
- class Atlaspack {
129
- #requestTracker /*: RequestTracker*/;
130
- #config /*: AtlaspackConfig*/;
131
- #farm /*: WorkerFarm*/;
132
- #initialized /*: boolean*/ = false;
133
- #disposable /*: Disposable */;
134
- #initialOptions /*: InitialAtlaspackOptions */;
135
- #reporterRunner /*: ReporterRunner*/;
136
- #resolvedOptions /*: ?AtlaspackOptions*/ = null;
137
- #optionsRef /*: SharedReference */;
138
- #watchAbortController /*: AbortController*/;
139
- #watchQueue /*: PromiseQueue<?BuildEvent>*/ = new (_utils2().PromiseQueue)({
140
- maxConcurrent: 1
141
- });
142
- #watchEvents /*: ValueEmitter<
143
- | {|
144
- +error: Error,
145
- +buildEvent?: void,
146
- |}
147
- | {|
148
- +buildEvent: BuildEvent,
149
- +error?: void,
150
- |},
151
- > */;
152
- #watcherSubscription /*: ?AsyncSubscription*/;
153
- #watcherCount /*: number*/ = 0;
154
- #requestedAssetIds /*: Set<string>*/ = new Set();
155
- constructor(options) {
156
- this.#initialOptions = options;
157
- }
158
- async _init() {
159
- if (this.#initialized) {
160
- return;
161
- }
162
- const featureFlags = {
163
- ..._featureFlags().DEFAULT_FEATURE_FLAGS,
164
- ...this.#initialOptions.featureFlags
165
- };
166
- (0, _featureFlags().setFeatureFlags)(featureFlags);
167
- await _sourceMap().init;
168
- await (_rust().init === null || _rust().init === void 0 ? void 0 : (0, _rust().init)());
169
- this.#disposable = new (_events().Disposable)();
170
- try {
171
- _rust().initializeMonitoring === null || _rust().initializeMonitoring === void 0 || (0, _rust().initializeMonitoring)();
172
- const onExit = () => {
173
- _rust().closeMonitoring === null || _rust().closeMonitoring === void 0 || (0, _rust().closeMonitoring)();
174
- };
175
- process.on('exit', onExit);
176
- this.#disposable.add(() => {
177
- process.off('exit', onExit);
178
- onExit();
179
- });
180
- } catch (e) {
181
- // Fallthrough
182
- // eslint-disable-next-line no-console
183
- console.warn(e);
184
- }
185
- let resolvedOptions = await (0, _resolveOptions.default)({
186
- ...this.#initialOptions,
187
- featureFlags
188
- });
189
- this.#resolvedOptions = resolvedOptions;
190
- let rustAtlaspack;
191
- if (resolvedOptions.featureFlags.atlaspackV3) {
192
- // eslint-disable-next-line no-unused-vars
193
- let {
194
- entries,
195
- inputFS,
196
- outputFS,
197
- ...options
198
- } = this.#initialOptions;
199
- if (!(resolvedOptions.cache instanceof _cache().LMDBLiteCache)) {
200
- throw new Error('Atlaspack v3 must be run with lmdb lite cache');
201
- }
202
- const lmdb = resolvedOptions.cache.getNativeRef();
203
-
204
- // $FlowFixMe
205
- const version = require('../package.json').version;
206
- await lmdb.put('current_session_version', Buffer.from(version));
207
- rustAtlaspack = new _atlaspackV.AtlaspackV3({
208
- ...options,
209
- corePath: _path().default.join(__dirname, '..'),
210
- threads: process.env.NODE_ENV === 'test' ? 2 : undefined,
211
- entries: Array.isArray(entries) ? entries : entries == null ? undefined : [entries],
212
- env: resolvedOptions.env,
213
- fs: inputFS && new _atlaspackV.FileSystemV3(inputFS),
214
- // $FlowFixMe ProjectPath is a string
215
- defaultTargetOptions: resolvedOptions.defaultTargetOptions,
216
- lmdb
217
- });
218
- }
219
- this.rustAtlaspack = rustAtlaspack;
220
- let {
221
- config
222
- } = await (0, _AtlaspackConfigRequest.loadAtlaspackConfig)(resolvedOptions);
223
- this.#config = new _AtlaspackConfig.AtlaspackConfig(config, resolvedOptions);
224
- if (this.#initialOptions.workerFarm) {
225
- if (this.#initialOptions.workerFarm.ending) {
226
- throw new Error('Supplied WorkerFarm is ending');
227
- }
228
- this.#farm = this.#initialOptions.workerFarm;
229
- } else {
230
- this.#farm = createWorkerFarm({
231
- shouldPatchConsole: resolvedOptions.shouldPatchConsole,
232
- shouldTrace: resolvedOptions.shouldTrace
233
- });
234
- }
235
- await resolvedOptions.cache.ensure();
236
- let {
237
- dispose: disposeOptions,
238
- ref: optionsRef
239
- } = await this.#farm.createSharedReference(resolvedOptions, false);
240
- this.#optionsRef = optionsRef;
241
- if (this.#initialOptions.workerFarm) {
242
- // If we don't own the farm, dispose of only these references when
243
- // Atlaspack ends.
244
- this.#disposable.add(disposeOptions);
245
- } else {
246
- // Otherwise, when shutting down, end the entire farm we created.
247
- this.#disposable.add(() => this.#farm.end());
248
- }
249
- this.#watchEvents = new (_events().ValueEmitter)();
250
- this.#disposable.add(() => this.#watchEvents.dispose());
251
- this.#reporterRunner = new _ReporterRunner.default({
252
- options: resolvedOptions,
253
- reporters: await this.#config.getReporters(),
254
- workerFarm: this.#farm
255
- });
256
- this.#disposable.add(this.#reporterRunner);
257
- _logger().default.verbose({
258
- origin: '@atlaspack/core',
259
- message: 'Intializing request tracker...'
260
- });
261
- this.#requestTracker = await _RequestTracker.default.init({
262
- farm: this.#farm,
263
- options: resolvedOptions,
264
- rustAtlaspack
265
- });
266
- this.#initialized = true;
267
- }
268
- async run() {
269
- let startTime = Date.now();
270
- if (!this.#initialized) {
271
- await this._init();
272
- }
273
- let result = await this._build({
274
- startTime
275
- });
276
- await this.#requestTracker.writeToCache();
277
- await this._end();
278
- if (result.type === 'buildFailure') {
279
- throw new BuildError(result.diagnostics);
280
- }
281
- return result;
282
- }
283
- async _end() {
284
- this.#initialized = false;
285
- await this.#disposable.dispose();
286
- }
287
- async writeRequestTrackerToCache() {
288
- if (this.#watchQueue.getNumWaiting() === 0) {
289
- // If there's no queued events, we are safe to write the request graph to disk
290
- const abortController = new AbortController();
291
- const unsubscribe = this.#watchQueue.subscribeToAdd(() => {
292
- abortController.abort();
293
- });
294
- try {
295
- await this.#requestTracker.writeToCache(abortController.signal);
296
- } catch (err) {
297
- if (!abortController.signal.aborted) {
298
- // We expect abort errors if we interrupt the cache write
299
- throw err;
300
- }
301
- }
302
- unsubscribe();
303
- }
304
- }
305
- async _startNextBuild() {
306
- this.#watchAbortController = new AbortController();
307
- await this.clearBuildCaches();
308
- try {
309
- let buildEvent = await this._build({
310
- signal: this.#watchAbortController.signal
311
- });
312
- this.#watchEvents.emit({
313
- buildEvent
314
- });
315
- return buildEvent;
316
- } catch (err) {
317
- // Ignore BuildAbortErrors and only emit critical errors.
318
- if (!(err instanceof _utils.BuildAbortError)) {
319
- throw err;
320
- }
321
- } finally {
322
- // If the build passes or fails, we want to cache the request graph
323
- await this.writeRequestTrackerToCache();
324
- }
325
- }
326
- async watch(cb) {
327
- if (!this.#initialized) {
328
- await this._init();
329
- }
330
- let watchEventsDisposable;
331
- if (cb) {
332
- watchEventsDisposable = this.#watchEvents.addListener(({
333
- error,
334
- buildEvent
335
- }) => cb(error, buildEvent));
336
- }
337
- if (this.#watcherCount === 0) {
338
- this.#watcherSubscription = await this._getWatcherSubscription();
339
- await this.#reporterRunner.report({
340
- type: 'watchStart'
341
- });
342
-
343
- // Kick off a first build, but don't await its results. Its results will
344
- // be provided to the callback.
345
- this.#watchQueue.add(() => this._startNextBuild());
346
- this.#watchQueue.run();
347
- }
348
- this.#watcherCount++;
349
- let unsubscribePromise;
350
- const unsubscribe = async () => {
351
- if (watchEventsDisposable) {
352
- watchEventsDisposable.dispose();
353
- }
354
- this.#watcherCount--;
355
- if (this.#watcherCount === 0) {
356
- await (0, _nullthrows().default)(this.#watcherSubscription).unsubscribe();
357
- this.#watcherSubscription = null;
358
- await this.#reporterRunner.report({
359
- type: 'watchEnd'
360
- });
361
- this.#watchAbortController.abort();
362
- await this.#watchQueue.run();
363
- await this._end();
364
- }
365
- };
366
- return {
367
- unsubscribe() {
368
- if (unsubscribePromise == null) {
369
- unsubscribePromise = unsubscribe();
370
- }
371
- return unsubscribePromise;
372
- }
373
- };
374
- }
375
- async _build({
376
- signal,
377
- startTime = Date.now()
378
- } = {
379
- /*::...null*/
380
- }) {
381
- this.#requestTracker.setSignal(signal);
382
- let options = (0, _nullthrows().default)(this.#resolvedOptions);
383
- try {
384
- if (options.shouldProfile) {
385
- await this.startProfiling();
386
- }
387
- if (options.shouldTrace) {
388
- _profiler().tracer.enable();
389
- }
390
- await this.#reporterRunner.report({
391
- type: 'buildStart'
392
- });
393
- this.#requestTracker.graph.invalidateOnBuildNodes();
394
- let request = (0, _AtlaspackBuildRequest.default)({
395
- optionsRef: this.#optionsRef,
396
- requestedAssetIds: this.#requestedAssetIds,
397
- signal
398
- });
399
- let {
400
- bundleGraph,
401
- bundleInfo,
402
- changedAssets,
403
- assetRequests
404
- } = await this.#requestTracker.runRequest(request, {
405
- force: true
406
- });
407
- this.#requestedAssetIds.clear();
408
- await (0, _dumpGraphToGraphViz.default)(
409
- // $FlowFixMe
410
- this.#requestTracker.graph, 'RequestGraph', _RequestTracker.requestGraphEdgeTypes);
411
- let event = {
412
- type: 'buildSuccess',
413
- changedAssets: new Map(Array.from(changedAssets).map(([id, asset]) => [id, (0, _Asset.assetFromValue)(asset, options)])),
414
- bundleGraph: new _BundleGraph.default(bundleGraph, (bundle, bundleGraph, options) => _Bundle.PackagedBundle.getWithInfo(bundle, bundleGraph, options, bundleInfo.get(bundle.id)), options),
415
- buildTime: Date.now() - startTime,
416
- requestBundle: async bundle => {
417
- let bundleNode = bundleGraph._graph.getNodeByContentKey(bundle.id);
418
- (0, _assert().default)((bundleNode === null || bundleNode === void 0 ? void 0 : bundleNode.type) === 'bundle', 'Bundle does not exist');
419
- if (!bundleNode.value.isPlaceholder) {
420
- // Nothing to do.
421
- return {
422
- type: 'buildSuccess',
423
- changedAssets: new Map(),
424
- bundleGraph: event.bundleGraph,
425
- buildTime: 0,
426
- requestBundle: event.requestBundle,
427
- unstable_requestStats: {}
428
- };
429
- }
430
- for (let assetId of bundleNode.value.entryAssetIds) {
431
- this.#requestedAssetIds.add(assetId);
432
- }
433
- if (this.#watchQueue.getNumWaiting() === 0) {
434
- if (this.#watchAbortController) {
435
- this.#watchAbortController.abort();
436
- }
437
- this.#watchQueue.add(() => this._startNextBuild());
438
- }
439
- let results = await this.#watchQueue.run();
440
- let result = results.filter(Boolean).pop();
441
- if (result.type === 'buildFailure') {
442
- throw new BuildError(result.diagnostics);
443
- }
444
- return result;
445
- },
446
- unstable_requestStats: this.#requestTracker.flushStats()
447
- };
448
- await this.#reporterRunner.report(event);
449
- await this.#requestTracker.runRequest((0, _ValidationRequest.default)({
450
- optionsRef: this.#optionsRef,
451
- assetRequests
452
- }), {
453
- force: assetRequests.length > 0
454
- });
455
- if (this.#reporterRunner.errors.length) {
456
- throw this.#reporterRunner.errors;
457
- }
458
- return event;
459
- } catch (e) {
460
- if (e instanceof _utils.BuildAbortError) {
461
- throw e;
462
- }
463
- let diagnostic = (0, _diagnostic().anyToDiagnostic)(e);
464
- let event = {
465
- type: 'buildFailure',
466
- diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic],
467
- unstable_requestStats: this.#requestTracker.flushStats()
468
- };
469
- await this.#reporterRunner.report(event);
470
- return event;
471
- } finally {
472
- if (this.isProfiling) {
473
- await this.stopProfiling();
474
- }
475
- await this.clearBuildCaches();
476
- }
477
- }
478
- async _getWatcherSubscription() {
479
- (0, _assert().default)(this.#watcherSubscription == null);
480
- let resolvedOptions = (0, _nullthrows().default)(this.#resolvedOptions);
481
- let opts = (0, _RequestTracker.getWatcherOptions)(resolvedOptions);
482
- let sub = await resolvedOptions.inputFS.watch(resolvedOptions.watchDir, async (err, events) => {
483
- var _events$, _events$2;
484
- if (err) {
485
- _logger().default.warn({
486
- message: `File watch event error occured`,
487
- meta: {
488
- err,
489
- trackableEvent: 'watcher_error'
490
- }
491
- });
492
- this.#watchEvents.emit({
493
- error: err
494
- });
495
- return;
496
- }
497
- _logger().default.verbose({
498
- message: `File watch event emitted with ${events.length} events. Sample event: [${(_events$ = events[0]) === null || _events$ === void 0 ? void 0 : _events$.type}] ${(_events$2 = events[0]) === null || _events$2 === void 0 ? void 0 : _events$2.path}`
499
- });
500
- let nativeInvalid = false;
501
- if (this.rustAtlaspack) {
502
- nativeInvalid = await this.rustAtlaspack.respondToFsEvents(events);
503
- }
504
- let isInvalid = await this.#requestTracker.respondToFSEvents(events, Number.POSITIVE_INFINITY);
505
- if ((nativeInvalid || isInvalid) && this.#watchQueue.getNumWaiting() === 0) {
506
- if (this.#watchAbortController) {
507
- this.#watchAbortController.abort();
508
- }
509
- this.#watchQueue.add(() => this._startNextBuild());
510
- this.#watchQueue.run();
511
- }
512
- }, opts);
513
- return {
514
- unsubscribe: () => sub.unsubscribe()
515
- };
516
- }
517
-
518
- // This is mainly for integration tests and it not public api!
519
- _getResolvedAtlaspackOptions() {
520
- return (0, _nullthrows().default)(this.#resolvedOptions, 'Resolved options is null, please let atlaspack initialize before accessing this.');
521
- }
522
- async startProfiling() {
523
- if (this.isProfiling) {
524
- throw new Error('Atlaspack is already profiling');
525
- }
526
- _logger().default.info({
527
- origin: '@atlaspack/core',
528
- message: 'Starting profiling...'
529
- });
530
- this.isProfiling = true;
531
- await this.#farm.startProfile();
532
- }
533
- stopProfiling() {
534
- if (!this.isProfiling) {
535
- throw new Error('Atlaspack is not profiling');
536
- }
537
- _logger().default.info({
538
- origin: '@atlaspack/core',
539
- message: 'Stopping profiling...'
540
- });
541
- this.isProfiling = false;
542
- return this.#farm.endProfile();
543
- }
544
- takeHeapSnapshot() {
545
- _logger().default.info({
546
- origin: '@atlaspack/core',
547
- message: 'Taking heap snapshot...'
548
- });
549
- return this.#farm.takeHeapSnapshot();
550
- }
551
-
552
- /**
553
- * Must be called between builds otherwise there is global state that will
554
- * break things unexpectedly.
555
- */
556
- async clearBuildCaches() {
557
- var _this$farm;
558
- await ((_this$farm = this.#farm) === null || _this$farm === void 0 ? void 0 : _this$farm.callAllWorkers('clearWorkerBuildCaches', []));
559
- }
560
- async unstable_invalidate() {
561
- await this._init();
562
- }
563
-
564
- /**
565
- * Build the asset graph
566
- */
567
- async unstable_buildAssetGraph(writeToCache = true) {
568
- await this._init();
569
- const origin = '@atlaspack/core';
570
- const input = {
571
- optionsRef: this.#optionsRef,
572
- name: 'Main',
573
- entries: this.#config.options.entries,
574
- shouldBuildLazily: false,
575
- lazyIncludes: [],
576
- lazyExcludes: [],
577
- requestedAssetIds: this.#requestedAssetIds
578
- };
579
- const start = Date.now();
580
- const result = await this.#requestTracker.runRequest(this.rustAtlaspack != null ? (0, _AssetGraphRequestRust.createAssetGraphRequestRust)(this.rustAtlaspack)(input) : (0, _AssetGraphRequest.default)(input), {
581
- force: true
582
- });
583
- const duration = Date.now() - start;
584
- _logger().default.info({
585
- message: `Done building asset graph in ${duration / 1000}s!`,
586
- origin
587
- });
588
- if (writeToCache) {
589
- _logger().default.info({
590
- message: 'Write request tracker to cache',
591
- origin
592
- });
593
- await this.writeRequestTrackerToCache();
594
- _logger().default.info({
595
- message: 'Done writing request tracker to cache',
596
- origin
597
- });
598
- }
599
- return result;
600
- }
601
- async unstable_transform(options) {
602
- var _options$env;
603
- if (!this.#initialized) {
604
- await this._init();
605
- }
606
- let projectRoot = (0, _nullthrows().default)(this.#resolvedOptions).projectRoot;
607
- let request = (0, _AssetRequest.default)({
608
- ...options,
609
- filePath: (0, _projectPath.toProjectPath)(projectRoot, options.filePath),
610
- optionsRef: this.#optionsRef,
611
- env: (0, _Environment.createEnvironment)({
612
- ...options.env,
613
- loc: ((_options$env = options.env) === null || _options$env === void 0 ? void 0 : _options$env.loc) != null ? {
614
- ...options.env.loc,
615
- filePath: (0, _projectPath.toProjectPath)(projectRoot, options.env.loc.filePath)
616
- } : undefined
617
- })
618
- });
619
- let res = await this.#requestTracker.runRequest(request, {
620
- force: true
621
- });
622
- return res.map(asset => (0, _Asset.assetFromValue)(asset, (0, _nullthrows().default)(this.#resolvedOptions)));
623
- }
624
- async unstable_resolve(request) {
625
- var _request$env;
626
- if (!this.#initialized) {
627
- await this._init();
628
- }
629
- let projectRoot = (0, _nullthrows().default)(this.#resolvedOptions).projectRoot;
630
- if (request.resolveFrom == null && _path().default.isAbsolute(request.specifier)) {
631
- request.specifier = (0, _projectPath.fromProjectPathRelative)((0, _projectPath.toProjectPath)(projectRoot, request.specifier));
632
- }
633
- let dependency = (0, _Dependency.createDependency)(projectRoot, {
634
- ...request,
635
- env: (0, _Environment.createEnvironment)({
636
- ...request.env,
637
- loc: ((_request$env = request.env) === null || _request$env === void 0 ? void 0 : _request$env.loc) != null ? {
638
- ...request.env.loc,
639
- filePath: (0, _projectPath.toProjectPath)(projectRoot, request.env.loc.filePath)
640
- } : undefined
641
- })
642
- });
643
- let req = (0, _PathRequest.default)({
644
- dependency,
645
- name: request.specifier
646
- });
647
- let res = await this.#requestTracker.runRequest(req, {
648
- force: true
649
- });
650
- if (!res) {
651
- return null;
652
- }
653
- return {
654
- filePath: (0, _projectPath.fromProjectPath)(projectRoot, res.filePath),
655
- code: res.code,
656
- query: res.query,
657
- sideEffects: res.sideEffects
658
- };
659
- }
660
- }
661
- exports.default = Atlaspack;
662
- class BuildError extends _diagnostic().default {
663
- constructor(diagnostic) {
664
- super({
665
- diagnostic
666
- });
667
- this.name = 'BuildError';
668
- }
669
- }
670
- exports.BuildError = BuildError;
671
- function createWorkerFarm(options = {}) {
672
- return new (_workers().default)({
673
- ...options,
674
- workerPath: require.resolve('./worker')
675
- });
676
- }