metro 0.71.2 → 0.72.1

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 (91) hide show
  1. package/package.json +21 -21
  2. package/src/Assets.js +3 -2
  3. package/src/Assets.js.flow +3 -2
  4. package/src/Bundler.js +11 -2
  5. package/src/Bundler.js.flow +7 -1
  6. package/src/DeltaBundler/DeltaCalculator.js +85 -21
  7. package/src/DeltaBundler/DeltaCalculator.js.flow +63 -8
  8. package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +1 -3
  9. package/src/DeltaBundler/Transformer.js +27 -4
  10. package/src/DeltaBundler/Transformer.js.flow +18 -2
  11. package/src/DeltaBundler/Worker.flow.js +45 -1
  12. package/src/DeltaBundler/Worker.flow.js.flow +42 -1
  13. package/src/DeltaBundler/WorkerFarm.js +3 -2
  14. package/src/DeltaBundler/WorkerFarm.js.flow +5 -3
  15. package/src/DeltaBundler/graphOperations.js +170 -63
  16. package/src/DeltaBundler/graphOperations.js.flow +144 -64
  17. package/src/DeltaBundler/types.flow.js.flow +11 -5
  18. package/src/HmrServer.js +2 -0
  19. package/src/HmrServer.js.flow +2 -0
  20. package/src/IncrementalBundler.js +6 -0
  21. package/src/IncrementalBundler.js.flow +6 -0
  22. package/src/ModuleGraph/node-haste/HasteFS.js.flow +1 -1
  23. package/src/ModuleGraph/node-haste/node-haste.js +14 -7
  24. package/src/ModuleGraph/node-haste/node-haste.js.flow +35 -10
  25. package/src/ModuleGraph/output/indexed-ram-bundle.js.flow +5 -13
  26. package/src/ModuleGraph/output/multiple-files-ram-bundle.js.flow +4 -14
  27. package/src/ModuleGraph/output/util.js +1 -0
  28. package/src/ModuleGraph/output/util.js.flow +4 -3
  29. package/src/ModuleGraph/silent-console.js +5 -4
  30. package/src/ModuleGraph/silent-console.js.flow +8 -4
  31. package/src/ModuleGraph/worker/collectDependencies.js +19 -30
  32. package/src/ModuleGraph/worker/collectDependencies.js.flow +28 -43
  33. package/src/Server.js +8 -0
  34. package/src/Server.js.flow +48 -12
  35. package/src/cli-utils.js.flow +1 -1
  36. package/src/commands/build.js +1 -2
  37. package/src/commands/build.js.flow +6 -9
  38. package/src/commands/dependencies.js +1 -1
  39. package/src/commands/serve.js +2 -1
  40. package/src/commands/serve.js.flow +7 -8
  41. package/src/index.flow.js +11 -8
  42. package/src/index.flow.js.flow +10 -7
  43. package/src/integration_tests/basic_bundle/require-context/conflict.js +25 -0
  44. package/src/integration_tests/basic_bundle/require-context/conflict.js.flow +27 -0
  45. package/src/integration_tests/basic_bundle/require-context/empty.js +29 -0
  46. package/src/integration_tests/basic_bundle/require-context/empty.js.flow +26 -0
  47. package/src/integration_tests/basic_bundle/require-context/matching.js +26 -0
  48. package/src/integration_tests/basic_bundle/require-context/matching.js.flow +27 -0
  49. package/src/integration_tests/basic_bundle/require-context/mode-eager.js +22 -0
  50. package/src/integration_tests/basic_bundle/require-context/mode-eager.js.flow +24 -0
  51. package/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js +22 -0
  52. package/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js.flow +24 -0
  53. package/src/integration_tests/basic_bundle/require-context/mode-lazy.js +22 -0
  54. package/src/integration_tests/basic_bundle/require-context/mode-lazy.js.flow +24 -0
  55. package/src/integration_tests/basic_bundle/require-context/mode-sync.js +20 -0
  56. package/src/integration_tests/basic_bundle/require-context/mode-sync.js.flow +22 -0
  57. package/src/integration_tests/basic_bundle/require-context/subdir/a.js +12 -0
  58. package/src/integration_tests/basic_bundle/require-context/subdir/a.js.flow +11 -0
  59. package/src/integration_tests/basic_bundle/require-context/subdir/b.js +18 -0
  60. package/src/integration_tests/basic_bundle/require-context/subdir/b.js.flow +11 -0
  61. package/src/integration_tests/basic_bundle/require-context/subdir/c.js +12 -0
  62. package/src/integration_tests/basic_bundle/require-context/subdir/c.js.flow +11 -0
  63. package/src/integration_tests/basic_bundle/require-context/subdir/nested/d.js +12 -0
  64. package/src/integration_tests/basic_bundle/require-context/subdir/nested/d.js.flow +11 -0
  65. package/src/integration_tests/basic_bundle/require-context/subdir-conflict/index.js +12 -0
  66. package/src/integration_tests/basic_bundle/require-context/subdir-conflict/index.js.flow +11 -0
  67. package/src/integration_tests/basic_bundle/require-context/utils.js +29 -0
  68. package/src/integration_tests/basic_bundle/require-context/utils.js.flow +44 -0
  69. package/src/lib/CountingSet.js +1 -0
  70. package/src/lib/CountingSet.js.flow +1 -0
  71. package/src/lib/contextModule.js +80 -0
  72. package/src/lib/contextModule.js.flow +86 -0
  73. package/src/lib/contextModuleTemplates.js +186 -0
  74. package/src/lib/contextModuleTemplates.js.flow +148 -0
  75. package/src/lib/getGraphId.js +2 -1
  76. package/src/lib/getGraphId.js.flow +3 -0
  77. package/src/lib/getPrependedScripts.js +2 -0
  78. package/src/lib/getPrependedScripts.js.flow +2 -0
  79. package/src/lib/parseOptionsFromUrl.js.flow +7 -18
  80. package/src/lib/transformHelpers.js +41 -9
  81. package/src/lib/transformHelpers.js.flow +46 -9
  82. package/src/node-haste/DependencyGraph/ModuleResolution.js +1 -0
  83. package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +3 -2
  84. package/src/node-haste/DependencyGraph/createHasteMap.js +7 -1
  85. package/src/node-haste/DependencyGraph/createHasteMap.js.flow +8 -2
  86. package/src/node-haste/DependencyGraph.js +7 -0
  87. package/src/node-haste/DependencyGraph.js.flow +17 -2
  88. package/src/shared/output/bundle.flow.js +67 -0
  89. package/src/shared/output/bundle.flow.js.flow +89 -0
  90. package/src/shared/output/bundle.js +8 -55
  91. package/src/shared/output/bundle.js.flow +8 -75
package/src/index.flow.js CHANGED
@@ -355,22 +355,25 @@ exports.buildGraph = async function (
355
355
 
356
356
  exports.attachMetroCli = function (
357
357
  yargs,
358
- { build = {}, serve = {}, dependencies = {} } = {}
358
+ // $FlowFixMe[prop-missing]
359
+ {
360
+ build = {},
361
+ serve = {},
362
+ dependencies = {}
363
+ } = {} // prettier-ignore
359
364
  ) {
365
+ yargs.strict();
366
+
360
367
  if (build) {
361
- const { command, description, builder, handler } = makeBuildCommand();
362
- yargs.command(command, description, builder, handler);
368
+ yargs.command(makeBuildCommand());
363
369
  }
364
370
 
365
371
  if (serve) {
366
- const { command, description, builder, handler } = makeServeCommand();
367
- yargs.command(command, description, builder, handler);
372
+ yargs.command(makeServeCommand());
368
373
  }
369
374
 
370
375
  if (dependencies) {
371
- const { command, description, builder, handler } =
372
- makeDependenciesCommand();
373
- yargs.command(command, description, builder, handler);
376
+ yargs.command(makeDependenciesCommand());
374
377
  }
375
378
 
376
379
  return yargs;
@@ -448,20 +448,23 @@ exports.attachMetroCli = function (
448
448
  serve: ServeCommandOptions,
449
449
  dependencies: any,
450
450
  ...
451
- } = {},
451
+ }
452
+ // prettier-ignore
453
+ // $FlowFixMe[prop-missing]
454
+ = {},
452
455
  ): Yargs {
456
+ yargs.strict();
457
+
453
458
  if (build) {
454
- const {command, description, builder, handler} = makeBuildCommand();
455
- yargs.command(command, description, builder, handler);
459
+ yargs.command(makeBuildCommand());
456
460
  }
457
461
  if (serve) {
458
- const {command, description, builder, handler} = makeServeCommand();
459
- yargs.command(command, description, builder, handler);
462
+ yargs.command(makeServeCommand());
460
463
  }
461
464
  if (dependencies) {
462
- const {command, description, builder, handler} = makeDependenciesCommand();
463
- yargs.command(command, description, builder, handler);
465
+ yargs.command(makeDependenciesCommand());
464
466
  }
467
+
465
468
  return yargs;
466
469
  };
467
470
 
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ var _utils = require("./utils");
4
+
5
+ /**
6
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
7
+ *
8
+ * This source code is licensed under the MIT license found in the
9
+ * LICENSE file in the root directory of this source tree.
10
+ *
11
+ * @format
12
+ *
13
+ */
14
+ const normalModule = require("./subdir-conflict");
15
+
16
+ const contextModule = require.context("./subdir-conflict");
17
+
18
+ function main() {
19
+ return {
20
+ normalModule,
21
+ contextModule: (0, _utils.copyContextToObject)(contextModule),
22
+ };
23
+ }
24
+
25
+ module.exports = main();
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict-local
9
+ */
10
+
11
+ import type {RequireWithContext} from './utils';
12
+
13
+ import {copyContextToObject} from './utils';
14
+
15
+ declare var require: RequireWithContext;
16
+
17
+ const normalModule = require('./subdir-conflict');
18
+ const contextModule = require.context('./subdir-conflict');
19
+
20
+ function main() {
21
+ return {
22
+ normalModule,
23
+ contextModule: copyContextToObject(contextModule),
24
+ };
25
+ }
26
+
27
+ module.exports = (main(): mixed);
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ *
9
+ * @format
10
+ *
11
+ */
12
+ const empty = require.context("./no-such-dir");
13
+
14
+ function main() {
15
+ try {
16
+ empty("./no-such-file.js");
17
+ } catch (e) {
18
+ return {
19
+ error: {
20
+ message: e.message,
21
+ code: e.code,
22
+ },
23
+ };
24
+ }
25
+
26
+ return null;
27
+ }
28
+
29
+ module.exports = main();
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict-local
9
+ */
10
+
11
+ import type {RequireWithContext} from './utils';
12
+
13
+ declare var require: RequireWithContext;
14
+
15
+ const empty = require.context('./no-such-dir');
16
+
17
+ function main() {
18
+ try {
19
+ empty('./no-such-file.js');
20
+ } catch (e) {
21
+ return {error: {message: e.message, code: e.code}};
22
+ }
23
+ return null;
24
+ }
25
+
26
+ module.exports = (main(): mixed);
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ *
9
+ * @format
10
+ *
11
+ */
12
+ const ab = require.context("./subdir", false, /\/(a|b)\.js$/);
13
+
14
+ const abc = require.context("./subdir", false);
15
+
16
+ const abcd = require.context("./subdir", true);
17
+
18
+ function main() {
19
+ return {
20
+ ab: ab.keys(),
21
+ abc: abc.keys(),
22
+ abcd: abcd.keys(),
23
+ };
24
+ }
25
+
26
+ module.exports = main();
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict-local
9
+ */
10
+
11
+ import type {RequireWithContext} from './utils';
12
+
13
+ declare var require: RequireWithContext;
14
+
15
+ const ab = require.context('./subdir', false, /\/(a|b)\.js$/);
16
+ const abc = require.context('./subdir', false);
17
+ const abcd = require.context('./subdir', true);
18
+
19
+ function main() {
20
+ return {
21
+ ab: ab.keys(),
22
+ abc: abc.keys(),
23
+ abcd: abcd.keys(),
24
+ };
25
+ }
26
+
27
+ module.exports = (main(): mixed);
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ var _utils = require("./utils");
4
+
5
+ /**
6
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
7
+ *
8
+ * This source code is licensed under the MIT license found in the
9
+ * LICENSE file in the root directory of this source tree.
10
+ *
11
+ * @format
12
+ *
13
+ */
14
+ function main() {
15
+ return (0, _utils.awaitProperties)(
16
+ (0, _utils.copyContextToObject)(
17
+ require.context("./subdir", undefined, undefined, "eager")
18
+ )
19
+ );
20
+ }
21
+
22
+ module.exports = main();
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict-local
9
+ */
10
+
11
+ import {copyContextToObject, awaitProperties} from './utils';
12
+ import type {RequireWithContext} from './utils';
13
+
14
+ declare var require: RequireWithContext;
15
+
16
+ function main() {
17
+ return awaitProperties(
18
+ copyContextToObject(
19
+ require.context('./subdir', undefined, undefined, 'eager'),
20
+ ),
21
+ );
22
+ }
23
+
24
+ module.exports = (main(): mixed);
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ var _utils = require("./utils");
4
+
5
+ /**
6
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
7
+ *
8
+ * This source code is licensed under the MIT license found in the
9
+ * LICENSE file in the root directory of this source tree.
10
+ *
11
+ * @format
12
+ *
13
+ */
14
+ function main() {
15
+ return (0, _utils.awaitProperties)(
16
+ (0, _utils.copyContextToObject)(
17
+ require.context("./subdir", undefined, undefined, "lazy-once")
18
+ )
19
+ );
20
+ }
21
+
22
+ module.exports = main();
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict-local
9
+ */
10
+
11
+ import {copyContextToObject, awaitProperties} from './utils';
12
+ import type {RequireWithContext} from './utils';
13
+
14
+ declare var require: RequireWithContext;
15
+
16
+ function main() {
17
+ return awaitProperties(
18
+ copyContextToObject(
19
+ require.context('./subdir', undefined, undefined, 'lazy-once'),
20
+ ),
21
+ );
22
+ }
23
+
24
+ module.exports = (main(): mixed);
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ var _utils = require("./utils");
4
+
5
+ /**
6
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
7
+ *
8
+ * This source code is licensed under the MIT license found in the
9
+ * LICENSE file in the root directory of this source tree.
10
+ *
11
+ * @format
12
+ *
13
+ */
14
+ function main() {
15
+ return (0, _utils.awaitProperties)(
16
+ (0, _utils.copyContextToObject)(
17
+ require.context("./subdir", undefined, undefined, "lazy")
18
+ )
19
+ );
20
+ }
21
+
22
+ module.exports = main();
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict-local
9
+ */
10
+
11
+ import {copyContextToObject, awaitProperties} from './utils';
12
+ import type {RequireWithContext} from './utils';
13
+
14
+ declare var require: RequireWithContext;
15
+
16
+ function main() {
17
+ return awaitProperties(
18
+ copyContextToObject(
19
+ require.context('./subdir', undefined, undefined, 'lazy'),
20
+ ),
21
+ );
22
+ }
23
+
24
+ module.exports = (main(): mixed);
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ var _utils = require("./utils");
4
+
5
+ /**
6
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
7
+ *
8
+ * This source code is licensed under the MIT license found in the
9
+ * LICENSE file in the root directory of this source tree.
10
+ *
11
+ * @format
12
+ *
13
+ */
14
+ function main() {
15
+ return (0, _utils.copyContextToObject)(
16
+ require.context("./subdir", undefined, undefined, "sync")
17
+ );
18
+ }
19
+
20
+ module.exports = main();
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict-local
9
+ */
10
+
11
+ import {copyContextToObject} from './utils';
12
+ import type {RequireWithContext} from './utils';
13
+
14
+ declare var require: RequireWithContext;
15
+
16
+ function main() {
17
+ return copyContextToObject(
18
+ require.context('./subdir', undefined, undefined, 'sync'),
19
+ );
20
+ }
21
+
22
+ module.exports = (main(): mixed);
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ *
9
+ * @format
10
+ *
11
+ */
12
+ module.exports = "a";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict
9
+ */
10
+
11
+ module.exports = 'a';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = void 0;
7
+
8
+ /**
9
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
10
+ *
11
+ * This source code is licensed under the MIT license found in the
12
+ * LICENSE file in the root directory of this source tree.
13
+ *
14
+ * @format
15
+ *
16
+ */
17
+ var _default = "b";
18
+ exports.default = _default;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict
9
+ */
10
+
11
+ export default 'b';
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ *
9
+ * @format
10
+ *
11
+ */
12
+ module.exports = "c";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict
9
+ */
10
+
11
+ module.exports = 'c';
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ *
9
+ * @format
10
+ *
11
+ */
12
+ module.exports = "d";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict
9
+ */
10
+
11
+ module.exports = 'd';
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ *
9
+ * @format
10
+ *
11
+ */
12
+ module.exports = "contents of subdir-conflict/index.js";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict
9
+ */
10
+
11
+ module.exports = 'contents of subdir-conflict/index.js';
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.copyContextToObject = copyContextToObject;
7
+ exports.awaitProperties = awaitProperties;
8
+
9
+ /**
10
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
11
+ *
12
+ * This source code is licensed under the MIT license found in the
13
+ * LICENSE file in the root directory of this source tree.
14
+ *
15
+ * @format
16
+ *
17
+ */
18
+ function copyContextToObject(ctx) {
19
+ return Object.fromEntries(ctx.keys().map((key) => [key, ctx(key)]));
20
+ }
21
+
22
+ function awaitProperties(obj) {
23
+ const result = {};
24
+ return Promise.all(
25
+ Object.keys(obj).map((key) => {
26
+ return obj[key].then((value) => (result[key] = value));
27
+ })
28
+ ).then(() => result);
29
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow
9
+ */
10
+
11
+ type ContextModule<T> = {
12
+ (key: string): T,
13
+ keys(): Array<string>,
14
+ };
15
+
16
+ export type RequireWithContext = {
17
+ (id: string): any,
18
+ resolve: (id: string, options?: {paths?: Array<string>, ...}) => string,
19
+ cache: any,
20
+ main: typeof module,
21
+ context<T>(
22
+ name: string,
23
+ recursive?: boolean,
24
+ filter?: RegExp,
25
+ mode?: 'sync' | 'eager' | 'lazy' | 'lazy-once',
26
+ ): ContextModule<T>,
27
+ };
28
+
29
+ export function copyContextToObject<T>(ctx: ContextModule<T>): {
30
+ [key: string]: T,
31
+ } {
32
+ return Object.fromEntries(ctx.keys().map(key => [key, ctx(key)]));
33
+ }
34
+
35
+ export function awaitProperties<T>(
36
+ obj: $ReadOnly<{[key: string]: Promise<T>}>,
37
+ ): Promise<{[key: string]: T}> {
38
+ const result = {};
39
+ return Promise.all(
40
+ Object.keys(obj).map(key => {
41
+ return obj[key].then(value => (result[key] = value));
42
+ }),
43
+ ).then(() => result);
44
+ }
@@ -68,6 +68,7 @@ class CountingSet {
68
68
  }
69
69
  } // Iterate over unique entries
70
70
  // $FlowIssue[unsupported-syntax]
71
+ // $FlowFixMe[missing-local-annot]
71
72
 
72
73
  [Symbol.iterator]() {
73
74
  return this.values();
@@ -81,6 +81,7 @@ export default class CountingSet<T> implements ReadOnlyCountingSet<T> {
81
81
 
82
82
  // Iterate over unique entries
83
83
  // $FlowIssue[unsupported-syntax]
84
+ // $FlowFixMe[missing-local-annot]
84
85
  [Symbol.iterator](): Iterator<T> {
85
86
  return this.values();
86
87
  }