From 2d0a01cd7e244d4dbabc1718aa5c2d43a98b2d48 Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Thu, 13 Apr 2023 06:49:37 -0700 Subject: [PATCH] Mark ResolutionContext.getPackageForModule as deprecated 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 --- docs/Resolution.md | 2 +- packages/metro-resolver/src/types.js | 2 ++ packages/metro-resolver/types/types.d.ts | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/Resolution.md b/docs/Resolution.md index ab968d8a3f..e8111b0359 100644 --- a/docs/Resolution.md +++ b/docs/Resolution.md @@ -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`
Deprecated
Given a module path that may exist under an npm package, locates and returns the package root path and parsed `package.json` contents. diff --git a/packages/metro-resolver/src/types.js b/packages/metro-resolver/src/types.js index f9676b7737..69b1c8c3bb 100644 --- a/packages/metro-resolver/src/types.js +++ b/packages/metro-resolver/src/types.js @@ -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, diff --git a/packages/metro-resolver/types/types.d.ts b/packages/metro-resolver/types/types.d.ts index 94f50c00be..9285cf67f3 100644 --- a/packages/metro-resolver/types/types.d.ts +++ b/packages/metro-resolver/types/types.d.ts @@ -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;