metro 0.72.1 → 0.72.3

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 (63) hide show
  1. package/package.json +23 -21
  2. package/src/DeltaBundler/Serializers/baseBytecodeBundle.js +3 -2
  3. package/src/DeltaBundler/Serializers/baseBytecodeBundle.js.flow +2 -1
  4. package/src/DeltaBundler/Serializers/helpers/bytecode.js +2 -2
  5. package/src/DeltaBundler/Serializers/helpers/bytecode.js.flow +2 -1
  6. package/src/DeltaBundler/Worker.js +0 -1
  7. package/src/DeltaBundler/Worker.js.flow +0 -1
  8. package/src/DeltaBundler/graphOperations.js +6 -6
  9. package/src/DeltaBundler/graphOperations.js.flow +5 -5
  10. package/src/DeltaBundler.js.flow +1 -1
  11. package/src/HmrServer.js +9 -5
  12. package/src/HmrServer.js.flow +9 -4
  13. package/src/IncrementalBundler.js +16 -4
  14. package/src/IncrementalBundler.js.flow +17 -4
  15. package/src/ModuleGraph/node-haste/HasteFS.js +0 -1
  16. package/src/ModuleGraph/node-haste/HasteFS.js.flow +0 -1
  17. package/src/ModuleGraph/node-haste/Package.js.flow +5 -5
  18. package/src/ModuleGraph/node-haste/node-haste.js +8 -4
  19. package/src/ModuleGraph/node-haste/node-haste.js.flow +21 -14
  20. package/src/ModuleGraph/output/reverse-dependency-map-references.js +1 -2
  21. package/src/ModuleGraph/output/reverse-dependency-map-references.js.flow +0 -1
  22. package/src/ModuleGraph/output/util.js +2 -4
  23. package/src/ModuleGraph/output/util.js.flow +1 -2
  24. package/src/ModuleGraph/types.flow.js.flow +28 -6
  25. package/src/Server/MultipartResponse.js +10 -12
  26. package/src/Server/MultipartResponse.js.flow +97 -0
  27. package/src/Server.js +100 -48
  28. package/src/Server.js.flow +118 -49
  29. package/src/index.flow.js +16 -8
  30. package/src/index.flow.js.flow +14 -8
  31. package/src/index.js +0 -1
  32. package/src/index.js.flow +0 -1
  33. package/src/lib/CountingSet.js +0 -1
  34. package/src/lib/CountingSet.js.flow +0 -1
  35. package/src/lib/RamBundleParser.js +1 -0
  36. package/src/lib/RamBundleParser.js.flow +1 -0
  37. package/src/lib/TerminalReporter.js +22 -24
  38. package/src/lib/TerminalReporter.js.flow +20 -24
  39. package/src/lib/bundleToBytecode.js +3 -2
  40. package/src/lib/bundleToBytecode.js.flow +2 -2
  41. package/src/lib/getGraphId.js +16 -3
  42. package/src/lib/getGraphId.js.flow +10 -10
  43. package/src/lib/getPrependedScripts.js +13 -5
  44. package/src/lib/getPrependedScripts.js.flow +6 -1
  45. package/src/lib/parseCustomResolverOptions.js +26 -0
  46. package/src/lib/parseCustomResolverOptions.js.flow +38 -0
  47. package/src/lib/parseOptionsFromUrl.js +3 -0
  48. package/src/lib/parseOptionsFromUrl.js.flow +2 -0
  49. package/src/lib/splitBundleOptions.js +3 -0
  50. package/src/lib/splitBundleOptions.js.flow +3 -0
  51. package/src/lib/transformHelpers.js +27 -13
  52. package/src/lib/transformHelpers.js.flow +27 -7
  53. package/src/node-haste/DependencyGraph/ModuleResolution.js +18 -2
  54. package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +5 -0
  55. package/src/node-haste/DependencyGraph.js +34 -9
  56. package/src/node-haste/DependencyGraph.js.flow +49 -11
  57. package/src/node-haste/Module.js +1 -0
  58. package/src/node-haste/Module.js.flow +1 -0
  59. package/src/node-haste/Package.js +0 -1
  60. package/src/node-haste/Package.js.flow +0 -1
  61. package/src/shared/output/bundle.js +0 -1
  62. package/src/shared/output/bundle.js.flow +0 -1
  63. package/src/shared/types.flow.js.flow +7 -0
@@ -182,28 +182,21 @@ class TerminalReporter {
182
182
 
183
183
  _logInitializing(port: number, hasReducedPerformance: boolean): void {
184
184
  const logo = [
185
- ' ',
186
- ' ####### ',
187
- ' ################ ',
188
- ' ######### ######### ',
189
- ' ######### ########## ',
190
- ' ######### ###### ######### ',
191
- ' ########################################## ',
192
- ' ##### ##################### ##### ',
193
- ' ##### ############## ##### ',
194
- ' ##### ### ###### ### ##### ',
195
- ' ##### ####### ####### ##### ',
196
- ' ##### ########### ########### ##### ',
197
- ' ##### ########################## ##### ',
198
- ' ##### ########################## ##### ',
199
- ' ##### ###################### ###### ',
200
- ' ###### ############# ####### ',
201
- ' ######### #### ######### ',
202
- ' ######### ######### ',
203
- ' ######### ######### ',
204
- ' ######### ',
205
- ' ',
206
- ' ',
185
+ '',
186
+ ' ▒▒▓▓▓▓▒▒',
187
+ ' ▒▓▓▓▒▒░░▒▒▓▓▓▒',
188
+ ' ▒▓▓▓▓░░░▒▒▒▒░░░▓▓▓▓▒',
189
+ ' ▓▓▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▓▓',
190
+ ' ▓▓░░░░░▒▓▓▓▓▓▓▒░░░░░▓▓',
191
+ ' ▓▓░░▓▓▒░░░▒▒░░░▒▓▒░░▓▓',
192
+ ' ▓▓░░▓▓▓▓▓▒▒▒▒▓▓▓▓▒░░▓▓',
193
+ ' ▓▓░░▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░▓▓',
194
+ ' ▓▓▒░░▒▒▓▓▓▓▓▓▓▓▒░░░▒▓▓',
195
+ ' ▒▓▓▓▒░░░▒▓▓▒░░░▒▓▓▓▒',
196
+ ' ▒▓▓▓▒░░░░▒▓▓▓▒',
197
+ ' ▒▒▓▓▓▓▒▒',
198
+ '',
199
+ '',
207
200
  ];
208
201
 
209
202
  const color = hasReducedPerformance ? chalk.red : chalk.blue;
@@ -275,9 +268,12 @@ class TerminalReporter {
275
268
  break;
276
269
  case 'dep_graph_loading':
277
270
  const color = event.hasReducedPerformance ? chalk.red : chalk.blue;
271
+ const version = 'v' + require('../../package.json').version;
278
272
  this.terminal.log(
279
- color.bold(' Welcome to Metro!\n') +
280
- chalk.dim(' Fast - Scalable - Integrated\n\n'),
273
+ color.bold(
274
+ ' '.repeat(19 - version.length / 2),
275
+ 'Welcome to Metro ' + chalk.white(version) + '\n',
276
+ ) + chalk.dim(' Fast - Scalable - Integrated\n\n'),
281
277
  );
282
278
 
283
279
  if (event.hasReducedPerformance) {
@@ -9,14 +9,13 @@
9
9
  */
10
10
  "use strict";
11
11
 
12
- const { getFileLength } = require("metro-hermes-compiler"); // The magic number is used as a header for bytecode.
12
+ // The magic number is used as a header for bytecode.
13
13
  // It represents a Metro tunnel in binary.
14
14
  //
15
15
  // 11111111
16
16
  // 11100111
17
17
  // 11000011
18
18
  // 11000011
19
-
20
19
  const MAGIC_NUMBER = 0xffe7c3c3;
21
20
 
22
21
  function getFileHeader(moduleCount) {
@@ -27,6 +26,8 @@ function getFileHeader(moduleCount) {
27
26
  }
28
27
 
29
28
  function addModuleHeader(buffer) {
29
+ const { getFileLength } = require("metro-hermes-compiler");
30
+
30
31
  const fileLength = getFileLength(buffer, 0);
31
32
  const header = Buffer.alloc(4);
32
33
  header.writeUInt32LE(fileLength, 0);
@@ -15,8 +15,6 @@ import type {
15
15
  BytecodeBundle,
16
16
  } from 'metro-runtime/src/modules/types.flow';
17
17
 
18
- const {getFileLength} = require('metro-hermes-compiler');
19
-
20
18
  // The magic number is used as a header for bytecode.
21
19
  // It represents a Metro tunnel in binary.
22
20
  //
@@ -34,6 +32,8 @@ function getFileHeader(moduleCount: number): Buffer {
34
32
  }
35
33
 
36
34
  function addModuleHeader(buffer: Buffer): [Buffer, Buffer] {
35
+ const {getFileLength} = require('metro-hermes-compiler');
36
+
37
37
  const fileLength = getFileLength(buffer, 0);
38
38
  const header = Buffer.alloc(4);
39
39
  header.writeUInt32LE(fileLength, 0);
@@ -14,15 +14,28 @@ const canonicalize = require("metro-core/src/canonicalize");
14
14
  function getGraphId(
15
15
  entryFile,
16
16
  options,
17
- { shallow, experimentalImportBundleSupport, unstable_allowRequireContext }
17
+ {
18
+ shallow,
19
+ experimentalImportBundleSupport,
20
+ unstable_allowRequireContext,
21
+ resolverOptions,
22
+ }
18
23
  ) {
24
+ var _resolverOptions$cust, _options$customTransf;
25
+
19
26
  return JSON.stringify(
20
27
  {
21
28
  entryFile,
22
29
  options: {
30
+ customResolverOptions:
31
+ (_resolverOptions$cust = resolverOptions.customResolverOptions) !==
32
+ null && _resolverOptions$cust !== void 0
33
+ ? _resolverOptions$cust
34
+ : {},
23
35
  customTransformOptions:
24
- options.customTransformOptions != null
25
- ? options.customTransformOptions
36
+ (_options$customTransf = options.customTransformOptions) !== null &&
37
+ _options$customTransf !== void 0
38
+ ? _options$customTransf
26
39
  : null,
27
40
  dev: options.dev,
28
41
  experimentalImportSupport: options.experimentalImportSupport || false,
@@ -11,6 +11,7 @@
11
11
  'use strict';
12
12
 
13
13
  import type {TransformInputOptions} from '../DeltaBundler/types.flow';
14
+ import type {ResolverInputOptions} from '../shared/types.flow';
14
15
 
15
16
  const canonicalize = require('metro-core/src/canonicalize');
16
17
 
@@ -23,21 +24,20 @@ function getGraphId(
23
24
  shallow,
24
25
  experimentalImportBundleSupport,
25
26
  unstable_allowRequireContext,
26
- }: {
27
- +shallow: boolean,
28
- +experimentalImportBundleSupport: boolean,
29
- +unstable_allowRequireContext: boolean,
30
- ...
31
- },
27
+ resolverOptions,
28
+ }: $ReadOnly<{
29
+ shallow: boolean,
30
+ experimentalImportBundleSupport: boolean,
31
+ unstable_allowRequireContext: boolean,
32
+ resolverOptions: ResolverInputOptions,
33
+ }>,
32
34
  ): GraphId {
33
35
  return JSON.stringify(
34
36
  {
35
37
  entryFile,
36
38
  options: {
37
- customTransformOptions:
38
- options.customTransformOptions != null
39
- ? options.customTransformOptions
40
- : null,
39
+ customResolverOptions: resolverOptions.customResolverOptions ?? {},
40
+ customTransformOptions: options.customTransformOptions ?? null,
41
41
  dev: options.dev,
42
42
  experimentalImportSupport: options.experimentalImportSupport || false,
43
43
  hot: options.hot,
@@ -23,9 +23,13 @@ const transformHelpers = require("./transformHelpers");
23
23
 
24
24
  const defaults = require("metro-config/src/defaults/defaults");
25
25
 
26
- const { compile } = require("metro-hermes-compiler");
27
-
28
- async function getPrependedScripts(config, options, bundler, deltaBundler) {
26
+ async function getPrependedScripts(
27
+ config,
28
+ options,
29
+ resolverOptions,
30
+ bundler,
31
+ deltaBundler
32
+ ) {
29
33
  // Get all the polyfills from the relevant option params (the
30
34
  // `getPolyfills()` method and the `polyfillModuleNames` variable).
31
35
  const polyfillModuleNames = config.serializer
@@ -39,14 +43,16 @@ async function getPrependedScripts(config, options, bundler, deltaBundler) {
39
43
  {
40
44
  resolve: await transformHelpers.getResolveDependencyFn(
41
45
  bundler,
42
- options.platform
46
+ options.platform,
47
+ resolverOptions
43
48
  ),
44
49
  transform: await transformHelpers.getTransformFn(
45
50
  [defaults.moduleSystem, ...polyfillModuleNames],
46
51
  bundler,
47
52
  deltaBundler,
48
53
  config,
49
- transformOptions
54
+ transformOptions,
55
+ resolverOptions
50
56
  ),
51
57
  unstable_allowRequireContext:
52
58
  config.transformer.unstable_allowRequireContext,
@@ -68,6 +74,8 @@ async function getPrependedScripts(config, options, bundler, deltaBundler) {
68
74
  }
69
75
 
70
76
  function _getPrelude({ dev, globalPrefix, requireCycleIgnorePatterns }) {
77
+ const { compile } = require("metro-hermes-compiler");
78
+
71
79
  const code = getPreludeCode({
72
80
  isDev: dev,
73
81
  globalPrefix,
@@ -13,6 +13,7 @@
13
13
  import type Bundler from '../Bundler';
14
14
  import type DeltaBundler, {Module} from '../DeltaBundler';
15
15
  import type {TransformInputOptions} from '../DeltaBundler/types.flow';
16
+ import type {ResolverInputOptions} from '../shared/types.flow';
16
17
  import type {ConfigT} from 'metro-config/src/configTypes.flow';
17
18
 
18
19
  import CountingSet from './CountingSet';
@@ -21,7 +22,6 @@ const countLines = require('./countLines');
21
22
  const getPreludeCode = require('./getPreludeCode');
22
23
  const transformHelpers = require('./transformHelpers');
23
24
  const defaults = require('metro-config/src/defaults/defaults');
24
- const {compile} = require('metro-hermes-compiler');
25
25
 
26
26
  async function getPrependedScripts(
27
27
  config: ConfigT,
@@ -29,6 +29,7 @@ async function getPrependedScripts(
29
29
  TransformInputOptions,
30
30
  {type: $PropertyType<TransformInputOptions, 'type'>, ...},
31
31
  >,
32
+ resolverOptions: ResolverInputOptions,
32
33
  bundler: Bundler,
33
34
  deltaBundler: DeltaBundler<>,
34
35
  ): Promise<$ReadOnlyArray<Module<>>> {
@@ -51,6 +52,7 @@ async function getPrependedScripts(
51
52
  resolve: await transformHelpers.getResolveDependencyFn(
52
53
  bundler,
53
54
  options.platform,
55
+ resolverOptions,
54
56
  ),
55
57
  transform: await transformHelpers.getTransformFn(
56
58
  [defaults.moduleSystem, ...polyfillModuleNames],
@@ -58,6 +60,7 @@ async function getPrependedScripts(
58
60
  deltaBundler,
59
61
  config,
60
62
  transformOptions,
63
+ resolverOptions,
61
64
  ),
62
65
  unstable_allowRequireContext:
63
66
  config.transformer.unstable_allowRequireContext,
@@ -89,6 +92,8 @@ function _getPrelude({
89
92
  requireCycleIgnorePatterns: $ReadOnlyArray<RegExp>,
90
93
  ...
91
94
  }): Module<> {
95
+ const {compile} = require('metro-hermes-compiler');
96
+
92
97
  const code = getPreludeCode({
93
98
  isDev: dev,
94
99
  globalPrefix,
@@ -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
+ * @emails oncall+metro_bundler
8
+ * @format
9
+ *
10
+ */
11
+ "use strict";
12
+
13
+ const nullthrows = require("nullthrows");
14
+
15
+ const PREFIX = "resolver.";
16
+
17
+ module.exports = function parseCustomResolverOptions(urlObj) {
18
+ const customResolverOptions = Object.create(null);
19
+ const query = nullthrows(urlObj.query);
20
+ Object.keys(query).forEach((key) => {
21
+ if (key.startsWith(PREFIX)) {
22
+ customResolverOptions[key.substr(PREFIX.length)] = query[key];
23
+ }
24
+ });
25
+ return customResolverOptions;
26
+ };
@@ -0,0 +1,38 @@
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
+ * @emails oncall+metro_bundler
8
+ * @format
9
+ * @flow strict-local
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ import type {CustomResolverOptions} from '../../../metro-resolver/src/types';
15
+
16
+ const nullthrows = require('nullthrows');
17
+
18
+ const PREFIX = 'resolver.';
19
+
20
+ module.exports = function parseCustomResolverOptions(urlObj: {
21
+ +query?: {[string]: string, ...},
22
+ ...
23
+ }): CustomResolverOptions {
24
+ const customResolverOptions: {
25
+ __proto__: null,
26
+ [string]: mixed,
27
+ ...
28
+ } = Object.create(null);
29
+ const query = nullthrows(urlObj.query);
30
+
31
+ Object.keys(query).forEach((key: string) => {
32
+ if (key.startsWith(PREFIX)) {
33
+ customResolverOptions[key.substr(PREFIX.length)] = query[key];
34
+ }
35
+ });
36
+
37
+ return customResolverOptions;
38
+ };
@@ -11,6 +11,8 @@
11
11
 
12
12
  const parsePlatformFilePath = require("../node-haste/lib/parsePlatformFilePath");
13
13
 
14
+ const parseCustomResolverOptions = require("./parseCustomResolverOptions");
15
+
14
16
  const parseCustomTransformOptions = require("./parseCustomTransformOptions");
15
17
 
16
18
  const nullthrows = require("nullthrows");
@@ -60,6 +62,7 @@ module.exports = function parseOptionsFromUrl(
60
62
  bundleType,
61
63
  runtimeBytecodeVersion:
62
64
  bytecodeVersion === runtimeBytecodeVersion ? bytecodeVersion : null,
65
+ customResolverOptions: parseCustomResolverOptions(parsedURL),
63
66
  customTransformOptions: parseCustomTransformOptions(parsedURL),
64
67
  dev: getBoolean(query, "dev", true),
65
68
  entryFile: pathname.replace(/^(?:\.?\/)?/, "./").replace(/\.[^/.]+$/, ""),
@@ -14,6 +14,7 @@ import type {BundleOptions} from '../shared/types.flow';
14
14
  import type {TransformProfile} from 'metro-babel-transformer';
15
15
 
16
16
  const parsePlatformFilePath = require('../node-haste/lib/parsePlatformFilePath');
17
+ const parseCustomResolverOptions = require('./parseCustomResolverOptions');
17
18
  const parseCustomTransformOptions = require('./parseCustomTransformOptions');
18
19
  const nullthrows = require('nullthrows');
19
20
  const path = require('path');
@@ -68,6 +69,7 @@ module.exports = function parseOptionsFromUrl(
68
69
  bundleType,
69
70
  runtimeBytecodeVersion:
70
71
  bytecodeVersion === runtimeBytecodeVersion ? bytecodeVersion : null,
72
+ customResolverOptions: parseCustomResolverOptions(parsedURL),
71
73
  customTransformOptions: parseCustomTransformOptions(parsedURL),
72
74
  dev: getBoolean(query, 'dev', true),
73
75
  entryFile: pathname.replace(/^(?:\.?\/)?/, './').replace(/\.[^/.]+$/, ''),
@@ -15,6 +15,9 @@
15
15
  function splitBundleOptions(options) {
16
16
  return {
17
17
  entryFile: options.entryFile,
18
+ resolverOptions: {
19
+ customResolverOptions: options.customResolverOptions,
20
+ },
18
21
  transformOptions: {
19
22
  customTransformOptions: options.customTransformOptions,
20
23
  dev: options.dev,
@@ -18,6 +18,9 @@ import type {BundleOptions, SplitBundleOptions} from '../shared/types.flow';
18
18
  function splitBundleOptions(options: BundleOptions): SplitBundleOptions {
19
19
  return {
20
20
  entryFile: options.entryFile,
21
+ resolverOptions: {
22
+ customResolverOptions: options.customResolverOptions,
23
+ },
21
24
  transformOptions: {
22
25
  customTransformOptions: options.customTransformOptions,
23
26
  dev: options.dev,
@@ -20,7 +20,8 @@ async function calcTransformerOptions(
20
20
  bundler,
21
21
  deltaBundler,
22
22
  config,
23
- options
23
+ options,
24
+ resolverOptions
24
25
  ) {
25
26
  const baseOptions = {
26
27
  customTransformOptions: options.customTransformOptions,
@@ -42,11 +43,19 @@ async function calcTransformerOptions(
42
43
 
43
44
  const getDependencies = async (path) => {
44
45
  const dependencies = await deltaBundler.getDependencies([path], {
45
- resolve: await getResolveDependencyFn(bundler, options.platform),
46
- transform: await getTransformFn([path], bundler, deltaBundler, config, {
47
- ...options,
48
- minify: false,
49
- }),
46
+ resolve: await getResolveDependencyFn(
47
+ bundler,
48
+ options.platform,
49
+ resolverOptions
50
+ ),
51
+ transform: await getTransformFn(
52
+ [path],
53
+ bundler,
54
+ deltaBundler,
55
+ config,
56
+ { ...options, minify: false },
57
+ resolverOptions
58
+ ),
50
59
  transformOptions: options,
51
60
  onProgress: null,
52
61
  experimentalImportBundleSupport:
@@ -92,14 +101,16 @@ async function getTransformFn(
92
101
  bundler,
93
102
  deltaBundler,
94
103
  config,
95
- options
104
+ options,
105
+ resolverOptions
96
106
  ) {
97
107
  const { inlineRequires, ...transformOptions } = await calcTransformerOptions(
98
108
  entryFiles,
99
109
  bundler,
100
110
  deltaBundler,
101
111
  config,
102
- options
112
+ options,
113
+ resolverOptions
103
114
  );
104
115
  return async (modulePath, requireContext) => {
105
116
  let templateBuffer;
@@ -153,12 +164,15 @@ function getType(type, filePath, assetExts) {
153
164
  return "module";
154
165
  }
155
166
 
156
- async function getResolveDependencyFn(bundler, platform) {
167
+ async function getResolveDependencyFn(bundler, platform, resolverOptions) {
157
168
  const dependencyGraph = await await bundler.getDependencyGraph();
158
- return (
159
- from,
160
- to // $FlowFixMe[incompatible-call]
161
- ) => dependencyGraph.resolveDependency(from, to, platform);
169
+ return (from, to) =>
170
+ dependencyGraph.resolveDependency(
171
+ from,
172
+ to,
173
+ platform !== null && platform !== void 0 ? platform : null,
174
+ resolverOptions
175
+ );
162
176
  }
163
177
 
164
178
  module.exports = {
@@ -21,6 +21,7 @@ import type {RequireContext} from './contextModule';
21
21
  import {getContextModuleTemplate} from './contextModuleTemplates';
22
22
 
23
23
  const path = require('path');
24
+ import type {ResolverInputOptions} from '../shared/types.flow';
24
25
 
25
26
  type InlineRequiresRaw = {+blockList: {[string]: true, ...}, ...} | boolean;
26
27
 
@@ -37,6 +38,7 @@ async function calcTransformerOptions(
37
38
  deltaBundler: DeltaBundler<>,
38
39
  config: ConfigT,
39
40
  options: TransformInputOptions,
41
+ resolverOptions: ResolverInputOptions,
40
42
  ): Promise<TransformOptionsWithRawInlines> {
41
43
  const baseOptions = {
42
44
  customTransformOptions: options.customTransformOptions,
@@ -62,11 +64,22 @@ async function calcTransformerOptions(
62
64
 
63
65
  const getDependencies = async (path: string) => {
64
66
  const dependencies = await deltaBundler.getDependencies([path], {
65
- resolve: await getResolveDependencyFn(bundler, options.platform),
66
- transform: await getTransformFn([path], bundler, deltaBundler, config, {
67
- ...options,
68
- minify: false,
69
- }),
67
+ resolve: await getResolveDependencyFn(
68
+ bundler,
69
+ options.platform,
70
+ resolverOptions,
71
+ ),
72
+ transform: await getTransformFn(
73
+ [path],
74
+ bundler,
75
+ deltaBundler,
76
+ config,
77
+ {
78
+ ...options,
79
+ minify: false,
80
+ },
81
+ resolverOptions,
82
+ ),
70
83
  transformOptions: options,
71
84
  onProgress: null,
72
85
  experimentalImportBundleSupport:
@@ -114,6 +127,7 @@ async function getTransformFn(
114
127
  deltaBundler: DeltaBundler<>,
115
128
  config: ConfigT,
116
129
  options: TransformInputOptions,
130
+ resolverOptions: ResolverInputOptions,
117
131
  ): Promise<TransformFn<>> {
118
132
  const {inlineRequires, ...transformOptions} = await calcTransformerOptions(
119
133
  entryFiles,
@@ -121,6 +135,7 @@ async function getTransformFn(
121
135
  deltaBundler,
122
136
  config,
123
137
  options,
138
+ resolverOptions,
124
139
  );
125
140
 
126
141
  return async (modulePath: string, requireContext: ?RequireContext) => {
@@ -186,12 +201,17 @@ function getType(
186
201
  async function getResolveDependencyFn(
187
202
  bundler: Bundler,
188
203
  platform: ?string,
204
+ resolverOptions: ResolverInputOptions,
189
205
  ): Promise<(from: string, to: string) => string> {
190
206
  const dependencyGraph = await await bundler.getDependencyGraph();
191
207
 
192
208
  return (from: string, to: string) =>
193
- // $FlowFixMe[incompatible-call]
194
- dependencyGraph.resolveDependency(from, to, platform);
209
+ dependencyGraph.resolveDependency(
210
+ from,
211
+ to,
212
+ platform ?? null,
213
+ resolverOptions,
214
+ );
195
215
  }
196
216
 
197
217
  module.exports = {
@@ -24,6 +24,7 @@ const util = require("util");
24
24
  class ModuleResolver {
25
25
  // A module representing the project root, used as the origin when resolving `emptyModulePath`.
26
26
  // An empty module, the result of resolving `emptyModulePath` from the project root.
27
+ // $FlowFixMe[missing-local-annot]
27
28
  constructor(options) {
28
29
  this._options = options;
29
30
  const { projectRoot, moduleCache } = this._options;
@@ -50,7 +51,9 @@ class ModuleResolver {
50
51
  this._projectRootFakeModule,
51
52
  this._options.emptyModulePath,
52
53
  false,
53
- null
54
+ null,
55
+ /* resolverOptions */
56
+ {}
54
57
  );
55
58
  this._cachedEmptyModule = emptyModule;
56
59
  }
@@ -110,11 +113,24 @@ class ModuleResolver {
110
113
  return modulePath;
111
114
  }
112
115
 
113
- resolveDependency(fromModule, moduleName, allowHaste, platform) {
116
+ resolveDependency(
117
+ fromModule,
118
+ moduleName,
119
+ allowHaste,
120
+ platform,
121
+ resolverOptions
122
+ ) {
114
123
  try {
124
+ var _resolverOptions$cust;
125
+
115
126
  const result = Resolver.resolve(
116
127
  {
117
128
  ...this._options,
129
+ customResolverOptions:
130
+ (_resolverOptions$cust = resolverOptions.customResolverOptions) !==
131
+ null && _resolverOptions$cust !== void 0
132
+ ? _resolverOptions$cust
133
+ : {},
118
134
  originModulePath: fromModule.path,
119
135
  redirectModulePath: (modulePath) =>
120
136
  this._redirectRequire(fromModule, modulePath),
@@ -26,6 +26,7 @@ const invariant = require('invariant');
26
26
  const Resolver = require('metro-resolver');
27
27
  const path = require('path');
28
28
  const util = require('util');
29
+ import type {ResolverInputOptions} from '../../shared/types.flow';
29
30
 
30
31
  export type DirExistsFn = (filePath: string) => boolean;
31
32
 
@@ -78,6 +79,7 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
78
79
  // An empty module, the result of resolving `emptyModulePath` from the project root.
79
80
  _cachedEmptyModule: ?TModule;
80
81
 
82
+ // $FlowFixMe[missing-local-annot]
81
83
  constructor(options: Options<TModule, TPackage>) {
82
84
  this._options = options;
83
85
  const {projectRoot, moduleCache} = this._options;
@@ -102,6 +104,7 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
102
104
  this._options.emptyModulePath,
103
105
  false,
104
106
  null,
107
+ /* resolverOptions */ {},
105
108
  );
106
109
  this._cachedEmptyModule = emptyModule;
107
110
  }
@@ -166,11 +169,13 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
166
169
  moduleName: string,
167
170
  allowHaste: boolean,
168
171
  platform: string | null,
172
+ resolverOptions: ResolverInputOptions,
169
173
  ): TModule {
170
174
  try {
171
175
  const result = Resolver.resolve(
172
176
  {
173
177
  ...this._options,
178
+ customResolverOptions: resolverOptions.customResolverOptions ?? {},
174
179
  originModulePath: fromModule.path,
175
180
  redirectModulePath: (modulePath: string) =>
176
181
  this._redirectRequire(fromModule, modulePath),