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

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 (94) hide show
  1. package/lib/AssetGraph.js +5 -1
  2. package/lib/Atlaspack.js +2 -2
  3. package/lib/Dependency.js +1 -1
  4. package/lib/PackagerRunner.js +45 -3
  5. package/lib/SymbolPropagation.js +25 -36
  6. package/lib/assetUtils.js +1 -1
  7. package/lib/atlaspack-v3/fs.js +31 -29
  8. package/lib/atlaspack-v3/index.js +2 -2
  9. package/lib/atlaspack-v3/jsCallable.js +9 -4
  10. package/lib/atlaspack-v3/worker/compat/asset-symbols.js +192 -0
  11. package/lib/atlaspack-v3/worker/compat/bitflags.js +84 -0
  12. package/lib/atlaspack-v3/worker/compat/dependency.js +44 -0
  13. package/lib/atlaspack-v3/worker/compat/environment.js +68 -0
  14. package/lib/atlaspack-v3/worker/compat/index.js +104 -0
  15. package/lib/atlaspack-v3/worker/compat/mutable-asset.js +144 -0
  16. package/lib/atlaspack-v3/worker/compat/plugin-config.js +58 -0
  17. package/lib/atlaspack-v3/worker/compat/plugin-logger.js +29 -0
  18. package/lib/atlaspack-v3/worker/compat/plugin-options.js +113 -0
  19. package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +12 -0
  20. package/lib/atlaspack-v3/worker/compat/target.js +17 -0
  21. package/lib/atlaspack-v3/worker/worker.js +115 -127
  22. package/lib/projectPath.js +12 -4
  23. package/lib/requests/ConfigRequest.js +1 -1
  24. package/lib/requests/WriteBundleRequest.js +15 -15
  25. package/package.json +23 -16
  26. package/src/AssetGraph.js +15 -13
  27. package/src/Atlaspack.js +5 -6
  28. package/src/AtlaspackConfig.js +11 -9
  29. package/src/AtlaspackConfig.schema.js +1 -1
  30. package/src/BundleGraph.js +83 -79
  31. package/src/CommittedAsset.js +1 -1
  32. package/src/Dependency.js +1 -1
  33. package/src/PackagerRunner.js +56 -8
  34. package/src/ReporterRunner.js +4 -4
  35. package/src/RequestTracker.js +18 -18
  36. package/src/SymbolPropagation.js +40 -52
  37. package/src/Transformation.js +12 -12
  38. package/src/UncommittedAsset.js +2 -2
  39. package/src/Validation.js +5 -5
  40. package/src/applyRuntimes.js +2 -2
  41. package/src/assetUtils.js +1 -1
  42. package/src/atlaspack-v3/AtlaspackV3.js +1 -1
  43. package/src/atlaspack-v3/fs.js +39 -25
  44. package/src/atlaspack-v3/index.js +1 -1
  45. package/src/atlaspack-v3/jsCallable.js +11 -10
  46. package/src/atlaspack-v3/worker/compat/asset-symbols.js +225 -0
  47. package/src/atlaspack-v3/worker/compat/bitflags.js +100 -0
  48. package/src/atlaspack-v3/worker/compat/dependency.js +83 -0
  49. package/src/atlaspack-v3/worker/compat/environment.js +92 -0
  50. package/src/atlaspack-v3/worker/compat/index.js +10 -0
  51. package/src/atlaspack-v3/worker/compat/mutable-asset.js +184 -0
  52. package/src/atlaspack-v3/worker/compat/plugin-config.js +94 -0
  53. package/src/atlaspack-v3/worker/compat/plugin-logger.js +47 -0
  54. package/src/atlaspack-v3/worker/compat/plugin-options.js +137 -0
  55. package/src/atlaspack-v3/worker/compat/plugin-tracer.js +11 -0
  56. package/src/atlaspack-v3/worker/compat/target.js +27 -0
  57. package/src/atlaspack-v3/worker/worker.js +148 -134
  58. package/src/dumpGraphToGraphViz.js +1 -1
  59. package/src/loadDotEnv.js +1 -1
  60. package/src/projectPath.js +12 -4
  61. package/src/public/Asset.js +1 -1
  62. package/src/public/Bundle.js +3 -3
  63. package/src/public/BundleGraph.js +20 -20
  64. package/src/public/Config.js +1 -1
  65. package/src/public/MutableBundleGraph.js +8 -8
  66. package/src/requests/AssetGraphRequest.js +10 -10
  67. package/src/requests/AssetGraphRequestRust.js +3 -3
  68. package/src/requests/AssetRequest.js +3 -3
  69. package/src/requests/AtlaspackConfigRequest.js +5 -3
  70. package/src/requests/BundleGraphRequest.js +6 -6
  71. package/src/requests/ConfigRequest.js +5 -5
  72. package/src/requests/DevDepRequest.js +7 -7
  73. package/src/requests/EntryRequest.js +2 -2
  74. package/src/requests/TargetRequest.js +9 -8
  75. package/src/requests/ValidationRequest.js +2 -2
  76. package/src/requests/WriteBundleRequest.js +26 -20
  77. package/src/requests/WriteBundlesRequest.js +6 -6
  78. package/src/requests/asset-graph-diff.js +4 -4
  79. package/src/resolveOptions.js +3 -3
  80. package/src/serializer.js +2 -2
  81. package/src/serializerCore.browser.js +3 -2
  82. package/src/serializerCore.js +2 -2
  83. package/src/utils.js +2 -2
  84. package/test/AtlaspackConfigRequest.test.js +1 -1
  85. package/test/BundleGraph.test.js +3 -3
  86. package/test/Dependency.test.js +28 -0
  87. package/test/PublicMutableBundleGraph.test.js +2 -2
  88. package/test/RequestTracker.test.js +7 -6
  89. package/test/SymbolPropagation.test.js +9 -9
  90. package/test/requests/ConfigRequest.test.js +3 -6
  91. package/test/utils.test.js +1 -1
  92. package/lib/atlaspack-v3/worker/compat.js +0 -57
  93. package/src/atlaspack-v3/worker/compat.js +0 -82
  94. package/test/requests/WriteBundleRequest.test.js +0 -132
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
  }
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 () {
@@ -300,7 +314,7 @@ class PackagerRunner {
300
314
  let bundle = _Bundle.NamedBundle.get(internalBundle, internalBundleGraph, this.options);
301
315
  let bundleGraph = new _BundleGraph.default(internalBundleGraph, _Bundle.NamedBundle.get.bind(_Bundle.NamedBundle), this.options);
302
316
  let optimizers = await this.config.getOptimizers(bundle.name, internalBundle.pipeline);
303
- if (optimizers.length === 0) {
317
+ if (!optimizers.length) {
304
318
  return {
305
319
  type: bundle.type,
306
320
  contents,
@@ -433,13 +447,40 @@ class PackagerRunner {
433
447
  }
434
448
  return devDepHashes;
435
449
  }
450
+ async readFromCache(cacheKey) {
451
+ let contentKey = PackagerRunner.getContentKey(cacheKey);
452
+ let mapKey = PackagerRunner.getMapKey(cacheKey);
453
+ let isLargeBlob = await this.options.cache.hasLargeBlob(contentKey);
454
+ let contentExists = isLargeBlob || (await this.options.cache.has(contentKey));
455
+ if (!contentExists) {
456
+ return null;
457
+ }
458
+ let mapExists = await this.options.cache.has(mapKey);
459
+ return {
460
+ contents: isLargeBlob ? this.options.cache.getStream(contentKey) : (0, _utils().blobToStream)(await this.options.cache.getBlob(contentKey)),
461
+ map: mapExists ? (0, _utils().blobToStream)(await this.options.cache.getBlob(mapKey)) : null
462
+ };
463
+ }
436
464
  async writeToCache(cacheKeys, type, contents, map) {
437
465
  let size = 0;
438
466
  let hash;
439
467
  let hashReferences = [];
468
+ let isLargeBlob = false;
440
469
 
441
470
  // TODO: don't replace hash references in binary files??
442
- if (typeof contents === 'string') {
471
+ if (contents instanceof _stream().Readable) {
472
+ isLargeBlob = true;
473
+ let boundaryStr = '';
474
+ let h = new (_rust().Hash)();
475
+ await this.options.cache.setStream(cacheKeys.content, (0, _utils().blobToStream)(contents).pipe(new (_utils().TapStream)(buf => {
476
+ let str = boundaryStr + buf.toString();
477
+ hashReferences = hashReferences.concat(str.match(_constants.HASH_REF_REGEX) ?? []);
478
+ size += buf.length;
479
+ h.writeBuffer(buf);
480
+ boundaryStr = str.slice(str.length - BOUNDARY_LENGTH);
481
+ })));
482
+ hash = h.finish();
483
+ } else if (typeof contents === 'string') {
443
484
  let buffer = Buffer.from(contents);
444
485
  size = buffer.byteLength;
445
486
  hash = (0, _rust().hashBuffer)(buffer);
@@ -459,7 +500,8 @@ class PackagerRunner {
459
500
  size,
460
501
  hash,
461
502
  hashReferences,
462
- cacheKeys
503
+ cacheKeys,
504
+ isLargeBlob
463
505
  };
464
506
  await this.options.cache.set(cacheKeys.info, info);
465
507
  return info;
@@ -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
  }
package/lib/assetUtils.js CHANGED
@@ -62,7 +62,7 @@ function _profiler() {
62
62
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
63
63
  function createAssetIdFromOptions(options) {
64
64
  return (0, _rust().createAssetId)({
65
- env: options.env,
65
+ environmentId: options.env.id,
66
66
  filePath: options.filePath,
67
67
  code: options.code,
68
68
  pipeline: options.pipeline,
@@ -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
  }
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MutableDependencySymbols = exports.MutableAssetSymbols = exports.AssetSymbols = void 0;
7
+ class MutableDependencySymbols {
8
+ #symbols;
9
+ #locals;
10
+ get isCleared() {
11
+ return this.#symbols.size === 0;
12
+ }
13
+ constructor(inner) {
14
+ this.#symbols = new Map();
15
+ this.#locals = new Set();
16
+ for (const {
17
+ exported,
18
+ local,
19
+ loc,
20
+ isWeak
21
+ } of inner || []) {
22
+ this.set(exported, local, loc, isWeak);
23
+ }
24
+ }
25
+ ensure() {
26
+ throw new Error('MutableDependencySymbols.ensure()');
27
+ }
28
+ get(exportSymbol) {
29
+ return this.#symbols.get(exportSymbol);
30
+ }
31
+ hasExportSymbol(exportSymbol) {
32
+ return this.#symbols.has(exportSymbol);
33
+ }
34
+ hasLocalSymbol(local) {
35
+ return this.#locals.has(local);
36
+ }
37
+ exportSymbols() {
38
+ return this.#symbols.keys();
39
+ }
40
+ set(exportSymbol, local, loc, isWeak) {
41
+ this.#locals.add(local);
42
+ this.#symbols.set(exportSymbol, {
43
+ local,
44
+ loc,
45
+ meta: {},
46
+ isWeak: isWeak ?? false
47
+ });
48
+ }
49
+ delete(exportSymbol) {
50
+ let existing = this.#symbols.get(exportSymbol);
51
+ if (!existing) return;
52
+ this.#locals.delete(existing.local);
53
+ this.#symbols.delete(exportSymbol);
54
+ }
55
+
56
+ /*:: @@iterator(): Iterator<[Symbol, DependencyAssetSymbol]> { return ({}: any); } */
57
+ // $FlowFixMe Flow can't do computed properties
58
+ [Symbol.iterator]() {
59
+ return this.#symbols.values();
60
+ }
61
+ }
62
+ exports.MutableDependencySymbols = MutableDependencySymbols;
63
+ class AssetSymbols {
64
+ #symbols;
65
+ #locals;
66
+ get isCleared() {
67
+ return this.#symbols.size === 0;
68
+ }
69
+ constructor(inner) {
70
+ this.#symbols = new Map();
71
+ this.#locals = new Set();
72
+ for (const {
73
+ exported,
74
+ local,
75
+ loc
76
+ } of inner || []) {
77
+ this.#set(exported, local, loc);
78
+ }
79
+ }
80
+ #set(exportSymbol, local, loc) {
81
+ this.#locals.add(local);
82
+ this.#symbols.set(exportSymbol, {
83
+ local,
84
+ loc,
85
+ meta: {}
86
+ });
87
+ }
88
+ get(exportSymbol) {
89
+ return this.#symbols.get(exportSymbol);
90
+ }
91
+ hasExportSymbol(exportSymbol) {
92
+ return this.#symbols.has(exportSymbol);
93
+ }
94
+ hasLocalSymbol(local) {
95
+ return this.#locals.has(local);
96
+ }
97
+ exportSymbols() {
98
+ return this.#symbols.keys();
99
+ }
100
+ intoNapi() {
101
+ return [];
102
+ }
103
+
104
+ /*:: @@iterator(): Iterator<[Symbol, AssetSymbol]> { return ({}: any); } */
105
+ // $FlowFixMe Flow can't do computed properties
106
+ [Symbol.iterator]() {
107
+ return this.#symbols.values();
108
+ }
109
+ }
110
+ exports.AssetSymbols = AssetSymbols;
111
+ class MutableAssetSymbols {
112
+ #symbols;
113
+ #locals;
114
+ get isCleared() {
115
+ return this.#symbols.size === 0;
116
+ }
117
+ constructor(inner) {
118
+ this.#symbols = new Map();
119
+ this.#locals = new Set();
120
+ for (const {
121
+ exported,
122
+ local,
123
+ loc
124
+ } of inner || []) {
125
+ this.set(exported, local, loc);
126
+ }
127
+ }
128
+ intoNapi() {
129
+ const results = [];
130
+ for (const [exportSymbol, {
131
+ local,
132
+ loc
133
+ }] of this.#symbols.entries()) {
134
+ results.push({
135
+ exported: exportSymbol,
136
+ local,
137
+ loc: loc ? {
138
+ filePath: loc.filePath,
139
+ start: {
140
+ line: loc.start.line,
141
+ column: loc.start.column
142
+ },
143
+ end: {
144
+ line: loc.end.line,
145
+ column: loc.end.column
146
+ }
147
+ } : undefined,
148
+ // TODO
149
+ isWeak: false,
150
+ isEsmExport: false,
151
+ selfReferenced: false
152
+ });
153
+ }
154
+ return results;
155
+ }
156
+ ensure() {
157
+ throw new Error('MutableAssetSymbols.ensure()');
158
+ }
159
+ set(exportSymbol, local, loc) {
160
+ this.#locals.add(local);
161
+ this.#symbols.set(exportSymbol, {
162
+ local,
163
+ loc,
164
+ meta: {}
165
+ });
166
+ }
167
+ get(exportSymbol) {
168
+ return this.#symbols.get(exportSymbol);
169
+ }
170
+ hasExportSymbol(exportSymbol) {
171
+ return this.#symbols.has(exportSymbol);
172
+ }
173
+ hasLocalSymbol(local) {
174
+ return this.#locals.has(local);
175
+ }
176
+ exportSymbols() {
177
+ return this.#symbols.keys();
178
+ }
179
+ delete(exportSymbol) {
180
+ let existing = this.#symbols.get(exportSymbol);
181
+ if (!existing) return;
182
+ this.#locals.delete(existing.local);
183
+ this.#symbols.delete(exportSymbol);
184
+ }
185
+
186
+ /*:: @@iterator(): Iterator<[Symbol, AssetSymbol]> { return ({}: any); } */
187
+ // $FlowFixMe Flow can't do computed properties
188
+ [Symbol.iterator]() {
189
+ return this.#symbols.values();
190
+ }
191
+ }
192
+ exports.MutableAssetSymbols = MutableAssetSymbols;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.specifierTypeMap = exports.packageConditionsMap = exports.dependencyPriorityMap = exports.bundleBehaviorMap = exports.BitFlags = void 0;
7
+ /// BitFlags is used to map number/string types from napi types
8
+ class BitFlags {
9
+ #kv;
10
+ #vk;
11
+ constructor(source) {
12
+ this.#kv = source;
13
+ this.#vk = Object.fromEntries(
14
+ // $FlowFixMe
15
+ Object.entries(source).map(a => a.reverse()));
16
+ }
17
+ into(key) {
18
+ const found = this.#kv[key];
19
+ if (found === undefined) {
20
+ // $FlowFixMe
21
+ throw new Error(`Invalid BundleBehavior(${key})`);
22
+ }
23
+ return found;
24
+ }
25
+ intoNullable(key) {
26
+ if (key === undefined || key === null) {
27
+ return undefined;
28
+ }
29
+ return this.into(key);
30
+ }
31
+ intoArray(keys) {
32
+ return keys.map(key => this.into(key));
33
+ }
34
+ from(key) {
35
+ const found = this.#vk[key];
36
+ if (found === undefined) {
37
+ // $FlowFixMe
38
+ throw new Error(`Invalid BundleBehavior(${key})`);
39
+ }
40
+ return found;
41
+ }
42
+ fromNullable(key) {
43
+ if (key === undefined || key === null) {
44
+ return undefined;
45
+ }
46
+ return this.from(key);
47
+ }
48
+ fromArray(keys) {
49
+ return keys.map(key => this.from(key));
50
+ }
51
+ }
52
+ exports.BitFlags = BitFlags;
53
+ const bundleBehaviorMap = exports.bundleBehaviorMap = new BitFlags({
54
+ inline: 0,
55
+ isolated: 1
56
+ });
57
+ const dependencyPriorityMap = exports.dependencyPriorityMap = new BitFlags({
58
+ sync: 0,
59
+ parallel: 1,
60
+ lazy: 2,
61
+ conditional: 3
62
+ });
63
+ const packageConditionsMap = exports.packageConditionsMap = new BitFlags({
64
+ import: 0,
65
+ require: 1,
66
+ module: 2,
67
+ node: 3,
68
+ browser: 4,
69
+ worker: 5,
70
+ worklet: 6,
71
+ electron: 7,
72
+ development: 8,
73
+ production: 9,
74
+ types: 10,
75
+ default: 11,
76
+ style: 12,
77
+ sass: 13
78
+ });
79
+ const specifierTypeMap = exports.specifierTypeMap = new BitFlags({
80
+ esm: 0,
81
+ commonjs: 1,
82
+ url: 2,
83
+ custom: 3
84
+ });
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Dependency = void 0;
7
+ var _target = require("./target");
8
+ var _assetSymbols = require("./asset-symbols");
9
+ var _bitflags = require("./bitflags");
10
+ class Dependency {
11
+ get id() {
12
+ throw new Error('Dependency.id');
13
+ }
14
+ constructor(inner, env) {
15
+ this.env = env;
16
+ this.meta = inner.meta || {};
17
+ this.target = undefined;
18
+ if (inner.target) {
19
+ this.target = new _target.Target(inner.target, this.env);
20
+ }
21
+ if (!inner.bundleBehavior) {
22
+ this.bundleBehavior = undefined;
23
+ } else {
24
+ this.bundleBehavior = _bitflags.bundleBehaviorMap.from(inner.bundleBehavior);
25
+ }
26
+ this.bundleBehavior = undefined;
27
+ this.symbols = new _assetSymbols.MutableDependencySymbols(inner.symbols || []);
28
+ this.specifier = inner.specifier;
29
+ this.specifierType = _bitflags.specifierTypeMap.from(inner.specifierType);
30
+ this.priority = _bitflags.dependencyPriorityMap.from(inner.priority);
31
+ this.needsStableName = inner.needsStableName;
32
+ this.isOptional = inner.isOptional;
33
+ this.isEntry = inner.isEntry;
34
+ this.loc = inner.loc;
35
+ this.packageConditions = _bitflags.packageConditionsMap.fromArray(inner.packageConditions || []);
36
+ this.sourceAssetId = inner.sourceAssetId;
37
+ this.sourcePath = inner.sourcePath;
38
+ this.sourceAssetType = inner.sourceAssetType;
39
+ this.resolveFrom = inner.resolveFrom;
40
+ this.range = inner.range;
41
+ this.pipeline = inner.pipeline;
42
+ }
43
+ }
44
+ exports.Dependency = Dependency;