Skip to content

Feature request: add preserveSymlinks option to require.resolve() #18009

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

Closed
searls opened this issue Jan 5, 2018 · 8 comments
Closed

Feature request: add preserveSymlinks option to require.resolve() #18009

searls opened this issue Jan 5, 2018 · 8 comments
Labels
feature request Issues that request new features to be added to Node.js. module Issues and PRs related to the module subsystem. stale

Comments

@searls
Copy link

searls commented Jan 5, 2018

According to the docs, the only option currently on require.resolve(path[, options]) is paths. I have a project that I'm trying to eliminate a dependency on browserify/resolve, and the only thing holding me back is that my library needs to know the resolved path of a given string while preserving symlinks, regardless of whatever the end-user has set their global Node environment to.

I propose a second option be added to this method named preserveSymlinks which behaves the same way as the --preserve-symlinks CLI flag and ENV var, but is local only to the call on require.resolve().

I attempted to work around this by changing the NODE_PRESERVE_SYMLINKS env var at runtime, but it had no effect.

If this seems like an agreeable enhancement to require.resolve, I'd happily take a stab at a PR

@jasnell
Copy link
Member

jasnell commented Jan 5, 2018

I'm fine with this. I had suggested this previously and it wasn't too popular at the time -- but at that time there was no options argument on resolve() already. Now that it's there, the story might be different.

@cjihrig
Copy link
Contributor

cjihrig commented Jan 8, 2018

Something like this commit should do the trick. It would need benchmarked and documented though.

EDIT: module benchmark results:

                                                                        improvement confidence   p.value
 module/module-loader.js useCache="false" fullPath="false" thousands=50      0.08 %            0.9925357
 module/module-loader.js useCache="false" fullPath="true" thousands=50       2.62 %            0.6623119
 module/module-loader.js useCache="true" fullPath="false" thousands=50       0.46 %            0.7855123
 module/module-loader.js useCache="true" fullPath="true" thousands=50       -2.31 %            0.2031434

@safizn
Copy link

safizn commented Aug 26, 2018

I prefer adding an object as the argument for specific options which there is now already the options object argument https://nodejs.org/api/modules.html#modules_require_resolve_request_options.
e.g.
require.resolve('<path>', { preserveSymlinks: true })

Any plan on adding preserveSymlinks option ?

@clydin
Copy link

clydin commented Mar 5, 2019

@cjihrig Any chance we could see the changes in your commit turned into a full PR? I think many people would greatly benefit from the added options. Having to rely on third-party packages that attempt to mimic the behavior of the node resolution algorithm is considerably less than ideal.

@targos targos added feature request Issues that request new features to be added to Node.js. module Issues and PRs related to the module subsystem. labels Dec 11, 2019
@alcuadrado
Copy link

Any news on this? It would be very beneficial for one of my projects. I have to rely on a third-party package that just recreates part node's functionality, and it feels fragile.

@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot added the stale label Mar 18, 2022
@targos targos moved this from Pending Triage to Stale in Node.js feature requests Mar 19, 2022
@targos targos moved this to Pending Triage in Node.js feature requests Mar 19, 2022
@github-actions
Copy link
Contributor

There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@zkochan
Copy link

zkochan commented Jan 9, 2024

This would be a useful feature. For now the resolve package can be used instead, which has the preserveSymlinks option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. module Issues and PRs related to the module subsystem. stale
Projects
None yet
Development

No branches or pull requests

8 participants