@atlaspack/core 2.12.1-dev.3450 → 2.12.1-dev.3466

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 (112) hide show
  1. package/lib/AssetGraph.js +5 -1
  2. package/lib/Atlaspack.js +2 -2
  3. package/lib/CommittedAsset.js +11 -5
  4. package/lib/Dependency.js +1 -1
  5. package/lib/PackagerRunner.js +53 -5
  6. package/lib/RequestTracker.js +10 -4
  7. package/lib/SymbolPropagation.js +25 -36
  8. package/lib/UncommittedAsset.js +8 -2
  9. package/lib/assetUtils.js +9 -3
  10. package/lib/atlaspack-v3/fs.js +31 -29
  11. package/lib/atlaspack-v3/index.js +2 -2
  12. package/lib/atlaspack-v3/jsCallable.js +9 -4
  13. package/lib/atlaspack-v3/worker/compat/asset-symbols.js +192 -0
  14. package/lib/atlaspack-v3/worker/compat/bitflags.js +84 -0
  15. package/lib/atlaspack-v3/worker/compat/dependency.js +44 -0
  16. package/lib/atlaspack-v3/worker/compat/environment.js +68 -0
  17. package/lib/atlaspack-v3/worker/compat/index.js +104 -0
  18. package/lib/atlaspack-v3/worker/compat/mutable-asset.js +144 -0
  19. package/lib/atlaspack-v3/worker/compat/plugin-config.js +58 -0
  20. package/lib/atlaspack-v3/worker/compat/plugin-logger.js +29 -0
  21. package/lib/atlaspack-v3/worker/compat/plugin-options.js +113 -0
  22. package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +12 -0
  23. package/lib/atlaspack-v3/worker/compat/target.js +17 -0
  24. package/lib/atlaspack-v3/worker/worker.js +115 -127
  25. package/lib/index.js +0 -43
  26. package/lib/projectPath.js +12 -4
  27. package/lib/registerCoreWithSerializer.js +11 -5
  28. package/lib/requests/AtlaspackConfigRequest.js +8 -2
  29. package/lib/requests/ConfigRequest.js +9 -4
  30. package/lib/requests/DevDepRequest.js +9 -3
  31. package/lib/requests/PathRequest.js +8 -2
  32. package/lib/requests/WriteBundleRequest.js +15 -15
  33. package/lib/worker.js +8 -2
  34. package/package.json +24 -16
  35. package/src/AssetGraph.js +15 -13
  36. package/src/Atlaspack.js +5 -6
  37. package/src/AtlaspackConfig.js +11 -9
  38. package/src/AtlaspackConfig.schema.js +1 -1
  39. package/src/BundleGraph.js +83 -79
  40. package/src/CommittedAsset.js +5 -3
  41. package/src/Dependency.js +1 -1
  42. package/src/PackagerRunner.js +57 -9
  43. package/src/ReporterRunner.js +4 -4
  44. package/src/RequestTracker.js +19 -19
  45. package/src/SymbolPropagation.js +40 -52
  46. package/src/Transformation.js +12 -12
  47. package/src/UncommittedAsset.js +3 -3
  48. package/src/Validation.js +5 -5
  49. package/src/applyRuntimes.js +2 -2
  50. package/src/assetUtils.js +2 -2
  51. package/src/atlaspack-v3/AtlaspackV3.js +1 -1
  52. package/src/atlaspack-v3/fs.js +39 -25
  53. package/src/atlaspack-v3/index.js +1 -1
  54. package/src/atlaspack-v3/jsCallable.js +11 -10
  55. package/src/atlaspack-v3/worker/compat/asset-symbols.js +225 -0
  56. package/src/atlaspack-v3/worker/compat/bitflags.js +100 -0
  57. package/src/atlaspack-v3/worker/compat/dependency.js +83 -0
  58. package/src/atlaspack-v3/worker/compat/environment.js +92 -0
  59. package/src/atlaspack-v3/worker/compat/index.js +10 -0
  60. package/src/atlaspack-v3/worker/compat/mutable-asset.js +184 -0
  61. package/src/atlaspack-v3/worker/compat/plugin-config.js +94 -0
  62. package/src/atlaspack-v3/worker/compat/plugin-logger.js +47 -0
  63. package/src/atlaspack-v3/worker/compat/plugin-options.js +137 -0
  64. package/src/atlaspack-v3/worker/compat/plugin-tracer.js +11 -0
  65. package/src/atlaspack-v3/worker/compat/target.js +27 -0
  66. package/src/atlaspack-v3/worker/worker.js +148 -134
  67. package/src/dumpGraphToGraphViz.js +1 -1
  68. package/src/index.js +0 -10
  69. package/src/loadDotEnv.js +1 -1
  70. package/src/projectPath.js +12 -4
  71. package/src/public/Asset.js +1 -1
  72. package/src/public/Bundle.js +3 -3
  73. package/src/public/BundleGraph.js +20 -20
  74. package/src/public/Config.js +1 -1
  75. package/src/public/MutableBundleGraph.js +8 -8
  76. package/src/registerCoreWithSerializer.js +7 -4
  77. package/src/requests/AssetGraphRequest.js +10 -10
  78. package/src/requests/AssetGraphRequestRust.js +3 -3
  79. package/src/requests/AssetRequest.js +3 -3
  80. package/src/requests/AtlaspackConfigRequest.js +6 -4
  81. package/src/requests/BundleGraphRequest.js +6 -6
  82. package/src/requests/ConfigRequest.js +5 -6
  83. package/src/requests/DevDepRequest.js +8 -8
  84. package/src/requests/EntryRequest.js +2 -2
  85. package/src/requests/PathRequest.js +1 -1
  86. package/src/requests/TargetRequest.js +9 -8
  87. package/src/requests/ValidationRequest.js +2 -2
  88. package/src/requests/WriteBundleRequest.js +26 -20
  89. package/src/requests/WriteBundlesRequest.js +6 -6
  90. package/src/requests/asset-graph-diff.js +4 -4
  91. package/src/resolveOptions.js +3 -3
  92. package/src/serializerCore.browser.js +3 -2
  93. package/src/utils.js +2 -2
  94. package/src/worker.js +1 -1
  95. package/test/AtlaspackConfigRequest.test.js +1 -1
  96. package/test/BundleGraph.test.js +3 -3
  97. package/test/Dependency.test.js +28 -0
  98. package/test/PublicMutableBundleGraph.test.js +2 -2
  99. package/test/RequestTracker.test.js +7 -6
  100. package/test/SymbolPropagation.test.js +9 -9
  101. package/test/requests/ConfigRequest.test.js +3 -6
  102. package/test/utils.test.js +1 -1
  103. package/lib/atlaspack-v3/worker/compat.js +0 -57
  104. package/lib/buildCache.js +0 -18
  105. package/lib/serializer.js +0 -216
  106. package/lib/serializerCore.js +0 -16
  107. package/src/atlaspack-v3/worker/compat.js +0 -82
  108. package/src/buildCache.js +0 -15
  109. package/src/serializer.js +0 -255
  110. package/src/serializerCore.js +0 -5
  111. package/test/requests/WriteBundleRequest.test.js +0 -132
  112. package/test/serializer.test.js +0 -302
package/lib/AssetGraph.js CHANGED
@@ -153,7 +153,11 @@ class AssetGraph extends _graph().ContentGraph {
153
153
  nodes.push(node);
154
154
  }
155
155
  } else if (assetGroups) {
156
- nodes.push(...assetGroups.map(assetGroup => nodeFromAssetGroup(assetGroup)));
156
+ for (const assetGroup of assetGroups) {
157
+ // Adding nodes individually ensures we do not encounter a range stack size exceeded error
158
+ // when there are >100000 asset groups
159
+ nodes.push(nodeFromAssetGroup(assetGroup));
160
+ }
157
161
  }
158
162
  this.replaceNodeIdsConnectedTo((0, _nullthrows().default)(this.rootNodeId), nodes.map(node => this.addNode(node)));
159
163
  }
package/lib/Atlaspack.js CHANGED
@@ -187,7 +187,7 @@ class Atlaspack {
187
187
  threads: process.env.NODE_ENV === 'test' ? 2 : undefined,
188
188
  entries: Array.isArray(entries) ? entries : entries == null ? undefined : [entries],
189
189
  env: resolvedOptions.env,
190
- fs: inputFS && (0, _atlaspackV.toFileSystemV3)(inputFS),
190
+ fs: inputFS && new _atlaspackV.FileSystemV3(inputFS),
191
191
  defaultTargetOptions: {
192
192
  // $FlowFixMe projectPath is just a string
193
193
  distDir: resolvedOptions.defaultTargetOptions.distDir,
@@ -604,6 +604,6 @@ function createWorkerFarm(options = {}) {
604
604
  return new (_workers().default)({
605
605
  ...options,
606
606
  // $FlowFixMe
607
- workerPath: process.browser ? '@atlaspack/core/src/worker.js' : require.resolve('./worker')
607
+ workerPath: process.browser ? '@atlaspack/core/worker' : require.resolve('./worker')
608
608
  });
609
609
  }
@@ -11,9 +11,9 @@ function _stream() {
11
11
  };
12
12
  return data;
13
13
  }
14
- function _sourceMap() {
15
- const data = _interopRequireDefault(require("@parcel/source-map"));
16
- _sourceMap = function () {
14
+ function _buildCache() {
15
+ const data = require("@atlaspack/build-cache");
16
+ _buildCache = function () {
17
17
  return data;
18
18
  };
19
19
  return data;
@@ -25,8 +25,14 @@ function _utils() {
25
25
  };
26
26
  return data;
27
27
  }
28
+ function _sourceMap() {
29
+ const data = _interopRequireDefault(require("@parcel/source-map"));
30
+ _sourceMap = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
28
35
  var _assetUtils = require("./assetUtils");
29
- var _serializer = require("./serializer");
30
36
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
37
  class CommittedAsset {
32
38
  constructor(value, options) {
@@ -122,7 +128,7 @@ class CommittedAsset {
122
128
  return Promise.resolve(null);
123
129
  }
124
130
  if (this.ast == null) {
125
- this.ast = this.options.cache.getBlob(this.value.astKey).then(serializedAst => (0, _serializer.deserializeRaw)(serializedAst));
131
+ this.ast = this.options.cache.getBlob(this.value.astKey).then(serializedAst => (0, _buildCache().deserializeRaw)(serializedAst));
126
132
  }
127
133
  return this.ast;
128
134
  }
package/lib/Dependency.js CHANGED
@@ -40,7 +40,7 @@ function createDependencyId({
40
40
  const params = {
41
41
  sourceAssetId,
42
42
  specifier,
43
- env,
43
+ environmentId: env.id,
44
44
  target,
45
45
  pipeline,
46
46
  specifierType: _types.SpecifierType[specifierType],
@@ -11,6 +11,13 @@ function _assert() {
11
11
  };
12
12
  return data;
13
13
  }
14
+ function _utils() {
15
+ const data = require("@atlaspack/utils");
16
+ _utils = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
14
21
  function _logger() {
15
22
  const data = require("@atlaspack/logger");
16
23
  _logger = function () {
@@ -25,6 +32,13 @@ function _diagnostic() {
25
32
  };
26
33
  return data;
27
34
  }
35
+ function _stream() {
36
+ const data = require("stream");
37
+ _stream = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
28
42
  function _nullthrows() {
29
43
  const data = _interopRequireDefault(require("nullthrows"));
30
44
  _nullthrows = function () {
@@ -62,7 +76,13 @@ var _projectPath = require("./projectPath");
62
76
  var _InternalConfig = require("./InternalConfig");
63
77
  var _ConfigRequest = require("./requests/ConfigRequest");
64
78
  var _DevDepRequest = require("./requests/DevDepRequest");
65
- var _buildCache = require("./buildCache");
79
+ function _buildCache() {
80
+ const data = require("@atlaspack/build-cache");
81
+ _buildCache = function () {
82
+ return data;
83
+ };
84
+ return data;
85
+ }
66
86
  var _assetUtils = require("./assetUtils");
67
87
  var _utils2 = require("./utils");
68
88
  function _profiler() {
@@ -79,7 +99,7 @@ const BOUNDARY_LENGTH = _constants.HASH_REF_PREFIX.length + 32 - 1;
79
99
 
80
100
  // Packager/optimizer configs are not bundle-specific, so we only need to
81
101
  // load them once per build.
82
- const pluginConfigs = (0, _buildCache.createBuildCache)();
102
+ const pluginConfigs = (0, _buildCache().createBuildCache)();
83
103
  class PackagerRunner {
84
104
  constructor({
85
105
  config,
@@ -300,7 +320,7 @@ class PackagerRunner {
300
320
  let bundle = _Bundle.NamedBundle.get(internalBundle, internalBundleGraph, this.options);
301
321
  let bundleGraph = new _BundleGraph.default(internalBundleGraph, _Bundle.NamedBundle.get.bind(_Bundle.NamedBundle), this.options);
302
322
  let optimizers = await this.config.getOptimizers(bundle.name, internalBundle.pipeline);
303
- if (optimizers.length === 0) {
323
+ if (!optimizers.length) {
304
324
  return {
305
325
  type: bundle.type,
306
326
  contents,
@@ -433,13 +453,40 @@ class PackagerRunner {
433
453
  }
434
454
  return devDepHashes;
435
455
  }
456
+ async readFromCache(cacheKey) {
457
+ let contentKey = PackagerRunner.getContentKey(cacheKey);
458
+ let mapKey = PackagerRunner.getMapKey(cacheKey);
459
+ let isLargeBlob = await this.options.cache.hasLargeBlob(contentKey);
460
+ let contentExists = isLargeBlob || (await this.options.cache.has(contentKey));
461
+ if (!contentExists) {
462
+ return null;
463
+ }
464
+ let mapExists = await this.options.cache.has(mapKey);
465
+ return {
466
+ contents: isLargeBlob ? this.options.cache.getStream(contentKey) : (0, _utils().blobToStream)(await this.options.cache.getBlob(contentKey)),
467
+ map: mapExists ? (0, _utils().blobToStream)(await this.options.cache.getBlob(mapKey)) : null
468
+ };
469
+ }
436
470
  async writeToCache(cacheKeys, type, contents, map) {
437
471
  let size = 0;
438
472
  let hash;
439
473
  let hashReferences = [];
474
+ let isLargeBlob = false;
440
475
 
441
476
  // TODO: don't replace hash references in binary files??
442
- if (typeof contents === 'string') {
477
+ if (contents instanceof _stream().Readable) {
478
+ isLargeBlob = true;
479
+ let boundaryStr = '';
480
+ let h = new (_rust().Hash)();
481
+ await this.options.cache.setStream(cacheKeys.content, (0, _utils().blobToStream)(contents).pipe(new (_utils().TapStream)(buf => {
482
+ let str = boundaryStr + buf.toString();
483
+ hashReferences = hashReferences.concat(str.match(_constants.HASH_REF_REGEX) ?? []);
484
+ size += buf.length;
485
+ h.writeBuffer(buf);
486
+ boundaryStr = str.slice(str.length - BOUNDARY_LENGTH);
487
+ })));
488
+ hash = h.finish();
489
+ } else if (typeof contents === 'string') {
443
490
  let buffer = Buffer.from(contents);
444
491
  size = buffer.byteLength;
445
492
  hash = (0, _rust().hashBuffer)(buffer);
@@ -459,7 +506,8 @@ class PackagerRunner {
459
506
  size,
460
507
  hash,
461
508
  hashReferences,
462
- cacheKeys
509
+ cacheKeys,
510
+ isLargeBlob
463
511
  };
464
512
  await this.options.cache.set(cacheKeys.info, info);
465
513
  return info;
@@ -69,7 +69,13 @@ var _constants = require("./constants");
69
69
  var _projectPath = require("./projectPath");
70
70
  var _ReporterRunner = require("./ReporterRunner");
71
71
  var _ConfigRequest = require("./requests/ConfigRequest");
72
- var _serializer = require("./serializer");
72
+ function _buildCache() {
73
+ const data = require("@atlaspack/build-cache");
74
+ _buildCache = function () {
75
+ return data;
76
+ };
77
+ return data;
78
+ }
73
79
  var _utils2 = require("./utils");
74
80
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
75
81
  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); }
@@ -749,7 +755,7 @@ class RequestTracker {
749
755
  } else if (node.resultCacheKey != null && ifMatch == null) {
750
756
  let key = node.resultCacheKey;
751
757
  (0, _assert().default)(this.options.cache.hasLargeBlob(key));
752
- let cachedResult = (0, _serializer.deserialize)(await this.options.cache.getLargeBlob(key));
758
+ let cachedResult = (0, _buildCache().deserialize)(await this.options.cache.getLargeBlob(key));
753
759
  node.result = cachedResult;
754
760
  return cachedResult;
755
761
  }
@@ -927,7 +933,7 @@ class RequestTracker {
927
933
  if (signal !== null && signal !== void 0 && signal.aborted) {
928
934
  throw new Error('Serialization was aborted');
929
935
  }
930
- await this.options.cache.setLargeBlob(key, (0, _serializer.serialize)(contents), signal ? {
936
+ await this.options.cache.setLargeBlob(key, (0, _buildCache().serialize)(contents), signal ? {
931
937
  signal: signal
932
938
  } : undefined);
933
939
  total += 1;
@@ -1046,7 +1052,7 @@ async function readAndDeserializeRequestGraph(cache, requestGraphKey, cacheKey)
1046
1052
  const getAndDeserialize = async key => {
1047
1053
  let buffer = await cache.getLargeBlob(key);
1048
1054
  bufferLength += Buffer.byteLength(buffer);
1049
- return (0, _serializer.deserialize)(buffer);
1055
+ return (0, _buildCache().deserialize)(buffer);
1050
1056
  };
1051
1057
  let serializedRequestGraph = await getAndDeserialize(requestGraphKey);
1052
1058
  let nodePromises = serializedRequestGraph.nodeCountsPerBlob.map(async (nodesCount, i) => {
@@ -438,15 +438,7 @@ function propagateSymbolsDown(assetGraph, changedAssets, assetGroupsWithRemovedP
438
438
  wasNodeDirty = node.usedSymbolsDownDirty;
439
439
  node.usedSymbolsDownDirty = false;
440
440
  } else if (node.type === 'asset' && node.usedSymbolsDownDirty) {
441
- visit(node, assetGraph.getIncomingDependencies(node.value).map(d => {
442
- let dep = assetGraph.getNodeByContentKey(d.id);
443
- (0, _assert().default)(dep && dep.type === 'dependency');
444
- return dep;
445
- }), outgoing.map(dep => {
446
- let depNode = (0, _nullthrows().default)(assetGraph.getNode(dep));
447
- (0, _assert().default)(depNode.type === 'dependency');
448
- return depNode;
449
- }));
441
+ visit(node, incomingDependencyNodesFromAsset(assetGraph, node.value), dependencyNodesFromIds(assetGraph, outgoing));
450
442
  node.usedSymbolsDownDirty = false;
451
443
  }
452
444
  for (let child of outgoing) {
@@ -494,23 +486,15 @@ function propagateSymbolsUp(assetGraph, changedAssets, changedDepsUsedSymbolsUpD
494
486
  let rootNodeId = (0, _nullthrows().default)(assetGraph.rootNodeId, 'A root node is required to traverse');
495
487
  const nodeVisitor = nodeId => {
496
488
  let node = (0, _nullthrows().default)(assetGraph.getNode(nodeId));
497
- let outgoing = assetGraph.getNodeIdsConnectedFrom(nodeId);
498
- for (let childId of outgoing) {
499
- let child = (0, _nullthrows().default)(assetGraph.getNode(childId));
500
- if (node.type === 'asset') {
501
- (0, _assert().default)(child.type === 'dependency');
489
+ if (node.type === 'asset') {
490
+ let outgoing = outgoingDependencyNodesFromAsset(assetGraph, nodeId);
491
+ for (let child of outgoing) {
502
492
  if (child.usedSymbolsUpDirtyUp) {
503
493
  node.usedSymbolsUpDirty = true;
504
494
  child.usedSymbolsUpDirtyUp = false;
505
495
  }
506
496
  }
507
- }
508
- if (node.type === 'asset') {
509
- let incoming = assetGraph.getIncomingDependencies(node.value).map(d => {
510
- let n = assetGraph.getNodeByContentKey(d.id);
511
- (0, _assert().default)(n && n.type === 'dependency');
512
- return n;
513
- });
497
+ let incoming = incomingDependencyNodesFromAsset(assetGraph, node.value);
514
498
  for (let dep of incoming) {
515
499
  if (dep.usedSymbolsUpDirtyDown) {
516
500
  dep.usedSymbolsUpDirtyDown = false;
@@ -518,11 +502,7 @@ function propagateSymbolsUp(assetGraph, changedAssets, changedDepsUsedSymbolsUpD
518
502
  }
519
503
  }
520
504
  if (node.usedSymbolsUpDirty) {
521
- let e = visit(node, incoming, outgoing.map(depNodeId => {
522
- let depNode = (0, _nullthrows().default)(assetGraph.getNode(depNodeId));
523
- (0, _assert().default)(depNode.type === 'dependency');
524
- return depNode;
525
- }));
505
+ let e = visit(node, incoming, outgoing);
526
506
  if (e.length > 0) {
527
507
  node.usedSymbolsUpDirty = true;
528
508
  errors.set(nodeId, e);
@@ -548,22 +528,14 @@ function propagateSymbolsUp(assetGraph, changedAssets, changedDepsUsedSymbolsUpD
548
528
  let queuedNodeId = setPop(queue);
549
529
  let node = (0, _nullthrows().default)(assetGraph.getNode(queuedNodeId));
550
530
  if (node.type === 'asset') {
551
- let incoming = assetGraph.getIncomingDependencies(node.value).map(dep => {
552
- let depNode = assetGraph.getNodeByContentKey(dep.id);
553
- (0, _assert().default)(depNode && depNode.type === 'dependency');
554
- return depNode;
555
- });
531
+ let incoming = incomingDependencyNodesFromAsset(assetGraph, node.value);
556
532
  for (let dep of incoming) {
557
533
  if (dep.usedSymbolsUpDirtyDown) {
558
534
  dep.usedSymbolsUpDirtyDown = false;
559
535
  node.usedSymbolsUpDirty = true;
560
536
  }
561
537
  }
562
- let outgoing = assetGraph.getNodeIdsConnectedFrom(queuedNodeId).map(depNodeId => {
563
- let depNode = (0, _nullthrows().default)(assetGraph.getNode(depNodeId));
564
- (0, _assert().default)(depNode.type === 'dependency');
565
- return depNode;
566
- });
538
+ let outgoing = outgoingDependencyNodesFromAsset(assetGraph, queuedNodeId);
567
539
  for (let dep of outgoing) {
568
540
  if (dep.usedSymbolsUpDirtyUp) {
569
541
  node.usedSymbolsUpDirty = true;
@@ -622,4 +594,21 @@ function setPop(set) {
622
594
  let v = (0, _nullthrows().default)(set.values().next().value);
623
595
  set.delete(v);
624
596
  return v;
597
+ }
598
+ function outgoingDependencyNodesFromAsset(assetGraph, assetNode) {
599
+ return dependencyNodesFromIds(assetGraph, assetGraph.getNodeIdsConnectedFrom(assetNode));
600
+ }
601
+ function dependencyNodesFromIds(assetGraph, dependencyIds) {
602
+ return dependencyIds.map(depNodeId => {
603
+ let depNode = (0, _nullthrows().default)(assetGraph.getNode(depNodeId));
604
+ (0, _assert().default)(depNode.type === 'dependency');
605
+ return depNode;
606
+ });
607
+ }
608
+ function incomingDependencyNodesFromAsset(assetGraph, assetNodeValue) {
609
+ return assetGraph.getIncomingDependencies(assetNodeValue).map(d => {
610
+ let n = assetGraph.getNodeByContentKey(d.id);
611
+ (0, _assert().default)(n && n.type === 'dependency');
612
+ return n;
613
+ });
625
614
  }
@@ -39,7 +39,13 @@ function _rust() {
39
39
  };
40
40
  return data;
41
41
  }
42
- var _serializer = require("./serializer");
42
+ function _buildCache() {
43
+ const data = require("@atlaspack/build-cache");
44
+ _buildCache = function () {
45
+ return data;
46
+ };
47
+ return data;
48
+ }
43
49
  var _Dependency = require("./Dependency");
44
50
  var _Environment = require("./Environment");
45
51
  var _constants = require("./constants");
@@ -88,7 +94,7 @@ class UncommittedAsset {
88
94
 
89
95
  // Since we can only read from the stream once, compute the content length
90
96
  // and hash while it's being written to the cache.
91
- await Promise.all([contentKey != null && this.commitContent(contentKey).then(s => (size = s.size, outputHash = s.hash)), this.mapBuffer != null && mapKey != null && this.options.cache.setBlob(mapKey, this.mapBuffer), astKey != null && this.options.cache.setBlob(astKey, (0, _serializer.serializeRaw)(this.ast))]);
97
+ await Promise.all([contentKey != null && this.commitContent(contentKey).then(s => (size = s.size, outputHash = s.hash)), this.mapBuffer != null && mapKey != null && this.options.cache.setBlob(mapKey, this.mapBuffer), astKey != null && this.options.cache.setBlob(astKey, (0, _buildCache().serializeRaw)(this.ast))]);
92
98
  this.value.contentKey = contentKey;
93
99
  this.value.mapKey = mapKey;
94
100
  this.value.astKey = astKey;
package/lib/assetUtils.js CHANGED
@@ -42,7 +42,13 @@ function _utils() {
42
42
  return data;
43
43
  }
44
44
  var _utils2 = require("./utils");
45
- var _buildCache = require("./buildCache");
45
+ function _buildCache() {
46
+ const data = require("@atlaspack/build-cache");
47
+ _buildCache = function () {
48
+ return data;
49
+ };
50
+ return data;
51
+ }
46
52
  var _projectPath = require("./projectPath");
47
53
  function _rust() {
48
54
  const data = require("@atlaspack/rust");
@@ -62,7 +68,7 @@ function _profiler() {
62
68
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
63
69
  function createAssetIdFromOptions(options) {
64
70
  return (0, _rust().createAssetId)({
65
- env: options.env,
71
+ environmentId: options.env.id,
66
72
  filePath: options.filePath,
67
73
  code: options.code,
68
74
  pipeline: options.pipeline,
@@ -161,7 +167,7 @@ function getInvalidationId(invalidation) {
161
167
  throw new Error('Unknown invalidation type: ' + invalidation.type);
162
168
  }
163
169
  }
164
- const hashCache = (0, _buildCache.createBuildCache)();
170
+ const hashCache = (0, _buildCache().createBuildCache)();
165
171
  async function getInvalidationHash(invalidations, options) {
166
172
  if (invalidations.length === 0) {
167
173
  return '';
@@ -3,35 +3,37 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.toFileSystemV3 = toFileSystemV3;
6
+ exports.FileSystemV3 = void 0;
7
7
  var _jsCallable = require("./jsCallable");
8
- // Move to @atlaspack/utils or a dedicated v3 / migration package later
9
- function toFileSystemV3(fs) {
10
- return {
11
- canonicalize: (0, _jsCallable.jsCallable)(path => fs.realpathSync(path)),
12
- createDirectory: (0, _jsCallable.jsCallable)(path => fs.mkdirp(path)),
13
- cwd: (0, _jsCallable.jsCallable)(() => fs.cwd()),
14
- readFile: (0, _jsCallable.jsCallable)((path, encoding) => {
15
- if (!encoding) {
16
- // $FlowFixMe
17
- return [...fs.readFileSync(path)];
18
- } else {
19
- return fs.readFileSync(path, encoding);
20
- }
21
- }),
22
- isFile: path => {
23
- try {
24
- return fs.statSync(path).isFile();
25
- } catch {
26
- return false;
27
- }
28
- },
29
- isDir: path => {
30
- try {
31
- return fs.statSync(path).isDirectory();
32
- } catch {
33
- return false;
34
- }
8
+ class FileSystemV3 {
9
+ #fs;
10
+ constructor(fs) {
11
+ this.#fs = fs;
12
+ }
13
+ canonicalize = (0, _jsCallable.jsCallable)(path => this.#fs.realpathSync(path));
14
+ createDirectory = (0, _jsCallable.jsCallable)(path => this.#fs.mkdirp(path));
15
+ cwd = (0, _jsCallable.jsCallable)(() => this.#fs.cwd());
16
+ isFile = path => {
17
+ try {
18
+ return this.#fs.statSync(path).isFile();
19
+ } catch {
20
+ return false;
35
21
  }
36
22
  };
37
- }
23
+ isDir = path => {
24
+ try {
25
+ return this.#fs.statSync(path).isDirectory();
26
+ } catch {
27
+ return false;
28
+ }
29
+ };
30
+ readFile = (0, _jsCallable.jsCallable)((path, encoding) => {
31
+ if (!encoding) {
32
+ // $FlowFixMe
33
+ return [...this.#fs.readFileSync(path)];
34
+ } else {
35
+ return this.#fs.readFileSync(path, encoding);
36
+ }
37
+ });
38
+ }
39
+ exports.FileSystemV3 = FileSystemV3;
@@ -9,10 +9,10 @@ Object.defineProperty(exports, "AtlaspackV3", {
9
9
  return _AtlaspackV.AtlaspackV3;
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "toFileSystemV3", {
12
+ Object.defineProperty(exports, "FileSystemV3", {
13
13
  enumerable: true,
14
14
  get: function () {
15
- return _fs.toFileSystemV3;
15
+ return _fs.FileSystemV3;
16
16
  }
17
17
  });
18
18
  var _fs = require("./fs");
@@ -5,11 +5,16 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.jsCallable = jsCallable;
7
7
  function jsCallable(fn) {
8
- return (...args) => {
8
+ return async (...args) => {
9
9
  try {
10
- return fn(...args);
11
- } catch (err) {
12
- return err;
10
+ // $FlowFixMe "await" is needed to log the error from
11
+ // Promises and is safe to use on non-promises
12
+ return await fn(...args);
13
+ // $FlowFixMe
14
+ } catch (error) {
15
+ // eslint-disable-next-line no-console
16
+ console.error(error);
17
+ throw error;
13
18
  }
14
19
  };
15
20
  }