@atlaspack/query 2.14.5-canary.138 → 2.14.5-canary.139

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.
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,14 @@
1
1
  "use strict";
2
2
 
3
3
  /* eslint-disable monorepo/no-internal-import */
4
- const v = process.env.ATLASPACK_BUILD_ENV === 'production' ? {
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
18
13
  } : {
19
14
  AssetGraph: require('@atlaspack/core/src/AssetGraph').default,
package/lib/index.js CHANGED
@@ -27,6 +27,7 @@ function _assert() {
27
27
  }
28
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
29
  /* eslint-disable no-console, monorepo/no-internal-import */
30
+
30
31
  const {
31
32
  AssetGraph,
32
33
  BundleGraph: {
@@ -38,7 +39,7 @@ const {
38
39
  requestGraphEdgeTypes
39
40
  },
40
41
  LMDBLiteCache
41
- } = require('./deep-imports.js');
42
+ } = process.env.ATLASPACK_REGISTER_USE_SRC === 'true' ? require('./deep-imports.js') : require('./deep-imports.ts');
42
43
  async function loadGraphs(cacheDir) {
43
44
  let cacheInfo = new Map();
44
45
  const cache = new LMDBLiteCache(cacheDir);
@@ -70,6 +71,7 @@ async function loadGraphs(cacheDir) {
70
71
  });
71
72
 
72
73
  // Get requestTracker
74
+ // @ts-expect-error TS7034
73
75
  let requestTracker;
74
76
  if (requestGraphBlob != null && requestGraphKey != null) {
75
77
  try {
@@ -84,9 +86,7 @@ async function loadGraphs(cacheDir) {
84
86
  } = await readAndDeserializeRequestGraph(cache, requestGraphBlob, requestGraphKey);
85
87
  requestTracker = new RequestTracker({
86
88
  graph: requestGraph,
87
- // $FlowFixMe
88
89
  farm: null,
89
- // $FlowFixMe
90
90
  options: null
91
91
  });
92
92
  let timeToDeserialize = Date.now() - date;
@@ -134,7 +134,12 @@ async function loadGraphs(cacheDir) {
134
134
  }
135
135
  }
136
136
  function getSubRequests(id) {
137
- 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
+ );
138
143
  }
139
144
 
140
145
  // Load graphs by finding the main subrequests and loading their results
@@ -145,10 +150,11 @@ async function loadGraphs(cacheDir) {
145
150
  let buildRequestNode = (0, _nullthrows().default)(requestTracker.graph.getNode(buildRequestId));
146
151
  (0, _assert().default)(buildRequestNode.type === 1 && buildRequestNode.requestType === 1);
147
152
  let buildRequestSubRequests = getSubRequests(buildRequestId);
148
- 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);
149
156
  if (writeBundlesRequest != null) {
150
157
  (0, _assert().default)(writeBundlesRequest.type === 1);
151
- // $FlowFixMe[incompatible-cast]
152
158
  bundleInfo = (0, _nullthrows().default)(writeBundlesRequest.result);
153
159
  }
154
160
  } catch (e) {
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@atlaspack/query",
3
- "version": "2.14.5-canary.138+eda07caaf",
3
+ "version": "2.14.5-canary.139+d2fd84977",
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
9
  "dev:prepare": "rimraf ./lib/ && mkdir -p lib && cp ./bin/dev-bin.js ./lib/bin.js"
11
10
  },
12
11
  "repository": {
@@ -18,9 +17,9 @@
18
17
  },
19
18
  "main": "src/index.js",
20
19
  "dependencies": {
21
- "@atlaspack/cache": "3.1.1-canary.138+eda07caaf",
22
- "@atlaspack/core": "2.16.2-canary.138+eda07caaf",
23
- "@atlaspack/graph": "3.4.1-canary.206+eda07caaf",
20
+ "@atlaspack/cache": "3.1.1-canary.139+d2fd84977",
21
+ "@atlaspack/core": "2.16.2-canary.139+d2fd84977",
22
+ "@atlaspack/graph": "3.4.1-canary.207+d2fd84977",
24
23
  "nullthrows": "^1.1.1",
25
24
  "table": "^6.8.1",
26
25
  "v8-compile-cache": "^2.0.0"
@@ -31,5 +30,5 @@
31
30
  "rimraf": "^5.0.5"
32
31
  },
33
32
  "type": "commonjs",
34
- "gitHead": "eda07caafd2ebb814bbdbfd0ec12fa63124e213f"
33
+ "gitHead": "d2fd849770fe6305e9c694bd97b1bd905abd9d94"
35
34
  }
@@ -1,4 +1,3 @@
1
- // @flow strict-local
2
1
  /* eslint-disable no-console, monorepo/no-internal-import */
3
2
  import type {ContentGraph, ContentKey, NodeId} from '@atlaspack/graph';
4
3
  import type {BundleGraphEdgeType} from '@atlaspack/core/src/BundleGraph';
@@ -11,7 +10,6 @@ import os from 'os';
11
10
  import nullthrows from 'nullthrows';
12
11
  import invariant from 'assert';
13
12
  import {serialize} from 'v8';
14
- // $FlowFixMe
15
13
  import {table} from 'table';
16
14
 
17
15
  import {loadGraphs} from './index';
@@ -33,7 +31,7 @@ export async function run(input: string[]) {
33
31
 
34
32
  try {
35
33
  fs.accessSync(cacheDir);
36
- } catch (e) {
34
+ } catch (e: any) {
37
35
  console.error("Can't find cache dir", cacheDir);
38
36
  process.exit(1);
39
37
  }
@@ -85,7 +83,7 @@ export async function run(input: string[]) {
85
83
  }
86
84
 
87
85
  function parseAssetLocator(v: string) {
88
- let id: ?string = null;
86
+ let id: string | null | undefined = null;
89
87
  if (v.length === 16) {
90
88
  id = v;
91
89
  } else {
@@ -138,7 +136,7 @@ export async function run(input: string[]) {
138
136
  }
139
137
 
140
138
  function getAsset(v: string) {
141
- let id: ?string = parseAssetLocator(v);
139
+ let id: string | null | undefined = parseAssetLocator(v);
142
140
 
143
141
  if (id == null) {
144
142
  console.log(null);
@@ -151,7 +149,7 @@ export async function run(input: string[]) {
151
149
  let asset = bundleGraph.getAssetById(id);
152
150
  console.log('Public id', bundleGraph.getAssetPublicId(asset));
153
151
  console.log(asset);
154
- } catch (e) {
152
+ } catch (e: any) {
155
153
  if (!hasAssetGraph()) {
156
154
  return;
157
155
  }
@@ -192,7 +190,7 @@ export async function run(input: string[]) {
192
190
  bundleGraph.getAssetById(node.id),
193
191
  )} ${fromProjectPathRelative(node.value.filePath)}`,
194
192
  );
195
- } catch (e) {
193
+ } catch (e: any) {
196
194
  console.log(fromProjectPathRelative(node.value.filePath));
197
195
  }
198
196
  }
@@ -246,7 +244,7 @@ export async function run(input: string[]) {
246
244
  bundleGraph.getAssetById(asset.id),
247
245
  )} ${fromProjectPathRelative(asset.value.filePath)}`,
248
246
  );
249
- } catch (e) {
247
+ } catch (e: any) {
250
248
  console.log(fromProjectPathRelative(asset.value.filePath));
251
249
  }
252
250
  if (binding === 'export' && asset.value.symbols) {
@@ -262,7 +260,7 @@ export async function run(input: string[]) {
262
260
  bundleGraph.getAssetById(locAsset.id),
263
261
  )} ${fromProjectPathRelative(locAsset.value.filePath)}`,
264
262
  );
265
- } catch (e) {
263
+ } catch (e: any) {
266
264
  console.log(
267
265
  `imported as ${symbolName} from ${fromProjectPathRelative(
268
266
  locAsset.value.filePath,
@@ -311,12 +309,12 @@ export async function run(input: string[]) {
311
309
  this.label = label;
312
310
  this.suffix = suffix;
313
311
  }
314
- add(v: T, label: string | void, suffix: string | void): Paths<T> {
312
+ add(v: T, label?: string, suffix?: string): Paths<T> {
315
313
  let next = new Paths(v, label, suffix);
316
314
  this.children.push(next);
317
315
  return next;
318
316
  }
319
- print(format: (T) => string, prefix = '') {
317
+ print(format: (arg1: T) => string, prefix = '') {
320
318
  console.log(
321
319
  `${prefix}${this.label} ${format(this.value)} ${this.suffix}`,
322
320
  );
@@ -335,7 +333,14 @@ export async function run(input: string[]) {
335
333
  let asset = nullthrows(parseAssetLocator(v), 'Asset not found');
336
334
 
337
335
  let paths = new Paths<NodeId>(graph.getNodeIdByContentKey(asset), ' ');
338
- let cb = (id, ctx, revisiting) => {
336
+ let cb = (
337
+ id: NodeId,
338
+ ctx: {
339
+ lazyOutgoing: boolean;
340
+ paths: Paths<NodeId>;
341
+ },
342
+ revisiting: boolean,
343
+ ) => {
339
344
  let {paths, lazyOutgoing} = ctx;
340
345
  let node = nullthrows(graph.getNode(id));
341
346
  if (node.id === asset) return ctx;
@@ -356,7 +361,13 @@ export async function run(input: string[]) {
356
361
 
357
362
  // like graph.dfs, but revisiting nodes and skipping its children
358
363
  let seen = new Set();
359
- function walk(id, ctx) {
364
+ function walk(
365
+ id: NodeId,
366
+ ctx: {
367
+ lazyOutgoing: boolean;
368
+ paths: Paths<NodeId>;
369
+ },
370
+ ) {
360
371
  let revisiting = seen.has(id);
361
372
  let newCtx = cb(id, ctx, revisiting);
362
373
  if (revisiting) return;
@@ -434,7 +445,7 @@ export async function run(input: string[]) {
434
445
  }
435
446
 
436
447
  // eslint-disable-next-line no-unused-vars
437
- function getBundles(_) {
448
+ function getBundles(_: any) {
438
449
  if (!hasBundleGraph()) {
439
450
  return;
440
451
  }
@@ -549,6 +560,7 @@ export async function run(input: string[]) {
549
560
  'Node is not a bundle, but a ' + node.type,
550
561
  );
551
562
 
563
+ // @ts-expect-error TS7006
552
564
  bundleGraph.traverseAssets(node.value, (asset) => {
553
565
  console.log(asset.id, asset.filePath);
554
566
  });
@@ -568,6 +580,7 @@ export async function run(input: string[]) {
568
580
  'Node is not a bundle, but a ' + node.type,
569
581
  );
570
582
 
583
+ // @ts-expect-error TS7006
571
584
  bundleGraph.traverseBundle(node.value, (node) => {
572
585
  if (node.type === 'asset') {
573
586
  console.log(node.id, node.value.filePath);
@@ -667,6 +680,7 @@ export async function run(input: string[]) {
667
680
  assetNodeId,
668
681
  )) {
669
682
  if (
683
+ // @ts-expect-error TS7006
670
684
  referencingBundles.some((ref) =>
671
685
  bundleGraph._graph.hasEdge(
672
686
  bundleGraph._graph.getNodeIdByContentKey(ref.id),
@@ -680,22 +694,33 @@ export async function run(input: string[]) {
680
694
  }
681
695
  }
682
696
 
683
- function _getIncomingNodeOfType(bundleGraph, node, type: string) {
697
+ function _getIncomingNodeOfType(
698
+ // @ts-expect-error TS2304
699
+ bundleGraph: BundleGraph,
700
+ // @ts-expect-error TS7006
701
+ node,
702
+ type: string,
703
+ ) {
684
704
  if (!hasBundleGraph()) {
685
705
  return;
686
706
  }
687
707
  invariant(bundleGraph != null);
688
708
  const bundleGraphNodeId = bundleGraph._graph.getNodeIdByContentKey(node.id);
689
- return bundleGraph._graph
690
- .getNodeIdsConnectedTo(bundleGraphNodeId, -1)
691
- .map((id) => nullthrows(bundleGraph._graph.getNode(id)))
692
- .find((node) => node.type == type);
709
+ return (
710
+ bundleGraph._graph
711
+ .getNodeIdsConnectedTo(bundleGraphNodeId, -1)
712
+ // @ts-expect-error TS7006
713
+ .map((id) => nullthrows(bundleGraph._graph.getNode(id)))
714
+ // @ts-expect-error TS7006
715
+ .find((node) => node.type == type)
716
+ );
693
717
  }
694
718
 
695
719
  // We find the priority of a Bundle or BundleGroup by looking at its incoming dependencies.
696
720
  // If a Bundle does not have an incoming dependency, we look for an incoming BundleGroup and its dependency
697
721
  // e.g. Dep(priority = 1) -> BundleGroup -> Bundle means that the Bundle has priority 1.
698
- function _getBundlePriority(bundleGraph, bundle) {
722
+ // @ts-expect-error TS2304
723
+ function _getBundlePriority(bundleGraph: BundleGraph, bundle: BundleNode) {
699
724
  if (!hasBundleGraph()) {
700
725
  return;
701
726
  }
@@ -715,7 +740,8 @@ export async function run(input: string[]) {
715
740
  return node.value.priority;
716
741
  }
717
742
 
718
- function _findEntryBundle(bundleGraph, node) {
743
+ // @ts-expect-error TS2304
744
+ function _findEntryBundle(bundleGraph: BundleGraph, node: BundleNode) {
719
745
  if (!hasBundleGraph()) {
720
746
  return;
721
747
  }
@@ -723,8 +749,10 @@ export async function run(input: string[]) {
723
749
  const bundleGraphNodeId = bundleGraph._graph.getNodeIdByContentKey(node.id);
724
750
  const entryBundleGroup = bundleGraph._graph
725
751
  .getNodeIdsConnectedTo(bundleGraphNodeId, -1)
752
+ // @ts-expect-error TS7006
726
753
  .map((id) => nullthrows(bundleGraph._graph.getNode(id)))
727
754
  .find(
755
+ // @ts-expect-error TS7006
728
756
  (node) =>
729
757
  node.type === 'bundle_group' &&
730
758
  bundleGraph.isEntryBundleGroup(node.value),
@@ -733,7 +761,7 @@ export async function run(input: string[]) {
733
761
  return entryBundleGroup;
734
762
  }
735
763
  // eslint-disable-next-line no-unused-vars
736
- function inspectCache(_) {
764
+ function inspectCache(_: any) {
737
765
  // displays sizing of various entries of the cache
738
766
  let table: Array<Array<string | number>> = [];
739
767
  table.push([
@@ -767,6 +795,7 @@ export async function run(input: string[]) {
767
795
  column.shift();
768
796
  invariant(column != null);
769
797
  return column.reduce(
798
+ // @ts-expect-error TS2365
770
799
  (accumulator, currentValue) => accumulator + currentValue,
771
800
  initialValue,
772
801
  );
@@ -780,13 +809,19 @@ export async function run(input: string[]) {
780
809
  _printStatsTable('Cache Info', table);
781
810
  }
782
811
 
783
- function timeSerialize(graph) {
812
+ function timeSerialize(
813
+ // @ts-expect-error TS2304
814
+ graph: AssetGraph | null | undefined | BundleGraph | RequestTracker,
815
+ ) {
784
816
  let date = Date.now();
785
817
  serialize(graph);
786
818
  date = Date.now() - date;
787
819
  return date;
788
820
  }
789
- function _printStatsTable(header, data) {
821
+ function _printStatsTable(
822
+ header: string,
823
+ data: Array<Array<string | number>> | Array<[string, unknown]>,
824
+ ) {
790
825
  const config = {
791
826
  columnDefault: {
792
827
  width: 18,
@@ -795,13 +830,13 @@ export async function run(input: string[]) {
795
830
  alignment: 'center',
796
831
  content: header,
797
832
  },
798
- };
833
+ } as const;
799
834
 
800
835
  console.log(table(data, config));
801
836
  }
802
837
 
803
838
  // eslint-disable-next-line no-unused-vars
804
- function stats(_) {
839
+ function stats(_: any) {
805
840
  let ag = {
806
841
  asset: 0,
807
842
  dependency: 0,
@@ -812,7 +847,7 @@ export async function run(input: string[]) {
812
847
  invariant(assetGraph != null);
813
848
  for (let n of assetGraph.nodes) {
814
849
  if (n && n.type in ag) {
815
- // $FlowFixMe
850
+ // @ts-expect-error TS7053
816
851
  ag[n.type]++;
817
852
  }
818
853
  }
@@ -839,7 +874,7 @@ export async function run(input: string[]) {
839
874
  sync: 0,
840
875
  };
841
876
 
842
- let b_ext = {};
877
+ let b_ext: Record<string, any> = {};
843
878
 
844
879
  const entries = new Set();
845
880
 
@@ -849,10 +884,8 @@ export async function run(input: string[]) {
849
884
  } else if (n?.type === 'bundle') {
850
885
  bg.bundle++;
851
886
 
852
- // $FlowFixMe
853
887
  b_ext[n.value.type] = (b_ext[n.value.type] || 0) + 1;
854
888
 
855
- // $FlowFixMe
856
889
  const entry_group = _findEntryBundle(bundleGraph, n);
857
890
 
858
891
  if (entry_group != null && !entries.has(entry_group.id)) {
@@ -874,7 +907,6 @@ export async function run(input: string[]) {
874
907
  }
875
908
  } else if (n?.type === 'asset') {
876
909
  if (
877
- // $FlowFixMe
878
910
  fromProjectPathRelative(n.value.filePath).includes('node_modules')
879
911
  ) {
880
912
  bg.asset_node_modules++;
@@ -899,6 +931,7 @@ export async function run(input: string[]) {
899
931
 
900
932
  let sum_b_type = 0;
901
933
  for (let k in b_type) {
934
+ // @ts-expect-error TS7053
902
935
  sum_b_type += b_type[k];
903
936
  }
904
937
 
@@ -929,19 +962,14 @@ export async function run(input: string[]) {
929
962
  });
930
963
 
931
964
  const server = repl.start({useColors: true, useGlobal: true});
932
- // $FlowFixMe[prop-missing]
933
965
  server.setupHistory(
934
966
  path.join(os.homedir(), '.parcel_query_history'),
935
967
  () => {},
936
968
  );
937
969
 
938
- // $FlowFixMe[prop-missing]
939
970
  server.context.bundleGraph = bundleGraph;
940
- // $FlowFixMe[prop-missing]
941
971
  server.context.assetGraph = assetGraph;
942
- // $FlowFixMe[prop-missing]
943
972
  server.context.requestTracker = requestTracker;
944
- // $FlowFixMe[prop-missing]
945
973
  server.context.cacheInfo = cacheInfo;
946
974
  for (let [name, cmd] of new Map([
947
975
  [
@@ -1060,6 +1088,7 @@ export async function run(input: string[]) {
1060
1088
  'findBundleReason',
1061
1089
  {
1062
1090
  help: 'args: <bundle> <asset>. Why is the asset in the bundle',
1091
+ // @ts-expect-error TS2556
1063
1092
  action: (v) => findBundleReason(...v.split(' ')),
1064
1093
  },
1065
1094
  ],
@@ -1106,16 +1135,11 @@ export async function run(input: string[]) {
1106
1135
  },
1107
1136
  ],
1108
1137
  ])) {
1109
- // $FlowFixMe
1110
1138
  server.context[name] = cmd.action;
1111
- // $FlowFixMe
1112
1139
  server.defineCommand(name, {
1113
- // $FlowFixMe
1114
1140
  help: '📦 ' + cmd.help,
1115
1141
  action: (v) => {
1116
- // $FlowFixMe
1117
1142
  server.clearBufferedCommand();
1118
- // $FlowFixMe
1119
1143
  try {
1120
1144
  cmd.action(v);
1121
1145
  } finally {
@@ -1,34 +1,28 @@
1
- // @flow
2
1
  /* eslint-disable monorepo/no-internal-import */
3
- import typeof AssetGraph from '@atlaspack/core/src/AssetGraph';
4
- import typeof BundleGraph, {
2
+ import AssetGraph from '@atlaspack/core/src/AssetGraph';
3
+ import BundleGraph, {
5
4
  bundleGraphEdgeTypes,
6
5
  } from '@atlaspack/core/src/BundleGraph';
7
- import typeof RequestTracker, {
6
+ import RequestTracker, {
8
7
  RequestGraph,
9
8
  readAndDeserializeRequestGraph,
10
9
  } from '@atlaspack/core/src/RequestTracker';
11
- import typeof {requestGraphEdgeTypes} from '@atlaspack/core/src/RequestTracker';
12
- import typeof {LMDBLiteCache} from '@atlaspack/cache/src/LMDBLiteCache';
13
- import typeof {Priority} from '@atlaspack/core/src/types';
14
- import typeof {fromProjectPathRelative} from '@atlaspack/core/src/projectPath';
10
+ import {requestGraphEdgeTypes} from '@atlaspack/core/src/RequestTracker';
11
+ import {LMDBLiteCache} from '@atlaspack/cache/src/LMDBLiteCache';
12
+ import {Priority} from '@atlaspack/core/src/types';
13
+ import {fromProjectPathRelative} from '@atlaspack/core/src/projectPath';
15
14
 
16
15
  const v =
17
- process.env.ATLASPACK_BUILD_ENV === 'production'
16
+ process.env.ATLASPACK_BUILD_ENV === 'production' ||
17
+ process.env.ATLASPACK_REGISTER_USE_SRC !== 'true'
18
18
  ? {
19
19
  // Split up require specifier to outsmart packages/dev/babel-register/babel-plugin-module-translate.js
20
- // $FlowFixMe(unsupported-syntax)
21
20
  AssetGraph: require('@atlaspack/core' + '/lib/AssetGraph').default,
22
- // $FlowFixMe(unsupported-syntax)
23
21
  BundleGraph: require('@atlaspack/core' + '/lib/BundleGraph'),
24
- // $FlowFixMe(unsupported-syntax)
25
22
  RequestTracker: require('@atlaspack/core' + '/lib/RequestTracker'),
26
- // $FlowFixMe(unsupported-syntax)
27
23
  LMDBLiteCache: require('@atlaspack/cache' + '/lib/LMDBLiteCache')
28
24
  .LMDBLiteCache,
29
- // $FlowFixMe(unsupported-syntax)
30
25
  Priority: require('@atlaspack/core' + '/lib/types').Priority,
31
- // $FlowFixMe(unsupported-syntax)
32
26
  fromProjectPathRelative: require('@atlaspack/core' + '/lib/projectPath')
33
27
  .fromProjectPathRelative,
34
28
  }
@@ -43,21 +37,24 @@ const v =
43
37
  .fromProjectPathRelative,
44
38
  };
45
39
 
46
- module.exports = (v: {|
47
- AssetGraph: AssetGraph,
40
+ module.exports = v as {
41
+ AssetGraph: AssetGraph;
48
42
  BundleGraph: {
49
- default: BundleGraph,
50
- bundleGraphEdgeTypes: bundleGraphEdgeTypes,
51
- ...
52
- },
43
+ default: BundleGraph;
44
+ // @ts-expect-error TS2749
45
+ bundleGraphEdgeTypes: bundleGraphEdgeTypes;
46
+ };
53
47
  RequestTracker: {
54
- default: RequestTracker,
55
- readAndDeserializeRequestGraph: readAndDeserializeRequestGraph,
56
- RequestGraph: RequestGraph,
57
- requestGraphEdgeTypes: requestGraphEdgeTypes,
58
- ...
59
- },
60
- LMDBLiteCache: LMDBLiteCache,
61
- Priority: Priority,
62
- fromProjectPathRelative: fromProjectPathRelative,
63
- |});
48
+ default: RequestTracker;
49
+ // @ts-expect-error TS2749
50
+ readAndDeserializeRequestGraph: readAndDeserializeRequestGraph;
51
+ RequestGraph: RequestGraph;
52
+ // @ts-expect-error TS2749
53
+ requestGraphEdgeTypes: requestGraphEdgeTypes;
54
+ };
55
+ LMDBLiteCache: LMDBLiteCache;
56
+ // @ts-expect-error TS2749
57
+ Priority: Priority;
58
+ // @ts-expect-error TS2749
59
+ fromProjectPathRelative: fromProjectPathRelative;
60
+ };
@@ -1,4 +1,3 @@
1
- // @flow strict-local
2
1
  /* eslint-disable no-console, monorepo/no-internal-import */
3
2
  import type {ContentKey, NodeId} from '@atlaspack/graph';
4
3
  import type {PackagedBundleInfo} from '@atlaspack/core/src/types';
@@ -16,15 +15,20 @@ const {
16
15
  requestGraphEdgeTypes,
17
16
  },
18
17
  LMDBLiteCache,
19
- } = require('./deep-imports.js');
20
-
21
- export async function loadGraphs(cacheDir: string): Promise<{|
22
- assetGraph: ?AssetGraph,
23
- bundleGraph: ?BundleGraph,
24
- requestTracker: ?RequestTracker,
25
- bundleInfo: ?Map<ContentKey, PackagedBundleInfo>,
26
- cacheInfo: ?Map<string, Array<string | number>>,
27
- |}> {
18
+ } = process.env.ATLASPACK_REGISTER_USE_SRC === 'true'
19
+ ? require('./deep-imports.js')
20
+ : require('./deep-imports.ts');
21
+
22
+ export async function loadGraphs(cacheDir: string): Promise<{
23
+ // @ts-expect-error TS2749
24
+ assetGraph: AssetGraph | null | undefined;
25
+ // @ts-expect-error TS2749
26
+ bundleGraph: BundleGraph | null | undefined;
27
+ // @ts-expect-error TS2749
28
+ requestTracker: RequestTracker | null | undefined;
29
+ bundleInfo: Map<ContentKey, PackagedBundleInfo> | null | undefined;
30
+ cacheInfo: Map<string, Array<string | number>> | null | undefined;
31
+ }> {
28
32
  let cacheInfo: Map<string, Array<string | number>> = new Map();
29
33
  const cache = new LMDBLiteCache(cacheDir);
30
34
 
@@ -54,6 +58,7 @@ export async function loadGraphs(cacheDir: string): Promise<{|
54
58
  console.log({requestGraphBlob, bundleGraphBlob, assetGraphBlob});
55
59
 
56
60
  // Get requestTracker
61
+ // @ts-expect-error TS7034
57
62
  let requestTracker;
58
63
  if (requestGraphBlob != null && requestGraphKey != null) {
59
64
  try {
@@ -74,15 +79,13 @@ export async function loadGraphs(cacheDir: string): Promise<{|
74
79
 
75
80
  requestTracker = new RequestTracker({
76
81
  graph: requestGraph,
77
- // $FlowFixMe
78
82
  farm: null,
79
- // $FlowFixMe
80
83
  options: null,
81
84
  });
82
85
  let timeToDeserialize = Date.now() - date;
83
86
  cacheInfo.set('RequestGraph', [bufferLength]);
84
87
  cacheInfo.get('RequestGraph')?.push(timeToDeserialize);
85
- } catch (e) {
88
+ } catch (e: any) {
86
89
  console.error('Error loading Request Graph\n', e);
87
90
  }
88
91
  }
@@ -101,7 +104,7 @@ export async function loadGraphs(cacheDir: string): Promise<{|
101
104
 
102
105
  cacheInfo.set('BundleGraph', [Buffer.byteLength(file)]);
103
106
  cacheInfo.get('BundleGraph')?.push(timeToDeserialize);
104
- } catch (e) {
107
+ } catch (e: any) {
105
108
  console.error('Error loading Bundle Graph\n', e);
106
109
  }
107
110
  }
@@ -121,15 +124,19 @@ export async function loadGraphs(cacheDir: string): Promise<{|
121
124
 
122
125
  cacheInfo.set('AssetGraph', [Buffer.byteLength(file)]);
123
126
  cacheInfo.get('AssetGraph')?.push(timeToDeserialize);
124
- } catch (e) {
127
+ } catch (e: any) {
125
128
  console.error('Error loading Asset Graph\n', e);
126
129
  }
127
130
  }
128
131
 
129
132
  function getSubRequests(id: NodeId) {
130
- return requestTracker.graph
131
- .getNodeIdsConnectedFrom(id, requestGraphEdgeTypes.subrequest)
132
- .map((n) => nullthrows(requestTracker.graph.getNode(n)));
133
+ return (
134
+ // @ts-expect-error TS7005
135
+ requestTracker.graph
136
+ .getNodeIdsConnectedFrom(id, requestGraphEdgeTypes.subrequest)
137
+ // @ts-expect-error TS7006
138
+ .map((n) => nullthrows(requestTracker.graph.getNode(n)))
139
+ );
133
140
  }
134
141
 
135
142
  // Load graphs by finding the main subrequests and loading their results
@@ -148,17 +155,17 @@ export async function loadGraphs(cacheDir: string): Promise<{|
148
155
  let buildRequestSubRequests = getSubRequests(buildRequestId);
149
156
 
150
157
  let writeBundlesRequest = buildRequestSubRequests.find(
158
+ // @ts-expect-error TS7006
151
159
  (n) => n.type === 1 && n.requestType === 11,
152
160
  );
153
161
  if (writeBundlesRequest != null) {
154
162
  invariant(writeBundlesRequest.type === 1);
155
- // $FlowFixMe[incompatible-cast]
156
- bundleInfo = (nullthrows(writeBundlesRequest.result): Map<
163
+ bundleInfo = nullthrows(writeBundlesRequest.result) as Map<
157
164
  ContentKey,
158
- PackagedBundleInfo,
159
- >);
165
+ PackagedBundleInfo
166
+ >;
160
167
  }
161
- } catch (e) {
168
+ } catch (e: any) {
162
169
  console.error('Error loading bundleInfo\n', e);
163
170
  }
164
171
 
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "include": ["src"]
4
+ }