Skip to content

Commit

Permalink
feat: remove conditional unstable type-checking (#21825)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bartlomieju authored Jan 14, 2024
1 parent f3bb0a1 commit 0d51c1f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 30 deletions.
10 changes: 1 addition & 9 deletions cli/lsp/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
18 changes: 10 additions & 8 deletions cli/tests/integration/lsp_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 }
}
})
);
Expand All @@ -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!({
Expand Down
7 changes: 1 addition & 6 deletions cli/tools/doc.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down
9 changes: 3 additions & 6 deletions cli/tsc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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| {
Expand Down

0 comments on commit 0d51c1f

Please sign in to comment.