metro 0.70.3 → 0.71.2

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/package.json +23 -22
  2. package/src/Assets.js.flow +4 -4
  3. package/src/Bundler/util.js +1 -1
  4. package/src/Bundler/util.js.flow +2 -2
  5. package/src/Bundler.js +15 -10
  6. package/src/Bundler.js.flow +19 -14
  7. package/src/DeltaBundler/DeltaCalculator.js +13 -17
  8. package/src/DeltaBundler/DeltaCalculator.js.flow +15 -20
  9. package/src/DeltaBundler/Serializers/getAllFiles.js.flow +2 -2
  10. package/src/DeltaBundler/Serializers/getAssets.js.flow +2 -2
  11. package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +4 -4
  12. package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +6 -6
  13. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js.flow +4 -4
  14. package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js.flow +2 -2
  15. package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +2 -2
  16. package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +2 -2
  17. package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +6 -6
  18. package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +4 -4
  19. package/src/DeltaBundler/Serializers/sourceMapString.js.flow +2 -2
  20. package/src/DeltaBundler/Worker.flow.js +78 -0
  21. package/src/DeltaBundler/Worker.flow.js.flow +121 -0
  22. package/src/DeltaBundler/Worker.js +8 -66
  23. package/src/DeltaBundler/Worker.js.flow +8 -107
  24. package/src/DeltaBundler/WorkerFarm.js.flow +4 -4
  25. package/src/DeltaBundler/__fixtures__/hasteImpl.js +4 -0
  26. package/src/DeltaBundler/getTransformCacheKey.js.flow +2 -2
  27. package/src/DeltaBundler/graphOperations.js +641 -0
  28. package/src/DeltaBundler/graphOperations.js.flow +752 -0
  29. package/src/DeltaBundler/types.flow.js +6 -0
  30. package/src/DeltaBundler/types.flow.js.flow +43 -31
  31. package/src/DeltaBundler.js +12 -6
  32. package/src/DeltaBundler.js.flow +14 -10
  33. package/src/HmrServer.js +0 -2
  34. package/src/HmrServer.js.flow +7 -8
  35. package/src/IncrementalBundler.js +1 -1
  36. package/src/IncrementalBundler.js.flow +8 -8
  37. package/src/ModuleGraph/node-haste/ModuleCache.js +1 -1
  38. package/src/ModuleGraph/node-haste/ModuleCache.js.flow +1 -1
  39. package/src/ModuleGraph/node-haste/node-haste.flow.js +0 -1
  40. package/src/ModuleGraph/node-haste/node-haste.flow.js.flow +3 -4
  41. package/src/ModuleGraph/node-haste/node-haste.js +4 -4
  42. package/src/ModuleGraph/node-haste/node-haste.js.flow +13 -7
  43. package/src/ModuleGraph/output/indexed-ram-bundle.js.flow +2 -2
  44. package/src/ModuleGraph/output/plain-bundle.js.flow +2 -2
  45. package/src/ModuleGraph/output/reverse-dependency-map-references.js.flow +8 -8
  46. package/src/ModuleGraph/output/util.js.flow +2 -2
  47. package/src/ModuleGraph/types.flow.js.flow +37 -37
  48. package/src/ModuleGraph/worker/collectDependencies.js +215 -8
  49. package/src/ModuleGraph/worker/collectDependencies.js.flow +230 -13
  50. package/src/Server/symbolicate.js.flow +1 -1
  51. package/src/Server.js.flow +18 -18
  52. package/src/cli.js +5 -0
  53. package/src/cli.js.flow +5 -0
  54. package/src/commands/build.js +4 -3
  55. package/src/commands/build.js.flow +5 -3
  56. package/src/commands/serve.js +3 -3
  57. package/src/commands/serve.js.flow +5 -3
  58. package/src/index.flow.js +392 -0
  59. package/src/index.flow.js.flow +480 -0
  60. package/src/index.js +8 -366
  61. package/src/index.js.flow +8 -456
  62. package/src/lib/CountingSet.js +116 -0
  63. package/src/lib/CountingSet.js.flow +126 -0
  64. package/src/lib/JsonReporter.js +0 -2
  65. package/src/lib/JsonReporter.js.flow +1 -1
  66. package/src/lib/bundleToBytecode.js.flow +2 -2
  67. package/src/lib/bundleToString.js.flow +2 -2
  68. package/src/lib/getAppendScripts.js +10 -4
  69. package/src/lib/getAppendScripts.js.flow +6 -4
  70. package/src/lib/getPreludeCode.js +19 -1
  71. package/src/lib/getPreludeCode.js.flow +17 -2
  72. package/src/lib/getPrependedScripts.js +10 -2
  73. package/src/lib/getPrependedScripts.js.flow +11 -2
  74. package/src/lib/reporting.js +0 -2
  75. package/src/lib/reporting.js.flow +2 -1
  76. package/src/lib/transformHelpers.js.flow +2 -2
  77. package/src/node-haste/DependencyGraph/ModuleResolution.js +17 -4
  78. package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +20 -12
  79. package/src/node-haste/DependencyGraph/createHasteMap.js +80 -19
  80. package/src/node-haste/DependencyGraph/createHasteMap.js.flow +16 -14
  81. package/src/node-haste/DependencyGraph.js +31 -29
  82. package/src/node-haste/DependencyGraph.js.flow +44 -38
  83. package/src/node-haste/ModuleCache.js.flow +1 -1
  84. package/src/node-haste/lib/AssetPaths.js.flow +2 -2
  85. package/src/node-haste/lib/parsePlatformFilePath.js.flow +2 -2
  86. package/src/shared/output/RamBundle/as-indexed-file.js.flow +1 -1
  87. package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +2 -2
  88. package/src/shared/types.flow.js.flow +14 -14
  89. package/src/DeltaBundler/computeDelta.js +0 -42
  90. package/src/DeltaBundler/computeDelta.js.flow +0 -47
  91. package/src/DeltaBundler/traverseDependencies.js +0 -470
  92. package/src/DeltaBundler/traverseDependencies.js.flow +0 -565
  93. package/src/node-haste/DependencyGraph/types.js +0 -10
  94. package/src/node-haste/DependencyGraph/types.js.flow +0 -88
@@ -10,7 +10,7 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- const {Writable} = require('stream');
13
+ import type {Writable} from 'stream';
14
14
 
15
15
  class JsonReporter<TEvent: {[string]: any, ...}> {
16
16
  _stream: Writable;
@@ -49,10 +49,10 @@ function addModuleHeader(buffer: Buffer): [Buffer, Buffer] {
49
49
  * ...
50
50
  *
51
51
  */
52
- function bundleToBytecode(bundle: BytecodeBundle): {|
52
+ function bundleToBytecode(bundle: BytecodeBundle): {
53
53
  +bytecode: Buffer,
54
54
  +metadata: BundleMetadata,
55
- |} {
55
+ } {
56
56
  const buffers = [];
57
57
 
58
58
  if (bundle.pre.length) {
@@ -18,10 +18,10 @@ import type {
18
18
  /**
19
19
  * Serializes a bundle into a plain JS bundle.
20
20
  */
21
- function bundleToString(bundle: Bundle): {|
21
+ function bundleToString(bundle: Bundle): {
22
22
  +code: string,
23
23
  +metadata: BundleMetadata,
24
- |} {
24
+ } {
25
25
  let code = bundle.pre.length > 0 ? bundle.pre + '\n' : '';
26
26
  const modules = [];
27
27
 
@@ -9,6 +9,12 @@
9
9
  */
10
10
  "use strict";
11
11
 
12
+ var _CountingSet = _interopRequireDefault(require("./CountingSet"));
13
+
14
+ function _interopRequireDefault(obj) {
15
+ return obj && obj.__esModule ? obj : { default: obj };
16
+ }
17
+
12
18
  const getInlineSourceMappingURL = require("../DeltaBundler/Serializers/helpers/getInlineSourceMappingURL");
13
19
 
14
20
  const sourceMapString = require("../DeltaBundler/Serializers/sourceMapString");
@@ -38,7 +44,7 @@ function getAppendScripts(entryPoint, modules, importBundleNames, options) {
38
44
  path: "$$importBundleNames",
39
45
  dependencies: new Map(),
40
46
  getSource: () => Buffer.from(""),
41
- inverseDependencies: new Set(),
47
+ inverseDependencies: new _CountingSet.default(),
42
48
  output: [
43
49
  {
44
50
  type: "js/script/virtual",
@@ -64,7 +70,7 @@ function getAppendScripts(entryPoint, modules, importBundleNames, options) {
64
70
  path: `require-${path}`,
65
71
  dependencies: new Map(),
66
72
  getSource: () => Buffer.from(""),
67
- inverseDependencies: new Set(),
73
+ inverseDependencies: new _CountingSet.default(),
68
74
  output: [
69
75
  {
70
76
  type: "js/script/virtual",
@@ -94,7 +100,7 @@ function getAppendScripts(entryPoint, modules, importBundleNames, options) {
94
100
  path: "source-map",
95
101
  dependencies: new Map(),
96
102
  getSource: () => Buffer.from(""),
97
- inverseDependencies: new Set(),
103
+ inverseDependencies: new _CountingSet.default(),
98
104
  output: [
99
105
  {
100
106
  type: "js/script/virtual",
@@ -114,7 +120,7 @@ function getAppendScripts(entryPoint, modules, importBundleNames, options) {
114
120
  path: "source-url",
115
121
  dependencies: new Map(),
116
122
  getSource: () => Buffer.from(""),
117
- inverseDependencies: new Set(),
123
+ inverseDependencies: new _CountingSet.default(),
118
124
  output: [
119
125
  {
120
126
  type: "js/script/virtual",
@@ -12,6 +12,8 @@
12
12
 
13
13
  import type {Module} from '../DeltaBundler';
14
14
 
15
+ import CountingSet from './CountingSet';
16
+
15
17
  const getInlineSourceMappingURL = require('../DeltaBundler/Serializers/helpers/getInlineSourceMappingURL');
16
18
  const sourceMapString = require('../DeltaBundler/Serializers/sourceMapString');
17
19
  const countLines = require('./countLines');
@@ -56,7 +58,7 @@ function getAppendScripts<T: number | string>(
56
58
  path: '$$importBundleNames',
57
59
  dependencies: new Map(),
58
60
  getSource: (): Buffer => Buffer.from(''),
59
- inverseDependencies: new Set(),
61
+ inverseDependencies: new CountingSet(),
60
62
  output: [
61
63
  {
62
64
  type: 'js/script/virtual',
@@ -82,7 +84,7 @@ function getAppendScripts<T: number | string>(
82
84
  path: `require-${path}`,
83
85
  dependencies: new Map(),
84
86
  getSource: (): Buffer => Buffer.from(''),
85
- inverseDependencies: new Set(),
87
+ inverseDependencies: new CountingSet(),
86
88
  output: [
87
89
  {
88
90
  type: 'js/script/virtual',
@@ -113,7 +115,7 @@ function getAppendScripts<T: number | string>(
113
115
  path: 'source-map',
114
116
  dependencies: new Map(),
115
117
  getSource: (): Buffer => Buffer.from(''),
116
- inverseDependencies: new Set(),
118
+ inverseDependencies: new CountingSet(),
117
119
  output: [
118
120
  {
119
121
  type: 'js/script/virtual',
@@ -133,7 +135,7 @@ function getAppendScripts<T: number | string>(
133
135
  path: 'source-url',
134
136
  dependencies: new Map(),
135
137
  getSource: (): Buffer => Buffer.from(''),
136
- inverseDependencies: new Set(),
138
+ inverseDependencies: new CountingSet(),
137
139
  output: [
138
140
  {
139
141
  type: 'js/script/virtual',
@@ -9,14 +9,32 @@
9
9
  */
10
10
  "use strict";
11
11
 
12
- function getPreludeCode({ extraVars, isDev, globalPrefix }) {
12
+ function getPreludeCode({
13
+ extraVars,
14
+ isDev,
15
+ globalPrefix,
16
+ requireCycleIgnorePatterns,
17
+ }) {
13
18
  const vars = [
19
+ // Ensure these variable names match the ones referenced in metro-runtime
20
+ // require.js
14
21
  "__BUNDLE_START_TIME__=this.nativePerformanceNow?nativePerformanceNow():Date.now()",
15
22
  `__DEV__=${String(isDev)}`,
16
23
  ...formatExtraVars(extraVars),
17
24
  "process=this.process||{}",
18
25
  `__METRO_GLOBAL_PREFIX__='${globalPrefix}'`,
19
26
  ];
27
+
28
+ if (isDev) {
29
+ // Ensure these variable names match the ones referenced in metro-runtime
30
+ // require.js
31
+ vars.push(
32
+ `${globalPrefix}__requireCycleIgnorePatterns=[${requireCycleIgnorePatterns
33
+ .map((regex) => regex.toString())
34
+ .join(",")}]`
35
+ );
36
+ }
37
+
20
38
  return `var ${vars.join(",")};${processEnv(
21
39
  isDev ? "development" : "production"
22
40
  )}`;
@@ -14,18 +14,33 @@ function getPreludeCode({
14
14
  extraVars,
15
15
  isDev,
16
16
  globalPrefix,
17
- }: {|
17
+ requireCycleIgnorePatterns,
18
+ }: {
18
19
  +extraVars?: {[string]: mixed, ...},
19
20
  +isDev: boolean,
20
21
  +globalPrefix: string,
21
- |}): string {
22
+ +requireCycleIgnorePatterns: $ReadOnlyArray<RegExp>,
23
+ }): string {
22
24
  const vars = [
25
+ // Ensure these variable names match the ones referenced in metro-runtime
26
+ // require.js
23
27
  '__BUNDLE_START_TIME__=this.nativePerformanceNow?nativePerformanceNow():Date.now()',
24
28
  `__DEV__=${String(isDev)}`,
25
29
  ...formatExtraVars(extraVars),
26
30
  'process=this.process||{}',
27
31
  `__METRO_GLOBAL_PREFIX__='${globalPrefix}'`,
28
32
  ];
33
+
34
+ if (isDev) {
35
+ // Ensure these variable names match the ones referenced in metro-runtime
36
+ // require.js
37
+ vars.push(
38
+ `${globalPrefix}__requireCycleIgnorePatterns=[${requireCycleIgnorePatterns
39
+ .map(regex => regex.toString())
40
+ .join(',')}]`,
41
+ );
42
+ }
43
+
29
44
  return `var ${vars.join(',')};${processEnv(
30
45
  isDev ? 'development' : 'production',
31
46
  )}`;
@@ -9,6 +9,12 @@
9
9
  */
10
10
  "use strict";
11
11
 
12
+ var _CountingSet = _interopRequireDefault(require("./CountingSet"));
13
+
14
+ function _interopRequireDefault(obj) {
15
+ return obj && obj.__esModule ? obj : { default: obj };
16
+ }
17
+
12
18
  const countLines = require("./countLines");
13
19
 
14
20
  const getPreludeCode = require("./getPreludeCode");
@@ -53,21 +59,23 @@ async function getPrependedScripts(config, options, bundler, deltaBundler) {
53
59
  _getPrelude({
54
60
  dev: options.dev,
55
61
  globalPrefix: config.transformer.globalPrefix,
62
+ requireCycleIgnorePatterns: config.resolver.requireCycleIgnorePatterns,
56
63
  }),
57
64
  ...dependencies.values(),
58
65
  ];
59
66
  }
60
67
 
61
- function _getPrelude({ dev, globalPrefix }) {
68
+ function _getPrelude({ dev, globalPrefix, requireCycleIgnorePatterns }) {
62
69
  const code = getPreludeCode({
63
70
  isDev: dev,
64
71
  globalPrefix,
72
+ requireCycleIgnorePatterns,
65
73
  });
66
74
  const name = "__prelude__";
67
75
  return {
68
76
  dependencies: new Map(),
69
77
  getSource: () => Buffer.from(code),
70
- inverseDependencies: new Set(),
78
+ inverseDependencies: new _CountingSet.default(),
71
79
  path: name,
72
80
  output: [
73
81
  {
@@ -15,6 +15,8 @@ import type DeltaBundler, {Module} from '../DeltaBundler';
15
15
  import type {TransformInputOptions} from '../DeltaBundler/types.flow';
16
16
  import type {ConfigT} from 'metro-config/src/configTypes.flow';
17
17
 
18
+ import CountingSet from './CountingSet';
19
+
18
20
  const countLines = require('./countLines');
19
21
  const getPreludeCode = require('./getPreludeCode');
20
22
  const transformHelpers = require('./transformHelpers');
@@ -69,6 +71,7 @@ async function getPrependedScripts(
69
71
  _getPrelude({
70
72
  dev: options.dev,
71
73
  globalPrefix: config.transformer.globalPrefix,
74
+ requireCycleIgnorePatterns: config.resolver.requireCycleIgnorePatterns,
72
75
  }),
73
76
  ...dependencies.values(),
74
77
  ];
@@ -77,18 +80,24 @@ async function getPrependedScripts(
77
80
  function _getPrelude({
78
81
  dev,
79
82
  globalPrefix,
83
+ requireCycleIgnorePatterns,
80
84
  }: {
81
85
  dev: boolean,
82
86
  globalPrefix: string,
87
+ requireCycleIgnorePatterns: $ReadOnlyArray<RegExp>,
83
88
  ...
84
89
  }): Module<> {
85
- const code = getPreludeCode({isDev: dev, globalPrefix});
90
+ const code = getPreludeCode({
91
+ isDev: dev,
92
+ globalPrefix,
93
+ requireCycleIgnorePatterns,
94
+ });
86
95
  const name = '__prelude__';
87
96
 
88
97
  return {
89
98
  dependencies: new Map(),
90
99
  getSource: (): Buffer => Buffer.from(code),
91
- inverseDependencies: new Set(),
100
+ inverseDependencies: new CountingSet(),
92
101
  path: name,
93
102
  output: [
94
103
  {
@@ -11,8 +11,6 @@
11
11
 
12
12
  const chalk = require("chalk");
13
13
 
14
- const { Terminal } = require("metro-core");
15
-
16
14
  const stripAnsi = require("strip-ansi");
17
15
 
18
16
  const util = require("util");
@@ -10,8 +10,9 @@
10
10
 
11
11
  'use strict';
12
12
 
13
+ import type {Terminal} from 'metro-core';
14
+
13
15
  const chalk = require('chalk');
14
- const {Terminal} = require('metro-core');
15
16
  const stripAnsi = require('strip-ansi');
16
17
  const util = require('util');
17
18
 
@@ -21,10 +21,10 @@ const path = require('path');
21
21
 
22
22
  type InlineRequiresRaw = {+blockList: {[string]: true, ...}, ...} | boolean;
23
23
 
24
- type TransformOptionsWithRawInlines = {|
24
+ type TransformOptionsWithRawInlines = {
25
25
  ...TransformOptions,
26
26
  +inlineRequires: InlineRequiresRaw,
27
- |};
27
+ };
28
28
 
29
29
  const baseIgnoredInlineRequires = ['React', 'react', 'react-native'];
30
30
 
@@ -144,12 +144,16 @@ class ModuleResolver {
144
144
  ` * ${Resolver.formatFileCandidates(
145
145
  this._removeRoot(candidates.dir)
146
146
  )}`,
147
- ].join("\n")
147
+ ].join("\n"),
148
+ {
149
+ cause: error,
150
+ }
148
151
  );
149
152
  }
150
153
 
151
154
  if (error instanceof Resolver.FailedToResolveNameError) {
152
- const { dirPaths, extraPaths } = error;
155
+ const dirPaths = error.dirPaths;
156
+ const extraPaths = error.extraPaths;
153
157
  const displayDirPaths = dirPaths
154
158
  .filter((dirPath) => this._options.dirExists(dirPath))
155
159
  .map((dirPath) => path.relative(this._options.projectRoot, dirPath))
@@ -161,7 +165,10 @@ class ModuleResolver {
161
165
  [
162
166
  `${moduleName} could not be found within the project${hint || "."}`,
163
167
  ...displayDirPaths.map((dirPath) => ` ${dirPath}`),
164
- ].join("\n")
168
+ ].join("\n"),
169
+ {
170
+ cause: error,
171
+ }
165
172
  );
166
173
  }
167
174
 
@@ -237,7 +244,11 @@ class UnableToResolveError extends Error {
237
244
  * The name of the module that was required, no necessarily a path,
238
245
  * ex. `./bar`, or `invariant`.
239
246
  */
240
- constructor(originModulePath, targetModuleName, message) {
247
+
248
+ /**
249
+ * Original error that causes this error
250
+ */
251
+ constructor(originModulePath, targetModuleName, message, options) {
241
252
  super();
242
253
  this.originModulePath = originModulePath;
243
254
  this.targetModuleName = targetModuleName;
@@ -249,6 +260,8 @@ class UnableToResolveError extends Error {
249
260
  originModulePath,
250
261
  message
251
262
  ) + (codeFrameMessage ? "\n" + codeFrameMessage : "");
263
+ this.cause =
264
+ options === null || options === void 0 ? void 0 : options.cause;
252
265
  }
253
266
 
254
267
  buildCodeFrameMessage() {
@@ -10,7 +10,7 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- import type {ModuleMap} from './types';
13
+ import type {ModuleMap} from 'metro-file-map';
14
14
  import type {
15
15
  CustomResolver,
16
16
  DoesFileExist,
@@ -53,7 +53,7 @@ export type ModuleishCache<TModule, TPackage> = interface {
53
53
  getPackageOf(modulePath: string): ?TPackage,
54
54
  };
55
55
 
56
- type Options<TModule, TPackage> = {|
56
+ type Options<TModule, TPackage> = {
57
57
  +dirExists: DirExistsFn,
58
58
  +disableHierarchicalLookup: boolean,
59
59
  +doesFileExist: DoesFileExist,
@@ -69,7 +69,7 @@ type Options<TModule, TPackage> = {|
69
69
  +resolveAsset: ResolveAsset,
70
70
  +resolveRequest: ?CustomResolver,
71
71
  +sourceExts: $ReadOnlyArray<string>,
72
- |};
72
+ };
73
73
 
74
74
  class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
75
75
  _options: Options<TModule, TPackage>;
@@ -201,18 +201,14 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
201
201
  this._removeRoot(candidates.dir),
202
202
  )}`,
203
203
  ].join('\n'),
204
+ {
205
+ cause: error,
206
+ },
204
207
  );
205
208
  }
206
209
  if (error instanceof Resolver.FailedToResolveNameError) {
207
- const {
208
- dirPaths,
209
- extraPaths,
210
- }: {
211
- // $flowfixme these types are defined explicitly in FailedToResolveNameError but Flow refuses to recognize them here
212
- dirPaths: $ReadOnlyArray<string>,
213
- extraPaths: $ReadOnlyArray<string>,
214
- ...
215
- } = error;
210
+ const dirPaths = error.dirPaths;
211
+ const extraPaths = error.extraPaths;
216
212
  const displayDirPaths = dirPaths
217
213
  .filter((dirPath: string) => this._options.dirExists(dirPath))
218
214
  .map(dirPath => path.relative(this._options.projectRoot, dirPath))
@@ -227,6 +223,9 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
227
223
  `${moduleName} could not be found within the project${hint || '.'}`,
228
224
  ...displayDirPaths.map((dirPath: string) => ` ${dirPath}`),
229
225
  ].join('\n'),
226
+ {
227
+ cause: error,
228
+ },
230
229
  );
231
230
  }
232
231
  throw error;
@@ -294,11 +293,18 @@ class UnableToResolveError extends Error {
294
293
  * ex. `./bar`, or `invariant`.
295
294
  */
296
295
  targetModuleName: string;
296
+ /**
297
+ * Original error that causes this error
298
+ */
299
+ cause: ?Error;
297
300
 
298
301
  constructor(
299
302
  originModulePath: string,
300
303
  targetModuleName: string,
301
304
  message: string,
305
+ options?: $ReadOnly<{
306
+ cause?: Error,
307
+ }>,
302
308
  ) {
303
309
  super();
304
310
  this.originModulePath = originModulePath;
@@ -311,6 +317,8 @@ class UnableToResolveError extends Error {
311
317
  originModulePath,
312
318
  message,
313
319
  ) + (codeFrameMessage ? '\n' + codeFrameMessage : '');
320
+
321
+ this.cause = options?.cause;
314
322
  }
315
323
 
316
324
  buildCodeFrameMessage(): ?string {
@@ -1,9 +1,47 @@
1
1
  "use strict";
2
2
 
3
- var _jestHasteMap = _interopRequireDefault(require("jest-haste-map"));
3
+ var _metroFileMap = _interopRequireWildcard(require("metro-file-map"));
4
4
 
5
- function _interopRequireDefault(obj) {
6
- return obj && obj.__esModule ? obj : { default: obj };
5
+ function _getRequireWildcardCache(nodeInterop) {
6
+ if (typeof WeakMap !== "function") return null;
7
+ var cacheBabelInterop = new WeakMap();
8
+ var cacheNodeInterop = new WeakMap();
9
+ return (_getRequireWildcardCache = function (nodeInterop) {
10
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
11
+ })(nodeInterop);
12
+ }
13
+
14
+ function _interopRequireWildcard(obj, nodeInterop) {
15
+ if (!nodeInterop && obj && obj.__esModule) {
16
+ return obj;
17
+ }
18
+ if (obj === null || (typeof obj !== "object" && typeof obj !== "function")) {
19
+ return { default: obj };
20
+ }
21
+ var cache = _getRequireWildcardCache(nodeInterop);
22
+ if (cache && cache.has(obj)) {
23
+ return cache.get(obj);
24
+ }
25
+ var newObj = {};
26
+ var hasPropertyDescriptor =
27
+ Object.defineProperty && Object.getOwnPropertyDescriptor;
28
+ for (var key in obj) {
29
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
30
+ var desc = hasPropertyDescriptor
31
+ ? Object.getOwnPropertyDescriptor(obj, key)
32
+ : null;
33
+ if (desc && (desc.get || desc.set)) {
34
+ Object.defineProperty(newObj, key, desc);
35
+ } else {
36
+ newObj[key] = obj[key];
37
+ }
38
+ }
39
+ }
40
+ newObj.default = obj;
41
+ if (cache) {
42
+ cache.set(obj, newObj);
43
+ }
44
+ return newObj;
7
45
  }
8
46
 
9
47
  /**
@@ -15,13 +53,10 @@ function _interopRequireDefault(obj) {
15
53
  *
16
54
  * @format
17
55
  */
18
- // $FlowFixMe: Types for `jest-haste-map`
19
56
  const ci = require("ci-info");
20
57
 
21
58
  const path = require("path");
22
59
 
23
- const JEST_HASTE_MAP_CACHE_BREAKER = 5;
24
-
25
60
  function getIgnorePattern(config) {
26
61
  // For now we support both options
27
62
  const { blockList, blacklistRE } = config.resolver;
@@ -46,7 +81,10 @@ function getIgnorePattern(config) {
46
81
  }
47
82
 
48
83
  function createHasteMap(config, options) {
49
- var _options$name, _options$throwOnModul;
84
+ var _config$unstable_file,
85
+ _config$unstable_perf,
86
+ _config$unstable_perf2,
87
+ _options$throwOnModul;
50
88
 
51
89
  const dependencyExtractor =
52
90
  (options === null || options === void 0
@@ -55,25 +93,48 @@ function createHasteMap(config, options) {
55
93
  ? null
56
94
  : config.resolver.dependencyExtractor;
57
95
  const computeDependencies = dependencyExtractor != null;
58
- const hasteConfig = {
59
- cacheDirectory: config.hasteMapCacheDirectory,
96
+ return _metroFileMap.default.create({
97
+ cacheManagerFactory:
98
+ (_config$unstable_file =
99
+ config === null || config === void 0
100
+ ? void 0
101
+ : config.unstable_fileMapCacheManagerFactory) !== null &&
102
+ _config$unstable_file !== void 0
103
+ ? _config$unstable_file
104
+ : (buildParameters) => {
105
+ var _config$fileMapCacheD;
106
+
107
+ return new _metroFileMap.DiskCacheManager({
108
+ buildParameters,
109
+ cacheDirectory:
110
+ (_config$fileMapCacheD = config.fileMapCacheDirectory) !==
111
+ null && _config$fileMapCacheD !== void 0
112
+ ? _config$fileMapCacheD
113
+ : config.hasteMapCacheDirectory,
114
+ cacheFilePrefix:
115
+ options === null || options === void 0
116
+ ? void 0
117
+ : options.cacheFilePrefix,
118
+ });
119
+ },
120
+ perfLogger:
121
+ (_config$unstable_perf =
122
+ (_config$unstable_perf2 = config.unstable_perfLogger) === null ||
123
+ _config$unstable_perf2 === void 0
124
+ ? void 0
125
+ : _config$unstable_perf2.subSpan("hasteMap")) !== null &&
126
+ _config$unstable_perf !== void 0
127
+ ? _config$unstable_perf
128
+ : null,
60
129
  computeDependencies,
61
130
  computeSha1: true,
62
131
  dependencyExtractor: config.resolver.dependencyExtractor,
63
132
  extensions: config.resolver.sourceExts.concat(config.resolver.assetExts),
64
133
  forceNodeFilesystemAPI: !config.resolver.useWatchman,
65
134
  hasteImplModulePath: config.resolver.hasteImplModulePath,
66
- hasteMapModulePath: config.resolver.unstable_hasteMapModulePath,
67
135
  ignorePattern: getIgnorePattern(config),
68
136
  maxWorkers: config.maxWorkers,
69
137
  mocksPattern: "",
70
- name: `${
71
- (_options$name =
72
- options === null || options === void 0 ? void 0 : options.name) !==
73
- null && _options$name !== void 0
74
- ? _options$name
75
- : "metro"
76
- }-${JEST_HASTE_MAP_CACHE_BREAKER}`,
77
138
  platforms: config.resolver.platforms,
78
139
  retainAllFiles: true,
79
140
  resetCache: config.resetCache,
@@ -92,8 +153,8 @@ function createHasteMap(config, options) {
92
153
  (options === null || options === void 0 ? void 0 : options.watch) == null
93
154
  ? !ci.isCI
94
155
  : options.watch,
95
- };
96
- return _jestHasteMap.default.create(hasteConfig);
156
+ watchmanDeferStates: config.watcher.watchman.deferStates,
157
+ });
97
158
  }
98
159
 
99
160
  module.exports = createHasteMap;
@@ -8,17 +8,13 @@
8
8
  * @format
9
9
  */
10
10
 
11
- import type {HasteConfig, HasteMap} from './types';
12
11
  import type {ConfigT} from 'metro-config/src/configTypes.flow';
13
12
 
14
- // $FlowFixMe: Types for `jest-haste-map`
15
- import JestHasteMap from 'jest-haste-map';
13
+ import MetroFileMap, {DiskCacheManager} from 'metro-file-map';
16
14
 
17
15
  const ci = require('ci-info');
18
16
  const path = require('path');
19
17
 
20
- const JEST_HASTE_MAP_CACHE_BREAKER = 5;
21
-
22
18
  function getIgnorePattern(config: ConfigT): RegExp {
23
19
  // For now we support both options
24
20
  const {blockList, blacklistRE} = config.resolver;
@@ -50,28 +46,35 @@ function createHasteMap(
50
46
  extractDependencies?: boolean,
51
47
  watch?: boolean,
52
48
  throwOnModuleCollision?: boolean,
53
- name?: string,
49
+ cacheFilePrefix?: string,
54
50
  }>,
55
- ): HasteMap {
51
+ ): MetroFileMap {
56
52
  const dependencyExtractor =
57
53
  options?.extractDependencies === false
58
54
  ? null
59
55
  : config.resolver.dependencyExtractor;
60
56
  const computeDependencies = dependencyExtractor != null;
61
57
 
62
- const hasteConfig: HasteConfig = {
63
- cacheDirectory: config.hasteMapCacheDirectory,
58
+ return MetroFileMap.create({
59
+ cacheManagerFactory:
60
+ config?.unstable_fileMapCacheManagerFactory ??
61
+ (buildParameters =>
62
+ new DiskCacheManager({
63
+ buildParameters,
64
+ cacheDirectory:
65
+ config.fileMapCacheDirectory ?? config.hasteMapCacheDirectory,
66
+ cacheFilePrefix: options?.cacheFilePrefix,
67
+ })),
68
+ perfLogger: config.unstable_perfLogger?.subSpan('hasteMap') ?? null,
64
69
  computeDependencies,
65
70
  computeSha1: true,
66
71
  dependencyExtractor: config.resolver.dependencyExtractor,
67
72
  extensions: config.resolver.sourceExts.concat(config.resolver.assetExts),
68
73
  forceNodeFilesystemAPI: !config.resolver.useWatchman,
69
74
  hasteImplModulePath: config.resolver.hasteImplModulePath,
70
- hasteMapModulePath: config.resolver.unstable_hasteMapModulePath,
71
75
  ignorePattern: getIgnorePattern(config),
72
76
  maxWorkers: config.maxWorkers,
73
77
  mocksPattern: '',
74
- name: `${options?.name ?? 'metro'}-${JEST_HASTE_MAP_CACHE_BREAKER}`,
75
78
  platforms: config.resolver.platforms,
76
79
  retainAllFiles: true,
77
80
  resetCache: config.resetCache,
@@ -80,9 +83,8 @@ function createHasteMap(
80
83
  throwOnModuleCollision: options?.throwOnModuleCollision ?? true,
81
84
  useWatchman: config.resolver.useWatchman,
82
85
  watch: options?.watch == null ? !ci.isCI : options.watch,
83
- };
84
-
85
- return JestHasteMap.create(hasteConfig);
86
+ watchmanDeferStates: config.watcher.watchman.deferStates,
87
+ });
86
88
  }
87
89
 
88
90
  module.exports = createHasteMap;