feat: remove conditional unstable type-checking (#21825)

This commit removes conditional type-checking of unstable APIs.

Before this commit `deno check` (or any other type-checking command and
the LSP) would error out if there was an unstable API in the code, but not
`--unstable` flag provided.

This situation hinders DX and makes it harder to configure Deno. Failing
during runtime unless `--unstable` flag is provided is enough in this case.
This commit is contained in:
Bartek Iwańczuk 2024-01-14 18:29:17 +01:00 committed by GitHub
parent f3bb0a1a0e
commit 0d51c1f90e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 30 deletions

View file

@ -1126,7 +1126,7 @@ impl Inner {
"experimentalDecorators": true,
"isolatedModules": true,
"jsx": "react",
"lib": ["deno.ns", "deno.window"],
"lib": ["deno.ns", "deno.window", "deno.unstable"],
"module": "esnext",
"moduleDetection": "force",
"noEmit": true,
@ -1137,14 +1137,6 @@ impl Inner {
// TODO(@kitsonk) remove for Deno 1.15
"useUnknownInCatchVariables": false,
}));
let config = &self.config;
let workspace_settings = config.workspace_settings();
if workspace_settings.unstable {
let unstable_libs = json!({
"lib": ["deno.ns", "deno.window", "deno.unstable"]
});
tsconfig.merge(&unstable_libs);
}
if let Err(err) = self.merge_user_tsconfig(&mut tsconfig) {
self.client.show_message(MessageType::WARNING, err);
}

View file

@ -195,7 +195,7 @@ async fn run_subcommand(flags: Flags) -> Result<i32, AnyError> {
})
}
DenoSubcommand::Types => spawn_subcommand(async move {
let types = tsc::get_types_declaration_file_text(flags.unstable);
let types = tsc::get_types_declaration_file_text();
display::write_to_stdout_ignore_sigpipe(types.as_bytes())
}),
#[cfg(feature = "upgrade")]

View file

@ -1904,7 +1904,7 @@ fn lsp_exclude_config() {
}
#[test]
fn lsp_hover_unstable_disabled() {
fn lsp_hover_unstable_always_enabled() {
let context = TestContextBuilder::new().use_temp_cwd().build();
let mut client = context.new_lsp_command().build();
client.initialize_default();
@ -1930,16 +1930,17 @@ fn lsp_hover_unstable_disabled() {
assert_eq!(
res,
json!({
"contents": [
"contents":[
{
"language": "typescript",
"value": "type Deno.ForeignLibraryInterface = /*unresolved*/ any",
"language":"typescript",
"value":"interface Deno.ForeignLibraryInterface"
},
"",
"**UNSTABLE**: New API, yet to be vetted.\n\nA foreign library interface descriptor.",
"\n\n*@category* - FFI",
],
"range": {
"start": { "line": 0, "character": 14 },
"end": { "line": 0, "character": 37 }
"range":{
"start":{ "line":0, "character":14 },
"end":{ "line":0, "character":37 }
}
})
);
@ -1951,6 +1952,7 @@ fn lsp_hover_unstable_enabled() {
let context = TestContextBuilder::new().use_temp_cwd().build();
let mut client = context.new_lsp_command().build();
client.initialize(|builder| {
// NOTE(bartlomieju): this is effectively not used anymore.
builder.set_unstable(true);
});
client.did_open(json!({

View file

@ -1,6 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use crate::args::CliOptions;
use crate::args::DocFlags;
use crate::args::DocHtmlFlag;
use crate::args::DocSourceFileFlag;
@ -28,17 +27,15 @@ use indexmap::IndexMap;
use std::collections::BTreeMap;
use std::path::PathBuf;
use std::rc::Rc;
use std::sync::Arc;
async fn generate_doc_nodes_for_builtin_types(
doc_flags: DocFlags,
cli_options: &Arc<CliOptions>,
parser: &dyn ModuleParser,
analyzer: &dyn ModuleAnalyzer,
) -> Result<IndexMap<ModuleSpecifier, Vec<doc::DocNode>>, AnyError> {
let source_file_specifier =
ModuleSpecifier::parse("internal://lib.deno.d.ts").unwrap();
let content = get_types_declaration_file_text(cli_options.unstable());
let content = get_types_declaration_file_text();
let mut loader = deno_graph::source::MemoryLoader::new(
vec![(
source_file_specifier.to_string(),
@ -86,7 +83,6 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> {
DocSourceFileFlag::Builtin => {
generate_doc_nodes_for_builtin_types(
doc_flags.clone(),
cli_options,
&capturing_parser,
&analyzer,
)
@ -156,7 +152,6 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> {
let deno_ns = if doc_flags.source_files != DocSourceFileFlag::Builtin {
let deno_ns = generate_doc_nodes_for_builtin_types(
doc_flags.clone(),
cli_options,
&capturing_parser,
&analyzer,
)

View file

@ -78,14 +78,14 @@ pub static COMPILER_SNAPSHOT: Lazy<Box<[u8]>> = Lazy::new(
},
);
pub fn get_types_declaration_file_text(unstable: bool) -> String {
pub fn get_types_declaration_file_text() -> String {
let mut assets = get_asset_texts_from_new_runtime()
.unwrap()
.into_iter()
.map(|a| (a.specifier, a.text))
.collect::<HashMap<_, _>>();
let mut lib_names = vec![
let lib_names = vec![
"deno.ns",
"deno.console",
"deno.url",
@ -100,12 +100,9 @@ pub fn get_types_declaration_file_text(unstable: bool) -> String {
"deno.shared_globals",
"deno.cache",
"deno.window",
"deno.unstable",
];
if unstable {
lib_names.push("deno.unstable");
}
lib_names
.into_iter()
.map(|name| {