mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 08:39:09 -05:00
Add execPath function (#1743)
This commit is contained in:
parent
1d7c74e9b5
commit
4dc4329e27
6 changed files with 26 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
// Public deno module.
|
// Public deno module.
|
||||||
export { noColor, pid, env, exit, isTTY } from "./os";
|
export { noColor, pid, env, exit, isTTY, execPath } from "./os";
|
||||||
export { chdir, cwd } from "./dir";
|
export { chdir, cwd } from "./dir";
|
||||||
export {
|
export {
|
||||||
File,
|
File,
|
||||||
|
|
12
js/os.ts
12
js/os.ts
|
@ -12,11 +12,19 @@ export let pid: number;
|
||||||
/** Reflects the NO_COLOR environment variable: https://no-color.org/ */
|
/** Reflects the NO_COLOR environment variable: https://no-color.org/ */
|
||||||
export let noColor: boolean;
|
export let noColor: boolean;
|
||||||
|
|
||||||
|
/** Path to the current deno process's executable file. */
|
||||||
|
export let execPath: string;
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
export function setGlobals(pid_: number, noColor_: boolean): void {
|
export function setGlobals(
|
||||||
|
pid_: number,
|
||||||
|
noColor_: boolean,
|
||||||
|
execPath_: string
|
||||||
|
): void {
|
||||||
assert(!pid);
|
assert(!pid);
|
||||||
pid = pid_;
|
pid = pid_;
|
||||||
noColor = noColor_;
|
noColor = noColor_;
|
||||||
|
execPath = execPath_;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CodeInfo {
|
interface CodeInfo {
|
||||||
|
@ -190,7 +198,7 @@ export function start(source?: string): msg.StartRes {
|
||||||
|
|
||||||
util.setLogDebug(startResMsg.debugFlag(), source);
|
util.setLogDebug(startResMsg.debugFlag(), source);
|
||||||
|
|
||||||
setGlobals(startResMsg.pid(), startResMsg.noColor());
|
setGlobals(startResMsg.pid(), startResMsg.noColor(), startResMsg.execPath()!);
|
||||||
|
|
||||||
return startResMsg;
|
return startResMsg;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ union Any {
|
||||||
Now,
|
Now,
|
||||||
NowRes,
|
NowRes,
|
||||||
IsTTY,
|
IsTTY,
|
||||||
IsTTYRes
|
IsTTYRes,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ErrorKind: byte {
|
enum ErrorKind: byte {
|
||||||
|
@ -156,6 +156,7 @@ table StartRes {
|
||||||
cwd: string;
|
cwd: string;
|
||||||
pid: uint32;
|
pid: uint32;
|
||||||
argv: [string];
|
argv: [string];
|
||||||
|
exec_path: string;
|
||||||
debug_flag: bool;
|
debug_flag: bool;
|
||||||
deps_flag: bool;
|
deps_flag: bool;
|
||||||
types_flag: bool;
|
types_flag: bool;
|
||||||
|
|
|
@ -252,6 +252,9 @@ fn op_start(
|
||||||
let cwd_off =
|
let cwd_off =
|
||||||
builder.create_string(deno_fs::normalize_path(cwd_path.as_ref()).as_ref());
|
builder.create_string(deno_fs::normalize_path(cwd_path.as_ref()).as_ref());
|
||||||
|
|
||||||
|
let exec_path =
|
||||||
|
builder.create_string(std::env::current_exe().unwrap().to_str().unwrap());
|
||||||
|
|
||||||
let v8_version = version::v8();
|
let v8_version = version::v8();
|
||||||
let v8_version_off = builder.create_string(v8_version);
|
let v8_version_off = builder.create_string(v8_version);
|
||||||
|
|
||||||
|
@ -270,6 +273,7 @@ fn op_start(
|
||||||
v8_version: Some(v8_version_off),
|
v8_version: Some(v8_version_off),
|
||||||
deno_version: Some(deno_version_off),
|
deno_version: Some(deno_version_off),
|
||||||
no_color: !ansi::use_color(),
|
no_color: !ansi::use_color(),
|
||||||
|
exec_path: Some(exec_path),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
1
tests/exec_path.ts
Normal file
1
tests/exec_path.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
console.log(Deno.execPath);
|
|
@ -38,6 +38,12 @@ def test_no_color(deno_exe):
|
||||||
print green_ok()
|
print green_ok()
|
||||||
|
|
||||||
|
|
||||||
|
def exec_path_test(deno_exe):
|
||||||
|
cmd = [deno_exe, "tests/exec_path.ts"]
|
||||||
|
output = run_output(cmd)
|
||||||
|
assert deno_exe in output.strip()
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
if len(argv) == 2:
|
if len(argv) == 2:
|
||||||
build_dir = sys.argv[1]
|
build_dir = sys.argv[1]
|
||||||
|
@ -59,6 +65,8 @@ def main(argv):
|
||||||
deno_exe = os.path.join(build_dir, "deno" + executable_suffix)
|
deno_exe = os.path.join(build_dir, "deno" + executable_suffix)
|
||||||
check_exists(deno_exe)
|
check_exists(deno_exe)
|
||||||
|
|
||||||
|
exec_path_test(deno_exe)
|
||||||
|
|
||||||
# Internal tools testing
|
# Internal tools testing
|
||||||
run([
|
run([
|
||||||
"node", "./node_modules/.bin/ts-node", "--project",
|
"node", "./node_modules/.bin/ts-node", "--project",
|
||||||
|
|
Loading…
Reference in a new issue