mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -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:
parent
1ad754b412
commit
b72f0be27c
9 changed files with 39 additions and 0 deletions
|
@ -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) => {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -551,6 +551,7 @@ pub async fn run(
|
|||
create_coverage_collector: None,
|
||||
},
|
||||
None,
|
||||
false,
|
||||
// TODO(bartlomieju): temporarily disabled
|
||||
// metadata.disable_deprecated_api_warning,
|
||||
true,
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -446,6 +448,7 @@ impl CliMainWorkerFactory {
|
|||
maybe_lockfile,
|
||||
feature_checker,
|
||||
node_ipc,
|
||||
enable_future_features,
|
||||
disable_deprecated_api_warning,
|
||||
verbose_deprecated_api_warning,
|
||||
}),
|
||||
|
@ -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(),
|
||||
|
@ -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(),
|
||||
|
|
|
@ -647,6 +647,7 @@ function bootstrapMainRuntime(runtimeOptions) {
|
|||
6: maybeBinaryNpmCommandName,
|
||||
7: shouldDisableDeprecatedApiWarning,
|
||||
8: shouldUseVerboseDeprecatedApiWarning,
|
||||
9: future,
|
||||
} = runtimeOptions;
|
||||
|
||||
removeImportedOps();
|
||||
|
@ -769,6 +770,10 @@ function bootstrapMainRuntime(runtimeOptions) {
|
|||
if (nodeBootstrap) {
|
||||
nodeBootstrap(hasNodeModulesDir, maybeBinaryNpmCommandName);
|
||||
}
|
||||
|
||||
if (future) {
|
||||
delete globalThis.window;
|
||||
}
|
||||
}
|
||||
|
||||
function bootstrapWorkerRuntime(
|
||||
|
|
|
@ -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 {
|
||||
|
@ -92,6 +93,7 @@ impl Default for BootstrapOptions {
|
|||
node_ipc_fd: None,
|
||||
disable_deprecated_api_warning: false,
|
||||
verbose_deprecated_api_warning: false,
|
||||
future: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,6 +127,8 @@ struct BootstrapV8<'a>(
|
|||
bool,
|
||||
// verbose_deprecated_api_warning
|
||||
bool,
|
||||
// future
|
||||
bool,
|
||||
);
|
||||
|
||||
impl BootstrapOptions {
|
||||
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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",
|
||||
|
|
3
tests/testdata/run/deno_futures_env.ts
vendored
Normal file
3
tests/testdata/run/deno_futures_env.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
if (typeof window !== "undefined") {
|
||||
throw new Error("Window global available");
|
||||
}
|
Loading…
Reference in a new issue