deno_runtime/
lib.rs

1// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
3pub use deno_broadcast_channel;
4pub use deno_cache;
5pub use deno_canvas;
6pub use deno_console;
7pub use deno_core;
8pub use deno_cron;
9pub use deno_crypto;
10pub use deno_fetch;
11pub use deno_ffi;
12pub use deno_fs;
13pub use deno_http;
14pub use deno_io;
15pub use deno_kv;
16pub use deno_napi;
17pub use deno_net;
18pub use deno_node;
19pub use deno_permissions;
20pub use deno_terminal::colors;
21pub use deno_tls;
22pub use deno_url;
23pub use deno_web;
24pub use deno_webgpu;
25pub use deno_webidl;
26pub use deno_websocket;
27pub use deno_webstorage;
28
29pub mod code_cache;
30pub mod errors;
31pub mod fmt_errors;
32pub mod fs_util;
33pub mod inspector_server;
34pub mod js;
35pub mod ops;
36pub mod permissions;
37pub mod snapshot;
38pub mod sys_info;
39pub mod tokio_util;
40pub mod web_worker;
41pub mod worker;
42
43mod worker_bootstrap;
44pub use worker_bootstrap::BootstrapOptions;
45pub use worker_bootstrap::WorkerExecutionMode;
46pub use worker_bootstrap::WorkerLogLevel;
47
48mod shared;
49pub use shared::runtime;
50
51pub struct UnstableGranularFlag {
52  pub name: &'static str,
53  pub help_text: &'static str,
54  pub show_in_help: bool,
55  // id to enable it in runtime/99_main.js
56  pub id: i32,
57}
58
59// NOTE(bartlomieju): keep IDs in sync with `runtime/90_deno_ns.js` (search for `unstableFeatures`)
60pub static UNSTABLE_GRANULAR_FLAGS: &[UnstableGranularFlag] = &[
61  UnstableGranularFlag {
62    name: deno_broadcast_channel::UNSTABLE_FEATURE_NAME,
63    help_text: "Enable unstable `BroadcastChannel` API",
64    show_in_help: true,
65    id: 1,
66  },
67  UnstableGranularFlag {
68    name: deno_cron::UNSTABLE_FEATURE_NAME,
69    help_text: "Enable unstable Deno.cron API",
70    show_in_help: true,
71    id: 2,
72  },
73  UnstableGranularFlag {
74    name: deno_ffi::UNSTABLE_FEATURE_NAME,
75    help_text: "Enable unstable FFI APIs",
76    show_in_help: false,
77    id: 3,
78  },
79  UnstableGranularFlag {
80    name: deno_fs::UNSTABLE_FEATURE_NAME,
81    help_text: "Enable unstable file system APIs",
82    show_in_help: false,
83    id: 4,
84  },
85  UnstableGranularFlag {
86    name: ops::http::UNSTABLE_FEATURE_NAME,
87    help_text: "Enable unstable HTTP APIs",
88    show_in_help: false,
89    id: 5,
90  },
91  UnstableGranularFlag {
92    name: deno_kv::UNSTABLE_FEATURE_NAME,
93    help_text: "Enable unstable Key-Value store APIs",
94    show_in_help: true,
95    id: 6,
96  },
97  UnstableGranularFlag {
98    name: deno_net::UNSTABLE_FEATURE_NAME,
99    help_text: "Enable unstable net APIs",
100    show_in_help: true,
101    id: 7,
102  },
103  UnstableGranularFlag {
104    name: "node-globals",
105    help_text: "Expose Node globals everywhere",
106    show_in_help: true,
107    id: 8,
108  },
109  UnstableGranularFlag {
110    name: "otel",
111    help_text: "Enable unstable OpenTelemetry features",
112    show_in_help: false,
113    id: 9,
114  },
115  // TODO(bartlomieju): consider removing it
116  UnstableGranularFlag {
117    name: ops::process::UNSTABLE_FEATURE_NAME,
118    help_text: "Enable unstable process APIs",
119    show_in_help: false,
120    id: 10,
121  },
122  UnstableGranularFlag {
123    name: "temporal",
124    help_text: "Enable unstable Temporal API",
125    show_in_help: true,
126    id: 11,
127  },
128  UnstableGranularFlag {
129    name: "unsafe-proto",
130    help_text: "Enable unsafe __proto__ support. This is a security risk.",
131    show_in_help: true,
132    // This number is used directly in the JS code. Search
133    // for "unstableIds" to see where it's used.
134    id: 12,
135  },
136  UnstableGranularFlag {
137    name: deno_webgpu::UNSTABLE_FEATURE_NAME,
138    help_text: "Enable unstable `WebGPU` APIs",
139    show_in_help: true,
140    id: 13,
141  },
142  UnstableGranularFlag {
143    name: ops::worker_host::UNSTABLE_FEATURE_NAME,
144    help_text: "Enable unstable Web Worker APIs",
145    show_in_help: true,
146    id: 14,
147  },
148];
149
150pub fn exit(code: i32) -> ! {
151  deno_telemetry::flush();
152  #[allow(clippy::disallowed_methods)]
153  std::process::exit(code);
154}
155
156#[cfg(test)]
157mod test {
158  use super::*;
159
160  #[test]
161  fn unstable_granular_flag_names_sorted() {
162    let flags = UNSTABLE_GRANULAR_FLAGS
163      .iter()
164      .map(|granular_flag| granular_flag.name.to_string())
165      .collect::<Vec<_>>();
166    let mut sorted_flags = flags.clone();
167    sorted_flags.sort();
168    // sort the flags by name so they appear nicely in the help text
169    assert_eq!(flags, sorted_flags);
170  }
171}