cli icon indicating copy to clipboard operation
cli copied to clipboard

cli-tools: Use resolver alongside resolveNodeModuleDir

Open Downchuck opened this issue 10 months ago • 3 comments

Describe the Feature

The CLI can use resolvers to find node module folders for dependencies in addition to the current search heuristic.

Node.js whether using ESM or CJS has require.resolve or import.meta.resolve -- this technique is already being used in the CLI, just not for the node modules resolution on dependencies. The method simply resolves packageName/package.json then gets the directory name.

Possible Implementations

While ESM may not be relevant, if it is used, the path returned by a resolver is a url,

import {fileURLToPath} from "node:url";

const resolvedUrl = import.meta.resolve("packageName/package.json");
console.log(fileURLToPath(resolvedUrl));

With CJS, and this is code already in the code base:

path.dirname(
      require.resolve('@react-native-community/example/package.json'),
),

A little simpler - as there are packages that define exports and an entry point (such as @react-navigation/bottom-tabs) - using import.meta.resolve("@react-navigation/bottom-tabs") will give the entry point, and one can still traverse up to the nearest package.json file (e.g. package-up).

Context

The find-up usage in findPackageDependencyDir is fine, but the resolver also makes sense, either as the first lookup option or as a fallback.

Downchuck avatar Feb 12 '25 18:02 Downchuck

@Downchuck what's the issue that you're trying to resolve with this one? Usage with other package manager e.g. pnpm?

szymonrybczak avatar Mar 07 '25 09:03 szymonrybczak

There hasn't been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

github-actions[bot] avatar Jun 06 '25 03:06 github-actions[bot]

That's correct - supporting other corepack managers

Downchuck avatar Jun 06 '25 04:06 Downchuck

There hasn't been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

github-actions[bot] avatar Sep 06 '25 03:09 github-actions[bot]

Could we get this in, it'd be incredibly helpful to allow --any-- async as there's no escape hatch here for getting that in on a pure sync path.

Downchuck avatar Sep 06 '25 04:09 Downchuck

@Downchuck What change are you proposing, and what problem is this solving, exactly? I don't understand the request here. A PR might be helpful.

robhogan avatar Sep 07 '25 19:09 robhogan