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

Specify working directory for node --run #57489

Open
flakey5 opened this issue Mar 16, 2025 · 8 comments · May be fixed by #57523
Open

Specify working directory for node --run #57489

flakey5 opened this issue Mar 16, 2025 · 8 comments · May be fixed by #57523
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@flakey5
Copy link
Member

flakey5 commented Mar 16, 2025

What is the problem this feature will solve?

Currently node --run doesn't allow you to specify the working directory to run the command in. This is needed for things like running the new api docs tooling (re #57343)

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

Something similar to npm's --prefix flag (i.e. npx --prefix <working dir> ... or npm --prefix <working dir> ...)

What alternatives have you considered?

No response

@flakey5 flakey5 added the feature request Issues that request new features to be added to Node.js. label Mar 16, 2025
@github-project-automation github-project-automation bot moved this to Awaiting Triage in Node.js feature requests Mar 16, 2025
@flakey5
Copy link
Member Author

flakey5 commented Mar 16, 2025

cc @anonrig

re #57343 (comment)

@jasnell
Copy link
Member

jasnell commented Mar 16, 2025

@flakey5 ... any suggestions on what the flag should look like?

I've never been a big fan of --prefix as a name for this. Perhaps node --run-in=/some/path --run ... ?

Also, this is definitely worthwhile I think. While I'm sure @anonrig can do it, I'd also encourage you to take a stab at it. The changes necessary are fairly straightforward.

@anonrig
Copy link
Member

anonrig commented Mar 16, 2025

@flakey5 ... any suggestions on what the flag should look like?

What about --working-directory? Something like node --working-directory=../hello --run script

cc @JonasBa if interested, this could be a good contribution opportunity

@anonrig anonrig moved this from Awaiting Triage to In Progress in Node.js feature requests Mar 16, 2025
@flakey5
Copy link
Member Author

flakey5 commented Mar 16, 2025

--run-in would work if this just applies for --run, --working-directory is better imo but there's an implication that it can also be used for source files as well

I.e.

// node --working-directory=/etc/123 main.js
process.cwd() // = /etc/123

@flakey5
Copy link
Member Author

flakey5 commented Mar 16, 2025

I can also take a swing at this if @JonasBa isn't interested

@anonrig
Copy link
Member

anonrig commented Mar 16, 2025

--run-in would work if this just applies for --run, --working-directory is better imo but there's an implication that it can also be used for source files as well

I.e.

// node --working-directory=/etc/123 main.js
process.cwd() // = /etc/123

I'd just don't add working-directory to argument parser, and just parse it inside node run file implementation. If we have other implementation that uses working-directory then we can add it to arg parser.

@anonrig
Copy link
Member

anonrig commented Mar 16, 2025

I can also take a swing at this if @JonasBa isn't interested

Go for it :-)

@jasnell
Copy link
Member

jasnell commented Mar 16, 2025

I think just --working-directory would be confusing unless it sets the working directory for the entire process, including fs apis. If the impact of the flag is just for the run command then its name should reflect that.

@mertcanaltin mertcanaltin linked a pull request Mar 17, 2025 that will close this issue
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: In Progress
Development

Successfully merging a pull request may close this issue.

3 participants