metro 0.75.1 → 0.76.0

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 (55) hide show
  1. package/package.json +23 -24
  2. package/src/Assets.js +2 -2
  3. package/src/Assets.js.flow +1 -1
  4. package/src/DeltaBundler/Graph.js +11 -28
  5. package/src/DeltaBundler/Graph.js.flow +7 -0
  6. package/src/DeltaBundler/Serializers/helpers/js.js +2 -7
  7. package/src/DeltaBundler/types.flow.js.flow +1 -7
  8. package/src/HmrServer.js +9 -32
  9. package/src/IncrementalBundler.js +5 -9
  10. package/src/ModuleGraph/worker/collectDependencies.js +53 -89
  11. package/src/ModuleGraph/worker/collectDependencies.js.flow +113 -141
  12. package/src/Server/symbolicate.js +1 -5
  13. package/src/Server.js +10 -53
  14. package/src/commands/dependencies.js +1 -5
  15. package/src/index.flow.js +1 -2
  16. package/src/integration_tests/basic_bundle/TestBigInt.js +0 -3
  17. package/src/integration_tests/basic_bundle/TestBigInt.js.flow +0 -3
  18. package/src/integration_tests/basic_bundle/require-resolveWeak/import-and-resolveWeak.js +28 -0
  19. package/src/integration_tests/basic_bundle/require-resolveWeak/import-and-resolveWeak.js.flow +33 -0
  20. package/src/integration_tests/basic_bundle/require-resolveWeak/multiple.js +20 -0
  21. package/src/integration_tests/basic_bundle/require-resolveWeak/multiple.js.flow +23 -0
  22. package/src/integration_tests/basic_bundle/require-resolveWeak/never-required.js +18 -0
  23. package/src/integration_tests/basic_bundle/require-resolveWeak/never-required.js.flow +21 -0
  24. package/src/integration_tests/basic_bundle/require-resolveWeak/require-and-resolveWeak.js +28 -0
  25. package/src/integration_tests/basic_bundle/require-resolveWeak/require-and-resolveWeak.js.flow +33 -0
  26. package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/counter-module.js +19 -0
  27. package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/counter-module.js.flow +18 -0
  28. package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/throwing-module.js +13 -0
  29. package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/throwing-module.js.flow +11 -0
  30. package/src/integration_tests/basic_bundle/require-resolveWeak/utils.js +1 -0
  31. package/src/integration_tests/basic_bundle/require-resolveWeak/utils.js.flow +14 -0
  32. package/src/lib/CountingSet.js +1 -5
  33. package/src/lib/RamBundleParser.js +0 -1
  34. package/src/lib/RamBundleParser.js.flow +0 -1
  35. package/src/lib/TerminalReporter.js +3 -17
  36. package/src/lib/contextModuleTemplates.js +1 -1
  37. package/src/lib/contextModuleTemplates.js.flow +1 -1
  38. package/src/lib/formatBundlingError.js +0 -3
  39. package/src/lib/formatBundlingError.js.flow +0 -3
  40. package/src/lib/getAppendScripts.js +0 -3
  41. package/src/lib/getAppendScripts.js.flow +0 -3
  42. package/src/lib/getGraphId.js +2 -11
  43. package/src/lib/getPrependedScripts.js +0 -1
  44. package/src/lib/getPrependedScripts.js.flow +0 -1
  45. package/src/lib/transformHelpers.js +14 -22
  46. package/src/lib/transformHelpers.js.flow +5 -8
  47. package/src/node-haste/DependencyGraph/ModuleResolution.js +4 -11
  48. package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +3 -5
  49. package/src/node-haste/DependencyGraph/createHasteMap.js +13 -38
  50. package/src/node-haste/DependencyGraph/createHasteMap.js.flow +2 -1
  51. package/src/node-haste/DependencyGraph.js +6 -17
  52. package/src/node-haste/DependencyGraph.js.flow +1 -5
  53. package/src/node-haste/Module.js +5 -3
  54. package/src/node-haste/Module.js.flow +2 -3
  55. package/src/node-haste/ModuleCache.js +1 -5
@@ -17,7 +17,6 @@ const fs = require("fs");
17
17
  const { loadConfig } = require("metro-config");
18
18
  const path = require("path");
19
19
  async function dependencies(args, config) {
20
- var _config$server$unstab;
21
20
  const rootModuleAbsolutePath = args.entryFile;
22
21
  if (!fs.existsSync(rootModuleAbsolutePath)) {
23
22
  return Promise.reject(
@@ -26,10 +25,7 @@ async function dependencies(args, config) {
26
25
  }
27
26
  config.cacheStores = [];
28
27
  const relativePath = path.relative(
29
- (_config$server$unstab = config.server.unstable_serverRoot) !== null &&
30
- _config$server$unstab !== void 0
31
- ? _config$server$unstab
32
- : config.projectRoot,
28
+ config.server.unstable_serverRoot ?? config.projectRoot,
33
29
  rootModuleAbsolutePath
34
30
  );
35
31
  const options = {
package/src/index.flow.js CHANGED
@@ -45,8 +45,7 @@ async function runMetro(config, options) {
45
45
  port,
46
46
  type: "initialize_started",
47
47
  });
48
- const { waitForBundler = false, ...serverOptions } =
49
- options !== null && options !== void 0 ? options : {};
48
+ const { waitForBundler = false, ...serverOptions } = options ?? {};
50
49
  const server = new MetroServer(mergedConfig, serverOptions);
51
50
  const readyPromise = server
52
51
  .ready()
@@ -10,11 +10,8 @@
10
10
 
11
11
  "use strict";
12
12
 
13
- // $FlowIssue[bigint-unsupported]
14
13
  // $FlowFixMe[signature-verification-failure]
15
14
  var a = 2n;
16
- // $FlowIssue[bigint-unsupported]
17
15
  // $FlowFixMe[signature-verification-failure]
18
16
  var b = 3n;
19
- // $FlowFixMe[unsafe-addition]
20
17
  module.exports = a ** b;
@@ -10,11 +10,8 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- // $FlowIssue[bigint-unsupported]
14
13
  // $FlowFixMe[signature-verification-failure]
15
14
  var a = 2n;
16
- // $FlowIssue[bigint-unsupported]
17
15
  // $FlowFixMe[signature-verification-failure]
18
16
  var b = 3n;
19
- // $FlowFixMe[unsafe-addition]
20
17
  module.exports = a ** b;
@@ -0,0 +1,28 @@
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
+
13
+ async function main() {
14
+ const moduleId = require.resolveWeak("./subdir/counter-module");
15
+
16
+ // Require the module statically via its path, spelled slightly differently
17
+ (await import("./subdir/counter-module.js")).increment();
18
+ const dynamicRequire = require;
19
+
20
+ // Require the module dynamically via its ID
21
+ const timesIncremented = dynamicRequire(moduleId).increment();
22
+ return {
23
+ moduleId,
24
+ // Should be 2, proving there's just one module instance
25
+ timesIncremented,
26
+ };
27
+ }
28
+ module.exports = main();
@@ -0,0 +1,33 @@
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 {RequireWithResolveWeak} from './utils';
12
+
13
+ declare var require: RequireWithResolveWeak;
14
+
15
+ async function main() {
16
+ const moduleId = require.resolveWeak('./subdir/counter-module');
17
+
18
+ // Require the module statically via its path, spelled slightly differently
19
+ (await import('./subdir/counter-module.js')).increment();
20
+
21
+ const dynamicRequire = require;
22
+
23
+ // Require the module dynamically via its ID
24
+ const timesIncremented = dynamicRequire(moduleId).increment();
25
+
26
+ return {
27
+ moduleId,
28
+ // Should be 2, proving there's just one module instance
29
+ timesIncremented,
30
+ };
31
+ }
32
+
33
+ module.exports = (main(): mixed);
@@ -0,0 +1,20 @@
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
+
13
+ async function main() {
14
+ return {
15
+ counterModuleId1: require.resolveWeak("./subdir/counter-module"),
16
+ counterModuleId2: require.resolveWeak("./subdir/counter-module.js"),
17
+ throwingModuleId: require.resolveWeak("./subdir/throwing-module.js"),
18
+ };
19
+ }
20
+ module.exports = main();
@@ -0,0 +1,23 @@
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 {RequireWithResolveWeak} from './utils';
12
+
13
+ declare var require: RequireWithResolveWeak;
14
+
15
+ async function main() {
16
+ return {
17
+ counterModuleId1: require.resolveWeak('./subdir/counter-module'),
18
+ counterModuleId2: require.resolveWeak('./subdir/counter-module.js'),
19
+ throwingModuleId: require.resolveWeak('./subdir/throwing-module.js'),
20
+ };
21
+ }
22
+
23
+ module.exports = (main(): mixed);
@@ -0,0 +1,18 @@
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
+
13
+ function main() {
14
+ return {
15
+ moduleId: require.resolveWeak("./subdir/throwing-module"),
16
+ };
17
+ }
18
+ module.exports = main();
@@ -0,0 +1,21 @@
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 {RequireWithResolveWeak} from './utils';
12
+
13
+ declare var require: RequireWithResolveWeak;
14
+
15
+ function main() {
16
+ return {
17
+ moduleId: require.resolveWeak('./subdir/throwing-module'),
18
+ };
19
+ }
20
+
21
+ module.exports = (main(): mixed);
@@ -0,0 +1,28 @@
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
+
13
+ function main() {
14
+ const moduleId = require.resolveWeak("./subdir/counter-module");
15
+ const dynamicRequire = require;
16
+
17
+ // Require the module dynamically via its ID
18
+ dynamicRequire(moduleId).increment();
19
+
20
+ // Require the module statically via its path, spelled slightly differently
21
+ const timesIncremented = require("./subdir/counter-module.js").increment();
22
+ return {
23
+ moduleId,
24
+ // Should be 2, proving there's just one module instance
25
+ timesIncremented,
26
+ };
27
+ }
28
+ module.exports = main();
@@ -0,0 +1,33 @@
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 {RequireWithResolveWeak} from './utils';
12
+
13
+ declare var require: RequireWithResolveWeak;
14
+
15
+ function main() {
16
+ const moduleId = require.resolveWeak('./subdir/counter-module');
17
+
18
+ const dynamicRequire = require;
19
+
20
+ // Require the module dynamically via its ID
21
+ dynamicRequire(moduleId).increment();
22
+
23
+ // Require the module statically via its path, spelled slightly differently
24
+ const timesIncremented = require('./subdir/counter-module.js').increment();
25
+
26
+ return {
27
+ moduleId,
28
+ // Should be 2, proving there's just one module instance
29
+ timesIncremented,
30
+ };
31
+ }
32
+
33
+ module.exports = (main(): mixed);
@@ -0,0 +1,19 @@
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
+
13
+ let count = 0;
14
+ module.exports = {
15
+ increment() {
16
+ ++count;
17
+ return count;
18
+ },
19
+ };
@@ -0,0 +1,18 @@
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
+ let count: number = 0;
12
+
13
+ module.exports = {
14
+ increment(): number {
15
+ ++count;
16
+ return count;
17
+ },
18
+ };
@@ -0,0 +1,13 @@
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
+
13
+ throw new Error("This module cannot be evaluated.");
@@ -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-local
9
+ */
10
+
11
+ throw new Error('This module cannot be evaluated.');
@@ -0,0 +1,14 @@
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
+ export type RequireWithResolveWeak = {
12
+ (id: string | number): any,
13
+ resolveWeak: (id: string) => string | number,
14
+ };
@@ -79,11 +79,7 @@ class CountingSet {
79
79
  return this.#map.size;
80
80
  }
81
81
  count(item) {
82
- var _this$map$get;
83
- return (_this$map$get = this.#map.get(item)) !== null &&
84
- _this$map$get !== void 0
85
- ? _this$map$get
86
- : 0;
82
+ return this.#map.get(item) ?? 0;
87
83
  }
88
84
  clear() {
89
85
  this.#map.clear();
@@ -24,7 +24,6 @@ const HEADER_SIZE = 3;
24
24
  * getModule(): returns the code for the specified module.
25
25
  */
26
26
  class RamBundleParser {
27
- // $FlowFixMe[missing-local-annot]
28
27
  constructor(buffer) {
29
28
  this._buffer = buffer;
30
29
  if (this._readPosition(0) !== MAGIC_NUMBER) {
@@ -29,7 +29,6 @@ class RamBundleParser {
29
29
  _startupCodeLength: number;
30
30
  _startOffset: number;
31
31
 
32
- // $FlowFixMe[missing-local-annot]
33
32
  constructor(buffer: Buffer) {
34
33
  this._buffer = buffer;
35
34
 
@@ -367,30 +367,16 @@ class TerminalReporter {
367
367
  reporting.logWarning(this.terminal, message);
368
368
  }
369
369
  _logWatcherHealthCheckResult(result) {
370
- var _result$pauseReason, _this$_prevHealthChec;
371
370
  // Don't be spammy; only report changes in status.
372
371
  if (
373
372
  !this._prevHealthCheckResult ||
374
373
  result.type !== this._prevHealthCheckResult.type ||
375
374
  (result.type === "timeout" &&
376
375
  this._prevHealthCheckResult.type === "timeout" &&
377
- ((_result$pauseReason = result.pauseReason) !== null &&
378
- _result$pauseReason !== void 0
379
- ? _result$pauseReason
380
- : null) !==
381
- ((_this$_prevHealthChec = this._prevHealthCheckResult.pauseReason) !==
382
- null && _this$_prevHealthChec !== void 0
383
- ? _this$_prevHealthChec
384
- : null))
376
+ (result.pauseReason ?? null) !==
377
+ (this._prevHealthCheckResult.pauseReason ?? null))
385
378
  ) {
386
- var _result$watcher;
387
- const watcherName =
388
- "'" +
389
- ((_result$watcher = result.watcher) !== null &&
390
- _result$watcher !== void 0
391
- ? _result$watcher
392
- : "unknown") +
393
- "'";
379
+ const watcherName = "'" + (result.watcher ?? "unknown") + "'";
394
380
  switch (result.type) {
395
381
  case "success":
396
382
  // Only report success after a prior failure.
@@ -66,7 +66,7 @@ function createFileMap(modulePath, files, processModule) {
66
66
  .forEach((file) => {
67
67
  let filePath = path.relative(modulePath, file);
68
68
  if (os.platform() === "win32") {
69
- filePath = filePath.replace(/\\/g, "/");
69
+ filePath = filePath.replaceAll("\\", "/");
70
70
  }
71
71
 
72
72
  // NOTE(EvanBacon): I'd prefer we prevent the ability for a module to require itself (`require.context('./')`)
@@ -28,7 +28,7 @@ function createFileMap(
28
28
  let filePath = path.relative(modulePath, file);
29
29
 
30
30
  if (os.platform() === 'win32') {
31
- filePath = filePath.replace(/\\/g, '/');
31
+ filePath = filePath.replaceAll('\\', '/');
32
32
  }
33
33
 
34
34
  // NOTE(EvanBacon): I'd prefer we prevent the ability for a module to require itself (`require.context('./')`)
@@ -59,7 +59,6 @@ function formatBundlingError(error) {
59
59
  } else if (error instanceof ResourceNotFoundError) {
60
60
  return {
61
61
  type: "ResourceNotFoundError",
62
- // $FlowFixMe[missing-empty-array-annot]
63
62
  // $FlowFixMe[incompatible-return]
64
63
  errors: [],
65
64
  message: error.message,
@@ -67,7 +66,6 @@ function formatBundlingError(error) {
67
66
  } else if (error instanceof GraphNotFoundError) {
68
67
  return {
69
68
  type: "GraphNotFoundError",
70
- // $FlowFixMe[missing-empty-array-annot]
71
69
  // $FlowFixMe[incompatible-return]
72
70
  errors: [],
73
71
  message: error.message,
@@ -75,7 +73,6 @@ function formatBundlingError(error) {
75
73
  } else if (error instanceof RevisionNotFoundError) {
76
74
  return {
77
75
  type: "RevisionNotFoundError",
78
- // $FlowFixMe[missing-empty-array-annot]
79
76
  // $FlowFixMe[incompatible-return]
80
77
  errors: [],
81
78
  message: error.message,
@@ -74,7 +74,6 @@ function formatBundlingError(error: CustomError): FormattedError {
74
74
  } else if (error instanceof ResourceNotFoundError) {
75
75
  return {
76
76
  type: 'ResourceNotFoundError',
77
- // $FlowFixMe[missing-empty-array-annot]
78
77
  // $FlowFixMe[incompatible-return]
79
78
  errors: [],
80
79
  message: error.message,
@@ -82,7 +81,6 @@ function formatBundlingError(error: CustomError): FormattedError {
82
81
  } else if (error instanceof GraphNotFoundError) {
83
82
  return {
84
83
  type: 'GraphNotFoundError',
85
- // $FlowFixMe[missing-empty-array-annot]
86
84
  // $FlowFixMe[incompatible-return]
87
85
  errors: [],
88
86
  message: error.message,
@@ -90,7 +88,6 @@ function formatBundlingError(error: CustomError): FormattedError {
90
88
  } else if (error instanceof RevisionNotFoundError) {
91
89
  return {
92
90
  type: 'RevisionNotFoundError',
93
- // $FlowFixMe[missing-empty-array-annot]
94
91
  // $FlowFixMe[incompatible-return]
95
92
  errors: [],
96
93
  message: error.message,
@@ -39,7 +39,6 @@ function getAppendScripts(entryPoint, modules, options) {
39
39
  data: {
40
40
  code,
41
41
  lineCount: countLines(code),
42
- // $FlowFixMe[missing-empty-array-annot]
43
42
  map: [],
44
43
  },
45
44
  },
@@ -69,7 +68,6 @@ function getAppendScripts(entryPoint, modules, options) {
69
68
  data: {
70
69
  code,
71
70
  lineCount: countLines(code),
72
- // $FlowFixMe[missing-empty-array-annot]
73
71
  map: [],
74
72
  },
75
73
  },
@@ -89,7 +87,6 @@ function getAppendScripts(entryPoint, modules, options) {
89
87
  data: {
90
88
  code,
91
89
  lineCount: countLines(code),
92
- // $FlowFixMe[missing-empty-array-annot]
93
90
  map: [],
94
91
  },
95
92
  },
@@ -58,7 +58,6 @@ function getAppendScripts<T: number | string>(
58
58
  data: {
59
59
  code,
60
60
  lineCount: countLines(code),
61
- // $FlowFixMe[missing-empty-array-annot]
62
61
  map: [],
63
62
  },
64
63
  },
@@ -90,7 +89,6 @@ function getAppendScripts<T: number | string>(
90
89
  data: {
91
90
  code,
92
91
  lineCount: countLines(code),
93
- // $FlowFixMe[missing-empty-array-annot]
94
92
  map: [],
95
93
  },
96
94
  },
@@ -111,7 +109,6 @@ function getAppendScripts<T: number | string>(
111
109
  data: {
112
110
  code,
113
111
  lineCount: countLines(code),
114
- // $FlowFixMe[missing-empty-array-annot]
115
112
  map: [],
116
113
  },
117
114
  },
@@ -22,21 +22,12 @@ function getGraphId(
22
22
  resolverOptions,
23
23
  }
24
24
  ) {
25
- var _resolverOptions$cust, _options$customTransf;
26
25
  return JSON.stringify(
27
26
  {
28
27
  entryFile,
29
28
  options: {
30
- customResolverOptions:
31
- (_resolverOptions$cust = resolverOptions.customResolverOptions) !==
32
- null && _resolverOptions$cust !== void 0
33
- ? _resolverOptions$cust
34
- : {},
35
- customTransformOptions:
36
- (_options$customTransf = options.customTransformOptions) !== null &&
37
- _options$customTransf !== void 0
38
- ? _options$customTransf
39
- : null,
29
+ customResolverOptions: resolverOptions.customResolverOptions ?? {},
30
+ customTransformOptions: options.customTransformOptions ?? null,
40
31
  dev: options.dev,
41
32
  experimentalImportSupport: options.experimentalImportSupport || false,
42
33
  hot: options.hot,
@@ -92,7 +92,6 @@ function _getPrelude({ dev, globalPrefix, requireCycleIgnorePatterns }) {
92
92
  data: {
93
93
  code,
94
94
  lineCount: countLines(code),
95
- // $FlowFixMe[missing-empty-array-annot]
96
95
  map: [],
97
96
  },
98
97
  },
@@ -115,7 +115,6 @@ function _getPrelude({
115
115
  data: {
116
116
  code,
117
117
  lineCount: countLines(code),
118
- // $FlowFixMe[missing-empty-array-annot]
119
118
  map: [],
120
119
  },
121
120
  },
@@ -12,7 +12,12 @@
12
12
  "use strict";
13
13
 
14
14
  var _contextModuleTemplates = require("./contextModuleTemplates");
15
- const path = require("path");
15
+ var _isAssetFile = _interopRequireDefault(
16
+ require("metro-resolver/src/utils/isAssetFile")
17
+ );
18
+ function _interopRequireDefault(obj) {
19
+ return obj && obj.__esModule ? obj : { default: obj };
20
+ }
16
21
  const baseIgnoredInlineRequires = ["React", "react", "react-native"];
17
22
  async function calcTransformerOptions(
18
23
  entryFiles,
@@ -84,22 +89,12 @@ async function calcTransformerOptions(
84
89
  );
85
90
  return {
86
91
  ...baseOptions,
87
- inlineRequires:
88
- (transform === null || transform === void 0
89
- ? void 0
90
- : transform.inlineRequires) || false,
91
- experimentalImportSupport:
92
- (transform === null || transform === void 0
93
- ? void 0
94
- : transform.experimentalImportSupport) || false,
92
+ inlineRequires: transform?.inlineRequires || false,
93
+ experimentalImportSupport: transform?.experimentalImportSupport || false,
95
94
  unstable_disableES6Transforms:
96
- (transform === null || transform === void 0
97
- ? void 0
98
- : transform.unstable_disableES6Transforms) || false,
95
+ transform?.unstable_disableES6Transforms || false,
99
96
  nonInlinedRequires:
100
- (transform === null || transform === void 0
101
- ? void 0
102
- : transform.nonInlinedRequires) || baseIgnoredInlineRequires,
97
+ transform?.nonInlinedRequires || baseIgnoredInlineRequires,
103
98
  type: "module",
104
99
  };
105
100
  }
@@ -125,6 +120,7 @@ async function getTransformFn(
125
120
  options,
126
121
  resolverOptions
127
122
  );
123
+ const assetExts = new Set(config.resolver.assetExts);
128
124
  return async (modulePath, requireContext) => {
129
125
  let templateBuffer;
130
126
  if (requireContext) {
@@ -150,11 +146,7 @@ async function getTransformFn(
150
146
  modulePath,
151
147
  {
152
148
  ...transformOptions,
153
- type: getType(
154
- transformOptions.type,
155
- modulePath,
156
- config.resolver.assetExts
157
- ),
149
+ type: getType(transformOptions.type, modulePath, assetExts),
158
150
  inlineRequires: removeInlineRequiresBlockListFromOptions(
159
151
  modulePath,
160
152
  inlineRequires
@@ -168,7 +160,7 @@ function getType(type, filePath, assetExts) {
168
160
  if (type === "script") {
169
161
  return type;
170
162
  }
171
- if (assetExts.indexOf(path.extname(filePath).slice(1)) !== -1) {
163
+ if ((0, _isAssetFile.default)(filePath, assetExts)) {
172
164
  return "asset";
173
165
  }
174
166
  return "module";
@@ -179,7 +171,7 @@ async function getResolveDependencyFn(bundler, platform, resolverOptions) {
179
171
  dependencyGraph.resolveDependency(
180
172
  from,
181
173
  to,
182
- platform !== null && platform !== void 0 ? platform : null,
174
+ platform ?? null,
183
175
  resolverOptions
184
176
  );
185
177
  }