diff --git a/.dprint.json b/.dprint.json index 959c44aa8f..511e674ed5 100644 --- a/.dprint.json +++ b/.dprint.json @@ -21,12 +21,7 @@ ".git", "cli/bench/testdata/express-router.js", "cli/bench/testdata/npm/*", - "cli/dts/lib.d.ts", - "cli/dts/lib.dom*", - "cli/dts/lib.es*", - "cli/dts/lib.scripthost.d.ts", - "cli/dts/lib.webworker*.d.ts", - "cli/dts/typescript.d.ts", + "cli/tsc/dts/*.d.ts", "cli/tests/testdata/fmt/badly_formatted.json", "cli/tests/testdata/fmt/badly_formatted.md", "cli/tests/testdata/byte_order_mark.ts", diff --git a/cli/args/config_file.rs b/cli/args/config_file.rs index cf88e3999c..435e0d715b 100644 --- a/cli/args/config_file.rs +++ b/cli/args/config_file.rs @@ -762,6 +762,157 @@ impl ConfigFile { } } +/// Represents the "default" type library that should be used when type +/// checking the code in the module graph. Note that a user provided config +/// of `"lib"` would override this value. +#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)] +pub enum TsTypeLib { + DenoWindow, + DenoWorker, + UnstableDenoWindow, + UnstableDenoWorker, +} + +impl Default for TsTypeLib { + fn default() -> Self { + Self::DenoWindow + } +} + +impl Serialize for TsTypeLib { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let value = match self { + Self::DenoWindow => vec!["deno.window".to_string()], + Self::DenoWorker => vec!["deno.worker".to_string()], + Self::UnstableDenoWindow => { + vec!["deno.window".to_string(), "deno.unstable".to_string()] + } + Self::UnstableDenoWorker => { + vec!["deno.worker".to_string(), "deno.unstable".to_string()] + } + }; + Serialize::serialize(&value, serializer) + } +} + +/// An enum that represents the base tsc configuration to return. +pub enum TsConfigType { + /// Return a configuration for bundling, using swc to emit the bundle. This is + /// independent of type checking. + Bundle, + /// Return a configuration to use tsc to type check. This + /// is independent of either bundling or emitting via swc. + Check { lib: TsTypeLib }, + /// Return a configuration to use swc to emit single module files. + Emit, +} + +pub struct TsConfigForEmit { + pub ts_config: TsConfig, + pub maybe_ignored_options: Option, +} + +/// For a given configuration type and optionally a configuration file, +/// return a `TsConfig` struct and optionally any user configuration +/// options that were ignored. +pub fn get_ts_config_for_emit( + config_type: TsConfigType, + maybe_config_file: Option<&ConfigFile>, +) -> Result { + let mut ts_config = match config_type { + TsConfigType::Bundle => TsConfig::new(json!({ + "checkJs": false, + "emitDecoratorMetadata": false, + "importsNotUsedAsValues": "remove", + "inlineSourceMap": false, + "inlineSources": false, + "sourceMap": false, + "jsx": "react", + "jsxFactory": "React.createElement", + "jsxFragmentFactory": "React.Fragment", + })), + TsConfigType::Check { lib } => TsConfig::new(json!({ + "allowJs": true, + "allowSyntheticDefaultImports": true, + "checkJs": false, + "emitDecoratorMetadata": false, + "experimentalDecorators": true, + "incremental": true, + "jsx": "react", + "importsNotUsedAsValues": "remove", + "inlineSourceMap": true, + "inlineSources": true, + "isolatedModules": true, + "lib": lib, + "module": "esnext", + "moduleDetection": "force", + "noEmit": true, + "resolveJsonModule": true, + "sourceMap": false, + "strict": true, + "target": "esnext", + "tsBuildInfoFile": "deno:///.tsbuildinfo", + "useDefineForClassFields": true, + // TODO(@kitsonk) remove for Deno 2.0 + "useUnknownInCatchVariables": false, + })), + TsConfigType::Emit => TsConfig::new(json!({ + "checkJs": false, + "emitDecoratorMetadata": false, + "importsNotUsedAsValues": "remove", + "inlineSourceMap": true, + "inlineSources": true, + "sourceMap": false, + "jsx": "react", + "jsxFactory": "React.createElement", + "jsxFragmentFactory": "React.Fragment", + "resolveJsonModule": true, + })), + }; + let maybe_ignored_options = + ts_config.merge_tsconfig_from_config_file(maybe_config_file)?; + Ok(TsConfigForEmit { + ts_config, + maybe_ignored_options, + }) +} + +impl From for deno_ast::EmitOptions { + fn from(config: TsConfig) -> Self { + let options: EmitConfigOptions = serde_json::from_value(config.0).unwrap(); + let imports_not_used_as_values = + match options.imports_not_used_as_values.as_str() { + "preserve" => deno_ast::ImportsNotUsedAsValues::Preserve, + "error" => deno_ast::ImportsNotUsedAsValues::Error, + _ => deno_ast::ImportsNotUsedAsValues::Remove, + }; + let (transform_jsx, jsx_automatic, jsx_development) = + match options.jsx.as_str() { + "react" => (true, false, false), + "react-jsx" => (true, true, false), + "react-jsxdev" => (true, true, true), + _ => (false, false, false), + }; + deno_ast::EmitOptions { + emit_metadata: options.emit_decorator_metadata, + imports_not_used_as_values, + inline_source_map: options.inline_source_map, + inline_sources: options.inline_sources, + source_map: options.source_map, + jsx_automatic, + jsx_development, + jsx_factory: options.jsx_factory, + jsx_fragment_factory: options.jsx_fragment_factory, + jsx_import_source: options.jsx_import_source, + transform_jsx, + var_decl_imports: false, + } + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/cli/lockfile.rs b/cli/args/lockfile.rs similarity index 98% rename from cli/lockfile.rs rename to cli/args/lockfile.rs index b1f0c777fe..f99d2f5701 100644 --- a/cli/lockfile.rs +++ b/cli/args/lockfile.rs @@ -95,6 +95,15 @@ pub struct Lockfile { } impl Lockfile { + pub fn as_maybe_locker( + lockfile: Option>>, + ) -> Option>> { + lockfile.as_ref().map(|lf| { + Rc::new(RefCell::new(Locker(Some(lf.clone())))) + as Rc> + }) + } + pub fn discover( flags: &Flags, maybe_config_file: Option<&ConfigFile>, @@ -359,15 +368,6 @@ impl deno_graph::source::Locker for Locker { } } -pub fn as_maybe_locker( - lockfile: Option>>, -) -> Option>> { - lockfile.as_ref().map(|lf| { - Rc::new(RefCell::new(Locker(Some(lf.clone())))) - as Rc> - }) -} - #[cfg(test)] mod tests { use super::*; diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 64755a4948..ae43bccaf0 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -1,7 +1,8 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. -pub mod config_file; -pub mod flags; +mod config_file; +mod flags; +mod lockfile; mod flags_allow_net; @@ -10,13 +11,20 @@ pub use config_file::ConfigFile; pub use config_file::EmitConfigOptions; pub use config_file::FmtConfig; pub use config_file::FmtOptionsConfig; +pub use config_file::IgnoredCompilerOptions; +pub use config_file::JsxImportSourceConfig; pub use config_file::LintConfig; pub use config_file::LintRulesConfig; pub use config_file::MaybeImportsResult; pub use config_file::ProseWrap; pub use config_file::TestConfig; pub use config_file::TsConfig; +pub use config_file::TsConfigForEmit; +pub use config_file::TsConfigType; +pub use config_file::TsTypeLib; pub use flags::*; +pub use lockfile::Lockfile; +pub use lockfile::LockfileError; use deno_ast::ModuleSpecifier; use deno_core::anyhow::anyhow; @@ -36,16 +44,10 @@ use std::net::SocketAddr; use std::path::PathBuf; use std::sync::Arc; -use crate::args::config_file::JsxImportSourceConfig; use crate::deno_dir::DenoDir; -use crate::emit::get_ts_config_for_emit; -use crate::emit::TsConfigType; -use crate::emit::TsConfigWithIgnoredOptions; -use crate::emit::TsTypeLib; use crate::file_fetcher::get_root_cert_store; use crate::file_fetcher::CacheSetting; use crate::fs_util; -use crate::lockfile::Lockfile; use crate::version; /// Overrides for the options below that when set will @@ -188,8 +190,11 @@ impl CliOptions { pub fn resolve_ts_config_for_emit( &self, config_type: TsConfigType, - ) -> Result { - get_ts_config_for_emit(config_type, self.maybe_config_file.as_ref()) + ) -> Result { + config_file::get_ts_config_for_emit( + config_type, + self.maybe_config_file.as_ref(), + ) } /// Resolves the storage key to use based on the current flags, config, or main module. diff --git a/cli/build.rs b/cli/build.rs index c7d902941f..a7076145a5 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -122,7 +122,7 @@ mod ts { "esnext.intl", ]; - let path_dts = cwd.join("dts"); + let path_dts = cwd.join("tsc/dts"); // ensure we invalidate the build properly. for name in libs.iter() { println!( @@ -476,5 +476,8 @@ fn main() { fn deno_webgpu_get_declaration() -> PathBuf { let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR")); - manifest_dir.join("dts").join("lib.deno_webgpu.d.ts") + manifest_dir + .join("tsc") + .join("dts") + .join("lib.deno_webgpu.d.ts") } diff --git a/cli/dts/README.md b/cli/dts/README.md deleted file mode 100644 index 14d937c88d..0000000000 --- a/cli/dts/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# How to upgrade TypeScript. - -The files in this directory are mostly from the TypeScript repository. We -currently (unfortunately) have a rather manual process for upgrading TypeScript. -It works like this currently: - -1. Checkout denoland/TypeScript repo in a separate directory. -1. Add Microsoft/TypeScript as a remote and fetch its latest tags -1. Checkout a new branch based on this tag. -1. Cherry pick the custom commit we made in a previous release to the new one. -1. This commit has a "deno.ts" file in it. Read the instructions in it. -1. Copy typescript.js into Deno repo. -1. Copy d.ts files into dts directory. - -So that might look something like this: - -``` -git clone https://github.com/denoland/TypeScript.git -cd typescript -git remote add upstream https://github.com/Microsoft/TypeScript -git fetch upstream -git checkout v3.9.7 -git checkout -b branch_v3.9.7 -git cherry pick -npm install -gulp local -rsync lib/typescript.js ~/src/deno/cli/tsc/00_typescript.js -rsync --exclude=protocol.d.ts --exclude=tsserverlibrary.d.ts --exclude=typescriptServices.d.ts lib/*.d.ts ~/src/deno/cli/dts/ -``` diff --git a/cli/emit.rs b/cli/emit.rs index f2d890adc5..3bf56fae69 100644 --- a/cli/emit.rs +++ b/cli/emit.rs @@ -1,154 +1,18 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. -//! The collection of APIs to be able to take `deno_graph` module graphs and -//! populate a cache, emit files, and transform a graph into the structures for -//! loading into an isolate. - -use crate::args::config_file::IgnoredCompilerOptions; -use crate::args::ConfigFile; -use crate::args::EmitConfigOptions; -use crate::args::TsConfig; use crate::cache::EmitCache; use crate::cache::FastInsecureHasher; use crate::cache::ParsedSourceCache; -use deno_ast::swc::bundler::Hook; -use deno_ast::swc::bundler::ModuleRecord; -use deno_ast::swc::common::Span; use deno_core::error::AnyError; -use deno_core::serde::Serialize; -use deno_core::serde::Serializer; -use deno_core::serde_json; -use deno_core::serde_json::json; use deno_core::ModuleSpecifier; use deno_graph::MediaType; -use deno_graph::ModuleGraphError; -use deno_graph::ResolutionError; -use std::fmt; use std::sync::Arc; -/// Represents the "default" type library that should be used when type -/// checking the code in the module graph. Note that a user provided config -/// of `"lib"` would override this value. -#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)] -pub enum TsTypeLib { - DenoWindow, - DenoWorker, - UnstableDenoWindow, - UnstableDenoWorker, -} - -impl Default for TsTypeLib { - fn default() -> Self { - Self::DenoWindow - } -} - -impl Serialize for TsTypeLib { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - let value = match self { - Self::DenoWindow => vec!["deno.window".to_string()], - Self::DenoWorker => vec!["deno.worker".to_string()], - Self::UnstableDenoWindow => { - vec!["deno.window".to_string(), "deno.unstable".to_string()] - } - Self::UnstableDenoWorker => { - vec!["deno.worker".to_string(), "deno.unstable".to_string()] - } - }; - Serialize::serialize(&value, serializer) - } -} - -/// An enum that represents the base tsc configuration to return. -pub enum TsConfigType { - /// Return a configuration for bundling, using swc to emit the bundle. This is - /// independent of type checking. - Bundle, - /// Return a configuration to use tsc to type check. This - /// is independent of either bundling or emitting via swc. - Check { lib: TsTypeLib }, - /// Return a configuration to use swc to emit single module files. - Emit, -} - -pub struct TsConfigWithIgnoredOptions { - pub ts_config: TsConfig, - pub maybe_ignored_options: Option, -} - -/// For a given configuration type and optionally a configuration file, -/// return a `TsConfig` struct and optionally any user configuration -/// options that were ignored. -pub fn get_ts_config_for_emit( - config_type: TsConfigType, - maybe_config_file: Option<&ConfigFile>, -) -> Result { - let mut ts_config = match config_type { - TsConfigType::Bundle => TsConfig::new(json!({ - "checkJs": false, - "emitDecoratorMetadata": false, - "importsNotUsedAsValues": "remove", - "inlineSourceMap": false, - "inlineSources": false, - "sourceMap": false, - "jsx": "react", - "jsxFactory": "React.createElement", - "jsxFragmentFactory": "React.Fragment", - })), - TsConfigType::Check { lib } => TsConfig::new(json!({ - "allowJs": true, - "allowSyntheticDefaultImports": true, - "checkJs": false, - "emitDecoratorMetadata": false, - "experimentalDecorators": true, - "incremental": true, - "jsx": "react", - "importsNotUsedAsValues": "remove", - "inlineSourceMap": true, - "inlineSources": true, - "isolatedModules": true, - "lib": lib, - "module": "esnext", - "moduleDetection": "force", - "noEmit": true, - "resolveJsonModule": true, - "sourceMap": false, - "strict": true, - "target": "esnext", - "tsBuildInfoFile": "deno:///.tsbuildinfo", - "useDefineForClassFields": true, - // TODO(@kitsonk) remove for Deno 2.0 - "useUnknownInCatchVariables": false, - })), - TsConfigType::Emit => TsConfig::new(json!({ - "checkJs": false, - "emitDecoratorMetadata": false, - "importsNotUsedAsValues": "remove", - "inlineSourceMap": true, - "inlineSources": true, - "sourceMap": false, - "jsx": "react", - "jsxFactory": "React.createElement", - "jsxFragmentFactory": "React.Fragment", - "resolveJsonModule": true, - })), - }; - let maybe_ignored_options = - ts_config.merge_tsconfig_from_config_file(maybe_config_file)?; - Ok(TsConfigWithIgnoredOptions { - ts_config, - maybe_ignored_options, - }) -} - -/// A hashing function that takes the source code, version and optionally a -/// user provided config and generates a string hash which can be stored to +/// A hashing function that takes the source code and emit options +/// hash then generates a string hash which can be stored to /// determine if the cached emit is valid or not. -pub fn get_source_hash(source_text: &str, emit_options_hash: u64) -> u64 { +fn get_source_hash(source_text: &str, emit_options_hash: u64) -> u64 { FastInsecureHasher::new() .write_str(source_text) .write_u64(emit_options_hash) @@ -183,107 +47,3 @@ pub fn emit_parsed_source( Ok(transpiled_source.text) } } - -/// An adapter struct to make a deno_graph::ModuleGraphError display as expected -/// in the Deno CLI. -#[derive(Debug)] -pub struct GraphError(pub ModuleGraphError); - -impl std::error::Error for GraphError {} - -impl From for GraphError { - fn from(err: ModuleGraphError) -> Self { - Self(err) - } -} - -impl fmt::Display for GraphError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match &self.0 { - ModuleGraphError::ResolutionError(err) => { - if matches!( - err, - ResolutionError::InvalidDowngrade { .. } - | ResolutionError::InvalidLocalImport { .. } - ) { - write!(f, "{}", err.to_string_with_range()) - } else { - self.0.fmt(f) - } - } - _ => self.0.fmt(f), - } - } -} - -/// This contains the logic for Deno to rewrite the `import.meta` when bundling. -pub struct BundleHook; - -impl Hook for BundleHook { - fn get_import_meta_props( - &self, - span: Span, - module_record: &ModuleRecord, - ) -> Result, AnyError> { - use deno_ast::swc::ast; - - Ok(vec![ - ast::KeyValueProp { - key: ast::PropName::Ident(ast::Ident::new("url".into(), span)), - value: Box::new(ast::Expr::Lit(ast::Lit::Str(ast::Str { - span, - value: module_record.file_name.to_string().into(), - raw: None, - }))), - }, - ast::KeyValueProp { - key: ast::PropName::Ident(ast::Ident::new("main".into(), span)), - value: Box::new(if module_record.is_entry { - ast::Expr::Member(ast::MemberExpr { - span, - obj: Box::new(ast::Expr::MetaProp(ast::MetaPropExpr { - span, - kind: ast::MetaPropKind::ImportMeta, - })), - prop: ast::MemberProp::Ident(ast::Ident::new("main".into(), span)), - }) - } else { - ast::Expr::Lit(ast::Lit::Bool(ast::Bool { span, value: false })) - }), - }, - ]) - } -} - -impl From for deno_ast::EmitOptions { - fn from(config: TsConfig) -> Self { - let options: EmitConfigOptions = serde_json::from_value(config.0).unwrap(); - let imports_not_used_as_values = - match options.imports_not_used_as_values.as_str() { - "preserve" => deno_ast::ImportsNotUsedAsValues::Preserve, - "error" => deno_ast::ImportsNotUsedAsValues::Error, - _ => deno_ast::ImportsNotUsedAsValues::Remove, - }; - let (transform_jsx, jsx_automatic, jsx_development) = - match options.jsx.as_str() { - "react" => (true, false, false), - "react-jsx" => (true, true, false), - "react-jsxdev" => (true, true, true), - _ => (false, false, false), - }; - deno_ast::EmitOptions { - emit_metadata: options.emit_decorator_metadata, - imports_not_used_as_values, - inline_source_map: options.inline_source_map, - inline_sources: options.inline_sources, - source_map: options.source_map, - jsx_automatic, - jsx_development, - jsx_factory: options.jsx_factory, - jsx_fragment_factory: options.jsx_fragment_factory, - jsx_import_source: options.jsx_import_source, - transform_jsx, - var_decl_imports: false, - } - } -} diff --git a/cli/errors.rs b/cli/errors.rs index fbf9da8e0a..2b5d195035 100644 --- a/cli/errors.rs +++ b/cli/errors.rs @@ -9,8 +9,6 @@ //! Diagnostics are compile-time type errors, whereas JsErrors are runtime //! exceptions. -use crate::emit::GraphError; - use deno_ast::Diagnostic; use deno_core::error::AnyError; use deno_graph::ModuleGraphError; @@ -25,11 +23,7 @@ fn get_diagnostic_class(_: &Diagnostic) -> &'static str { "SyntaxError" } -fn get_graph_error_class(err: &GraphError) -> &'static str { - get_module_graph_error_class(&err.0) -} - -pub fn get_module_graph_error_class(err: &ModuleGraphError) -> &'static str { +fn get_module_graph_error_class(err: &ModuleGraphError) -> &'static str { match err { ModuleGraphError::LoadingErr(_, err) => get_error_class_name(err.as_ref()), ModuleGraphError::InvalidSource(_, _) @@ -60,7 +54,6 @@ pub fn get_error_class_name(e: &AnyError) -> &'static str { .map(get_import_map_error_class) }) .or_else(|| e.downcast_ref::().map(get_diagnostic_class)) - .or_else(|| e.downcast_ref::().map(get_graph_error_class)) .or_else(|| { e.downcast_ref::() .map(get_module_graph_error_class) diff --git a/cli/graph_util.rs b/cli/graph_util.rs index b919d50420..8ffd284b81 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -1,7 +1,7 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +use crate::args::TsTypeLib; use crate::colors; -use crate::emit::TsTypeLib; use crate::errors::get_error_class_name; use crate::npm::resolve_npm_package_reqs; use crate::npm::NpmPackageReference; diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs index aac6e58627..58156bad26 100644 --- a/cli/lsp/diagnostics.rs +++ b/cli/lsp/diagnostics.rs @@ -13,7 +13,6 @@ use super::tsc; use super::tsc::TsServer; use crate::args::LintConfig; -use crate::diagnostics; use crate::npm::NpmPackageReference; use deno_ast::MediaType; @@ -43,7 +42,7 @@ pub type DiagnosticRecord = pub type DiagnosticVec = Vec; type DiagnosticMap = HashMap, Vec)>; -type TsDiagnosticsMap = HashMap>; +type TsDiagnosticsMap = HashMap>; type DiagnosticsByVersionMap = HashMap, Vec>; #[derive(Clone)] @@ -335,25 +334,25 @@ impl DiagnosticsServer { } } -impl<'a> From<&'a diagnostics::DiagnosticCategory> for lsp::DiagnosticSeverity { - fn from(category: &'a diagnostics::DiagnosticCategory) -> Self { +impl<'a> From<&'a crate::tsc::DiagnosticCategory> for lsp::DiagnosticSeverity { + fn from(category: &'a crate::tsc::DiagnosticCategory) -> Self { match category { - diagnostics::DiagnosticCategory::Error => lsp::DiagnosticSeverity::ERROR, - diagnostics::DiagnosticCategory::Warning => { + crate::tsc::DiagnosticCategory::Error => lsp::DiagnosticSeverity::ERROR, + crate::tsc::DiagnosticCategory::Warning => { lsp::DiagnosticSeverity::WARNING } - diagnostics::DiagnosticCategory::Suggestion => { + crate::tsc::DiagnosticCategory::Suggestion => { lsp::DiagnosticSeverity::HINT } - diagnostics::DiagnosticCategory::Message => { + crate::tsc::DiagnosticCategory::Message => { lsp::DiagnosticSeverity::INFORMATION } } } } -impl<'a> From<&'a diagnostics::Position> for lsp::Position { - fn from(pos: &'a diagnostics::Position) -> Self { +impl<'a> From<&'a crate::tsc::Position> for lsp::Position { + fn from(pos: &'a crate::tsc::Position) -> Self { Self { line: pos.line as u32, character: pos.character as u32, @@ -361,7 +360,7 @@ impl<'a> From<&'a diagnostics::Position> for lsp::Position { } } -fn get_diagnostic_message(diagnostic: &diagnostics::Diagnostic) -> String { +fn get_diagnostic_message(diagnostic: &crate::tsc::Diagnostic) -> String { if let Some(message) = diagnostic.message_text.clone() { message } else if let Some(message_chain) = diagnostic.message_chain.clone() { @@ -372,8 +371,8 @@ fn get_diagnostic_message(diagnostic: &diagnostics::Diagnostic) -> String { } fn to_lsp_range( - start: &diagnostics::Position, - end: &diagnostics::Position, + start: &crate::tsc::Position, + end: &crate::tsc::Position, ) -> lsp::Range { lsp::Range { start: start.into(), @@ -382,7 +381,7 @@ fn to_lsp_range( } fn to_lsp_related_information( - related_information: &Option>, + related_information: &Option>, ) -> Option> { related_information.as_ref().map(|related| { related @@ -408,7 +407,7 @@ fn to_lsp_related_information( } fn ts_json_to_diagnostics( - diagnostics: Vec, + diagnostics: Vec, ) -> Vec { diagnostics .iter() diff --git a/cli/main.rs b/cli/main.rs index 15110b301a..4ed845deff 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -7,7 +7,6 @@ mod cdp; mod checksum; mod deno_dir; mod deno_std; -mod diagnostics; mod diff; mod display; mod emit; @@ -19,7 +18,6 @@ mod graph_util; mod http_cache; mod http_util; mod js; -mod lockfile; mod logger; mod lsp; mod module_loader; @@ -60,12 +58,12 @@ use crate::args::ReplFlags; use crate::args::RunFlags; use crate::args::TaskFlags; use crate::args::TestFlags; +use crate::args::TsConfigType; use crate::args::TypeCheckMode; use crate::args::UninstallFlags; use crate::args::UpgradeFlags; use crate::args::VendorFlags; use crate::cache::TypeCheckCache; -use crate::emit::TsConfigType; use crate::file_fetcher::File; use crate::file_watcher::ResolutionResult; use crate::graph_util::graph_lock_or_exit; @@ -74,6 +72,7 @@ use crate::resolver::CliResolver; use crate::tools::check; use args::CliOptions; +use args::Lockfile; use deno_ast::MediaType; use deno_core::anyhow::bail; use deno_core::error::generic_error; @@ -327,7 +326,7 @@ async fn create_graph_and_maybe_check( Permissions::allow_all(), Permissions::allow_all(), ); - let maybe_locker = lockfile::as_maybe_locker(ps.lockfile.clone()); + let maybe_locker = Lockfile::as_maybe_locker(ps.lockfile.clone()); let maybe_imports = ps.options.to_maybe_imports()?; let maybe_cli_resolver = CliResolver::maybe_new( ps.options.to_maybe_jsx_import_source_config(), @@ -925,7 +924,7 @@ fn unwrap_or_exit(result: Result) -> T { if let Some(e) = error.downcast_ref::() { error_string = format_js_error(e); - } else if let Some(e) = error.downcast_ref::() { + } else if let Some(e) = error.downcast_ref::() { error_string = e.to_string(); error_code = 10; } diff --git a/cli/module_loader.rs b/cli/module_loader.rs index dc367f5e75..41ec7e28ce 100644 --- a/cli/module_loader.rs +++ b/cli/module_loader.rs @@ -1,7 +1,7 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +use crate::args::TsTypeLib; use crate::emit::emit_parsed_source; -use crate::emit::TsTypeLib; use crate::graph_util::ModuleEntry; use crate::node; use crate::proc_state::ProcState; diff --git a/cli/node/mod.rs b/cli/node/mod.rs index 8f0f0ef6dc..fc4db33ee2 100644 --- a/cli/node/mod.rs +++ b/cli/node/mod.rs @@ -703,20 +703,25 @@ pub fn url_to_node_resolution( npm_resolver: &dyn RequireNpmResolver, ) -> Result { let url_str = url.as_str().to_lowercase(); - Ok(if url_str.starts_with("http") { - NodeResolution::Esm(url) + if url_str.starts_with("http") { + Ok(NodeResolution::Esm(url)) } else if url_str.ends_with(".js") || url_str.ends_with(".d.ts") { let package_config = get_closest_package_json(&url, npm_resolver)?; if package_config.typ == "module" { - NodeResolution::Esm(url) + Ok(NodeResolution::Esm(url)) } else { - NodeResolution::CommonJs(url) + Ok(NodeResolution::CommonJs(url)) } } else if url_str.ends_with(".mjs") || url_str.ends_with(".d.mts") { - NodeResolution::Esm(url) + Ok(NodeResolution::Esm(url)) + } else if url_str.ends_with(".ts") { + Err(generic_error(format!( + "TypeScript files are not supported in npm packages: {}", + url + ))) } else { - NodeResolution::CommonJs(url) - }) + Ok(NodeResolution::CommonJs(url)) + } } fn finalize_resolution( diff --git a/cli/npm/resolution/mod.rs b/cli/npm/resolution/mod.rs index 4a8c2e8e17..15de4ceffa 100644 --- a/cli/npm/resolution/mod.rs +++ b/cli/npm/resolution/mod.rs @@ -10,7 +10,7 @@ use deno_core::parking_lot::RwLock; use serde::Deserialize; use serde::Serialize; -use crate::lockfile::Lockfile; +use crate::args::Lockfile; use self::graph::GraphDependencyResolver; use self::snapshot::NpmPackagesPartitioned; diff --git a/cli/npm/resolution/snapshot.rs b/cli/npm/resolution/snapshot.rs index d76ba8b1a6..738b68d21f 100644 --- a/cli/npm/resolution/snapshot.rs +++ b/cli/npm/resolution/snapshot.rs @@ -13,7 +13,7 @@ use deno_core::parking_lot::Mutex; use serde::Deserialize; use serde::Serialize; -use crate::lockfile::Lockfile; +use crate::args::Lockfile; use crate::npm::cache::should_sync_download; use crate::npm::cache::NpmPackageCacheFolderId; use crate::npm::registry::NpmPackageVersionDistInfo; diff --git a/cli/npm/resolvers/common.rs b/cli/npm/resolvers/common.rs index b160697d10..e3acef3f52 100644 --- a/cli/npm/resolvers/common.rs +++ b/cli/npm/resolvers/common.rs @@ -11,7 +11,7 @@ use deno_core::futures; use deno_core::futures::future::BoxFuture; use deno_core::url::Url; -use crate::lockfile::Lockfile; +use crate::args::Lockfile; use crate::npm::cache::should_sync_download; use crate::npm::resolution::NpmResolutionSnapshot; use crate::npm::NpmCache; diff --git a/cli/npm/resolvers/global.rs b/cli/npm/resolvers/global.rs index 3fad9f2d93..044c889d8f 100644 --- a/cli/npm/resolvers/global.rs +++ b/cli/npm/resolvers/global.rs @@ -15,8 +15,8 @@ use deno_core::url::Url; use deno_runtime::deno_node::PackageJson; use deno_runtime::deno_node::TYPES_CONDITIONS; +use crate::args::Lockfile; use crate::fs_util; -use crate::lockfile::Lockfile; use crate::npm::resolution::NpmResolution; use crate::npm::resolution::NpmResolutionSnapshot; use crate::npm::resolvers::common::cache_packages; diff --git a/cli/npm/resolvers/local.rs b/cli/npm/resolvers/local.rs index 0a47a7ff1e..a6df641d19 100644 --- a/cli/npm/resolvers/local.rs +++ b/cli/npm/resolvers/local.rs @@ -22,8 +22,8 @@ use deno_runtime::deno_node::PackageJson; use deno_runtime::deno_node::TYPES_CONDITIONS; use tokio::task::JoinHandle; +use crate::args::Lockfile; use crate::fs_util; -use crate::lockfile::Lockfile; use crate::npm::cache::mixed_case_package_name_encode; use crate::npm::cache::should_sync_download; use crate::npm::cache::NpmPackageCacheFolderId; diff --git a/cli/npm/resolvers/mod.rs b/cli/npm/resolvers/mod.rs index 23cbde5d9c..869874c8b6 100644 --- a/cli/npm/resolvers/mod.rs +++ b/cli/npm/resolvers/mod.rs @@ -22,8 +22,8 @@ use std::path::Path; use std::path::PathBuf; use std::sync::Arc; +use crate::args::Lockfile; use crate::fs_util; -use crate::lockfile::Lockfile; use self::common::InnerNpmPackageResolver; use self::local::LocalNpmPackageResolver; diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 2064d38511..019b6e4473 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -3,6 +3,9 @@ use crate::args::CliOptions; use crate::args::DenoSubcommand; use crate::args::Flags; +use crate::args::Lockfile; +use crate::args::TsConfigType; +use crate::args::TsTypeLib; use crate::args::TypeCheckMode; use crate::cache; use crate::cache::EmitCache; @@ -12,16 +15,12 @@ use crate::cache::ParsedSourceCache; use crate::cache::TypeCheckCache; use crate::deno_dir; use crate::emit::emit_parsed_source; -use crate::emit::TsConfigType; -use crate::emit::TsTypeLib; use crate::file_fetcher::FileFetcher; use crate::graph_util::graph_lock_or_exit; use crate::graph_util::GraphData; use crate::graph_util::ModuleEntry; use crate::http_cache; use crate::http_util::HttpClient; -use crate::lockfile::as_maybe_locker; -use crate::lockfile::Lockfile; use crate::node; use crate::node::NodeResolution; use crate::npm::resolve_npm_package_reqs; @@ -330,7 +329,7 @@ impl ProcState { root_permissions.clone(), dynamic_permissions.clone(), ); - let maybe_locker = as_maybe_locker(self.lockfile.clone()); + let maybe_locker = Lockfile::as_maybe_locker(self.lockfile.clone()); let maybe_imports = self.options.to_maybe_imports()?; let maybe_resolver = self.maybe_resolver.as_ref().map(|r| r.as_graph_resolver()); @@ -640,7 +639,7 @@ impl ProcState { roots: Vec<(ModuleSpecifier, ModuleKind)>, loader: &mut dyn Loader, ) -> Result { - let maybe_locker = as_maybe_locker(self.lockfile.clone()); + let maybe_locker = Lockfile::as_maybe_locker(self.lockfile.clone()); let maybe_imports = self.options.to_maybe_imports()?; let maybe_cli_resolver = CliResolver::maybe_new( diff --git a/cli/resolver.rs b/cli/resolver.rs index c28d9df75c..a4c4439abd 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -8,7 +8,7 @@ use deno_graph::source::DEFAULT_JSX_IMPORT_SOURCE_MODULE; use import_map::ImportMap; use std::sync::Arc; -use crate::args::config_file::JsxImportSourceConfig; +use crate::args::JsxImportSourceConfig; /// A resolver that takes care of resolution, taking into account loaded /// import map, JSX settings. diff --git a/cli/tests/integration/check_tests.rs b/cli/tests/integration/check_tests.rs index 03a5c932c1..4b3e512c46 100644 --- a/cli/tests/integration/check_tests.rs +++ b/cli/tests/integration/check_tests.rs @@ -126,7 +126,7 @@ fn typecheck_declarations_ns() { let output = util::deno_cmd() .arg("test") .arg("--doc") - .arg(util::root_path().join("cli/dts/lib.deno.ns.d.ts")) + .arg(util::root_path().join("cli/tsc/dts/lib.deno.ns.d.ts")) .output() .unwrap(); println!("stdout: {}", String::from_utf8(output.stdout).unwrap()); @@ -140,7 +140,7 @@ fn typecheck_declarations_unstable() { .arg("test") .arg("--doc") .arg("--unstable") - .arg(util::root_path().join("cli/dts/lib.deno.unstable.d.ts")) + .arg(util::root_path().join("cli/tsc/dts/lib.deno.unstable.d.ts")) .output() .unwrap(); println!("stdout: {}", String::from_utf8(output.stdout).unwrap()); diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs index ea577d412e..288500ce44 100644 --- a/cli/tests/integration/npm_tests.rs +++ b/cli/tests/integration/npm_tests.rs @@ -314,6 +314,14 @@ itest!(types_no_types_entry { exit_code: 0, }); +itest!(typescript_file_in_package { + args: "run npm/typescript_file_in_package/main.ts", + output: "npm/typescript_file_in_package/main.out", + envs: env_vars(), + http_server: true, + exit_code: 1, +}); + #[test] fn parallel_downloading() { let (out, _err) = util::run_and_collect_output_with_args( diff --git a/cli/tests/testdata/npm/registry/@denotest/typescript-file/1.0.0/index.ts b/cli/tests/testdata/npm/registry/@denotest/typescript-file/1.0.0/index.ts new file mode 100644 index 0000000000..44b441a1e2 --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/typescript-file/1.0.0/index.ts @@ -0,0 +1,4 @@ +// this should not work because we don't support typescript files in npm packages +export function getValue(): 5 { + return 5; +} \ No newline at end of file diff --git a/cli/tests/testdata/npm/registry/@denotest/typescript-file/1.0.0/package.json b/cli/tests/testdata/npm/registry/@denotest/typescript-file/1.0.0/package.json new file mode 100644 index 0000000000..e899f4100a --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/typescript-file/1.0.0/package.json @@ -0,0 +1,5 @@ +{ + "name": "@denotest/typescript-file", + "version": "1.0.0", + "main": "./index.ts" +} diff --git a/cli/tests/testdata/npm/typescript_file_in_package/main.out b/cli/tests/testdata/npm/typescript_file_in_package/main.out new file mode 100644 index 0000000000..ba53f77255 --- /dev/null +++ b/cli/tests/testdata/npm/typescript_file_in_package/main.out @@ -0,0 +1,6 @@ +Download http://localhost:4545/npm/registry/@denotest/typescript-file +Download http://localhost:4545/npm/registry/@denotest/typescript-file/1.0.0.tgz +error: Could not resolve 'npm:@denotest/typescript-file'. + +Caused by: + TypeScript files are not supported in npm packages: file:///[WILDCARD]/@denotest/typescript-file/1.0.0/index.ts diff --git a/cli/tests/testdata/npm/typescript_file_in_package/main.ts b/cli/tests/testdata/npm/typescript_file_in_package/main.ts new file mode 100644 index 0000000000..aefc38ebe6 --- /dev/null +++ b/cli/tests/testdata/npm/typescript_file_in_package/main.ts @@ -0,0 +1,5 @@ +// We don't support typescript files in npm packages because we don't +// want to encourage people distributing npm packages that aren't JavaScript. +import { getValue } from "npm:@denotest/typescript-file"; + +console.log(getValue()); diff --git a/cli/tools/check.rs b/cli/tools/check.rs index 88c05e1308..cf3bf0a498 100644 --- a/cli/tools/check.rs +++ b/cli/tools/check.rs @@ -15,11 +15,11 @@ use crate::args::TsConfig; use crate::args::TypeCheckMode; use crate::cache::FastInsecureHasher; use crate::cache::TypeCheckCache; -use crate::diagnostics::Diagnostics; use crate::graph_util::GraphData; use crate::graph_util::ModuleEntry; use crate::npm::NpmPackageResolver; use crate::tsc; +use crate::tsc::Diagnostics; use crate::tsc::Stats; use crate::version; diff --git a/cli/tsc/README.md b/cli/tsc/README.md index e8287f3c09..657aa2b5a4 100644 --- a/cli/tsc/README.md +++ b/cli/tsc/README.md @@ -2,3 +2,33 @@ This directory contains the typescript compiler and a small compiler host for the runtime snapshot. + +## How to upgrade TypeScript. + +The files in this directory are mostly from the TypeScript repository. We +currently (unfortunately) have a rather manual process for upgrading TypeScript. +It works like this currently: + +1. Checkout denoland/TypeScript repo in a separate directory. +1. Add Microsoft/TypeScript as a remote and fetch its latest tags +1. Checkout a new branch based on this tag. +1. Cherry pick the custom commit we made in a previous release to the new one. +1. This commit has a "deno.ts" file in it. Read the instructions in it. +1. Copy typescript.js into Deno repo. +1. Copy d.ts files into dts directory. + +So that might look something like this: + +``` +git clone https://github.com/denoland/TypeScript.git +cd typescript +git remote add upstream https://github.com/Microsoft/TypeScript +git fetch upstream +git checkout v3.9.7 +git checkout -b branch_v3.9.7 +git cherry pick +npm install +gulp local +rsync lib/typescript.js ~/src/deno/cli/tsc/00_typescript.js +rsync --exclude=protocol.d.ts --exclude=tsserverlibrary.d.ts --exclude=typescriptServices.d.ts lib/*.d.ts ~/src/deno/cli/tsc/dts/ +``` diff --git a/cli/tsc/compiler.d.ts b/cli/tsc/compiler.d.ts index 62a1bbdd2b..47910bbad9 100644 --- a/cli/tsc/compiler.d.ts +++ b/cli/tsc/compiler.d.ts @@ -2,7 +2,7 @@ // Contains types that can be used to validate and check `99_main_compiler.js` -import * as _ts from "../dts/typescript"; +import * as _ts from "./dts/typescript"; declare global { namespace ts { diff --git a/cli/diagnostics.rs b/cli/tsc/diagnostics.rs similarity index 100% rename from cli/diagnostics.rs rename to cli/tsc/diagnostics.rs diff --git a/cli/dts/lib.d.ts b/cli/tsc/dts/lib.d.ts similarity index 100% rename from cli/dts/lib.d.ts rename to cli/tsc/dts/lib.d.ts diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/tsc/dts/lib.deno.ns.d.ts similarity index 100% rename from cli/dts/lib.deno.ns.d.ts rename to cli/tsc/dts/lib.deno.ns.d.ts diff --git a/cli/dts/lib.deno.shared_globals.d.ts b/cli/tsc/dts/lib.deno.shared_globals.d.ts similarity index 100% rename from cli/dts/lib.deno.shared_globals.d.ts rename to cli/tsc/dts/lib.deno.shared_globals.d.ts diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/tsc/dts/lib.deno.unstable.d.ts similarity index 100% rename from cli/dts/lib.deno.unstable.d.ts rename to cli/tsc/dts/lib.deno.unstable.d.ts diff --git a/cli/dts/lib.deno.window.d.ts b/cli/tsc/dts/lib.deno.window.d.ts similarity index 100% rename from cli/dts/lib.deno.window.d.ts rename to cli/tsc/dts/lib.deno.window.d.ts diff --git a/cli/dts/lib.deno.worker.d.ts b/cli/tsc/dts/lib.deno.worker.d.ts similarity index 100% rename from cli/dts/lib.deno.worker.d.ts rename to cli/tsc/dts/lib.deno.worker.d.ts diff --git a/cli/dts/lib.deno_webgpu.d.ts b/cli/tsc/dts/lib.deno_webgpu.d.ts similarity index 100% rename from cli/dts/lib.deno_webgpu.d.ts rename to cli/tsc/dts/lib.deno_webgpu.d.ts diff --git a/cli/dts/lib.dom.asynciterable.d.ts b/cli/tsc/dts/lib.dom.asynciterable.d.ts similarity index 100% rename from cli/dts/lib.dom.asynciterable.d.ts rename to cli/tsc/dts/lib.dom.asynciterable.d.ts diff --git a/cli/dts/lib.dom.d.ts b/cli/tsc/dts/lib.dom.d.ts similarity index 100% rename from cli/dts/lib.dom.d.ts rename to cli/tsc/dts/lib.dom.d.ts diff --git a/cli/dts/lib.dom.extras.d.ts b/cli/tsc/dts/lib.dom.extras.d.ts similarity index 100% rename from cli/dts/lib.dom.extras.d.ts rename to cli/tsc/dts/lib.dom.extras.d.ts diff --git a/cli/dts/lib.dom.iterable.d.ts b/cli/tsc/dts/lib.dom.iterable.d.ts similarity index 100% rename from cli/dts/lib.dom.iterable.d.ts rename to cli/tsc/dts/lib.dom.iterable.d.ts diff --git a/cli/dts/lib.es2015.collection.d.ts b/cli/tsc/dts/lib.es2015.collection.d.ts similarity index 100% rename from cli/dts/lib.es2015.collection.d.ts rename to cli/tsc/dts/lib.es2015.collection.d.ts diff --git a/cli/dts/lib.es2015.core.d.ts b/cli/tsc/dts/lib.es2015.core.d.ts similarity index 100% rename from cli/dts/lib.es2015.core.d.ts rename to cli/tsc/dts/lib.es2015.core.d.ts diff --git a/cli/dts/lib.es2015.d.ts b/cli/tsc/dts/lib.es2015.d.ts similarity index 100% rename from cli/dts/lib.es2015.d.ts rename to cli/tsc/dts/lib.es2015.d.ts diff --git a/cli/dts/lib.es2015.generator.d.ts b/cli/tsc/dts/lib.es2015.generator.d.ts similarity index 100% rename from cli/dts/lib.es2015.generator.d.ts rename to cli/tsc/dts/lib.es2015.generator.d.ts diff --git a/cli/dts/lib.es2015.iterable.d.ts b/cli/tsc/dts/lib.es2015.iterable.d.ts similarity index 100% rename from cli/dts/lib.es2015.iterable.d.ts rename to cli/tsc/dts/lib.es2015.iterable.d.ts diff --git a/cli/dts/lib.es2015.promise.d.ts b/cli/tsc/dts/lib.es2015.promise.d.ts similarity index 100% rename from cli/dts/lib.es2015.promise.d.ts rename to cli/tsc/dts/lib.es2015.promise.d.ts diff --git a/cli/dts/lib.es2015.proxy.d.ts b/cli/tsc/dts/lib.es2015.proxy.d.ts similarity index 100% rename from cli/dts/lib.es2015.proxy.d.ts rename to cli/tsc/dts/lib.es2015.proxy.d.ts diff --git a/cli/dts/lib.es2015.reflect.d.ts b/cli/tsc/dts/lib.es2015.reflect.d.ts similarity index 100% rename from cli/dts/lib.es2015.reflect.d.ts rename to cli/tsc/dts/lib.es2015.reflect.d.ts diff --git a/cli/dts/lib.es2015.symbol.d.ts b/cli/tsc/dts/lib.es2015.symbol.d.ts similarity index 100% rename from cli/dts/lib.es2015.symbol.d.ts rename to cli/tsc/dts/lib.es2015.symbol.d.ts diff --git a/cli/dts/lib.es2015.symbol.wellknown.d.ts b/cli/tsc/dts/lib.es2015.symbol.wellknown.d.ts similarity index 100% rename from cli/dts/lib.es2015.symbol.wellknown.d.ts rename to cli/tsc/dts/lib.es2015.symbol.wellknown.d.ts diff --git a/cli/dts/lib.es2016.array.include.d.ts b/cli/tsc/dts/lib.es2016.array.include.d.ts similarity index 100% rename from cli/dts/lib.es2016.array.include.d.ts rename to cli/tsc/dts/lib.es2016.array.include.d.ts diff --git a/cli/dts/lib.es2016.d.ts b/cli/tsc/dts/lib.es2016.d.ts similarity index 100% rename from cli/dts/lib.es2016.d.ts rename to cli/tsc/dts/lib.es2016.d.ts diff --git a/cli/dts/lib.es2016.full.d.ts b/cli/tsc/dts/lib.es2016.full.d.ts similarity index 100% rename from cli/dts/lib.es2016.full.d.ts rename to cli/tsc/dts/lib.es2016.full.d.ts diff --git a/cli/dts/lib.es2017.d.ts b/cli/tsc/dts/lib.es2017.d.ts similarity index 100% rename from cli/dts/lib.es2017.d.ts rename to cli/tsc/dts/lib.es2017.d.ts diff --git a/cli/dts/lib.es2017.full.d.ts b/cli/tsc/dts/lib.es2017.full.d.ts similarity index 100% rename from cli/dts/lib.es2017.full.d.ts rename to cli/tsc/dts/lib.es2017.full.d.ts diff --git a/cli/dts/lib.es2017.intl.d.ts b/cli/tsc/dts/lib.es2017.intl.d.ts similarity index 100% rename from cli/dts/lib.es2017.intl.d.ts rename to cli/tsc/dts/lib.es2017.intl.d.ts diff --git a/cli/dts/lib.es2017.object.d.ts b/cli/tsc/dts/lib.es2017.object.d.ts similarity index 100% rename from cli/dts/lib.es2017.object.d.ts rename to cli/tsc/dts/lib.es2017.object.d.ts diff --git a/cli/dts/lib.es2017.sharedmemory.d.ts b/cli/tsc/dts/lib.es2017.sharedmemory.d.ts similarity index 100% rename from cli/dts/lib.es2017.sharedmemory.d.ts rename to cli/tsc/dts/lib.es2017.sharedmemory.d.ts diff --git a/cli/dts/lib.es2017.string.d.ts b/cli/tsc/dts/lib.es2017.string.d.ts similarity index 100% rename from cli/dts/lib.es2017.string.d.ts rename to cli/tsc/dts/lib.es2017.string.d.ts diff --git a/cli/dts/lib.es2017.typedarrays.d.ts b/cli/tsc/dts/lib.es2017.typedarrays.d.ts similarity index 100% rename from cli/dts/lib.es2017.typedarrays.d.ts rename to cli/tsc/dts/lib.es2017.typedarrays.d.ts diff --git a/cli/dts/lib.es2018.asyncgenerator.d.ts b/cli/tsc/dts/lib.es2018.asyncgenerator.d.ts similarity index 100% rename from cli/dts/lib.es2018.asyncgenerator.d.ts rename to cli/tsc/dts/lib.es2018.asyncgenerator.d.ts diff --git a/cli/dts/lib.es2018.asynciterable.d.ts b/cli/tsc/dts/lib.es2018.asynciterable.d.ts similarity index 100% rename from cli/dts/lib.es2018.asynciterable.d.ts rename to cli/tsc/dts/lib.es2018.asynciterable.d.ts diff --git a/cli/dts/lib.es2018.d.ts b/cli/tsc/dts/lib.es2018.d.ts similarity index 100% rename from cli/dts/lib.es2018.d.ts rename to cli/tsc/dts/lib.es2018.d.ts diff --git a/cli/dts/lib.es2018.full.d.ts b/cli/tsc/dts/lib.es2018.full.d.ts similarity index 100% rename from cli/dts/lib.es2018.full.d.ts rename to cli/tsc/dts/lib.es2018.full.d.ts diff --git a/cli/dts/lib.es2018.intl.d.ts b/cli/tsc/dts/lib.es2018.intl.d.ts similarity index 100% rename from cli/dts/lib.es2018.intl.d.ts rename to cli/tsc/dts/lib.es2018.intl.d.ts diff --git a/cli/dts/lib.es2018.promise.d.ts b/cli/tsc/dts/lib.es2018.promise.d.ts similarity index 100% rename from cli/dts/lib.es2018.promise.d.ts rename to cli/tsc/dts/lib.es2018.promise.d.ts diff --git a/cli/dts/lib.es2018.regexp.d.ts b/cli/tsc/dts/lib.es2018.regexp.d.ts similarity index 100% rename from cli/dts/lib.es2018.regexp.d.ts rename to cli/tsc/dts/lib.es2018.regexp.d.ts diff --git a/cli/dts/lib.es2019.array.d.ts b/cli/tsc/dts/lib.es2019.array.d.ts similarity index 100% rename from cli/dts/lib.es2019.array.d.ts rename to cli/tsc/dts/lib.es2019.array.d.ts diff --git a/cli/dts/lib.es2019.d.ts b/cli/tsc/dts/lib.es2019.d.ts similarity index 100% rename from cli/dts/lib.es2019.d.ts rename to cli/tsc/dts/lib.es2019.d.ts diff --git a/cli/dts/lib.es2019.full.d.ts b/cli/tsc/dts/lib.es2019.full.d.ts similarity index 100% rename from cli/dts/lib.es2019.full.d.ts rename to cli/tsc/dts/lib.es2019.full.d.ts diff --git a/cli/dts/lib.es2019.object.d.ts b/cli/tsc/dts/lib.es2019.object.d.ts similarity index 100% rename from cli/dts/lib.es2019.object.d.ts rename to cli/tsc/dts/lib.es2019.object.d.ts diff --git a/cli/dts/lib.es2019.string.d.ts b/cli/tsc/dts/lib.es2019.string.d.ts similarity index 100% rename from cli/dts/lib.es2019.string.d.ts rename to cli/tsc/dts/lib.es2019.string.d.ts diff --git a/cli/dts/lib.es2019.symbol.d.ts b/cli/tsc/dts/lib.es2019.symbol.d.ts similarity index 100% rename from cli/dts/lib.es2019.symbol.d.ts rename to cli/tsc/dts/lib.es2019.symbol.d.ts diff --git a/cli/dts/lib.es2020.bigint.d.ts b/cli/tsc/dts/lib.es2020.bigint.d.ts similarity index 100% rename from cli/dts/lib.es2020.bigint.d.ts rename to cli/tsc/dts/lib.es2020.bigint.d.ts diff --git a/cli/dts/lib.es2020.d.ts b/cli/tsc/dts/lib.es2020.d.ts similarity index 100% rename from cli/dts/lib.es2020.d.ts rename to cli/tsc/dts/lib.es2020.d.ts diff --git a/cli/dts/lib.es2020.date.d.ts b/cli/tsc/dts/lib.es2020.date.d.ts similarity index 100% rename from cli/dts/lib.es2020.date.d.ts rename to cli/tsc/dts/lib.es2020.date.d.ts diff --git a/cli/dts/lib.es2020.full.d.ts b/cli/tsc/dts/lib.es2020.full.d.ts similarity index 100% rename from cli/dts/lib.es2020.full.d.ts rename to cli/tsc/dts/lib.es2020.full.d.ts diff --git a/cli/dts/lib.es2020.intl.d.ts b/cli/tsc/dts/lib.es2020.intl.d.ts similarity index 100% rename from cli/dts/lib.es2020.intl.d.ts rename to cli/tsc/dts/lib.es2020.intl.d.ts diff --git a/cli/dts/lib.es2020.number.d.ts b/cli/tsc/dts/lib.es2020.number.d.ts similarity index 100% rename from cli/dts/lib.es2020.number.d.ts rename to cli/tsc/dts/lib.es2020.number.d.ts diff --git a/cli/dts/lib.es2020.promise.d.ts b/cli/tsc/dts/lib.es2020.promise.d.ts similarity index 100% rename from cli/dts/lib.es2020.promise.d.ts rename to cli/tsc/dts/lib.es2020.promise.d.ts diff --git a/cli/dts/lib.es2020.sharedmemory.d.ts b/cli/tsc/dts/lib.es2020.sharedmemory.d.ts similarity index 100% rename from cli/dts/lib.es2020.sharedmemory.d.ts rename to cli/tsc/dts/lib.es2020.sharedmemory.d.ts diff --git a/cli/dts/lib.es2020.string.d.ts b/cli/tsc/dts/lib.es2020.string.d.ts similarity index 100% rename from cli/dts/lib.es2020.string.d.ts rename to cli/tsc/dts/lib.es2020.string.d.ts diff --git a/cli/dts/lib.es2020.symbol.wellknown.d.ts b/cli/tsc/dts/lib.es2020.symbol.wellknown.d.ts similarity index 100% rename from cli/dts/lib.es2020.symbol.wellknown.d.ts rename to cli/tsc/dts/lib.es2020.symbol.wellknown.d.ts diff --git a/cli/dts/lib.es2021.d.ts b/cli/tsc/dts/lib.es2021.d.ts similarity index 100% rename from cli/dts/lib.es2021.d.ts rename to cli/tsc/dts/lib.es2021.d.ts diff --git a/cli/dts/lib.es2021.full.d.ts b/cli/tsc/dts/lib.es2021.full.d.ts similarity index 100% rename from cli/dts/lib.es2021.full.d.ts rename to cli/tsc/dts/lib.es2021.full.d.ts diff --git a/cli/dts/lib.es2021.intl.d.ts b/cli/tsc/dts/lib.es2021.intl.d.ts similarity index 100% rename from cli/dts/lib.es2021.intl.d.ts rename to cli/tsc/dts/lib.es2021.intl.d.ts diff --git a/cli/dts/lib.es2021.promise.d.ts b/cli/tsc/dts/lib.es2021.promise.d.ts similarity index 100% rename from cli/dts/lib.es2021.promise.d.ts rename to cli/tsc/dts/lib.es2021.promise.d.ts diff --git a/cli/dts/lib.es2021.string.d.ts b/cli/tsc/dts/lib.es2021.string.d.ts similarity index 100% rename from cli/dts/lib.es2021.string.d.ts rename to cli/tsc/dts/lib.es2021.string.d.ts diff --git a/cli/dts/lib.es2021.weakref.d.ts b/cli/tsc/dts/lib.es2021.weakref.d.ts similarity index 100% rename from cli/dts/lib.es2021.weakref.d.ts rename to cli/tsc/dts/lib.es2021.weakref.d.ts diff --git a/cli/dts/lib.es2022.array.d.ts b/cli/tsc/dts/lib.es2022.array.d.ts similarity index 100% rename from cli/dts/lib.es2022.array.d.ts rename to cli/tsc/dts/lib.es2022.array.d.ts diff --git a/cli/dts/lib.es2022.d.ts b/cli/tsc/dts/lib.es2022.d.ts similarity index 100% rename from cli/dts/lib.es2022.d.ts rename to cli/tsc/dts/lib.es2022.d.ts diff --git a/cli/dts/lib.es2022.error.d.ts b/cli/tsc/dts/lib.es2022.error.d.ts similarity index 100% rename from cli/dts/lib.es2022.error.d.ts rename to cli/tsc/dts/lib.es2022.error.d.ts diff --git a/cli/dts/lib.es2022.full.d.ts b/cli/tsc/dts/lib.es2022.full.d.ts similarity index 100% rename from cli/dts/lib.es2022.full.d.ts rename to cli/tsc/dts/lib.es2022.full.d.ts diff --git a/cli/dts/lib.es2022.intl.d.ts b/cli/tsc/dts/lib.es2022.intl.d.ts similarity index 100% rename from cli/dts/lib.es2022.intl.d.ts rename to cli/tsc/dts/lib.es2022.intl.d.ts diff --git a/cli/dts/lib.es2022.object.d.ts b/cli/tsc/dts/lib.es2022.object.d.ts similarity index 100% rename from cli/dts/lib.es2022.object.d.ts rename to cli/tsc/dts/lib.es2022.object.d.ts diff --git a/cli/dts/lib.es2022.sharedmemory.d.ts b/cli/tsc/dts/lib.es2022.sharedmemory.d.ts similarity index 100% rename from cli/dts/lib.es2022.sharedmemory.d.ts rename to cli/tsc/dts/lib.es2022.sharedmemory.d.ts diff --git a/cli/dts/lib.es2022.string.d.ts b/cli/tsc/dts/lib.es2022.string.d.ts similarity index 100% rename from cli/dts/lib.es2022.string.d.ts rename to cli/tsc/dts/lib.es2022.string.d.ts diff --git a/cli/dts/lib.es5.d.ts b/cli/tsc/dts/lib.es5.d.ts similarity index 100% rename from cli/dts/lib.es5.d.ts rename to cli/tsc/dts/lib.es5.d.ts diff --git a/cli/dts/lib.es6.d.ts b/cli/tsc/dts/lib.es6.d.ts similarity index 100% rename from cli/dts/lib.es6.d.ts rename to cli/tsc/dts/lib.es6.d.ts diff --git a/cli/dts/lib.esnext.array.d.ts b/cli/tsc/dts/lib.esnext.array.d.ts similarity index 100% rename from cli/dts/lib.esnext.array.d.ts rename to cli/tsc/dts/lib.esnext.array.d.ts diff --git a/cli/dts/lib.esnext.d.ts b/cli/tsc/dts/lib.esnext.d.ts similarity index 100% rename from cli/dts/lib.esnext.d.ts rename to cli/tsc/dts/lib.esnext.d.ts diff --git a/cli/dts/lib.esnext.full.d.ts b/cli/tsc/dts/lib.esnext.full.d.ts similarity index 100% rename from cli/dts/lib.esnext.full.d.ts rename to cli/tsc/dts/lib.esnext.full.d.ts diff --git a/cli/dts/lib.esnext.intl.d.ts b/cli/tsc/dts/lib.esnext.intl.d.ts similarity index 100% rename from cli/dts/lib.esnext.intl.d.ts rename to cli/tsc/dts/lib.esnext.intl.d.ts diff --git a/cli/dts/lib.scripthost.d.ts b/cli/tsc/dts/lib.scripthost.d.ts similarity index 100% rename from cli/dts/lib.scripthost.d.ts rename to cli/tsc/dts/lib.scripthost.d.ts diff --git a/cli/dts/lib.webworker.d.ts b/cli/tsc/dts/lib.webworker.d.ts similarity index 100% rename from cli/dts/lib.webworker.d.ts rename to cli/tsc/dts/lib.webworker.d.ts diff --git a/cli/dts/lib.webworker.importscripts.d.ts b/cli/tsc/dts/lib.webworker.importscripts.d.ts similarity index 100% rename from cli/dts/lib.webworker.importscripts.d.ts rename to cli/tsc/dts/lib.webworker.importscripts.d.ts diff --git a/cli/dts/lib.webworker.iterable.d.ts b/cli/tsc/dts/lib.webworker.iterable.d.ts similarity index 100% rename from cli/dts/lib.webworker.iterable.d.ts rename to cli/tsc/dts/lib.webworker.iterable.d.ts diff --git a/cli/dts/typescript.d.ts b/cli/tsc/dts/typescript.d.ts similarity index 100% rename from cli/dts/typescript.d.ts rename to cli/tsc/dts/typescript.d.ts diff --git a/cli/tsc.rs b/cli/tsc/mod.rs similarity index 99% rename from cli/tsc.rs rename to cli/tsc/mod.rs index 766bf09e38..a8cb7bcabc 100644 --- a/cli/tsc.rs +++ b/cli/tsc/mod.rs @@ -1,7 +1,6 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::args::TsConfig; -use crate::diagnostics::Diagnostics; use crate::graph_util::GraphData; use crate::graph_util::ModuleEntry; use crate::node; @@ -40,6 +39,14 @@ use std::fmt; use std::path::PathBuf; use std::sync::Arc; +mod diagnostics; + +pub use self::diagnostics::Diagnostic; +pub use self::diagnostics::DiagnosticCategory; +pub use self::diagnostics::DiagnosticMessageChain; +pub use self::diagnostics::Diagnostics; +pub use self::diagnostics::Position; + // Declaration files pub static DENO_NS_LIB: &str = include_str!("dts/lib.deno.ns.d.ts"); @@ -85,7 +92,7 @@ pub fn compiler_snapshot() -> Snapshot { macro_rules! inc { ($e:expr) => { - include_str!(concat!("dts/", $e)) + include_str!(concat!("./dts/", $e)) }; } @@ -797,10 +804,10 @@ pub fn exec(request: Request) -> Result { #[cfg(test)] mod tests { + use super::Diagnostic; + use super::DiagnosticCategory; use super::*; use crate::args::TsConfig; - use crate::diagnostics::Diagnostic; - use crate::diagnostics::DiagnosticCategory; use deno_core::futures::future; use deno_core::OpState; use deno_graph::ModuleKind; diff --git a/tools/lint.js b/tools/lint.js index 45c94abdf3..4e842c2b95 100755 --- a/tools/lint.js +++ b/tools/lint.js @@ -24,7 +24,7 @@ async function dlint() { ":!:cli/bench/testdata/express-router.js", ":!:cli/bench/testdata/react-dom.js", ":!:cli/compilers/wasm_wrap.js", - ":!:cli/dts/**", + ":!:cli/tsc/dts/**", ":!:cli/tests/testdata/encoding/**", ":!:cli/tests/testdata/error_syntax.js", ":!:cli/tests/testdata/fmt/**",