From 2ed984ba3aa638c3f088ac1edc5c779c7d9195d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 8 Mar 2024 00:32:11 +0000 Subject: [PATCH] fix: respect unstable "temporal" configuration in config file (#22134) Actual fix happened in https://github.com/denoland/deno/pull/22782, but this commit adds additional tests and cleans up V8 flags passed on init. Closes https://github.com/denoland/deno/issues/22123 Closes https://github.com/denoland/deno/issues/22560 Closes https://github.com/denoland/deno/issues/22557 --- cli/main.rs | 13 +------ runtime/lib.rs | 7 +--- tests/integration/compile_tests.rs | 38 ++++++++++++++++++- tests/integration/run_tests.rs | 11 +++++- tests/testdata/compile/unstable_features.ts | 1 + .../run/unstable_temporal_api/deno.json | 3 ++ 6 files changed, 52 insertions(+), 21 deletions(-) create mode 100644 tests/testdata/run/unstable_temporal_api/deno.json diff --git a/cli/main.rs b/cli/main.rs index d4a6846a8e..3d72a33343 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -372,18 +372,7 @@ pub fn main() { // Using same default as VSCode: // https://github.com/microsoft/vscode/blob/48d4ba271686e8072fc6674137415bc80d936bc7/extensions/typescript-language-features/src/configuration/configuration.ts#L213-L214 DenoSubcommand::Lsp => vec!["--max-old-space-size=3072".to_string()], - _ => { - if flags.unstable_config.legacy_flag_enabled - || flags - .unstable_config - .features - .contains(&"temporal".to_string()) - { - vec!["--harmony-temporal".to_string()] - } else { - vec![] - } - } + _ => vec![], }; init_v8_flags(&default_v8_flags, &flags.v8_flags, get_v8_flags_from_env()); deno_core::JsRuntime::init_platform(None); diff --git a/runtime/lib.rs b/runtime/lib.rs index b63fd41340..ade10a9c68 100644 --- a/runtime/lib.rs +++ b/runtime/lib.rs @@ -87,12 +87,7 @@ pub static UNSTABLE_GRANULAR_FLAGS: &[( "Enable unstable net APIs", 7, ), - ( - "temporal", - "Enable unstable Temporal API", - // Not used in JS - 8, - ), + ("temporal", "Enable unstable Temporal API", 8), ( "unsafe-proto", "Enable unsafe __proto__ support. This is a security risk.", diff --git a/tests/integration/compile_tests.rs b/tests/integration/compile_tests.rs index b038819a7a..9258da89fc 100644 --- a/tests/integration/compile_tests.rs +++ b/tests/integration/compile_tests.rs @@ -1,5 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use deno_core::serde_json; use test_util as util; use util::assert_contains; use util::assert_not_contains; @@ -1140,6 +1141,7 @@ fn granular_unstable_features() { "--output", &exe.to_string_lossy(), "--unstable-kv", + "--unstable-temporal", "./compile/unstable_features.ts", ]) .run(); @@ -1147,7 +1149,41 @@ fn granular_unstable_features() { output.skip_output_check(); let output = context.new_command().name(&exe).run(); output.assert_exit_code(0); - output.assert_matches_text("Kv {}\n"); + output.assert_matches_text("Kv {}\nObject [Temporal] {}\n"); +} + +#[test] +fn granular_unstable_features_config_file() { + let context = TestContextBuilder::new().build(); + let dir = context.temp_dir(); + let exe = if cfg!(windows) { + dir.path().join("app.exe") + } else { + dir.path().join("app") + }; + dir.write( + "deno.json", + serde_json::to_string_pretty(&serde_json::json!({ + "unstable": ["kv", "temporal"] + })) + .unwrap(), + ); + let output = context + .new_command() + .args_vec([ + "compile", + "--config", + &dir.path().join("deno.json").to_string(), + "--output", + &exe.to_string_lossy(), + "./compile/unstable_features.ts", + ]) + .run(); + output.assert_exit_code(0); + output.skip_output_check(); + let output = context.new_command().name(&exe).run(); + output.assert_exit_code(0); + output.assert_matches_text("Kv {}\nObject [Temporal] {}\n"); } #[test] diff --git a/tests/integration/run_tests.rs b/tests/integration/run_tests.rs index 77e1db2ab4..637dc578bb 100644 --- a/tests/integration/run_tests.rs +++ b/tests/integration/run_tests.rs @@ -5060,14 +5060,21 @@ Warning Sloppy module resolution (hint: specify path to index.tsx file in direct } itest!(unstable_temporal_api { - args: "run --unstable-temporal --check run/unstable_temporal_api/main.ts", + args: "run --no-config --unstable-temporal --check run/unstable_temporal_api/main.ts", + output: "run/unstable_temporal_api/main.out", + http_server: false, + exit_code: 0, +}); + +itest!(unstable_temporal_api_config_file { + args: "run --check run/unstable_temporal_api/main.ts", output: "run/unstable_temporal_api/main.out", http_server: false, exit_code: 0, }); itest!(unstable_temporal_api_missing_flag { - args: "run run/unstable_temporal_api/missing_flag.js", + args: "run --no-config run/unstable_temporal_api/missing_flag.js", output: "run/unstable_temporal_api/missing_flag.out", http_server: false, exit_code: 1, diff --git a/tests/testdata/compile/unstable_features.ts b/tests/testdata/compile/unstable_features.ts index 819a3d1875..19d5e03f50 100644 --- a/tests/testdata/compile/unstable_features.ts +++ b/tests/testdata/compile/unstable_features.ts @@ -1,2 +1,3 @@ const db = await Deno.openKv(); console.log(db); +console.log(Temporal); diff --git a/tests/testdata/run/unstable_temporal_api/deno.json b/tests/testdata/run/unstable_temporal_api/deno.json new file mode 100644 index 0000000000..fea0791c53 --- /dev/null +++ b/tests/testdata/run/unstable_temporal_api/deno.json @@ -0,0 +1,3 @@ +{ + "unstable": ["temporal"] +}