mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 04:52:26 -05:00
Merge remote-tracking branch 'upstream/main' into check-workspace-member-compiler-options
This commit is contained in:
commit
b71605088a
947 changed files with 2346 additions and 6990 deletions
202
Cargo.lock
generated
202
Cargo.lock
generated
|
@ -128,19 +128,6 @@ version = "0.2.18"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f"
|
||||
|
||||
[[package]]
|
||||
name = "ammonia"
|
||||
version = "4.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ab99eae5ee58501ab236beb6f20f6ca39be615267b014899c89b2f0bc18a459"
|
||||
dependencies = [
|
||||
"html5ever",
|
||||
"maplit",
|
||||
"once_cell",
|
||||
"tendril",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "android_system_properties"
|
||||
version = "0.1.5"
|
||||
|
@ -407,6 +394,12 @@ dependencies = [
|
|||
"tower-service",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "az"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973"
|
||||
|
||||
[[package]]
|
||||
name = "backtrace"
|
||||
version = "0.3.73"
|
||||
|
@ -1233,6 +1226,7 @@ dependencies = [
|
|||
"deno_runtime",
|
||||
"deno_semver",
|
||||
"deno_task_shell",
|
||||
"deno_telemetry",
|
||||
"deno_terminal 0.2.0",
|
||||
"deno_tower_lsp",
|
||||
"dhat",
|
||||
|
@ -1466,11 +1460,12 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "deno_core"
|
||||
version = "0.322.0"
|
||||
version = "0.323.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f593ef2b8acab8cd3ace9d50052edc65a3654fdbde808070cfa5da5cf7aaae6"
|
||||
checksum = "a781bcfe1b5211b8497f45bf5b3dba73036b8d5d1533c1f05d26ccf0afb25a78"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"az",
|
||||
"bincode",
|
||||
"bit-set",
|
||||
"bit-vec",
|
||||
|
@ -1556,18 +1551,16 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "deno_doc"
|
||||
version = "0.160.0"
|
||||
version = "0.161.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "db2baa33e5d1ed235209c2990f5fe9644bac6b9e7bcb789dd92894f907b09ad7"
|
||||
checksum = "32d994915f85e873865fc341e592080a487b0a987d06177016b2d93fd62162f8"
|
||||
dependencies = [
|
||||
"ammonia",
|
||||
"anyhow",
|
||||
"cfg-if",
|
||||
"comrak",
|
||||
"deno_ast",
|
||||
"deno_graph",
|
||||
"deno_path_util",
|
||||
"futures",
|
||||
"handlebars",
|
||||
"html-escape",
|
||||
"import_map",
|
||||
|
@ -1664,9 +1657,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "deno_graph"
|
||||
version = "0.85.1"
|
||||
version = "0.86.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c11027d9b4e9ff4f8bcb8316a1a5dd5241dc267380507e177457bc491696189"
|
||||
checksum = "4c3f4be49dad28e794ff4eeb2daaf7956c97f8557097ef6f9c3ff1292e0a5c28"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
|
@ -1983,9 +1976,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "deno_ops"
|
||||
version = "0.198.0"
|
||||
version = "0.199.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "870826735cd9aa0376d2aadca14365b753e830e3cc16891efb9232845a6982a4"
|
||||
checksum = "a24a1f3e22029a57d3094b32070b8328eac793920b5a022027d360f085e6b245"
|
||||
dependencies = [
|
||||
"proc-macro-rules",
|
||||
"proc-macro2",
|
||||
|
@ -2063,7 +2056,6 @@ dependencies = [
|
|||
name = "deno_runtime"
|
||||
version = "0.188.0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"color-print",
|
||||
"deno_ast",
|
||||
"deno_broadcast_channel",
|
||||
|
@ -2084,6 +2076,7 @@ dependencies = [
|
|||
"deno_node",
|
||||
"deno_path_util",
|
||||
"deno_permissions",
|
||||
"deno_telemetry",
|
||||
"deno_terminal 0.2.0",
|
||||
"deno_tls",
|
||||
"deno_url",
|
||||
|
@ -2109,13 +2102,7 @@ dependencies = [
|
|||
"notify",
|
||||
"ntapi",
|
||||
"once_cell",
|
||||
"opentelemetry",
|
||||
"opentelemetry-http",
|
||||
"opentelemetry-otlp",
|
||||
"opentelemetry-semantic-conventions",
|
||||
"opentelemetry_sdk",
|
||||
"percent-encoding",
|
||||
"pin-project",
|
||||
"regex",
|
||||
"rustyline",
|
||||
"same-file",
|
||||
|
@ -2164,6 +2151,27 @@ dependencies = [
|
|||
"tokio-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "deno_telemetry"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"deno_core",
|
||||
"http-body-util",
|
||||
"hyper 1.4.1",
|
||||
"hyper-util",
|
||||
"log",
|
||||
"once_cell",
|
||||
"opentelemetry",
|
||||
"opentelemetry-http",
|
||||
"opentelemetry-otlp",
|
||||
"opentelemetry-semantic-conventions",
|
||||
"opentelemetry_sdk",
|
||||
"pin-project",
|
||||
"serde",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "deno_terminal"
|
||||
version = "0.1.1"
|
||||
|
@ -3249,16 +3257,6 @@ version = "2.0.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
|
||||
|
||||
[[package]]
|
||||
name = "futf"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843"
|
||||
dependencies = [
|
||||
"mac",
|
||||
"new_debug_unreachable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures"
|
||||
version = "0.3.30"
|
||||
|
@ -3786,20 +3784,6 @@ dependencies = [
|
|||
"utf8-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "html5ever"
|
||||
version = "0.27.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4"
|
||||
dependencies = [
|
||||
"log",
|
||||
"mac",
|
||||
"markup5ever",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "0.2.12"
|
||||
|
@ -4647,12 +4631,6 @@ dependencies = [
|
|||
"serde_repr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mac"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4"
|
||||
|
||||
[[package]]
|
||||
name = "malloc_buf"
|
||||
version = "0.0.6"
|
||||
|
@ -4675,26 +4653,6 @@ dependencies = [
|
|||
"tiny_pretty",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "maplit"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
|
||||
|
||||
[[package]]
|
||||
name = "markup5ever"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45"
|
||||
dependencies = [
|
||||
"log",
|
||||
"phf",
|
||||
"phf_codegen",
|
||||
"string_cache",
|
||||
"string_cache_codegen",
|
||||
"tendril",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "markup_fmt"
|
||||
version = "0.16.0"
|
||||
|
@ -5452,27 +5410,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc"
|
||||
dependencies = [
|
||||
"phf_macros",
|
||||
"phf_shared 0.11.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_codegen"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a"
|
||||
dependencies = [
|
||||
"phf_generator 0.11.2",
|
||||
"phf_shared 0.11.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_generator"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6"
|
||||
dependencies = [
|
||||
"phf_shared 0.10.0",
|
||||
"rand",
|
||||
"phf_shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -5481,7 +5419,7 @@ version = "0.11.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0"
|
||||
dependencies = [
|
||||
"phf_shared 0.11.2",
|
||||
"phf_shared",
|
||||
"rand",
|
||||
]
|
||||
|
||||
|
@ -5491,22 +5429,13 @@ version = "0.11.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b"
|
||||
dependencies = [
|
||||
"phf_generator 0.11.2",
|
||||
"phf_shared 0.11.2",
|
||||
"phf_generator",
|
||||
"phf_shared",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_shared"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096"
|
||||
dependencies = [
|
||||
"siphasher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_shared"
|
||||
version = "0.11.2"
|
||||
|
@ -5629,12 +5558,6 @@ version = "0.2.17"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "precomputed-hash"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
|
||||
|
||||
[[package]]
|
||||
name = "pretty_assertions"
|
||||
version = "1.4.0"
|
||||
|
@ -6654,9 +6577,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde_v8"
|
||||
version = "0.231.0"
|
||||
version = "0.232.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a0c48b8842ebae21c52da1d978fba5c2be5991680bddfdc1a36ee0ccbc60114"
|
||||
checksum = "5c9feae92f7293fcc1a32a86be1a399859c0637e55dad8991d5258c43f7ff4d2"
|
||||
dependencies = [
|
||||
"num-bigint",
|
||||
"serde",
|
||||
|
@ -6969,32 +6892,6 @@ version = "1.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||
|
||||
[[package]]
|
||||
name = "string_cache"
|
||||
version = "0.8.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b"
|
||||
dependencies = [
|
||||
"new_debug_unreachable",
|
||||
"once_cell",
|
||||
"parking_lot",
|
||||
"phf_shared 0.10.0",
|
||||
"precomputed-hash",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "string_cache_codegen"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988"
|
||||
dependencies = [
|
||||
"phf_generator 0.10.0",
|
||||
"phf_shared 0.10.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "string_enum"
|
||||
version = "0.4.4"
|
||||
|
@ -7582,17 +7479,6 @@ dependencies = [
|
|||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tendril"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0"
|
||||
dependencies = [
|
||||
"futf",
|
||||
"mac",
|
||||
"utf-8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.4.1"
|
||||
|
|
|
@ -21,6 +21,7 @@ members = [
|
|||
"ext/napi/sym",
|
||||
"ext/net",
|
||||
"ext/node",
|
||||
"ext/telemetry",
|
||||
"ext/url",
|
||||
"ext/web",
|
||||
"ext/webgpu",
|
||||
|
@ -46,7 +47,7 @@ repository = "https://github.com/denoland/deno"
|
|||
|
||||
[workspace.dependencies]
|
||||
deno_ast = { version = "=0.43.3", features = ["transpiling"] }
|
||||
deno_core = { version = "0.322.0" }
|
||||
deno_core = { version = "0.323.0" }
|
||||
|
||||
deno_bench_util = { version = "0.173.0", path = "./bench_util" }
|
||||
deno_config = { version = "=0.39.2", features = ["workspace", "sync"] }
|
||||
|
@ -82,6 +83,7 @@ deno_kv = { version = "0.87.0", path = "./ext/kv" }
|
|||
deno_napi = { version = "0.110.0", path = "./ext/napi" }
|
||||
deno_net = { version = "0.171.0", path = "./ext/net" }
|
||||
deno_node = { version = "0.116.0", path = "./ext/node" }
|
||||
deno_telemetry = { version = "0.1.0", path = "./ext/telemetry" }
|
||||
deno_tls = { version = "0.166.0", path = "./ext/tls" }
|
||||
deno_url = { version = "0.179.0", path = "./ext/url" }
|
||||
deno_web = { version = "0.210.0", path = "./ext/web" }
|
||||
|
|
|
@ -72,8 +72,8 @@ deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "proposa
|
|||
deno_cache_dir.workspace = true
|
||||
deno_config.workspace = true
|
||||
deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] }
|
||||
deno_doc = { version = "0.160.0", features = ["rust", "comrak"] }
|
||||
deno_graph = { version = "=0.85.1" }
|
||||
deno_doc = { version = "=0.161.1", features = ["rust", "comrak"] }
|
||||
deno_graph = { version = "=0.86.2" }
|
||||
deno_lint = { version = "=0.68.0", features = ["docs"] }
|
||||
deno_lockfile.workspace = true
|
||||
deno_npm.workspace = true
|
||||
|
@ -83,6 +83,7 @@ deno_resolver.workspace = true
|
|||
deno_runtime = { workspace = true, features = ["include_js_files_for_snapshotting"] }
|
||||
deno_semver.workspace = true
|
||||
deno_task_shell = "=0.18.1"
|
||||
deno_telemetry.workspace = true
|
||||
deno_terminal.workspace = true
|
||||
libsui = "0.5.0"
|
||||
node_resolver.workspace = true
|
||||
|
|
|
@ -36,7 +36,7 @@ use deno_path_util::normalize_path;
|
|||
use deno_path_util::url_to_file_path;
|
||||
use deno_runtime::deno_permissions::PermissionsOptions;
|
||||
use deno_runtime::deno_permissions::SysDescriptor;
|
||||
use deno_runtime::ops::otel::OtelConfig;
|
||||
use deno_telemetry::OtelConfig;
|
||||
use log::debug;
|
||||
use log::Level;
|
||||
use serde::Deserialize;
|
||||
|
@ -598,6 +598,7 @@ pub struct UnstableConfig {
|
|||
// TODO(bartlomieju): remove in Deno 2.5
|
||||
pub legacy_flag_enabled: bool, // --unstable
|
||||
pub bare_node_builtins: bool,
|
||||
pub detect_cjs: bool,
|
||||
pub sloppy_imports: bool,
|
||||
pub features: Vec<String>, // --unstabe-kv --unstable-cron
|
||||
}
|
||||
|
@ -2662,7 +2663,7 @@ By default, outdated dependencies are only displayed.
|
|||
Display outdated dependencies:
|
||||
<p(245)>deno outdated</>
|
||||
<p(245)>deno outdated --compatible</>
|
||||
|
||||
|
||||
Update dependencies:
|
||||
<p(245)>deno outdated --update</>
|
||||
<p(245)>deno outdated --update --latest</>
|
||||
|
@ -3047,7 +3048,7 @@ fn task_subcommand() -> Command {
|
|||
|
||||
List all available tasks:
|
||||
<p(245)>deno task</>
|
||||
|
||||
|
||||
Evaluate a task from string
|
||||
<p(245)>deno task --eval \"echo $(pwd)\"</>"
|
||||
),
|
||||
|
@ -4373,7 +4374,7 @@ impl CommandExt for Command {
|
|||
).arg(
|
||||
Arg::new("unstable-detect-cjs")
|
||||
.long("unstable-detect-cjs")
|
||||
.help("Reads the package.json type field in a project to treat .js files as .cjs")
|
||||
.help("Treats ambiguous .js, .jsx, .ts, .tsx files as CommonJS modules in more cases")
|
||||
.value_parser(FalseyValueParser::new())
|
||||
.action(ArgAction::SetTrue)
|
||||
.hide(true)
|
||||
|
@ -5986,6 +5987,7 @@ fn unstable_args_parse(
|
|||
|
||||
flags.unstable_config.bare_node_builtins =
|
||||
matches.get_flag("unstable-bare-node-builtins");
|
||||
flags.unstable_config.detect_cjs = matches.get_flag("unstable-detect-cjs");
|
||||
flags.unstable_config.sloppy_imports =
|
||||
matches.get_flag("unstable-sloppy-imports");
|
||||
|
||||
|
|
|
@ -28,8 +28,8 @@ use deno_npm::npm_rc::ResolvedNpmRc;
|
|||
use deno_npm::resolution::ValidSerializedNpmResolutionSnapshot;
|
||||
use deno_npm::NpmSystemInfo;
|
||||
use deno_path_util::normalize_path;
|
||||
use deno_runtime::ops::otel::OtelConfig;
|
||||
use deno_semver::npm::NpmPackageReqReference;
|
||||
use deno_telemetry::OtelConfig;
|
||||
use import_map::resolve_import_map_value_from_specifier;
|
||||
|
||||
pub use deno_config::deno_json::BenchConfig;
|
||||
|
@ -1620,6 +1620,11 @@ impl CliOptions {
|
|||
|| self.workspace().has_unstable("bare-node-builtins")
|
||||
}
|
||||
|
||||
pub fn unstable_detect_cjs(&self) -> bool {
|
||||
self.flags.unstable_config.detect_cjs
|
||||
|| self.workspace().has_unstable("detect-cjs")
|
||||
}
|
||||
|
||||
pub fn detect_cjs(&self) -> bool {
|
||||
// only enabled when there's a package.json in order to not have a
|
||||
// perf penalty for non-npm Deno projects of searching for the closest
|
||||
|
@ -1689,6 +1694,7 @@ impl CliOptions {
|
|||
"sloppy-imports",
|
||||
"byonm",
|
||||
"bare-node-builtins",
|
||||
"detect-cjs",
|
||||
"fmt-component",
|
||||
"fmt-sql",
|
||||
])
|
||||
|
|
24
cli/cache/module_info.rs
vendored
24
cli/cache/module_info.rs
vendored
|
@ -284,6 +284,7 @@ fn serialize_media_type(media_type: MediaType) -> i64 {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use deno_graph::JsDocImportInfo;
|
||||
use deno_graph::PositionRange;
|
||||
use deno_graph::SpecifierWithRange;
|
||||
|
||||
|
@ -308,18 +309,21 @@ mod test {
|
|||
);
|
||||
|
||||
let mut module_info = ModuleInfo::default();
|
||||
module_info.jsdoc_imports.push(SpecifierWithRange {
|
||||
range: PositionRange {
|
||||
start: deno_graph::Position {
|
||||
line: 0,
|
||||
character: 3,
|
||||
},
|
||||
end: deno_graph::Position {
|
||||
line: 1,
|
||||
character: 2,
|
||||
module_info.jsdoc_imports.push(JsDocImportInfo {
|
||||
specifier: SpecifierWithRange {
|
||||
range: PositionRange {
|
||||
start: deno_graph::Position {
|
||||
line: 0,
|
||||
character: 3,
|
||||
},
|
||||
end: deno_graph::Position {
|
||||
line: 1,
|
||||
character: 2,
|
||||
},
|
||||
},
|
||||
text: "test".to_string(),
|
||||
},
|
||||
text: "test".to_string(),
|
||||
resolution_mode: None,
|
||||
});
|
||||
cache
|
||||
.set_module_info(
|
||||
|
|
|
@ -48,7 +48,6 @@ use crate::resolver::CliNpmReqResolver;
|
|||
use crate::resolver::CliResolver;
|
||||
use crate::resolver::CliResolverOptions;
|
||||
use crate::resolver::CliSloppyImportsResolver;
|
||||
use crate::resolver::IsCjsResolverOptions;
|
||||
use crate::resolver::NpmModuleLoader;
|
||||
use crate::resolver::SloppyImportsCachedFs;
|
||||
use crate::standalone::DenoCompileBinaryWriter;
|
||||
|
@ -72,6 +71,7 @@ use deno_core::error::AnyError;
|
|||
use deno_core::futures::FutureExt;
|
||||
use deno_core::FeatureChecker;
|
||||
|
||||
use deno_resolver::cjs::IsCjsResolutionMode;
|
||||
use deno_resolver::npm::NpmReqResolverOptions;
|
||||
use deno_resolver::DenoResolverOptions;
|
||||
use deno_resolver::NodeAndNpmReqResolver;
|
||||
|
@ -845,9 +845,12 @@ impl CliFactory {
|
|||
Ok(Arc::new(CjsTracker::new(
|
||||
self.in_npm_pkg_checker()?.clone(),
|
||||
self.pkg_json_resolver().clone(),
|
||||
IsCjsResolverOptions {
|
||||
detect_cjs: options.detect_cjs(),
|
||||
is_node_main: options.is_node_main(),
|
||||
if options.is_node_main() || options.unstable_detect_cjs() {
|
||||
IsCjsResolutionMode::ImplicitTypeCommonJs
|
||||
} else if options.detect_cjs() {
|
||||
IsCjsResolutionMode::ExplicitTypeCommonJs
|
||||
} else {
|
||||
IsCjsResolutionMode::Disabled
|
||||
},
|
||||
)))
|
||||
})
|
||||
|
|
|
@ -25,7 +25,7 @@ use deno_config::deno_json::JsxImportSourceConfig;
|
|||
use deno_config::workspace::JsrPackageConfig;
|
||||
use deno_core::anyhow::bail;
|
||||
use deno_graph::source::LoaderChecksum;
|
||||
use deno_graph::source::ResolutionMode;
|
||||
use deno_graph::source::ResolutionKind;
|
||||
use deno_graph::FillFromLockfileOptions;
|
||||
use deno_graph::JsrLoadError;
|
||||
use deno_graph::ModuleLoadError;
|
||||
|
@ -44,7 +44,7 @@ use deno_graph::ModuleGraphError;
|
|||
use deno_graph::ResolutionError;
|
||||
use deno_graph::SpecifierError;
|
||||
use deno_path_util::url_to_file_path;
|
||||
use deno_resolver::sloppy_imports::SloppyImportsResolutionMode;
|
||||
use deno_resolver::sloppy_imports::SloppyImportsResolutionKind;
|
||||
use deno_runtime::deno_fs::FileSystem;
|
||||
use deno_runtime::deno_node;
|
||||
use deno_runtime::deno_permissions::PermissionsContainer;
|
||||
|
@ -796,7 +796,7 @@ fn enhanced_sloppy_imports_error_message(
|
|||
ModuleError::LoadingErr(specifier, _, ModuleLoadError::Loader(_)) // ex. "Is a directory" error
|
||||
| ModuleError::Missing(specifier, _) => {
|
||||
let additional_message = CliSloppyImportsResolver::new(SloppyImportsCachedFs::new(fs.clone()))
|
||||
.resolve(specifier, SloppyImportsResolutionMode::Execution)?
|
||||
.resolve(specifier, SloppyImportsResolutionKind::Execution)?
|
||||
.as_suggestion_message();
|
||||
Some(format!(
|
||||
"{} {} or run with --unstable-sloppy-imports",
|
||||
|
@ -1101,12 +1101,12 @@ impl<'a> deno_graph::source::FileSystem for DenoGraphFsAdapter<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn format_range_with_colors(range: &deno_graph::Range) -> String {
|
||||
pub fn format_range_with_colors(referrer: &deno_graph::Range) -> String {
|
||||
format!(
|
||||
"{}:{}:{}",
|
||||
colors::cyan(range.specifier.as_str()),
|
||||
colors::yellow(&(range.start.line + 1).to_string()),
|
||||
colors::yellow(&(range.start.character + 1).to_string())
|
||||
colors::cyan(referrer.specifier.as_str()),
|
||||
colors::yellow(&(referrer.range.start.line + 1).to_string()),
|
||||
colors::yellow(&(referrer.range.start.character + 1).to_string())
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1196,26 +1196,54 @@ impl<'a> deno_graph::source::Resolver for CliGraphResolver<'a> {
|
|||
&self,
|
||||
raw_specifier: &str,
|
||||
referrer_range: &deno_graph::Range,
|
||||
mode: ResolutionMode,
|
||||
resolution_kind: ResolutionKind,
|
||||
) -> Result<ModuleSpecifier, ResolveError> {
|
||||
self.resolver.resolve(
|
||||
raw_specifier,
|
||||
referrer_range,
|
||||
self
|
||||
.cjs_tracker
|
||||
.get_referrer_kind(&referrer_range.specifier),
|
||||
mode,
|
||||
&referrer_range.specifier,
|
||||
referrer_range.range.start,
|
||||
referrer_range
|
||||
.resolution_mode
|
||||
.map(to_node_resolution_mode)
|
||||
.unwrap_or_else(|| {
|
||||
self
|
||||
.cjs_tracker
|
||||
.get_referrer_kind(&referrer_range.specifier)
|
||||
}),
|
||||
to_node_resolution_kind(resolution_kind),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_node_resolution_kind(
|
||||
kind: ResolutionKind,
|
||||
) -> node_resolver::NodeResolutionKind {
|
||||
match kind {
|
||||
ResolutionKind::Execution => node_resolver::NodeResolutionKind::Execution,
|
||||
ResolutionKind::Types => node_resolver::NodeResolutionKind::Types,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_node_resolution_mode(
|
||||
mode: deno_graph::source::ResolutionMode,
|
||||
) -> node_resolver::ResolutionMode {
|
||||
match mode {
|
||||
deno_graph::source::ResolutionMode::Import => {
|
||||
node_resolver::ResolutionMode::Import
|
||||
}
|
||||
deno_graph::source::ResolutionMode::Require => {
|
||||
node_resolver::ResolutionMode::Require
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::sync::Arc;
|
||||
|
||||
use deno_ast::ModuleSpecifier;
|
||||
use deno_graph::source::ResolveError;
|
||||
use deno_graph::Position;
|
||||
use deno_graph::PositionRange;
|
||||
use deno_graph::Range;
|
||||
use deno_graph::ResolutionError;
|
||||
use deno_graph::SpecifierError;
|
||||
|
@ -1236,8 +1264,8 @@ mod test {
|
|||
specifier: input.to_string(),
|
||||
range: Range {
|
||||
specifier,
|
||||
start: Position::zeroed(),
|
||||
end: Position::zeroed(),
|
||||
resolution_mode: None,
|
||||
range: PositionRange::zeroed(),
|
||||
},
|
||||
};
|
||||
assert_eq!(get_resolution_error_bare_node_specifier(&err), output);
|
||||
|
@ -1252,8 +1280,8 @@ mod test {
|
|||
let err = ResolutionError::InvalidSpecifier {
|
||||
range: Range {
|
||||
specifier,
|
||||
start: Position::zeroed(),
|
||||
end: Position::zeroed(),
|
||||
resolution_mode: None,
|
||||
range: PositionRange::zeroed(),
|
||||
},
|
||||
error: SpecifierError::ImportPrefixMissing {
|
||||
specifier: input.to_string(),
|
||||
|
|
|
@ -15,7 +15,6 @@ use crate::lsp::search::PackageSearchApi;
|
|||
use crate::tools::lint::CliLinter;
|
||||
use crate::util::path::relative_specifier;
|
||||
use deno_config::workspace::MappedResolution;
|
||||
use deno_graph::source::ResolutionMode;
|
||||
use deno_lint::diagnostic::LintDiagnosticRange;
|
||||
|
||||
use deno_ast::SourceRange;
|
||||
|
@ -39,7 +38,8 @@ use deno_semver::package::PackageReq;
|
|||
use deno_semver::package::PackageReqReference;
|
||||
use deno_semver::Version;
|
||||
use import_map::ImportMap;
|
||||
use node_resolver::NodeModuleKind;
|
||||
use node_resolver::NodeResolutionKind;
|
||||
use node_resolver::ResolutionMode;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use std::borrow::Cow;
|
||||
|
@ -467,7 +467,7 @@ impl<'a> TsResponseImportMapper<'a> {
|
|||
&self,
|
||||
specifier: &str,
|
||||
referrer: &ModuleSpecifier,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
) -> Option<String> {
|
||||
let specifier_stem = specifier.strip_suffix(".js").unwrap_or(specifier);
|
||||
let specifiers = std::iter::once(Cow::Borrowed(specifier)).chain(
|
||||
|
@ -481,13 +481,10 @@ impl<'a> TsResponseImportMapper<'a> {
|
|||
.as_cli_resolver(Some(&self.file_referrer))
|
||||
.resolve(
|
||||
&specifier,
|
||||
&deno_graph::Range {
|
||||
specifier: referrer.clone(),
|
||||
start: deno_graph::Position::zeroed(),
|
||||
end: deno_graph::Position::zeroed(),
|
||||
},
|
||||
referrer_kind,
|
||||
ResolutionMode::Types,
|
||||
referrer,
|
||||
deno_graph::Position::zeroed(),
|
||||
resolution_mode,
|
||||
NodeResolutionKind::Types,
|
||||
)
|
||||
.ok()
|
||||
.and_then(|s| self.tsc_specifier_map.normalize(s.as_str()).ok())
|
||||
|
@ -509,20 +506,17 @@ impl<'a> TsResponseImportMapper<'a> {
|
|||
&self,
|
||||
specifier_text: &str,
|
||||
referrer: &ModuleSpecifier,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
) -> bool {
|
||||
self
|
||||
.resolver
|
||||
.as_cli_resolver(Some(&self.file_referrer))
|
||||
.resolve(
|
||||
specifier_text,
|
||||
&deno_graph::Range {
|
||||
specifier: referrer.clone(),
|
||||
start: deno_graph::Position::zeroed(),
|
||||
end: deno_graph::Position::zeroed(),
|
||||
},
|
||||
referrer_kind,
|
||||
deno_graph::source::ResolutionMode::Types,
|
||||
referrer,
|
||||
deno_graph::Position::zeroed(),
|
||||
resolution_mode,
|
||||
NodeResolutionKind::Types,
|
||||
)
|
||||
.is_ok()
|
||||
}
|
||||
|
@ -590,7 +584,7 @@ fn try_reverse_map_package_json_exports(
|
|||
/// like an import and rewrite the import specifier to include the extension
|
||||
pub fn fix_ts_import_changes(
|
||||
referrer: &ModuleSpecifier,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
changes: &[tsc::FileTextChanges],
|
||||
language_server: &language_server::Inner,
|
||||
) -> Result<Vec<tsc::FileTextChanges>, AnyError> {
|
||||
|
@ -608,7 +602,7 @@ pub fn fix_ts_import_changes(
|
|||
let specifier =
|
||||
captures.iter().skip(1).find_map(|s| s).unwrap().as_str();
|
||||
if let Some(new_specifier) = import_mapper
|
||||
.check_unresolved_specifier(specifier, referrer, referrer_kind)
|
||||
.check_unresolved_specifier(specifier, referrer, resolution_mode)
|
||||
{
|
||||
line.replace(specifier, &new_specifier)
|
||||
} else {
|
||||
|
@ -638,7 +632,7 @@ pub fn fix_ts_import_changes(
|
|||
/// resolution by Deno (includes the extension).
|
||||
fn fix_ts_import_action<'a>(
|
||||
referrer: &ModuleSpecifier,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
action: &'a tsc::CodeFixAction,
|
||||
language_server: &language_server::Inner,
|
||||
) -> Option<Cow<'a, tsc::CodeFixAction>> {
|
||||
|
@ -657,9 +651,11 @@ fn fix_ts_import_action<'a>(
|
|||
return Some(Cow::Borrowed(action));
|
||||
};
|
||||
let import_mapper = language_server.get_ts_response_import_mapper(referrer);
|
||||
if let Some(new_specifier) =
|
||||
import_mapper.check_unresolved_specifier(specifier, referrer, referrer_kind)
|
||||
{
|
||||
if let Some(new_specifier) = import_mapper.check_unresolved_specifier(
|
||||
specifier,
|
||||
referrer,
|
||||
resolution_mode,
|
||||
) {
|
||||
let description = action.description.replace(specifier, &new_specifier);
|
||||
let changes = action
|
||||
.changes
|
||||
|
@ -689,7 +685,8 @@ fn fix_ts_import_action<'a>(
|
|||
fix_id: None,
|
||||
fix_all_description: None,
|
||||
}))
|
||||
} else if !import_mapper.is_valid_import(specifier, referrer, referrer_kind) {
|
||||
} else if !import_mapper.is_valid_import(specifier, referrer, resolution_mode)
|
||||
{
|
||||
None
|
||||
} else {
|
||||
Some(Cow::Borrowed(action))
|
||||
|
@ -1023,7 +1020,7 @@ impl CodeActionCollection {
|
|||
pub fn add_ts_fix_action(
|
||||
&mut self,
|
||||
specifier: &ModuleSpecifier,
|
||||
specifier_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
action: &tsc::CodeFixAction,
|
||||
diagnostic: &lsp::Diagnostic,
|
||||
language_server: &language_server::Inner,
|
||||
|
@ -1042,7 +1039,7 @@ impl CodeActionCollection {
|
|||
));
|
||||
}
|
||||
let Some(action) =
|
||||
fix_ts_import_action(specifier, specifier_kind, action, language_server)
|
||||
fix_ts_import_action(specifier, resolution_mode, action, language_server)
|
||||
else {
|
||||
return Ok(());
|
||||
};
|
||||
|
@ -1237,12 +1234,12 @@ impl CodeActionCollection {
|
|||
let text_info = parsed_source.text_info_lazy();
|
||||
let specifier_range = SourceRange::new(
|
||||
text_info.loc_to_source_pos(LineAndColumnIndex {
|
||||
line_index: import.specifier_range.start.line,
|
||||
column_index: import.specifier_range.start.character,
|
||||
line_index: import.specifier_range.range.start.line,
|
||||
column_index: import.specifier_range.range.start.character,
|
||||
}),
|
||||
text_info.loc_to_source_pos(LineAndColumnIndex {
|
||||
line_index: import.specifier_range.end.line,
|
||||
column_index: import.specifier_range.end.character,
|
||||
line_index: import.specifier_range.range.end.line,
|
||||
column_index: import.specifier_range.range.end.character,
|
||||
}),
|
||||
);
|
||||
|
||||
|
@ -1277,16 +1274,14 @@ impl CodeActionCollection {
|
|||
if json!(i.kind) != json!("es") && json!(i.kind) != json!("tsType") {
|
||||
return None;
|
||||
}
|
||||
if !i.specifier_range.includes(&position) {
|
||||
if !i.specifier_range.includes(position) {
|
||||
return None;
|
||||
}
|
||||
|
||||
import_start_from_specifier(document, i)
|
||||
})?;
|
||||
let referrer = document.specifier();
|
||||
let referrer_kind = language_server
|
||||
.is_cjs_resolver
|
||||
.get_doc_module_kind(document);
|
||||
let resolution_mode = document.resolution_mode();
|
||||
let file_referrer = document.file_referrer();
|
||||
let config_data = language_server
|
||||
.config
|
||||
|
@ -1312,7 +1307,7 @@ impl CodeActionCollection {
|
|||
if !language_server.resolver.is_bare_package_json_dep(
|
||||
&dep_key,
|
||||
referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
) {
|
||||
return None;
|
||||
}
|
||||
|
@ -1332,7 +1327,7 @@ impl CodeActionCollection {
|
|||
}
|
||||
if language_server
|
||||
.resolver
|
||||
.npm_to_file_url(&npm_ref, referrer, referrer_kind, file_referrer)
|
||||
.npm_to_file_url(&npm_ref, referrer, resolution_mode, file_referrer)
|
||||
.is_some()
|
||||
{
|
||||
// The package import has types.
|
||||
|
|
|
@ -9,16 +9,14 @@ use super::jsr::CliJsrSearchApi;
|
|||
use super::lsp_custom;
|
||||
use super::npm::CliNpmSearchApi;
|
||||
use super::registries::ModuleRegistry;
|
||||
use super::resolver::LspIsCjsResolver;
|
||||
use super::resolver::LspResolver;
|
||||
use super::search::PackageSearchApi;
|
||||
use super::tsc;
|
||||
|
||||
use crate::graph_util::to_node_resolution_mode;
|
||||
use crate::jsr::JsrFetchResolver;
|
||||
use crate::util::path::is_importable_ext;
|
||||
use crate::util::path::relative_specifier;
|
||||
use deno_graph::source::ResolutionMode;
|
||||
use deno_graph::Range;
|
||||
use deno_runtime::deno_node::SUPPORTED_BUILTIN_NODE_MODULES;
|
||||
|
||||
use deno_ast::LineAndColumnIndex;
|
||||
|
@ -36,7 +34,8 @@ use deno_semver::package::PackageNv;
|
|||
use import_map::ImportMap;
|
||||
use indexmap::IndexSet;
|
||||
use lsp_types::CompletionList;
|
||||
use node_resolver::NodeModuleKind;
|
||||
use node_resolver::NodeResolutionKind;
|
||||
use node_resolver::ResolutionMode;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
|
@ -113,7 +112,7 @@ async fn check_auto_config_registry(
|
|||
/// which we want to ignore when replacing text.
|
||||
fn to_narrow_lsp_range(
|
||||
text_info: &SourceTextInfo,
|
||||
range: &deno_graph::Range,
|
||||
range: deno_graph::PositionRange,
|
||||
) -> lsp::Range {
|
||||
let end_byte_index = text_info
|
||||
.loc_to_source_pos(LineAndColumnIndex {
|
||||
|
@ -161,26 +160,25 @@ pub async fn get_import_completions(
|
|||
jsr_search_api: &CliJsrSearchApi,
|
||||
npm_search_api: &CliNpmSearchApi,
|
||||
documents: &Documents,
|
||||
is_cjs_resolver: &LspIsCjsResolver,
|
||||
resolver: &LspResolver,
|
||||
maybe_import_map: Option<&ImportMap>,
|
||||
) -> Option<lsp::CompletionResponse> {
|
||||
let document = documents.get(specifier)?;
|
||||
let specifier_kind = is_cjs_resolver.get_doc_module_kind(&document);
|
||||
let file_referrer = document.file_referrer();
|
||||
let (text, _, range) = document.get_maybe_dependency(position)?;
|
||||
let range = to_narrow_lsp_range(document.text_info(), &range);
|
||||
let (text, _, graph_range) = document.get_maybe_dependency(position)?;
|
||||
let resolution_mode = graph_range
|
||||
.resolution_mode
|
||||
.map(to_node_resolution_mode)
|
||||
.unwrap_or_else(|| document.resolution_mode());
|
||||
let range = to_narrow_lsp_range(document.text_info(), graph_range.range);
|
||||
let resolved = resolver
|
||||
.as_cli_resolver(file_referrer)
|
||||
.resolve(
|
||||
&text,
|
||||
&Range {
|
||||
specifier: specifier.clone(),
|
||||
start: deno_graph::Position::zeroed(),
|
||||
end: deno_graph::Position::zeroed(),
|
||||
},
|
||||
specifier_kind,
|
||||
ResolutionMode::Execution,
|
||||
specifier,
|
||||
deno_graph::Position::zeroed(),
|
||||
resolution_mode,
|
||||
NodeResolutionKind::Execution,
|
||||
)
|
||||
.ok();
|
||||
if let Some(completion_list) = get_jsr_completions(
|
||||
|
@ -206,7 +204,7 @@ pub async fn get_import_completions(
|
|||
// completions for import map specifiers
|
||||
Some(lsp::CompletionResponse::List(completion_list))
|
||||
} else if let Some(completion_list) =
|
||||
get_local_completions(specifier, specifier_kind, &text, &range, resolver)
|
||||
get_local_completions(specifier, resolution_mode, &text, &range, resolver)
|
||||
{
|
||||
// completions for local relative modules
|
||||
Some(lsp::CompletionResponse::List(completion_list))
|
||||
|
@ -361,7 +359,7 @@ fn get_import_map_completions(
|
|||
/// Return local completions that are relative to the base specifier.
|
||||
fn get_local_completions(
|
||||
referrer: &ModuleSpecifier,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
text: &str,
|
||||
range: &lsp::Range,
|
||||
resolver: &LspResolver,
|
||||
|
@ -374,13 +372,10 @@ fn get_local_completions(
|
|||
.as_cli_resolver(Some(referrer))
|
||||
.resolve(
|
||||
parent,
|
||||
&Range {
|
||||
specifier: referrer.clone(),
|
||||
start: deno_graph::Position::zeroed(),
|
||||
end: deno_graph::Position::zeroed(),
|
||||
},
|
||||
referrer_kind,
|
||||
ResolutionMode::Execution,
|
||||
referrer,
|
||||
deno_graph::Position::zeroed(),
|
||||
resolution_mode,
|
||||
NodeResolutionKind::Execution,
|
||||
)
|
||||
.ok()?;
|
||||
let resolved_parent_path = url_to_file_path(&resolved_parent).ok()?;
|
||||
|
@ -831,7 +826,6 @@ mod tests {
|
|||
use crate::lsp::documents::LanguageId;
|
||||
use crate::lsp::search::tests::TestPackageSearchApi;
|
||||
use deno_core::resolve_url;
|
||||
use deno_graph::Range;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::collections::HashMap;
|
||||
use test_util::TempDir;
|
||||
|
@ -912,7 +906,7 @@ mod tests {
|
|||
ModuleSpecifier::from_file_path(file_c).expect("could not create");
|
||||
let actual = get_local_completions(
|
||||
&specifier,
|
||||
NodeModuleKind::Esm,
|
||||
ResolutionMode::Import,
|
||||
"./",
|
||||
&lsp::Range {
|
||||
start: lsp::Position {
|
||||
|
@ -1608,8 +1602,7 @@ mod tests {
|
|||
let text_info = SourceTextInfo::from_string(r#""te""#.to_string());
|
||||
let range = to_narrow_lsp_range(
|
||||
&text_info,
|
||||
&Range {
|
||||
specifier: ModuleSpecifier::parse("https://deno.land").unwrap(),
|
||||
deno_graph::PositionRange {
|
||||
start: deno_graph::Position {
|
||||
line: 0,
|
||||
character: 0,
|
||||
|
@ -1632,8 +1625,7 @@ mod tests {
|
|||
let text_info = SourceTextInfo::from_string(r#""te"#.to_string());
|
||||
let range = to_narrow_lsp_range(
|
||||
&text_info,
|
||||
&Range {
|
||||
specifier: ModuleSpecifier::parse("https://deno.land").unwrap(),
|
||||
deno_graph::PositionRange {
|
||||
start: deno_graph::Position {
|
||||
line: 0,
|
||||
character: 0,
|
||||
|
|
|
@ -45,7 +45,7 @@ use deno_graph::Resolution;
|
|||
use deno_graph::ResolutionError;
|
||||
use deno_graph::SpecifierError;
|
||||
use deno_resolver::sloppy_imports::SloppyImportsResolution;
|
||||
use deno_resolver::sloppy_imports::SloppyImportsResolutionMode;
|
||||
use deno_resolver::sloppy_imports::SloppyImportsResolutionKind;
|
||||
use deno_runtime::deno_fs;
|
||||
use deno_runtime::deno_node;
|
||||
use deno_runtime::tokio_util::create_basic_runtime;
|
||||
|
@ -1266,7 +1266,7 @@ impl DenoDiagnostic {
|
|||
Self::NoLocal(specifier) => {
|
||||
let maybe_sloppy_resolution = CliSloppyImportsResolver::new(
|
||||
SloppyImportsCachedFs::new(Arc::new(deno_fs::RealFs))
|
||||
).resolve(specifier, SloppyImportsResolutionMode::Execution);
|
||||
).resolve(specifier, SloppyImportsResolutionKind::Execution);
|
||||
let data = maybe_sloppy_resolution.as_ref().map(|res| {
|
||||
json!({
|
||||
"specifier": specifier,
|
||||
|
@ -1531,7 +1531,7 @@ fn diagnose_dependency(
|
|||
&& !dependency.imports.iter().any(|i| {
|
||||
dependency
|
||||
.maybe_type
|
||||
.includes(&i.specifier_range.start)
|
||||
.includes(i.specifier_range.range.start)
|
||||
.is_some()
|
||||
});
|
||||
|
||||
|
@ -1707,7 +1707,6 @@ mod tests {
|
|||
documents: Arc::new(documents),
|
||||
assets: Default::default(),
|
||||
config: Arc::new(config),
|
||||
is_cjs_resolver: Default::default(),
|
||||
resolver,
|
||||
},
|
||||
)
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
use super::cache::calculate_fs_version;
|
||||
use super::cache::LspCache;
|
||||
use super::config::Config;
|
||||
use super::resolver::LspIsCjsResolver;
|
||||
use super::resolver::LspResolver;
|
||||
use super::resolver::ScopeDepInfo;
|
||||
use super::resolver::SingleReferrerGraphResolver;
|
||||
|
@ -27,7 +26,6 @@ use deno_core::futures::future::Shared;
|
|||
use deno_core::futures::FutureExt;
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use deno_graph::source::ResolutionMode;
|
||||
use deno_graph::Resolution;
|
||||
use deno_path_util::url_to_file_path;
|
||||
use deno_runtime::deno_node;
|
||||
|
@ -36,7 +34,8 @@ use deno_semver::npm::NpmPackageReqReference;
|
|||
use deno_semver::package::PackageReq;
|
||||
use indexmap::IndexMap;
|
||||
use indexmap::IndexSet;
|
||||
use node_resolver::NodeModuleKind;
|
||||
use node_resolver::NodeResolutionKind;
|
||||
use node_resolver::ResolutionMode;
|
||||
use std::borrow::Cow;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
|
@ -313,6 +312,7 @@ pub struct Document {
|
|||
media_type: MediaType,
|
||||
/// Present if and only if this is an open document.
|
||||
open_data: Option<DocumentOpenData>,
|
||||
resolution_mode: ResolutionMode,
|
||||
resolver: Arc<LspResolver>,
|
||||
specifier: ModuleSpecifier,
|
||||
text: Arc<str>,
|
||||
|
@ -328,7 +328,6 @@ impl Document {
|
|||
maybe_lsp_version: Option<i32>,
|
||||
maybe_language_id: Option<LanguageId>,
|
||||
maybe_headers: Option<HashMap<String, String>>,
|
||||
is_cjs_resolver: &LspIsCjsResolver,
|
||||
resolver: Arc<LspResolver>,
|
||||
config: Arc<Config>,
|
||||
cache: &Arc<LspCache>,
|
||||
|
@ -340,7 +339,7 @@ impl Document {
|
|||
.or(file_referrer);
|
||||
let media_type =
|
||||
resolve_media_type(&specifier, maybe_headers.as_ref(), maybe_language_id);
|
||||
let (maybe_parsed_source, maybe_module) =
|
||||
let (maybe_parsed_source, maybe_module, resolution_mode) =
|
||||
if media_type_is_diagnosable(media_type) {
|
||||
parse_and_analyze_module(
|
||||
specifier.clone(),
|
||||
|
@ -348,11 +347,10 @@ impl Document {
|
|||
maybe_headers.as_ref(),
|
||||
media_type,
|
||||
file_referrer.as_ref(),
|
||||
is_cjs_resolver,
|
||||
&resolver,
|
||||
)
|
||||
} else {
|
||||
(None, None)
|
||||
(None, None, ResolutionMode::Import)
|
||||
};
|
||||
let maybe_module = maybe_module.and_then(Result::ok);
|
||||
let dependencies = maybe_module
|
||||
|
@ -387,6 +385,7 @@ impl Document {
|
|||
maybe_parsed_source,
|
||||
maybe_semantic_tokens: Default::default(),
|
||||
}),
|
||||
resolution_mode,
|
||||
resolver,
|
||||
specifier,
|
||||
text,
|
||||
|
@ -396,7 +395,6 @@ impl Document {
|
|||
|
||||
fn with_new_config(
|
||||
&self,
|
||||
is_cjs_resolver: &LspIsCjsResolver,
|
||||
resolver: Arc<LspResolver>,
|
||||
config: Arc<Config>,
|
||||
) -> Arc<Self> {
|
||||
|
@ -408,20 +406,20 @@ impl Document {
|
|||
let dependencies;
|
||||
let maybe_types_dependency;
|
||||
let maybe_parsed_source;
|
||||
let found_resolution_mode;
|
||||
let is_script;
|
||||
let maybe_test_module_fut;
|
||||
if media_type != self.media_type {
|
||||
let parsed_source_result =
|
||||
parse_source(self.specifier.clone(), self.text.clone(), media_type);
|
||||
let maybe_module = analyze_module(
|
||||
let (maybe_module_result, resolution_mode) = analyze_module(
|
||||
self.specifier.clone(),
|
||||
&parsed_source_result,
|
||||
self.maybe_headers.as_ref(),
|
||||
self.file_referrer.as_ref(),
|
||||
is_cjs_resolver,
|
||||
&resolver,
|
||||
)
|
||||
.ok();
|
||||
);
|
||||
let maybe_module = maybe_module_result.ok();
|
||||
dependencies = maybe_module
|
||||
.as_ref()
|
||||
.map(|m| Arc::new(m.dependencies.clone()))
|
||||
|
@ -433,17 +431,21 @@ impl Document {
|
|||
maybe_parsed_source = Some(parsed_source_result);
|
||||
maybe_test_module_fut =
|
||||
get_maybe_test_module_fut(maybe_parsed_source.as_ref(), &config);
|
||||
found_resolution_mode = resolution_mode;
|
||||
} else {
|
||||
let cli_resolver = resolver.as_cli_resolver(self.file_referrer.as_ref());
|
||||
let is_cjs_resolver =
|
||||
resolver.as_is_cjs_resolver(self.file_referrer.as_ref());
|
||||
let npm_resolver =
|
||||
resolver.create_graph_npm_resolver(self.file_referrer.as_ref());
|
||||
let config_data = resolver.as_config_data(self.file_referrer.as_ref());
|
||||
let jsx_import_source_config =
|
||||
config_data.and_then(|d| d.maybe_jsx_import_source_config());
|
||||
found_resolution_mode = is_cjs_resolver
|
||||
.get_lsp_resolution_mode(&self.specifier, self.is_script);
|
||||
let resolver = SingleReferrerGraphResolver {
|
||||
valid_referrer: &self.specifier,
|
||||
referrer_kind: is_cjs_resolver
|
||||
.get_lsp_referrer_kind(&self.specifier, self.is_script),
|
||||
module_resolution_mode: found_resolution_mode,
|
||||
cli_resolver,
|
||||
jsx_import_source_config: jsx_import_source_config.as_ref(),
|
||||
};
|
||||
|
@ -493,6 +495,7 @@ impl Document {
|
|||
maybe_language_id: self.maybe_language_id,
|
||||
maybe_test_module_fut,
|
||||
media_type,
|
||||
resolution_mode: found_resolution_mode,
|
||||
open_data: self.open_data.as_ref().map(|d| DocumentOpenData {
|
||||
lsp_version: d.lsp_version,
|
||||
maybe_parsed_source,
|
||||
|
@ -508,7 +511,6 @@ impl Document {
|
|||
|
||||
fn with_change(
|
||||
&self,
|
||||
is_cjs_resolver: &LspIsCjsResolver,
|
||||
version: i32,
|
||||
changes: Vec<lsp::TextDocumentContentChangeEvent>,
|
||||
) -> Result<Arc<Self>, AnyError> {
|
||||
|
@ -530,7 +532,7 @@ impl Document {
|
|||
}
|
||||
let text: Arc<str> = content.into();
|
||||
let media_type = self.media_type;
|
||||
let (maybe_parsed_source, maybe_module) = if self
|
||||
let (maybe_parsed_source, maybe_module, resolution_mode) = if self
|
||||
.maybe_language_id
|
||||
.as_ref()
|
||||
.map(|li| li.is_diagnosable())
|
||||
|
@ -542,11 +544,10 @@ impl Document {
|
|||
self.maybe_headers.as_ref(),
|
||||
media_type,
|
||||
self.file_referrer.as_ref(),
|
||||
is_cjs_resolver,
|
||||
self.resolver.as_ref(),
|
||||
)
|
||||
} else {
|
||||
(None, None)
|
||||
(None, None, ResolutionMode::Import)
|
||||
};
|
||||
let maybe_module = maybe_module.and_then(Result::ok);
|
||||
let dependencies = maybe_module
|
||||
|
@ -580,6 +581,7 @@ impl Document {
|
|||
maybe_navigation_tree: Mutex::new(None),
|
||||
maybe_test_module_fut,
|
||||
media_type,
|
||||
resolution_mode,
|
||||
open_data: self.open_data.is_some().then_some(DocumentOpenData {
|
||||
lsp_version: version,
|
||||
maybe_parsed_source,
|
||||
|
@ -613,6 +615,7 @@ impl Document {
|
|||
maybe_test_module_fut: self.maybe_test_module_fut.clone(),
|
||||
media_type: self.media_type,
|
||||
open_data: None,
|
||||
resolution_mode: self.resolution_mode,
|
||||
resolver: self.resolver.clone(),
|
||||
})
|
||||
}
|
||||
|
@ -641,6 +644,7 @@ impl Document {
|
|||
maybe_test_module_fut: self.maybe_test_module_fut.clone(),
|
||||
media_type: self.media_type,
|
||||
open_data: self.open_data.clone(),
|
||||
resolution_mode: self.resolution_mode,
|
||||
resolver: self.resolver.clone(),
|
||||
})
|
||||
}
|
||||
|
@ -664,6 +668,10 @@ impl Document {
|
|||
&self.text
|
||||
}
|
||||
|
||||
pub fn resolution_mode(&self) -> ResolutionMode {
|
||||
self.resolution_mode
|
||||
}
|
||||
|
||||
pub fn text_info(&self) -> &SourceTextInfo {
|
||||
// try to get the text info from the parsed source and if
|
||||
// not then create one in the cell
|
||||
|
@ -677,14 +685,6 @@ impl Document {
|
|||
.get_or_init(|| SourceTextInfo::new(self.text.clone()))
|
||||
})
|
||||
}
|
||||
|
||||
/// If this is maybe a CJS script and maybe not an ES module.
|
||||
///
|
||||
/// Use `LspIsCjsResolver` to determine for sure.
|
||||
pub fn is_script(&self) -> Option<bool> {
|
||||
self.is_script
|
||||
}
|
||||
|
||||
pub fn line_index(&self) -> Arc<LineIndex> {
|
||||
self.line_index.clone()
|
||||
}
|
||||
|
@ -768,7 +768,7 @@ impl Document {
|
|||
};
|
||||
self.dependencies().iter().find_map(|(s, dep)| {
|
||||
dep
|
||||
.includes(&position)
|
||||
.includes(position)
|
||||
.map(|r| (s.clone(), dep.clone(), r.clone()))
|
||||
})
|
||||
}
|
||||
|
@ -809,15 +809,15 @@ fn resolve_media_type(
|
|||
MediaType::from_specifier(specifier)
|
||||
}
|
||||
|
||||
pub fn to_lsp_range(range: &deno_graph::Range) -> lsp::Range {
|
||||
pub fn to_lsp_range(referrer: &deno_graph::Range) -> lsp::Range {
|
||||
lsp::Range {
|
||||
start: lsp::Position {
|
||||
line: range.start.line as u32,
|
||||
character: range.start.character as u32,
|
||||
line: referrer.range.start.line as u32,
|
||||
character: referrer.range.start.character as u32,
|
||||
},
|
||||
end: lsp::Position {
|
||||
line: range.end.line as u32,
|
||||
character: range.end.character as u32,
|
||||
line: referrer.range.end.line as u32,
|
||||
character: referrer.range.end.character as u32,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -832,7 +832,6 @@ impl FileSystemDocuments {
|
|||
pub fn get(
|
||||
&self,
|
||||
specifier: &ModuleSpecifier,
|
||||
is_cjs_resolver: &LspIsCjsResolver,
|
||||
resolver: &Arc<LspResolver>,
|
||||
config: &Arc<Config>,
|
||||
cache: &Arc<LspCache>,
|
||||
|
@ -856,14 +855,7 @@ impl FileSystemDocuments {
|
|||
};
|
||||
if dirty {
|
||||
// attempt to update the file on the file system
|
||||
self.refresh_document(
|
||||
specifier,
|
||||
is_cjs_resolver,
|
||||
resolver,
|
||||
config,
|
||||
cache,
|
||||
file_referrer,
|
||||
)
|
||||
self.refresh_document(specifier, resolver, config, cache, file_referrer)
|
||||
} else {
|
||||
old_doc
|
||||
}
|
||||
|
@ -874,7 +866,6 @@ impl FileSystemDocuments {
|
|||
fn refresh_document(
|
||||
&self,
|
||||
specifier: &ModuleSpecifier,
|
||||
is_cjs_resolver: &LspIsCjsResolver,
|
||||
resolver: &Arc<LspResolver>,
|
||||
config: &Arc<Config>,
|
||||
cache: &Arc<LspCache>,
|
||||
|
@ -896,7 +887,6 @@ impl FileSystemDocuments {
|
|||
None,
|
||||
None,
|
||||
None,
|
||||
is_cjs_resolver,
|
||||
resolver.clone(),
|
||||
config.clone(),
|
||||
cache,
|
||||
|
@ -913,7 +903,6 @@ impl FileSystemDocuments {
|
|||
None,
|
||||
None,
|
||||
None,
|
||||
is_cjs_resolver,
|
||||
resolver.clone(),
|
||||
config.clone(),
|
||||
cache,
|
||||
|
@ -946,7 +935,6 @@ impl FileSystemDocuments {
|
|||
None,
|
||||
None,
|
||||
Some(cached_file.metadata.headers),
|
||||
is_cjs_resolver,
|
||||
resolver.clone(),
|
||||
config.clone(),
|
||||
cache,
|
||||
|
@ -987,8 +975,6 @@ pub struct Documents {
|
|||
/// The DENO_DIR that the documents looks for non-file based modules.
|
||||
cache: Arc<LspCache>,
|
||||
config: Arc<Config>,
|
||||
/// Resolver for detecting if a document is CJS or ESM.
|
||||
is_cjs_resolver: Arc<LspIsCjsResolver>,
|
||||
/// A resolver that takes into account currently loaded import map and JSX
|
||||
/// settings.
|
||||
resolver: Arc<LspResolver>,
|
||||
|
@ -1024,7 +1010,6 @@ impl Documents {
|
|||
// the cache for remote modules here in order to get the
|
||||
// x-typescript-types?
|
||||
None,
|
||||
&self.is_cjs_resolver,
|
||||
self.resolver.clone(),
|
||||
self.config.clone(),
|
||||
&self.cache,
|
||||
|
@ -1059,7 +1044,7 @@ impl Documents {
|
|||
))
|
||||
})?;
|
||||
self.dirty = true;
|
||||
let doc = doc.with_change(&self.is_cjs_resolver, version, changes)?;
|
||||
let doc = doc.with_change(version, changes)?;
|
||||
self.open_docs.insert(doc.specifier().clone(), doc.clone());
|
||||
Ok(doc)
|
||||
}
|
||||
|
@ -1191,7 +1176,6 @@ impl Documents {
|
|||
if let Some(old_doc) = old_doc {
|
||||
self.file_system_docs.get(
|
||||
specifier,
|
||||
&self.is_cjs_resolver,
|
||||
&self.resolver,
|
||||
&self.config,
|
||||
&self.cache,
|
||||
|
@ -1216,7 +1200,6 @@ impl Documents {
|
|||
} else {
|
||||
self.file_system_docs.get(
|
||||
&specifier,
|
||||
&self.is_cjs_resolver,
|
||||
&self.resolver,
|
||||
&self.config,
|
||||
&self.cache,
|
||||
|
@ -1271,7 +1254,8 @@ impl Documents {
|
|||
/// tsc when type checking.
|
||||
pub fn resolve(
|
||||
&self,
|
||||
raw_specifiers: &[String],
|
||||
// (is_cjs: bool, raw_specifier: String)
|
||||
raw_specifiers: &[(bool, String)],
|
||||
referrer: &ModuleSpecifier,
|
||||
file_referrer: Option<&ModuleSpecifier>,
|
||||
) -> Vec<Option<(ModuleSpecifier, MediaType)>> {
|
||||
|
@ -1281,11 +1265,12 @@ impl Documents {
|
|||
.and_then(|d| d.file_referrer())
|
||||
.or(file_referrer);
|
||||
let dependencies = referrer_doc.as_ref().map(|d| d.dependencies());
|
||||
let referrer_kind = self
|
||||
.is_cjs_resolver
|
||||
.get_maybe_doc_module_kind(referrer, referrer_doc.as_deref());
|
||||
let mut results = Vec::new();
|
||||
for raw_specifier in raw_specifiers {
|
||||
for (is_cjs, raw_specifier) in raw_specifiers {
|
||||
let resolution_mode = match is_cjs {
|
||||
true => ResolutionMode::Require,
|
||||
false => ResolutionMode::Import,
|
||||
};
|
||||
if raw_specifier.starts_with("asset:") {
|
||||
if let Ok(specifier) = ModuleSpecifier::parse(raw_specifier) {
|
||||
let media_type = MediaType::from_specifier(&specifier);
|
||||
|
@ -1300,14 +1285,14 @@ impl Documents {
|
|||
results.push(self.resolve_dependency(
|
||||
specifier,
|
||||
referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
file_referrer,
|
||||
));
|
||||
} else if let Some(specifier) = dep.maybe_code.maybe_specifier() {
|
||||
results.push(self.resolve_dependency(
|
||||
specifier,
|
||||
referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
file_referrer,
|
||||
));
|
||||
} else {
|
||||
|
@ -1316,19 +1301,16 @@ impl Documents {
|
|||
} else if let Ok(specifier) =
|
||||
self.resolver.as_cli_resolver(file_referrer).resolve(
|
||||
raw_specifier,
|
||||
&deno_graph::Range {
|
||||
specifier: referrer.clone(),
|
||||
start: deno_graph::Position::zeroed(),
|
||||
end: deno_graph::Position::zeroed(),
|
||||
},
|
||||
referrer_kind,
|
||||
ResolutionMode::Types,
|
||||
referrer,
|
||||
deno_graph::Position::zeroed(),
|
||||
resolution_mode,
|
||||
NodeResolutionKind::Types,
|
||||
)
|
||||
{
|
||||
results.push(self.resolve_dependency(
|
||||
&specifier,
|
||||
referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
file_referrer,
|
||||
));
|
||||
} else {
|
||||
|
@ -1347,7 +1329,6 @@ impl Documents {
|
|||
) {
|
||||
self.config = Arc::new(config.clone());
|
||||
self.cache = Arc::new(cache.clone());
|
||||
self.is_cjs_resolver = Arc::new(LspIsCjsResolver::new(cache));
|
||||
self.resolver = resolver.clone();
|
||||
|
||||
node_resolver::PackageJsonThreadLocalCache::clear();
|
||||
|
@ -1371,21 +1352,14 @@ impl Documents {
|
|||
if !config.specifier_enabled(doc.specifier()) {
|
||||
continue;
|
||||
}
|
||||
*doc = doc.with_new_config(
|
||||
&self.is_cjs_resolver,
|
||||
self.resolver.clone(),
|
||||
self.config.clone(),
|
||||
);
|
||||
*doc = doc.with_new_config(self.resolver.clone(), self.config.clone());
|
||||
}
|
||||
for mut doc in self.file_system_docs.docs.iter_mut() {
|
||||
if !config.specifier_enabled(doc.specifier()) {
|
||||
continue;
|
||||
}
|
||||
*doc.value_mut() = doc.with_new_config(
|
||||
&self.is_cjs_resolver,
|
||||
self.resolver.clone(),
|
||||
self.config.clone(),
|
||||
);
|
||||
*doc.value_mut() =
|
||||
doc.with_new_config(self.resolver.clone(), self.config.clone());
|
||||
}
|
||||
self.open_docs = open_docs;
|
||||
let mut preload_count = 0;
|
||||
|
@ -1402,7 +1376,6 @@ impl Documents {
|
|||
{
|
||||
fs_docs.refresh_document(
|
||||
specifier,
|
||||
&self.is_cjs_resolver,
|
||||
&self.resolver,
|
||||
&self.config,
|
||||
&self.cache,
|
||||
|
@ -1477,27 +1450,24 @@ impl Documents {
|
|||
let type_specifier = jsx_config.default_types_specifier.as_ref()?;
|
||||
let code_specifier = jsx_config.default_specifier.as_ref()?;
|
||||
let cli_resolver = self.resolver.as_cli_resolver(Some(scope));
|
||||
let range = deno_graph::Range {
|
||||
specifier: jsx_config.base_url.clone(),
|
||||
start: deno_graph::Position::zeroed(),
|
||||
end: deno_graph::Position::zeroed(),
|
||||
};
|
||||
let type_specifier = cli_resolver
|
||||
.resolve(
|
||||
type_specifier,
|
||||
&range,
|
||||
&jsx_config.base_url,
|
||||
deno_graph::Position::zeroed(),
|
||||
// todo(dsherret): this is wrong because it doesn't consider CJS referrers
|
||||
deno_package_json::NodeModuleKind::Esm,
|
||||
ResolutionMode::Types,
|
||||
ResolutionMode::Import,
|
||||
NodeResolutionKind::Types,
|
||||
)
|
||||
.ok()?;
|
||||
let code_specifier = cli_resolver
|
||||
.resolve(
|
||||
code_specifier,
|
||||
&range,
|
||||
&jsx_config.base_url,
|
||||
deno_graph::Position::zeroed(),
|
||||
// todo(dsherret): this is wrong because it doesn't consider CJS referrers
|
||||
deno_package_json::NodeModuleKind::Esm,
|
||||
ResolutionMode::Execution,
|
||||
ResolutionMode::Import,
|
||||
NodeResolutionKind::Execution,
|
||||
)
|
||||
.ok()?;
|
||||
dep_info
|
||||
|
@ -1542,7 +1512,7 @@ impl Documents {
|
|||
&self,
|
||||
specifier: &ModuleSpecifier,
|
||||
referrer: &ModuleSpecifier,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
file_referrer: Option<&ModuleSpecifier>,
|
||||
) -> Option<(ModuleSpecifier, MediaType)> {
|
||||
if let Some(module_name) = specifier.as_str().strip_prefix("node:") {
|
||||
|
@ -1559,7 +1529,7 @@ impl Documents {
|
|||
let (s, mt) = self.resolver.npm_to_file_url(
|
||||
&npm_ref,
|
||||
referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
file_referrer,
|
||||
)?;
|
||||
specifier = s;
|
||||
|
@ -1571,8 +1541,12 @@ impl Documents {
|
|||
return Some((specifier, media_type));
|
||||
};
|
||||
if let Some(types) = doc.maybe_types_dependency().maybe_specifier() {
|
||||
let specifier_kind = self.is_cjs_resolver.get_doc_module_kind(&doc);
|
||||
self.resolve_dependency(types, &specifier, specifier_kind, file_referrer)
|
||||
self.resolve_dependency(
|
||||
types,
|
||||
&specifier,
|
||||
doc.resolution_mode(),
|
||||
file_referrer,
|
||||
)
|
||||
} else {
|
||||
Some((doc.specifier().clone(), doc.media_type()))
|
||||
}
|
||||
|
@ -1640,19 +1614,25 @@ fn parse_and_analyze_module(
|
|||
maybe_headers: Option<&HashMap<String, String>>,
|
||||
media_type: MediaType,
|
||||
file_referrer: Option<&ModuleSpecifier>,
|
||||
is_cjs_resolver: &LspIsCjsResolver,
|
||||
resolver: &LspResolver,
|
||||
) -> (Option<ParsedSourceResult>, Option<ModuleResult>) {
|
||||
) -> (
|
||||
Option<ParsedSourceResult>,
|
||||
Option<ModuleResult>,
|
||||
ResolutionMode,
|
||||
) {
|
||||
let parsed_source_result = parse_source(specifier.clone(), text, media_type);
|
||||
let module_result = analyze_module(
|
||||
let (module_result, resolution_mode) = analyze_module(
|
||||
specifier,
|
||||
&parsed_source_result,
|
||||
maybe_headers,
|
||||
file_referrer,
|
||||
is_cjs_resolver,
|
||||
resolver,
|
||||
);
|
||||
(Some(parsed_source_result), Some(module_result))
|
||||
(
|
||||
Some(parsed_source_result),
|
||||
Some(module_result),
|
||||
resolution_mode,
|
||||
)
|
||||
}
|
||||
|
||||
fn parse_source(
|
||||
|
@ -1675,44 +1655,51 @@ fn analyze_module(
|
|||
parsed_source_result: &ParsedSourceResult,
|
||||
maybe_headers: Option<&HashMap<String, String>>,
|
||||
file_referrer: Option<&ModuleSpecifier>,
|
||||
is_cjs_resolver: &LspIsCjsResolver,
|
||||
resolver: &LspResolver,
|
||||
) -> ModuleResult {
|
||||
) -> (ModuleResult, ResolutionMode) {
|
||||
match parsed_source_result {
|
||||
Ok(parsed_source) => {
|
||||
let npm_resolver = resolver.create_graph_npm_resolver(file_referrer);
|
||||
let cli_resolver = resolver.as_cli_resolver(file_referrer);
|
||||
let is_cjs_resolver = resolver.as_is_cjs_resolver(file_referrer);
|
||||
let config_data = resolver.as_config_data(file_referrer);
|
||||
let valid_referrer = specifier.clone();
|
||||
let jsx_import_source_config =
|
||||
config_data.and_then(|d| d.maybe_jsx_import_source_config());
|
||||
let module_resolution_mode = is_cjs_resolver.get_lsp_resolution_mode(
|
||||
&specifier,
|
||||
Some(parsed_source.compute_is_script()),
|
||||
);
|
||||
let resolver = SingleReferrerGraphResolver {
|
||||
valid_referrer: &valid_referrer,
|
||||
referrer_kind: is_cjs_resolver.get_lsp_referrer_kind(
|
||||
&specifier,
|
||||
Some(parsed_source.compute_is_script()),
|
||||
),
|
||||
module_resolution_mode,
|
||||
cli_resolver,
|
||||
jsx_import_source_config: jsx_import_source_config.as_ref(),
|
||||
};
|
||||
Ok(deno_graph::parse_module_from_ast(
|
||||
deno_graph::ParseModuleFromAstOptions {
|
||||
graph_kind: deno_graph::GraphKind::TypesOnly,
|
||||
specifier,
|
||||
maybe_headers,
|
||||
parsed_source,
|
||||
// use a null file system because there's no need to bother resolving
|
||||
// dynamic imports like import(`./dir/${something}`) in the LSP
|
||||
file_system: &deno_graph::source::NullFileSystem,
|
||||
jsr_url_provider: &CliJsrUrlProvider,
|
||||
maybe_resolver: Some(&resolver),
|
||||
maybe_npm_resolver: Some(&npm_resolver),
|
||||
},
|
||||
))
|
||||
(
|
||||
Ok(deno_graph::parse_module_from_ast(
|
||||
deno_graph::ParseModuleFromAstOptions {
|
||||
graph_kind: deno_graph::GraphKind::TypesOnly,
|
||||
specifier,
|
||||
maybe_headers,
|
||||
parsed_source,
|
||||
// use a null file system because there's no need to bother resolving
|
||||
// dynamic imports like import(`./dir/${something}`) in the LSP
|
||||
file_system: &deno_graph::source::NullFileSystem,
|
||||
jsr_url_provider: &CliJsrUrlProvider,
|
||||
maybe_resolver: Some(&resolver),
|
||||
maybe_npm_resolver: Some(&npm_resolver),
|
||||
},
|
||||
)),
|
||||
module_resolution_mode,
|
||||
)
|
||||
}
|
||||
Err(err) => Err(deno_graph::ModuleGraphError::ModuleError(
|
||||
deno_graph::ModuleError::ParseErr(specifier, err.clone()),
|
||||
)),
|
||||
Err(err) => (
|
||||
Err(deno_graph::ModuleGraphError::ModuleError(
|
||||
deno_graph::ModuleError::ParseErr(specifier, err.clone()),
|
||||
)),
|
||||
ResolutionMode::Import,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,8 @@ use deno_semver::jsr::JsrPackageReqReference;
|
|||
use indexmap::Equivalent;
|
||||
use indexmap::IndexSet;
|
||||
use log::error;
|
||||
use node_resolver::NodeModuleKind;
|
||||
use node_resolver::NodeResolutionKind;
|
||||
use node_resolver::ResolutionMode;
|
||||
use serde::Deserialize;
|
||||
use serde_json::from_value;
|
||||
use std::collections::BTreeMap;
|
||||
|
@ -78,7 +79,6 @@ use super::parent_process_checker;
|
|||
use super::performance::Performance;
|
||||
use super::refactor;
|
||||
use super::registries::ModuleRegistry;
|
||||
use super::resolver::LspIsCjsResolver;
|
||||
use super::resolver::LspResolver;
|
||||
use super::testing;
|
||||
use super::text;
|
||||
|
@ -146,7 +146,6 @@ pub struct StateSnapshot {
|
|||
pub project_version: usize,
|
||||
pub assets: AssetsSnapshot,
|
||||
pub config: Arc<Config>,
|
||||
pub is_cjs_resolver: Arc<LspIsCjsResolver>,
|
||||
pub documents: Arc<Documents>,
|
||||
pub resolver: Arc<LspResolver>,
|
||||
}
|
||||
|
@ -206,7 +205,6 @@ pub struct Inner {
|
|||
pub documents: Documents,
|
||||
http_client_provider: Arc<HttpClientProvider>,
|
||||
initial_cwd: PathBuf,
|
||||
pub is_cjs_resolver: Arc<LspIsCjsResolver>,
|
||||
jsr_search_api: CliJsrSearchApi,
|
||||
/// Handles module registries, which allow discovery of modules
|
||||
module_registry: ModuleRegistry,
|
||||
|
@ -484,7 +482,6 @@ impl Inner {
|
|||
let initial_cwd = std::env::current_dir().unwrap_or_else(|_| {
|
||||
panic!("Could not resolve current working directory")
|
||||
});
|
||||
let is_cjs_resolver = Arc::new(LspIsCjsResolver::new(&cache));
|
||||
|
||||
Self {
|
||||
assets,
|
||||
|
@ -496,7 +493,6 @@ impl Inner {
|
|||
documents,
|
||||
http_client_provider,
|
||||
initial_cwd: initial_cwd.clone(),
|
||||
is_cjs_resolver,
|
||||
jsr_search_api,
|
||||
project_version: 0,
|
||||
task_queue: Default::default(),
|
||||
|
@ -607,7 +603,6 @@ impl Inner {
|
|||
project_version: self.project_version,
|
||||
assets: self.assets.snapshot(),
|
||||
config: Arc::new(self.config.clone()),
|
||||
is_cjs_resolver: self.is_cjs_resolver.clone(),
|
||||
documents: Arc::new(self.documents.clone()),
|
||||
resolver: self.resolver.snapshot(),
|
||||
})
|
||||
|
@ -629,7 +624,6 @@ impl Inner {
|
|||
}
|
||||
});
|
||||
self.cache = LspCache::new(global_cache_url);
|
||||
self.is_cjs_resolver = Arc::new(LspIsCjsResolver::new(&self.cache));
|
||||
let deno_dir = self.cache.deno_dir();
|
||||
let workspace_settings = self.config.workspace_settings();
|
||||
let maybe_root_path = self
|
||||
|
@ -993,13 +987,10 @@ impl Inner {
|
|||
let resolver = inner.resolver.as_cli_resolver(Some(&referrer));
|
||||
let Ok(specifier) = resolver.resolve(
|
||||
&specifier,
|
||||
&deno_graph::Range {
|
||||
specifier: referrer.clone(),
|
||||
start: deno_graph::Position::zeroed(),
|
||||
end: deno_graph::Position::zeroed(),
|
||||
},
|
||||
NodeModuleKind::Esm,
|
||||
deno_graph::source::ResolutionMode::Types,
|
||||
&referrer,
|
||||
deno_graph::Position::zeroed(),
|
||||
ResolutionMode::Import,
|
||||
NodeResolutionKind::Types,
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
|
@ -1640,8 +1631,8 @@ impl Inner {
|
|||
.get_ts_diagnostics(&specifier, asset_or_doc.document_lsp_version());
|
||||
let specifier_kind = asset_or_doc
|
||||
.document()
|
||||
.map(|d| self.is_cjs_resolver.get_doc_module_kind(d))
|
||||
.unwrap_or(NodeModuleKind::Esm);
|
||||
.map(|d| d.resolution_mode())
|
||||
.unwrap_or(ResolutionMode::Import);
|
||||
let mut includes_no_cache = false;
|
||||
for diagnostic in &fixable_diagnostics {
|
||||
match diagnostic.source.as_deref() {
|
||||
|
@ -1864,8 +1855,8 @@ impl Inner {
|
|||
maybe_asset_or_doc
|
||||
.as_ref()
|
||||
.and_then(|d| d.document())
|
||||
.map(|d| self.is_cjs_resolver.get_doc_module_kind(d))
|
||||
.unwrap_or(NodeModuleKind::Esm),
|
||||
.map(|d| d.resolution_mode())
|
||||
.unwrap_or(ResolutionMode::Import),
|
||||
&combined_code_actions.changes,
|
||||
self,
|
||||
)
|
||||
|
@ -1921,8 +1912,8 @@ impl Inner {
|
|||
&action_data.specifier,
|
||||
asset_or_doc
|
||||
.document()
|
||||
.map(|d| self.is_cjs_resolver.get_doc_module_kind(d))
|
||||
.unwrap_or(NodeModuleKind::Esm),
|
||||
.map(|d| d.resolution_mode())
|
||||
.unwrap_or(ResolutionMode::Import),
|
||||
&refactor_edit_info.edits,
|
||||
self,
|
||||
)
|
||||
|
@ -2272,7 +2263,6 @@ impl Inner {
|
|||
&self.jsr_search_api,
|
||||
&self.npm_search_api,
|
||||
&self.documents,
|
||||
&self.is_cjs_resolver,
|
||||
self.resolver.as_ref(),
|
||||
self
|
||||
.config
|
||||
|
|
|
@ -9,13 +9,12 @@ use deno_config::workspace::PackageJsonDepResolution;
|
|||
use deno_config::workspace::WorkspaceResolver;
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::url::Url;
|
||||
use deno_graph::source::ResolutionMode;
|
||||
use deno_graph::GraphImport;
|
||||
use deno_graph::ModuleSpecifier;
|
||||
use deno_graph::Range;
|
||||
use deno_npm::NpmSystemInfo;
|
||||
use deno_path_util::url_from_directory_path;
|
||||
use deno_path_util::url_to_file_path;
|
||||
use deno_resolver::cjs::IsCjsResolutionMode;
|
||||
use deno_resolver::npm::NpmReqResolverOptions;
|
||||
use deno_resolver::DenoResolverOptions;
|
||||
use deno_resolver::NodeAndNpmReqResolver;
|
||||
|
@ -30,8 +29,8 @@ use deno_semver::package::PackageReq;
|
|||
use indexmap::IndexMap;
|
||||
use node_resolver::errors::ClosestPkgJsonError;
|
||||
use node_resolver::InNpmPackageChecker;
|
||||
use node_resolver::NodeModuleKind;
|
||||
use node_resolver::NodeResolutionMode;
|
||||
use node_resolver::NodeResolutionKind;
|
||||
use node_resolver::ResolutionMode;
|
||||
use std::borrow::Cow;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::BTreeSet;
|
||||
|
@ -40,7 +39,6 @@ use std::collections::HashSet;
|
|||
use std::sync::Arc;
|
||||
|
||||
use super::cache::LspCache;
|
||||
use super::documents::Document;
|
||||
use super::jsr::JsrCacheResolver;
|
||||
use crate::args::create_default_npmrc;
|
||||
use crate::args::CacheSetting;
|
||||
|
@ -48,6 +46,8 @@ use crate::args::CliLockfile;
|
|||
use crate::args::NpmInstallDepsProvider;
|
||||
use crate::cache::DenoCacheEnvFsAdapter;
|
||||
use crate::factory::Deferred;
|
||||
use crate::graph_util::to_node_resolution_kind;
|
||||
use crate::graph_util::to_node_resolution_mode;
|
||||
use crate::graph_util::CliJsrUrlProvider;
|
||||
use crate::http_util::HttpClientProvider;
|
||||
use crate::lsp::config::Config;
|
||||
|
@ -70,7 +70,6 @@ use crate::resolver::CliResolverOptions;
|
|||
use crate::resolver::IsCjsResolver;
|
||||
use crate::resolver::WorkerCliNpmGraphResolver;
|
||||
use crate::tsc::into_specifier_and_media_type;
|
||||
use crate::util::fs::canonicalize_path_maybe_not_exists;
|
||||
use crate::util::progress_bar::ProgressBar;
|
||||
use crate::util::progress_bar::ProgressBarStyle;
|
||||
|
||||
|
@ -78,6 +77,7 @@ use crate::util::progress_bar::ProgressBarStyle;
|
|||
struct LspScopeResolver {
|
||||
resolver: Arc<CliResolver>,
|
||||
in_npm_pkg_checker: Arc<dyn InNpmPackageChecker>,
|
||||
is_cjs_resolver: Arc<IsCjsResolver>,
|
||||
jsr_resolver: Option<Arc<JsrCacheResolver>>,
|
||||
npm_resolver: Option<Arc<dyn CliNpmResolver>>,
|
||||
node_resolver: Option<Arc<NodeResolver>>,
|
||||
|
@ -96,6 +96,7 @@ impl Default for LspScopeResolver {
|
|||
Self {
|
||||
resolver: factory.cli_resolver().clone(),
|
||||
in_npm_pkg_checker: factory.in_npm_pkg_checker().clone(),
|
||||
is_cjs_resolver: factory.is_cjs_resolver().clone(),
|
||||
jsr_resolver: None,
|
||||
npm_resolver: None,
|
||||
node_resolver: None,
|
||||
|
@ -146,7 +147,7 @@ impl LspScopeResolver {
|
|||
.map(|(referrer, imports)| {
|
||||
let resolver = SingleReferrerGraphResolver {
|
||||
valid_referrer: &referrer,
|
||||
referrer_kind: NodeModuleKind::Esm,
|
||||
module_resolution_mode: ResolutionMode::Import,
|
||||
cli_resolver: &cli_resolver,
|
||||
jsx_import_source_config: maybe_jsx_import_source_config
|
||||
.as_ref(),
|
||||
|
@ -180,16 +181,16 @@ impl LspScopeResolver {
|
|||
&req_ref,
|
||||
&referrer,
|
||||
// todo(dsherret): this is wrong because it doesn't consider CJS referrers
|
||||
NodeModuleKind::Esm,
|
||||
NodeResolutionMode::Types,
|
||||
ResolutionMode::Import,
|
||||
NodeResolutionKind::Types,
|
||||
)
|
||||
.or_else(|_| {
|
||||
npm_pkg_req_resolver.resolve_req_reference(
|
||||
&req_ref,
|
||||
&referrer,
|
||||
// todo(dsherret): this is wrong because it doesn't consider CJS referrers
|
||||
NodeModuleKind::Esm,
|
||||
NodeResolutionMode::Execution,
|
||||
ResolutionMode::Import,
|
||||
NodeResolutionKind::Execution,
|
||||
)
|
||||
})
|
||||
.ok()?,
|
||||
|
@ -205,6 +206,7 @@ impl LspScopeResolver {
|
|||
Self {
|
||||
resolver: cli_resolver,
|
||||
in_npm_pkg_checker,
|
||||
is_cjs_resolver: factory.is_cjs_resolver().clone(),
|
||||
jsr_resolver,
|
||||
npm_pkg_req_resolver,
|
||||
npm_resolver,
|
||||
|
@ -228,6 +230,7 @@ impl LspScopeResolver {
|
|||
Arc::new(Self {
|
||||
resolver: factory.cli_resolver().clone(),
|
||||
in_npm_pkg_checker: factory.in_npm_pkg_checker().clone(),
|
||||
is_cjs_resolver: factory.is_cjs_resolver().clone(),
|
||||
jsr_resolver: self.jsr_resolver.clone(),
|
||||
npm_pkg_req_resolver: factory.npm_pkg_req_resolver().cloned(),
|
||||
npm_resolver: factory.npm_resolver().cloned(),
|
||||
|
@ -345,6 +348,14 @@ impl LspResolver {
|
|||
resolver.resolver.create_graph_npm_resolver()
|
||||
}
|
||||
|
||||
pub fn as_is_cjs_resolver(
|
||||
&self,
|
||||
file_referrer: Option<&ModuleSpecifier>,
|
||||
) -> &IsCjsResolver {
|
||||
let resolver = self.get_scope_resolver(file_referrer);
|
||||
resolver.is_cjs_resolver.as_ref()
|
||||
}
|
||||
|
||||
pub fn as_config_data(
|
||||
&self,
|
||||
file_referrer: Option<&ModuleSpecifier>,
|
||||
|
@ -424,7 +435,7 @@ impl LspResolver {
|
|||
&self,
|
||||
req_ref: &NpmPackageReqReference,
|
||||
referrer: &ModuleSpecifier,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
file_referrer: Option<&ModuleSpecifier>,
|
||||
) -> Option<(ModuleSpecifier, MediaType)> {
|
||||
let resolver = self.get_scope_resolver(file_referrer);
|
||||
|
@ -434,8 +445,8 @@ impl LspResolver {
|
|||
.resolve_req_reference(
|
||||
req_ref,
|
||||
referrer,
|
||||
referrer_kind,
|
||||
NodeResolutionMode::Types,
|
||||
resolution_mode,
|
||||
NodeResolutionKind::Types,
|
||||
)
|
||||
.ok()?,
|
||||
)))
|
||||
|
@ -492,7 +503,7 @@ impl LspResolver {
|
|||
&self,
|
||||
specifier_text: &str,
|
||||
referrer: &ModuleSpecifier,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
) -> bool {
|
||||
let resolver = self.get_scope_resolver(Some(referrer));
|
||||
let Some(npm_pkg_req_resolver) = resolver.npm_pkg_req_resolver.as_ref()
|
||||
|
@ -503,8 +514,8 @@ impl LspResolver {
|
|||
.resolve_if_for_npm_pkg(
|
||||
specifier_text,
|
||||
referrer,
|
||||
referrer_kind,
|
||||
NodeResolutionMode::Types,
|
||||
resolution_mode,
|
||||
NodeResolutionKind::Types,
|
||||
)
|
||||
.ok()
|
||||
.flatten()
|
||||
|
@ -581,6 +592,7 @@ pub struct ScopeDepInfo {
|
|||
struct ResolverFactoryServices {
|
||||
cli_resolver: Deferred<Arc<CliResolver>>,
|
||||
in_npm_pkg_checker: Deferred<Arc<dyn InNpmPackageChecker>>,
|
||||
is_cjs_resolver: Deferred<Arc<IsCjsResolver>>,
|
||||
node_resolver: Deferred<Option<Arc<NodeResolver>>>,
|
||||
npm_pkg_req_resolver: Deferred<Option<Arc<CliNpmReqResolver>>>,
|
||||
npm_resolver: Option<Arc<dyn CliNpmResolver>>,
|
||||
|
@ -744,6 +756,23 @@ impl<'a> ResolverFactory<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn is_cjs_resolver(&self) -> &Arc<IsCjsResolver> {
|
||||
self.services.is_cjs_resolver.get_or_init(|| {
|
||||
Arc::new(IsCjsResolver::new(
|
||||
self.in_npm_pkg_checker().clone(),
|
||||
self.pkg_json_resolver().clone(),
|
||||
if self
|
||||
.config_data
|
||||
.is_some_and(|d| d.unstable.contains("detect-cjs"))
|
||||
{
|
||||
IsCjsResolutionMode::ImplicitTypeCommonJs
|
||||
} else {
|
||||
IsCjsResolutionMode::ExplicitTypeCommonJs
|
||||
},
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn node_resolver(&self) -> Option<&Arc<NodeResolver>> {
|
||||
self
|
||||
.services
|
||||
|
@ -803,99 +832,10 @@ impl std::fmt::Debug for RedirectResolver {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct LspIsCjsResolver {
|
||||
inner: IsCjsResolver,
|
||||
}
|
||||
|
||||
impl Default for LspIsCjsResolver {
|
||||
fn default() -> Self {
|
||||
LspIsCjsResolver::new(&Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl LspIsCjsResolver {
|
||||
pub fn new(cache: &LspCache) -> Self {
|
||||
#[derive(Debug)]
|
||||
struct LspInNpmPackageChecker {
|
||||
global_cache_dir: ModuleSpecifier,
|
||||
}
|
||||
|
||||
impl LspInNpmPackageChecker {
|
||||
pub fn new(cache: &LspCache) -> Self {
|
||||
let npm_folder_path = cache.deno_dir().npm_folder_path();
|
||||
Self {
|
||||
global_cache_dir: url_from_directory_path(
|
||||
&canonicalize_path_maybe_not_exists(&npm_folder_path)
|
||||
.unwrap_or(npm_folder_path),
|
||||
)
|
||||
.unwrap_or_else(|_| {
|
||||
ModuleSpecifier::parse("file:///invalid/").unwrap()
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl InNpmPackageChecker for LspInNpmPackageChecker {
|
||||
fn in_npm_package(&self, specifier: &ModuleSpecifier) -> bool {
|
||||
if specifier.scheme() != "file" {
|
||||
return false;
|
||||
}
|
||||
if specifier
|
||||
.as_str()
|
||||
.starts_with(self.global_cache_dir.as_str())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
specifier.as_str().contains("/node_modules/")
|
||||
}
|
||||
}
|
||||
|
||||
let fs = Arc::new(deno_fs::RealFs);
|
||||
let pkg_json_resolver = Arc::new(PackageJsonResolver::new(
|
||||
deno_runtime::deno_node::DenoFsNodeResolverEnv::new(fs.clone()),
|
||||
));
|
||||
|
||||
LspIsCjsResolver {
|
||||
inner: IsCjsResolver::new(
|
||||
Arc::new(LspInNpmPackageChecker::new(cache)),
|
||||
pkg_json_resolver,
|
||||
crate::resolver::IsCjsResolverOptions {
|
||||
detect_cjs: true,
|
||||
is_node_main: false,
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_maybe_doc_module_kind(
|
||||
&self,
|
||||
specifier: &ModuleSpecifier,
|
||||
maybe_document: Option<&Document>,
|
||||
) -> NodeModuleKind {
|
||||
self.get_lsp_referrer_kind(
|
||||
specifier,
|
||||
maybe_document.and_then(|d| d.is_script()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn get_doc_module_kind(&self, document: &Document) -> NodeModuleKind {
|
||||
self.get_lsp_referrer_kind(document.specifier(), document.is_script())
|
||||
}
|
||||
|
||||
pub fn get_lsp_referrer_kind(
|
||||
&self,
|
||||
specifier: &ModuleSpecifier,
|
||||
is_script: Option<bool>,
|
||||
) -> NodeModuleKind {
|
||||
self.inner.get_lsp_referrer_kind(specifier, is_script)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SingleReferrerGraphResolver<'a> {
|
||||
pub valid_referrer: &'a ModuleSpecifier,
|
||||
pub referrer_kind: NodeModuleKind,
|
||||
pub module_resolution_mode: ResolutionMode,
|
||||
pub cli_resolver: &'a CliResolver,
|
||||
pub jsx_import_source_config: Option<&'a JsxImportSourceConfig>,
|
||||
}
|
||||
|
@ -924,16 +864,20 @@ impl<'a> deno_graph::source::Resolver for SingleReferrerGraphResolver<'a> {
|
|||
&self,
|
||||
specifier_text: &str,
|
||||
referrer_range: &Range,
|
||||
mode: ResolutionMode,
|
||||
resolution_kind: deno_graph::source::ResolutionKind,
|
||||
) -> Result<ModuleSpecifier, deno_graph::source::ResolveError> {
|
||||
// this resolver assumes it will only be used with a single referrer
|
||||
// with the provided referrer kind
|
||||
debug_assert_eq!(referrer_range.specifier, *self.valid_referrer);
|
||||
self.cli_resolver.resolve(
|
||||
specifier_text,
|
||||
referrer_range,
|
||||
self.referrer_kind,
|
||||
mode,
|
||||
&referrer_range.specifier,
|
||||
referrer_range.range.start,
|
||||
referrer_range
|
||||
.resolution_mode
|
||||
.map(to_node_resolution_mode)
|
||||
.unwrap_or(self.module_resolution_mode),
|
||||
to_node_resolution_kind(resolution_kind),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ use indexmap::IndexMap;
|
|||
use indexmap::IndexSet;
|
||||
use lazy_regex::lazy_regex;
|
||||
use log::error;
|
||||
use node_resolver::NodeModuleKind;
|
||||
use node_resolver::ResolutionMode;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Captures;
|
||||
use regex::Regex;
|
||||
|
@ -4449,9 +4449,9 @@ fn op_load<'s>(
|
|||
version: state.script_version(&specifier),
|
||||
is_cjs: doc
|
||||
.document()
|
||||
.map(|d| state.state_snapshot.is_cjs_resolver.get_doc_module_kind(d))
|
||||
.unwrap_or(NodeModuleKind::Esm)
|
||||
== NodeModuleKind::Cjs,
|
||||
.map(|d| d.resolution_mode())
|
||||
.unwrap_or(ResolutionMode::Import)
|
||||
== ResolutionMode::Require,
|
||||
})
|
||||
};
|
||||
let serialized = serde_v8::to_v8(scope, maybe_load_response)?;
|
||||
|
@ -4479,17 +4479,9 @@ fn op_release(
|
|||
fn op_resolve(
|
||||
state: &mut OpState,
|
||||
#[string] base: String,
|
||||
is_base_cjs: bool,
|
||||
#[serde] specifiers: Vec<String>,
|
||||
#[serde] specifiers: Vec<(bool, String)>,
|
||||
) -> Result<Vec<Option<(String, String)>>, AnyError> {
|
||||
op_resolve_inner(
|
||||
state,
|
||||
ResolveArgs {
|
||||
base,
|
||||
is_base_cjs,
|
||||
specifiers,
|
||||
},
|
||||
)
|
||||
op_resolve_inner(state, ResolveArgs { base, specifiers })
|
||||
}
|
||||
|
||||
struct TscRequestArray {
|
||||
|
@ -4692,10 +4684,7 @@ fn op_script_names(state: &mut OpState) -> ScriptNames {
|
|||
let (types, _) = documents.resolve_dependency(
|
||||
types,
|
||||
specifier,
|
||||
state
|
||||
.state_snapshot
|
||||
.is_cjs_resolver
|
||||
.get_doc_module_kind(doc),
|
||||
doc.resolution_mode(),
|
||||
doc.file_referrer(),
|
||||
)?;
|
||||
let types_doc = documents.get_or_load(&types, doc.file_referrer())?;
|
||||
|
@ -5579,7 +5568,6 @@ mod tests {
|
|||
documents: Arc::new(documents),
|
||||
assets: Default::default(),
|
||||
config: Arc::new(config),
|
||||
is_cjs_resolver: Default::default(),
|
||||
resolver,
|
||||
});
|
||||
let performance = Arc::new(Performance::default());
|
||||
|
@ -6430,8 +6418,7 @@ mod tests {
|
|||
&mut state,
|
||||
ResolveArgs {
|
||||
base: temp_dir.url().join("a.ts").unwrap().to_string(),
|
||||
is_base_cjs: false,
|
||||
specifiers: vec!["./b.ts".to_string()],
|
||||
specifiers: vec![(false, "./b.ts".to_string())],
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
|
|
@ -448,7 +448,7 @@ fn resolve_flags_and_init(
|
|||
};
|
||||
|
||||
if let Some(otel_config) = flags.otel_config() {
|
||||
deno_runtime::ops::otel::init(otel_config)?;
|
||||
deno_telemetry::init(otel_config)?;
|
||||
}
|
||||
util::logger::init(flags.log_level);
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ fn main() {
|
|||
match standalone {
|
||||
Ok(Some(data)) => {
|
||||
if let Some(otel_config) = data.metadata.otel_config.clone() {
|
||||
deno_runtime::ops::otel::init(otel_config)?;
|
||||
deno_telemetry::init(otel_config)?;
|
||||
}
|
||||
util::logger::init(data.metadata.log_level);
|
||||
load_env_vars(&data.metadata.env_vars_from_env_file);
|
||||
|
|
|
@ -58,9 +58,7 @@ use deno_core::ModuleSourceCode;
|
|||
use deno_core::ModuleSpecifier;
|
||||
use deno_core::ModuleType;
|
||||
use deno_core::RequestedModuleType;
|
||||
use deno_core::ResolutionKind;
|
||||
use deno_core::SourceCodeCacheInfo;
|
||||
use deno_graph::source::ResolutionMode;
|
||||
use deno_graph::GraphKind;
|
||||
use deno_graph::JsModule;
|
||||
use deno_graph::JsonModule;
|
||||
|
@ -77,7 +75,8 @@ use deno_runtime::deno_permissions::PermissionsContainer;
|
|||
use deno_semver::npm::NpmPackageReqReference;
|
||||
use node_resolver::errors::ClosestPkgJsonError;
|
||||
use node_resolver::InNpmPackageChecker;
|
||||
use node_resolver::NodeResolutionMode;
|
||||
use node_resolver::NodeResolutionKind;
|
||||
use node_resolver::ResolutionMode;
|
||||
|
||||
pub struct ModuleLoadPreparer {
|
||||
options: Arc<CliOptions>,
|
||||
|
@ -499,13 +498,11 @@ impl<TGraphContainer: ModuleGraphContainer>
|
|||
}
|
||||
Resolution::None => Cow::Owned(self.shared.resolver.resolve(
|
||||
raw_specifier,
|
||||
&deno_graph::Range {
|
||||
specifier: referrer.clone(),
|
||||
start: deno_graph::Position::zeroed(),
|
||||
end: deno_graph::Position::zeroed(),
|
||||
},
|
||||
self.shared.cjs_tracker.get_referrer_kind(referrer),
|
||||
ResolutionMode::Execution,
|
||||
referrer,
|
||||
deno_graph::Position::zeroed(),
|
||||
// if we're here, that means it's resolving a dynamic import
|
||||
ResolutionMode::Import,
|
||||
NodeResolutionKind::Execution,
|
||||
)?),
|
||||
};
|
||||
|
||||
|
@ -518,8 +515,8 @@ impl<TGraphContainer: ModuleGraphContainer>
|
|||
.resolve_req_reference(
|
||||
&reference,
|
||||
referrer,
|
||||
self.shared.cjs_tracker.get_referrer_kind(referrer),
|
||||
NodeResolutionMode::Execution,
|
||||
ResolutionMode::Import,
|
||||
NodeResolutionKind::Execution,
|
||||
)
|
||||
.map_err(AnyError::from);
|
||||
}
|
||||
|
@ -540,8 +537,8 @@ impl<TGraphContainer: ModuleGraphContainer>
|
|||
&package_folder,
|
||||
module.nv_reference.sub_path(),
|
||||
Some(referrer),
|
||||
self.shared.cjs_tracker.get_referrer_kind(referrer),
|
||||
NodeResolutionMode::Execution,
|
||||
ResolutionMode::Import,
|
||||
NodeResolutionKind::Execution,
|
||||
)
|
||||
.with_context(|| {
|
||||
format!("Could not resolve '{}'.", module.nv_reference)
|
||||
|
@ -807,7 +804,7 @@ impl<TGraphContainer: ModuleGraphContainer> ModuleLoader
|
|||
&self,
|
||||
specifier: &str,
|
||||
referrer: &str,
|
||||
_kind: ResolutionKind,
|
||||
_kind: deno_core::ResolutionKind,
|
||||
) -> Result<ModuleSpecifier, AnyError> {
|
||||
fn ensure_not_jsr_non_jsr_remote_import(
|
||||
specifier: &ModuleSpecifier,
|
||||
|
|
|
@ -182,6 +182,12 @@ impl<'a> LifecycleScripts<'a> {
|
|||
);
|
||||
|
||||
let mut env_vars = crate::task_runner::real_env_vars();
|
||||
// so the subprocess can detect that it is running as part of a lifecycle script,
|
||||
// and avoid trying to set up node_modules again
|
||||
env_vars.insert(
|
||||
LIFECYCLE_SCRIPTS_RUNNING_ENV_VAR.to_string(),
|
||||
"1".to_string(),
|
||||
);
|
||||
// we want to pass the current state of npm resolution down to the deno subprocess
|
||||
// (that may be running as part of the script). we do this with an inherited temp file
|
||||
//
|
||||
|
@ -303,6 +309,13 @@ impl<'a> LifecycleScripts<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
const LIFECYCLE_SCRIPTS_RUNNING_ENV_VAR: &str =
|
||||
"DENO_INTERNAL_IS_LIFECYCLE_SCRIPT";
|
||||
|
||||
pub fn is_running_lifecycle_script() -> bool {
|
||||
std::env::var(LIFECYCLE_SCRIPTS_RUNNING_ENV_VAR).is_ok()
|
||||
}
|
||||
|
||||
// take in all (non copy) packages from snapshot,
|
||||
// and resolve the set of available binaries to create
|
||||
// custom commands available to the task runner
|
||||
|
|
|
@ -298,6 +298,12 @@ async fn sync_resolution_with_fs(
|
|||
return Ok(()); // don't create the directory
|
||||
}
|
||||
|
||||
// don't set up node_modules (and more importantly try to acquire the file lock)
|
||||
// if we're running as part of a lifecycle script
|
||||
if super::common::lifecycle_scripts::is_running_lifecycle_script() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let deno_local_registry_dir = root_node_modules_dir_path.join(".deno");
|
||||
let deno_node_modules_dir = deno_local_registry_dir.join("node_modules");
|
||||
fs::create_dir_all(&deno_node_modules_dir).with_context(|| {
|
||||
|
|
|
@ -12,7 +12,6 @@ use deno_core::error::AnyError;
|
|||
use deno_core::url::Url;
|
||||
use deno_core::ModuleSourceCode;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use deno_graph::source::ResolutionMode;
|
||||
use deno_graph::source::ResolveError;
|
||||
use deno_graph::source::UnknownBuiltInNodeModuleError;
|
||||
use deno_graph::NpmLoadError;
|
||||
|
@ -25,8 +24,8 @@ use deno_runtime::deno_fs::FileSystem;
|
|||
use deno_runtime::deno_node::is_builtin_node_module;
|
||||
use deno_runtime::deno_node::DenoFsNodeResolverEnv;
|
||||
use deno_semver::package::PackageReq;
|
||||
use node_resolver::NodeModuleKind;
|
||||
use node_resolver::NodeResolutionMode;
|
||||
use node_resolver::NodeResolutionKind;
|
||||
use node_resolver::ResolutionMode;
|
||||
use std::borrow::Cow;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
@ -43,7 +42,6 @@ use crate::util::text_encoding::from_utf8_lossy_owned;
|
|||
pub type CjsTracker = deno_resolver::cjs::CjsTracker<DenoFsNodeResolverEnv>;
|
||||
pub type IsCjsResolver =
|
||||
deno_resolver::cjs::IsCjsResolver<DenoFsNodeResolverEnv>;
|
||||
pub type IsCjsResolverOptions = deno_resolver::cjs::IsCjsResolverOptions;
|
||||
pub type CliSloppyImportsResolver =
|
||||
SloppyImportsResolver<SloppyImportsCachedFs>;
|
||||
pub type CliDenoResolver = deno_resolver::DenoResolver<
|
||||
|
@ -247,25 +245,14 @@ impl CliResolver {
|
|||
pub fn resolve(
|
||||
&self,
|
||||
raw_specifier: &str,
|
||||
referrer_range: &deno_graph::Range,
|
||||
referrer_kind: NodeModuleKind,
|
||||
mode: ResolutionMode,
|
||||
referrer: &ModuleSpecifier,
|
||||
referrer_range_start: deno_graph::Position,
|
||||
resolution_mode: ResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<ModuleSpecifier, ResolveError> {
|
||||
fn to_node_mode(mode: ResolutionMode) -> NodeResolutionMode {
|
||||
match mode {
|
||||
ResolutionMode::Execution => NodeResolutionMode::Execution,
|
||||
ResolutionMode::Types => NodeResolutionMode::Types,
|
||||
}
|
||||
}
|
||||
|
||||
let resolution = self
|
||||
.deno_resolver
|
||||
.resolve(
|
||||
raw_specifier,
|
||||
&referrer_range.specifier,
|
||||
referrer_kind,
|
||||
to_node_mode(mode),
|
||||
)
|
||||
.resolve(raw_specifier, referrer, resolution_mode, resolution_kind)
|
||||
.map_err(|err| match err.into_kind() {
|
||||
deno_resolver::DenoResolveErrorKind::MappedResolution(
|
||||
mapped_resolution_error,
|
||||
|
@ -291,10 +278,11 @@ impl CliResolver {
|
|||
} => {
|
||||
if self.warned_pkgs.insert(reference.req().clone()) {
|
||||
log::warn!(
|
||||
"{} {}\n at {}",
|
||||
"{} {}\n at {}:{}",
|
||||
colors::yellow("Warning"),
|
||||
diagnostic,
|
||||
referrer_range
|
||||
referrer,
|
||||
referrer_range_start,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -335,13 +323,10 @@ impl<'a> deno_graph::source::NpmResolver for WorkerCliNpmGraphResolver<'a> {
|
|||
module_name: &str,
|
||||
range: &deno_graph::Range,
|
||||
) {
|
||||
let deno_graph::Range {
|
||||
start, specifier, ..
|
||||
} = range;
|
||||
let line = start.line + 1;
|
||||
let column = start.character + 1;
|
||||
let start = range.range.start;
|
||||
let specifier = &range.specifier;
|
||||
if !*DENO_DISABLE_PEDANTIC_NODE_WARNINGS {
|
||||
log::warn!("{} Resolving \"{module_name}\" as \"node:{module_name}\" at {specifier}:{line}:{column}. If you want to use a built-in Node module, add a \"node:\" prefix.", colors::yellow("Warning"))
|
||||
log::warn!("{} Resolving \"{module_name}\" as \"node:{module_name}\" at {specifier}:{start}. If you want to use a built-in Node module, add a \"node:\" prefix.", colors::yellow("Warning"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -554,6 +554,7 @@
|
|||
"bare-node-builtins",
|
||||
"byonm",
|
||||
"cron",
|
||||
"detect-cjs",
|
||||
"ffi",
|
||||
"fs",
|
||||
"fmt-component",
|
||||
|
|
|
@ -4,6 +4,7 @@ use std::borrow::Cow;
|
|||
use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::VecDeque;
|
||||
use std::env;
|
||||
use std::env::current_exe;
|
||||
use std::ffi::OsString;
|
||||
use std::fs;
|
||||
|
@ -15,6 +16,7 @@ use std::io::Seek;
|
|||
use std::io::SeekFrom;
|
||||
use std::io::Write;
|
||||
use std::ops::Range;
|
||||
use std::path::Component;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
@ -47,11 +49,11 @@ use deno_runtime::deno_fs::FileSystem;
|
|||
use deno_runtime::deno_fs::RealFs;
|
||||
use deno_runtime::deno_io::fs::FsError;
|
||||
use deno_runtime::deno_node::PackageJson;
|
||||
use deno_runtime::ops::otel::OtelConfig;
|
||||
use deno_semver::npm::NpmVersionReqParseError;
|
||||
use deno_semver::package::PackageReq;
|
||||
use deno_semver::Version;
|
||||
use deno_semver::VersionReqSpecifierParseError;
|
||||
use deno_telemetry::OtelConfig;
|
||||
use indexmap::IndexMap;
|
||||
use log::Level;
|
||||
use serde::Deserialize;
|
||||
|
@ -457,7 +459,7 @@ impl<'a> DenoCompileBinaryWriter<'a> {
|
|||
//
|
||||
// Phase 2 of the 'min sized' deno compile RFC talks
|
||||
// about adding this as a flag.
|
||||
if let Some(path) = std::env::var_os("DENORT_BIN") {
|
||||
if let Some(path) = get_dev_binary_path() {
|
||||
return std::fs::read(&path).with_context(|| {
|
||||
format!("Could not find denort at '{}'", path.to_string_lossy())
|
||||
});
|
||||
|
@ -775,6 +777,7 @@ impl<'a> DenoCompileBinaryWriter<'a> {
|
|||
unstable_config: UnstableConfig {
|
||||
legacy_flag_enabled: false,
|
||||
bare_node_builtins: self.cli_options.unstable_bare_node_builtins(),
|
||||
detect_cjs: self.cli_options.unstable_detect_cjs(),
|
||||
sloppy_imports: self.cli_options.unstable_sloppy_imports(),
|
||||
features: self.cli_options.unstable_features(),
|
||||
},
|
||||
|
@ -908,6 +911,31 @@ impl<'a> DenoCompileBinaryWriter<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_denort_path(deno_exe: PathBuf) -> Option<OsString> {
|
||||
let mut denort = deno_exe;
|
||||
denort.set_file_name(if cfg!(windows) {
|
||||
"denort.exe"
|
||||
} else {
|
||||
"denort"
|
||||
});
|
||||
denort.exists().then(|| denort.into_os_string())
|
||||
}
|
||||
|
||||
fn get_dev_binary_path() -> Option<OsString> {
|
||||
env::var_os("DENORT_BIN").or_else(|| {
|
||||
env::current_exe().ok().and_then(|exec_path| {
|
||||
if exec_path
|
||||
.components()
|
||||
.any(|component| component == Component::Normal("target".as_ref()))
|
||||
{
|
||||
get_denort_path(exec_path)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// This function returns the environment variables specified
|
||||
/// in the passed environment file.
|
||||
fn get_file_env_vars(
|
||||
|
|
|
@ -32,6 +32,7 @@ use deno_core::ResolutionKind;
|
|||
use deno_core::SourceCodeCacheInfo;
|
||||
use deno_npm::npm_rc::ResolvedNpmRc;
|
||||
use deno_package_json::PackageJsonDepValue;
|
||||
use deno_resolver::cjs::IsCjsResolutionMode;
|
||||
use deno_resolver::npm::NpmReqResolverOptions;
|
||||
use deno_runtime::deno_fs;
|
||||
use deno_runtime::deno_node::create_host_defined_options;
|
||||
|
@ -50,8 +51,8 @@ use deno_semver::npm::NpmPackageReqReference;
|
|||
use import_map::parse_from_json;
|
||||
use node_resolver::analyze::NodeCodeTranslator;
|
||||
use node_resolver::errors::ClosestPkgJsonError;
|
||||
use node_resolver::NodeModuleKind;
|
||||
use node_resolver::NodeResolutionMode;
|
||||
use node_resolver::NodeResolutionKind;
|
||||
use node_resolver::ResolutionMode;
|
||||
use serialization::DenoCompileModuleSource;
|
||||
use std::borrow::Cow;
|
||||
use std::rc::Rc;
|
||||
|
@ -87,7 +88,6 @@ use crate::npm::CreateInNpmPkgCheckerOptions;
|
|||
use crate::resolver::CjsTracker;
|
||||
use crate::resolver::CliDenoResolverFs;
|
||||
use crate::resolver::CliNpmReqResolver;
|
||||
use crate::resolver::IsCjsResolverOptions;
|
||||
use crate::resolver::NpmModuleLoader;
|
||||
use crate::util::progress_bar::ProgressBar;
|
||||
use crate::util::progress_bar::ProgressBarStyle;
|
||||
|
@ -193,9 +193,9 @@ impl ModuleLoader for EmbeddedModuleLoader {
|
|||
.cjs_tracker
|
||||
.is_maybe_cjs(&referrer, MediaType::from_specifier(&referrer))?
|
||||
{
|
||||
NodeModuleKind::Cjs
|
||||
ResolutionMode::Require
|
||||
} else {
|
||||
NodeModuleKind::Esm
|
||||
ResolutionMode::Import
|
||||
};
|
||||
|
||||
if self.shared.node_resolver.in_npm_package(&referrer) {
|
||||
|
@ -207,7 +207,7 @@ impl ModuleLoader for EmbeddedModuleLoader {
|
|||
raw_specifier,
|
||||
&referrer,
|
||||
referrer_kind,
|
||||
NodeResolutionMode::Execution,
|
||||
NodeResolutionKind::Execution,
|
||||
)?
|
||||
.into_url(),
|
||||
);
|
||||
|
@ -235,7 +235,7 @@ impl ModuleLoader for EmbeddedModuleLoader {
|
|||
sub_path.as_deref(),
|
||||
Some(&referrer),
|
||||
referrer_kind,
|
||||
NodeResolutionMode::Execution,
|
||||
NodeResolutionKind::Execution,
|
||||
)?,
|
||||
),
|
||||
Ok(MappedResolution::PackageJson {
|
||||
|
@ -252,7 +252,7 @@ impl ModuleLoader for EmbeddedModuleLoader {
|
|||
sub_path.as_deref(),
|
||||
&referrer,
|
||||
referrer_kind,
|
||||
NodeResolutionMode::Execution,
|
||||
NodeResolutionKind::Execution,
|
||||
)
|
||||
.map_err(AnyError::from),
|
||||
PackageJsonDepValue::Workspace(version_req) => {
|
||||
|
@ -272,7 +272,7 @@ impl ModuleLoader for EmbeddedModuleLoader {
|
|||
sub_path.as_deref(),
|
||||
Some(&referrer),
|
||||
referrer_kind,
|
||||
NodeResolutionMode::Execution,
|
||||
NodeResolutionKind::Execution,
|
||||
)?,
|
||||
)
|
||||
}
|
||||
|
@ -286,7 +286,7 @@ impl ModuleLoader for EmbeddedModuleLoader {
|
|||
&reference,
|
||||
&referrer,
|
||||
referrer_kind,
|
||||
NodeResolutionMode::Execution,
|
||||
NodeResolutionKind::Execution,
|
||||
)?);
|
||||
}
|
||||
|
||||
|
@ -313,7 +313,7 @@ impl ModuleLoader for EmbeddedModuleLoader {
|
|||
raw_specifier,
|
||||
&referrer,
|
||||
referrer_kind,
|
||||
NodeResolutionMode::Execution,
|
||||
NodeResolutionKind::Execution,
|
||||
)?;
|
||||
if let Some(res) = maybe_res {
|
||||
return Ok(res.into_url());
|
||||
|
@ -731,9 +731,12 @@ pub async fn run(data: StandaloneData) -> Result<i32, AnyError> {
|
|||
let cjs_tracker = Arc::new(CjsTracker::new(
|
||||
in_npm_pkg_checker.clone(),
|
||||
pkg_json_resolver.clone(),
|
||||
IsCjsResolverOptions {
|
||||
detect_cjs: !metadata.workspace_resolver.package_jsons.is_empty(),
|
||||
is_node_main: false,
|
||||
if metadata.unstable_config.detect_cjs {
|
||||
IsCjsResolutionMode::ImplicitTypeCommonJs
|
||||
} else if metadata.workspace_resolver.package_jsons.is_empty() {
|
||||
IsCjsResolutionMode::Disabled
|
||||
} else {
|
||||
IsCjsResolutionMode::ExplicitTypeCommonJs
|
||||
},
|
||||
));
|
||||
let cache_db = Caches::new(deno_dir_provider.clone());
|
||||
|
|
|
@ -209,10 +209,14 @@ pub async fn doc(
|
|||
Default::default()
|
||||
};
|
||||
|
||||
let mut main_entrypoint = None;
|
||||
|
||||
let rewrite_map =
|
||||
if let Some(config_file) = cli_options.start_dir.maybe_deno_json() {
|
||||
let config = config_file.to_exports_config()?;
|
||||
|
||||
main_entrypoint = config.get_resolved(".").ok().flatten();
|
||||
|
||||
let rewrite_map = config
|
||||
.clone()
|
||||
.into_map()
|
||||
|
@ -240,6 +244,7 @@ pub async fn doc(
|
|||
html_options,
|
||||
deno_ns,
|
||||
rewrite_map,
|
||||
main_entrypoint,
|
||||
)
|
||||
} else {
|
||||
let modules_len = doc_nodes_by_url.len();
|
||||
|
@ -383,6 +388,7 @@ fn generate_docs_directory(
|
|||
html_options: &DocHtmlFlag,
|
||||
deno_ns: std::collections::HashMap<Vec<String>, Option<Rc<ShortPath>>>,
|
||||
rewrite_map: Option<IndexMap<ModuleSpecifier, String>>,
|
||||
main_entrypoint: Option<ModuleSpecifier>,
|
||||
) -> Result<(), AnyError> {
|
||||
let cwd = std::env::current_dir().context("Failed to get CWD")?;
|
||||
let output_dir_resolved = cwd.join(&html_options.output);
|
||||
|
@ -415,7 +421,7 @@ fn generate_docs_directory(
|
|||
|
||||
let options = deno_doc::html::GenerateOptions {
|
||||
package_name: html_options.name.clone(),
|
||||
main_entrypoint: None,
|
||||
main_entrypoint,
|
||||
rewrite_map,
|
||||
href_resolver: Rc::new(DocResolver {
|
||||
deno_ns,
|
||||
|
@ -427,33 +433,7 @@ fn generate_docs_directory(
|
|||
symbol_redirect_map,
|
||||
default_symbol_map,
|
||||
markdown_renderer: deno_doc::html::comrak::create_renderer(
|
||||
None,
|
||||
Some(Box::new(|ammonia| {
|
||||
ammonia.add_allowed_classes(
|
||||
"code",
|
||||
&[
|
||||
"language-ts",
|
||||
"language-tsx",
|
||||
"language-typescript",
|
||||
"language-js",
|
||||
"language-jsx",
|
||||
"language-javascript",
|
||||
"language-bash",
|
||||
"language-shell",
|
||||
"language-md",
|
||||
"language-markdown",
|
||||
"language-rs",
|
||||
"language-rust",
|
||||
"language-html",
|
||||
"language-xml",
|
||||
"language-css",
|
||||
"language-json",
|
||||
"language-regex",
|
||||
"language-svg",
|
||||
],
|
||||
);
|
||||
})),
|
||||
None,
|
||||
None, None, None,
|
||||
),
|
||||
markdown_stripper: Rc::new(deno_doc::html::comrak::strip),
|
||||
head_inject: Some(Rc::new(|root| {
|
||||
|
|
|
@ -235,22 +235,31 @@ fn add_npm_packages_to_json(
|
|||
.get_mut("dependencies")
|
||||
.and_then(|d| d.as_array_mut());
|
||||
if let Some(dependencies) = dependencies {
|
||||
for dep in dependencies.iter_mut() {
|
||||
if let serde_json::Value::Object(dep) = dep {
|
||||
let specifier = dep.get("specifier").and_then(|s| s.as_str());
|
||||
if let Some(specifier) = specifier {
|
||||
if let Ok(npm_ref) = NpmPackageReqReference::from_str(specifier) {
|
||||
if let Ok(pkg) =
|
||||
snapshot.resolve_pkg_from_pkg_req(npm_ref.req())
|
||||
{
|
||||
dep.insert(
|
||||
"npmPackage".to_string(),
|
||||
pkg.id.as_serialized().into(),
|
||||
);
|
||||
}
|
||||
for dep in dependencies.iter_mut().flat_map(|d| d.as_object_mut()) {
|
||||
if let Some(specifier) = dep.get("specifier").and_then(|s| s.as_str())
|
||||
{
|
||||
if let Ok(npm_ref) = NpmPackageReqReference::from_str(specifier) {
|
||||
if let Ok(pkg) = snapshot.resolve_pkg_from_pkg_req(npm_ref.req())
|
||||
{
|
||||
dep.insert(
|
||||
"npmPackage".to_string(),
|
||||
pkg.id.as_serialized().into(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// don't show this in the output unless someone needs it
|
||||
if let Some(code) =
|
||||
dep.get_mut("code").and_then(|c| c.as_object_mut())
|
||||
{
|
||||
code.remove("resolutionMode");
|
||||
}
|
||||
if let Some(types) =
|
||||
dep.get_mut("types").and_then(|c| c.as_object_mut())
|
||||
{
|
||||
types.remove("resolutionMode");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::sync::Arc;
|
|||
use deno_ast::SourceRange;
|
||||
use deno_config::workspace::WorkspaceResolver;
|
||||
use deno_core::anyhow::anyhow;
|
||||
use deno_graph::source::ResolutionMode;
|
||||
use deno_graph::source::ResolutionKind;
|
||||
use deno_graph::source::ResolveError;
|
||||
use deno_graph::Range;
|
||||
use deno_lint::diagnostic::LintDiagnosticDetails;
|
||||
|
@ -17,7 +17,7 @@ use deno_lint::diagnostic::LintFix;
|
|||
use deno_lint::diagnostic::LintFixChange;
|
||||
use deno_lint::rules::LintRule;
|
||||
use deno_resolver::sloppy_imports::SloppyImportsResolution;
|
||||
use deno_resolver::sloppy_imports::SloppyImportsResolutionMode;
|
||||
use deno_resolver::sloppy_imports::SloppyImportsResolutionKind;
|
||||
use text_lines::LineAndColumnIndex;
|
||||
|
||||
use crate::graph_util::CliJsrUrlProvider;
|
||||
|
@ -101,16 +101,16 @@ impl LintRule for NoSloppyImportsRule {
|
|||
maybe_npm_resolver: None,
|
||||
});
|
||||
|
||||
for (range, sloppy_import) in resolver.captures.borrow_mut().drain() {
|
||||
for (referrer, sloppy_import) in resolver.captures.borrow_mut().drain() {
|
||||
let start_range =
|
||||
context.text_info().loc_to_source_pos(LineAndColumnIndex {
|
||||
line_index: range.start.line,
|
||||
column_index: range.start.character,
|
||||
line_index: referrer.range.start.line,
|
||||
column_index: referrer.range.start.character,
|
||||
});
|
||||
let end_range =
|
||||
context.text_info().loc_to_source_pos(LineAndColumnIndex {
|
||||
line_index: range.end.line,
|
||||
column_index: range.end.character,
|
||||
line_index: referrer.range.end.line,
|
||||
column_index: referrer.range.end.character,
|
||||
});
|
||||
let source_range = SourceRange::new(start_range, end_range);
|
||||
context.add_diagnostic_details(
|
||||
|
@ -183,7 +183,7 @@ impl<'a> deno_graph::source::Resolver for SloppyImportCaptureResolver<'a> {
|
|||
&self,
|
||||
specifier_text: &str,
|
||||
referrer_range: &Range,
|
||||
mode: ResolutionMode,
|
||||
resolution_kind: ResolutionKind,
|
||||
) -> Result<deno_ast::ModuleSpecifier, deno_graph::source::ResolveError> {
|
||||
let resolution = self
|
||||
.workspace_resolver
|
||||
|
@ -198,9 +198,9 @@ impl<'a> deno_graph::source::Resolver for SloppyImportCaptureResolver<'a> {
|
|||
specifier, ..
|
||||
} => match self.sloppy_imports_resolver.resolve(
|
||||
&specifier,
|
||||
match mode {
|
||||
ResolutionMode::Execution => SloppyImportsResolutionMode::Execution,
|
||||
ResolutionMode::Types => SloppyImportsResolutionMode::Types,
|
||||
match resolution_kind {
|
||||
ResolutionKind::Execution => SloppyImportsResolutionKind::Execution,
|
||||
ResolutionKind::Types => SloppyImportsResolutionKind::Types,
|
||||
},
|
||||
) {
|
||||
Some(res) => {
|
||||
|
|
|
@ -234,8 +234,8 @@ impl Diagnostic for PublishDiagnostic {
|
|||
specifier: Cow::Borrowed(&referrer.specifier),
|
||||
text_info: Cow::Borrowed(text_info),
|
||||
source_pos: DiagnosticSourcePos::LineAndCol {
|
||||
line: referrer.start.line,
|
||||
column: referrer.start.character,
|
||||
line: referrer.range.start.line,
|
||||
column: referrer.range.start.character,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ impl Diagnostic for PublishDiagnostic {
|
|||
text_info: &'a SourceTextInfo,
|
||||
referrer: &'a deno_graph::Range,
|
||||
) -> Option<DiagnosticSnippet<'a>> {
|
||||
if referrer.start.line == 0 && referrer.start.character == 0 {
|
||||
if referrer.range.start.line == 0 && referrer.range.start.character == 0 {
|
||||
return None; // no range, probably a jsxImportSource import
|
||||
}
|
||||
|
||||
|
@ -310,12 +310,12 @@ impl Diagnostic for PublishDiagnostic {
|
|||
style: DiagnosticSnippetHighlightStyle::Error,
|
||||
range: DiagnosticSourceRange {
|
||||
start: DiagnosticSourcePos::LineAndCol {
|
||||
line: referrer.start.line,
|
||||
column: referrer.start.character,
|
||||
line: referrer.range.start.line,
|
||||
column: referrer.range.start.character,
|
||||
},
|
||||
end: DiagnosticSourcePos::LineAndCol {
|
||||
line: referrer.end.line,
|
||||
column: referrer.end.character,
|
||||
line: referrer.range.end.line,
|
||||
column: referrer.range.end.character,
|
||||
},
|
||||
},
|
||||
description: Some("the specifier".into()),
|
||||
|
|
|
@ -12,7 +12,7 @@ use deno_graph::DynamicTemplatePart;
|
|||
use deno_graph::ParserModuleAnalyzer;
|
||||
use deno_graph::TypeScriptReference;
|
||||
use deno_package_json::PackageJsonDepValue;
|
||||
use deno_resolver::sloppy_imports::SloppyImportsResolutionMode;
|
||||
use deno_resolver::sloppy_imports::SloppyImportsResolutionKind;
|
||||
use deno_runtime::deno_node::is_builtin_node_module;
|
||||
|
||||
use crate::resolver::CliSloppyImportsResolver;
|
||||
|
@ -180,7 +180,7 @@ impl SpecifierUnfurler {
|
|||
let resolved =
|
||||
if let Some(sloppy_imports_resolver) = &self.sloppy_imports_resolver {
|
||||
sloppy_imports_resolver
|
||||
.resolve(&resolved, SloppyImportsResolutionMode::Execution)
|
||||
.resolve(&resolved, SloppyImportsResolutionKind::Execution)
|
||||
.map(|res| res.into_specifier())
|
||||
.unwrap_or(resolved)
|
||||
} else {
|
||||
|
@ -319,8 +319,8 @@ impl SpecifierUnfurler {
|
|||
}
|
||||
for ts_ref in &module_info.ts_references {
|
||||
let specifier_with_range = match ts_ref {
|
||||
TypeScriptReference::Path(range) => range,
|
||||
TypeScriptReference::Types(range) => range,
|
||||
TypeScriptReference::Path(s) => s,
|
||||
TypeScriptReference::Types { specifier, .. } => specifier,
|
||||
};
|
||||
analyze_specifier(
|
||||
&specifier_with_range.text,
|
||||
|
@ -328,10 +328,10 @@ impl SpecifierUnfurler {
|
|||
&mut text_changes,
|
||||
);
|
||||
}
|
||||
for specifier_with_range in &module_info.jsdoc_imports {
|
||||
for jsdoc in &module_info.jsdoc_imports {
|
||||
analyze_specifier(
|
||||
&specifier_with_range.text,
|
||||
&specifier_with_range.range,
|
||||
&jsdoc.specifier.text,
|
||||
&jsdoc.specifier.range,
|
||||
&mut text_changes,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -43,13 +43,13 @@ use deno_core::unsync::spawn;
|
|||
use deno_core::url::Url;
|
||||
use deno_core::LocalInspectorSession;
|
||||
use deno_core::PollEventLoopOptions;
|
||||
use deno_graph::source::ResolutionMode;
|
||||
use deno_graph::Position;
|
||||
use deno_graph::PositionRange;
|
||||
use deno_graph::SpecifierWithRange;
|
||||
use deno_runtime::worker::MainWorker;
|
||||
use deno_semver::npm::NpmPackageReqReference;
|
||||
use node_resolver::NodeModuleKind;
|
||||
use node_resolver::NodeResolutionKind;
|
||||
use node_resolver::ResolutionMode;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Match;
|
||||
use regex::Regex;
|
||||
|
@ -701,11 +701,6 @@ impl ReplSession {
|
|||
let mut collector = ImportCollector::new();
|
||||
program.visit_with(&mut collector);
|
||||
|
||||
let referrer_range = deno_graph::Range {
|
||||
specifier: self.referrer.clone(),
|
||||
start: deno_graph::Position::zeroed(),
|
||||
end: deno_graph::Position::zeroed(),
|
||||
};
|
||||
let resolved_imports = collector
|
||||
.imports
|
||||
.iter()
|
||||
|
@ -714,9 +709,10 @@ impl ReplSession {
|
|||
.resolver
|
||||
.resolve(
|
||||
i,
|
||||
&referrer_range,
|
||||
NodeModuleKind::Esm,
|
||||
ResolutionMode::Execution,
|
||||
&self.referrer,
|
||||
deno_graph::Position::zeroed(),
|
||||
ResolutionMode::Import,
|
||||
NodeResolutionKind::Execution,
|
||||
)
|
||||
.ok()
|
||||
.or_else(|| ModuleSpecifier::parse(i).ok())
|
||||
|
|
|
@ -8,6 +8,7 @@ use std::path::PathBuf;
|
|||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use console_static_text::ansi::strip_ansi_codes;
|
||||
use deno_config::workspace::FolderConfigs;
|
||||
use deno_config::workspace::TaskDefinition;
|
||||
use deno_config::workspace::TaskOrScript;
|
||||
|
@ -721,20 +722,48 @@ fn print_available_tasks(
|
|||
)?;
|
||||
if let Some(description) = &desc.task.description {
|
||||
let slash_slash = colors::italic_gray("//");
|
||||
for line in description.split('\n') {
|
||||
writeln!(writer, " {slash_slash} {}", colors::italic_gray(line))?;
|
||||
for line in description.lines() {
|
||||
writeln!(
|
||||
writer,
|
||||
" {slash_slash} {}",
|
||||
colors::italic_gray(strip_ansi_codes_and_escape_control_chars(line))
|
||||
)?;
|
||||
}
|
||||
}
|
||||
writeln!(writer, " {}", desc.task.command)?;
|
||||
writeln!(
|
||||
writer,
|
||||
" {}",
|
||||
strip_ansi_codes_and_escape_control_chars(&desc.task.command)
|
||||
)?;
|
||||
if !desc.task.dependencies.is_empty() {
|
||||
let dependencies = desc
|
||||
.task
|
||||
.dependencies
|
||||
.into_iter()
|
||||
.map(|d| strip_ansi_codes_and_escape_control_chars(&d))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
writeln!(
|
||||
writer,
|
||||
" {} {}",
|
||||
colors::gray("depends on:"),
|
||||
colors::cyan(desc.task.dependencies.join(", "))
|
||||
colors::cyan(dependencies)
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn strip_ansi_codes_and_escape_control_chars(s: &str) -> String {
|
||||
strip_ansi_codes(s)
|
||||
.chars()
|
||||
.map(|c| match c {
|
||||
'\n' => "\\n".to_string(),
|
||||
'\r' => "\\r".to_string(),
|
||||
'\t' => "\\t".to_string(),
|
||||
c if c.is_control() => format!("\\x{:02x}", c as u8),
|
||||
c => c.to_string(),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
|
|
@ -681,14 +681,18 @@ delete Object.prototype.__proto__;
|
|||
getNewLine() {
|
||||
return "\n";
|
||||
},
|
||||
resolveTypeReferenceDirectives(
|
||||
typeDirectiveNames,
|
||||
resolveTypeReferenceDirectiveReferences(
|
||||
typeDirectiveReferences,
|
||||
containingFilePath,
|
||||
redirectedReference,
|
||||
options,
|
||||
containingFileMode,
|
||||
containingSourceFile,
|
||||
_reusedNames,
|
||||
) {
|
||||
return typeDirectiveNames.map((arg) => {
|
||||
const isCjs =
|
||||
containingSourceFile?.impliedNodeFormat === ts.ModuleKind.CommonJS;
|
||||
/** @type {Array<ts.ResolvedTypeReferenceDirectiveWithFailedLookupLocations>} */
|
||||
const result = typeDirectiveReferences.map((arg) => {
|
||||
/** @type {ts.FileReference} */
|
||||
const fileReference = typeof arg === "string"
|
||||
? {
|
||||
|
@ -701,16 +705,28 @@ delete Object.prototype.__proto__;
|
|||
/** @type {[string, ts.Extension] | undefined} */
|
||||
const resolved = ops.op_resolve(
|
||||
containingFilePath,
|
||||
containingFileMode === ts.ModuleKind.CommonJS,
|
||||
[fileReference.fileName],
|
||||
[
|
||||
[
|
||||
fileReference.resolutionMode == null
|
||||
? isCjs
|
||||
: fileReference.resolutionMode === ts.ModuleKind.CommonJS,
|
||||
fileReference.fileName,
|
||||
],
|
||||
],
|
||||
)?.[0];
|
||||
if (resolved) {
|
||||
return {
|
||||
primary: true,
|
||||
resolvedFileName: resolved[0],
|
||||
resolvedTypeReferenceDirective: {
|
||||
primary: true,
|
||||
resolvedFileName: resolved[0],
|
||||
// todo(dsherret): we should probably be setting this
|
||||
isExternalLibraryImport: undefined,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
return undefined;
|
||||
return {
|
||||
resolvedTypeReferenceDirective: undefined,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return ts.resolveTypeReferenceDirective(
|
||||
|
@ -720,41 +736,56 @@ delete Object.prototype.__proto__;
|
|||
host,
|
||||
redirectedReference,
|
||||
undefined,
|
||||
containingFileMode ?? fileReference.resolutionMode,
|
||||
).resolvedTypeReferenceDirective;
|
||||
containingSourceFile?.impliedNodeFormat ??
|
||||
fileReference.resolutionMode,
|
||||
);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
},
|
||||
resolveModuleNames(
|
||||
specifiers,
|
||||
resolveModuleNameLiterals(
|
||||
moduleLiterals,
|
||||
base,
|
||||
_reusedNames,
|
||||
_redirectedReference,
|
||||
_options,
|
||||
compilerOptions,
|
||||
containingSourceFile,
|
||||
_reusedNames,
|
||||
) {
|
||||
const specifiers = moduleLiterals.map((literal) => [
|
||||
ts.getModeForUsageLocation(
|
||||
containingSourceFile,
|
||||
literal,
|
||||
compilerOptions,
|
||||
) === ts.ModuleKind.CommonJS,
|
||||
literal.text,
|
||||
]);
|
||||
if (logDebug) {
|
||||
debug(`host.resolveModuleNames()`);
|
||||
debug(` base: ${base}`);
|
||||
debug(` specifiers: ${specifiers.join(", ")}`);
|
||||
debug(` specifiers: ${specifiers.map((s) => s[1]).join(", ")}`);
|
||||
}
|
||||
/** @type {Array<[string, ts.Extension] | undefined>} */
|
||||
const resolved = ops.op_resolve(
|
||||
base,
|
||||
containingSourceFile?.impliedNodeFormat === ts.ModuleKind.CommonJS,
|
||||
specifiers,
|
||||
);
|
||||
if (resolved) {
|
||||
/** @type {Array<ts.ResolvedModuleWithFailedLookupLocations>} */
|
||||
const result = resolved.map((item) => {
|
||||
if (item) {
|
||||
const [resolvedFileName, extension] = item;
|
||||
return {
|
||||
resolvedFileName,
|
||||
extension,
|
||||
isExternalLibraryImport: false,
|
||||
resolvedModule: {
|
||||
resolvedFileName,
|
||||
extension,
|
||||
// todo(dsherret): we should probably be setting this
|
||||
isExternalLibraryImport: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
return {
|
||||
resolvedModule: undefined,
|
||||
};
|
||||
});
|
||||
result.length = specifiers.length;
|
||||
return result;
|
||||
|
|
2
cli/tsc/dts/lib.dom.d.ts
vendored
2
cli/tsc/dts/lib.dom.d.ts
vendored
|
@ -18277,7 +18277,7 @@ declare var ReadableStream: {
|
|||
new(underlyingSource: UnderlyingByteSource, strategy?: { highWaterMark?: number }): ReadableStream<Uint8Array>;
|
||||
new<R = any>(underlyingSource: UnderlyingDefaultSource<R>, strategy?: QueuingStrategy<R>): ReadableStream<R>;
|
||||
new<R = any>(underlyingSource?: UnderlyingSource<R>, strategy?: QueuingStrategy<R>): ReadableStream<R>;
|
||||
from<R>(asyncIterable: AsyncIterable<R> | Iterable<R | PromiseLike<R>>): ReadableStream<R>;
|
||||
from<R>(asyncIterable: AsyncIterable<R> | Iterable<R | PromiseLike<R>> & object): ReadableStream<R>;
|
||||
};
|
||||
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader) */
|
||||
|
|
|
@ -41,8 +41,8 @@ use deno_semver::npm::NpmPackageReqReference;
|
|||
use node_resolver::errors::NodeJsErrorCode;
|
||||
use node_resolver::errors::NodeJsErrorCoded;
|
||||
use node_resolver::errors::PackageSubpathResolveError;
|
||||
use node_resolver::NodeModuleKind;
|
||||
use node_resolver::NodeResolutionMode;
|
||||
use node_resolver::NodeResolutionKind;
|
||||
use node_resolver::ResolutionMode;
|
||||
use once_cell::sync::Lazy;
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
|
@ -703,10 +703,9 @@ pub struct ResolveArgs {
|
|||
/// The base specifier that the supplied specifier strings should be resolved
|
||||
/// relative to.
|
||||
pub base: String,
|
||||
/// If the base is cjs.
|
||||
pub is_base_cjs: bool,
|
||||
/// A list of specifiers that should be resolved.
|
||||
pub specifiers: Vec<String>,
|
||||
/// (is_cjs: bool, raw_specifier: String)
|
||||
pub specifiers: Vec<(bool, String)>,
|
||||
}
|
||||
|
||||
#[op2]
|
||||
|
@ -714,17 +713,9 @@ pub struct ResolveArgs {
|
|||
fn op_resolve(
|
||||
state: &mut OpState,
|
||||
#[string] base: String,
|
||||
is_base_cjs: bool,
|
||||
#[serde] specifiers: Vec<String>,
|
||||
#[serde] specifiers: Vec<(bool, String)>,
|
||||
) -> Result<Vec<(String, &'static str)>, AnyError> {
|
||||
op_resolve_inner(
|
||||
state,
|
||||
ResolveArgs {
|
||||
base,
|
||||
is_base_cjs,
|
||||
specifiers,
|
||||
},
|
||||
)
|
||||
op_resolve_inner(state, ResolveArgs { base, specifiers })
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -735,11 +726,6 @@ fn op_resolve_inner(
|
|||
let state = state.borrow_mut::<State>();
|
||||
let mut resolved: Vec<(String, &'static str)> =
|
||||
Vec::with_capacity(args.specifiers.len());
|
||||
let referrer_kind = if args.is_base_cjs {
|
||||
NodeModuleKind::Cjs
|
||||
} else {
|
||||
NodeModuleKind::Esm
|
||||
};
|
||||
let referrer = if let Some(remapped_specifier) =
|
||||
state.remapped_specifiers.get(&args.base)
|
||||
{
|
||||
|
@ -752,7 +738,7 @@ fn op_resolve_inner(
|
|||
)?
|
||||
};
|
||||
let referrer_module = state.graph.get(&referrer);
|
||||
for specifier in args.specifiers {
|
||||
for (is_cjs, specifier) in args.specifiers {
|
||||
if specifier.starts_with("node:") {
|
||||
resolved.push((
|
||||
MISSING_DEPENDENCY_SPECIFIER.to_string(),
|
||||
|
@ -771,13 +757,20 @@ fn op_resolve_inner(
|
|||
.and_then(|m| m.js())
|
||||
.and_then(|m| m.dependencies_prefer_fast_check().get(&specifier))
|
||||
.and_then(|d| d.maybe_type.ok().or_else(|| d.maybe_code.ok()));
|
||||
let resolution_mode = if is_cjs {
|
||||
ResolutionMode::Require
|
||||
} else {
|
||||
ResolutionMode::Import
|
||||
};
|
||||
|
||||
let maybe_result = match resolved_dep {
|
||||
Some(ResolutionResolved { specifier, .. }) => {
|
||||
resolve_graph_specifier_types(
|
||||
specifier,
|
||||
&referrer,
|
||||
referrer_kind,
|
||||
// we could get this from the resolved dep, but for now assume
|
||||
// the value resolved in TypeScript is better
|
||||
resolution_mode,
|
||||
state,
|
||||
)?
|
||||
}
|
||||
|
@ -785,7 +778,7 @@ fn op_resolve_inner(
|
|||
match resolve_non_graph_specifier_types(
|
||||
&specifier,
|
||||
&referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
state,
|
||||
) {
|
||||
Ok(maybe_result) => maybe_result,
|
||||
|
@ -852,7 +845,7 @@ fn op_resolve_inner(
|
|||
fn resolve_graph_specifier_types(
|
||||
specifier: &ModuleSpecifier,
|
||||
referrer: &ModuleSpecifier,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
state: &State,
|
||||
) -> Result<Option<(ModuleSpecifier, MediaType)>, AnyError> {
|
||||
let graph = &state.graph;
|
||||
|
@ -908,8 +901,8 @@ fn resolve_graph_specifier_types(
|
|||
&package_folder,
|
||||
module.nv_reference.sub_path(),
|
||||
Some(referrer),
|
||||
referrer_kind,
|
||||
NodeResolutionMode::Types,
|
||||
resolution_mode,
|
||||
NodeResolutionKind::Types,
|
||||
);
|
||||
let maybe_url = match res_result {
|
||||
Ok(url) => Some(url),
|
||||
|
@ -949,7 +942,7 @@ enum ResolveNonGraphSpecifierTypesError {
|
|||
fn resolve_non_graph_specifier_types(
|
||||
raw_specifier: &str,
|
||||
referrer: &ModuleSpecifier,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
state: &State,
|
||||
) -> Result<
|
||||
Option<(ModuleSpecifier, MediaType)>,
|
||||
|
@ -967,8 +960,8 @@ fn resolve_non_graph_specifier_types(
|
|||
.resolve(
|
||||
raw_specifier,
|
||||
referrer,
|
||||
referrer_kind,
|
||||
NodeResolutionMode::Types,
|
||||
resolution_mode,
|
||||
NodeResolutionKind::Types,
|
||||
)
|
||||
.ok()
|
||||
.map(|res| res.into_url()),
|
||||
|
@ -976,7 +969,7 @@ fn resolve_non_graph_specifier_types(
|
|||
} else if let Ok(npm_req_ref) =
|
||||
NpmPackageReqReference::from_str(raw_specifier)
|
||||
{
|
||||
debug_assert_eq!(referrer_kind, NodeModuleKind::Esm);
|
||||
debug_assert_eq!(resolution_mode, ResolutionMode::Import);
|
||||
// todo(dsherret): add support for injecting this in the graph so
|
||||
// we don't need this special code here.
|
||||
// This could occur when resolving npm:@types/node when it is
|
||||
|
@ -988,8 +981,8 @@ fn resolve_non_graph_specifier_types(
|
|||
&package_folder,
|
||||
npm_req_ref.sub_path(),
|
||||
Some(referrer),
|
||||
referrer_kind,
|
||||
NodeResolutionMode::Types,
|
||||
resolution_mode,
|
||||
NodeResolutionKind::Types,
|
||||
);
|
||||
let maybe_url = match res_result {
|
||||
Ok(url) => Some(url),
|
||||
|
@ -1388,8 +1381,7 @@ mod tests {
|
|||
&mut state,
|
||||
ResolveArgs {
|
||||
base: "https://deno.land/x/a.ts".to_string(),
|
||||
is_base_cjs: false,
|
||||
specifiers: vec!["./b.ts".to_string()],
|
||||
specifiers: vec![(false, "./b.ts".to_string())],
|
||||
},
|
||||
)
|
||||
.expect("should have invoked op");
|
||||
|
@ -1408,8 +1400,7 @@ mod tests {
|
|||
&mut state,
|
||||
ResolveArgs {
|
||||
base: "https://deno.land/x/a.ts".to_string(),
|
||||
is_base_cjs: false,
|
||||
specifiers: vec!["./bad.ts".to_string()],
|
||||
specifiers: vec![(false, "./bad.ts".to_string())],
|
||||
},
|
||||
)
|
||||
.expect("should have not errored");
|
||||
|
|
|
@ -659,7 +659,7 @@ impl LaxSingleProcessFsFlag {
|
|||
//
|
||||
// This uses a blocking task because we use a single threaded
|
||||
// runtime and this is time sensitive so we don't want it to update
|
||||
// at the whims of of whatever is occurring on the runtime thread.
|
||||
// at the whims of whatever is occurring on the runtime thread.
|
||||
spawn_blocking({
|
||||
let token = token.clone();
|
||||
let last_updated_path = last_updated_path.clone();
|
||||
|
|
|
@ -29,7 +29,7 @@ impl log::Log for CliLogger {
|
|||
// thread's state
|
||||
DrawThread::hide();
|
||||
self.0.log(record);
|
||||
deno_runtime::ops::otel::handle_log(record);
|
||||
deno_telemetry::handle_log(record);
|
||||
DrawThread::show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ use deno_runtime::deno_tls::RootCertStoreProvider;
|
|||
use deno_runtime::deno_web::BlobStore;
|
||||
use deno_runtime::fmt_errors::format_js_error;
|
||||
use deno_runtime::inspector_server::InspectorServer;
|
||||
use deno_runtime::ops::otel::OtelConfig;
|
||||
use deno_runtime::ops::process::NpmProcessStateProviderRc;
|
||||
use deno_runtime::ops::worker_host::CreateWebWorkerCb;
|
||||
use deno_runtime::web_worker::WebWorker;
|
||||
|
@ -43,9 +42,10 @@ use deno_runtime::BootstrapOptions;
|
|||
use deno_runtime::WorkerExecutionMode;
|
||||
use deno_runtime::WorkerLogLevel;
|
||||
use deno_semver::npm::NpmPackageReqReference;
|
||||
use deno_telemetry::OtelConfig;
|
||||
use deno_terminal::colors;
|
||||
use node_resolver::NodeModuleKind;
|
||||
use node_resolver::NodeResolutionMode;
|
||||
use node_resolver::NodeResolutionKind;
|
||||
use node_resolver::ResolutionMode;
|
||||
use tokio::select;
|
||||
|
||||
use crate::args::CliLockfile;
|
||||
|
@ -698,8 +698,8 @@ impl CliMainWorkerFactory {
|
|||
package_folder,
|
||||
sub_path,
|
||||
/* referrer */ None,
|
||||
NodeModuleKind::Esm,
|
||||
NodeResolutionMode::Execution,
|
||||
ResolutionMode::Import,
|
||||
NodeResolutionKind::Execution,
|
||||
)?;
|
||||
if specifier
|
||||
.to_file_path()
|
||||
|
|
|
@ -286,8 +286,13 @@ function mixinBody(prototype, bodySymbol, mimeTypeSymbol) {
|
|||
*/
|
||||
get() {
|
||||
webidl.assertBranded(this, prototype);
|
||||
if (this[bodySymbol] !== null) {
|
||||
return this[bodySymbol].consumed();
|
||||
try {
|
||||
if (this[bodySymbol] !== null) {
|
||||
return this[bodySymbol].consumed();
|
||||
}
|
||||
} catch (_) {
|
||||
// Request is closed.
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
/// <reference path="./lib.deno_fetch.d.ts" />
|
||||
/// <reference lib="esnext" />
|
||||
|
||||
import { core, internals, primordials } from "ext:core/mod.js";
|
||||
import { core, primordials } from "ext:core/mod.js";
|
||||
import {
|
||||
op_fetch,
|
||||
op_fetch_promise_is_settled,
|
||||
|
@ -32,7 +32,6 @@ const {
|
|||
SafePromisePrototypeFinally,
|
||||
String,
|
||||
StringPrototypeEndsWith,
|
||||
StringPrototypeSlice,
|
||||
StringPrototypeStartsWith,
|
||||
StringPrototypeToLowerCase,
|
||||
TypeError,
|
||||
|
@ -59,6 +58,17 @@ import {
|
|||
toInnerResponse,
|
||||
} from "ext:deno_fetch/23_response.js";
|
||||
import * as abortSignal from "ext:deno_web/03_abort_signal.js";
|
||||
import {
|
||||
endSpan,
|
||||
enterSpan,
|
||||
exitSpan,
|
||||
Span,
|
||||
TRACING_ENABLED,
|
||||
} from "ext:deno_telemetry/telemetry.ts";
|
||||
import {
|
||||
updateSpanFromRequest,
|
||||
updateSpanFromResponse,
|
||||
} from "ext:deno_telemetry/util.ts";
|
||||
|
||||
const REQUEST_BODY_HEADER_NAMES = [
|
||||
"content-encoding",
|
||||
|
@ -343,9 +353,9 @@ function httpRedirectFetch(request, response, terminator) {
|
|||
function fetch(input, init = { __proto__: null }) {
|
||||
let span;
|
||||
try {
|
||||
if (internals.telemetry?.tracingEnabled) {
|
||||
span = new internals.telemetry.Span("fetch", { kind: 2 });
|
||||
internals.telemetry.enterSpan(span);
|
||||
if (TRACING_ENABLED) {
|
||||
span = new Span("fetch", { kind: 2 });
|
||||
enterSpan(span);
|
||||
}
|
||||
|
||||
// There is an async dispatch later that causes a stack trace disconnect.
|
||||
|
@ -361,16 +371,7 @@ function fetch(input, init = { __proto__: null }) {
|
|||
const requestObject = new Request(input, init);
|
||||
|
||||
if (span) {
|
||||
span.updateName(requestObject.method);
|
||||
span.setAttribute("http.request.method", requestObject.method);
|
||||
const url = new URL(requestObject.url);
|
||||
span.setAttribute("url.full", requestObject.url);
|
||||
span.setAttribute(
|
||||
"url.scheme",
|
||||
StringPrototypeSlice(url.protocol, 0, -1),
|
||||
);
|
||||
span.setAttribute("url.path", url.pathname);
|
||||
span.setAttribute("url.query", StringPrototypeSlice(url.search, 1));
|
||||
updateSpanFromRequest(span, requestObject);
|
||||
}
|
||||
|
||||
// 3.
|
||||
|
@ -432,10 +433,7 @@ function fetch(input, init = { __proto__: null }) {
|
|||
responseObject = fromInnerResponse(response, "immutable");
|
||||
|
||||
if (span) {
|
||||
span.setAttribute(
|
||||
"http.response.status_code",
|
||||
String(responseObject.status),
|
||||
);
|
||||
updateSpanFromResponse(span, responseObject);
|
||||
}
|
||||
|
||||
resolve(responseObject);
|
||||
|
@ -457,7 +455,7 @@ function fetch(input, init = { __proto__: null }) {
|
|||
return result;
|
||||
} finally {
|
||||
if (span) {
|
||||
internals.telemetry.endSpan(span);
|
||||
endSpan(span);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
@ -471,18 +469,18 @@ function fetch(input, init = { __proto__: null }) {
|
|||
// XXX: This should always be true, otherwise `opPromise` would be present.
|
||||
if (op_fetch_promise_is_settled(result)) {
|
||||
// It's already settled.
|
||||
internals.telemetry.endSpan(span);
|
||||
endSpan(span);
|
||||
} else {
|
||||
// Not settled yet, we can return a new wrapper promise.
|
||||
return SafePromisePrototypeFinally(result, () => {
|
||||
internals.telemetry.endSpan(span);
|
||||
endSpan(span);
|
||||
});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} finally {
|
||||
if (span) {
|
||||
internals.telemetry.exitSpan(span);
|
||||
exitSpan(span);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,9 +36,7 @@ const {
|
|||
PromisePrototypeCatch,
|
||||
SafePromisePrototypeFinally,
|
||||
PromisePrototypeThen,
|
||||
String,
|
||||
StringPrototypeIncludes,
|
||||
StringPrototypeSlice,
|
||||
Symbol,
|
||||
TypeError,
|
||||
TypedArrayPrototypeGetSymbolToStringTag,
|
||||
|
@ -91,6 +89,16 @@ import {
|
|||
} from "ext:deno_net/01_net.js";
|
||||
import { hasTlsKeyPairOptions, listenTls } from "ext:deno_net/02_tls.js";
|
||||
import { SymbolAsyncDispose } from "ext:deno_web/00_infra.js";
|
||||
import {
|
||||
endSpan,
|
||||
enterSpan,
|
||||
Span,
|
||||
TRACING_ENABLED,
|
||||
} from "ext:deno_telemetry/telemetry.ts";
|
||||
import {
|
||||
updateSpanFromRequest,
|
||||
updateSpanFromResponse,
|
||||
} from "ext:deno_telemetry/util.ts";
|
||||
|
||||
const _upgraded = Symbol("_upgraded");
|
||||
|
||||
|
@ -527,16 +535,7 @@ function mapToCallback(context, callback, onError) {
|
|||
innerRequest.request = request;
|
||||
|
||||
if (span) {
|
||||
span.updateName(request.method);
|
||||
span.setAttribute("http.request.method", request.method);
|
||||
const url = new URL(request.url);
|
||||
span.setAttribute("url.full", request.url);
|
||||
span.setAttribute(
|
||||
"url.scheme",
|
||||
StringPrototypeSlice(url.protocol, 0, -1),
|
||||
);
|
||||
span.setAttribute("url.path", url.pathname);
|
||||
span.setAttribute("url.query", StringPrototypeSlice(url.search, 1));
|
||||
updateSpanFromRequest(span, request);
|
||||
}
|
||||
|
||||
response = await callback(
|
||||
|
@ -578,10 +577,7 @@ function mapToCallback(context, callback, onError) {
|
|||
}
|
||||
|
||||
if (span) {
|
||||
span.setAttribute(
|
||||
"http.response.status_code",
|
||||
String(response.status),
|
||||
);
|
||||
updateSpanFromResponse(span, response);
|
||||
}
|
||||
|
||||
const inner = toInnerResponse(response);
|
||||
|
@ -617,8 +613,7 @@ function mapToCallback(context, callback, onError) {
|
|||
fastSyncResponseOrStream(req, inner.body, status, innerRequest);
|
||||
};
|
||||
|
||||
if (internals.telemetry?.tracingEnabled) {
|
||||
const { Span, enterSpan, endSpan } = internals.telemetry;
|
||||
if (TRACING_ENABLED) {
|
||||
const origMapped = mapped;
|
||||
mapped = function (req, _span) {
|
||||
const oldCtx = getAsyncContext();
|
||||
|
|
|
@ -8,13 +8,13 @@ use deno_core::v8;
|
|||
use deno_core::JsRuntimeInspector;
|
||||
use deno_core::OpState;
|
||||
use deno_fs::FileSystemRc;
|
||||
use deno_package_json::NodeModuleKind;
|
||||
use deno_package_json::PackageJsonRc;
|
||||
use deno_path_util::normalize_path;
|
||||
use deno_path_util::url_from_file_path;
|
||||
use deno_path_util::url_to_file_path;
|
||||
use node_resolver::errors::ClosestPkgJsonError;
|
||||
use node_resolver::NodeResolutionMode;
|
||||
use node_resolver::NodeResolutionKind;
|
||||
use node_resolver::ResolutionMode;
|
||||
use node_resolver::REQUIRE_CONDITIONS;
|
||||
use std::borrow::Cow;
|
||||
use std::cell::RefCell;
|
||||
|
@ -462,9 +462,9 @@ where
|
|||
&expansion,
|
||||
exports,
|
||||
Some(&referrer),
|
||||
NodeModuleKind::Cjs,
|
||||
ResolutionMode::Require,
|
||||
REQUIRE_CONDITIONS,
|
||||
NodeResolutionMode::Execution,
|
||||
NodeResolutionKind::Execution,
|
||||
)?;
|
||||
Ok(Some(if r.scheme() == "file" {
|
||||
url_to_file_path_string(&r)?
|
||||
|
@ -559,9 +559,9 @@ where
|
|||
&format!(".{expansion}"),
|
||||
exports,
|
||||
referrer.as_ref(),
|
||||
NodeModuleKind::Cjs,
|
||||
ResolutionMode::Require,
|
||||
REQUIRE_CONDITIONS,
|
||||
NodeResolutionMode::Execution,
|
||||
NodeResolutionKind::Execution,
|
||||
)?;
|
||||
Ok(Some(if r.scheme() == "file" {
|
||||
url_to_file_path_string(&r)?
|
||||
|
@ -630,10 +630,10 @@ where
|
|||
let url = node_resolver.package_imports_resolve(
|
||||
&request,
|
||||
Some(&referrer_url),
|
||||
NodeModuleKind::Cjs,
|
||||
ResolutionMode::Require,
|
||||
Some(&pkg),
|
||||
REQUIRE_CONDITIONS,
|
||||
NodeResolutionMode::Execution,
|
||||
NodeResolutionKind::Execution,
|
||||
)?;
|
||||
Ok(Some(url_to_file_path_string(&url)?))
|
||||
} else {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
import { denoErrorToNodeError } from "ext:deno_node/internal/errors.ts";
|
||||
import { promisify } from "ext:deno_node/internal/util.mjs";
|
||||
import { primordials } from "ext:core/mod.js";
|
||||
import { getValidatedPath } from "ext:deno_node/internal/fs/utils.mjs";
|
||||
|
||||
const { ObjectCreate, ObjectAssign } = primordials;
|
||||
|
||||
|
@ -379,6 +380,7 @@ export function stat(
|
|||
? optionsOrCallback
|
||||
: { bigint: false };
|
||||
|
||||
path = getValidatedPath(path).toString();
|
||||
if (!callback) throw new Error("No callback function supplied");
|
||||
|
||||
Deno.stat(path).then(
|
||||
|
@ -409,6 +411,8 @@ export function statSync(
|
|||
path: string | URL,
|
||||
options: statOptions = { bigint: false, throwIfNoEntry: true },
|
||||
): Stats | BigIntStats | undefined {
|
||||
path = getValidatedPath(path).toString();
|
||||
|
||||
try {
|
||||
const origin = Deno.statSync(path);
|
||||
return CFISBIS(origin, options.bigint);
|
||||
|
|
|
@ -1409,7 +1409,7 @@ ServerResponse.prototype.hasHeader = function (
|
|||
this: ServerResponse,
|
||||
name: string,
|
||||
) {
|
||||
return Object.hasOwn(this._headers, name);
|
||||
return Object.hasOwn(this._headers, StringPrototypeToLowerCase(name));
|
||||
};
|
||||
|
||||
ServerResponse.prototype.writeHead = function (
|
||||
|
|
31
ext/telemetry/Cargo.toml
Normal file
31
ext/telemetry/Cargo.toml
Normal file
|
@ -0,0 +1,31 @@
|
|||
# Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
[package]
|
||||
name = "deno_telemetry"
|
||||
version = "0.1.0"
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
readme = "README.md"
|
||||
repository.workspace = true
|
||||
description = "Telemetry for Deno"
|
||||
|
||||
[lib]
|
||||
path = "lib.rs"
|
||||
|
||||
[dependencies]
|
||||
async-trait.workspace = true
|
||||
deno_core.workspace = true
|
||||
http-body-util.workspace = true
|
||||
hyper.workspace = true
|
||||
hyper-util.workspace = true
|
||||
log.workspace = true
|
||||
once_cell.workspace = true
|
||||
opentelemetry.workspace = true
|
||||
opentelemetry-http.workspace = true
|
||||
opentelemetry-otlp.workspace = true
|
||||
opentelemetry-semantic-conventions.workspace = true
|
||||
opentelemetry_sdk.workspace = true
|
||||
pin-project.workspace = true
|
||||
serde.workspace = true
|
||||
tokio.workspace = true
|
3
ext/telemetry/README.md
Normal file
3
ext/telemetry/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# `deno_telemetry`
|
||||
|
||||
This crate implements telemetry for Deno using OpenTelemetry.
|
|
@ -1,6 +1,5 @@
|
|||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use crate::tokio_util::create_basic_runtime;
|
||||
use deno_core::anyhow;
|
||||
use deno_core::anyhow::anyhow;
|
||||
use deno_core::futures::channel::mpsc;
|
||||
|
@ -59,7 +58,7 @@ type SpanProcessor = BatchSpanProcessor<OtelSharedRuntime>;
|
|||
type LogProcessor = BatchLogProcessor<OtelSharedRuntime>;
|
||||
|
||||
deno_core::extension!(
|
||||
deno_otel,
|
||||
deno_telemetry,
|
||||
ops = [
|
||||
op_otel_log,
|
||||
op_otel_instrumentation_scope_create_and_enter,
|
||||
|
@ -73,6 +72,7 @@ deno_core::extension!(
|
|||
op_otel_span_set_dropped,
|
||||
op_otel_span_flush,
|
||||
],
|
||||
esm = ["telemetry.ts", "util.ts"],
|
||||
);
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
|
@ -111,7 +111,26 @@ fn otel_create_shared_runtime() -> UnboundedSender<BoxFuture<'static, ()>> {
|
|||
mpsc::unbounded::<BoxFuture<'static, ()>>();
|
||||
|
||||
thread::spawn(move || {
|
||||
let rt = create_basic_runtime();
|
||||
let rt = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_io()
|
||||
.enable_time()
|
||||
// This limits the number of threads for blocking operations (like for
|
||||
// synchronous fs ops) or CPU bound tasks like when we run dprint in
|
||||
// parallel for deno fmt.
|
||||
// The default value is 512, which is an unhelpfully large thread pool. We
|
||||
// don't ever want to have more than a couple dozen threads.
|
||||
.max_blocking_threads(if cfg!(windows) {
|
||||
// on windows, tokio uses blocking tasks for child process IO, make sure
|
||||
// we have enough available threads for other tasks to run
|
||||
4 * std::thread::available_parallelism()
|
||||
.map(|n| n.get())
|
||||
.unwrap_or(8)
|
||||
} else {
|
||||
32
|
||||
})
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
rt.block_on(async move {
|
||||
while let Some(task) = spawn_task_rx.next().await {
|
||||
tokio::spawn(task);
|
|
@ -1,6 +1,6 @@
|
|||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import { core, internals, primordials } from "ext:core/mod.js";
|
||||
import { core, primordials } from "ext:core/mod.js";
|
||||
import {
|
||||
op_crypto_get_random_values,
|
||||
op_otel_instrumentation_scope_create_and_enter,
|
||||
|
@ -38,7 +38,7 @@ const {
|
|||
} = primordials;
|
||||
const { AsyncVariable, setAsyncContext } = core;
|
||||
|
||||
let TRACING_ENABLED = false;
|
||||
export let TRACING_ENABLED = false;
|
||||
let DETERMINISTIC = false;
|
||||
|
||||
// Note: These start at 0 in the JS library,
|
||||
|
@ -709,12 +709,3 @@ export const telemetry = {
|
|||
SpanExporter,
|
||||
ContextManager,
|
||||
};
|
||||
internals.telemetry = {
|
||||
Span,
|
||||
enterSpan,
|
||||
exitSpan,
|
||||
endSpan,
|
||||
get tracingEnabled() {
|
||||
return TRACING_ENABLED;
|
||||
},
|
||||
};
|
27
ext/telemetry/util.ts
Normal file
27
ext/telemetry/util.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import { primordials } from "ext:core/mod.js";
|
||||
import type { Span } from "ext:deno_telemetry/telemetry.ts";
|
||||
|
||||
const { String, StringPrototypeSlice } = primordials;
|
||||
|
||||
export function updateSpanFromRequest(span: Span, request: Request) {
|
||||
span.updateName(request.method);
|
||||
|
||||
span.setAttribute("http.request.method", request.method);
|
||||
const url = new URL(request.url);
|
||||
span.setAttribute("url.full", request.url);
|
||||
span.setAttribute(
|
||||
"url.scheme",
|
||||
StringPrototypeSlice(url.protocol, 0, -1),
|
||||
);
|
||||
span.setAttribute("url.path", url.pathname);
|
||||
span.setAttribute("url.query", StringPrototypeSlice(url.search, 1));
|
||||
}
|
||||
|
||||
export function updateSpanFromResponse(span: Span, response: Response) {
|
||||
span.setAttribute(
|
||||
"http.response.status_code",
|
||||
String(response.status),
|
||||
);
|
||||
}
|
|
@ -2922,7 +2922,7 @@ function readableStreamPipeTo(
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {ReadableStreamGenericReader<any> | ReadableStreamBYOBReader} reader
|
||||
* @param {ReadableStreamGenericReader | ReadableStreamBYOBReader} reader
|
||||
* @param {any} reason
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
|
@ -2955,7 +2955,7 @@ function readableStreamReaderGenericInitialize(reader, stream) {
|
|||
|
||||
/**
|
||||
* @template R
|
||||
* @param {ReadableStreamGenericReader<R> | ReadableStreamBYOBReader} reader
|
||||
* @param {ReadableStreamGenericReader | ReadableStreamBYOBReader} reader
|
||||
*/
|
||||
function readableStreamReaderGenericRelease(reader) {
|
||||
const stream = reader[_stream];
|
||||
|
|
4
ext/web/06_streams_types.d.ts
vendored
4
ext/web/06_streams_types.d.ts
vendored
|
@ -60,8 +60,8 @@ interface VoidFunction {
|
|||
(): void;
|
||||
}
|
||||
|
||||
interface ReadableStreamGenericReader<T> {
|
||||
readonly closed: Promise<void>;
|
||||
interface ReadableStreamGenericReader {
|
||||
readonly closed: Promise<undefined>;
|
||||
// deno-lint-ignore no-explicit-any
|
||||
cancel(reason?: any): Promise<void>;
|
||||
}
|
||||
|
|
2
ext/web/lib.deno_web.d.ts
vendored
2
ext/web/lib.deno_web.d.ts
vendored
|
@ -882,7 +882,7 @@ declare var ReadableStream: {
|
|||
strategy?: QueuingStrategy<R>,
|
||||
): ReadableStream<R>;
|
||||
from<R>(
|
||||
asyncIterable: AsyncIterable<R> | Iterable<R | PromiseLike<R>>,
|
||||
asyncIterable: AsyncIterable<R> | Iterable<R | PromiseLike<R>> & object,
|
||||
): ReadableStream<R>;
|
||||
};
|
||||
|
||||
|
|
|
@ -98,6 +98,11 @@ const {
|
|||
ArrayPrototypePush,
|
||||
DataViewPrototypeGetBuffer,
|
||||
Error,
|
||||
Number,
|
||||
NumberPOSITIVE_INFINITY,
|
||||
NumberMAX_SAFE_INTEGER,
|
||||
NumberNEGATIVE_INFINITY,
|
||||
NumberMIN_SAFE_INTEGER,
|
||||
MathMax,
|
||||
ObjectDefineProperty,
|
||||
ObjectHasOwn,
|
||||
|
@ -614,6 +619,19 @@ function createGPUSupportedLimits(limits) {
|
|||
return adapterFeatures;
|
||||
}
|
||||
|
||||
function normalizeLimit(limit) {
|
||||
if (typeof num === "bigint") {
|
||||
limit = Number(limit);
|
||||
if (limit === NumberPOSITIVE_INFINITY) {
|
||||
limit = NumberMAX_SAFE_INTEGER;
|
||||
} else if (limit === NumberNEGATIVE_INFINITY) {
|
||||
limit = NumberMIN_SAFE_INTEGER;
|
||||
}
|
||||
}
|
||||
|
||||
return limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef InnerAdapterLimits
|
||||
* @property {number} maxTextureDimension1D
|
||||
|
@ -653,123 +671,127 @@ class GPUSupportedLimits {
|
|||
|
||||
get maxTextureDimension1D() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxTextureDimension1D;
|
||||
return normalizeLimit(this[_limits].maxTextureDimension1D);
|
||||
}
|
||||
get maxTextureDimension2D() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxTextureDimension2D;
|
||||
return normalizeLimit(this[_limits].maxTextureDimension2D);
|
||||
}
|
||||
get maxTextureDimension3D() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxTextureDimension3D;
|
||||
return normalizeLimit(this[_limits].maxTextureDimension3D);
|
||||
}
|
||||
get maxTextureArrayLayers() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxTextureArrayLayers;
|
||||
return normalizeLimit(this[_limits].maxTextureArrayLayers);
|
||||
}
|
||||
get maxBindGroups() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxBindGroups;
|
||||
return normalizeLimit(this[_limits].maxBindGroups);
|
||||
}
|
||||
get maxBindingsPerBindGroup() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxBindingsPerBindGroup;
|
||||
return normalizeLimit(this[_limits].maxBindingsPerBindGroup);
|
||||
}
|
||||
get maxBufferSize() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxBufferSize;
|
||||
return normalizeLimit(this[_limits].maxBufferSize);
|
||||
}
|
||||
get maxDynamicUniformBuffersPerPipelineLayout() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxDynamicUniformBuffersPerPipelineLayout;
|
||||
return normalizeLimit(
|
||||
this[_limits].maxDynamicUniformBuffersPerPipelineLayout,
|
||||
);
|
||||
}
|
||||
get maxDynamicStorageBuffersPerPipelineLayout() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxDynamicStorageBuffersPerPipelineLayout;
|
||||
return normalizeLimit(
|
||||
this[_limits].maxDynamicStorageBuffersPerPipelineLayout,
|
||||
);
|
||||
}
|
||||
get maxSampledTexturesPerShaderStage() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxSampledTexturesPerShaderStage;
|
||||
return normalizeLimit(this[_limits].maxSampledTexturesPerShaderStage);
|
||||
}
|
||||
get maxSamplersPerShaderStage() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxSamplersPerShaderStage;
|
||||
return normalizeLimit(this[_limits].maxSamplersPerShaderStage);
|
||||
}
|
||||
get maxStorageBuffersPerShaderStage() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxStorageBuffersPerShaderStage;
|
||||
return normalizeLimit(this[_limits].maxStorageBuffersPerShaderStage);
|
||||
}
|
||||
get maxStorageTexturesPerShaderStage() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxStorageTexturesPerShaderStage;
|
||||
return normalizeLimit(this[_limits].maxStorageTexturesPerShaderStage);
|
||||
}
|
||||
get maxUniformBuffersPerShaderStage() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxUniformBuffersPerShaderStage;
|
||||
return normalizeLimit(this[_limits].maxUniformBuffersPerShaderStage);
|
||||
}
|
||||
get maxUniformBufferBindingSize() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxUniformBufferBindingSize;
|
||||
return normalizeLimit(this[_limits].maxUniformBufferBindingSize);
|
||||
}
|
||||
get maxStorageBufferBindingSize() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxStorageBufferBindingSize;
|
||||
return normalizeLimit(this[_limits].maxStorageBufferBindingSize);
|
||||
}
|
||||
get minUniformBufferOffsetAlignment() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].minUniformBufferOffsetAlignment;
|
||||
return normalizeLimit(this[_limits].minUniformBufferOffsetAlignment);
|
||||
}
|
||||
get minStorageBufferOffsetAlignment() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].minStorageBufferOffsetAlignment;
|
||||
return normalizeLimit(this[_limits].minStorageBufferOffsetAlignment);
|
||||
}
|
||||
get maxVertexBuffers() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxVertexBuffers;
|
||||
return normalizeLimit(this[_limits].maxVertexBuffers);
|
||||
}
|
||||
get maxVertexAttributes() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxVertexAttributes;
|
||||
return normalizeLimit(this[_limits].maxVertexAttributes);
|
||||
}
|
||||
get maxVertexBufferArrayStride() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxVertexBufferArrayStride;
|
||||
return normalizeLimit(this[_limits].maxVertexBufferArrayStride);
|
||||
}
|
||||
get maxInterStageShaderComponents() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxInterStageShaderComponents;
|
||||
return normalizeLimit(this[_limits].maxInterStageShaderComponents);
|
||||
}
|
||||
get maxColorAttachments() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxColorAttachments;
|
||||
return normalizeLimit(this[_limits].maxColorAttachments);
|
||||
}
|
||||
get maxColorAttachmentBytesPerSample() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxColorAttachmentBytesPerSample;
|
||||
return normalizeLimit(this[_limits].maxColorAttachmentBytesPerSample);
|
||||
}
|
||||
get maxComputeWorkgroupStorageSize() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxComputeWorkgroupStorageSize;
|
||||
return normalizeLimit(this[_limits].maxComputeWorkgroupStorageSize);
|
||||
}
|
||||
get maxComputeInvocationsPerWorkgroup() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxComputeInvocationsPerWorkgroup;
|
||||
return normalizeLimit(this[_limits].maxComputeInvocationsPerWorkgroup);
|
||||
}
|
||||
get maxComputeWorkgroupSizeX() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxComputeWorkgroupSizeX;
|
||||
return normalizeLimit(this[_limits].maxComputeWorkgroupSizeX);
|
||||
}
|
||||
get maxComputeWorkgroupSizeY() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxComputeWorkgroupSizeY;
|
||||
return normalizeLimit(this[_limits].maxComputeWorkgroupSizeY);
|
||||
}
|
||||
get maxComputeWorkgroupSizeZ() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxComputeWorkgroupSizeZ;
|
||||
return normalizeLimit(this[_limits].maxComputeWorkgroupSizeZ);
|
||||
}
|
||||
get maxComputeWorkgroupsPerDimension() {
|
||||
webidl.assertBranded(this, GPUSupportedLimitsPrototype);
|
||||
return this[_limits].maxComputeWorkgroupsPerDimension;
|
||||
return normalizeLimit(this[_limits].maxComputeWorkgroupsPerDimension);
|
||||
}
|
||||
|
||||
[SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) {
|
||||
|
|
|
@ -3,91 +3,20 @@
|
|||
/// <reference path="../../core/internal.d.ts" />
|
||||
|
||||
import { primordials } from "ext:core/mod.js";
|
||||
import {
|
||||
op_webstorage_clear,
|
||||
op_webstorage_get,
|
||||
op_webstorage_iterate_keys,
|
||||
op_webstorage_key,
|
||||
op_webstorage_length,
|
||||
op_webstorage_remove,
|
||||
op_webstorage_set,
|
||||
} from "ext:core/ops";
|
||||
import { op_webstorage_iterate_keys, Storage } from "ext:core/ops";
|
||||
const {
|
||||
Symbol,
|
||||
SymbolFor,
|
||||
ObjectFromEntries,
|
||||
ObjectEntries,
|
||||
ReflectDefineProperty,
|
||||
ReflectDeleteProperty,
|
||||
ReflectGet,
|
||||
FunctionPrototypeBind,
|
||||
ReflectHas,
|
||||
Proxy,
|
||||
} = primordials;
|
||||
|
||||
import * as webidl from "ext:deno_webidl/00_webidl.js";
|
||||
|
||||
const _persistent = Symbol("[[persistent]]");
|
||||
|
||||
class Storage {
|
||||
[_persistent];
|
||||
|
||||
constructor() {
|
||||
webidl.illegalConstructor();
|
||||
}
|
||||
|
||||
get length() {
|
||||
webidl.assertBranded(this, StoragePrototype);
|
||||
return op_webstorage_length(this[_persistent]);
|
||||
}
|
||||
|
||||
key(index) {
|
||||
webidl.assertBranded(this, StoragePrototype);
|
||||
const prefix = "Failed to execute 'key' on 'Storage'";
|
||||
webidl.requiredArguments(arguments.length, 1, prefix);
|
||||
index = webidl.converters["unsigned long"](index, prefix, "Argument 1");
|
||||
|
||||
return op_webstorage_key(index, this[_persistent]);
|
||||
}
|
||||
|
||||
setItem(key, value) {
|
||||
webidl.assertBranded(this, StoragePrototype);
|
||||
const prefix = "Failed to execute 'setItem' on 'Storage'";
|
||||
webidl.requiredArguments(arguments.length, 2, prefix);
|
||||
key = webidl.converters.DOMString(key, prefix, "Argument 1");
|
||||
value = webidl.converters.DOMString(value, prefix, "Argument 2");
|
||||
|
||||
op_webstorage_set(key, value, this[_persistent]);
|
||||
}
|
||||
|
||||
getItem(key) {
|
||||
webidl.assertBranded(this, StoragePrototype);
|
||||
const prefix = "Failed to execute 'getItem' on 'Storage'";
|
||||
webidl.requiredArguments(arguments.length, 1, prefix);
|
||||
key = webidl.converters.DOMString(key, prefix, "Argument 1");
|
||||
|
||||
return op_webstorage_get(key, this[_persistent]);
|
||||
}
|
||||
|
||||
removeItem(key) {
|
||||
webidl.assertBranded(this, StoragePrototype);
|
||||
const prefix = "Failed to execute 'removeItem' on 'Storage'";
|
||||
webidl.requiredArguments(arguments.length, 1, prefix);
|
||||
key = webidl.converters.DOMString(key, prefix, "Argument 1");
|
||||
|
||||
op_webstorage_remove(key, this[_persistent]);
|
||||
}
|
||||
|
||||
clear() {
|
||||
webidl.assertBranded(this, StoragePrototype);
|
||||
op_webstorage_clear(this[_persistent]);
|
||||
}
|
||||
}
|
||||
|
||||
const StoragePrototype = Storage.prototype;
|
||||
|
||||
function createStorage(persistent) {
|
||||
const storage = webidl.createBranded(Storage);
|
||||
storage[_persistent] = persistent;
|
||||
const storage = new Storage(persistent);
|
||||
|
||||
const proxy = new Proxy(storage, {
|
||||
deleteProperty(target, key) {
|
||||
|
@ -106,12 +35,16 @@ function createStorage(persistent) {
|
|||
return true;
|
||||
},
|
||||
|
||||
get(target, key, receiver) {
|
||||
get(target, key) {
|
||||
if (typeof key === "symbol") {
|
||||
return target[key];
|
||||
}
|
||||
if (ReflectHas(target, key)) {
|
||||
return ReflectGet(target, key, receiver);
|
||||
const value = target[key];
|
||||
if (typeof value === "function") {
|
||||
return FunctionPrototypeBind(value, target);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
return target.getItem(key) ?? undefined;
|
||||
},
|
||||
|
@ -136,7 +69,7 @@ function createStorage(persistent) {
|
|||
},
|
||||
|
||||
ownKeys() {
|
||||
return op_webstorage_iterate_keys(persistent);
|
||||
return op_webstorage_iterate_keys(storage);
|
||||
},
|
||||
|
||||
getOwnPropertyDescriptor(target, key) {
|
||||
|
@ -163,7 +96,7 @@ function createStorage(persistent) {
|
|||
inspect,
|
||||
inspectOptions,
|
||||
) {
|
||||
return `${this.constructor.name} ${
|
||||
return `Storage ${
|
||||
inspect({
|
||||
...ObjectFromEntries(ObjectEntries(proxy)),
|
||||
length: this.length,
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use deno_core::op2;
|
||||
use deno_core::GarbageCollected;
|
||||
use deno_core::OpState;
|
||||
use rusqlite::params;
|
||||
use rusqlite::Connection;
|
||||
|
@ -32,17 +33,14 @@ const MAX_STORAGE_BYTES: usize = 10 * 1024 * 1024;
|
|||
deno_core::extension!(deno_webstorage,
|
||||
deps = [ deno_webidl ],
|
||||
ops = [
|
||||
op_webstorage_length,
|
||||
op_webstorage_key,
|
||||
op_webstorage_set,
|
||||
op_webstorage_get,
|
||||
op_webstorage_remove,
|
||||
op_webstorage_clear,
|
||||
op_webstorage_iterate_keys,
|
||||
],
|
||||
objects = [
|
||||
Storage
|
||||
],
|
||||
esm = [ "01_webstorage.js" ],
|
||||
options = {
|
||||
origin_storage_dir: Option<PathBuf>
|
||||
origin_storage_dir: Option<PathBuf>
|
||||
},
|
||||
state = |state, options| {
|
||||
if let Some(origin_storage_dir) = options.origin_storage_dir {
|
||||
|
@ -110,38 +108,6 @@ fn get_webstorage(
|
|||
Ok(conn)
|
||||
}
|
||||
|
||||
#[op2(fast)]
|
||||
pub fn op_webstorage_length(
|
||||
state: &mut OpState,
|
||||
persistent: bool,
|
||||
) -> Result<u32, WebStorageError> {
|
||||
let conn = get_webstorage(state, persistent)?;
|
||||
|
||||
let mut stmt = conn.prepare_cached("SELECT COUNT(*) FROM data")?;
|
||||
let length: u32 = stmt.query_row(params![], |row| row.get(0))?;
|
||||
|
||||
Ok(length)
|
||||
}
|
||||
|
||||
#[op2]
|
||||
#[string]
|
||||
pub fn op_webstorage_key(
|
||||
state: &mut OpState,
|
||||
#[smi] index: u32,
|
||||
persistent: bool,
|
||||
) -> Result<Option<String>, WebStorageError> {
|
||||
let conn = get_webstorage(state, persistent)?;
|
||||
|
||||
let mut stmt =
|
||||
conn.prepare_cached("SELECT key FROM data LIMIT 1 OFFSET ?")?;
|
||||
|
||||
let key: Option<String> = stmt
|
||||
.query_row(params![index], |row| row.get(0))
|
||||
.optional()?;
|
||||
|
||||
Ok(key)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn size_check(input: usize) -> Result<(), WebStorageError> {
|
||||
if input >= MAX_STORAGE_BYTES {
|
||||
|
@ -151,81 +117,125 @@ fn size_check(input: usize) -> Result<(), WebStorageError> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[op2(fast)]
|
||||
pub fn op_webstorage_set(
|
||||
state: &mut OpState,
|
||||
#[string] key: &str,
|
||||
#[string] value: &str,
|
||||
struct Storage {
|
||||
persistent: bool,
|
||||
) -> Result<(), WebStorageError> {
|
||||
let conn = get_webstorage(state, persistent)?;
|
||||
|
||||
size_check(key.len() + value.len())?;
|
||||
|
||||
let mut stmt = conn
|
||||
.prepare_cached("SELECT SUM(pgsize) FROM dbstat WHERE name = 'data'")?;
|
||||
let size: u32 = stmt.query_row(params![], |row| row.get(0))?;
|
||||
|
||||
size_check(size as usize)?;
|
||||
|
||||
let mut stmt = conn
|
||||
.prepare_cached("INSERT OR REPLACE INTO data (key, value) VALUES (?, ?)")?;
|
||||
stmt.execute(params![key, value])?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl GarbageCollected for Storage {}
|
||||
|
||||
#[op2]
|
||||
#[string]
|
||||
pub fn op_webstorage_get(
|
||||
state: &mut OpState,
|
||||
#[string] key_name: String,
|
||||
persistent: bool,
|
||||
) -> Result<Option<String>, WebStorageError> {
|
||||
let conn = get_webstorage(state, persistent)?;
|
||||
impl Storage {
|
||||
#[constructor]
|
||||
#[cppgc]
|
||||
fn new(persistent: bool) -> Storage {
|
||||
Storage { persistent }
|
||||
}
|
||||
|
||||
let mut stmt = conn.prepare_cached("SELECT value FROM data WHERE key = ?")?;
|
||||
let val = stmt
|
||||
.query_row(params![key_name], |row| row.get(0))
|
||||
.optional()?;
|
||||
#[getter]
|
||||
#[smi]
|
||||
fn length(&self, state: &mut OpState) -> Result<u32, WebStorageError> {
|
||||
let conn = get_webstorage(state, self.persistent)?;
|
||||
|
||||
Ok(val)
|
||||
}
|
||||
let mut stmt = conn.prepare_cached("SELECT COUNT(*) FROM data")?;
|
||||
let length: u32 = stmt.query_row(params![], |row| row.get(0))?;
|
||||
|
||||
#[op2(fast)]
|
||||
pub fn op_webstorage_remove(
|
||||
state: &mut OpState,
|
||||
#[string] key_name: &str,
|
||||
persistent: bool,
|
||||
) -> Result<(), WebStorageError> {
|
||||
let conn = get_webstorage(state, persistent)?;
|
||||
Ok(length)
|
||||
}
|
||||
|
||||
let mut stmt = conn.prepare_cached("DELETE FROM data WHERE key = ?")?;
|
||||
stmt.execute(params![key_name])?;
|
||||
#[required(1)]
|
||||
#[string]
|
||||
fn key(
|
||||
&self,
|
||||
state: &mut OpState,
|
||||
#[smi] index: u32,
|
||||
) -> Result<Option<String>, WebStorageError> {
|
||||
let conn = get_webstorage(state, self.persistent)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
let mut stmt =
|
||||
conn.prepare_cached("SELECT key FROM data LIMIT 1 OFFSET ?")?;
|
||||
|
||||
#[op2(fast)]
|
||||
pub fn op_webstorage_clear(
|
||||
state: &mut OpState,
|
||||
persistent: bool,
|
||||
) -> Result<(), WebStorageError> {
|
||||
let conn = get_webstorage(state, persistent)?;
|
||||
let key: Option<String> = stmt
|
||||
.query_row(params![index], |row| row.get(0))
|
||||
.optional()?;
|
||||
|
||||
let mut stmt = conn.prepare_cached("DELETE FROM data")?;
|
||||
stmt.execute(params![])?;
|
||||
Ok(key)
|
||||
}
|
||||
|
||||
Ok(())
|
||||
#[fast]
|
||||
#[required(2)]
|
||||
fn set_item(
|
||||
&self,
|
||||
state: &mut OpState,
|
||||
#[string] key: &str,
|
||||
#[string] value: &str,
|
||||
) -> Result<(), WebStorageError> {
|
||||
let conn = get_webstorage(state, self.persistent)?;
|
||||
|
||||
size_check(key.len() + value.len())?;
|
||||
|
||||
let mut stmt = conn
|
||||
.prepare_cached("SELECT SUM(pgsize) FROM dbstat WHERE name = 'data'")?;
|
||||
let size: u32 = stmt.query_row(params![], |row| row.get(0))?;
|
||||
|
||||
size_check(size as usize)?;
|
||||
|
||||
let mut stmt = conn.prepare_cached(
|
||||
"INSERT OR REPLACE INTO data (key, value) VALUES (?, ?)",
|
||||
)?;
|
||||
stmt.execute(params![key, value])?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[required(1)]
|
||||
#[string]
|
||||
fn get_item(
|
||||
&self,
|
||||
state: &mut OpState,
|
||||
#[string] key: &str,
|
||||
) -> Result<Option<String>, WebStorageError> {
|
||||
let conn = get_webstorage(state, self.persistent)?;
|
||||
|
||||
let mut stmt =
|
||||
conn.prepare_cached("SELECT value FROM data WHERE key = ?")?;
|
||||
let val = stmt.query_row(params![key], |row| row.get(0)).optional()?;
|
||||
|
||||
Ok(val)
|
||||
}
|
||||
|
||||
#[fast]
|
||||
#[required(1)]
|
||||
fn remove_item(
|
||||
&self,
|
||||
state: &mut OpState,
|
||||
#[string] key: &str,
|
||||
) -> Result<(), WebStorageError> {
|
||||
let conn = get_webstorage(state, self.persistent)?;
|
||||
|
||||
let mut stmt = conn.prepare_cached("DELETE FROM data WHERE key = ?")?;
|
||||
stmt.execute(params![key])?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[fast]
|
||||
fn clear(&self, state: &mut OpState) -> Result<(), WebStorageError> {
|
||||
let conn = get_webstorage(state, self.persistent)?;
|
||||
|
||||
let mut stmt = conn.prepare_cached("DELETE FROM data")?;
|
||||
stmt.execute(params![])?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[op2]
|
||||
#[serde]
|
||||
pub fn op_webstorage_iterate_keys(
|
||||
fn op_webstorage_iterate_keys(
|
||||
#[cppgc] storage: &Storage,
|
||||
state: &mut OpState,
|
||||
persistent: bool,
|
||||
) -> Result<Vec<String>, WebStorageError> {
|
||||
let conn = get_webstorage(state, persistent)?;
|
||||
let conn = get_webstorage(state, storage.persistent)?;
|
||||
|
||||
let mut stmt = conn.prepare_cached("SELECT key FROM data")?;
|
||||
let keys = stmt
|
||||
|
|
|
@ -7,8 +7,8 @@ use deno_media_type::MediaType;
|
|||
use node_resolver::env::NodeResolverEnv;
|
||||
use node_resolver::errors::ClosestPkgJsonError;
|
||||
use node_resolver::InNpmPackageChecker;
|
||||
use node_resolver::NodeModuleKind;
|
||||
use node_resolver::PackageJsonResolver;
|
||||
use node_resolver::ResolutionMode;
|
||||
use url::Url;
|
||||
|
||||
/// Keeps track of what module specifiers were resolved as CJS.
|
||||
|
@ -19,20 +19,20 @@ use url::Url;
|
|||
#[derive(Debug)]
|
||||
pub struct CjsTracker<TEnv: NodeResolverEnv> {
|
||||
is_cjs_resolver: IsCjsResolver<TEnv>,
|
||||
known: DashMap<Url, NodeModuleKind>,
|
||||
known: DashMap<Url, ResolutionMode>,
|
||||
}
|
||||
|
||||
impl<TEnv: NodeResolverEnv> CjsTracker<TEnv> {
|
||||
pub fn new(
|
||||
in_npm_pkg_checker: Arc<dyn InNpmPackageChecker>,
|
||||
pkg_json_resolver: Arc<PackageJsonResolver<TEnv>>,
|
||||
options: IsCjsResolverOptions,
|
||||
mode: IsCjsResolutionMode,
|
||||
) -> Self {
|
||||
Self {
|
||||
is_cjs_resolver: IsCjsResolver::new(
|
||||
in_npm_pkg_checker,
|
||||
pkg_json_resolver,
|
||||
options,
|
||||
mode,
|
||||
),
|
||||
known: Default::default(),
|
||||
}
|
||||
|
@ -70,42 +70,42 @@ impl<TEnv: NodeResolverEnv> CjsTracker<TEnv> {
|
|||
is_script: Option<bool>,
|
||||
) -> Result<bool, ClosestPkgJsonError> {
|
||||
let kind = match self
|
||||
.get_known_kind_with_is_script(specifier, media_type, is_script)
|
||||
.get_known_mode_with_is_script(specifier, media_type, is_script)
|
||||
{
|
||||
Some(kind) => kind,
|
||||
None => self.is_cjs_resolver.check_based_on_pkg_json(specifier)?,
|
||||
};
|
||||
Ok(kind == NodeModuleKind::Cjs)
|
||||
Ok(kind == ResolutionMode::Require)
|
||||
}
|
||||
|
||||
/// Gets the referrer for the specified module specifier.
|
||||
///
|
||||
/// Generally the referrer should already be tracked by calling
|
||||
/// `is_cjs_with_known_is_script` before calling this method.
|
||||
pub fn get_referrer_kind(&self, specifier: &Url) -> NodeModuleKind {
|
||||
pub fn get_referrer_kind(&self, specifier: &Url) -> ResolutionMode {
|
||||
if specifier.scheme() != "file" {
|
||||
return NodeModuleKind::Esm;
|
||||
return ResolutionMode::Import;
|
||||
}
|
||||
self
|
||||
.get_known_kind(specifier, MediaType::from_specifier(specifier))
|
||||
.unwrap_or(NodeModuleKind::Esm)
|
||||
.get_known_mode(specifier, MediaType::from_specifier(specifier))
|
||||
.unwrap_or(ResolutionMode::Import)
|
||||
}
|
||||
|
||||
fn get_known_kind(
|
||||
fn get_known_mode(
|
||||
&self,
|
||||
specifier: &Url,
|
||||
media_type: MediaType,
|
||||
) -> Option<NodeModuleKind> {
|
||||
self.get_known_kind_with_is_script(specifier, media_type, None)
|
||||
) -> Option<ResolutionMode> {
|
||||
self.get_known_mode_with_is_script(specifier, media_type, None)
|
||||
}
|
||||
|
||||
fn get_known_kind_with_is_script(
|
||||
fn get_known_mode_with_is_script(
|
||||
&self,
|
||||
specifier: &Url,
|
||||
media_type: MediaType,
|
||||
is_script: Option<bool>,
|
||||
) -> Option<NodeModuleKind> {
|
||||
self.is_cjs_resolver.get_known_kind_with_is_script(
|
||||
) -> Option<ResolutionMode> {
|
||||
self.is_cjs_resolver.get_known_mode_with_is_script(
|
||||
specifier,
|
||||
media_type,
|
||||
is_script,
|
||||
|
@ -114,10 +114,14 @@ impl<TEnv: NodeResolverEnv> CjsTracker<TEnv> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct IsCjsResolverOptions {
|
||||
pub detect_cjs: bool,
|
||||
pub is_node_main: bool,
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum IsCjsResolutionMode {
|
||||
/// Requires an explicit `"type": "commonjs"` in the package.json.
|
||||
ExplicitTypeCommonJs,
|
||||
/// Implicitly uses `"type": "commonjs"` if no `"type"` is specified.
|
||||
ImplicitTypeCommonJs,
|
||||
/// Does not respect `"type": "commonjs"` and always treats ambiguous files as ESM.
|
||||
Disabled,
|
||||
}
|
||||
|
||||
/// Resolves whether a module is CJS or ESM.
|
||||
|
@ -125,41 +129,41 @@ pub struct IsCjsResolverOptions {
|
|||
pub struct IsCjsResolver<TEnv: NodeResolverEnv> {
|
||||
in_npm_pkg_checker: Arc<dyn InNpmPackageChecker>,
|
||||
pkg_json_resolver: Arc<PackageJsonResolver<TEnv>>,
|
||||
options: IsCjsResolverOptions,
|
||||
mode: IsCjsResolutionMode,
|
||||
}
|
||||
|
||||
impl<TEnv: NodeResolverEnv> IsCjsResolver<TEnv> {
|
||||
pub fn new(
|
||||
in_npm_pkg_checker: Arc<dyn InNpmPackageChecker>,
|
||||
pkg_json_resolver: Arc<PackageJsonResolver<TEnv>>,
|
||||
options: IsCjsResolverOptions,
|
||||
mode: IsCjsResolutionMode,
|
||||
) -> Self {
|
||||
Self {
|
||||
in_npm_pkg_checker,
|
||||
pkg_json_resolver,
|
||||
options,
|
||||
mode,
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the referrer kind for a script in the LSP.
|
||||
pub fn get_lsp_referrer_kind(
|
||||
/// Gets the resolution mode for a module in the LSP.
|
||||
pub fn get_lsp_resolution_mode(
|
||||
&self,
|
||||
specifier: &Url,
|
||||
is_script: Option<bool>,
|
||||
) -> NodeModuleKind {
|
||||
) -> ResolutionMode {
|
||||
if specifier.scheme() != "file" {
|
||||
return NodeModuleKind::Esm;
|
||||
return ResolutionMode::Import;
|
||||
}
|
||||
match MediaType::from_specifier(specifier) {
|
||||
MediaType::Mts | MediaType::Mjs | MediaType::Dmts => NodeModuleKind::Esm,
|
||||
MediaType::Cjs | MediaType::Cts | MediaType::Dcts => NodeModuleKind::Cjs,
|
||||
MediaType::Mts | MediaType::Mjs | MediaType::Dmts => ResolutionMode::Import,
|
||||
MediaType::Cjs | MediaType::Cts | MediaType::Dcts => ResolutionMode::Require,
|
||||
MediaType::Dts => {
|
||||
// dts files are always determined based on the package.json because
|
||||
// they contain imports/exports even when considered CJS
|
||||
self.check_based_on_pkg_json(specifier).unwrap_or(NodeModuleKind::Esm)
|
||||
self.check_based_on_pkg_json(specifier).unwrap_or(ResolutionMode::Import)
|
||||
}
|
||||
MediaType::Wasm |
|
||||
MediaType::Json => NodeModuleKind::Esm,
|
||||
MediaType::Json => ResolutionMode::Import,
|
||||
MediaType::JavaScript
|
||||
| MediaType::Jsx
|
||||
| MediaType::TypeScript
|
||||
|
@ -169,27 +173,27 @@ impl<TEnv: NodeResolverEnv> IsCjsResolver<TEnv> {
|
|||
| MediaType::SourceMap
|
||||
| MediaType::Unknown => {
|
||||
match is_script {
|
||||
Some(true) => self.check_based_on_pkg_json(specifier).unwrap_or(NodeModuleKind::Esm),
|
||||
Some(false) | None => NodeModuleKind::Esm,
|
||||
Some(true) => self.check_based_on_pkg_json(specifier).unwrap_or(ResolutionMode::Import),
|
||||
Some(false) | None => ResolutionMode::Import,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_known_kind_with_is_script(
|
||||
fn get_known_mode_with_is_script(
|
||||
&self,
|
||||
specifier: &Url,
|
||||
media_type: MediaType,
|
||||
is_script: Option<bool>,
|
||||
known_cache: &DashMap<Url, NodeModuleKind>,
|
||||
) -> Option<NodeModuleKind> {
|
||||
known_cache: &DashMap<Url, ResolutionMode>,
|
||||
) -> Option<ResolutionMode> {
|
||||
if specifier.scheme() != "file" {
|
||||
return Some(NodeModuleKind::Esm);
|
||||
return Some(ResolutionMode::Import);
|
||||
}
|
||||
|
||||
match media_type {
|
||||
MediaType::Mts | MediaType::Mjs | MediaType::Dmts => Some(NodeModuleKind::Esm),
|
||||
MediaType::Cjs | MediaType::Cts | MediaType::Dcts => Some(NodeModuleKind::Cjs),
|
||||
MediaType::Mts | MediaType::Mjs | MediaType::Dmts => Some(ResolutionMode::Import),
|
||||
MediaType::Cjs | MediaType::Cts | MediaType::Dcts => Some(ResolutionMode::Require),
|
||||
MediaType::Dts => {
|
||||
// dts files are always determined based on the package.json because
|
||||
// they contain imports/exports even when considered CJS
|
||||
|
@ -200,11 +204,11 @@ impl<TEnv: NodeResolverEnv> IsCjsResolver<TEnv> {
|
|||
if let Some(value) = value {
|
||||
known_cache.insert(specifier.clone(), value);
|
||||
}
|
||||
Some(value.unwrap_or(NodeModuleKind::Esm))
|
||||
Some(value.unwrap_or(ResolutionMode::Import))
|
||||
}
|
||||
}
|
||||
MediaType::Wasm |
|
||||
MediaType::Json => Some(NodeModuleKind::Esm),
|
||||
MediaType::Json => Some(ResolutionMode::Import),
|
||||
MediaType::JavaScript
|
||||
| MediaType::Jsx
|
||||
| MediaType::TypeScript
|
||||
|
@ -214,17 +218,17 @@ impl<TEnv: NodeResolverEnv> IsCjsResolver<TEnv> {
|
|||
| MediaType::SourceMap
|
||||
| MediaType::Unknown => {
|
||||
if let Some(value) = known_cache.get(specifier).map(|v| *v) {
|
||||
if value == NodeModuleKind::Cjs && is_script == Some(false) {
|
||||
if value == ResolutionMode::Require && is_script == Some(false) {
|
||||
// we now know this is actually esm
|
||||
known_cache.insert(specifier.clone(), NodeModuleKind::Esm);
|
||||
Some(NodeModuleKind::Esm)
|
||||
known_cache.insert(specifier.clone(), ResolutionMode::Import);
|
||||
Some(ResolutionMode::Import)
|
||||
} else {
|
||||
Some(value)
|
||||
}
|
||||
} else if is_script == Some(false) {
|
||||
// we know this is esm
|
||||
known_cache.insert(specifier.clone(), NodeModuleKind::Esm);
|
||||
Some(NodeModuleKind::Esm)
|
||||
known_cache.insert(specifier.clone(), ResolutionMode::Import);
|
||||
Some(ResolutionMode::Import)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -235,38 +239,39 @@ impl<TEnv: NodeResolverEnv> IsCjsResolver<TEnv> {
|
|||
fn check_based_on_pkg_json(
|
||||
&self,
|
||||
specifier: &Url,
|
||||
) -> Result<NodeModuleKind, ClosestPkgJsonError> {
|
||||
) -> Result<ResolutionMode, ClosestPkgJsonError> {
|
||||
if self.in_npm_pkg_checker.in_npm_package(specifier) {
|
||||
if let Some(pkg_json) =
|
||||
self.pkg_json_resolver.get_closest_package_json(specifier)?
|
||||
{
|
||||
let is_file_location_cjs = pkg_json.typ != "module";
|
||||
Ok(if is_file_location_cjs {
|
||||
NodeModuleKind::Cjs
|
||||
ResolutionMode::Require
|
||||
} else {
|
||||
NodeModuleKind::Esm
|
||||
ResolutionMode::Import
|
||||
})
|
||||
} else {
|
||||
Ok(NodeModuleKind::Cjs)
|
||||
Ok(ResolutionMode::Require)
|
||||
}
|
||||
} else if self.options.detect_cjs || self.options.is_node_main {
|
||||
} else if self.mode != IsCjsResolutionMode::Disabled {
|
||||
if let Some(pkg_json) =
|
||||
self.pkg_json_resolver.get_closest_package_json(specifier)?
|
||||
{
|
||||
let is_cjs_type = pkg_json.typ == "commonjs"
|
||||
|| self.options.is_node_main && pkg_json.typ == "none";
|
||||
|| self.mode == IsCjsResolutionMode::ImplicitTypeCommonJs
|
||||
&& pkg_json.typ == "none";
|
||||
Ok(if is_cjs_type {
|
||||
NodeModuleKind::Cjs
|
||||
ResolutionMode::Require
|
||||
} else {
|
||||
NodeModuleKind::Esm
|
||||
ResolutionMode::Import
|
||||
})
|
||||
} else if self.options.is_node_main {
|
||||
Ok(NodeModuleKind::Cjs)
|
||||
} else if self.mode == IsCjsResolutionMode::ImplicitTypeCommonJs {
|
||||
Ok(ResolutionMode::Require)
|
||||
} else {
|
||||
Ok(NodeModuleKind::Esm)
|
||||
Ok(ResolutionMode::Import)
|
||||
}
|
||||
} else {
|
||||
Ok(NodeModuleKind::Esm)
|
||||
Ok(ResolutionMode::Import)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,10 +20,10 @@ use node_resolver::env::NodeResolverEnv;
|
|||
use node_resolver::errors::NodeResolveError;
|
||||
use node_resolver::errors::PackageSubpathResolveError;
|
||||
use node_resolver::InNpmPackageChecker;
|
||||
use node_resolver::NodeModuleKind;
|
||||
use node_resolver::NodeResolution;
|
||||
use node_resolver::NodeResolutionMode;
|
||||
use node_resolver::NodeResolutionKind;
|
||||
use node_resolver::NodeResolver;
|
||||
use node_resolver::ResolutionMode;
|
||||
use npm::MissingPackageNodeModulesFolderError;
|
||||
use npm::NodeModulesOutOfDateError;
|
||||
use npm::NpmReqResolver;
|
||||
|
@ -31,7 +31,7 @@ use npm::ResolveIfForNpmPackageErrorKind;
|
|||
use npm::ResolvePkgFolderFromDenoReqError;
|
||||
use npm::ResolveReqWithSubPathErrorKind;
|
||||
use sloppy_imports::SloppyImportResolverFs;
|
||||
use sloppy_imports::SloppyImportsResolutionMode;
|
||||
use sloppy_imports::SloppyImportsResolutionKind;
|
||||
use sloppy_imports::SloppyImportsResolver;
|
||||
use thiserror::Error;
|
||||
use url::Url;
|
||||
|
@ -145,8 +145,8 @@ impl<
|
|||
&self,
|
||||
raw_specifier: &str,
|
||||
referrer: &Url,
|
||||
referrer_kind: NodeModuleKind,
|
||||
mode: NodeResolutionMode,
|
||||
resolution_mode: ResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<DenoResolution, DenoResolveError> {
|
||||
let mut found_package_json_dep = false;
|
||||
let mut maybe_diagnostic = None;
|
||||
|
@ -157,7 +157,7 @@ impl<
|
|||
&& self.in_npm_pkg_checker.in_npm_package(referrer)
|
||||
{
|
||||
return node_resolver
|
||||
.resolve(raw_specifier, referrer, referrer_kind, mode)
|
||||
.resolve(raw_specifier, referrer, resolution_mode, resolution_kind)
|
||||
.map(|res| DenoResolution {
|
||||
url: res.into_url(),
|
||||
found_package_json_dep,
|
||||
|
@ -189,12 +189,12 @@ impl<
|
|||
sloppy_imports_resolver
|
||||
.resolve(
|
||||
&specifier,
|
||||
match mode {
|
||||
NodeResolutionMode::Execution => {
|
||||
SloppyImportsResolutionMode::Execution
|
||||
match resolution_kind {
|
||||
NodeResolutionKind::Execution => {
|
||||
SloppyImportsResolutionKind::Execution
|
||||
}
|
||||
NodeResolutionMode::Types => {
|
||||
SloppyImportsResolutionMode::Types
|
||||
NodeResolutionKind::Types => {
|
||||
SloppyImportsResolutionKind::Types
|
||||
}
|
||||
},
|
||||
)
|
||||
|
@ -221,8 +221,8 @@ impl<
|
|||
pkg_json.dir_path(),
|
||||
sub_path.as_deref(),
|
||||
Some(referrer),
|
||||
referrer_kind,
|
||||
mode,
|
||||
resolution_mode,
|
||||
resolution_kind,
|
||||
)
|
||||
.map_err(|e| e.into()),
|
||||
MappedResolution::PackageJson {
|
||||
|
@ -272,8 +272,8 @@ impl<
|
|||
pkg_folder,
|
||||
sub_path.as_deref(),
|
||||
Some(referrer),
|
||||
referrer_kind,
|
||||
mode,
|
||||
resolution_mode,
|
||||
resolution_kind,
|
||||
)
|
||||
.map_err(|e| {
|
||||
DenoResolveErrorKind::PackageSubpathResolve(e).into_box()
|
||||
|
@ -328,8 +328,8 @@ impl<
|
|||
pkg_folder,
|
||||
npm_req_ref.sub_path(),
|
||||
Some(referrer),
|
||||
referrer_kind,
|
||||
mode,
|
||||
resolution_mode,
|
||||
resolution_kind,
|
||||
)
|
||||
.map(|url| DenoResolution {
|
||||
url,
|
||||
|
@ -345,8 +345,8 @@ impl<
|
|||
.resolve_req_reference(
|
||||
&npm_req_ref,
|
||||
referrer,
|
||||
referrer_kind,
|
||||
mode,
|
||||
resolution_mode,
|
||||
resolution_kind,
|
||||
)
|
||||
.map(|url| DenoResolution {
|
||||
url,
|
||||
|
@ -384,8 +384,8 @@ impl<
|
|||
.resolve_if_for_npm_pkg(
|
||||
raw_specifier,
|
||||
referrer,
|
||||
referrer_kind,
|
||||
mode,
|
||||
resolution_mode,
|
||||
resolution_kind,
|
||||
)
|
||||
.map_err(|e| match e.into_kind() {
|
||||
ResolveIfForNpmPackageErrorKind::NodeResolve(e) => {
|
||||
|
|
|
@ -16,10 +16,10 @@ use node_resolver::errors::PackageNotFoundError;
|
|||
use node_resolver::errors::PackageResolveErrorKind;
|
||||
use node_resolver::errors::PackageSubpathResolveError;
|
||||
use node_resolver::InNpmPackageChecker;
|
||||
use node_resolver::NodeModuleKind;
|
||||
use node_resolver::NodeResolution;
|
||||
use node_resolver::NodeResolutionMode;
|
||||
use node_resolver::NodeResolutionKind;
|
||||
use node_resolver::NodeResolver;
|
||||
use node_resolver::ResolutionMode;
|
||||
use thiserror::Error;
|
||||
use url::Url;
|
||||
|
||||
|
@ -132,15 +132,15 @@ impl<Fs: DenoResolverFs, TNodeResolverEnv: NodeResolverEnv>
|
|||
&self,
|
||||
req_ref: &NpmPackageReqReference,
|
||||
referrer: &Url,
|
||||
referrer_kind: NodeModuleKind,
|
||||
mode: NodeResolutionMode,
|
||||
resolution_mode: ResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<Url, ResolveReqWithSubPathError> {
|
||||
self.resolve_req_with_sub_path(
|
||||
req_ref.req(),
|
||||
req_ref.sub_path(),
|
||||
referrer,
|
||||
referrer_kind,
|
||||
mode,
|
||||
resolution_mode,
|
||||
resolution_kind,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -149,8 +149,8 @@ impl<Fs: DenoResolverFs, TNodeResolverEnv: NodeResolverEnv>
|
|||
req: &PackageReq,
|
||||
sub_path: Option<&str>,
|
||||
referrer: &Url,
|
||||
referrer_kind: NodeModuleKind,
|
||||
mode: NodeResolutionMode,
|
||||
resolution_mode: ResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<Url, ResolveReqWithSubPathError> {
|
||||
let package_folder = self
|
||||
.npm_resolver
|
||||
|
@ -160,8 +160,8 @@ impl<Fs: DenoResolverFs, TNodeResolverEnv: NodeResolverEnv>
|
|||
&package_folder,
|
||||
sub_path,
|
||||
Some(referrer),
|
||||
referrer_kind,
|
||||
mode,
|
||||
resolution_mode,
|
||||
resolution_kind,
|
||||
);
|
||||
match resolution_result {
|
||||
Ok(url) => Ok(url),
|
||||
|
@ -183,13 +183,15 @@ impl<Fs: DenoResolverFs, TNodeResolverEnv: NodeResolverEnv>
|
|||
&self,
|
||||
specifier: &str,
|
||||
referrer: &Url,
|
||||
referrer_kind: NodeModuleKind,
|
||||
mode: NodeResolutionMode,
|
||||
resolution_mode: ResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<Option<NodeResolution>, ResolveIfForNpmPackageError> {
|
||||
let resolution_result =
|
||||
self
|
||||
.node_resolver
|
||||
.resolve(specifier, referrer, referrer_kind, mode);
|
||||
let resolution_result = self.node_resolver.resolve(
|
||||
specifier,
|
||||
referrer,
|
||||
resolution_mode,
|
||||
resolution_kind,
|
||||
);
|
||||
match resolution_result {
|
||||
Ok(res) => Ok(Some(res)),
|
||||
Err(err) => {
|
||||
|
|
|
@ -80,16 +80,16 @@ impl SloppyImportsResolution {
|
|||
|
||||
/// The kind of resolution currently being done.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum SloppyImportsResolutionMode {
|
||||
pub enum SloppyImportsResolutionKind {
|
||||
/// Resolving for code that will be executed.
|
||||
Execution,
|
||||
/// Resolving for code that will be used for type information.
|
||||
Types,
|
||||
}
|
||||
|
||||
impl SloppyImportsResolutionMode {
|
||||
impl SloppyImportsResolutionKind {
|
||||
pub fn is_types(&self) -> bool {
|
||||
*self == SloppyImportsResolutionMode::Types
|
||||
*self == SloppyImportsResolutionKind::Types
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ impl<Fs: SloppyImportResolverFs> SloppyImportsResolver<Fs> {
|
|||
pub fn resolve(
|
||||
&self,
|
||||
specifier: &Url,
|
||||
mode: SloppyImportsResolutionMode,
|
||||
resolution_kind: SloppyImportsResolutionKind,
|
||||
) -> Option<SloppyImportsResolution> {
|
||||
fn path_without_ext(
|
||||
path: &Path,
|
||||
|
@ -167,7 +167,7 @@ impl<Fs: SloppyImportResolverFs> SloppyImportsResolver<Fs> {
|
|||
let probe_paths: Vec<(PathBuf, SloppyImportsResolutionReason)> =
|
||||
match self.fs.stat_sync(&path) {
|
||||
Some(SloppyImportsFsEntry::File) => {
|
||||
if mode.is_types() {
|
||||
if resolution_kind.is_types() {
|
||||
let media_type = MediaType::from_specifier(specifier);
|
||||
// attempt to resolve the .d.ts file before the .js file
|
||||
let probe_media_type_types = match media_type {
|
||||
|
@ -197,7 +197,7 @@ impl<Fs: SloppyImportResolverFs> SloppyImportsResolver<Fs> {
|
|||
let media_type = MediaType::from_specifier(specifier);
|
||||
let probe_media_type_types = match media_type {
|
||||
MediaType::JavaScript => (
|
||||
if mode.is_types() {
|
||||
if resolution_kind.is_types() {
|
||||
vec![MediaType::TypeScript, MediaType::Tsx, MediaType::Dts]
|
||||
} else {
|
||||
vec![MediaType::TypeScript, MediaType::Tsx]
|
||||
|
@ -208,7 +208,7 @@ impl<Fs: SloppyImportResolverFs> SloppyImportsResolver<Fs> {
|
|||
(vec![MediaType::Tsx], SloppyImportsResolutionReason::JsToTs)
|
||||
}
|
||||
MediaType::Mjs => (
|
||||
if mode.is_types() {
|
||||
if resolution_kind.is_types() {
|
||||
vec![MediaType::Mts, MediaType::Dmts, MediaType::Dts]
|
||||
} else {
|
||||
vec![MediaType::Mts]
|
||||
|
@ -216,7 +216,7 @@ impl<Fs: SloppyImportResolverFs> SloppyImportsResolver<Fs> {
|
|||
SloppyImportsResolutionReason::JsToTs,
|
||||
),
|
||||
MediaType::Cjs => (
|
||||
if mode.is_types() {
|
||||
if resolution_kind.is_types() {
|
||||
vec![MediaType::Cts, MediaType::Dcts, MediaType::Dts]
|
||||
} else {
|
||||
vec![MediaType::Cts]
|
||||
|
@ -237,7 +237,7 @@ impl<Fs: SloppyImportResolverFs> SloppyImportsResolver<Fs> {
|
|||
return None;
|
||||
}
|
||||
MediaType::Unknown => (
|
||||
if mode.is_types() {
|
||||
if resolution_kind.is_types() {
|
||||
vec![
|
||||
MediaType::TypeScript,
|
||||
MediaType::Tsx,
|
||||
|
@ -274,7 +274,7 @@ impl<Fs: SloppyImportResolverFs> SloppyImportsResolver<Fs> {
|
|||
|
||||
if matches!(entry, Some(SloppyImportsFsEntry::Dir)) {
|
||||
// try to resolve at the index file
|
||||
if mode.is_types() {
|
||||
if resolution_kind.is_types() {
|
||||
probe_paths.push((
|
||||
path.join("index.ts"),
|
||||
SloppyImportsResolutionReason::Directory,
|
||||
|
@ -373,16 +373,22 @@ mod test {
|
|||
#[test]
|
||||
fn test_unstable_sloppy_imports() {
|
||||
fn resolve(specifier: &Url) -> Option<SloppyImportsResolution> {
|
||||
resolve_with_mode(specifier, SloppyImportsResolutionMode::Execution)
|
||||
resolve_with_resolution_kind(
|
||||
specifier,
|
||||
SloppyImportsResolutionKind::Execution,
|
||||
)
|
||||
}
|
||||
|
||||
fn resolve_types(specifier: &Url) -> Option<SloppyImportsResolution> {
|
||||
resolve_with_mode(specifier, SloppyImportsResolutionMode::Types)
|
||||
resolve_with_resolution_kind(
|
||||
specifier,
|
||||
SloppyImportsResolutionKind::Types,
|
||||
)
|
||||
}
|
||||
|
||||
fn resolve_with_mode(
|
||||
fn resolve_with_resolution_kind(
|
||||
specifier: &Url,
|
||||
mode: SloppyImportsResolutionMode,
|
||||
resolution_kind: SloppyImportsResolutionKind,
|
||||
) -> Option<SloppyImportsResolution> {
|
||||
struct RealSloppyImportsResolverFs;
|
||||
impl SloppyImportResolverFs for RealSloppyImportsResolverFs {
|
||||
|
@ -400,7 +406,7 @@ mod test {
|
|||
}
|
||||
|
||||
SloppyImportsResolver::new(RealSloppyImportsResolverFs)
|
||||
.resolve(specifier, mode)
|
||||
.resolve(specifier, resolution_kind)
|
||||
}
|
||||
|
||||
let context = TestContext::default();
|
||||
|
|
|
@ -21,11 +21,11 @@ use url::Url;
|
|||
use crate::env::NodeResolverEnv;
|
||||
use crate::npm::InNpmPackageCheckerRc;
|
||||
use crate::resolution::NodeResolverRc;
|
||||
use crate::NodeModuleKind;
|
||||
use crate::NodeResolutionMode;
|
||||
use crate::NodeResolutionKind;
|
||||
use crate::NpmPackageFolderResolverRc;
|
||||
use crate::PackageJsonResolverRc;
|
||||
use crate::PathClean;
|
||||
use crate::ResolutionMode;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum CjsAnalysis<'a> {
|
||||
|
@ -209,7 +209,7 @@ impl<TCjsCodeAnalyzer: CjsCodeAnalyzer, TNodeResolverEnv: NodeResolverEnv>
|
|||
// FIXME(bartlomieju): check if these conditions are okay, probably
|
||||
// should be `deno-require`, because `deno` is already used in `esm_resolver.rs`
|
||||
&["deno", "node", "require", "default"],
|
||||
NodeResolutionMode::Execution,
|
||||
NodeResolutionKind::Execution,
|
||||
);
|
||||
let reexport_specifier = match result {
|
||||
Ok(Some(specifier)) => specifier,
|
||||
|
@ -303,7 +303,7 @@ impl<TCjsCodeAnalyzer: CjsCodeAnalyzer, TNodeResolverEnv: NodeResolverEnv>
|
|||
specifier: &str,
|
||||
referrer: &Url,
|
||||
conditions: &[&str],
|
||||
mode: NodeResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<Option<Url>, AnyError> {
|
||||
if specifier.starts_with('/') {
|
||||
todo!();
|
||||
|
@ -354,9 +354,9 @@ impl<TCjsCodeAnalyzer: CjsCodeAnalyzer, TNodeResolverEnv: NodeResolverEnv>
|
|||
&package_subpath,
|
||||
exports,
|
||||
Some(referrer),
|
||||
NodeModuleKind::Esm,
|
||||
ResolutionMode::Import,
|
||||
conditions,
|
||||
mode,
|
||||
resolution_kind,
|
||||
)
|
||||
.map_err(AnyError::from),
|
||||
)
|
||||
|
@ -373,7 +373,9 @@ impl<TCjsCodeAnalyzer: CjsCodeAnalyzer, TNodeResolverEnv: NodeResolverEnv>
|
|||
.pkg_json_resolver
|
||||
.load_package_json(&package_json_path)?;
|
||||
if let Some(package_json) = maybe_package_json {
|
||||
if let Some(main) = package_json.main(NodeModuleKind::Cjs) {
|
||||
if let Some(main) =
|
||||
package_json.main(deno_package_json::NodeModuleKind::Cjs)
|
||||
{
|
||||
return Ok(Some(url_from_file_path(&d.join(main).clean())?));
|
||||
}
|
||||
}
|
||||
|
@ -384,7 +386,9 @@ impl<TCjsCodeAnalyzer: CjsCodeAnalyzer, TNodeResolverEnv: NodeResolverEnv>
|
|||
.file_extension_probe(d, &referrer_path)
|
||||
.and_then(|p| url_from_file_path(&p).map_err(AnyError::from))
|
||||
.map(Some);
|
||||
} else if let Some(main) = package_json.main(NodeModuleKind::Cjs) {
|
||||
} else if let Some(main) =
|
||||
package_json.main(deno_package_json::NodeModuleKind::Cjs)
|
||||
{
|
||||
return Ok(Some(url_from_file_path(&module_dir.join(main).clean())?));
|
||||
} else {
|
||||
return Ok(Some(url_from_file_path(
|
||||
|
|
|
@ -8,8 +8,8 @@ use boxed_error::Boxed;
|
|||
use thiserror::Error;
|
||||
use url::Url;
|
||||
|
||||
use crate::NodeModuleKind;
|
||||
use crate::NodeResolutionMode;
|
||||
use crate::NodeResolutionKind;
|
||||
use crate::ResolutionMode;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[allow(non_camel_case_types)]
|
||||
|
@ -203,24 +203,24 @@ pub enum PackageSubpathResolveErrorKind {
|
|||
maybe_referrer.as_ref().map(|r|
|
||||
format!(
|
||||
" from{} referrer {}",
|
||||
match referrer_kind {
|
||||
NodeModuleKind::Esm => "",
|
||||
NodeModuleKind::Cjs => " cjs",
|
||||
match resolution_mode {
|
||||
ResolutionMode::Import => "",
|
||||
ResolutionMode::Require => " cjs",
|
||||
},
|
||||
r
|
||||
)
|
||||
).unwrap_or_default(),
|
||||
match mode {
|
||||
NodeResolutionMode::Execution => "",
|
||||
NodeResolutionMode::Types => " for types",
|
||||
match resolution_kind {
|
||||
NodeResolutionKind::Execution => "",
|
||||
NodeResolutionKind::Types => " for types",
|
||||
}
|
||||
)]
|
||||
pub struct PackageTargetNotFoundError {
|
||||
pub pkg_json_path: PathBuf,
|
||||
pub target: String,
|
||||
pub maybe_referrer: Option<Url>,
|
||||
pub referrer_kind: NodeModuleKind,
|
||||
pub mode: NodeResolutionMode,
|
||||
pub resolution_mode: ResolutionMode,
|
||||
pub resolution_kind: NodeResolutionKind,
|
||||
}
|
||||
|
||||
impl NodeJsErrorCoded for PackageTargetNotFoundError {
|
||||
|
@ -586,7 +586,7 @@ pub struct PackagePathNotExportedError {
|
|||
pub pkg_json_path: PathBuf,
|
||||
pub subpath: String,
|
||||
pub maybe_referrer: Option<Url>,
|
||||
pub mode: NodeResolutionMode,
|
||||
pub resolution_kind: NodeResolutionKind,
|
||||
}
|
||||
|
||||
impl NodeJsErrorCoded for PackagePathNotExportedError {
|
||||
|
@ -603,9 +603,9 @@ impl std::fmt::Display for PackagePathNotExportedError {
|
|||
f.write_str(self.code().as_str())?;
|
||||
f.write_char(']')?;
|
||||
|
||||
let types_msg = match self.mode {
|
||||
NodeResolutionMode::Execution => String::new(),
|
||||
NodeResolutionMode::Types => " for types".to_string(),
|
||||
let types_msg = match self.resolution_kind {
|
||||
NodeResolutionKind::Execution => String::new(),
|
||||
NodeResolutionKind::Types => " for types".to_string(),
|
||||
};
|
||||
if self.subpath == "." {
|
||||
write!(
|
||||
|
@ -678,7 +678,7 @@ mod test {
|
|||
pkg_json_path: PathBuf::from("test_path").join("package.json"),
|
||||
subpath: "./jsx-runtime".to_string(),
|
||||
maybe_referrer: None,
|
||||
mode: NodeResolutionMode::Types
|
||||
resolution_kind: NodeResolutionKind::Types
|
||||
}.to_string(),
|
||||
format!("[ERR_PACKAGE_PATH_NOT_EXPORTED] Package subpath './jsx-runtime' is not defined for types by \"exports\" in 'test_path{separator_char}package.json'")
|
||||
);
|
||||
|
@ -687,7 +687,7 @@ mod test {
|
|||
pkg_json_path: PathBuf::from("test_path").join("package.json"),
|
||||
subpath: ".".to_string(),
|
||||
maybe_referrer: None,
|
||||
mode: NodeResolutionMode::Types
|
||||
resolution_kind: NodeResolutionKind::Types
|
||||
}.to_string(),
|
||||
format!("[ERR_PACKAGE_PATH_NOT_EXPORTED] No \"exports\" main defined for types in 'test_path{separator_char}package.json'")
|
||||
);
|
||||
|
|
|
@ -23,9 +23,9 @@ pub use package_json::PackageJsonThreadLocalCache;
|
|||
pub use path::PathClean;
|
||||
pub use resolution::parse_npm_pkg_name;
|
||||
pub use resolution::resolve_specifier_into_node_modules;
|
||||
pub use resolution::NodeModuleKind;
|
||||
pub use resolution::NodeResolution;
|
||||
pub use resolution::NodeResolutionMode;
|
||||
pub use resolution::NodeResolutionKind;
|
||||
pub use resolution::NodeResolver;
|
||||
pub use resolution::ResolutionMode;
|
||||
pub use resolution::DEFAULT_CONDITIONS;
|
||||
pub use resolution::REQUIRE_CONDITIONS;
|
||||
|
|
|
@ -50,26 +50,30 @@ pub static DEFAULT_CONDITIONS: &[&str] = &["deno", "node", "import"];
|
|||
pub static REQUIRE_CONDITIONS: &[&str] = &["require", "node"];
|
||||
static TYPES_ONLY_CONDITIONS: &[&str] = &["types"];
|
||||
|
||||
fn conditions_from_module_kind(
|
||||
kind: NodeModuleKind,
|
||||
fn conditions_from_resolution_mode(
|
||||
resolution_mode: ResolutionMode,
|
||||
) -> &'static [&'static str] {
|
||||
match kind {
|
||||
NodeModuleKind::Esm => DEFAULT_CONDITIONS,
|
||||
NodeModuleKind::Cjs => REQUIRE_CONDITIONS,
|
||||
match resolution_mode {
|
||||
ResolutionMode::Import => DEFAULT_CONDITIONS,
|
||||
ResolutionMode::Require => REQUIRE_CONDITIONS,
|
||||
}
|
||||
}
|
||||
|
||||
pub type NodeModuleKind = deno_package_json::NodeModuleKind;
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum ResolutionMode {
|
||||
Import,
|
||||
Require,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum NodeResolutionMode {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum NodeResolutionKind {
|
||||
Execution,
|
||||
Types,
|
||||
}
|
||||
|
||||
impl NodeResolutionMode {
|
||||
impl NodeResolutionKind {
|
||||
pub fn is_types(&self) -> bool {
|
||||
matches!(self, NodeResolutionMode::Types)
|
||||
matches!(self, NodeResolutionKind::Types)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,8 +134,8 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
&self,
|
||||
specifier: &str,
|
||||
referrer: &Url,
|
||||
referrer_kind: NodeModuleKind,
|
||||
mode: NodeResolutionMode,
|
||||
resolution_mode: ResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<NodeResolution, NodeResolveError> {
|
||||
// Note: if we are here, then the referrer is an esm module
|
||||
// TODO(bartlomieju): skipped "policy" part as we don't plan to support it
|
||||
|
@ -174,14 +178,18 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
let url = self.module_resolve(
|
||||
specifier,
|
||||
referrer,
|
||||
referrer_kind,
|
||||
conditions_from_module_kind(referrer_kind),
|
||||
mode,
|
||||
resolution_mode,
|
||||
conditions_from_resolution_mode(resolution_mode),
|
||||
resolution_kind,
|
||||
)?;
|
||||
|
||||
let url = if mode.is_types() {
|
||||
let url = if resolution_kind.is_types() {
|
||||
let file_path = to_file_path(&url);
|
||||
self.path_to_declaration_url(&file_path, Some(referrer), referrer_kind)?
|
||||
self.path_to_declaration_url(
|
||||
&file_path,
|
||||
Some(referrer),
|
||||
resolution_mode,
|
||||
)?
|
||||
} else {
|
||||
url
|
||||
};
|
||||
|
@ -197,9 +205,9 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
&self,
|
||||
specifier: &str,
|
||||
referrer: &Url,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
conditions: &[&str],
|
||||
mode: NodeResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<Url, NodeResolveError> {
|
||||
if should_be_treated_as_relative_or_absolute_path(specifier) {
|
||||
Ok(node_join_url(referrer, specifier).map_err(|err| {
|
||||
|
@ -218,10 +226,10 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
Ok(self.package_imports_resolve(
|
||||
specifier,
|
||||
Some(referrer),
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
pkg_config.as_deref(),
|
||||
conditions,
|
||||
mode,
|
||||
resolution_kind,
|
||||
)?)
|
||||
} else if let Ok(resolved) = Url::parse(specifier) {
|
||||
Ok(resolved)
|
||||
|
@ -229,9 +237,9 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
Ok(self.package_resolve(
|
||||
specifier,
|
||||
referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
conditions,
|
||||
mode,
|
||||
resolution_kind,
|
||||
)?)
|
||||
}
|
||||
}
|
||||
|
@ -307,8 +315,8 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
package_dir: &Path,
|
||||
package_subpath: Option<&str>,
|
||||
maybe_referrer: Option<&Url>,
|
||||
referrer_kind: NodeModuleKind,
|
||||
mode: NodeResolutionMode,
|
||||
resolution_mode: ResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<Url, PackageSubpathResolveError> {
|
||||
let package_subpath = package_subpath
|
||||
.map(|s| format!("./{s}"))
|
||||
|
@ -317,9 +325,9 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
package_dir,
|
||||
&package_subpath,
|
||||
maybe_referrer,
|
||||
referrer_kind,
|
||||
conditions_from_module_kind(referrer_kind),
|
||||
mode,
|
||||
resolution_mode,
|
||||
conditions_from_resolution_mode(resolution_mode),
|
||||
resolution_kind,
|
||||
)?;
|
||||
// TODO(bartlomieju): skipped checking errors for commonJS resolution and
|
||||
// "preserveSymlinksMain"/"preserveSymlinks" options.
|
||||
|
@ -385,13 +393,13 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
&self,
|
||||
path: &Path,
|
||||
maybe_referrer: Option<&Url>,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
) -> Result<Url, TypesNotFoundError> {
|
||||
fn probe_extensions<TEnv: NodeResolverEnv>(
|
||||
fs: &TEnv,
|
||||
path: &Path,
|
||||
lowercase_path: &str,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
) -> Option<PathBuf> {
|
||||
let mut searched_for_d_mts = false;
|
||||
let mut searched_for_d_cts = false;
|
||||
|
@ -414,11 +422,11 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
return Some(dts_path);
|
||||
}
|
||||
|
||||
let specific_dts_path = match referrer_kind {
|
||||
NodeModuleKind::Cjs if !searched_for_d_cts => {
|
||||
let specific_dts_path = match resolution_mode {
|
||||
ResolutionMode::Require if !searched_for_d_cts => {
|
||||
Some(with_known_extension(path, "d.cts"))
|
||||
}
|
||||
NodeModuleKind::Esm if !searched_for_d_mts => {
|
||||
ResolutionMode::Import if !searched_for_d_mts => {
|
||||
Some(with_known_extension(path, "d.mts"))
|
||||
}
|
||||
_ => None, // already searched above
|
||||
|
@ -439,7 +447,7 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
return Ok(url_from_file_path(path).unwrap());
|
||||
}
|
||||
if let Some(path) =
|
||||
probe_extensions(&self.env, path, &lowercase_path, referrer_kind)
|
||||
probe_extensions(&self.env, path, &lowercase_path, resolution_mode)
|
||||
{
|
||||
return Ok(url_from_file_path(&path).unwrap());
|
||||
}
|
||||
|
@ -448,9 +456,9 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
path,
|
||||
/* sub path */ ".",
|
||||
maybe_referrer,
|
||||
referrer_kind,
|
||||
conditions_from_module_kind(referrer_kind),
|
||||
NodeResolutionMode::Types,
|
||||
resolution_mode,
|
||||
conditions_from_resolution_mode(resolution_mode),
|
||||
NodeResolutionKind::Types,
|
||||
);
|
||||
if let Ok(resolution) = resolution_result {
|
||||
return Ok(resolution);
|
||||
|
@ -460,7 +468,7 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
&self.env,
|
||||
&index_path,
|
||||
&index_path.to_string_lossy().to_lowercase(),
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
) {
|
||||
return Ok(url_from_file_path(&path).unwrap());
|
||||
}
|
||||
|
@ -480,10 +488,10 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
&self,
|
||||
name: &str,
|
||||
maybe_referrer: Option<&Url>,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
referrer_pkg_json: Option<&PackageJson>,
|
||||
conditions: &[&str],
|
||||
mode: NodeResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<Url, PackageImportsResolveError> {
|
||||
if name == "#" || name.starts_with("#/") || name.ends_with('/') {
|
||||
let reason = "is not a valid internal imports specifier name";
|
||||
|
@ -509,11 +517,11 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
"",
|
||||
name,
|
||||
maybe_referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
false,
|
||||
true,
|
||||
conditions,
|
||||
mode,
|
||||
resolution_kind,
|
||||
)?;
|
||||
if let Some(resolved) = maybe_resolved {
|
||||
return Ok(resolved);
|
||||
|
@ -549,11 +557,11 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
best_match_subpath.unwrap(),
|
||||
best_match,
|
||||
maybe_referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
true,
|
||||
true,
|
||||
conditions,
|
||||
mode,
|
||||
resolution_kind,
|
||||
)?;
|
||||
if let Some(resolved) = maybe_resolved {
|
||||
return Ok(resolved);
|
||||
|
@ -581,11 +589,11 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
match_: &str,
|
||||
package_json_path: &Path,
|
||||
maybe_referrer: Option<&Url>,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
pattern: bool,
|
||||
internal: bool,
|
||||
conditions: &[&str],
|
||||
mode: NodeResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<Url, PackageTargetResolveError> {
|
||||
if !subpath.is_empty() && !pattern && !target.ends_with('/') {
|
||||
return Err(
|
||||
|
@ -626,9 +634,9 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
let result = match self.package_resolve(
|
||||
&export_target,
|
||||
&package_json_url,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
conditions,
|
||||
mode,
|
||||
resolution_kind,
|
||||
) {
|
||||
Ok(url) => Ok(url),
|
||||
Err(err) => match err.code() {
|
||||
|
@ -649,8 +657,8 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
pkg_json_path: package_json_path.to_path_buf(),
|
||||
target: export_target.to_string(),
|
||||
maybe_referrer: maybe_referrer.map(ToOwned::to_owned),
|
||||
referrer_kind,
|
||||
mode,
|
||||
resolution_mode,
|
||||
resolution_kind,
|
||||
},
|
||||
)
|
||||
.into(),
|
||||
|
@ -746,11 +754,11 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
subpath: &str,
|
||||
package_subpath: &str,
|
||||
maybe_referrer: Option<&Url>,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
pattern: bool,
|
||||
internal: bool,
|
||||
conditions: &[&str],
|
||||
mode: NodeResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<Option<Url>, PackageTargetResolveError> {
|
||||
let result = self.resolve_package_target_inner(
|
||||
package_json_path,
|
||||
|
@ -758,16 +766,16 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
subpath,
|
||||
package_subpath,
|
||||
maybe_referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
pattern,
|
||||
internal,
|
||||
conditions,
|
||||
mode,
|
||||
resolution_kind,
|
||||
);
|
||||
match result {
|
||||
Ok(maybe_resolved) => Ok(maybe_resolved),
|
||||
Err(err) => {
|
||||
if mode.is_types()
|
||||
if resolution_kind.is_types()
|
||||
&& err.code() == NodeJsErrorCode::ERR_TYPES_NOT_FOUND
|
||||
&& conditions != TYPES_ONLY_CONDITIONS
|
||||
{
|
||||
|
@ -779,11 +787,11 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
subpath,
|
||||
package_subpath,
|
||||
maybe_referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
pattern,
|
||||
internal,
|
||||
TYPES_ONLY_CONDITIONS,
|
||||
mode,
|
||||
resolution_kind,
|
||||
) {
|
||||
return Ok(Some(resolved));
|
||||
}
|
||||
|
@ -802,11 +810,11 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
subpath: &str,
|
||||
package_subpath: &str,
|
||||
maybe_referrer: Option<&Url>,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
pattern: bool,
|
||||
internal: bool,
|
||||
conditions: &[&str],
|
||||
mode: NodeResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<Option<Url>, PackageTargetResolveError> {
|
||||
if let Some(target) = target.as_str() {
|
||||
let url = self.resolve_package_target_string(
|
||||
|
@ -815,18 +823,18 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
package_subpath,
|
||||
package_json_path,
|
||||
maybe_referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
pattern,
|
||||
internal,
|
||||
conditions,
|
||||
mode,
|
||||
resolution_kind,
|
||||
)?;
|
||||
if mode.is_types() && url.scheme() == "file" {
|
||||
if resolution_kind.is_types() && url.scheme() == "file" {
|
||||
let path = deno_path_util::url_to_file_path(&url).unwrap();
|
||||
return Ok(Some(self.path_to_declaration_url(
|
||||
&path,
|
||||
maybe_referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
)?));
|
||||
} else {
|
||||
return Ok(Some(url));
|
||||
|
@ -844,11 +852,11 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
subpath,
|
||||
package_subpath,
|
||||
maybe_referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
pattern,
|
||||
internal,
|
||||
conditions,
|
||||
mode,
|
||||
resolution_kind,
|
||||
);
|
||||
|
||||
match resolved_result {
|
||||
|
@ -882,7 +890,7 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
|
||||
if key == "default"
|
||||
|| conditions.contains(&key.as_str())
|
||||
|| mode.is_types() && key.as_str() == "types"
|
||||
|| resolution_kind.is_types() && key.as_str() == "types"
|
||||
{
|
||||
let condition_target = target_obj.get(key).unwrap();
|
||||
|
||||
|
@ -892,11 +900,11 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
subpath,
|
||||
package_subpath,
|
||||
maybe_referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
pattern,
|
||||
internal,
|
||||
conditions,
|
||||
mode,
|
||||
resolution_kind,
|
||||
)?;
|
||||
match resolved {
|
||||
Some(resolved) => return Ok(Some(resolved)),
|
||||
|
@ -929,9 +937,9 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
package_subpath: &str,
|
||||
package_exports: &Map<String, Value>,
|
||||
maybe_referrer: Option<&Url>,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
conditions: &[&str],
|
||||
mode: NodeResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<Url, PackageExportsResolveError> {
|
||||
if package_exports.contains_key(package_subpath)
|
||||
&& package_subpath.find('*').is_none()
|
||||
|
@ -944,11 +952,11 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
"",
|
||||
package_subpath,
|
||||
maybe_referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
false,
|
||||
false,
|
||||
conditions,
|
||||
mode,
|
||||
resolution_kind,
|
||||
)?;
|
||||
return match resolved {
|
||||
Some(resolved) => Ok(resolved),
|
||||
|
@ -957,7 +965,7 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
pkg_json_path: package_json_path.to_path_buf(),
|
||||
subpath: package_subpath.to_string(),
|
||||
maybe_referrer: maybe_referrer.map(ToOwned::to_owned),
|
||||
mode,
|
||||
resolution_kind,
|
||||
}
|
||||
.into(),
|
||||
),
|
||||
|
@ -1006,11 +1014,11 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
&best_match_subpath.unwrap(),
|
||||
best_match,
|
||||
maybe_referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
true,
|
||||
false,
|
||||
conditions,
|
||||
mode,
|
||||
resolution_kind,
|
||||
)?;
|
||||
if let Some(resolved) = maybe_resolved {
|
||||
return Ok(resolved);
|
||||
|
@ -1020,7 +1028,7 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
pkg_json_path: package_json_path.to_path_buf(),
|
||||
subpath: package_subpath.to_string(),
|
||||
maybe_referrer: maybe_referrer.map(ToOwned::to_owned),
|
||||
mode,
|
||||
resolution_kind,
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
|
@ -1032,7 +1040,7 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
pkg_json_path: package_json_path.to_path_buf(),
|
||||
subpath: package_subpath.to_string(),
|
||||
maybe_referrer: maybe_referrer.map(ToOwned::to_owned),
|
||||
mode,
|
||||
resolution_kind,
|
||||
}
|
||||
.into(),
|
||||
)
|
||||
|
@ -1042,9 +1050,9 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
&self,
|
||||
specifier: &str,
|
||||
referrer: &Url,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
conditions: &[&str],
|
||||
mode: NodeResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<Url, PackageResolveError> {
|
||||
let (package_name, package_subpath, _is_scoped) =
|
||||
parse_npm_pkg_name(specifier, referrer)?;
|
||||
|
@ -1061,9 +1069,9 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
&package_subpath,
|
||||
exports,
|
||||
Some(referrer),
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
conditions,
|
||||
mode,
|
||||
resolution_kind,
|
||||
)
|
||||
.map_err(|err| err.into());
|
||||
}
|
||||
|
@ -1074,9 +1082,9 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
&package_name,
|
||||
&package_subpath,
|
||||
referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
conditions,
|
||||
mode,
|
||||
resolution_kind,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1086,28 +1094,28 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
package_name: &str,
|
||||
package_subpath: &str,
|
||||
referrer: &Url,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
conditions: &[&str],
|
||||
mode: NodeResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<Url, PackageResolveError> {
|
||||
let result = self.resolve_package_subpath_for_package_inner(
|
||||
package_name,
|
||||
package_subpath,
|
||||
referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
conditions,
|
||||
mode,
|
||||
resolution_kind,
|
||||
);
|
||||
if mode.is_types() && !matches!(result, Ok(Url { .. })) {
|
||||
if resolution_kind.is_types() && !matches!(result, Ok(Url { .. })) {
|
||||
// try to resolve with the @types package
|
||||
let package_name = types_package_name(package_name);
|
||||
if let Ok(result) = self.resolve_package_subpath_for_package_inner(
|
||||
&package_name,
|
||||
package_subpath,
|
||||
referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
conditions,
|
||||
mode,
|
||||
resolution_kind,
|
||||
) {
|
||||
return Ok(result);
|
||||
}
|
||||
|
@ -1121,9 +1129,9 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
package_name: &str,
|
||||
package_subpath: &str,
|
||||
referrer: &Url,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
conditions: &[&str],
|
||||
mode: NodeResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<Url, PackageResolveError> {
|
||||
let package_dir_path = self
|
||||
.npm_pkg_folder_resolver
|
||||
|
@ -1148,9 +1156,9 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
&package_dir_path,
|
||||
package_subpath,
|
||||
Some(referrer),
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
conditions,
|
||||
mode,
|
||||
resolution_kind,
|
||||
)
|
||||
.map_err(|err| err.into())
|
||||
}
|
||||
|
@ -1161,9 +1169,9 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
package_dir_path: &Path,
|
||||
package_subpath: &str,
|
||||
maybe_referrer: Option<&Url>,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
conditions: &[&str],
|
||||
mode: NodeResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<Url, PackageSubpathResolveError> {
|
||||
let package_json_path = package_dir_path.join("package.json");
|
||||
match self
|
||||
|
@ -1174,17 +1182,17 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
&pkg_json,
|
||||
package_subpath,
|
||||
maybe_referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
conditions,
|
||||
mode,
|
||||
resolution_kind,
|
||||
),
|
||||
None => self
|
||||
.resolve_package_subpath_no_pkg_json(
|
||||
package_dir_path,
|
||||
package_subpath,
|
||||
maybe_referrer,
|
||||
referrer_kind,
|
||||
mode,
|
||||
resolution_mode,
|
||||
resolution_kind,
|
||||
)
|
||||
.map_err(|err| {
|
||||
PackageSubpathResolveErrorKind::LegacyResolve(err).into()
|
||||
|
@ -1198,9 +1206,9 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
package_json: &PackageJson,
|
||||
package_subpath: &str,
|
||||
referrer: Option<&Url>,
|
||||
referrer_kind: NodeModuleKind,
|
||||
resolution_mode: ResolutionMode,
|
||||
conditions: &[&str],
|
||||
mode: NodeResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<Url, PackageSubpathResolveError> {
|
||||
if let Some(exports) = &package_json.exports {
|
||||
let result = self.package_exports_resolve(
|
||||
|
@ -1208,16 +1216,21 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
package_subpath,
|
||||
exports,
|
||||
referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
conditions,
|
||||
mode,
|
||||
resolution_kind,
|
||||
);
|
||||
match result {
|
||||
Ok(found) => return Ok(found),
|
||||
Err(exports_err) => {
|
||||
if mode.is_types() && package_subpath == "." {
|
||||
if resolution_kind.is_types() && package_subpath == "." {
|
||||
return self
|
||||
.legacy_main_resolve(package_json, referrer, referrer_kind, mode)
|
||||
.legacy_main_resolve(
|
||||
package_json,
|
||||
referrer,
|
||||
resolution_mode,
|
||||
resolution_kind,
|
||||
)
|
||||
.map_err(|err| {
|
||||
PackageSubpathResolveErrorKind::LegacyResolve(err).into()
|
||||
});
|
||||
|
@ -1231,7 +1244,12 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
|
||||
if package_subpath == "." {
|
||||
return self
|
||||
.legacy_main_resolve(package_json, referrer, referrer_kind, mode)
|
||||
.legacy_main_resolve(
|
||||
package_json,
|
||||
referrer,
|
||||
resolution_mode,
|
||||
resolution_kind,
|
||||
)
|
||||
.map_err(|err| {
|
||||
PackageSubpathResolveErrorKind::LegacyResolve(err).into()
|
||||
});
|
||||
|
@ -1242,8 +1260,8 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
package_json.path.parent().unwrap(),
|
||||
package_subpath,
|
||||
referrer,
|
||||
referrer_kind,
|
||||
mode,
|
||||
resolution_mode,
|
||||
resolution_kind,
|
||||
)
|
||||
.map_err(|err| {
|
||||
PackageSubpathResolveErrorKind::LegacyResolve(err.into()).into()
|
||||
|
@ -1255,13 +1273,13 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
directory: &Path,
|
||||
package_subpath: &str,
|
||||
referrer: Option<&Url>,
|
||||
referrer_kind: NodeModuleKind,
|
||||
mode: NodeResolutionMode,
|
||||
resolution_mode: ResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<Url, TypesNotFoundError> {
|
||||
assert_ne!(package_subpath, ".");
|
||||
let file_path = directory.join(package_subpath);
|
||||
if mode.is_types() {
|
||||
Ok(self.path_to_declaration_url(&file_path, referrer, referrer_kind)?)
|
||||
if resolution_kind.is_types() {
|
||||
Ok(self.path_to_declaration_url(&file_path, referrer, resolution_mode)?)
|
||||
} else {
|
||||
Ok(url_from_file_path(&file_path).unwrap())
|
||||
}
|
||||
|
@ -1272,19 +1290,24 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
directory: &Path,
|
||||
package_subpath: &str,
|
||||
maybe_referrer: Option<&Url>,
|
||||
referrer_kind: NodeModuleKind,
|
||||
mode: NodeResolutionMode,
|
||||
resolution_mode: ResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<Url, LegacyResolveError> {
|
||||
if package_subpath == "." {
|
||||
self.legacy_index_resolve(directory, maybe_referrer, referrer_kind, mode)
|
||||
self.legacy_index_resolve(
|
||||
directory,
|
||||
maybe_referrer,
|
||||
resolution_mode,
|
||||
resolution_kind,
|
||||
)
|
||||
} else {
|
||||
self
|
||||
.resolve_subpath_exact(
|
||||
directory,
|
||||
package_subpath,
|
||||
maybe_referrer,
|
||||
referrer_kind,
|
||||
mode,
|
||||
resolution_mode,
|
||||
resolution_kind,
|
||||
)
|
||||
.map_err(|err| err.into())
|
||||
}
|
||||
|
@ -1294,21 +1317,25 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
&self,
|
||||
package_json: &PackageJson,
|
||||
maybe_referrer: Option<&Url>,
|
||||
referrer_kind: NodeModuleKind,
|
||||
mode: NodeResolutionMode,
|
||||
resolution_mode: ResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<Url, LegacyResolveError> {
|
||||
let maybe_main = if mode.is_types() {
|
||||
let pkg_json_kind = match resolution_mode {
|
||||
ResolutionMode::Require => deno_package_json::NodeModuleKind::Cjs,
|
||||
ResolutionMode::Import => deno_package_json::NodeModuleKind::Esm,
|
||||
};
|
||||
let maybe_main = if resolution_kind.is_types() {
|
||||
match package_json.types.as_ref() {
|
||||
Some(types) => Some(types.as_str()),
|
||||
None => {
|
||||
// fallback to checking the main entrypoint for
|
||||
// a corresponding declaration file
|
||||
if let Some(main) = package_json.main(referrer_kind) {
|
||||
if let Some(main) = package_json.main(pkg_json_kind) {
|
||||
let main = package_json.path.parent().unwrap().join(main).clean();
|
||||
let decl_url_result = self.path_to_declaration_url(
|
||||
&main,
|
||||
maybe_referrer,
|
||||
referrer_kind,
|
||||
resolution_mode,
|
||||
);
|
||||
// don't surface errors, fallback to checking the index now
|
||||
if let Ok(url) = decl_url_result {
|
||||
|
@ -1319,7 +1346,7 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
package_json.main(referrer_kind)
|
||||
package_json.main(pkg_json_kind)
|
||||
};
|
||||
|
||||
if let Some(main) = maybe_main {
|
||||
|
@ -1329,12 +1356,12 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
}
|
||||
|
||||
// todo(dsherret): investigate exactly how node and typescript handles this
|
||||
let endings = if mode.is_types() {
|
||||
match referrer_kind {
|
||||
NodeModuleKind::Cjs => {
|
||||
let endings = if resolution_kind.is_types() {
|
||||
match resolution_mode {
|
||||
ResolutionMode::Require => {
|
||||
vec![".d.ts", ".d.cts", "/index.d.ts", "/index.d.cts"]
|
||||
}
|
||||
NodeModuleKind::Esm => vec![
|
||||
ResolutionMode::Import => vec![
|
||||
".d.ts",
|
||||
".d.mts",
|
||||
"/index.d.ts",
|
||||
|
@ -1363,8 +1390,8 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
self.legacy_index_resolve(
|
||||
package_json.path.parent().unwrap(),
|
||||
maybe_referrer,
|
||||
referrer_kind,
|
||||
mode,
|
||||
resolution_mode,
|
||||
resolution_kind,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1372,14 +1399,16 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
&self,
|
||||
directory: &Path,
|
||||
maybe_referrer: Option<&Url>,
|
||||
referrer_kind: NodeModuleKind,
|
||||
mode: NodeResolutionMode,
|
||||
resolution_mode: ResolutionMode,
|
||||
resolution_kind: NodeResolutionKind,
|
||||
) -> Result<Url, LegacyResolveError> {
|
||||
let index_file_names = if mode.is_types() {
|
||||
let index_file_names = if resolution_kind.is_types() {
|
||||
// todo(dsherret): investigate exactly how typescript does this
|
||||
match referrer_kind {
|
||||
NodeModuleKind::Cjs => vec!["index.d.ts", "index.d.cts"],
|
||||
NodeModuleKind::Esm => vec!["index.d.ts", "index.d.mts", "index.d.cts"],
|
||||
match resolution_mode {
|
||||
ResolutionMode::Require => vec!["index.d.ts", "index.d.cts"],
|
||||
ResolutionMode::Import => {
|
||||
vec!["index.d.ts", "index.d.mts", "index.d.cts"]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
vec!["index.js"]
|
||||
|
@ -1392,7 +1421,7 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
}
|
||||
}
|
||||
|
||||
if mode.is_types() {
|
||||
if resolution_kind.is_types() {
|
||||
Err(
|
||||
TypesNotFoundError(Box::new(TypesNotFoundErrorData {
|
||||
code_specifier: url_from_file_path(&directory.join("index.js"))
|
||||
|
|
|
@ -90,6 +90,7 @@ deno_net.workspace = true
|
|||
deno_node.workspace = true
|
||||
deno_path_util.workspace = true
|
||||
deno_permissions.workspace = true
|
||||
deno_telemetry.workspace = true
|
||||
deno_terminal.workspace = true
|
||||
deno_tls.workspace = true
|
||||
deno_url.workspace = true
|
||||
|
@ -100,7 +101,6 @@ deno_websocket.workspace = true
|
|||
deno_webstorage.workspace = true
|
||||
node_resolver = { workspace = true, features = ["sync"] }
|
||||
|
||||
async-trait.workspace = true
|
||||
color-print.workspace = true
|
||||
dlopen2.workspace = true
|
||||
encoding_rs.workspace = true
|
||||
|
@ -115,13 +115,7 @@ log.workspace = true
|
|||
netif = "0.1.6"
|
||||
notify.workspace = true
|
||||
once_cell.workspace = true
|
||||
opentelemetry.workspace = true
|
||||
opentelemetry-http.workspace = true
|
||||
opentelemetry-otlp.workspace = true
|
||||
opentelemetry-semantic-conventions.workspace = true
|
||||
opentelemetry_sdk.workspace = true
|
||||
percent-encoding.workspace = true
|
||||
pin-project.workspace = true
|
||||
regex.workspace = true
|
||||
rustyline = { workspace = true, features = ["custom-bindings"] }
|
||||
same-file = "1.0.6"
|
||||
|
|
|
@ -316,7 +316,8 @@ fn get_suggestions_for_terminal_errors(e: &JsError) -> Vec<FixSuggestion> {
|
|||
FixSuggestion::hint_multiline(&[
|
||||
"Rewrite this module to ESM,",
|
||||
cstr!("or change the file extension to <u>.cjs</u>,"),
|
||||
cstr!("or add <u>package.json</> next to the file with <i>\"type\": \"commonjs\"</> option."),
|
||||
cstr!("or add <u>package.json</> next to the file with <i>\"type\": \"commonjs\"</> option,"),
|
||||
cstr!("or pass <i>--unstable-detect-cjs</> flag to detect CommonJS when loading."),
|
||||
]),
|
||||
FixSuggestion::docs("https://docs.deno.com/go/commonjs"),
|
||||
];
|
||||
|
|
|
@ -29,7 +29,7 @@ import * as tty from "ext:runtime/40_tty.js";
|
|||
import * as kv from "ext:deno_kv/01_db.ts";
|
||||
import * as cron from "ext:deno_cron/01_cron.ts";
|
||||
import * as webgpuSurface from "ext:deno_webgpu/02_surface.js";
|
||||
import * as telemetry from "ext:runtime/telemetry.ts";
|
||||
import * as telemetry from "ext:deno_telemetry/telemetry.ts";
|
||||
|
||||
const denoNs = {
|
||||
Process: process.Process,
|
||||
|
|
|
@ -86,7 +86,7 @@ import {
|
|||
workerRuntimeGlobalProperties,
|
||||
} from "ext:runtime/98_global_scope_worker.js";
|
||||
import { SymbolDispose, SymbolMetadata } from "ext:deno_web/00_infra.js";
|
||||
import { bootstrap as bootstrapOtel } from "ext:runtime/telemetry.ts";
|
||||
import { bootstrap as bootstrapOtel } from "ext:deno_telemetry/telemetry.ts";
|
||||
|
||||
// deno-lint-ignore prefer-primordials
|
||||
if (Symbol.metadata) {
|
||||
|
|
|
@ -148,7 +148,7 @@ pub static UNSTABLE_GRANULAR_FLAGS: &[UnstableGranularFlag] = &[
|
|||
];
|
||||
|
||||
pub fn exit(code: i32) -> ! {
|
||||
crate::ops::otel::flush();
|
||||
deno_telemetry::flush();
|
||||
#[allow(clippy::disallowed_methods)]
|
||||
std::process::exit(code);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ pub mod bootstrap;
|
|||
pub mod fs_events;
|
||||
pub mod http;
|
||||
pub mod os;
|
||||
pub mod otel;
|
||||
pub mod permissions;
|
||||
pub mod process;
|
||||
pub mod runtime;
|
||||
|
|
|
@ -47,7 +47,6 @@ extension!(runtime,
|
|||
"40_signals.js",
|
||||
"40_tty.js",
|
||||
"41_prompt.js",
|
||||
"telemetry.ts",
|
||||
"90_deno_ns.js",
|
||||
"98_global_scope_shared.js",
|
||||
"98_global_scope_window.js",
|
||||
|
|
|
@ -268,6 +268,7 @@ pub fn create_runtime_snapshot(
|
|||
// `runtime/worker.rs`, `runtime/web_worker.rs` and `runtime/snapshot.rs`!
|
||||
let fs = std::sync::Arc::new(deno_fs::RealFs);
|
||||
let mut extensions: Vec<Extension> = vec![
|
||||
deno_telemetry::deno_telemetry::init_ops_and_esm(),
|
||||
deno_webidl::deno_webidl::init_ops_and_esm(),
|
||||
deno_console::deno_console::init_ops_and_esm(),
|
||||
deno_url::deno_url::init_ops_and_esm(),
|
||||
|
@ -314,7 +315,6 @@ pub fn create_runtime_snapshot(
|
|||
),
|
||||
ops::fs_events::deno_fs_events::init_ops(),
|
||||
ops::os::deno_os::init_ops(Default::default()),
|
||||
ops::otel::deno_otel::init_ops(),
|
||||
ops::permissions::deno_permissions::init_ops(),
|
||||
ops::process::deno_process::init_ops(None),
|
||||
ops::signal::deno_signal::init_ops(),
|
||||
|
|
|
@ -440,6 +440,7 @@ impl WebWorker {
|
|||
// `runtime/worker.rs` and `runtime/snapshot.rs`!
|
||||
|
||||
let mut extensions = vec![
|
||||
deno_telemetry::deno_telemetry::init_ops_and_esm(),
|
||||
// Web APIs
|
||||
deno_webidl::deno_webidl::init_ops_and_esm(),
|
||||
deno_console::deno_console::init_ops_and_esm(),
|
||||
|
@ -517,7 +518,6 @@ impl WebWorker {
|
|||
),
|
||||
ops::fs_events::deno_fs_events::init_ops_and_esm(),
|
||||
ops::os::deno_os_worker::init_ops_and_esm(),
|
||||
ops::otel::deno_otel::init_ops_and_esm(),
|
||||
ops::permissions::deno_permissions::init_ops_and_esm(),
|
||||
ops::process::deno_process::init_ops_and_esm(
|
||||
services.npm_process_state_provider,
|
||||
|
|
|
@ -348,6 +348,7 @@ impl MainWorker {
|
|||
// NOTE(bartlomieju): ordering is important here, keep it in sync with
|
||||
// `runtime/web_worker.rs` and `runtime/snapshot.rs`!
|
||||
let mut extensions = vec![
|
||||
deno_telemetry::deno_telemetry::init_ops_and_esm(),
|
||||
// Web APIs
|
||||
deno_webidl::deno_webidl::init_ops_and_esm(),
|
||||
deno_console::deno_console::init_ops_and_esm(),
|
||||
|
@ -428,7 +429,6 @@ impl MainWorker {
|
|||
),
|
||||
ops::fs_events::deno_fs_events::init_ops_and_esm(),
|
||||
ops::os::deno_os::init_ops_and_esm(exit_code.clone()),
|
||||
ops::otel::deno_otel::init_ops_and_esm(),
|
||||
ops::permissions::deno_permissions::init_ops_and_esm(),
|
||||
ops::process::deno_process::init_ops_and_esm(
|
||||
services.npm_process_state_provider,
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use crate::ops::otel::OtelConfig;
|
||||
use deno_core::v8;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use deno_telemetry::OtelConfig;
|
||||
use serde::Serialize;
|
||||
use std::cell::RefCell;
|
||||
use std::thread;
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
// Most of the tests for this are in deno_task_shell.
|
||||
// These tests are intended to only test integration.
|
||||
|
||||
use test_util as util;
|
||||
use util::TestContextBuilder;
|
||||
|
||||
// use test_util::env_vars_for_npm_tests;
|
||||
// use test_util::itest;
|
||||
// use test_util::TestContext;
|
||||
|
@ -28,3 +31,59 @@
|
|||
// exit_code: 1,
|
||||
// http_server: true,
|
||||
// });
|
||||
|
||||
#[test]
|
||||
fn deno_task_ansi_escape_codes() {
|
||||
let context = TestContextBuilder::default().use_temp_cwd().build();
|
||||
let temp_dir = context.temp_dir();
|
||||
temp_dir.write("deno.json", r#"{
|
||||
"tasks": {
|
||||
"dev": "echo 'BOOO!!!'",
|
||||
"next": "\u001b[3F\u001b[0G- dev\u001b[1E\u001b[2K echo 'I am your friend.'"
|
||||
}
|
||||
}
|
||||
"#);
|
||||
|
||||
context
|
||||
.new_command()
|
||||
.args_vec(["task"])
|
||||
.with_pty(|mut console| {
|
||||
console.expect("Available tasks:");
|
||||
console.expect("- dev");
|
||||
console.expect(" echo 'BOOO!!!'");
|
||||
console.expect("- next");
|
||||
console.expect(" - dev echo 'I am your friend.'");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deno_task_control_chars() {
|
||||
let context = TestContextBuilder::default().use_temp_cwd().build();
|
||||
let temp_dir = context.temp_dir();
|
||||
temp_dir.write(
|
||||
"deno.json",
|
||||
r#"{
|
||||
"tasks": {
|
||||
"dev": "echo 'BOOO!!!' && \r echo hi there is my command",
|
||||
"serve": {
|
||||
"description": "this is a\tm\rangled description",
|
||||
"command": "echo hello"
|
||||
}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
||||
context
|
||||
.new_command()
|
||||
.args_vec(["task"])
|
||||
.with_pty(|mut console| {
|
||||
console.expect("Available tasks:");
|
||||
console.expect("- dev");
|
||||
console
|
||||
.expect(" echo 'BOOO!!!' && \\r echo hi there is my command");
|
||||
console.expect("- serve");
|
||||
console.expect(" // this is a\\tm\\rangled description");
|
||||
console.expect(" echo hello");
|
||||
});
|
||||
}
|
||||
|
|
|
@ -338,6 +338,7 @@
|
|||
"test-fs-open-numeric-flags.js",
|
||||
"test-fs-open.js",
|
||||
"test-fs-opendir.js",
|
||||
"test-fs-promises-file-handle-stat.js",
|
||||
"test-fs-promises-writefile-with-fd.js",
|
||||
"test-fs-read-stream-autoClose.js",
|
||||
"test-fs-read-stream-concurrent-reads.js",
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<!-- deno-fmt-ignore-file -->
|
||||
# Remaining Node Tests
|
||||
|
||||
595 tests out of 3681 have been ported from Node 20.11.1 (16.16% ported, 83.94% remaining).
|
||||
|
||||
NOTE: This file should not be manually edited. Please edit `tests/node_compat/config.json` and run `deno task setup` in `tests/node_compat/runner` dir instead.
|
||||
|
||||
- [abort/test-abort-backtrace.js](https://github.com/nodejs/node/tree/v20.11.1/test/abort/test-abort-backtrace.js)
|
||||
|
@ -820,7 +822,6 @@ NOTE: This file should not be manually edited. Please edit `tests/node_compat/co
|
|||
- [parallel/test-fs-promises-file-handle-read-worker.js](https://github.com/nodejs/node/tree/v20.11.1/test/parallel/test-fs-promises-file-handle-read-worker.js)
|
||||
- [parallel/test-fs-promises-file-handle-read.js](https://github.com/nodejs/node/tree/v20.11.1/test/parallel/test-fs-promises-file-handle-read.js)
|
||||
- [parallel/test-fs-promises-file-handle-readFile.js](https://github.com/nodejs/node/tree/v20.11.1/test/parallel/test-fs-promises-file-handle-readFile.js)
|
||||
- [parallel/test-fs-promises-file-handle-stat.js](https://github.com/nodejs/node/tree/v20.11.1/test/parallel/test-fs-promises-file-handle-stat.js)
|
||||
- [parallel/test-fs-promises-file-handle-stream.js](https://github.com/nodejs/node/tree/v20.11.1/test/parallel/test-fs-promises-file-handle-stream.js)
|
||||
- [parallel/test-fs-promises-file-handle-sync.js](https://github.com/nodejs/node/tree/v20.11.1/test/parallel/test-fs-promises-file-handle-sync.js)
|
||||
- [parallel/test-fs-promises-file-handle-truncate.js](https://github.com/nodejs/node/tree/v20.11.1/test/parallel/test-fs-promises-file-handle-truncate.js)
|
||||
|
|
|
@ -74,15 +74,24 @@ async function updateToDo() {
|
|||
truncate: true,
|
||||
});
|
||||
|
||||
const missingTests = withoutAll(await getNodeTests(), await getDenoTests());
|
||||
const nodeTests = await getNodeTests();
|
||||
const portedTests = getDenoTests();
|
||||
const remainingTests = withoutAll(nodeTests, portedTests);
|
||||
const numPorted = portedTests.length;
|
||||
const numMissing = remainingTests.length;
|
||||
const numTotal = nodeTests.length;
|
||||
const portedPercentage = (numPorted / numTotal * 100).toFixed(2);
|
||||
const remainingPercentage = (numMissing / numTotal * 100).toFixed(2);
|
||||
|
||||
await file.write(encoder.encode(`<!-- deno-fmt-ignore-file -->
|
||||
# Remaining Node Tests
|
||||
|
||||
${numPorted} tests out of ${numTotal} have been ported from Node ${NODE_VERSION} (${portedPercentage}% ported, ${remainingPercentage}% remaining).
|
||||
|
||||
NOTE: This file should not be manually edited. Please edit \`tests/node_compat/config.json\` and run \`deno task setup\` in \`tests/node_compat/runner\` dir instead.
|
||||
|
||||
`));
|
||||
for (const test of missingTests) {
|
||||
for (const test of remainingTests) {
|
||||
await file.write(
|
||||
encoder.encode(
|
||||
`- [${test}](https://github.com/nodejs/node/tree/v${NODE_VERSION}/test/${test})\n`,
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 20.11.1
|
||||
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
|
||||
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
|
||||
// The following tests validate base functionality for the fs.promises
|
||||
// FileHandle.stat method.
|
||||
|
||||
const { open } = require('fs').promises;
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const assert = require('assert');
|
||||
|
||||
tmpdir.refresh();
|
||||
|
||||
async function validateStat() {
|
||||
const filePath = tmpdir.resolve('tmp-read-file.txt');
|
||||
const fileHandle = await open(filePath, 'w+');
|
||||
const stats = await fileHandle.stat();
|
||||
assert.ok(stats.mtime instanceof Date);
|
||||
await fileHandle.close();
|
||||
}
|
||||
|
||||
validateStat()
|
||||
.then(common.mustCall());
|
19
tests/specs/check/check_exclude_option/__test__.jsonc
Normal file
19
tests/specs/check/check_exclude_option/__test__.jsonc
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"tests": {
|
||||
"by_dir": {
|
||||
"args": "check --quiet --config deno.exclude_dir.json ignored/index.ts",
|
||||
"output": "",
|
||||
"exitCode": 0
|
||||
},
|
||||
"by_glob": {
|
||||
"args": "check --quiet --config deno.exclude_glob.json ignored/index.ts",
|
||||
"output": "",
|
||||
"exitCode": 0
|
||||
},
|
||||
"without": {
|
||||
"args": "check --quiet --config deno.json ignored/index.ts",
|
||||
"output": "exclude_option.ts.error.out",
|
||||
"exitCode": 1
|
||||
}
|
||||
}
|
||||
}
|
14
tests/specs/check/check_node_builtin_modules/__test__.jsonc
Normal file
14
tests/specs/check/check_node_builtin_modules/__test__.jsonc
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"tests": {
|
||||
"js": {
|
||||
"args": "check --quiet mod.js",
|
||||
"output": "mod.js.out",
|
||||
"exitCode": 1
|
||||
},
|
||||
"ts": {
|
||||
"args": "check --quiet mod.ts",
|
||||
"output": "mod.ts.out",
|
||||
"exitCode": 1
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,4 +2,4 @@ error: TS2769 [ERROR]: No overload matches this call.
|
|||
[WILDCARD]
|
||||
const _data = fs.readFileSync("./node_builtin.js", 123);
|
||||
~~~
|
||||
at file:///[WILDCARD]/node_builtin_modules/mod.js:3:52
|
||||
at file:///[WILDCARD]/mod.js:3:52
|
|
@ -2,12 +2,12 @@ error: TS2769 [ERROR]: No overload matches this call.
|
|||
[WILDCARD]
|
||||
const _data = fs.readFileSync("./node_builtin.js", 123);
|
||||
~~~
|
||||
at file:///[WILDCARD]/node_builtin_modules/mod.ts:2:52
|
||||
at file:///[WILDCARD]/mod.ts:2:52
|
||||
|
||||
TS2322 [ERROR]: Type 'string[]' is not assignable to type 'number[]'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
const _testString: number[] = builtinModules;
|
||||
~~~~~~~~~~~
|
||||
at file:///[WILDCARD]/node_builtin_modules/mod.ts:9:7
|
||||
at file:///[WILDCARD]/mod.ts:9:7
|
||||
|
||||
Found 2 errors.
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"args": "check --quiet node_builtin_modules/mod.js",
|
||||
"output": "node_builtin_modules/mod.js.out",
|
||||
"exitCode": 1
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
error: TS2769 [ERROR]: No overload matches this call.
|
||||
[WILDCARD]
|
||||
const _data = fs.readFileSync("./node_builtin.js", 123);
|
||||
~~~
|
||||
at file:///[WILDCARD]/node_builtin_modules/mod.js:3:52
|
|
@ -1,13 +0,0 @@
|
|||
error: TS2769 [ERROR]: No overload matches this call.
|
||||
[WILDCARD]
|
||||
const _data = fs.readFileSync("./node_builtin.js", 123);
|
||||
~~~
|
||||
at file:///[WILDCARD]/node_builtin_modules/mod.ts:2:52
|
||||
|
||||
TS2322 [ERROR]: Type 'string[]' is not assignable to type 'number[]'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
const _testString: number[] = builtinModules;
|
||||
~~~~~~~~~~~
|
||||
at file:///[WILDCARD]/node_builtin_modules/mod.ts:9:7
|
||||
|
||||
Found 2 errors.
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"args": "check --quiet node_builtin_modules/mod.ts",
|
||||
"output": "node_builtin_modules/mod.ts.out",
|
||||
"exitCode": 1
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
// @ts-check
|
||||
import fs from "node:fs";
|
||||
const _data = fs.readFileSync("./node_builtin.js", 123);
|
|
@ -1,9 +0,0 @@
|
|||
import fs from "node:fs";
|
||||
const _data = fs.readFileSync("./node_builtin.js", 123);
|
||||
|
||||
// check node:module specifically because for deno check it should
|
||||
// resolve to the @types/node package, but at runtime it uses a different
|
||||
// builtin object than deno_std
|
||||
import { builtinModules } from "node:module";
|
||||
// should error about being string[]
|
||||
const _testString: number[] = builtinModules;
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"args": "check --quiet --config exclude_option/deno.exclude_dir.json exclude_option/ignored/index.ts",
|
||||
"output": "",
|
||||
"exitCode": 0
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"args": "check --quiet --config exclude_option/deno.exclude_glob.json exclude_option/ignored/index.ts",
|
||||
"output": "",
|
||||
"exitCode": 0
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"exclude": [
|
||||
"ignored"
|
||||
]
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"exclude": [
|
||||
"ignored/**/*"
|
||||
]
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue