@atlaspack/query 2.14.5-canary.36 → 2.14.5-canary.361

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.
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const v = process.env.ATLASPACK_BUILD_ENV === 'production' ||
4
+ process.env.ATLASPACK_REGISTER_USE_SRC !== 'true'
5
+ ? {
6
+ // Split up require specifier to outsmart packages/dev/babel-register/babel-plugin-module-translate.js
7
+ AssetGraph: require('@atlaspack/core' + '/lib/AssetGraph').default,
8
+ BundleGraph: require('@atlaspack/core' + '/lib/BundleGraph'),
9
+ RequestTracker: require('@atlaspack/core' + '/lib/RequestTracker'),
10
+ LMDBLiteCache: require('@atlaspack/cache' + '/lib/LMDBLiteCache')
11
+ .LMDBLiteCache,
12
+ Priority: require('@atlaspack/core' + '/lib/types').Priority,
13
+ fromProjectPathRelative: require('@atlaspack/core' + '/lib/projectPath')
14
+ .fromProjectPathRelative,
15
+ }
16
+ : {
17
+ AssetGraph: require('@atlaspack/core/src/AssetGraph').default,
18
+ BundleGraph: require('@atlaspack/core/src/BundleGraph'),
19
+ RequestTracker: require('@atlaspack/core/src/RequestTracker'),
20
+ LMDBLiteCache: require('@atlaspack/cache/src/LMDBLiteCache')
21
+ .LMDBLiteCache,
22
+ Priority: require('@atlaspack/core/src/types').Priority,
23
+ fromProjectPathRelative: require('@atlaspack/core/src/projectPath')
24
+ .fromProjectPathRelative,
25
+ };
26
+ module.exports = v;
package/dist/index.js ADDED
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.loadGraphs = loadGraphs;
7
+ const v8_1 = __importDefault(require("v8"));
8
+ const nullthrows_1 = __importDefault(require("nullthrows"));
9
+ const assert_1 = __importDefault(require("assert"));
10
+ const { AssetGraph, BundleGraph: { default: BundleGraph }, RequestTracker: { default: RequestTracker, readAndDeserializeRequestGraph, requestGraphEdgeTypes, }, LMDBLiteCache, } = process.env.ATLASPACK_REGISTER_USE_SRC === 'true'
11
+ ? require('./deep-imports.ts')
12
+ : require('./deep-imports.js');
13
+ async function loadGraphs(cacheDir) {
14
+ let cacheInfo = new Map();
15
+ const cache = new LMDBLiteCache(cacheDir);
16
+ let requestGraphBlob;
17
+ let requestGraphKey;
18
+ let bundleGraphBlob;
19
+ let assetGraphBlob;
20
+ for (let key of cache.keys()) {
21
+ if (key.startsWith('Asset/')) {
22
+ continue;
23
+ }
24
+ else if (key.startsWith('PackagerRunner/')) {
25
+ continue;
26
+ }
27
+ if (key.startsWith('RequestTracker/') && key.endsWith('/RequestGraph')) {
28
+ requestGraphBlob = key;
29
+ requestGraphKey = key.split('/').slice(0, -1).join('/');
30
+ }
31
+ if (key.startsWith('BundleGraph/')) {
32
+ bundleGraphBlob = key;
33
+ }
34
+ if (key.startsWith('AssetGraph/')) {
35
+ assetGraphBlob = key;
36
+ }
37
+ }
38
+ console.log({ requestGraphBlob, bundleGraphBlob, assetGraphBlob });
39
+ // Get requestTracker
40
+ // @ts-expect-error TS7034
41
+ let requestTracker;
42
+ if (requestGraphBlob != null && requestGraphKey != null) {
43
+ try {
44
+ let date = Date.now();
45
+ const buffer = await cache.getBlob(requestGraphBlob);
46
+ const deserializer = new v8_1.default.Deserializer(buffer);
47
+ console.log('Wire format version stored', deserializer.getWireFormatVersion());
48
+ let { requestGraph, bufferLength } = await readAndDeserializeRequestGraph(cache, requestGraphBlob, requestGraphKey);
49
+ requestTracker = new RequestTracker({
50
+ graph: requestGraph,
51
+ farm: null,
52
+ options: null,
53
+ });
54
+ let timeToDeserialize = Date.now() - date;
55
+ cacheInfo.set('RequestGraph', [bufferLength]);
56
+ cacheInfo.get('RequestGraph')?.push(timeToDeserialize);
57
+ }
58
+ catch (e) {
59
+ console.error('Error loading Request Graph\n', e);
60
+ }
61
+ }
62
+ // Get bundleGraph
63
+ let bundleGraph;
64
+ if (bundleGraphBlob != null) {
65
+ try {
66
+ let file = await cache.getBlob(bundleGraphBlob);
67
+ let timeToDeserialize = Date.now();
68
+ let obj = v8_1.default.deserialize(file);
69
+ (0, assert_1.default)(obj.bundleGraph != null);
70
+ bundleGraph = BundleGraph.deserialize(obj.bundleGraph.value);
71
+ timeToDeserialize = Date.now() - timeToDeserialize;
72
+ cacheInfo.set('BundleGraph', [Buffer.byteLength(file)]);
73
+ cacheInfo.get('BundleGraph')?.push(timeToDeserialize);
74
+ }
75
+ catch (e) {
76
+ console.error('Error loading Bundle Graph\n', e);
77
+ }
78
+ }
79
+ // Get assetGraph
80
+ let assetGraph;
81
+ if (assetGraphBlob != null) {
82
+ try {
83
+ // TODO: this should be reviewed when `cachePerformanceImprovements` flag is removed, as we'll be writing files to LMDB cache instead of large blobs
84
+ let file = await cache.getBlob(assetGraphBlob);
85
+ let timeToDeserialize = Date.now();
86
+ let obj = v8_1.default.deserialize(file);
87
+ (0, assert_1.default)(obj.assetGraph != null);
88
+ assetGraph = AssetGraph.deserialize(obj.assetGraph.value);
89
+ timeToDeserialize = Date.now() - timeToDeserialize;
90
+ cacheInfo.set('AssetGraph', [Buffer.byteLength(file)]);
91
+ cacheInfo.get('AssetGraph')?.push(timeToDeserialize);
92
+ }
93
+ catch (e) {
94
+ console.error('Error loading Asset Graph\n', e);
95
+ }
96
+ }
97
+ function getSubRequests(id) {
98
+ return (
99
+ // @ts-expect-error TS7005
100
+ requestTracker.graph
101
+ .getNodeIdsConnectedFrom(id, requestGraphEdgeTypes.subrequest)
102
+ // @ts-expect-error TS7006
103
+ .map((n) => (0, nullthrows_1.default)(requestTracker.graph.getNode(n))));
104
+ }
105
+ // Load graphs by finding the main subrequests and loading their results
106
+ let bundleInfo;
107
+ try {
108
+ (0, assert_1.default)(requestTracker);
109
+ let buildRequestId = requestTracker.graph.getNodeIdByContentKey('atlaspack_build_request');
110
+ let buildRequestNode = (0, nullthrows_1.default)(requestTracker.graph.getNode(buildRequestId));
111
+ (0, assert_1.default)(buildRequestNode.type === 1 && buildRequestNode.requestType === 1);
112
+ let buildRequestSubRequests = getSubRequests(buildRequestId);
113
+ let writeBundlesRequest = buildRequestSubRequests.find(
114
+ // @ts-expect-error TS7006
115
+ (n) => n.type === 1 && n.requestType === 11);
116
+ if (writeBundlesRequest != null) {
117
+ (0, assert_1.default)(writeBundlesRequest.type === 1);
118
+ bundleInfo = (0, nullthrows_1.default)(writeBundlesRequest.result);
119
+ }
120
+ }
121
+ catch (e) {
122
+ console.error('Error loading bundleInfo\n', e);
123
+ }
124
+ return { assetGraph, bundleGraph, requestTracker, bundleInfo, cacheInfo };
125
+ }
package/lib/bin.js CHANGED
@@ -1,6 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
+ if (process.env.ATLASPACK_SOURCES === 'true' || process.env.ATLASPACK_BUILD_ENV === 'test' || process.env.ATLASPACK_SELF_BUILD) {
5
+ require('@atlaspack/babel-register');
6
+ }
4
7
  const run = require('./cli').run;
5
8
  require('v8-compile-cache');
6
9
  run(process.argv.slice(2));
package/lib/cli.js CHANGED
@@ -63,7 +63,7 @@ function _table() {
63
63
  var _index = require("./index");
64
64
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
65
65
  /* eslint-disable no-console, monorepo/no-internal-import */
66
- // $FlowFixMe
66
+
67
67
  const {
68
68
  BundleGraph: {
69
69
  bundleGraphEdgeTypes: bundleGraphEdgeTypes
@@ -488,6 +488,8 @@ async function run(input) {
488
488
  let bundleId = (0, _nullthrows().default)(parseBundleLocator(v), 'Bundle not found');
489
489
  let node = (0, _nullthrows().default)(bundleGraph._graph.getNodeByContentKey(bundleId), 'Bundle not found');
490
490
  (0, _assert().default)(node.type === 'bundle', 'Node is not a bundle, but a ' + node.type);
491
+
492
+ // @ts-expect-error TS7006
491
493
  bundleGraph.traverseAssets(node.value, asset => {
492
494
  console.log(asset.id, asset.filePath);
493
495
  });
@@ -500,6 +502,8 @@ async function run(input) {
500
502
  let bundleId = (0, _nullthrows().default)(parseBundleLocator(v), 'Bundle not found');
501
503
  let node = (0, _nullthrows().default)(bundleGraph._graph.getNodeByContentKey(bundleId), 'Bundle not found');
502
504
  (0, _assert().default)(node.type === 'bundle', 'Node is not a bundle, but a ' + node.type);
505
+
506
+ // @ts-expect-error TS7006
503
507
  bundleGraph.traverseBundle(node.value, node => {
504
508
  if (node.type === 'asset') {
505
509
  console.log(node.id, node.value.filePath);
@@ -546,23 +550,34 @@ async function run(input) {
546
550
  console.log('# Incoming dependencies contained in referencing bundles (using this bundle as a shared bundle)');
547
551
  let referencingBundles = bundleGraph.getReferencingBundles(bundleNode.value);
548
552
  for (let incoming of bundleGraph._graph.getNodeIdsConnectedTo(assetNodeId)) {
549
- if (referencingBundles.some(ref => bundleGraph._graph.hasEdge(bundleGraph._graph.getNodeIdByContentKey(ref.id), incoming, bundleGraphEdgeTypes.contains))) {
553
+ if (
554
+ // @ts-expect-error TS7006
555
+ referencingBundles.some(ref => bundleGraph._graph.hasEdge(bundleGraph._graph.getNodeIdByContentKey(ref.id), incoming, bundleGraphEdgeTypes.contains))) {
550
556
  console.log(bundleGraph._graph.getNode(incoming));
551
557
  }
552
558
  }
553
559
  }
554
- function _getIncomingNodeOfType(bundleGraph, node, type) {
560
+ function _getIncomingNodeOfType(
561
+ // @ts-expect-error TS2304
562
+ bundleGraph,
563
+ // @ts-expect-error TS7006
564
+ node, type) {
555
565
  if (!hasBundleGraph()) {
556
566
  return;
557
567
  }
558
568
  (0, _assert().default)(bundleGraph != null);
559
569
  const bundleGraphNodeId = bundleGraph._graph.getNodeIdByContentKey(node.id);
560
- return bundleGraph._graph.getNodeIdsConnectedTo(bundleGraphNodeId, -1).map(id => (0, _nullthrows().default)(bundleGraph._graph.getNode(id))).find(node => node.type == type);
570
+ return bundleGraph._graph.getNodeIdsConnectedTo(bundleGraphNodeId, -1)
571
+ // @ts-expect-error TS7006
572
+ .map(id => (0, _nullthrows().default)(bundleGraph._graph.getNode(id)))
573
+ // @ts-expect-error TS7006
574
+ .find(node => node.type == type);
561
575
  }
562
576
 
563
577
  // We find the priority of a Bundle or BundleGroup by looking at its incoming dependencies.
564
578
  // If a Bundle does not have an incoming dependency, we look for an incoming BundleGroup and its dependency
565
579
  // e.g. Dep(priority = 1) -> BundleGroup -> Bundle means that the Bundle has priority 1.
580
+ // @ts-expect-error TS2304
566
581
  function _getBundlePriority(bundleGraph, bundle) {
567
582
  if (!hasBundleGraph()) {
568
583
  return;
@@ -578,13 +593,19 @@ async function run(input) {
578
593
  (0, _assert().default)(node.type === 'dependency', 'Not a dependency');
579
594
  return node.value.priority;
580
595
  }
596
+
597
+ // @ts-expect-error TS2304
581
598
  function _findEntryBundle(bundleGraph, node) {
582
599
  if (!hasBundleGraph()) {
583
600
  return;
584
601
  }
585
602
  (0, _assert().default)(bundleGraph != null);
586
603
  const bundleGraphNodeId = bundleGraph._graph.getNodeIdByContentKey(node.id);
587
- const entryBundleGroup = bundleGraph._graph.getNodeIdsConnectedTo(bundleGraphNodeId, -1).map(id => (0, _nullthrows().default)(bundleGraph._graph.getNode(id))).find(node => node.type === 'bundle_group' && bundleGraph.isEntryBundleGroup(node.value));
604
+ const entryBundleGroup = bundleGraph._graph.getNodeIdsConnectedTo(bundleGraphNodeId, -1)
605
+ // @ts-expect-error TS7006
606
+ .map(id => (0, _nullthrows().default)(bundleGraph._graph.getNode(id))).find(
607
+ // @ts-expect-error TS7006
608
+ node => node.type === 'bundle_group' && bundleGraph.isEntryBundleGroup(node.value));
588
609
  return entryBundleGroup;
589
610
  }
590
611
  // eslint-disable-next-line no-unused-vars
@@ -612,12 +633,16 @@ async function run(input) {
612
633
  let column = t.map(r => r[col]);
613
634
  column.shift();
614
635
  (0, _assert().default)(column != null);
615
- return column.reduce((accumulator, currentValue) => accumulator + currentValue, initialValue);
636
+ return column.reduce(
637
+ // @ts-expect-error TS2365
638
+ (accumulator, currentValue) => accumulator + currentValue, initialValue);
616
639
  }
617
640
  table.push(['Totals', getColumnSum(table, 1), getColumnSum(table, 2), getColumnSum(table, 3)]);
618
641
  _printStatsTable('Cache Info', table);
619
642
  }
620
- function timeSerialize(graph) {
643
+ function timeSerialize(
644
+ // @ts-expect-error TS2304
645
+ graph) {
621
646
  let date = Date.now();
622
647
  (0, _v().serialize)(graph);
623
648
  date = Date.now() - date;
@@ -647,7 +672,7 @@ async function run(input) {
647
672
  (0, _assert().default)(assetGraph != null);
648
673
  for (let n of assetGraph.nodes) {
649
674
  if (n && n.type in ag) {
650
- // $FlowFixMe
675
+ // @ts-expect-error TS7053
651
676
  ag[n.type]++;
652
677
  }
653
678
  }
@@ -678,11 +703,7 @@ async function run(input) {
678
703
  bg.bundle_group++;
679
704
  } else if ((n === null || n === void 0 ? void 0 : n.type) === 'bundle') {
680
705
  bg.bundle++;
681
-
682
- // $FlowFixMe
683
706
  b_ext[n.value.type] = (b_ext[n.value.type] || 0) + 1;
684
-
685
- // $FlowFixMe
686
707
  const entry_group = _findEntryBundle(bundleGraph, n);
687
708
  if (entry_group != null && !entries.has(entry_group.id)) {
688
709
  b_type.entry++;
@@ -701,9 +722,7 @@ async function run(input) {
701
722
  }
702
723
  }
703
724
  } else if ((n === null || n === void 0 ? void 0 : n.type) === 'asset') {
704
- if (
705
- // $FlowFixMe
706
- fromProjectPathRelative(n.value.filePath).includes('node_modules')) {
725
+ if (fromProjectPathRelative(n.value.filePath).includes('node_modules')) {
707
726
  bg.asset_node_modules++;
708
727
  } else {
709
728
  bg.asset_source++;
@@ -724,6 +743,7 @@ async function run(input) {
724
743
  }
725
744
  let sum_b_type = 0;
726
745
  for (let k in b_type) {
746
+ // @ts-expect-error TS7053
727
747
  sum_b_type += b_type[k];
728
748
  }
729
749
  (0, _assert().default)(bg.bundle == sum_b_type, `Bundles by type ${sum_b_type} does not equal total ${bg.bundle}`);
@@ -747,16 +767,10 @@ async function run(input) {
747
767
  useColors: true,
748
768
  useGlobal: true
749
769
  });
750
- // $FlowFixMe[prop-missing]
751
770
  server.setupHistory(_path().default.join(_os().default.homedir(), '.parcel_query_history'), () => {});
752
-
753
- // $FlowFixMe[prop-missing]
754
771
  server.context.bundleGraph = bundleGraph;
755
- // $FlowFixMe[prop-missing]
756
772
  server.context.assetGraph = assetGraph;
757
- // $FlowFixMe[prop-missing]
758
773
  server.context.requestTracker = requestTracker;
759
- // $FlowFixMe[prop-missing]
760
774
  server.context.cacheInfo = cacheInfo;
761
775
  for (let [name, cmd] of new Map([['getAsset', {
762
776
  help: 'args: <id | public id | filepath>',
@@ -808,6 +822,7 @@ async function run(input) {
808
822
  action: getBundle
809
823
  }], ['findBundleReason', {
810
824
  help: 'args: <bundle> <asset>. Why is the asset in the bundle',
825
+ // @ts-expect-error TS2556
811
826
  action: v => findBundleReason(...v.split(' '))
812
827
  }], ['getBundles', {
813
828
  help: 'List all bundles',
@@ -828,16 +843,11 @@ async function run(input) {
828
843
  help: 'args: <local>. Get the asset that defines the symbol with the given local name',
829
844
  action: findAssetWithSymbol
830
845
  }]])) {
831
- // $FlowFixMe
832
846
  server.context[name] = cmd.action;
833
- // $FlowFixMe
834
847
  server.defineCommand(name, {
835
- // $FlowFixMe
836
848
  help: '📦 ' + cmd.help,
837
849
  action: v => {
838
- // $FlowFixMe
839
850
  server.clearBufferedCommand();
840
- // $FlowFixMe
841
851
  try {
842
852
  cmd.action(v);
843
853
  } finally {
@@ -1,19 +1,21 @@
1
1
  "use strict";
2
2
 
3
3
  /* eslint-disable monorepo/no-internal-import */
4
- const v = {
4
+
5
+ const v = process.env.ATLASPACK_BUILD_ENV === 'production' || process.env.ATLASPACK_REGISTER_USE_SRC !== 'true' ? {
5
6
  // Split up require specifier to outsmart packages/dev/babel-register/babel-plugin-module-translate.js
6
- // $FlowFixMe(unsupported-syntax)
7
7
  AssetGraph: require('@atlaspack/core' + '/lib/AssetGraph').default,
8
- // $FlowFixMe(unsupported-syntax)
9
8
  BundleGraph: require('@atlaspack/core' + '/lib/BundleGraph'),
10
- // $FlowFixMe(unsupported-syntax)
11
9
  RequestTracker: require('@atlaspack/core' + '/lib/RequestTracker'),
12
- // $FlowFixMe(unsupported-syntax)
13
10
  LMDBLiteCache: require('@atlaspack/cache' + '/lib/LMDBLiteCache').LMDBLiteCache,
14
- // $FlowFixMe(unsupported-syntax)
15
11
  Priority: require('@atlaspack/core' + '/lib/types').Priority,
16
- // $FlowFixMe(unsupported-syntax)
17
12
  fromProjectPathRelative: require('@atlaspack/core' + '/lib/projectPath').fromProjectPathRelative
13
+ } : {
14
+ AssetGraph: require('@atlaspack/core/src/AssetGraph').default,
15
+ BundleGraph: require('@atlaspack/core/src/BundleGraph'),
16
+ RequestTracker: require('@atlaspack/core/src/RequestTracker'),
17
+ LMDBLiteCache: require('@atlaspack/cache/src/LMDBLiteCache').LMDBLiteCache,
18
+ Priority: require('@atlaspack/core/src/types').Priority,
19
+ fromProjectPathRelative: require('@atlaspack/core/src/projectPath').fromProjectPathRelative
18
20
  };
19
21
  module.exports = v;
package/lib/index.js CHANGED
@@ -4,20 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.loadGraphs = loadGraphs;
7
- function _fs() {
8
- const data = _interopRequireDefault(require("fs"));
9
- _fs = function () {
10
- return data;
11
- };
12
- return data;
13
- }
14
- function _path() {
15
- const data = _interopRequireDefault(require("path"));
16
- _path = function () {
17
- return data;
18
- };
19
- return data;
20
- }
21
7
  function _v() {
22
8
  const data = _interopRequireDefault(require("v8"));
23
9
  _v = function () {
@@ -41,6 +27,7 @@ function _assert() {
41
27
  }
42
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
43
29
  /* eslint-disable no-console, monorepo/no-internal-import */
30
+
44
31
  const {
45
32
  AssetGraph,
46
33
  BundleGraph: {
@@ -52,75 +39,70 @@ const {
52
39
  requestGraphEdgeTypes
53
40
  },
54
41
  LMDBLiteCache
55
- } = require('./deep-imports.js');
42
+ } = process.env.ATLASPACK_REGISTER_USE_SRC === 'true' ? require('./deep-imports.ts') : require('./deep-imports.js');
56
43
  async function loadGraphs(cacheDir) {
57
44
  let cacheInfo = new Map();
58
- let {
45
+ const cache = new LMDBLiteCache(cacheDir);
46
+ let requestGraphBlob;
47
+ let requestGraphKey;
48
+ let bundleGraphBlob;
49
+ let assetGraphBlob;
50
+ for (let key of cache.keys()) {
51
+ if (key.startsWith('Asset/')) {
52
+ continue;
53
+ } else if (key.startsWith('PackagerRunner/')) {
54
+ continue;
55
+ }
56
+ if (key.startsWith('RequestTracker/') && key.endsWith('/RequestGraph')) {
57
+ requestGraphBlob = key;
58
+ requestGraphKey = key.split('/').slice(0, -1).join('/');
59
+ }
60
+ if (key.startsWith('BundleGraph/')) {
61
+ bundleGraphBlob = key;
62
+ }
63
+ if (key.startsWith('AssetGraph/')) {
64
+ assetGraphBlob = key;
65
+ }
66
+ }
67
+ console.log({
59
68
  requestGraphBlob,
60
69
  bundleGraphBlob,
61
70
  assetGraphBlob
62
- } = function getMostRecentCacheBlobs() {
63
- let files = _fs().default.readdirSync(cacheDir);
64
- let result = {};
65
- let blobsToFind = [{
66
- name: 'requestGraphBlob',
67
- check: basename => basename.startsWith('requestGraph-') && !basename.startsWith('requestGraph-nodes')
68
- }, {
69
- name: 'bundleGraphBlob',
70
- check: basename => basename.endsWith('BundleGraph-0')
71
- }, {
72
- name: 'assetGraphBlob',
73
- check: basename => basename.endsWith('AssetGraph-0')
74
- }];
75
- for (let file of files) {
76
- let basename = _path().default.basename(file);
77
- let match = blobsToFind.find(({
78
- check
79
- }) => check(basename));
80
- if (match) {
81
- let stat = _fs().default.statSync(_path().default.join(cacheDir, file));
82
- if (!match.mtime || stat.mtime > match.mtime) {
83
- match.mtime = stat.mtime;
84
- result[match.name] = file;
85
- }
86
- }
87
- }
88
- return result;
89
- }();
90
- const cache = new LMDBLiteCache(cacheDir);
71
+ });
91
72
 
92
73
  // Get requestTracker
74
+ // @ts-expect-error TS7034
93
75
  let requestTracker;
94
- if (requestGraphBlob) {
76
+ if (requestGraphBlob != null && requestGraphKey != null) {
95
77
  try {
96
78
  var _cacheInfo$get;
97
- let requestGraphKey = requestGraphBlob.slice(0, -'-0'.length);
98
79
  let date = Date.now();
80
+ const buffer = await cache.getBlob(requestGraphBlob);
81
+ const deserializer = new (_v().default.Deserializer)(buffer);
82
+ console.log('Wire format version stored', deserializer.getWireFormatVersion());
99
83
  let {
100
84
  requestGraph,
101
85
  bufferLength
102
- } = await readAndDeserializeRequestGraph(cache, requestGraphKey, requestGraphKey.replace('requestGraph-', ''));
86
+ } = await readAndDeserializeRequestGraph(cache, requestGraphBlob, requestGraphKey);
103
87
  requestTracker = new RequestTracker({
104
88
  graph: requestGraph,
105
- // $FlowFixMe
106
89
  farm: null,
107
- // $FlowFixMe
108
90
  options: null
109
91
  });
110
92
  let timeToDeserialize = Date.now() - date;
111
93
  cacheInfo.set('RequestGraph', [bufferLength]);
112
94
  (_cacheInfo$get = cacheInfo.get('RequestGraph')) === null || _cacheInfo$get === void 0 || _cacheInfo$get.push(timeToDeserialize);
113
95
  } catch (e) {
114
- console.log('Error loading Request Graph\n', e);
96
+ console.error('Error loading Request Graph\n', e);
115
97
  }
116
98
  }
117
99
 
118
100
  // Get bundleGraph
119
101
  let bundleGraph;
120
- if (bundleGraphBlob) {
102
+ if (bundleGraphBlob != null) {
121
103
  try {
122
104
  var _cacheInfo$get2;
123
- let file = await cache.getLargeBlob(_path().default.basename(bundleGraphBlob).slice(0, -'-0'.length));
105
+ let file = await cache.getBlob(bundleGraphBlob);
124
106
  let timeToDeserialize = Date.now();
125
107
  let obj = _v().default.deserialize(file);
126
108
  (0, _assert().default)(obj.bundleGraph != null);
@@ -129,17 +111,17 @@ async function loadGraphs(cacheDir) {
129
111
  cacheInfo.set('BundleGraph', [Buffer.byteLength(file)]);
130
112
  (_cacheInfo$get2 = cacheInfo.get('BundleGraph')) === null || _cacheInfo$get2 === void 0 || _cacheInfo$get2.push(timeToDeserialize);
131
113
  } catch (e) {
132
- console.log('Error loading Bundle Graph\n', e);
114
+ console.error('Error loading Bundle Graph\n', e);
133
115
  }
134
116
  }
135
117
 
136
118
  // Get assetGraph
137
119
  let assetGraph;
138
- if (assetGraphBlob) {
120
+ if (assetGraphBlob != null) {
139
121
  try {
140
122
  var _cacheInfo$get3;
141
123
  // TODO: this should be reviewed when `cachePerformanceImprovements` flag is removed, as we'll be writing files to LMDB cache instead of large blobs
142
- let file = await cache.getLargeBlob(_path().default.basename(assetGraphBlob).slice(0, -'-0'.length));
124
+ let file = await cache.getBlob(assetGraphBlob);
143
125
  let timeToDeserialize = Date.now();
144
126
  let obj = _v().default.deserialize(file);
145
127
  (0, _assert().default)(obj.assetGraph != null);
@@ -148,11 +130,16 @@ async function loadGraphs(cacheDir) {
148
130
  cacheInfo.set('AssetGraph', [Buffer.byteLength(file)]);
149
131
  (_cacheInfo$get3 = cacheInfo.get('AssetGraph')) === null || _cacheInfo$get3 === void 0 || _cacheInfo$get3.push(timeToDeserialize);
150
132
  } catch (e) {
151
- console.log('Error loading Asset Graph\n', e);
133
+ console.error('Error loading Asset Graph\n', e);
152
134
  }
153
135
  }
154
136
  function getSubRequests(id) {
155
- return requestTracker.graph.getNodeIdsConnectedFrom(id, requestGraphEdgeTypes.subrequest).map(n => (0, _nullthrows().default)(requestTracker.graph.getNode(n)));
137
+ return (
138
+ // @ts-expect-error TS7005
139
+ requestTracker.graph.getNodeIdsConnectedFrom(id, requestGraphEdgeTypes.subrequest)
140
+ // @ts-expect-error TS7006
141
+ .map(n => (0, _nullthrows().default)(requestTracker.graph.getNode(n)))
142
+ );
156
143
  }
157
144
 
158
145
  // Load graphs by finding the main subrequests and loading their results
@@ -163,14 +150,15 @@ async function loadGraphs(cacheDir) {
163
150
  let buildRequestNode = (0, _nullthrows().default)(requestTracker.graph.getNode(buildRequestId));
164
151
  (0, _assert().default)(buildRequestNode.type === 1 && buildRequestNode.requestType === 1);
165
152
  let buildRequestSubRequests = getSubRequests(buildRequestId);
166
- let writeBundlesRequest = buildRequestSubRequests.find(n => n.type === 1 && n.requestType === 11);
153
+ let writeBundlesRequest = buildRequestSubRequests.find(
154
+ // @ts-expect-error TS7006
155
+ n => n.type === 1 && n.requestType === 11);
167
156
  if (writeBundlesRequest != null) {
168
157
  (0, _assert().default)(writeBundlesRequest.type === 1);
169
- // $FlowFixMe[incompatible-cast]
170
158
  bundleInfo = (0, _nullthrows().default)(writeBundlesRequest.result);
171
159
  }
172
160
  } catch (e) {
173
- console.log('Error loading bundleInfo\n', e);
161
+ console.error('Error loading bundleInfo\n', e);
174
162
  }
175
163
  return {
176
164
  assetGraph,
@@ -0,0 +1 @@
1
+ export declare function run(input: string[]): Promise<void>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { ContentKey } from '@atlaspack/graph';
2
+ import type { PackagedBundleInfo } from '@atlaspack/core/src/types';
3
+ export declare function loadGraphs(cacheDir: string): Promise<{
4
+ assetGraph: AssetGraph | null | undefined;
5
+ bundleGraph: BundleGraph | null | undefined;
6
+ requestTracker: RequestTracker | null | undefined;
7
+ bundleInfo: Map<ContentKey, PackagedBundleInfo> | null | undefined;
8
+ cacheInfo: Map<string, Array<string | number>> | null | undefined;
9
+ }>;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@atlaspack/query",
3
- "version": "2.14.5-canary.36+2d10c6656",
3
+ "version": "2.14.5-canary.361+405bbaf61",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
8
  "scripts": {
9
- "prepack": "./ensure-no-dev-lib.sh",
10
- "dev:prepare": "rimraf ./lib/ && mkdir -p lib && cp ./bin/dev-bin.js ./lib/bin.js"
9
+ "dev:prepare": "rimraf ./lib/ && mkdir -p lib && cp ./bin/dev-bin.js ./lib/bin.js",
10
+ "build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
@@ -16,20 +16,21 @@
16
16
  "bin": {
17
17
  "atlaspack-query": "bin/atlaspack-query.js"
18
18
  },
19
- "main": "src/index.js",
19
+ "main": "lib/index.js",
20
+ "source": "src/index.ts",
20
21
  "dependencies": {
21
- "@atlaspack/cache": "3.1.1-canary.36+2d10c6656",
22
- "@atlaspack/core": "2.16.2-canary.36+2d10c6656",
23
- "@atlaspack/graph": "3.4.1-canary.104+2d10c6656",
22
+ "@atlaspack/cache": "3.1.1-canary.361+405bbaf61",
23
+ "@atlaspack/core": "2.16.2-canary.361+405bbaf61",
24
+ "@atlaspack/graph": "3.4.1-canary.429+405bbaf61",
24
25
  "nullthrows": "^1.1.1",
25
26
  "table": "^6.8.1",
26
27
  "v8-compile-cache": "^2.0.0"
27
28
  },
28
29
  "devDependencies": {
29
- "@atlaspack/babel-register": "2.14.1",
30
+ "@atlaspack/babel-register": "2.14.4",
30
31
  "@babel/core": "^7.22.11",
31
32
  "rimraf": "^5.0.5"
32
33
  },
33
34
  "type": "commonjs",
34
- "gitHead": "2d10c6656fc58743c5dbed1d2b6c5666887f9fe4"
35
+ "gitHead": "405bbaf619f634cf9e58cc618d9a911f7db2998d"
35
36
  }
package/src/bin.js CHANGED
@@ -3,7 +3,8 @@
3
3
  'use strict';
4
4
 
5
5
  if (
6
- process.env.ATLASPACK_BUILD_ENV !== 'production' ||
6
+ process.env.ATLASPACK_SOURCES === 'true' ||
7
+ process.env.ATLASPACK_BUILD_ENV === 'test' ||
7
8
  process.env.ATLASPACK_SELF_BUILD
8
9
  ) {
9
10
  require('@atlaspack/babel-register');