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

Support IPC in bun package.json script runner #11132

Open
yus-ham opened this issue May 17, 2024 · 2 comments
Open

Support IPC in bun package.json script runner #11132

yus-ham opened this issue May 17, 2024 · 2 comments
Labels
enhancement New feature or request good first issue Something that would be good for new contributors

Comments

@yus-ham
Copy link
Contributor

yus-ham commented May 17, 2024

What is the problem this feature would solve?

package.json

{ "scripts": { "mycoolscript":"bun ./child.js"}}

./child.js

process.send('hello')

parent.js

Bun.spawn(['bun', 'mycoolscript'], {
  ipc(message) {
    console.info(message) // hello
  }
})

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

Make bun script runner as IPC proxy

What alternatives have you considered?

No response

@yus-ham yus-ham added the enhancement New feature or request label May 17, 2024
@yus-ham yus-ham changed the title Support IPC in bun script runner Support IPC in bun package.json script runner May 17, 2024
@robobun robobun changed the title Support IPC in bun package.json script runner Support IPC in bun package.json script runner May 17, 2024
@Jarred-Sumner Jarred-Sumner added the good first issue Something that would be good for new contributors label May 17, 2024
@Jarred-Sumner
Copy link
Collaborator

Jarred-Sumner commented May 17, 2024

To any contributors who want to do this:

  • An environment variable is used to inform the other process about IPC
  • In Bun, file descriptors are not inherited when a process spawns (we try to prevent leaking file descriptors as much as possible) which means we mark the IPC file descriptor as "close-on-exec".
  • The fix is to make the codepaths which do bun run <package.json script> and bun <package.json script> add the IPC file descriptor as .inherit in the Stdio options if the environment variable exists. Most of this code is in src/cli/run_command.zig

@lpessoa
Copy link

lpessoa commented May 24, 2024

Can I have a go at this one? been looking to jump in the zig bandwagon for some time 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Something that would be good for new contributors
Projects
None yet
Development

No branches or pull requests

3 participants