metro 0.74.0 → 0.75.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metro",
3
- "version": "0.74.0",
3
+ "version": "0.75.0",
4
4
  "description": "🚇 The JavaScript bundler for React Native.",
5
5
  "main": "src/index.js",
6
6
  "bin": "src/cli.js",
@@ -35,23 +35,23 @@
35
35
  "invariant": "^2.2.4",
36
36
  "jest-worker": "^27.2.0",
37
37
  "lodash.throttle": "^4.1.1",
38
- "metro-babel-transformer": "0.74.0",
39
- "metro-cache": "0.74.0",
40
- "metro-cache-key": "0.74.0",
41
- "metro-config": "0.74.0",
42
- "metro-core": "0.74.0",
43
- "metro-file-map": "0.74.0",
44
- "metro-hermes-compiler": "0.74.0",
45
- "metro-inspector-proxy": "0.74.0",
46
- "metro-minify-terser": "0.74.0",
47
- "metro-minify-uglify": "0.74.0",
48
- "metro-react-native-babel-preset": "0.74.0",
49
- "metro-resolver": "0.74.0",
50
- "metro-runtime": "0.74.0",
51
- "metro-source-map": "0.74.0",
52
- "metro-symbolicate": "0.74.0",
53
- "metro-transform-plugins": "0.74.0",
54
- "metro-transform-worker": "0.74.0",
38
+ "metro-babel-transformer": "0.75.0",
39
+ "metro-cache": "0.75.0",
40
+ "metro-cache-key": "0.75.0",
41
+ "metro-config": "0.75.0",
42
+ "metro-core": "0.75.0",
43
+ "metro-file-map": "0.75.0",
44
+ "metro-hermes-compiler": "0.75.0",
45
+ "metro-inspector-proxy": "0.75.0",
46
+ "metro-minify-terser": "0.75.0",
47
+ "metro-minify-uglify": "0.75.0",
48
+ "metro-react-native-babel-preset": "0.75.0",
49
+ "metro-resolver": "0.75.0",
50
+ "metro-runtime": "0.75.0",
51
+ "metro-source-map": "0.75.0",
52
+ "metro-symbolicate": "0.75.0",
53
+ "metro-transform-plugins": "0.75.0",
54
+ "metro-transform-worker": "0.75.0",
55
55
  "mime-types": "^2.1.27",
56
56
  "node-fetch": "^2.2.0",
57
57
  "nullthrows": "^1.1.1",
@@ -70,13 +70,16 @@
70
70
  "dedent": "^0.7.0",
71
71
  "jest-snapshot": "^26.5.2",
72
72
  "jest-snapshot-serializer-raw": "^1.2.0",
73
- "metro-babel-register": "0.74.0",
74
- "metro-memory-fs": "0.74.0",
75
- "metro-react-native-babel-preset": "0.74.0",
76
- "metro-react-native-babel-transformer": "0.74.0",
73
+ "metro-babel-register": "0.75.0",
74
+ "metro-memory-fs": "0.75.0",
75
+ "metro-react-native-babel-preset": "0.75.0",
76
+ "metro-react-native-babel-transformer": "0.75.0",
77
77
  "mock-req": "^0.2.0",
78
78
  "mock-res": "^0.6.0",
79
79
  "stack-trace": "^0.0.10"
80
80
  },
81
- "license": "MIT"
81
+ "license": "MIT",
82
+ "engines": {
83
+ "node": ">=14.17.0"
84
+ }
82
85
  }
@@ -12,6 +12,7 @@
12
12
  "use strict";
13
13
 
14
14
  var _Graph = require("./Graph");
15
+ const debug = require("debug")("Metro:DeltaCalculator");
15
16
  const { EventEmitter } = require("events");
16
17
 
17
18
  /**
@@ -24,6 +25,7 @@ class DeltaCalculator extends EventEmitter {
24
25
  _deletedFiles = new Set();
25
26
  _modifiedFiles = new Set();
26
27
  _addedFiles = new Set();
28
+ _hasSymlinkChanges = false;
27
29
  constructor(entryPoints, changeEventSource, options) {
28
30
  super();
29
31
  this._options = options;
@@ -60,6 +62,7 @@ class DeltaCalculator extends EventEmitter {
60
62
  * which contain the modified/added modules and the removed modules.
61
63
  */
62
64
  async getDelta({ reset, shallow }) {
65
+ debug("Calculating delta (reset: %s, shallow: %s)", reset, shallow);
63
66
  // If there is already a build in progress, wait until it finish to start
64
67
  // processing a new one (delta server doesn't support concurrent builds).
65
68
  if (this._currentBuildPromise) {
@@ -75,6 +78,21 @@ class DeltaCalculator extends EventEmitter {
75
78
  this._deletedFiles = new Set();
76
79
  const addedFiles = this._addedFiles;
77
80
  this._addedFiles = new Set();
81
+ const hasSymlinkChanges = this._hasSymlinkChanges;
82
+ this._hasSymlinkChanges = false;
83
+
84
+ // Revisit all files if changes include symlinks - resolutions may be
85
+ // invalidated but we don't yet know which. This should be optimized in the
86
+ // future.
87
+ if (hasSymlinkChanges) {
88
+ const markModified = (file) => {
89
+ if (!addedFiles.has(file) && !deletedFiles.has(file)) {
90
+ modifiedFiles.add(file);
91
+ }
92
+ };
93
+ this._graph.dependencies.forEach((_, key) => markModified(key));
94
+ this._graph.entryPoints.forEach(markModified);
95
+ }
78
96
 
79
97
  // Concurrent requests should reuse the same bundling process. To do so,
80
98
  // this method stores the promise as an instance variable, and then it's
@@ -145,7 +163,15 @@ class DeltaCalculator extends EventEmitter {
145
163
  * the listener only stores the modified file, which will then be used later
146
164
  * when the delta needs to be calculated.
147
165
  */
148
- _handleFileChange = ({ type, filePath }, logger) => {
166
+ _handleFileChange = ({ type, filePath, metadata }, logger) => {
167
+ debug("Handling %s: %s (type: %s)", type, filePath, metadata.type);
168
+ if (metadata.type === "l") {
169
+ this._hasSymlinkChanges = true;
170
+ this.emit("change", {
171
+ logger,
172
+ });
173
+ return;
174
+ }
149
175
  let state;
150
176
  if (this._deletedFiles.has(filePath)) {
151
177
  state = "deleted";
@@ -14,7 +14,9 @@
14
14
  import {Graph} from './Graph';
15
15
  import type {DeltaResult, Options} from './types.flow';
16
16
  import type {RootPerfLogger} from 'metro-config';
17
+ import type {ChangeEventMetadata} from 'metro-file-map';
17
18
 
19
+ const debug = require('debug')('Metro:DeltaCalculator');
18
20
  const {EventEmitter} = require('events');
19
21
 
20
22
  /**
@@ -31,6 +33,7 @@ class DeltaCalculator<T> extends EventEmitter {
31
33
  _deletedFiles: Set<string> = new Set();
32
34
  _modifiedFiles: Set<string> = new Set();
33
35
  _addedFiles: Set<string> = new Set();
36
+ _hasSymlinkChanges = false;
34
37
 
35
38
  _graph: Graph<T>;
36
39
 
@@ -85,6 +88,7 @@ class DeltaCalculator<T> extends EventEmitter {
85
88
  shallow: boolean,
86
89
  ...
87
90
  }): Promise<DeltaResult<T>> {
91
+ debug('Calculating delta (reset: %s, shallow: %s)', reset, shallow);
88
92
  // If there is already a build in progress, wait until it finish to start
89
93
  // processing a new one (delta server doesn't support concurrent builds).
90
94
  if (this._currentBuildPromise) {
@@ -100,6 +104,21 @@ class DeltaCalculator<T> extends EventEmitter {
100
104
  this._deletedFiles = new Set();
101
105
  const addedFiles = this._addedFiles;
102
106
  this._addedFiles = new Set();
107
+ const hasSymlinkChanges = this._hasSymlinkChanges;
108
+ this._hasSymlinkChanges = false;
109
+
110
+ // Revisit all files if changes include symlinks - resolutions may be
111
+ // invalidated but we don't yet know which. This should be optimized in the
112
+ // future.
113
+ if (hasSymlinkChanges) {
114
+ const markModified = (file: string) => {
115
+ if (!addedFiles.has(file) && !deletedFiles.has(file)) {
116
+ modifiedFiles.add(file);
117
+ }
118
+ };
119
+ this._graph.dependencies.forEach((_, key) => markModified(key));
120
+ this._graph.entryPoints.forEach(markModified);
121
+ }
103
122
 
104
123
  // Concurrent requests should reuse the same bundling process. To do so,
105
124
  // this method stores the promise as an instance variable, and then it's
@@ -178,13 +197,21 @@ class DeltaCalculator<T> extends EventEmitter {
178
197
  {
179
198
  type,
180
199
  filePath,
200
+ metadata,
181
201
  }: {
182
202
  type: string,
183
203
  filePath: string,
204
+ metadata: ChangeEventMetadata,
184
205
  ...
185
206
  },
186
207
  logger: ?RootPerfLogger,
187
208
  ): mixed => {
209
+ debug('Handling %s: %s (type: %s)', type, filePath, metadata.type);
210
+ if (metadata.type === 'l') {
211
+ this._hasSymlinkChanges = true;
212
+ this.emit('change', {logger});
213
+ return;
214
+ }
188
215
  let state: void | 'deleted' | 'modified' | 'added';
189
216
  if (this._deletedFiles.has(filePath)) {
190
217
  state = 'deleted';
@@ -429,7 +429,7 @@ class Graph {
429
429
  } else {
430
430
  try {
431
431
  resolvedDep = {
432
- absolutePath: options.resolve(parentPath, dep.name),
432
+ absolutePath: options.resolve(parentPath, dep.name).filePath,
433
433
  data: dep,
434
434
  };
435
435
 
@@ -503,7 +503,7 @@ export class Graph<T = MixedOutput> {
503
503
  } else {
504
504
  try {
505
505
  resolvedDep = {
506
- absolutePath: options.resolve(parentPath, dep.name),
506
+ absolutePath: options.resolve(parentPath, dep.name).filePath,
507
507
  data: dep,
508
508
  };
509
509
 
@@ -78,6 +78,7 @@ class WorkerFarm {
78
78
  return new JestWorker(workerPath, {
79
79
  computeWorkerKey: this._config.stickyWorkers
80
80
  ? // $FlowFixMe[method-unbinding] added when improving typing for this parameters
81
+ // $FlowFixMe[incompatible-call]
81
82
  this._computeWorkerKey
82
83
  : undefined,
83
84
  exposedMethods,
@@ -120,6 +120,7 @@ class WorkerFarm {
120
120
  return new JestWorker(workerPath, {
121
121
  computeWorkerKey: this._config.stickyWorkers
122
122
  ? // $FlowFixMe[method-unbinding] added when improving typing for this parameters
123
+ // $FlowFixMe[incompatible-call]
123
124
  this._computeWorkerKey
124
125
  : undefined,
125
126
  exposedMethods,
@@ -126,8 +126,13 @@ export type AllowOptionalDependencies =
126
126
  | boolean
127
127
  | AllowOptionalDependenciesWithOptions;
128
128
 
129
+ export type BundlerResolution = $ReadOnly<{
130
+ type: 'sourceFile',
131
+ filePath: string,
132
+ }>;
133
+
129
134
  export type Options<T = MixedOutput> = {
130
- +resolve: (from: string, to: string) => string,
135
+ +resolve: (from: string, to: string) => BundlerResolution,
131
136
  +transform: TransformFn<T>,
132
137
  +transformOptions: TransformInputOptions,
133
138
  +onProgress: ?(numProcessed: number, total: number) => mixed,
package/src/HmrServer.js CHANGED
@@ -82,7 +82,7 @@ class HmrServer {
82
82
  ? _this$_config$server$
83
83
  : this._config.projectRoot) + "/.",
84
84
  entryFile
85
- );
85
+ ).filePath;
86
86
  const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
87
87
  resolverOptions,
88
88
  shallow: graphOptions.shallow,
@@ -124,7 +124,7 @@ class HmrServer<TClient: Client> {
124
124
  (this._config.server.unstable_serverRoot ?? this._config.projectRoot) +
125
125
  '/.',
126
126
  entryFile,
127
- );
127
+ ).filePath;
128
128
  const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
129
129
  resolverOptions,
130
130
  shallow: graphOptions.shallow,
package/src/Server.js CHANGED
@@ -392,7 +392,7 @@ class Server {
392
392
  bundlePerfLogger:
393
393
  (_this$_config$unstabl =
394
394
  (_this$_config$unstabl2 = (_this$_config = this._config)
395
- .unstable_perfLogger) === null ||
395
+ .unstable_perfLoggerFactory) === null ||
396
396
  _this$_config$unstabl2 === void 0
397
397
  ? void 0
398
398
  : _this$_config$unstabl2.call(
@@ -1162,7 +1162,7 @@ class Server {
1162
1162
  relativeTo === "server"
1163
1163
  ? this._getServerRootDir()
1164
1164
  : this._config.projectRoot;
1165
- return resolutionFn(`${rootDir}/.`, filePath);
1165
+ return resolutionFn(`${rootDir}/.`, filePath).filePath;
1166
1166
  }
1167
1167
  getNewBuildNumber() {
1168
1168
  return this._nextBundleBuildNumber++;
@@ -519,7 +519,7 @@ class Server {
519
519
  await this._processBundleRequest(req, res, options, {
520
520
  buildNumber,
521
521
  bundlePerfLogger:
522
- this._config.unstable_perfLogger?.('BUNDLING_REQUEST', {
522
+ this._config.unstable_perfLoggerFactory?.('BUNDLING_REQUEST', {
523
523
  key: buildNumber,
524
524
  }) ?? noopLogger,
525
525
  });
@@ -1364,7 +1364,7 @@ class Server {
1364
1364
  relativeTo === 'server'
1365
1365
  ? this._getServerRootDir()
1366
1366
  : this._config.projectRoot;
1367
- return resolutionFn(`${rootDir}/.`, filePath);
1367
+ return resolutionFn(`${rootDir}/.`, filePath).filePath;
1368
1368
  }
1369
1369
 
1370
1370
  getNewBuildNumber(): number {
@@ -59,18 +59,24 @@ function formatBundlingError(error) {
59
59
  } else if (error instanceof ResourceNotFoundError) {
60
60
  return {
61
61
  type: "ResourceNotFoundError",
62
+ // $FlowFixMe[missing-empty-array-annot]
63
+ // $FlowFixMe[incompatible-return]
62
64
  errors: [],
63
65
  message: error.message,
64
66
  };
65
67
  } else if (error instanceof GraphNotFoundError) {
66
68
  return {
67
69
  type: "GraphNotFoundError",
70
+ // $FlowFixMe[missing-empty-array-annot]
71
+ // $FlowFixMe[incompatible-return]
68
72
  errors: [],
69
73
  message: error.message,
70
74
  };
71
75
  } else if (error instanceof RevisionNotFoundError) {
72
76
  return {
73
77
  type: "RevisionNotFoundError",
78
+ // $FlowFixMe[missing-empty-array-annot]
79
+ // $FlowFixMe[incompatible-return]
74
80
  errors: [],
75
81
  message: error.message,
76
82
  };
@@ -74,18 +74,24 @@ 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
+ // $FlowFixMe[incompatible-return]
77
79
  errors: [],
78
80
  message: error.message,
79
81
  };
80
82
  } else if (error instanceof GraphNotFoundError) {
81
83
  return {
82
84
  type: 'GraphNotFoundError',
85
+ // $FlowFixMe[missing-empty-array-annot]
86
+ // $FlowFixMe[incompatible-return]
83
87
  errors: [],
84
88
  message: error.message,
85
89
  };
86
90
  } else if (error instanceof RevisionNotFoundError) {
87
91
  return {
88
92
  type: 'RevisionNotFoundError',
93
+ // $FlowFixMe[missing-empty-array-annot]
94
+ // $FlowFixMe[incompatible-return]
89
95
  errors: [],
90
96
  message: error.message,
91
97
  };
@@ -39,6 +39,7 @@ function getAppendScripts(entryPoint, modules, options) {
39
39
  data: {
40
40
  code,
41
41
  lineCount: countLines(code),
42
+ // $FlowFixMe[missing-empty-array-annot]
42
43
  map: [],
43
44
  },
44
45
  },
@@ -68,6 +69,7 @@ function getAppendScripts(entryPoint, modules, options) {
68
69
  data: {
69
70
  code,
70
71
  lineCount: countLines(code),
72
+ // $FlowFixMe[missing-empty-array-annot]
71
73
  map: [],
72
74
  },
73
75
  },
@@ -87,6 +89,7 @@ function getAppendScripts(entryPoint, modules, options) {
87
89
  data: {
88
90
  code,
89
91
  lineCount: countLines(code),
92
+ // $FlowFixMe[missing-empty-array-annot]
90
93
  map: [],
91
94
  },
92
95
  },
@@ -58,6 +58,7 @@ function getAppendScripts<T: number | string>(
58
58
  data: {
59
59
  code,
60
60
  lineCount: countLines(code),
61
+ // $FlowFixMe[missing-empty-array-annot]
61
62
  map: [],
62
63
  },
63
64
  },
@@ -89,6 +90,7 @@ function getAppendScripts<T: number | string>(
89
90
  data: {
90
91
  code,
91
92
  lineCount: countLines(code),
93
+ // $FlowFixMe[missing-empty-array-annot]
92
94
  map: [],
93
95
  },
94
96
  },
@@ -109,6 +111,7 @@ function getAppendScripts<T: number | string>(
109
111
  data: {
110
112
  code,
111
113
  lineCount: countLines(code),
114
+ // $FlowFixMe[missing-empty-array-annot]
112
115
  map: [],
113
116
  },
114
117
  },
@@ -90,6 +90,7 @@ function _getPrelude({ dev, globalPrefix, requireCycleIgnorePatterns }) {
90
90
  data: {
91
91
  code,
92
92
  lineCount: countLines(code),
93
+ // $FlowFixMe[missing-empty-array-annot]
93
94
  map: [],
94
95
  },
95
96
  },
@@ -113,6 +113,7 @@ function _getPrelude({
113
113
  data: {
114
114
  code,
115
115
  lineCount: countLines(code),
116
+ // $FlowFixMe[missing-empty-array-annot]
116
117
  map: [],
117
118
  },
118
119
  },
@@ -13,7 +13,10 @@
13
13
 
14
14
  import type Bundler from '../Bundler';
15
15
  import type DeltaBundler, {TransformFn} from '../DeltaBundler';
16
- import type {TransformInputOptions} from '../DeltaBundler/types.flow';
16
+ import type {
17
+ BundlerResolution,
18
+ TransformInputOptions,
19
+ } from '../DeltaBundler/types.flow';
17
20
  import type {TransformOptions} from '../DeltaBundler/Worker';
18
21
  import type {ConfigT} from 'metro-config/src/configTypes.flow';
19
22
  import type {Type} from 'metro-transform-worker';
@@ -203,7 +206,7 @@ async function getResolveDependencyFn(
203
206
  bundler: Bundler,
204
207
  platform: ?string,
205
208
  resolverOptions: ResolverInputOptions,
206
- ): Promise<(from: string, to: string) => string> {
209
+ ): Promise<(from: string, to: string) => BundlerResolution> {
207
210
  const dependencyGraph = await await bundler.getDependencyGraph();
208
211
 
209
212
  return (from: string, to: string) =>
@@ -15,6 +15,7 @@ const { codeFrameColumns } = require("@babel/code-frame");
15
15
  const fs = require("fs");
16
16
  const invariant = require("invariant");
17
17
  const Resolver = require("metro-resolver");
18
+ const createDefaultContext = require("metro-resolver/src/createDefaultContext");
18
19
  const path = require("path");
19
20
  const util = require("util");
20
21
  class ModuleResolver {
@@ -52,53 +53,6 @@ class ModuleResolver {
52
53
  }
53
54
  return emptyModule;
54
55
  }
55
- _redirectRequire(fromModule, modulePath) {
56
- const moduleCache = this._options.moduleCache;
57
- try {
58
- if (modulePath.startsWith(".")) {
59
- const fromPackage = fromModule.getPackage();
60
- if (fromPackage) {
61
- // We need to convert the module path from module-relative to
62
- // package-relative, so that we can easily match it against the
63
- // "browser" map (where all paths are relative to the package root)
64
- const fromPackagePath =
65
- "./" +
66
- path.relative(
67
- path.dirname(fromPackage.path),
68
- path.resolve(path.dirname(fromModule.path), modulePath)
69
- );
70
- let redirectedPath = fromPackage.redirectRequire(
71
- fromPackagePath,
72
- this._options.mainFields
73
- );
74
-
75
- // Since the redirected path is still relative to the package root,
76
- // we have to transform it back to be module-relative (as it
77
- // originally was)
78
- if (redirectedPath !== false) {
79
- redirectedPath =
80
- "./" +
81
- path.relative(
82
- path.dirname(fromModule.path),
83
- path.resolve(path.dirname(fromPackage.path), redirectedPath)
84
- );
85
- }
86
- return redirectedPath;
87
- }
88
- } else {
89
- const pck = path.isAbsolute(modulePath)
90
- ? moduleCache.getPackageOf(modulePath)
91
- : fromModule.getPackage();
92
- if (pck) {
93
- return pck.redirectRequire(modulePath, this._options.mainFields);
94
- }
95
- }
96
- } catch (err) {
97
- // Do nothing. The standard module cache does not trigger any error, but
98
- // the ModuleGraph one does, if the module does not exist.
99
- }
100
- return modulePath;
101
- }
102
56
  resolveDependency(
103
57
  fromModule,
104
58
  moduleName,
@@ -106,27 +60,53 @@ class ModuleResolver {
106
60
  platform,
107
61
  resolverOptions
108
62
  ) {
63
+ const {
64
+ disableHierarchicalLookup,
65
+ doesFileExist,
66
+ extraNodeModules,
67
+ isAssetFile,
68
+ mainFields,
69
+ nodeModulesPaths,
70
+ preferNativePlatform,
71
+ resolveAsset,
72
+ resolveRequest,
73
+ sourceExts,
74
+ unstable_conditionNames,
75
+ unstable_conditionsByPlatform,
76
+ unstable_enablePackageExports,
77
+ } = this._options;
109
78
  try {
110
79
  var _resolverOptions$cust;
111
80
  const result = Resolver.resolve(
112
- {
113
- ...this._options,
81
+ createDefaultContext({
82
+ allowHaste,
83
+ disableHierarchicalLookup,
84
+ doesFileExist,
85
+ extraNodeModules,
86
+ isAssetFile,
87
+ mainFields,
88
+ nodeModulesPaths,
89
+ preferNativePlatform,
90
+ resolveAsset,
91
+ resolveRequest,
92
+ sourceExts,
93
+ unstable_conditionNames,
94
+ unstable_conditionsByPlatform,
95
+ unstable_enablePackageExports,
114
96
  customResolverOptions:
115
97
  (_resolverOptions$cust = resolverOptions.customResolverOptions) !==
116
98
  null && _resolverOptions$cust !== void 0
117
99
  ? _resolverOptions$cust
118
100
  : {},
119
101
  originModulePath: fromModule.path,
120
- redirectModulePath: (modulePath) =>
121
- this._redirectRequire(fromModule, modulePath),
122
- allowHaste,
123
- platform,
124
102
  resolveHasteModule: (name) =>
125
103
  this._options.getHasteModulePath(name, platform),
126
104
  resolveHastePackage: (name) =>
127
105
  this._options.getHastePackagePath(name, platform),
128
- getPackageMainPath: this._getPackageMainPath,
129
- },
106
+ getPackage: this._getPackage,
107
+ getPackageForModule: (modulePath) =>
108
+ this._getPackageForModule(fromModule, modulePath),
109
+ }),
130
110
  moduleName,
131
111
  platform
132
112
  );
@@ -174,27 +154,48 @@ class ModuleResolver {
174
154
  throw error;
175
155
  }
176
156
  }
177
- _getPackageMainPath = (packageJsonPath) => {
178
- const package_ = this._options.moduleCache.getPackage(packageJsonPath);
179
- return package_.getMain(this._options.mainFields);
157
+ _getPackage = (packageJsonPath) => {
158
+ try {
159
+ return this._options.moduleCache.getPackage(packageJsonPath).read();
160
+ } catch (e) {
161
+ // Do nothing. The standard module cache does not trigger any error, but
162
+ // the ModuleGraph one does, if the module does not exist.
163
+ }
164
+ return null;
165
+ };
166
+ _getPackageForModule = (fromModule, modulePath) => {
167
+ let pkg;
168
+ try {
169
+ pkg = this._options.moduleCache.getPackageOf(modulePath);
170
+ } catch (e) {
171
+ // Do nothing. The standard module cache does not trigger any error, but
172
+ // the ModuleGraph one does, if the module does not exist.
173
+ }
174
+ return pkg != null
175
+ ? {
176
+ rootPath: path.dirname(pkg.path),
177
+ packageJson: pkg.read(),
178
+ }
179
+ : null;
180
180
  };
181
181
 
182
182
  /**
183
- * FIXME: get rid of this function and of the reliance on `TModule`
184
- * altogether, return strongly typed resolutions at the top-level instead.
183
+ * TODO: Return Resolution instead of coercing to BundlerResolution here
185
184
  */
186
185
  _getFileResolvedModule(resolution) {
187
186
  switch (resolution.type) {
188
187
  case "sourceFile":
189
- return this._options.moduleCache.getModule(resolution.filePath);
188
+ return resolution;
190
189
  case "assetFiles":
191
190
  // FIXME: we should forward ALL the paths/metadata,
192
191
  // not just an arbitrary item!
193
192
  const arbitrary = getArrayLowestItem(resolution.filePaths);
194
193
  invariant(arbitrary != null, "invalid asset resolution");
195
- return this._options.moduleCache.getModule(arbitrary);
194
+ return {
195
+ type: "sourceFile",
196
+ filePath: arbitrary,
197
+ };
196
198
  case "empty":
197
- // $FlowFixMe[incompatible-return]
198
199
  return this._getEmptyModule();
199
200
  default:
200
201
  resolution.type;