metro 0.63.0 → 0.64.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 (90) hide show
  1. package/package.json +22 -22
  2. package/src/Assets.js +8 -2
  3. package/src/Bundler/util.js +17 -10
  4. package/src/Bundler/util.js.flow +13 -12
  5. package/src/Bundler.js +4 -0
  6. package/src/DeltaBundler/DeltaCalculator.js +6 -1
  7. package/src/DeltaBundler/Serializers/baseBytecodeBundle.js +10 -0
  8. package/src/DeltaBundler/Serializers/baseJSBundle.js +5 -0
  9. package/src/DeltaBundler/Serializers/getAllFiles.js +6 -0
  10. package/src/DeltaBundler/Serializers/getAssets.js +4 -0
  11. package/src/DeltaBundler/Serializers/getRamBundleInfo.js +6 -0
  12. package/src/DeltaBundler/Serializers/helpers/bytecode.js +5 -0
  13. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js +5 -0
  14. package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js +2 -0
  15. package/src/DeltaBundler/Serializers/helpers/processModules.js +2 -0
  16. package/src/DeltaBundler/Serializers/hmrJSBundle.js +8 -2
  17. package/src/DeltaBundler/Serializers/sourceMapGenerator.js +4 -0
  18. package/src/DeltaBundler/Serializers/sourceMapObject.js +4 -0
  19. package/src/DeltaBundler/Transformer.js +16 -0
  20. package/src/DeltaBundler/Worker.js +4 -0
  21. package/src/DeltaBundler/WorkerFarm.js +9 -0
  22. package/src/DeltaBundler/computeDelta.js +5 -0
  23. package/src/DeltaBundler/getTransformCacheKey.js +1 -1
  24. package/src/DeltaBundler/mergeDeltas.js +5 -0
  25. package/src/DeltaBundler/traverseDependencies.js +14 -0
  26. package/src/DeltaBundler.js +6 -1
  27. package/src/HmrServer.js +18 -0
  28. package/src/IncrementalBundler.js +16 -0
  29. package/src/ModuleGraph/node-haste/Package.js +5 -0
  30. package/src/ModuleGraph/node-haste/node-haste.flow.js.flow +0 -2
  31. package/src/ModuleGraph/node-haste/node-haste.js +3 -0
  32. package/src/ModuleGraph/node-haste/node-haste.js.flow +4 -2
  33. package/src/ModuleGraph/output/indexed-ram-bundle.js +10 -0
  34. package/src/ModuleGraph/output/multiple-files-ram-bundle.js +10 -0
  35. package/src/ModuleGraph/output/reverse-dependency-map-references.js +33 -9
  36. package/src/ModuleGraph/output/reverse-dependency-map-references.js.flow +28 -13
  37. package/src/ModuleGraph/output/util.js +59 -25
  38. package/src/ModuleGraph/output/util.js.flow +59 -23
  39. package/src/ModuleGraph/test-helpers.js +74 -2
  40. package/src/ModuleGraph/types.flow.js.flow +13 -8
  41. package/src/ModuleGraph/worker/JsFileWrapping.js +90 -12
  42. package/src/ModuleGraph/worker/JsFileWrapping.js.flow +34 -20
  43. package/src/ModuleGraph/worker/collectDependencies.js +329 -205
  44. package/src/ModuleGraph/worker/collectDependencies.js.flow +397 -209
  45. package/src/ModuleGraph/worker/generate.js.flow +2 -2
  46. package/src/ModuleGraph/worker/generateImportNames.js +2 -1
  47. package/src/ModuleGraph/worker/generateImportNames.js.flow +3 -4
  48. package/src/ModuleGraph/worker/mergeSourceMaps.js +5 -0
  49. package/src/Server/symbolicate.js +14 -0
  50. package/src/Server.js +16 -3
  51. package/src/Server.js.flow +1 -0
  52. package/src/cli-utils.js +4 -0
  53. package/src/cli.js +0 -0
  54. package/src/commands/build.js +10 -0
  55. package/src/commands/build.js.flow +2 -0
  56. package/src/commands/dependencies.js +4 -0
  57. package/src/commands/serve.js +5 -0
  58. package/src/commands/serve.js.flow +2 -0
  59. package/src/index.js +13 -1
  60. package/src/index.js.flow +2 -0
  61. package/src/integration_tests/basic_bundle/import-export/index.js +19 -2
  62. package/src/integration_tests/execBundle.js +2 -2
  63. package/src/integration_tests/metro.config.js +4 -0
  64. package/src/lib/BatchProcessor.js +1 -1
  65. package/src/lib/TerminalReporter.js +10 -0
  66. package/src/lib/attachWebsocketServer.js +5 -1
  67. package/src/lib/bundleToBytecode.js +7 -3
  68. package/src/lib/bundleToString.js +6 -1
  69. package/src/lib/debounceAsyncQueue.js +4 -0
  70. package/src/lib/getAppendScripts.js +2 -0
  71. package/src/lib/getPreludeCode.js +2 -0
  72. package/src/lib/getPrependedScripts.js +11 -0
  73. package/src/lib/logToConsole.js +1 -2
  74. package/src/lib/parseOptionsFromUrl.js +5 -0
  75. package/src/lib/reporting.js +1 -1
  76. package/src/lib/splitBundleOptions.js +1 -1
  77. package/src/lib/transformHelpers.js +19 -3
  78. package/src/lib/transformHelpers.js.flow +4 -4
  79. package/src/node-haste/DependencyGraph/ModuleResolution.js +10 -2
  80. package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +6 -5
  81. package/src/node-haste/DependencyGraph.js +11 -2
  82. package/src/node-haste/DependencyGraph.js.flow +5 -0
  83. package/src/node-haste/Package.js +2 -0
  84. package/src/shared/output/RamBundle/as-assets.js +1 -2
  85. package/src/shared/output/RamBundle/as-indexed-file.js +2 -0
  86. package/src/shared/output/RamBundle/util.js +2 -2
  87. package/src/shared/output/RamBundle.js +9 -0
  88. package/src/shared/output/bundle.js +9 -0
  89. package/src/ModuleGraph/worker/optimizeDependencies.js +0 -122
  90. package/src/ModuleGraph/worker/optimizeDependencies.js.flow +0 -128
@@ -11,6 +11,7 @@
11
11
 
12
12
  function ownKeys(object, enumerableOnly) {
13
13
  var keys = Object.keys(object);
14
+
14
15
  if (Object.getOwnPropertySymbols) {
15
16
  var symbols = Object.getOwnPropertySymbols(object);
16
17
  if (enumerableOnly)
@@ -19,12 +20,14 @@ function ownKeys(object, enumerableOnly) {
19
20
  });
20
21
  keys.push.apply(keys, symbols);
21
22
  }
23
+
22
24
  return keys;
23
25
  }
24
26
 
25
27
  function _objectSpread(target) {
26
28
  for (var i = 1; i < arguments.length; i++) {
27
29
  var source = arguments[i] != null ? arguments[i] : {};
30
+
28
31
  if (i % 2) {
29
32
  ownKeys(Object(source), true).forEach(function(key) {
30
33
  _defineProperty(target, key, source[key]);
@@ -41,6 +44,7 @@ function _objectSpread(target) {
41
44
  });
42
45
  }
43
46
  }
47
+
44
48
  return target;
45
49
  }
46
50
 
@@ -55,6 +59,7 @@ function _defineProperty(obj, key, value) {
55
59
  } else {
56
60
  obj[key] = value;
57
61
  }
62
+
58
63
  return obj;
59
64
  }
60
65
 
@@ -63,10 +63,8 @@ type HasteMapOptions = {|
63
63
  preferNativePlatform: true,
64
64
  |};
65
65
 
66
- /* eslint-disable flowtype/object-type-delimiter */
67
66
  declare class HasteMap {
68
67
  // node-haste/DependencyGraph/HasteMap.js
69
68
  build(): Promise<Object>;
70
69
  constructor(options: HasteMapOptions): void;
71
70
  }
72
- /* eslint-enable flowtype/object-type-delimiter */
@@ -45,7 +45,9 @@ function _arrayWithoutHoles(arr) {
45
45
 
46
46
  function _arrayLikeToArray(arr, len) {
47
47
  if (len == null || len > arr.length) len = arr.length;
48
+
48
49
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
50
+
49
51
  return arr2;
50
52
  }
51
53
 
@@ -183,6 +185,7 @@ exports.createResolveFn = function(options) {
183
185
  mocks: new Map(),
184
186
  rootDir: ""
185
187
  }),
188
+ nodeModulesPaths: options.nodeModulesPaths,
186
189
  preferNativePlatform: true,
187
190
  projectRoot: "",
188
191
  resolveAsset: (dirPath, assetName, extension) => {
@@ -29,14 +29,15 @@ import type {Extensions, Path} from './node-haste.flow';
29
29
  import type {CustomResolver} from 'metro-resolver';
30
30
 
31
31
  type ResolveOptions = {|
32
+ +platform: string,
33
+ +sourceExts: Extensions,
32
34
  assetExts: Extensions,
33
35
  assetResolutions: $ReadOnlyArray<string>,
34
36
  extraNodeModules: {[id: string]: string, ...},
35
37
  mainFields: $ReadOnlyArray<string>,
38
+ nodeModulesPaths: $ReadOnlyArray<string>,
36
39
  resolveRequest?: ?CustomResolver,
37
- +sourceExts: Extensions,
38
40
  transformedFiles: {[path: Path]: TransformedCodeFile, ...},
39
- +platform: string,
40
41
  |};
41
42
 
42
43
  const platforms = new Set(defaults.platforms);
@@ -147,6 +148,7 @@ exports.createResolveFn = function(options: ResolveOptions): ResolveFn {
147
148
  mocks: new Map(),
148
149
  rootDir: '',
149
150
  }),
151
+ nodeModulesPaths: options.nodeModulesPaths,
150
152
  preferNativePlatform: true,
151
153
  projectRoot: '',
152
154
  resolveAsset: (
@@ -11,6 +11,7 @@
11
11
 
12
12
  function ownKeys(object, enumerableOnly) {
13
13
  var keys = Object.keys(object);
14
+
14
15
  if (Object.getOwnPropertySymbols) {
15
16
  var symbols = Object.getOwnPropertySymbols(object);
16
17
  if (enumerableOnly)
@@ -19,12 +20,14 @@ function ownKeys(object, enumerableOnly) {
19
20
  });
20
21
  keys.push.apply(keys, symbols);
21
22
  }
23
+
22
24
  return keys;
23
25
  }
24
26
 
25
27
  function _objectSpread(target) {
26
28
  for (var i = 1; i < arguments.length; i++) {
27
29
  var source = arguments[i] != null ? arguments[i] : {};
30
+
28
31
  if (i % 2) {
29
32
  ownKeys(Object(source), true).forEach(function(key) {
30
33
  _defineProperty(target, key, source[key]);
@@ -41,6 +44,7 @@ function _objectSpread(target) {
41
44
  });
42
45
  }
43
46
  }
47
+
44
48
  return target;
45
49
  }
46
50
 
@@ -55,6 +59,7 @@ function _defineProperty(obj, key, value) {
55
59
  } else {
56
60
  obj[key] = value;
57
61
  }
62
+
58
63
  return obj;
59
64
  }
60
65
 
@@ -109,7 +114,9 @@ function _unsupportedIterableToArray(o, minLen) {
109
114
 
110
115
  function _arrayLikeToArray(arr, len) {
111
116
  if (len == null || len > arr.length) len = arr.length;
117
+
112
118
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
119
+
113
120
  return arr2;
114
121
  }
115
122
 
@@ -120,6 +127,7 @@ function _iterableToArrayLimit(arr, i) {
120
127
  var _n = true;
121
128
  var _d = false;
122
129
  var _e = undefined;
130
+
123
131
  try {
124
132
  for (
125
133
  var _i = arr[Symbol.iterator](), _s;
@@ -127,6 +135,7 @@ function _iterableToArrayLimit(arr, i) {
127
135
  _n = true
128
136
  ) {
129
137
  _arr.push(_s.value);
138
+
130
139
  if (i && _arr.length === i) break;
131
140
  }
132
141
  } catch (err) {
@@ -139,6 +148,7 @@ function _iterableToArrayLimit(arr, i) {
139
148
  if (_d) throw _e;
140
149
  }
141
150
  }
151
+
142
152
  return _arr;
143
153
  }
144
154
 
@@ -11,6 +11,7 @@
11
11
 
12
12
  function ownKeys(object, enumerableOnly) {
13
13
  var keys = Object.keys(object);
14
+
14
15
  if (Object.getOwnPropertySymbols) {
15
16
  var symbols = Object.getOwnPropertySymbols(object);
16
17
  if (enumerableOnly)
@@ -19,12 +20,14 @@ function ownKeys(object, enumerableOnly) {
19
20
  });
20
21
  keys.push.apply(keys, symbols);
21
22
  }
23
+
22
24
  return keys;
23
25
  }
24
26
 
25
27
  function _objectSpread(target) {
26
28
  for (var i = 1; i < arguments.length; i++) {
27
29
  var source = arguments[i] != null ? arguments[i] : {};
30
+
28
31
  if (i % 2) {
29
32
  ownKeys(Object(source), true).forEach(function(key) {
30
33
  _defineProperty(target, key, source[key]);
@@ -41,6 +44,7 @@ function _objectSpread(target) {
41
44
  });
42
45
  }
43
46
  }
47
+
44
48
  return target;
45
49
  }
46
50
 
@@ -55,6 +59,7 @@ function _defineProperty(obj, key, value) {
55
59
  } else {
56
60
  obj[key] = value;
57
61
  }
62
+
58
63
  return obj;
59
64
  }
60
65
 
@@ -109,7 +114,9 @@ function _unsupportedIterableToArray(o, minLen) {
109
114
 
110
115
  function _arrayLikeToArray(arr, len) {
111
116
  if (len == null || len > arr.length) len = arr.length;
117
+
112
118
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
119
+
113
120
  return arr2;
114
121
  }
115
122
 
@@ -120,6 +127,7 @@ function _iterableToArrayLimit(arr, i) {
120
127
  var _n = true;
121
128
  var _d = false;
122
129
  var _e = undefined;
130
+
123
131
  try {
124
132
  for (
125
133
  var _i = arr[Symbol.iterator](), _s;
@@ -127,6 +135,7 @@ function _iterableToArrayLimit(arr, i) {
127
135
  _n = true
128
136
  ) {
129
137
  _arr.push(_s.value);
138
+
130
139
  if (i && _arr.length === i) break;
131
140
  }
132
141
  } catch (err) {
@@ -139,6 +148,7 @@ function _iterableToArrayLimit(arr, i) {
139
148
  if (_d) throw _e;
140
149
  }
141
150
  }
151
+
142
152
  return _arr;
143
153
  }
144
154
 
@@ -9,6 +9,18 @@
9
9
  */
10
10
  "use strict";
11
11
 
12
+ var _invariant = _interopRequireDefault(require("invariant"));
13
+
14
+ var _nullthrows = _interopRequireDefault(require("nullthrows"));
15
+
16
+ function _interopRequireDefault(obj) {
17
+ return obj && obj.__esModule
18
+ ? obj
19
+ : {
20
+ default: obj
21
+ };
22
+ }
23
+
12
24
  function reverseDependencyMapReferences(_ref) {
13
25
  let t = _ref.types;
14
26
  return {
@@ -17,28 +29,40 @@ function reverseDependencyMapReferences(_ref) {
17
29
  const node = path.node;
18
30
 
19
31
  if (node.callee.name === `${state.opts.globalPrefix}__d`) {
20
- const lastArg = node.arguments[0].params.slice(-1)[0];
32
+ // $FlowFixMe Flow error uncovered by typing Babel more strictly
33
+ const lastArg = node.arguments[0].params.slice(-1)[0]; // $FlowFixMe Flow error uncovered by typing Babel more strictly
34
+
21
35
  const depMapName = lastArg && lastArg.name;
22
36
 
23
- if (!depMapName) {
37
+ if (depMapName == null) {
24
38
  return;
25
39
  }
26
40
 
27
- const scope = path.get("arguments.0.body").scope;
28
- const binding = scope.getBinding(depMapName);
41
+ const body = path.get("arguments.0.body");
42
+ (0, _invariant.default)(
43
+ !Array.isArray(body),
44
+ "meetro: Expected `body` to be a single path."
45
+ );
46
+ const scope = body.scope;
47
+ const binding = (0, _nullthrows.default)(
48
+ scope.getBinding(depMapName)
49
+ );
29
50
  binding.referencePaths.forEach(_ref2 => {
30
51
  let parentPath = _ref2.parentPath;
31
- const memberNode = parentPath.node;
52
+ const memberNode =
53
+ parentPath === null || parentPath === void 0
54
+ ? void 0
55
+ : parentPath.node;
32
56
 
33
57
  if (
58
+ memberNode != null &&
34
59
  memberNode.type === "MemberExpression" &&
35
60
  memberNode.property.type === "NumericLiteral"
36
61
  ) {
37
- parentPath.replaceWith(
38
- t.numericLiteral(
39
- state.opts.dependencyIds[memberNode.property.value]
40
- )
62
+ const numericLiteral = t.numericLiteral(
63
+ state.opts.dependencyIds[memberNode.property.value]
41
64
  );
65
+ (0, _nullthrows.default)(parentPath).replaceWith(numericLiteral);
42
66
  }
43
67
  });
44
68
  }
@@ -10,8 +10,11 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- import type {Path} from '@babel/traverse';
14
- import type {Types} from '@babel/types';
13
+ import type {NodePath} from '@babel/traverse';
14
+ import typeof * as Types from '@babel/types';
15
+ import type {CallExpression} from '@babel/types';
16
+ import invariant from 'invariant';
17
+ import nullthrows from 'nullthrows';
15
18
 
16
19
  type State = {|
17
20
  opts: {|
@@ -25,35 +28,47 @@ function reverseDependencyMapReferences({
25
28
  }: {
26
29
  types: Types,
27
30
  ...
28
- }): {|visitor: {|CallExpression: (path: Path, state: State) => void|}|} {
31
+ }): {|
32
+ visitor: {|
33
+ CallExpression: (path: NodePath<CallExpression>, state: State) => void,
34
+ |},
35
+ |} {
29
36
  return {
30
37
  visitor: {
31
- CallExpression(path: Path, state: State) {
38
+ CallExpression(path: NodePath<CallExpression>, state: State) {
32
39
  const {node} = path;
33
40
 
34
41
  if (node.callee.name === `${state.opts.globalPrefix}__d`) {
42
+ // $FlowFixMe Flow error uncovered by typing Babel more strictly
35
43
  const lastArg = node.arguments[0].params.slice(-1)[0];
36
- const depMapName = lastArg && lastArg.name;
44
+ // $FlowFixMe Flow error uncovered by typing Babel more strictly
45
+ const depMapName: ?string = lastArg && lastArg.name;
37
46
 
38
- if (!depMapName) {
47
+ if (depMapName == null) {
39
48
  return;
40
49
  }
41
50
 
42
- const scope = path.get('arguments.0.body').scope;
43
- const binding = scope.getBinding(depMapName);
51
+ const body = path.get('arguments.0.body');
52
+ invariant(
53
+ !Array.isArray(body),
54
+ 'meetro: Expected `body` to be a single path.',
55
+ );
56
+
57
+ const scope = body.scope;
58
+ const binding = nullthrows(scope.getBinding(depMapName));
44
59
 
45
60
  binding.referencePaths.forEach(({parentPath}) => {
46
- const memberNode = parentPath.node;
61
+ const memberNode = parentPath?.node;
47
62
 
48
63
  if (
64
+ memberNode != null &&
49
65
  memberNode.type === 'MemberExpression' &&
50
66
  memberNode.property.type === 'NumericLiteral'
51
67
  ) {
52
- parentPath.replaceWith(
53
- t.numericLiteral(
54
- state.opts.dependencyIds[memberNode.property.value],
55
- ),
68
+ const numericLiteral = t.numericLiteral(
69
+ state.opts.dependencyIds[memberNode.property.value],
56
70
  );
71
+ nullthrows(parentPath).replaceWith(numericLiteral);
57
72
  }
58
73
  });
59
74
  }
@@ -11,6 +11,7 @@
11
11
 
12
12
  function ownKeys(object, enumerableOnly) {
13
13
  var keys = Object.keys(object);
14
+
14
15
  if (Object.getOwnPropertySymbols) {
15
16
  var symbols = Object.getOwnPropertySymbols(object);
16
17
  if (enumerableOnly)
@@ -19,12 +20,14 @@ function ownKeys(object, enumerableOnly) {
19
20
  });
20
21
  keys.push.apply(keys, symbols);
21
22
  }
23
+
22
24
  return keys;
23
25
  }
24
26
 
25
27
  function _objectSpread(target) {
26
28
  for (var i = 1; i < arguments.length; i++) {
27
29
  var source = arguments[i] != null ? arguments[i] : {};
30
+
28
31
  if (i % 2) {
29
32
  ownKeys(Object(source), true).forEach(function(key) {
30
33
  _defineProperty(target, key, source[key]);
@@ -41,6 +44,7 @@ function _objectSpread(target) {
41
44
  });
42
45
  }
43
46
  }
47
+
44
48
  return target;
45
49
  }
46
50
 
@@ -55,6 +59,7 @@ function _defineProperty(obj, key, value) {
55
59
  } else {
56
60
  obj[key] = value;
57
61
  }
62
+
58
63
  return obj;
59
64
  }
60
65
 
@@ -94,7 +99,9 @@ function _arrayWithoutHoles(arr) {
94
99
 
95
100
  function _arrayLikeToArray(arr, len) {
96
101
  if (len == null || len > arr.length) len = arr.length;
102
+
97
103
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
104
+
98
105
  return arr2;
99
106
  }
100
107
 
@@ -115,15 +122,14 @@ const _require2 = require("metro-react-native-babel-preset"),
115
122
  passthroughSyntaxPlugins = _require2.passthroughSyntaxPlugins;
116
123
 
117
124
  const _require3 = require("@babel/core"),
118
- transformSync = _require3.transformSync;
119
-
120
- // Transformed modules have the form
125
+ transformSync = _require3.transformSync; // Transformed modules have the form
121
126
  // __d(function(require, module, global, exports, dependencyMap) {
122
127
  // /* code */
123
128
  // });
124
129
  //
125
130
  // This function adds the numeric module ID, and an array with dependencies of
126
131
  // the dependencies of the module before the closing parenthesis.
132
+
127
133
  function addModuleIdsToModuleWrapper(module, idForPath) {
128
134
  const dependencies = module.dependencies,
129
135
  file = module.file;
@@ -143,14 +149,14 @@ function addModuleIdsToModuleWrapper(module, idForPath) {
143
149
 
144
150
  exports.addModuleIdsToModuleWrapper = addModuleIdsToModuleWrapper;
145
151
 
146
- function inlineModuleIds(module, idForPath) {
147
- let _ref =
148
- arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
149
- _ref$dependencyMapRes = _ref.dependencyMapReservedName,
152
+ function inlineModuleIds(module, idForPath, _ref) {
153
+ let _ref$dependencyMapRes = _ref.dependencyMapReservedName,
150
154
  dependencyMapReservedName =
151
155
  _ref$dependencyMapRes === void 0 ? undefined : _ref$dependencyMapRes,
152
- globalPrefix = _ref.globalPrefix;
153
-
156
+ globalPrefix = _ref.globalPrefix,
157
+ _ref$ignoreMissingDep = _ref.ignoreMissingDependencyMapReference,
158
+ ignoreMissingDependencyMapReference =
159
+ _ref$ignoreMissingDep === void 0 ? false : _ref$ignoreMissingDep;
154
160
  const dependencies = module.dependencies,
155
161
  file = module.file;
156
162
  const code = file.code,
@@ -165,7 +171,8 @@ function inlineModuleIds(module, idForPath) {
165
171
  if (!dependencyIds.length) {
166
172
  // Nothing to inline in this module.
167
173
  return {
168
- moduleCode: addParamsToDefineCall(code, fileId),
174
+ fileId,
175
+ moduleCode: code,
169
176
  moduleMap: map
170
177
  };
171
178
  }
@@ -197,9 +204,16 @@ function inlineModuleIds(module, idForPath) {
197
204
  * integer printed as a simple sequence of digits.
198
205
  */
199
206
  if (!code.includes(dependencyMapReservedName)) {
200
- // If we're here, the module was probably generated by some code that
207
+ if (ignoreMissingDependencyMapReference) {
208
+ return {
209
+ fileId,
210
+ moduleCode: code,
211
+ moduleMap: map
212
+ };
213
+ } // If we're here, the module was probably generated by some code that
201
214
  // doesn't make the dependency map name externally configurable, or a
202
215
  // mock that needs to be updated.
216
+
203
217
  throw new Error(
204
218
  `Module has dependencies but does not use the preconfigured dependency map name '${dependencyMapReservedName}': ${file.path}\n` +
205
219
  "This is an internal error in Metro."
@@ -228,12 +242,14 @@ function inlineModuleIds(module, idForPath) {
228
242
  }
229
243
  );
230
244
  return {
231
- moduleCode: addParamsToDefineCall(inlinedCode, fileId),
245
+ fileId,
246
+ moduleCode: inlinedCode,
232
247
  moduleMap: map
233
248
  };
234
249
  }
235
250
 
236
- const _transformSync = transformSync(code, {
251
+ const ast = nullthrows(
252
+ transformSync(code, {
237
253
  ast: true,
238
254
  babelrc: false,
239
255
  code: false,
@@ -247,31 +263,45 @@ function inlineModuleIds(module, idForPath) {
247
263
  }
248
264
  ]
249
265
  ])
250
- }),
251
- ast = _transformSync.ast;
266
+ }).ast
267
+ );
252
268
 
253
269
  const _generate = generate(ast, path, ""),
254
270
  generatedCode = _generate.code,
255
271
  generatedMap = _generate.map;
256
272
 
257
273
  return {
258
- moduleCode: addParamsToDefineCall(generatedCode, fileId),
274
+ fileId,
275
+ moduleCode: generatedCode,
259
276
  moduleMap: map && generatedMap && mergeSourceMaps(path, map, generatedMap)
260
277
  };
261
278
  }
262
279
 
263
- function escapeRegex(str) {
264
- // From http://stackoverflow.com/questions/14076210/
265
- return str.replace(/([.?*+\^$\[\]\\(){}|\-])/g, "\\$1");
280
+ function inlineModuleIdsAndAddParamsToDefineCall(module, idForPath, options) {
281
+ const _inlineModuleIds = inlineModuleIds(module, idForPath, options),
282
+ fileId = _inlineModuleIds.fileId,
283
+ moduleCode = _inlineModuleIds.moduleCode,
284
+ moduleMap = _inlineModuleIds.moduleMap;
285
+
286
+ return {
287
+ moduleCode: addParamsToDefineCall(moduleCode, fileId),
288
+ moduleMap
289
+ };
266
290
  }
267
291
 
268
292
  exports.inlineModuleIds = inlineModuleIds;
293
+ exports.inlineModuleIdsAndAddParamsToDefineCall = inlineModuleIdsAndAddParamsToDefineCall;
269
294
 
295
+ function escapeRegex(str) {
296
+ // From http://stackoverflow.com/questions/14076210/
297
+ return str.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
298
+ }
270
299
  /**
271
300
  * 1. Adds the module ids to a file if the file is a module. If it's not (e.g.
272
301
  * a script) it just keeps it as-is.
273
302
  * 2. Packs the function map into the file's source map, if one exists.
274
303
  */
304
+
275
305
  function getModuleCodeAndMap(module, idForPath, options) {
276
306
  const file = module.file;
277
307
  let moduleCode, moduleMap;
@@ -283,13 +313,17 @@ function getModuleCodeAndMap(module, idForPath, options) {
283
313
  moduleCode = addModuleIdsToModuleWrapper(module, idForPath);
284
314
  moduleMap = file.map;
285
315
  } else {
286
- var _inlineModuleIds = inlineModuleIds(module, idForPath, {
287
- dependencyMapReservedName: options.dependencyMapReservedName,
288
- globalPrefix: options.globalPrefix
289
- });
316
+ var _inlineModuleIdsAndAd = inlineModuleIdsAndAddParamsToDefineCall(
317
+ module,
318
+ idForPath,
319
+ {
320
+ dependencyMapReservedName: options.dependencyMapReservedName,
321
+ globalPrefix: options.globalPrefix
322
+ }
323
+ );
290
324
 
291
- moduleCode = _inlineModuleIds.moduleCode;
292
- moduleMap = _inlineModuleIds.moduleMap;
325
+ moduleCode = _inlineModuleIdsAndAd.moduleCode;
326
+ moduleMap = _inlineModuleIdsAndAd.moduleMap;
293
327
  }
294
328
 
295
329
  if (moduleMap && moduleMap.sources) {