1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

chore: add DENO_FUTURE env var (#22318)

Closes https://github.com/denoland/deno/issues/22315

```
~> DENO_FUTURE=1 target/debug/deno

> globalThis.window
undefined
```
This commit is contained in:
Divy Srivastava 2024-02-15 10:20:17 +05:30 committed by GitHub
parent 1ad754b412
commit b72f0be27c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 39 additions and 0 deletions

View file

@ -987,6 +987,10 @@ impl CliOptions {
} }
} }
pub fn enable_future_features(&self) -> bool {
std::env::var("DENO_FUTURE").is_ok()
}
pub fn resolve_main_module(&self) -> Result<ModuleSpecifier, AnyError> { pub fn resolve_main_module(&self) -> Result<ModuleSpecifier, AnyError> {
match &self.flags.subcommand { match &self.flags.subcommand {
DenoSubcommand::Bundle(bundle_flags) => { DenoSubcommand::Bundle(bundle_flags) => {

View file

@ -775,6 +775,7 @@ impl CliFactory {
self.feature_checker().clone(), self.feature_checker().clone(),
self.create_cli_main_worker_options()?, self.create_cli_main_worker_options()?,
self.options.node_ipc_fd(), self.options.node_ipc_fd(),
self.options.enable_future_features(),
// TODO(bartlomieju): temporarily disabled // TODO(bartlomieju): temporarily disabled
// self.options.disable_deprecated_api_warning, // self.options.disable_deprecated_api_warning,
true, true,

View file

@ -551,6 +551,7 @@ pub async fn run(
create_coverage_collector: None, create_coverage_collector: None,
}, },
None, None,
false,
// TODO(bartlomieju): temporarily disabled // TODO(bartlomieju): temporarily disabled
// metadata.disable_deprecated_api_warning, // metadata.disable_deprecated_api_warning,
true, true,

View file

@ -144,6 +144,7 @@ struct SharedWorkerState {
maybe_lockfile: Option<Arc<Mutex<Lockfile>>>, maybe_lockfile: Option<Arc<Mutex<Lockfile>>>,
feature_checker: Arc<FeatureChecker>, feature_checker: Arc<FeatureChecker>,
node_ipc: Option<i64>, node_ipc: Option<i64>,
enable_future_features: bool,
disable_deprecated_api_warning: bool, disable_deprecated_api_warning: bool,
verbose_deprecated_api_warning: bool, verbose_deprecated_api_warning: bool,
} }
@ -424,6 +425,7 @@ impl CliMainWorkerFactory {
feature_checker: Arc<FeatureChecker>, feature_checker: Arc<FeatureChecker>,
options: CliMainWorkerOptions, options: CliMainWorkerOptions,
node_ipc: Option<i64>, node_ipc: Option<i64>,
enable_future_features: bool,
disable_deprecated_api_warning: bool, disable_deprecated_api_warning: bool,
verbose_deprecated_api_warning: bool, verbose_deprecated_api_warning: bool,
) -> Self { ) -> Self {
@ -446,6 +448,7 @@ impl CliMainWorkerFactory {
maybe_lockfile, maybe_lockfile,
feature_checker, feature_checker,
node_ipc, node_ipc,
enable_future_features,
disable_deprecated_api_warning, disable_deprecated_api_warning,
verbose_deprecated_api_warning, verbose_deprecated_api_warning,
}), }),
@ -612,6 +615,7 @@ impl CliMainWorkerFactory {
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,
future: shared.enable_future_features,
}, },
extensions: custom_extensions, extensions: custom_extensions,
startup_snapshot: crate::js::deno_isolate_init(), startup_snapshot: crate::js::deno_isolate_init(),
@ -818,6 +822,7 @@ fn create_web_worker_callback(
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,
future: false,
}, },
extensions: vec![], extensions: vec![],
startup_snapshot: crate::js::deno_isolate_init(), startup_snapshot: crate::js::deno_isolate_init(),

View file

@ -647,6 +647,7 @@ function bootstrapMainRuntime(runtimeOptions) {
6: maybeBinaryNpmCommandName, 6: maybeBinaryNpmCommandName,
7: shouldDisableDeprecatedApiWarning, 7: shouldDisableDeprecatedApiWarning,
8: shouldUseVerboseDeprecatedApiWarning, 8: shouldUseVerboseDeprecatedApiWarning,
9: future,
} = runtimeOptions; } = runtimeOptions;
removeImportedOps(); removeImportedOps();
@ -769,6 +770,10 @@ function bootstrapMainRuntime(runtimeOptions) {
if (nodeBootstrap) { if (nodeBootstrap) {
nodeBootstrap(hasNodeModulesDir, maybeBinaryNpmCommandName); nodeBootstrap(hasNodeModulesDir, maybeBinaryNpmCommandName);
} }
if (future) {
delete globalThis.window;
}
} }
function bootstrapWorkerRuntime( function bootstrapWorkerRuntime(

View file

@ -62,6 +62,7 @@ pub struct BootstrapOptions {
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,
pub future: bool,
} }
impl Default for BootstrapOptions { impl Default for BootstrapOptions {
@ -92,6 +93,7 @@ impl Default for BootstrapOptions {
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,
future: false,
} }
} }
} }
@ -125,6 +127,8 @@ struct BootstrapV8<'a>(
bool, bool,
// verbose_deprecated_api_warning // verbose_deprecated_api_warning
bool, bool,
// future
bool,
); );
impl BootstrapOptions { impl BootstrapOptions {
@ -146,6 +150,7 @@ impl BootstrapOptions {
self.maybe_binary_npm_command_name.as_deref(), self.maybe_binary_npm_command_name.as_deref(),
self.disable_deprecated_api_warning, self.disable_deprecated_api_warning,
self.verbose_deprecated_api_warning, self.verbose_deprecated_api_warning,
self.future,
); );
bootstrap.serialize(ser).unwrap() bootstrap.serialize(ser).unwrap()

View file

@ -166,6 +166,11 @@ impl TestContextBuilder {
self self
} }
pub fn add_future_env_vars(mut self) -> Self {
self = self.env("DENO_FUTURE", "1");
self
}
pub fn add_jsr_env_vars(mut self) -> Self { pub fn add_jsr_env_vars(mut self) -> Self {
for (key, value) in env_vars_for_jsr_tests() { for (key, value) in env_vars_for_jsr_tests() {
self = self.env(key, value); self = self.env(key, value);

View file

@ -1711,6 +1711,16 @@ fn type_directives_js_main() {
assert_not_contains!(output.combined_output(), "type_reference.d.ts"); assert_not_contains!(output.combined_output(), "type_reference.d.ts");
} }
#[test]
fn test_deno_futures_env() {
let context = TestContextBuilder::new().add_future_env_vars().build();
let output = context
.new_command()
.args("run --quiet --reload run/deno_futures_env.ts")
.run();
output.assert_exit_code(0);
}
itest!(type_directives_redirect { itest!(type_directives_redirect {
args: "run --reload --check run/type_directives_redirect.ts", args: "run --reload --check run/type_directives_redirect.ts",
output: "run/type_directives_redirect.ts.out", output: "run/type_directives_redirect.ts.out",

View file

@ -0,0 +1,3 @@
if (typeof window !== "undefined") {
throw new Error("Window global available");
}