Skip to content
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] Option/flag for process.cwd( ) to return the actual PWD with symlinks, not real path #56288

Open
ThePlenkov opened this issue Dec 17, 2024 · 2 comments
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@ThePlenkov
Copy link

ThePlenkov commented Dec 17, 2024

What is the problem this feature will solve?

Certain software such as docker or VS Code relies on the actual path, not real path. In case we use NodeJS based scripts - we would like to know from what actual folder this code is running. Unfortunately process.cwd( ) does not work. This code node -p 'process.cwd()' returns path without symlink. Flags like --preserve-symlinks or NODE_PRESERVE_SYMLINKS=1 do not help to solve the problem.

What is the feature you are proposing to solve the problem?

Please introduce a flag and what is more important environment variable to force process.cwd to follow the actual path, not realpath.
Environment variable is needed for scenarios when we cannot already change scripts, but we can force node to work different by changing it.

What alternatives have you considered?

Alternative solution now is to use process.env.PWD, but it's OS dependent, so will not work in Windows

Related issues

This will solve directly this issue:
devcontainers/cli#932

And as a result will help to solve following problems:
microsoft/vscode-remote-release#10301
docker/for-win#14380

Thanks!

@ThePlenkov ThePlenkov added the feature request Issues that request new features to be added to Node.js. label Dec 17, 2024
@github-project-automation github-project-automation bot moved this to Awaiting Triage in Node.js feature requests Dec 17, 2024
@aduh95
Copy link
Contributor

aduh95 commented Dec 18, 2024

Can you give a code snippet that would demonstrate the issue?

@ThePlenkov
Copy link
Author

ThePlenkov commented Dec 18, 2024

@aduh95 can it be considered as a code?

pplenkov@W:~/git_projects$ node -p 'process.cwd()'
/mnt/wsl/workspace/ubuntu
pplenkov@W:~/git_projects$ pwd
/home/pplenkov/git_projects
pplenkov@W:~/git_projects$ realpath $(pwd)
/mnt/wsl/workspace/ubuntu

where git_projects is symlink:

ls -lah | grep git_projects
lrwxrwxrwx  1 pplenkov pplenkov   25 Sep 18 10:46 git_projects -> /mnt/wsl/workspace/ubuntu

What I'd like to do is to get pwd as a result of cwd somehow

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.
Projects
Status: Awaiting Triage
Development

No branches or pull requests

2 participants