Skip to content

Commit

Permalink
Mark ResolutionContext.getPackageForModule as deprecated
Browse files Browse the repository at this point in the history
Summary:
We've realised that the implementation of this API ([`DependencyGraph._getClosestPackage`](https://github.com/facebook/metro/blob/61a30b7fc2075cf53f87ae8ad7b7423d204ef670/packages/metro/src/node-haste/DependencyGraph.js#L152-L164)) is mismatched with the rest of the resolver, which will additionally consider options such as `context.nodeModulesPaths` and `context.extraNodeModules`. Therefore we're marking this API as deprecated, to discourage new features from relying on it.

We will not be physically removing this API for a long time yet! (`"browser"` field resolution relies on this.)

Changelog: [Internal]

Reviewed By: robhogan

Differential Revision: D44706188

fbshipit-source-id: c3c7c478c6f859e56a95c72d9d209ec137c8aa33
  • Loading branch information
huntie authored and facebook-github-bot committed Apr 13, 2023
1 parent b995303 commit 2d0a01c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/Resolution.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ The ordered list of fields in `package.json` that should be read to resolve a pa

Given the path to a `package.json` file, returns the parsed file contents.

#### `getPackageForModule: (modulePath: string) => ?PackageInfo`
#### `getPackageForModule: (modulePath: string) => ?PackageInfo` <div class="label deprecated">Deprecated</div>

Given a module path that may exist under an npm package, locates and returns the package root path and parsed `package.json` contents.

Expand Down
2 changes: 2 additions & 0 deletions packages/metro-resolver/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ export type ResolutionContext = $ReadOnly<{
/**
* Get the package information and parsed `package.json` file for for a given
* module path, if it is contained within an npm package.
*
* @deprecated See https://github.com/facebook/metro/commit/29c77bff31e2475a086bc3f04073f485da8f9ff0
*/
getPackageForModule: (modulePath: string) => ?PackageInfo,

Expand Down
2 changes: 2 additions & 0 deletions packages/metro-resolver/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export interface ResolutionContext {
/**
* Get the package information and parsed `package.json` file for for a given
* module path, if it is contained within an npm package.
*
* @deprecated
*/
readonly getPackageForModule: (modulePath: string) => PackageInfo | null;

Expand Down

0 comments on commit 2d0a01c

Please sign in to comment.