mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix(ext/node): set correct process.argv0 (#22555)
This commit is contained in:
parent
cddefecfff
commit
47dee65e4a
7 changed files with 32 additions and 37 deletions
|
@ -855,9 +855,10 @@ impl CliFactory {
|
||||||
location: self.options.location_flag().clone(),
|
location: self.options.location_flag().clone(),
|
||||||
// if the user ran a binary command, we'll need to set process.argv[0]
|
// if the user ran a binary command, we'll need to set process.argv[0]
|
||||||
// to be the name of the binary command instead of deno
|
// to be the name of the binary command instead of deno
|
||||||
maybe_binary_npm_command_name: self
|
argv0: self
|
||||||
.options
|
.options
|
||||||
.take_binary_npm_command_name(),
|
.take_binary_npm_command_name()
|
||||||
|
.or(std::env::args().next()),
|
||||||
origin_data_folder_path: Some(self.deno_dir()?.origin_data_folder_path()),
|
origin_data_folder_path: Some(self.deno_dir()?.origin_data_folder_path()),
|
||||||
seed: self.options.seed(),
|
seed: self.options.seed(),
|
||||||
unsafely_ignore_certificate_errors: self
|
unsafely_ignore_certificate_errors: self
|
||||||
|
|
|
@ -536,11 +536,10 @@ pub async fn run(
|
||||||
is_npm_main: main_module.scheme() == "npm",
|
is_npm_main: main_module.scheme() == "npm",
|
||||||
skip_op_registration: true,
|
skip_op_registration: true,
|
||||||
location: metadata.location,
|
location: metadata.location,
|
||||||
maybe_binary_npm_command_name: NpmPackageReqReference::from_specifier(
|
argv0: NpmPackageReqReference::from_specifier(main_module)
|
||||||
main_module,
|
|
||||||
)
|
|
||||||
.ok()
|
.ok()
|
||||||
.map(|req_ref| npm_pkg_req_ref_to_binary_command(&req_ref)),
|
.map(|req_ref| npm_pkg_req_ref_to_binary_command(&req_ref))
|
||||||
|
.or(std::env::args().next()),
|
||||||
origin_data_folder_path: None,
|
origin_data_folder_path: None,
|
||||||
seed: metadata.seed,
|
seed: metadata.seed,
|
||||||
unsafely_ignore_certificate_errors: metadata
|
unsafely_ignore_certificate_errors: metadata
|
||||||
|
|
|
@ -115,7 +115,7 @@ pub struct CliMainWorkerOptions {
|
||||||
pub is_inspecting: bool,
|
pub is_inspecting: bool,
|
||||||
pub is_npm_main: bool,
|
pub is_npm_main: bool,
|
||||||
pub location: Option<Url>,
|
pub location: Option<Url>,
|
||||||
pub maybe_binary_npm_command_name: Option<String>,
|
pub argv0: Option<String>,
|
||||||
pub origin_data_folder_path: Option<PathBuf>,
|
pub origin_data_folder_path: Option<PathBuf>,
|
||||||
pub seed: Option<u64>,
|
pub seed: Option<u64>,
|
||||||
pub unsafely_ignore_certificate_errors: Option<Vec<String>>,
|
pub unsafely_ignore_certificate_errors: Option<Vec<String>>,
|
||||||
|
@ -608,10 +608,7 @@ impl CliMainWorkerFactory {
|
||||||
user_agent: version::get_user_agent().to_string(),
|
user_agent: version::get_user_agent().to_string(),
|
||||||
inspect: shared.options.is_inspecting,
|
inspect: shared.options.is_inspecting,
|
||||||
has_node_modules_dir: shared.options.has_node_modules_dir,
|
has_node_modules_dir: shared.options.has_node_modules_dir,
|
||||||
maybe_binary_npm_command_name: shared
|
argv0: shared.options.argv0.clone(),
|
||||||
.options
|
|
||||||
.maybe_binary_npm_command_name
|
|
||||||
.clone(),
|
|
||||||
node_ipc_fd: shared.node_ipc,
|
node_ipc_fd: shared.node_ipc,
|
||||||
disable_deprecated_api_warning: shared.disable_deprecated_api_warning,
|
disable_deprecated_api_warning: shared.disable_deprecated_api_warning,
|
||||||
verbose_deprecated_api_warning: shared.verbose_deprecated_api_warning,
|
verbose_deprecated_api_warning: shared.verbose_deprecated_api_warning,
|
||||||
|
@ -815,10 +812,7 @@ fn create_web_worker_callback(
|
||||||
user_agent: version::get_user_agent().to_string(),
|
user_agent: version::get_user_agent().to_string(),
|
||||||
inspect: shared.options.is_inspecting,
|
inspect: shared.options.is_inspecting,
|
||||||
has_node_modules_dir: shared.options.has_node_modules_dir,
|
has_node_modules_dir: shared.options.has_node_modules_dir,
|
||||||
maybe_binary_npm_command_name: shared
|
argv0: shared.options.argv0.clone(),
|
||||||
.options
|
|
||||||
.maybe_binary_npm_command_name
|
|
||||||
.clone(),
|
|
||||||
node_ipc_fd: None,
|
node_ipc_fd: None,
|
||||||
disable_deprecated_api_warning: shared.disable_deprecated_api_warning,
|
disable_deprecated_api_warning: shared.disable_deprecated_api_warning,
|
||||||
verbose_deprecated_api_warning: shared.verbose_deprecated_api_warning,
|
verbose_deprecated_api_warning: shared.verbose_deprecated_api_warning,
|
||||||
|
|
|
@ -45,8 +45,7 @@ import { isWindows } from "ext:deno_node/_util/os.ts";
|
||||||
import * as io from "ext:deno_io/12_io.js";
|
import * as io from "ext:deno_io/12_io.js";
|
||||||
import { Command } from "ext:runtime/40_process.js";
|
import { Command } from "ext:runtime/40_process.js";
|
||||||
|
|
||||||
let argv0Getter = () => "";
|
export let argv0 = "";
|
||||||
export let argv0 = "deno";
|
|
||||||
|
|
||||||
export let arch = "";
|
export let arch = "";
|
||||||
|
|
||||||
|
@ -389,9 +388,6 @@ class Process extends EventEmitter {
|
||||||
argv = argv;
|
argv = argv;
|
||||||
|
|
||||||
get argv0() {
|
get argv0() {
|
||||||
if (!argv0) {
|
|
||||||
argv0 = argv0Getter();
|
|
||||||
}
|
|
||||||
return argv0;
|
return argv0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -875,19 +871,14 @@ internals.__bootstrapNodeProcess = function (
|
||||||
) {
|
) {
|
||||||
// Overwrites the 1st item with getter.
|
// Overwrites the 1st item with getter.
|
||||||
if (typeof argv0Val === "string") {
|
if (typeof argv0Val === "string") {
|
||||||
|
argv0 = argv0Val;
|
||||||
Object.defineProperty(argv, "0", {
|
Object.defineProperty(argv, "0", {
|
||||||
get: () => {
|
get: () => {
|
||||||
return argv0Val;
|
return argv0Val;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
argv0Getter = () => argv0Val;
|
|
||||||
} else {
|
} else {
|
||||||
Object.defineProperty(argv, "0", {
|
Object.defineProperty(argv, "0", { get: () => argv0 });
|
||||||
get: () => {
|
|
||||||
return Deno.execPath();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
argv0Getter = () => Deno.execPath();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overwrites the 2st item with getter.
|
// Overwrites the 2st item with getter.
|
||||||
|
|
|
@ -644,7 +644,7 @@ function bootstrapMainRuntime(runtimeOptions) {
|
||||||
2: unstableFeatures,
|
2: unstableFeatures,
|
||||||
3: inspectFlag,
|
3: inspectFlag,
|
||||||
5: hasNodeModulesDir,
|
5: hasNodeModulesDir,
|
||||||
6: maybeBinaryNpmCommandName,
|
6: argv0,
|
||||||
7: shouldDisableDeprecatedApiWarning,
|
7: shouldDisableDeprecatedApiWarning,
|
||||||
8: shouldUseVerboseDeprecatedApiWarning,
|
8: shouldUseVerboseDeprecatedApiWarning,
|
||||||
9: future,
|
9: future,
|
||||||
|
@ -768,7 +768,7 @@ function bootstrapMainRuntime(runtimeOptions) {
|
||||||
ObjectDefineProperty(globalThis, "Deno", core.propReadOnly(finalDenoNs));
|
ObjectDefineProperty(globalThis, "Deno", core.propReadOnly(finalDenoNs));
|
||||||
|
|
||||||
if (nodeBootstrap) {
|
if (nodeBootstrap) {
|
||||||
nodeBootstrap(hasNodeModulesDir, maybeBinaryNpmCommandName);
|
nodeBootstrap(hasNodeModulesDir, argv0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (future) {
|
if (future) {
|
||||||
|
@ -793,7 +793,7 @@ function bootstrapWorkerRuntime(
|
||||||
2: unstableFeatures,
|
2: unstableFeatures,
|
||||||
4: enableTestingFeaturesFlag,
|
4: enableTestingFeaturesFlag,
|
||||||
5: hasNodeModulesDir,
|
5: hasNodeModulesDir,
|
||||||
6: maybeBinaryNpmCommandName,
|
6: argv0,
|
||||||
7: shouldDisableDeprecatedApiWarning,
|
7: shouldDisableDeprecatedApiWarning,
|
||||||
8: shouldUseVerboseDeprecatedApiWarning,
|
8: shouldUseVerboseDeprecatedApiWarning,
|
||||||
} = runtimeOptions;
|
} = runtimeOptions;
|
||||||
|
@ -897,7 +897,7 @@ function bootstrapWorkerRuntime(
|
||||||
ObjectDefineProperty(globalThis, "Deno", core.propReadOnly(finalDenoNs));
|
ObjectDefineProperty(globalThis, "Deno", core.propReadOnly(finalDenoNs));
|
||||||
|
|
||||||
if (nodeBootstrap) {
|
if (nodeBootstrap) {
|
||||||
nodeBootstrap(hasNodeModulesDir, maybeBinaryNpmCommandName);
|
nodeBootstrap(hasNodeModulesDir, argv0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ pub struct BootstrapOptions {
|
||||||
pub user_agent: String,
|
pub user_agent: String,
|
||||||
pub inspect: bool,
|
pub inspect: bool,
|
||||||
pub has_node_modules_dir: bool,
|
pub has_node_modules_dir: bool,
|
||||||
pub maybe_binary_npm_command_name: Option<String>,
|
pub argv0: Option<String>,
|
||||||
pub node_ipc_fd: Option<i64>,
|
pub node_ipc_fd: Option<i64>,
|
||||||
pub disable_deprecated_api_warning: bool,
|
pub disable_deprecated_api_warning: bool,
|
||||||
pub verbose_deprecated_api_warning: bool,
|
pub verbose_deprecated_api_warning: bool,
|
||||||
|
@ -89,7 +89,7 @@ impl Default for BootstrapOptions {
|
||||||
inspect: Default::default(),
|
inspect: Default::default(),
|
||||||
args: Default::default(),
|
args: Default::default(),
|
||||||
has_node_modules_dir: Default::default(),
|
has_node_modules_dir: Default::default(),
|
||||||
maybe_binary_npm_command_name: None,
|
argv0: None,
|
||||||
node_ipc_fd: None,
|
node_ipc_fd: None,
|
||||||
disable_deprecated_api_warning: false,
|
disable_deprecated_api_warning: false,
|
||||||
verbose_deprecated_api_warning: false,
|
verbose_deprecated_api_warning: false,
|
||||||
|
@ -121,7 +121,7 @@ struct BootstrapV8<'a>(
|
||||||
bool,
|
bool,
|
||||||
// has_node_modules_dir
|
// has_node_modules_dir
|
||||||
bool,
|
bool,
|
||||||
// maybe_binary_npm_command_name
|
// argv0
|
||||||
Option<&'a str>,
|
Option<&'a str>,
|
||||||
// disable_deprecated_api_warning,
|
// disable_deprecated_api_warning,
|
||||||
bool,
|
bool,
|
||||||
|
@ -147,7 +147,7 @@ impl BootstrapOptions {
|
||||||
self.inspect,
|
self.inspect,
|
||||||
self.enable_testing_features,
|
self.enable_testing_features,
|
||||||
self.has_node_modules_dir,
|
self.has_node_modules_dir,
|
||||||
self.maybe_binary_npm_command_name.as_deref(),
|
self.argv0.as_deref(),
|
||||||
self.disable_deprecated_api_warning,
|
self.disable_deprecated_api_warning,
|
||||||
self.verbose_deprecated_api_warning,
|
self.verbose_deprecated_api_warning,
|
||||||
self.future,
|
self.future,
|
||||||
|
|
|
@ -287,7 +287,17 @@ Deno.test({
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "process.argv0",
|
name: "process.argv0",
|
||||||
fn() {
|
async fn() {
|
||||||
|
const { stdout } = await new Deno.Command(Deno.execPath(), {
|
||||||
|
args: [
|
||||||
|
"eval",
|
||||||
|
`import process from "node:process";console.log(process.argv0);`,
|
||||||
|
],
|
||||||
|
stdout: "piped",
|
||||||
|
stderr: "null",
|
||||||
|
}).output();
|
||||||
|
assertEquals(new TextDecoder().decode(stdout).trim(), Deno.execPath());
|
||||||
|
|
||||||
assertEquals(typeof process.argv0, "string");
|
assertEquals(typeof process.argv0, "string");
|
||||||
assert(
|
assert(
|
||||||
process.argv0.match(/[^/\\]*deno[^/\\]*$/),
|
process.argv0.match(/[^/\\]*deno[^/\\]*$/),
|
||||||
|
|
Loading…
Reference in a new issue