Skip to content

Commit

Permalink
chore: add DENO_FUTURE env var (#22318)
Browse files Browse the repository at this point in the history
Closes #22315

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

> globalThis.window
undefined
```
  • Loading branch information
littledivy committed Feb 15, 2024
1 parent 2e1736d commit 8b1a4d1
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cli/args/mod.rs
Expand Up @@ -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> {
match &self.flags.subcommand {
DenoSubcommand::Bundle(bundle_flags) => {
Expand Down
1 change: 1 addition & 0 deletions cli/factory.rs
Expand Up @@ -775,6 +775,7 @@ impl CliFactory {
self.feature_checker().clone(),
self.create_cli_main_worker_options()?,
self.options.node_ipc_fd(),
self.options.enable_future_features(),
// TODO(bartlomieju): temporarily disabled
// self.options.disable_deprecated_api_warning,
true,
Expand Down
1 change: 1 addition & 0 deletions cli/standalone/mod.rs
Expand Up @@ -551,6 +551,7 @@ pub async fn run(
create_coverage_collector: None,
},
None,
false,
// TODO(bartlomieju): temporarily disabled
// metadata.disable_deprecated_api_warning,
true,
Expand Down
5 changes: 5 additions & 0 deletions cli/worker.rs
Expand Up @@ -144,6 +144,7 @@ struct SharedWorkerState {
maybe_lockfile: Option<Arc<Mutex<Lockfile>>>,
feature_checker: Arc<FeatureChecker>,
node_ipc: Option<i64>,
enable_future_features: bool,
disable_deprecated_api_warning: bool,
verbose_deprecated_api_warning: bool,
}
Expand Down Expand Up @@ -424,6 +425,7 @@ impl CliMainWorkerFactory {
feature_checker: Arc<FeatureChecker>,
options: CliMainWorkerOptions,
node_ipc: Option<i64>,
enable_future_features: bool,
disable_deprecated_api_warning: bool,
verbose_deprecated_api_warning: bool,
) -> Self {
Expand All @@ -446,6 +448,7 @@ impl CliMainWorkerFactory {
maybe_lockfile,
feature_checker,
node_ipc,
enable_future_features,
disable_deprecated_api_warning,
verbose_deprecated_api_warning,
}),
Expand Down Expand Up @@ -612,6 +615,7 @@ impl CliMainWorkerFactory {
node_ipc_fd: shared.node_ipc,
disable_deprecated_api_warning: shared.disable_deprecated_api_warning,
verbose_deprecated_api_warning: shared.verbose_deprecated_api_warning,
future: shared.enable_future_features,
},
extensions: custom_extensions,
startup_snapshot: crate::js::deno_isolate_init(),
Expand Down Expand Up @@ -818,6 +822,7 @@ fn create_web_worker_callback(
node_ipc_fd: None,
disable_deprecated_api_warning: shared.disable_deprecated_api_warning,
verbose_deprecated_api_warning: shared.verbose_deprecated_api_warning,
future: false,
},
extensions: vec![],
startup_snapshot: crate::js::deno_isolate_init(),
Expand Down
5 changes: 5 additions & 0 deletions runtime/js/99_main.js
Expand Up @@ -647,6 +647,7 @@ function bootstrapMainRuntime(runtimeOptions) {
6: maybeBinaryNpmCommandName,
7: shouldDisableDeprecatedApiWarning,
8: shouldUseVerboseDeprecatedApiWarning,
9: future,
} = runtimeOptions;

removeImportedOps();
Expand Down Expand Up @@ -769,6 +770,10 @@ function bootstrapMainRuntime(runtimeOptions) {
if (nodeBootstrap) {
nodeBootstrap(hasNodeModulesDir, maybeBinaryNpmCommandName);
}

if (future) {
delete globalThis.window;
}
}

function bootstrapWorkerRuntime(
Expand Down
5 changes: 5 additions & 0 deletions runtime/worker_bootstrap.rs
Expand Up @@ -62,6 +62,7 @@ pub struct BootstrapOptions {
pub node_ipc_fd: Option<i64>,
pub disable_deprecated_api_warning: bool,
pub verbose_deprecated_api_warning: bool,
pub future: bool,
}

impl Default for BootstrapOptions {
Expand Down Expand Up @@ -92,6 +93,7 @@ impl Default for BootstrapOptions {
node_ipc_fd: None,
disable_deprecated_api_warning: false,
verbose_deprecated_api_warning: false,
future: false,
}
}
}
Expand Down Expand Up @@ -125,6 +127,8 @@ struct BootstrapV8<'a>(
bool,
// verbose_deprecated_api_warning
bool,
// future
bool,
);

impl BootstrapOptions {
Expand All @@ -146,6 +150,7 @@ impl BootstrapOptions {
self.maybe_binary_npm_command_name.as_deref(),
self.disable_deprecated_api_warning,
self.verbose_deprecated_api_warning,
self.future,
);

bootstrap.serialize(ser).unwrap()
Expand Down
5 changes: 5 additions & 0 deletions test_util/src/builders.rs
Expand Up @@ -166,6 +166,11 @@ impl TestContextBuilder {
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 {
for (key, value) in env_vars_for_jsr_tests() {
self = self.env(key, value);
Expand Down
10 changes: 10 additions & 0 deletions tests/integration/run_tests.rs
Expand Up @@ -1711,6 +1711,16 @@ fn type_directives_js_main() {
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 {
args: "run --reload --check run/type_directives_redirect.ts",
output: "run/type_directives_redirect.ts.out",
Expand Down
3 changes: 3 additions & 0 deletions tests/testdata/run/deno_futures_env.ts
@@ -0,0 +1,3 @@
if (typeof window !== "undefined") {
throw new Error("Window global available");
}

0 comments on commit 8b1a4d1

Please sign in to comment.