-
Notifications
You must be signed in to change notification settings - Fork 5k
cli: honor --preserve-symlinks/-main for __filename, make SIGUSR1 inert by default #35782
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
Open
robobun
wants to merge
8
commits into
main
Choose a base branch
from
farm/5c75b191/node-flag-compat-signals-symlinks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fb2518c
cli: honor --preserve-symlinks/-main for __filename, make SIGUSR1 ine…
robobun 9683e8f
drop --heapsnapshot-signal (covered by #35390), keep SIGUSR1 + preser…
robobun f901e31
address review: tighten comments, drop redundant brace in finalize_re…
robobun 16a7551
[autofix.ci] apply automated fixes
autofix-ci[bot] 740fb31
fix: --preserve-symlinks must not apply to the main entry (only -main…
robobun ef71c79
preserve-symlinks-main: cover env var + bun run slow-path, pick .pret…
robobun 16143d3
test: clear NODE_PRESERVE_SYMLINKS{,_MAIN} from bunEnv for hermetic n…
robobun bb90f37
run_command: clarify preserve_symlinks override comment (the .pretty …
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
|
Check warning on line 1 in test/cli/run/node-cli-flags.test.ts
|
||
|
robobun marked this conversation as resolved.
|
||
| import { bunEnv, bunExe, isPosix, tempDir } from "harness"; | ||
| import { symlinkSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
|
|
||
| describe("--preserve-symlinks", () => { | ||
| test.concurrent("required symlink reports the symlink path as __filename", async () => { | ||
| using dir = tempDir("preserve-symlinks-require", { | ||
| "real.cjs": `module.exports = __filename;`, | ||
| "main.cjs": `console.log(require("./link.cjs"));`, | ||
| }); | ||
| symlinkSync(join(String(dir), "real.cjs"), join(String(dir), "link.cjs")); | ||
|
|
||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "--preserve-symlinks", "main.cjs"], | ||
| env: bunEnv, | ||
| cwd: String(dir), | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| expect(stderr).toBe(""); | ||
| expect(stdout.trim()).toBe(join(String(dir), "link.cjs")); | ||
| expect(exitCode).toBe(0); | ||
| }); | ||
|
|
||
| test.concurrent("without the flag, required symlink realpaths __filename", async () => { | ||
| using dir = tempDir("preserve-symlinks-off", { | ||
| "real.cjs": `module.exports = __filename;`, | ||
| "main.cjs": `console.log(require("./link.cjs"));`, | ||
| }); | ||
| symlinkSync(join(String(dir), "real.cjs"), join(String(dir), "link.cjs")); | ||
|
|
||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "main.cjs"], | ||
| env: bunEnv, | ||
| cwd: String(dir), | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| expect(stderr).toBe(""); | ||
| expect(stdout.trim()).toBe(join(String(dir), "real.cjs")); | ||
| expect(exitCode).toBe(0); | ||
| }); | ||
|
robobun marked this conversation as resolved.
|
||
|
|
||
| test.concurrent("--preserve-symlinks-main keeps the symlink path for the entry point", async () => { | ||
| using dir = tempDir("preserve-symlinks-main", { | ||
| "real.cjs": `console.log(__filename);`, | ||
| }); | ||
| symlinkSync(join(String(dir), "real.cjs"), join(String(dir), "link.cjs")); | ||
|
|
||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "--preserve-symlinks-main", "link.cjs"], | ||
| env: bunEnv, | ||
| cwd: String(dir), | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| expect(stderr).toBe(""); | ||
| expect(stdout.trim()).toBe(join(String(dir), "link.cjs")); | ||
| expect(exitCode).toBe(0); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }); | ||
| }); | ||
|
|
||
| describe.skipIf(!isPosix)("SIGUSR1 default disposition", () => { | ||
| test.concurrent("SIGUSR1 does not terminate the process by default", async () => { | ||
| await using proc = Bun.spawn({ | ||
| cmd: [ | ||
| bunExe(), | ||
| "-e", | ||
| `process.kill(process.pid, "SIGUSR1"); | ||
| setImmediate(() => { console.log("survived"); process.exit(0); });`, | ||
| ], | ||
| env: bunEnv, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| expect(stderr).toBe(""); | ||
| expect(stdout.trim()).toBe("survived"); | ||
| expect(exitCode).toBe(0); | ||
| expect(proc.signalCode).toBeNull(); | ||
| }); | ||
|
|
||
| test.concurrent("SIGUSR1 stays inert after the last listener is removed", async () => { | ||
| await using proc = Bun.spawn({ | ||
| cmd: [ | ||
| bunExe(), | ||
| "-e", | ||
| `const fn = () => {}; | ||
| process.on("SIGUSR1", fn); | ||
| process.removeListener("SIGUSR1", fn); | ||
| process.kill(process.pid, "SIGUSR1"); | ||
| setImmediate(() => { console.log("survived"); process.exit(0); });`, | ||
| ], | ||
| env: bunEnv, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| expect(stderr).toBe(""); | ||
| expect(stdout.trim()).toBe("survived"); | ||
| expect(exitCode).toBe(0); | ||
| }); | ||
|
|
||
| test.concurrent("child processes do not inherit an ignored SIGUSR1", async () => { | ||
| // Node.js installs a handler (reset to SIG_DFL on exec), not SIG_IGN | ||
| // (which would be inherited). A spawned `sh` must still be killable by | ||
| // SIGUSR1. | ||
| await using proc = Bun.spawn({ | ||
| cmd: [ | ||
| bunExe(), | ||
| "-e", | ||
| `const { spawnSync } = require("node:child_process"); | ||
| const r = spawnSync("sh", ["-c", "kill -USR1 $$; sleep 5"]); | ||
| console.log(r.signal);`, | ||
| ], | ||
| env: bunEnv, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| expect(stderr).toBe(""); | ||
| expect(stdout.trim()).toBe("SIGUSR1"); | ||
| expect(exitCode).toBe(0); | ||
|
robobun marked this conversation as resolved.
Outdated
|
||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.