mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 16:19:12 -05:00
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:
parent
f3bb0a1a0e
commit
0d51c1f90e
5 changed files with 16 additions and 30 deletions
|
@ -1126,7 +1126,7 @@ impl Inner {
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"isolatedModules": true,
|
"isolatedModules": true,
|
||||||
"jsx": "react",
|
"jsx": "react",
|
||||||
"lib": ["deno.ns", "deno.window"],
|
"lib": ["deno.ns", "deno.window", "deno.unstable"],
|
||||||
"module": "esnext",
|
"module": "esnext",
|
||||||
"moduleDetection": "force",
|
"moduleDetection": "force",
|
||||||
"noEmit": true,
|
"noEmit": true,
|
||||||
|
@ -1137,14 +1137,6 @@ impl Inner {
|
||||||
// TODO(@kitsonk) remove for Deno 1.15
|
// TODO(@kitsonk) remove for Deno 1.15
|
||||||
"useUnknownInCatchVariables": false,
|
"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) {
|
if let Err(err) = self.merge_user_tsconfig(&mut tsconfig) {
|
||||||
self.client.show_message(MessageType::WARNING, err);
|
self.client.show_message(MessageType::WARNING, err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,7 +195,7 @@ async fn run_subcommand(flags: Flags) -> Result<i32, AnyError> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
DenoSubcommand::Types => spawn_subcommand(async move {
|
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())
|
display::write_to_stdout_ignore_sigpipe(types.as_bytes())
|
||||||
}),
|
}),
|
||||||
#[cfg(feature = "upgrade")]
|
#[cfg(feature = "upgrade")]
|
||||||
|
|
|
@ -1904,7 +1904,7 @@ fn lsp_exclude_config() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lsp_hover_unstable_disabled() {
|
fn lsp_hover_unstable_always_enabled() {
|
||||||
let context = TestContextBuilder::new().use_temp_cwd().build();
|
let context = TestContextBuilder::new().use_temp_cwd().build();
|
||||||
let mut client = context.new_lsp_command().build();
|
let mut client = context.new_lsp_command().build();
|
||||||
client.initialize_default();
|
client.initialize_default();
|
||||||
|
@ -1933,9 +1933,10 @@ fn lsp_hover_unstable_disabled() {
|
||||||
"contents":[
|
"contents":[
|
||||||
{
|
{
|
||||||
"language":"typescript",
|
"language":"typescript",
|
||||||
"value": "type Deno.ForeignLibraryInterface = /*unresolved*/ any",
|
"value":"interface Deno.ForeignLibraryInterface"
|
||||||
},
|
},
|
||||||
"",
|
"**UNSTABLE**: New API, yet to be vetted.\n\nA foreign library interface descriptor.",
|
||||||
|
"\n\n*@category* - FFI",
|
||||||
],
|
],
|
||||||
"range":{
|
"range":{
|
||||||
"start":{ "line":0, "character":14 },
|
"start":{ "line":0, "character":14 },
|
||||||
|
@ -1951,6 +1952,7 @@ fn lsp_hover_unstable_enabled() {
|
||||||
let context = TestContextBuilder::new().use_temp_cwd().build();
|
let context = TestContextBuilder::new().use_temp_cwd().build();
|
||||||
let mut client = context.new_lsp_command().build();
|
let mut client = context.new_lsp_command().build();
|
||||||
client.initialize(|builder| {
|
client.initialize(|builder| {
|
||||||
|
// NOTE(bartlomieju): this is effectively not used anymore.
|
||||||
builder.set_unstable(true);
|
builder.set_unstable(true);
|
||||||
});
|
});
|
||||||
client.did_open(json!({
|
client.did_open(json!({
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
use crate::args::CliOptions;
|
|
||||||
use crate::args::DocFlags;
|
use crate::args::DocFlags;
|
||||||
use crate::args::DocHtmlFlag;
|
use crate::args::DocHtmlFlag;
|
||||||
use crate::args::DocSourceFileFlag;
|
use crate::args::DocSourceFileFlag;
|
||||||
|
@ -28,17 +27,15 @@ use indexmap::IndexMap;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
async fn generate_doc_nodes_for_builtin_types(
|
async fn generate_doc_nodes_for_builtin_types(
|
||||||
doc_flags: DocFlags,
|
doc_flags: DocFlags,
|
||||||
cli_options: &Arc<CliOptions>,
|
|
||||||
parser: &dyn ModuleParser,
|
parser: &dyn ModuleParser,
|
||||||
analyzer: &dyn ModuleAnalyzer,
|
analyzer: &dyn ModuleAnalyzer,
|
||||||
) -> Result<IndexMap<ModuleSpecifier, Vec<doc::DocNode>>, AnyError> {
|
) -> Result<IndexMap<ModuleSpecifier, Vec<doc::DocNode>>, AnyError> {
|
||||||
let source_file_specifier =
|
let source_file_specifier =
|
||||||
ModuleSpecifier::parse("internal://lib.deno.d.ts").unwrap();
|
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(
|
let mut loader = deno_graph::source::MemoryLoader::new(
|
||||||
vec![(
|
vec![(
|
||||||
source_file_specifier.to_string(),
|
source_file_specifier.to_string(),
|
||||||
|
@ -86,7 +83,6 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> {
|
||||||
DocSourceFileFlag::Builtin => {
|
DocSourceFileFlag::Builtin => {
|
||||||
generate_doc_nodes_for_builtin_types(
|
generate_doc_nodes_for_builtin_types(
|
||||||
doc_flags.clone(),
|
doc_flags.clone(),
|
||||||
cli_options,
|
|
||||||
&capturing_parser,
|
&capturing_parser,
|
||||||
&analyzer,
|
&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 = if doc_flags.source_files != DocSourceFileFlag::Builtin {
|
||||||
let deno_ns = generate_doc_nodes_for_builtin_types(
|
let deno_ns = generate_doc_nodes_for_builtin_types(
|
||||||
doc_flags.clone(),
|
doc_flags.clone(),
|
||||||
cli_options,
|
|
||||||
&capturing_parser,
|
&capturing_parser,
|
||||||
&analyzer,
|
&analyzer,
|
||||||
)
|
)
|
||||||
|
|
|
@ -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()
|
let mut assets = get_asset_texts_from_new_runtime()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|a| (a.specifier, a.text))
|
.map(|a| (a.specifier, a.text))
|
||||||
.collect::<HashMap<_, _>>();
|
.collect::<HashMap<_, _>>();
|
||||||
|
|
||||||
let mut lib_names = vec![
|
let lib_names = vec![
|
||||||
"deno.ns",
|
"deno.ns",
|
||||||
"deno.console",
|
"deno.console",
|
||||||
"deno.url",
|
"deno.url",
|
||||||
|
@ -100,12 +100,9 @@ pub fn get_types_declaration_file_text(unstable: bool) -> String {
|
||||||
"deno.shared_globals",
|
"deno.shared_globals",
|
||||||
"deno.cache",
|
"deno.cache",
|
||||||
"deno.window",
|
"deno.window",
|
||||||
|
"deno.unstable",
|
||||||
];
|
];
|
||||||
|
|
||||||
if unstable {
|
|
||||||
lib_names.push("deno.unstable");
|
|
||||||
}
|
|
||||||
|
|
||||||
lib_names
|
lib_names
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|name| {
|
.map(|name| {
|
||||||
|
|
Loading…
Reference in a new issue