-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: method for resolving the directory of a package #42219
Comments
|
the internal const require = createRequire(import.meta.url);
const rootExportPath = require.resolve('xyz'); // assuming root export
const xyzDirectoryPath = readPackageScope(rootExportPath).path // NOT exposed externally node/lib/internal/modules/cjs/loader.js Lines 321 to 336 in acc11c9
|
@nodejs/modules |
what would resolvePackageDirectory do when the target is not a folder with a package.json |
also do exports actually stop you from resolving package.json files? that seems like an anti-feature. |
Yes, exports does stop that. This api is one the modules group was on board to land, but never got built. |
This is a duplicate of #49445 and also discussed in nodejs/loaders#26, but I guess it’s not really a duplicate if it’s in the |
Is there any reason addressing it needs to wait for loaders to land? There's many use cases for it that don't (and can't) involve loaders. |
@ljharb there's no reason to wait for loaders to land, the loaders team has plans to do it in the future but I don't think they would mind if someone else was pushing it forward (quite the contrary), you (or anyone else) are welcome to open a PR to add an API doing this; however such API would have to align with the loader use case – so we don't end up with several slightly different API that don't interop with one another. |
Great, as long as the reverse is also true - that anything loaders provides also handles the non-loader use cases. |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
unstale |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
bump |
This is basically a duplicate of nodejs/loaders#26, right? If so, I'm inclined to close this as inactionable / blocked-on / whatever and direct people to the loaders issue. |
I don’t know if we want to make issues in other repos canonical. We archive those other repos occasionally, and we wouldn’t want to lose batches of feature requests when we do so. Yes this is duplicative, but only in the sense that the loaders issue is a proposal for an API to would do a bunch of things including satisfying this request. |
I don't see how a loader can satisfy this request, which is runtime resolution long after the program has begun. |
It doesn't matter to me if it's this issue that stays open or the loaders one but having two issues (and discussions) for the same feature isn't great. I'll close this but feel free to reopen when the other issue is resolved/archived/etc. To people coming here from search engines, please go here: nodejs/loaders#26 |
What is the problem this feature will solve?
exposing node's module resolution algorithm to utilities
What is the feature you are proposing to solve the problem?
What alternatives have you considered?
the previous trick was
but with the introduction of the
exports
specifier, there is no reliable way to resolve the package's location on diskThe text was updated successfully, but these errors were encountered: