Skip to content

Commit

Permalink
fix(ext/node): handle node child_process with --v8-options flag
Browse files Browse the repository at this point in the history
Makes `v8flags` package from NPM work.
  • Loading branch information
lucacasonato committed Jul 31, 2024
1 parent cd59fc5 commit d6c4261
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ext/node/polyfills/internal/child_process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,7 @@ const kNodeFlagsMap = new Map([
["--v8-pool-size", kLongArg],
]);
const kDenoSubcommands = new Set([
"add",
"bench",
"bundle",
"cache",
Expand All @@ -1046,6 +1047,7 @@ const kDenoSubcommands = new Set([
"install",
"lint",
"lsp",
"publish",
"repl",
"run",
"tasks",
Expand Down Expand Up @@ -1092,6 +1094,12 @@ function toDenoArgs(args: string[]): string[] {
let isLongWithValue = false;
let flagValue;

if (flag === "--v8-options") {
// If --v8-options is passed, it should be replaced with --v8-flags="--help".
denoArgs.push("--v8-flags=--help");
continue;
}

if (flagInfo === undefined) {
// If the flag was not found, it's either not a known flag or it's a long
// flag containing an '='.
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/npm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2930,3 +2930,11 @@ async fn test_private_npm_registry() {
let resp = client.execute(req).await.unwrap();
assert_eq!(resp.status(), reqwest::StatusCode::OK);
}

itest!(v8flags {
args: "run -A npm/v8flags/main.js",
output: "npm/v8flags/main.out",
envs: env_vars_for_npm_tests(),
exit_code: 0,
http_server: true,
});
1 change: 1 addition & 0 deletions tests/registry/npm/v8flags/registry.json

Large diffs are not rendered by default.

Binary file added tests/registry/npm/v8flags/v8flags-4.0.1.tgz
Binary file not shown.
17 changes: 17 additions & 0 deletions tests/testdata/npm/v8flags/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import v8flags from "npm:v8flags@4.0.1";

const flags = await new Promise((resolve, reject) => {
v8flags((err, flags) => {
if (err) {
reject(err);
} else {
resolve(flags);
}
});
});

if (flags.length < 100) {
throw new Error("Expected at least 100 flags");
}

console.log("ok");
3 changes: 3 additions & 0 deletions tests/testdata/npm/v8flags/main.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Download http://localhost:4260/v8flags
Download http://localhost:4260/v8flags/v8flags-4.0.1.tgz
ok

0 comments on commit d6c4261

Please sign in to comment.