1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 04:52:26 -05:00

Merge remote-tracking branch 'origin/main' into update_wpt

This commit is contained in:
Luca Casonato 2024-11-28 18:37:50 +01:00
commit a5a93f2aef
No known key found for this signature in database
GPG key ID: 01A83EB62563811F
1035 changed files with 3392 additions and 7280 deletions

View file

@ -5,7 +5,7 @@ import { stringify } from "jsr:@std/yaml@^0.221/stringify";
// Bump this number when you want to purge the cache. // Bump this number when you want to purge the cache.
// Note: the tools/release/01_bump_crate_versions.ts script will update this version // Note: the tools/release/01_bump_crate_versions.ts script will update this version
// automatically via regex, so ensure that this line maintains this format. // automatically via regex, so ensure that this line maintains this format.
const cacheVersion = 27; const cacheVersion = 28;
const ubuntuX86Runner = "ubuntu-24.04"; const ubuntuX86Runner = "ubuntu-24.04";
const ubuntuX86XlRunner = "ubuntu-24.04-xl"; const ubuntuX86XlRunner = "ubuntu-24.04-xl";

View file

@ -361,8 +361,8 @@ jobs:
path: |- path: |-
~/.cargo/registry/index ~/.cargo/registry/index
~/.cargo/registry/cache ~/.cargo/registry/cache
key: '27-cargo-home-${{ matrix.os }}-${{ matrix.arch }}-${{ hashFiles(''Cargo.lock'') }}' key: '28-cargo-home-${{ matrix.os }}-${{ matrix.arch }}-${{ hashFiles(''Cargo.lock'') }}'
restore-keys: '27-cargo-home-${{ matrix.os }}-${{ matrix.arch }}' restore-keys: '28-cargo-home-${{ matrix.os }}-${{ matrix.arch }}'
if: '!(matrix.skip)' if: '!(matrix.skip)'
- name: Restore cache build output (PR) - name: Restore cache build output (PR)
uses: actions/cache/restore@v4 uses: actions/cache/restore@v4
@ -375,7 +375,7 @@ jobs:
!./target/*/*.zip !./target/*/*.zip
!./target/*/*.tar.gz !./target/*/*.tar.gz
key: never_saved key: never_saved
restore-keys: '27-cargo-target-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.profile }}-${{ matrix.job }}-' restore-keys: '28-cargo-target-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.profile }}-${{ matrix.job }}-'
- name: Apply and update mtime cache - name: Apply and update mtime cache
if: '!(matrix.skip) && (!startsWith(github.ref, ''refs/tags/''))' if: '!(matrix.skip) && (!startsWith(github.ref, ''refs/tags/''))'
uses: ./.github/mtime_cache uses: ./.github/mtime_cache
@ -685,7 +685,7 @@ jobs:
!./target/*/*.zip !./target/*/*.zip
!./target/*/*.sha256sum !./target/*/*.sha256sum
!./target/*/*.tar.gz !./target/*/*.tar.gz
key: '27-cargo-target-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.profile }}-${{ matrix.job }}-${{ github.sha }}' key: '28-cargo-target-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.profile }}-${{ matrix.job }}-${{ github.sha }}'
publish-canary: publish-canary:
name: publish canary name: publish canary
runs-on: ubuntu-24.04 runs-on: ubuntu-24.04

260
Cargo.lock generated
View file

@ -128,19 +128,6 @@ version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" 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]] [[package]]
name = "android_system_properties" name = "android_system_properties"
version = "0.1.5" version = "0.1.5"
@ -407,6 +394,12 @@ dependencies = [
"tower-service", "tower-service",
] ]
[[package]]
name = "az"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973"
[[package]] [[package]]
name = "backtrace" name = "backtrace"
version = "0.3.73" version = "0.3.73"
@ -1201,7 +1194,7 @@ dependencies = [
[[package]] [[package]]
name = "deno" name = "deno"
version = "2.1.1" version = "2.1.2"
dependencies = [ dependencies = [
"anstream", "anstream",
"async-trait", "async-trait",
@ -1233,6 +1226,7 @@ dependencies = [
"deno_runtime", "deno_runtime",
"deno_semver", "deno_semver",
"deno_task_shell", "deno_task_shell",
"deno_telemetry",
"deno_terminal 0.2.0", "deno_terminal 0.2.0",
"deno_tower_lsp", "deno_tower_lsp",
"dhat", "dhat",
@ -1371,7 +1365,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_bench_util" name = "deno_bench_util"
version = "0.173.0" version = "0.174.0"
dependencies = [ dependencies = [
"bencher", "bencher",
"deno_core", "deno_core",
@ -1380,7 +1374,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_broadcast_channel" name = "deno_broadcast_channel"
version = "0.173.0" version = "0.174.0"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"deno_core", "deno_core",
@ -1391,7 +1385,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_cache" name = "deno_cache"
version = "0.111.0" version = "0.112.0"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"deno_core", "deno_core",
@ -1424,7 +1418,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_canvas" name = "deno_canvas"
version = "0.48.0" version = "0.49.0"
dependencies = [ dependencies = [
"deno_core", "deno_core",
"deno_webgpu", "deno_webgpu",
@ -1459,18 +1453,19 @@ dependencies = [
[[package]] [[package]]
name = "deno_console" name = "deno_console"
version = "0.179.0" version = "0.180.0"
dependencies = [ dependencies = [
"deno_core", "deno_core",
] ]
[[package]] [[package]]
name = "deno_core" name = "deno_core"
version = "0.322.0" version = "0.323.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f593ef2b8acab8cd3ace9d50052edc65a3654fdbde808070cfa5da5cf7aaae6" checksum = "a781bcfe1b5211b8497f45bf5b3dba73036b8d5d1533c1f05d26ccf0afb25a78"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"az",
"bincode", "bincode",
"bit-set", "bit-set",
"bit-vec", "bit-vec",
@ -1506,7 +1501,7 @@ checksum = "fe4dccb6147bb3f3ba0c7a48e993bfeb999d2c2e47a81badee80e2b370c8d695"
[[package]] [[package]]
name = "deno_cron" name = "deno_cron"
version = "0.59.0" version = "0.60.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
@ -1519,7 +1514,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_crypto" name = "deno_crypto"
version = "0.193.0" version = "0.194.0"
dependencies = [ dependencies = [
"aes", "aes",
"aes-gcm", "aes-gcm",
@ -1556,18 +1551,16 @@ dependencies = [
[[package]] [[package]]
name = "deno_doc" name = "deno_doc"
version = "0.160.0" version = "0.161.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db2baa33e5d1ed235209c2990f5fe9644bac6b9e7bcb789dd92894f907b09ad7" checksum = "32d994915f85e873865fc341e592080a487b0a987d06177016b2d93fd62162f8"
dependencies = [ dependencies = [
"ammonia",
"anyhow", "anyhow",
"cfg-if", "cfg-if",
"comrak", "comrak",
"deno_ast", "deno_ast",
"deno_graph", "deno_graph",
"deno_path_util", "deno_path_util",
"futures",
"handlebars", "handlebars",
"html-escape", "html-escape",
"import_map", "import_map",
@ -1587,7 +1580,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_fetch" name = "deno_fetch"
version = "0.203.0" version = "0.204.0"
dependencies = [ dependencies = [
"base64 0.21.7", "base64 0.21.7",
"bytes", "bytes",
@ -1621,7 +1614,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_ffi" name = "deno_ffi"
version = "0.166.0" version = "0.167.0"
dependencies = [ dependencies = [
"deno_core", "deno_core",
"deno_permissions", "deno_permissions",
@ -1641,7 +1634,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_fs" name = "deno_fs"
version = "0.89.0" version = "0.90.0"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"base32", "base32",
@ -1664,9 +1657,9 @@ dependencies = [
[[package]] [[package]]
name = "deno_graph" name = "deno_graph"
version = "0.85.0" version = "0.86.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d097305aba3f119781fe82b4d5a85a1ad10c586a388ee4d754e5bf82901cc5c" checksum = "4c3f4be49dad28e794ff4eeb2daaf7956c97f8557097ef6f9c3ff1292e0a5c28"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
@ -1694,7 +1687,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_http" name = "deno_http"
version = "0.177.0" version = "0.178.0"
dependencies = [ dependencies = [
"async-compression", "async-compression",
"async-trait", "async-trait",
@ -1733,7 +1726,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_io" name = "deno_io"
version = "0.89.0" version = "0.90.0"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"deno_core", "deno_core",
@ -1754,7 +1747,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_kv" name = "deno_kv"
version = "0.87.0" version = "0.88.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
@ -1827,7 +1820,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_napi" name = "deno_napi"
version = "0.110.0" version = "0.111.0"
dependencies = [ dependencies = [
"deno_core", "deno_core",
"deno_permissions", "deno_permissions",
@ -1855,7 +1848,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_net" name = "deno_net"
version = "0.171.0" version = "0.172.0"
dependencies = [ dependencies = [
"deno_core", "deno_core",
"deno_permissions", "deno_permissions",
@ -1872,7 +1865,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_node" name = "deno_node"
version = "0.116.0" version = "0.117.0"
dependencies = [ dependencies = [
"aead-gcm-stream", "aead-gcm-stream",
"aes", "aes",
@ -1983,9 +1976,9 @@ dependencies = [
[[package]] [[package]]
name = "deno_ops" name = "deno_ops"
version = "0.198.0" version = "0.199.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "870826735cd9aa0376d2aadca14365b753e830e3cc16891efb9232845a6982a4" checksum = "a24a1f3e22029a57d3094b32070b8328eac793920b5a022027d360f085e6b245"
dependencies = [ dependencies = [
"proc-macro-rules", "proc-macro-rules",
"proc-macro2", "proc-macro2",
@ -2024,7 +2017,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_permissions" name = "deno_permissions"
version = "0.39.0" version = "0.40.0"
dependencies = [ dependencies = [
"deno_core", "deno_core",
"deno_path_util", "deno_path_util",
@ -2042,7 +2035,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_resolver" name = "deno_resolver"
version = "0.11.0" version = "0.12.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base32", "base32",
@ -2061,9 +2054,8 @@ dependencies = [
[[package]] [[package]]
name = "deno_runtime" name = "deno_runtime"
version = "0.188.0" version = "0.189.0"
dependencies = [ dependencies = [
"async-trait",
"color-print", "color-print",
"deno_ast", "deno_ast",
"deno_broadcast_channel", "deno_broadcast_channel",
@ -2084,6 +2076,7 @@ dependencies = [
"deno_node", "deno_node",
"deno_path_util", "deno_path_util",
"deno_permissions", "deno_permissions",
"deno_telemetry",
"deno_terminal 0.2.0", "deno_terminal 0.2.0",
"deno_tls", "deno_tls",
"deno_url", "deno_url",
@ -2109,13 +2102,7 @@ dependencies = [
"notify", "notify",
"ntapi", "ntapi",
"once_cell", "once_cell",
"opentelemetry",
"opentelemetry-http",
"opentelemetry-otlp",
"opentelemetry-semantic-conventions",
"opentelemetry_sdk",
"percent-encoding", "percent-encoding",
"pin-project",
"regex", "regex",
"rustyline", "rustyline",
"same-file", "same-file",
@ -2164,6 +2151,27 @@ dependencies = [
"tokio-util", "tokio-util",
] ]
[[package]]
name = "deno_telemetry"
version = "0.2.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]] [[package]]
name = "deno_terminal" name = "deno_terminal"
version = "0.1.1" version = "0.1.1"
@ -2186,7 +2194,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_tls" name = "deno_tls"
version = "0.166.0" version = "0.167.0"
dependencies = [ dependencies = [
"deno_core", "deno_core",
"deno_native_certs", "deno_native_certs",
@ -2235,7 +2243,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_url" name = "deno_url"
version = "0.179.0" version = "0.180.0"
dependencies = [ dependencies = [
"deno_bench_util", "deno_bench_util",
"deno_console", "deno_console",
@ -2247,7 +2255,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_web" name = "deno_web"
version = "0.210.0" version = "0.211.0"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"base64-simd 0.8.0", "base64-simd 0.8.0",
@ -2269,7 +2277,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_webgpu" name = "deno_webgpu"
version = "0.146.0" version = "0.147.0"
dependencies = [ dependencies = [
"deno_core", "deno_core",
"raw-window-handle", "raw-window-handle",
@ -2282,7 +2290,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_webidl" name = "deno_webidl"
version = "0.179.0" version = "0.180.0"
dependencies = [ dependencies = [
"deno_bench_util", "deno_bench_util",
"deno_core", "deno_core",
@ -2290,7 +2298,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_websocket" name = "deno_websocket"
version = "0.184.0" version = "0.185.0"
dependencies = [ dependencies = [
"bytes", "bytes",
"deno_core", "deno_core",
@ -2312,7 +2320,7 @@ dependencies = [
[[package]] [[package]]
name = "deno_webstorage" name = "deno_webstorage"
version = "0.174.0" version = "0.175.0"
dependencies = [ dependencies = [
"deno_core", "deno_core",
"deno_web", "deno_web",
@ -3249,16 +3257,6 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" 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]] [[package]]
name = "futures" name = "futures"
version = "0.3.30" version = "0.3.30"
@ -3786,20 +3784,6 @@ dependencies = [
"utf8-width", "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]] [[package]]
name = "http" name = "http"
version = "0.2.12" version = "0.2.12"
@ -4647,12 +4631,6 @@ dependencies = [
"serde_repr", "serde_repr",
] ]
[[package]]
name = "mac"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4"
[[package]] [[package]]
name = "malloc_buf" name = "malloc_buf"
version = "0.0.6" version = "0.0.6"
@ -4675,26 +4653,6 @@ dependencies = [
"tiny_pretty", "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]] [[package]]
name = "markup_fmt" name = "markup_fmt"
version = "0.16.0" version = "0.16.0"
@ -4875,7 +4833,7 @@ dependencies = [
[[package]] [[package]]
name = "napi_sym" name = "napi_sym"
version = "0.109.0" version = "0.110.0"
dependencies = [ dependencies = [
"quote", "quote",
"serde", "serde",
@ -4930,7 +4888,7 @@ dependencies = [
[[package]] [[package]]
name = "node_resolver" name = "node_resolver"
version = "0.18.0" version = "0.19.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
@ -5452,27 +5410,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc"
dependencies = [ dependencies = [
"phf_macros", "phf_macros",
"phf_shared 0.11.2", "phf_shared",
]
[[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",
] ]
[[package]] [[package]]
@ -5481,7 +5419,7 @@ version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0"
dependencies = [ dependencies = [
"phf_shared 0.11.2", "phf_shared",
"rand", "rand",
] ]
@ -5491,22 +5429,13 @@ version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b"
dependencies = [ dependencies = [
"phf_generator 0.11.2", "phf_generator",
"phf_shared 0.11.2", "phf_shared",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.87", "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]] [[package]]
name = "phf_shared" name = "phf_shared"
version = "0.11.2" version = "0.11.2"
@ -5629,12 +5558,6 @@ version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "precomputed-hash"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
[[package]] [[package]]
name = "pretty_assertions" name = "pretty_assertions"
version = "1.4.0" version = "1.4.0"
@ -6654,9 +6577,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_v8" name = "serde_v8"
version = "0.231.0" version = "0.232.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a0c48b8842ebae21c52da1d978fba5c2be5991680bddfdc1a36ee0ccbc60114" checksum = "5c9feae92f7293fcc1a32a86be1a399859c0637e55dad8991d5258c43f7ff4d2"
dependencies = [ dependencies = [
"num-bigint", "num-bigint",
"serde", "serde",
@ -6969,32 +6892,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" 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]] [[package]]
name = "string_enum" name = "string_enum"
version = "0.4.4" version = "0.4.4"
@ -7582,17 +7479,6 @@ dependencies = [
"windows-sys 0.52.0", "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]] [[package]]
name = "termcolor" name = "termcolor"
version = "1.4.1" version = "1.4.1"

View file

@ -21,6 +21,7 @@ members = [
"ext/napi/sym", "ext/napi/sym",
"ext/net", "ext/net",
"ext/node", "ext/node",
"ext/telemetry",
"ext/url", "ext/url",
"ext/web", "ext/web",
"ext/webgpu", "ext/webgpu",
@ -46,19 +47,19 @@ repository = "https://github.com/denoland/deno"
[workspace.dependencies] [workspace.dependencies]
deno_ast = { version = "=0.43.3", features = ["transpiling"] } 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_bench_util = { version = "0.174.0", path = "./bench_util" }
deno_config = { version = "=0.39.2", features = ["workspace", "sync"] } deno_config = { version = "=0.39.2", features = ["workspace", "sync"] }
deno_lockfile = "=0.23.1" deno_lockfile = "=0.23.1"
deno_media_type = { version = "0.2.0", features = ["module_specifier"] } deno_media_type = { version = "0.2.0", features = ["module_specifier"] }
deno_npm = "=0.25.4" deno_npm = "=0.25.4"
deno_path_util = "=0.2.1" deno_path_util = "=0.2.1"
deno_permissions = { version = "0.39.0", path = "./runtime/permissions" } deno_permissions = { version = "0.40.0", path = "./runtime/permissions" }
deno_runtime = { version = "0.188.0", path = "./runtime" } deno_runtime = { version = "0.189.0", path = "./runtime" }
deno_semver = "=0.5.16" deno_semver = "=0.5.16"
deno_terminal = "0.2.0" deno_terminal = "0.2.0"
napi_sym = { version = "0.109.0", path = "./ext/napi/sym" } napi_sym = { version = "0.110.0", path = "./ext/napi/sym" }
test_util = { package = "test_server", path = "./tests/util/server" } test_util = { package = "test_server", path = "./tests/util/server" }
denokv_proto = "0.8.4" denokv_proto = "0.8.4"
@ -67,32 +68,33 @@ denokv_remote = "0.8.4"
denokv_sqlite = { default-features = false, version = "0.8.4" } denokv_sqlite = { default-features = false, version = "0.8.4" }
# exts # exts
deno_broadcast_channel = { version = "0.173.0", path = "./ext/broadcast_channel" } deno_broadcast_channel = { version = "0.174.0", path = "./ext/broadcast_channel" }
deno_cache = { version = "0.111.0", path = "./ext/cache" } deno_cache = { version = "0.112.0", path = "./ext/cache" }
deno_canvas = { version = "0.48.0", path = "./ext/canvas" } deno_canvas = { version = "0.49.0", path = "./ext/canvas" }
deno_console = { version = "0.179.0", path = "./ext/console" } deno_console = { version = "0.180.0", path = "./ext/console" }
deno_cron = { version = "0.59.0", path = "./ext/cron" } deno_cron = { version = "0.60.0", path = "./ext/cron" }
deno_crypto = { version = "0.193.0", path = "./ext/crypto" } deno_crypto = { version = "0.194.0", path = "./ext/crypto" }
deno_fetch = { version = "0.203.0", path = "./ext/fetch" } deno_fetch = { version = "0.204.0", path = "./ext/fetch" }
deno_ffi = { version = "0.166.0", path = "./ext/ffi" } deno_ffi = { version = "0.167.0", path = "./ext/ffi" }
deno_fs = { version = "0.89.0", path = "./ext/fs" } deno_fs = { version = "0.90.0", path = "./ext/fs" }
deno_http = { version = "0.177.0", path = "./ext/http" } deno_http = { version = "0.178.0", path = "./ext/http" }
deno_io = { version = "0.89.0", path = "./ext/io" } deno_io = { version = "0.90.0", path = "./ext/io" }
deno_kv = { version = "0.87.0", path = "./ext/kv" } deno_kv = { version = "0.88.0", path = "./ext/kv" }
deno_napi = { version = "0.110.0", path = "./ext/napi" } deno_napi = { version = "0.111.0", path = "./ext/napi" }
deno_net = { version = "0.171.0", path = "./ext/net" } deno_net = { version = "0.172.0", path = "./ext/net" }
deno_node = { version = "0.116.0", path = "./ext/node" } deno_node = { version = "0.117.0", path = "./ext/node" }
deno_tls = { version = "0.166.0", path = "./ext/tls" } deno_telemetry = { version = "0.2.0", path = "./ext/telemetry" }
deno_url = { version = "0.179.0", path = "./ext/url" } deno_tls = { version = "0.167.0", path = "./ext/tls" }
deno_web = { version = "0.210.0", path = "./ext/web" } deno_url = { version = "0.180.0", path = "./ext/url" }
deno_webgpu = { version = "0.146.0", path = "./ext/webgpu" } deno_web = { version = "0.211.0", path = "./ext/web" }
deno_webidl = { version = "0.179.0", path = "./ext/webidl" } deno_webgpu = { version = "0.147.0", path = "./ext/webgpu" }
deno_websocket = { version = "0.184.0", path = "./ext/websocket" } deno_webidl = { version = "0.180.0", path = "./ext/webidl" }
deno_webstorage = { version = "0.174.0", path = "./ext/webstorage" } deno_websocket = { version = "0.185.0", path = "./ext/websocket" }
deno_webstorage = { version = "0.175.0", path = "./ext/webstorage" }
# resolvers # resolvers
deno_resolver = { version = "0.11.0", path = "./resolvers/deno" } deno_resolver = { version = "0.12.0", path = "./resolvers/deno" }
node_resolver = { version = "0.18.0", path = "./resolvers/node" } node_resolver = { version = "0.19.0", path = "./resolvers/node" }
aes = "=0.8.3" aes = "=0.8.3"
anyhow = "1.0.57" anyhow = "1.0.57"

View file

@ -6,6 +6,50 @@ https://github.com/denoland/deno/releases
We also have one-line install commands at: We also have one-line install commands at:
https://github.com/denoland/deno_install https://github.com/denoland/deno_install
### 2.1.2 / 2024.11.28
- feat(unstable): Instrument Deno.serve (#26964)
- feat(unstable): Instrument fetch (#27057)
- feat(unstable): repurpose `--unstable-detect-cjs` to attempt loading more
modules as cjs (#27094)
- fix(check): support jsdoc `@import` tag (#26991)
- fix(compile): correct buffered reading of assets and files (#27008)
- fix(compile): do not error embedding same symlink via multiple methods
(#27015)
- fix(compile): handle TypeScript file included as asset (#27032)
- fix(ext/fetch): don't throw when `bodyUsed` inspect after upgrade (#27088)
- fix(ext/node): `tls.connect` socket upgrades (#27125)
- fix(ext/node): add `fs.promises.fstat` and `FileHandle#stat` (#26719)
- fix(ext/webgpu): normalize limits to number (#27072)
- fix(ext/webgpu): use correct variable name (#27108)
- fix(ext/websocket): don't throw exception when sending to closed socket
(#26932)
- fix(fmt): return `None` if sql fmt result is the same (#27014)
- fix(info): resolve bare specifier pointing to workspace member (#27020)
- fix(init): always force managed node modules (#27047)
- fix(init): support scoped npm packages (#27128)
- fix(install): don't re-set up node_modules if running lifecycle script
(#26984)
- fix(lsp): remove stray debug output (#27010)
- fix(lsp): support task object notation for tasks request (#27076)
- fix(lsp): wasm file import completions (#27018)
- fix(node): correct resolution of dynamic import of esm from cjs (#27071)
- fix(node/fs): add missing stat path argument validation (#27086)
- fix(node/fs): missing uv error context for readFile (#27011)
- fix(node/http): casing ignored in ServerResponse.hasHeader() (#27105)
- fix(node/timers): error when passing id to clearTimeout/clearInterval (#27130)
- fix(runtime/ops): Fix watchfs remove event (#27041)
- fix(streams): reject `string` in `ReadableStream.from` type (#25116)
- fix(task): handle carriage return in task description (#27099)
- fix(task): handle multiline descriptions properly (#27069)
- fix(task): strip ansi codes and control chars when printing tasks (#27100)
- fix(tools/doc): HTML resolve main entrypoint from config file (#27103)
- fix: support bun specifiers in JSR publish (#24588)
- fix: support non-function exports in Wasm modules (#26992)
- perf(compile): read embedded files as static references when UTF-8 and reading
as strings (#27033)
- perf(ext/webstorage): use object wrap for `Storage` (#26931)
### 2.1.1 / 2024.11.21 ### 2.1.1 / 2024.11.21
- docs(add): clarification to add command (#26968) - docs(add): clarification to add command (#26968)

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_bench_util" name = "deno_bench_util"
version = "0.173.0" version = "0.174.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno" name = "deno"
version = "2.1.1" version = "2.1.2"
authors.workspace = true authors.workspace = true
default-run = "deno" default-run = "deno"
edition.workspace = true edition.workspace = true
@ -72,8 +72,8 @@ deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "proposa
deno_cache_dir.workspace = true deno_cache_dir.workspace = true
deno_config.workspace = true deno_config.workspace = true
deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] } deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] }
deno_doc = { version = "0.160.0", features = ["rust", "comrak"] } deno_doc = { version = "=0.161.1", features = ["rust", "comrak"] }
deno_graph = { version = "=0.85.0" } deno_graph = { version = "=0.86.2" }
deno_lint = { version = "=0.68.0", features = ["docs"] } deno_lint = { version = "=0.68.0", features = ["docs"] }
deno_lockfile.workspace = true deno_lockfile.workspace = true
deno_npm.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_runtime = { workspace = true, features = ["include_js_files_for_snapshotting"] }
deno_semver.workspace = true deno_semver.workspace = true
deno_task_shell = "=0.18.1" deno_task_shell = "=0.18.1"
deno_telemetry.workspace = true
deno_terminal.workspace = true deno_terminal.workspace = true
libsui = "0.5.0" libsui = "0.5.0"
node_resolver.workspace = true node_resolver.workspace = true

View file

@ -22,6 +22,8 @@ impl<'a> deno_config::fs::DenoConfigFs for DenoConfigFsAdapter<'a> {
self self
.0 .0
.read_text_file_lossy_sync(path, None) .read_text_file_lossy_sync(path, None)
// todo(https://github.com/denoland/deno_config/pull/140): avoid clone
.map(|s| s.into_owned())
.map_err(|err| err.into_io_error()) .map_err(|err| err.into_io_error())
} }

View file

@ -36,7 +36,7 @@ use deno_path_util::normalize_path;
use deno_path_util::url_to_file_path; use deno_path_util::url_to_file_path;
use deno_runtime::deno_permissions::PermissionsOptions; use deno_runtime::deno_permissions::PermissionsOptions;
use deno_runtime::deno_permissions::SysDescriptor; use deno_runtime::deno_permissions::SysDescriptor;
use deno_runtime::ops::otel::OtelConfig; use deno_telemetry::OtelConfig;
use log::debug; use log::debug;
use log::Level; use log::Level;
use serde::Deserialize; use serde::Deserialize;
@ -598,6 +598,7 @@ pub struct UnstableConfig {
// TODO(bartlomieju): remove in Deno 2.5 // TODO(bartlomieju): remove in Deno 2.5
pub legacy_flag_enabled: bool, // --unstable pub legacy_flag_enabled: bool, // --unstable
pub bare_node_builtins: bool, pub bare_node_builtins: bool,
pub detect_cjs: bool,
pub sloppy_imports: bool, pub sloppy_imports: bool,
pub features: Vec<String>, // --unstabe-kv --unstable-cron pub features: Vec<String>, // --unstabe-kv --unstable-cron
} }
@ -2662,7 +2663,7 @@ By default, outdated dependencies are only displayed.
Display outdated dependencies: Display outdated dependencies:
<p(245)>deno outdated</> <p(245)>deno outdated</>
<p(245)>deno outdated --compatible</> <p(245)>deno outdated --compatible</>
Update dependencies: Update dependencies:
<p(245)>deno outdated --update</> <p(245)>deno outdated --update</>
<p(245)>deno outdated --update --latest</> <p(245)>deno outdated --update --latest</>
@ -3047,7 +3048,7 @@ fn task_subcommand() -> Command {
List all available tasks: List all available tasks:
<p(245)>deno task</> <p(245)>deno task</>
Evaluate a task from string Evaluate a task from string
<p(245)>deno task --eval \"echo $(pwd)\"</>" <p(245)>deno task --eval \"echo $(pwd)\"</>"
), ),
@ -4373,7 +4374,7 @@ impl CommandExt for Command {
).arg( ).arg(
Arg::new("unstable-detect-cjs") Arg::new("unstable-detect-cjs")
.long("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()) .value_parser(FalseyValueParser::new())
.action(ArgAction::SetTrue) .action(ArgAction::SetTrue)
.hide(true) .hide(true)
@ -5986,6 +5987,7 @@ fn unstable_args_parse(
flags.unstable_config.bare_node_builtins = flags.unstable_config.bare_node_builtins =
matches.get_flag("unstable-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 = flags.unstable_config.sloppy_imports =
matches.get_flag("unstable-sloppy-imports"); matches.get_flag("unstable-sloppy-imports");

View file

@ -28,8 +28,8 @@ use deno_npm::npm_rc::ResolvedNpmRc;
use deno_npm::resolution::ValidSerializedNpmResolutionSnapshot; use deno_npm::resolution::ValidSerializedNpmResolutionSnapshot;
use deno_npm::NpmSystemInfo; use deno_npm::NpmSystemInfo;
use deno_path_util::normalize_path; use deno_path_util::normalize_path;
use deno_runtime::ops::otel::OtelConfig;
use deno_semver::npm::NpmPackageReqReference; use deno_semver::npm::NpmPackageReqReference;
use deno_telemetry::OtelConfig;
use import_map::resolve_import_map_value_from_specifier; use import_map::resolve_import_map_value_from_specifier;
pub use deno_config::deno_json::BenchConfig; pub use deno_config::deno_json::BenchConfig;
@ -1606,6 +1606,11 @@ impl CliOptions {
|| self.workspace().has_unstable("bare-node-builtins") || 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 { pub fn detect_cjs(&self) -> bool {
// only enabled when there's a package.json in order to not have a // 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 // perf penalty for non-npm Deno projects of searching for the closest
@ -1675,6 +1680,7 @@ impl CliOptions {
"sloppy-imports", "sloppy-imports",
"byonm", "byonm",
"bare-node-builtins", "bare-node-builtins",
"detect-cjs",
"fmt-component", "fmt-component",
"fmt-sql", "fmt-sql",
]) ])

2
cli/cache/mod.rs vendored
View file

@ -116,6 +116,8 @@ impl<'a> deno_cache_dir::DenoCacheEnv for DenoCacheEnvFsAdapter<'a> {
self self
.0 .0
.read_file_sync(path, None) .read_file_sync(path, None)
// todo(https://github.com/denoland/deno_cache_dir/pull/66): avoid clone
.map(|bytes| bytes.into_owned())
.map_err(|err| err.into_io_error()) .map_err(|err| err.into_io_error())
} }

View file

@ -284,6 +284,7 @@ fn serialize_media_type(media_type: MediaType) -> i64 {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use deno_graph::JsDocImportInfo;
use deno_graph::PositionRange; use deno_graph::PositionRange;
use deno_graph::SpecifierWithRange; use deno_graph::SpecifierWithRange;
@ -308,18 +309,21 @@ mod test {
); );
let mut module_info = ModuleInfo::default(); let mut module_info = ModuleInfo::default();
module_info.jsdoc_imports.push(SpecifierWithRange { module_info.jsdoc_imports.push(JsDocImportInfo {
range: PositionRange { specifier: SpecifierWithRange {
start: deno_graph::Position { range: PositionRange {
line: 0, start: deno_graph::Position {
character: 3, line: 0,
}, character: 3,
end: deno_graph::Position { },
line: 1, end: deno_graph::Position {
character: 2, line: 1,
character: 2,
},
}, },
text: "test".to_string(),
}, },
text: "test".to_string(), resolution_mode: None,
}); });
cache cache
.set_module_info( .set_module_info(

View file

@ -48,7 +48,6 @@ use crate::resolver::CliNpmReqResolver;
use crate::resolver::CliResolver; use crate::resolver::CliResolver;
use crate::resolver::CliResolverOptions; use crate::resolver::CliResolverOptions;
use crate::resolver::CliSloppyImportsResolver; use crate::resolver::CliSloppyImportsResolver;
use crate::resolver::IsCjsResolverOptions;
use crate::resolver::NpmModuleLoader; use crate::resolver::NpmModuleLoader;
use crate::resolver::SloppyImportsCachedFs; use crate::resolver::SloppyImportsCachedFs;
use crate::standalone::DenoCompileBinaryWriter; use crate::standalone::DenoCompileBinaryWriter;
@ -72,6 +71,7 @@ use deno_core::error::AnyError;
use deno_core::futures::FutureExt; use deno_core::futures::FutureExt;
use deno_core::FeatureChecker; use deno_core::FeatureChecker;
use deno_resolver::cjs::IsCjsResolutionMode;
use deno_resolver::npm::NpmReqResolverOptions; use deno_resolver::npm::NpmReqResolverOptions;
use deno_resolver::DenoResolverOptions; use deno_resolver::DenoResolverOptions;
use deno_resolver::NodeAndNpmReqResolver; use deno_resolver::NodeAndNpmReqResolver;
@ -845,9 +845,12 @@ impl CliFactory {
Ok(Arc::new(CjsTracker::new( Ok(Arc::new(CjsTracker::new(
self.in_npm_pkg_checker()?.clone(), self.in_npm_pkg_checker()?.clone(),
self.pkg_json_resolver().clone(), self.pkg_json_resolver().clone(),
IsCjsResolverOptions { if options.is_node_main() || options.unstable_detect_cjs() {
detect_cjs: options.detect_cjs(), IsCjsResolutionMode::ImplicitTypeCommonJs
is_node_main: options.is_node_main(), } else if options.detect_cjs() {
IsCjsResolutionMode::ExplicitTypeCommonJs
} else {
IsCjsResolutionMode::Disabled
}, },
))) )))
}) })

View file

@ -6,6 +6,7 @@ use crate::args::CliLockfile;
use crate::args::CliOptions; use crate::args::CliOptions;
use crate::args::DENO_DISABLE_PEDANTIC_NODE_WARNINGS; use crate::args::DENO_DISABLE_PEDANTIC_NODE_WARNINGS;
use crate::cache; use crate::cache;
use crate::cache::FetchCacher;
use crate::cache::GlobalHttpCache; use crate::cache::GlobalHttpCache;
use crate::cache::ModuleInfoCache; use crate::cache::ModuleInfoCache;
use crate::cache::ParsedSourceCache; use crate::cache::ParsedSourceCache;
@ -25,7 +26,7 @@ use deno_config::deno_json::JsxImportSourceConfig;
use deno_config::workspace::JsrPackageConfig; use deno_config::workspace::JsrPackageConfig;
use deno_core::anyhow::bail; use deno_core::anyhow::bail;
use deno_graph::source::LoaderChecksum; use deno_graph::source::LoaderChecksum;
use deno_graph::source::ResolutionMode; use deno_graph::source::ResolutionKind;
use deno_graph::FillFromLockfileOptions; use deno_graph::FillFromLockfileOptions;
use deno_graph::JsrLoadError; use deno_graph::JsrLoadError;
use deno_graph::ModuleLoadError; use deno_graph::ModuleLoadError;
@ -44,7 +45,7 @@ use deno_graph::ModuleGraphError;
use deno_graph::ResolutionError; use deno_graph::ResolutionError;
use deno_graph::SpecifierError; use deno_graph::SpecifierError;
use deno_path_util::url_to_file_path; 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_fs::FileSystem;
use deno_runtime::deno_node; use deno_runtime::deno_node;
use deno_runtime::deno_permissions::PermissionsContainer; use deno_runtime::deno_permissions::PermissionsContainer;
@ -254,6 +255,23 @@ impl ModuleGraphCreator {
package_configs: &[JsrPackageConfig], package_configs: &[JsrPackageConfig],
build_fast_check_graph: bool, build_fast_check_graph: bool,
) -> Result<ModuleGraph, AnyError> { ) -> Result<ModuleGraph, AnyError> {
struct PublishLoader(FetchCacher);
impl Loader for PublishLoader {
fn load(
&self,
specifier: &deno_ast::ModuleSpecifier,
options: deno_graph::source::LoadOptions,
) -> deno_graph::source::LoadFuture {
if specifier.scheme() == "bun" {
return Box::pin(std::future::ready(Ok(Some(
deno_graph::source::LoadResponse::External {
specifier: specifier.clone(),
},
))));
}
self.0.load(specifier, options)
}
}
fn graph_has_external_remote(graph: &ModuleGraph) -> bool { fn graph_has_external_remote(graph: &ModuleGraph) -> bool {
// Earlier on, we marked external non-JSR modules as external. // Earlier on, we marked external non-JSR modules as external.
// If the graph contains any of those, it would cause type checking // If the graph contains any of those, it would cause type checking
@ -271,12 +289,15 @@ impl ModuleGraphCreator {
for package_config in package_configs { for package_config in package_configs {
roots.extend(package_config.config_file.resolve_export_value_urls()?); roots.extend(package_config.config_file.resolve_export_value_urls()?);
} }
let loader = self.module_graph_builder.create_graph_loader();
let mut publish_loader = PublishLoader(loader);
let mut graph = self let mut graph = self
.create_graph_with_options(CreateGraphOptions { .create_graph_with_options(CreateGraphOptions {
is_dynamic: false, is_dynamic: false,
graph_kind: deno_graph::GraphKind::All, graph_kind: deno_graph::GraphKind::All,
roots, roots,
loader: None, loader: Some(&mut publish_loader),
}) })
.await?; .await?;
self.graph_valid(&graph)?; self.graph_valid(&graph)?;
@ -795,7 +816,7 @@ fn enhanced_sloppy_imports_error_message(
ModuleError::LoadingErr(specifier, _, ModuleLoadError::Loader(_)) // ex. "Is a directory" error ModuleError::LoadingErr(specifier, _, ModuleLoadError::Loader(_)) // ex. "Is a directory" error
| ModuleError::Missing(specifier, _) => { | ModuleError::Missing(specifier, _) => {
let additional_message = CliSloppyImportsResolver::new(SloppyImportsCachedFs::new(fs.clone())) let additional_message = CliSloppyImportsResolver::new(SloppyImportsCachedFs::new(fs.clone()))
.resolve(specifier, SloppyImportsResolutionMode::Execution)? .resolve(specifier, SloppyImportsResolutionKind::Execution)?
.as_suggestion_message(); .as_suggestion_message();
Some(format!( Some(format!(
"{} {} or run with --unstable-sloppy-imports", "{} {} or run with --unstable-sloppy-imports",
@ -1100,12 +1121,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!( format!(
"{}:{}:{}", "{}:{}:{}",
colors::cyan(range.specifier.as_str()), colors::cyan(referrer.specifier.as_str()),
colors::yellow(&(range.start.line + 1).to_string()), colors::yellow(&(referrer.range.start.line + 1).to_string()),
colors::yellow(&(range.start.character + 1).to_string()) colors::yellow(&(referrer.range.start.character + 1).to_string())
) )
} }
@ -1195,26 +1216,54 @@ impl<'a> deno_graph::source::Resolver for CliGraphResolver<'a> {
&self, &self,
raw_specifier: &str, raw_specifier: &str,
referrer_range: &deno_graph::Range, referrer_range: &deno_graph::Range,
mode: ResolutionMode, resolution_kind: ResolutionKind,
) -> Result<ModuleSpecifier, ResolveError> { ) -> Result<ModuleSpecifier, ResolveError> {
self.resolver.resolve( self.resolver.resolve(
raw_specifier, raw_specifier,
referrer_range, &referrer_range.specifier,
self referrer_range.range.start,
.cjs_tracker referrer_range
.get_referrer_kind(&referrer_range.specifier), .resolution_mode
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)] #[cfg(test)]
mod test { mod test {
use std::sync::Arc; use std::sync::Arc;
use deno_ast::ModuleSpecifier; use deno_ast::ModuleSpecifier;
use deno_graph::source::ResolveError; use deno_graph::source::ResolveError;
use deno_graph::Position; use deno_graph::PositionRange;
use deno_graph::Range; use deno_graph::Range;
use deno_graph::ResolutionError; use deno_graph::ResolutionError;
use deno_graph::SpecifierError; use deno_graph::SpecifierError;
@ -1235,8 +1284,8 @@ mod test {
specifier: input.to_string(), specifier: input.to_string(),
range: Range { range: Range {
specifier, specifier,
start: Position::zeroed(), resolution_mode: None,
end: Position::zeroed(), range: PositionRange::zeroed(),
}, },
}; };
assert_eq!(get_resolution_error_bare_node_specifier(&err), output); assert_eq!(get_resolution_error_bare_node_specifier(&err), output);
@ -1251,8 +1300,8 @@ mod test {
let err = ResolutionError::InvalidSpecifier { let err = ResolutionError::InvalidSpecifier {
range: Range { range: Range {
specifier, specifier,
start: Position::zeroed(), resolution_mode: None,
end: Position::zeroed(), range: PositionRange::zeroed(),
}, },
error: SpecifierError::ImportPrefixMissing { error: SpecifierError::ImportPrefixMissing {
specifier: input.to_string(), specifier: input.to_string(),

View file

@ -15,7 +15,6 @@ use crate::lsp::search::PackageSearchApi;
use crate::tools::lint::CliLinter; use crate::tools::lint::CliLinter;
use crate::util::path::relative_specifier; use crate::util::path::relative_specifier;
use deno_config::workspace::MappedResolution; use deno_config::workspace::MappedResolution;
use deno_graph::source::ResolutionMode;
use deno_lint::diagnostic::LintDiagnosticRange; use deno_lint::diagnostic::LintDiagnosticRange;
use deno_ast::SourceRange; use deno_ast::SourceRange;
@ -39,7 +38,8 @@ use deno_semver::package::PackageReq;
use deno_semver::package::PackageReqReference; use deno_semver::package::PackageReqReference;
use deno_semver::Version; use deno_semver::Version;
use import_map::ImportMap; use import_map::ImportMap;
use node_resolver::NodeModuleKind; use node_resolver::NodeResolutionKind;
use node_resolver::ResolutionMode;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use regex::Regex; use regex::Regex;
use std::borrow::Cow; use std::borrow::Cow;
@ -467,7 +467,7 @@ impl<'a> TsResponseImportMapper<'a> {
&self, &self,
specifier: &str, specifier: &str,
referrer: &ModuleSpecifier, referrer: &ModuleSpecifier,
referrer_kind: NodeModuleKind, resolution_mode: ResolutionMode,
) -> Option<String> { ) -> Option<String> {
let specifier_stem = specifier.strip_suffix(".js").unwrap_or(specifier); let specifier_stem = specifier.strip_suffix(".js").unwrap_or(specifier);
let specifiers = std::iter::once(Cow::Borrowed(specifier)).chain( let specifiers = std::iter::once(Cow::Borrowed(specifier)).chain(
@ -481,13 +481,10 @@ impl<'a> TsResponseImportMapper<'a> {
.as_cli_resolver(Some(&self.file_referrer)) .as_cli_resolver(Some(&self.file_referrer))
.resolve( .resolve(
&specifier, &specifier,
&deno_graph::Range { referrer,
specifier: referrer.clone(), deno_graph::Position::zeroed(),
start: deno_graph::Position::zeroed(), resolution_mode,
end: deno_graph::Position::zeroed(), NodeResolutionKind::Types,
},
referrer_kind,
ResolutionMode::Types,
) )
.ok() .ok()
.and_then(|s| self.tsc_specifier_map.normalize(s.as_str()).ok()) .and_then(|s| self.tsc_specifier_map.normalize(s.as_str()).ok())
@ -509,20 +506,17 @@ impl<'a> TsResponseImportMapper<'a> {
&self, &self,
specifier_text: &str, specifier_text: &str,
referrer: &ModuleSpecifier, referrer: &ModuleSpecifier,
referrer_kind: NodeModuleKind, resolution_mode: ResolutionMode,
) -> bool { ) -> bool {
self self
.resolver .resolver
.as_cli_resolver(Some(&self.file_referrer)) .as_cli_resolver(Some(&self.file_referrer))
.resolve( .resolve(
specifier_text, specifier_text,
&deno_graph::Range { referrer,
specifier: referrer.clone(), deno_graph::Position::zeroed(),
start: deno_graph::Position::zeroed(), resolution_mode,
end: deno_graph::Position::zeroed(), NodeResolutionKind::Types,
},
referrer_kind,
deno_graph::source::ResolutionMode::Types,
) )
.is_ok() .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 /// like an import and rewrite the import specifier to include the extension
pub fn fix_ts_import_changes( pub fn fix_ts_import_changes(
referrer: &ModuleSpecifier, referrer: &ModuleSpecifier,
referrer_kind: NodeModuleKind, resolution_mode: ResolutionMode,
changes: &[tsc::FileTextChanges], changes: &[tsc::FileTextChanges],
language_server: &language_server::Inner, language_server: &language_server::Inner,
) -> Result<Vec<tsc::FileTextChanges>, AnyError> { ) -> Result<Vec<tsc::FileTextChanges>, AnyError> {
@ -608,7 +602,7 @@ pub fn fix_ts_import_changes(
let specifier = let specifier =
captures.iter().skip(1).find_map(|s| s).unwrap().as_str(); captures.iter().skip(1).find_map(|s| s).unwrap().as_str();
if let Some(new_specifier) = import_mapper 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) line.replace(specifier, &new_specifier)
} else { } else {
@ -638,7 +632,7 @@ pub fn fix_ts_import_changes(
/// resolution by Deno (includes the extension). /// resolution by Deno (includes the extension).
fn fix_ts_import_action<'a>( fn fix_ts_import_action<'a>(
referrer: &ModuleSpecifier, referrer: &ModuleSpecifier,
referrer_kind: NodeModuleKind, resolution_mode: ResolutionMode,
action: &'a tsc::CodeFixAction, action: &'a tsc::CodeFixAction,
language_server: &language_server::Inner, language_server: &language_server::Inner,
) -> Option<Cow<'a, tsc::CodeFixAction>> { ) -> Option<Cow<'a, tsc::CodeFixAction>> {
@ -657,9 +651,11 @@ fn fix_ts_import_action<'a>(
return Some(Cow::Borrowed(action)); return Some(Cow::Borrowed(action));
}; };
let import_mapper = language_server.get_ts_response_import_mapper(referrer); let import_mapper = language_server.get_ts_response_import_mapper(referrer);
if let Some(new_specifier) = if let Some(new_specifier) = import_mapper.check_unresolved_specifier(
import_mapper.check_unresolved_specifier(specifier, referrer, referrer_kind) specifier,
{ referrer,
resolution_mode,
) {
let description = action.description.replace(specifier, &new_specifier); let description = action.description.replace(specifier, &new_specifier);
let changes = action let changes = action
.changes .changes
@ -689,7 +685,8 @@ fn fix_ts_import_action<'a>(
fix_id: None, fix_id: None,
fix_all_description: 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 None
} else { } else {
Some(Cow::Borrowed(action)) Some(Cow::Borrowed(action))
@ -1023,7 +1020,7 @@ impl CodeActionCollection {
pub fn add_ts_fix_action( pub fn add_ts_fix_action(
&mut self, &mut self,
specifier: &ModuleSpecifier, specifier: &ModuleSpecifier,
specifier_kind: NodeModuleKind, resolution_mode: ResolutionMode,
action: &tsc::CodeFixAction, action: &tsc::CodeFixAction,
diagnostic: &lsp::Diagnostic, diagnostic: &lsp::Diagnostic,
language_server: &language_server::Inner, language_server: &language_server::Inner,
@ -1042,7 +1039,7 @@ impl CodeActionCollection {
)); ));
} }
let Some(action) = let Some(action) =
fix_ts_import_action(specifier, specifier_kind, action, language_server) fix_ts_import_action(specifier, resolution_mode, action, language_server)
else { else {
return Ok(()); return Ok(());
}; };
@ -1237,12 +1234,12 @@ impl CodeActionCollection {
let text_info = parsed_source.text_info_lazy(); let text_info = parsed_source.text_info_lazy();
let specifier_range = SourceRange::new( let specifier_range = SourceRange::new(
text_info.loc_to_source_pos(LineAndColumnIndex { text_info.loc_to_source_pos(LineAndColumnIndex {
line_index: import.specifier_range.start.line, line_index: import.specifier_range.range.start.line,
column_index: import.specifier_range.start.character, column_index: import.specifier_range.range.start.character,
}), }),
text_info.loc_to_source_pos(LineAndColumnIndex { text_info.loc_to_source_pos(LineAndColumnIndex {
line_index: import.specifier_range.end.line, line_index: import.specifier_range.range.end.line,
column_index: import.specifier_range.end.character, 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") { if json!(i.kind) != json!("es") && json!(i.kind) != json!("tsType") {
return None; return None;
} }
if !i.specifier_range.includes(&position) { if !i.specifier_range.includes(position) {
return None; return None;
} }
import_start_from_specifier(document, i) import_start_from_specifier(document, i)
})?; })?;
let referrer = document.specifier(); let referrer = document.specifier();
let referrer_kind = language_server let resolution_mode = document.resolution_mode();
.is_cjs_resolver
.get_doc_module_kind(document);
let file_referrer = document.file_referrer(); let file_referrer = document.file_referrer();
let config_data = language_server let config_data = language_server
.config .config
@ -1312,7 +1307,7 @@ impl CodeActionCollection {
if !language_server.resolver.is_bare_package_json_dep( if !language_server.resolver.is_bare_package_json_dep(
&dep_key, &dep_key,
referrer, referrer,
referrer_kind, resolution_mode,
) { ) {
return None; return None;
} }
@ -1332,7 +1327,7 @@ impl CodeActionCollection {
} }
if language_server if language_server
.resolver .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() .is_some()
{ {
// The package import has types. // The package import has types.

View file

@ -9,16 +9,14 @@ use super::jsr::CliJsrSearchApi;
use super::lsp_custom; use super::lsp_custom;
use super::npm::CliNpmSearchApi; use super::npm::CliNpmSearchApi;
use super::registries::ModuleRegistry; use super::registries::ModuleRegistry;
use super::resolver::LspIsCjsResolver;
use super::resolver::LspResolver; use super::resolver::LspResolver;
use super::search::PackageSearchApi; use super::search::PackageSearchApi;
use super::tsc; use super::tsc;
use crate::graph_util::to_node_resolution_mode;
use crate::jsr::JsrFetchResolver; use crate::jsr::JsrFetchResolver;
use crate::util::path::is_importable_ext; use crate::util::path::is_importable_ext;
use crate::util::path::relative_specifier; 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_runtime::deno_node::SUPPORTED_BUILTIN_NODE_MODULES;
use deno_ast::LineAndColumnIndex; use deno_ast::LineAndColumnIndex;
@ -36,7 +34,8 @@ use deno_semver::package::PackageNv;
use import_map::ImportMap; use import_map::ImportMap;
use indexmap::IndexSet; use indexmap::IndexSet;
use lsp_types::CompletionList; use lsp_types::CompletionList;
use node_resolver::NodeModuleKind; use node_resolver::NodeResolutionKind;
use node_resolver::ResolutionMode;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use regex::Regex; use regex::Regex;
use tower_lsp::lsp_types as lsp; 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. /// which we want to ignore when replacing text.
fn to_narrow_lsp_range( fn to_narrow_lsp_range(
text_info: &SourceTextInfo, text_info: &SourceTextInfo,
range: &deno_graph::Range, range: deno_graph::PositionRange,
) -> lsp::Range { ) -> lsp::Range {
let end_byte_index = text_info let end_byte_index = text_info
.loc_to_source_pos(LineAndColumnIndex { .loc_to_source_pos(LineAndColumnIndex {
@ -161,26 +160,25 @@ pub async fn get_import_completions(
jsr_search_api: &CliJsrSearchApi, jsr_search_api: &CliJsrSearchApi,
npm_search_api: &CliNpmSearchApi, npm_search_api: &CliNpmSearchApi,
documents: &Documents, documents: &Documents,
is_cjs_resolver: &LspIsCjsResolver,
resolver: &LspResolver, resolver: &LspResolver,
maybe_import_map: Option<&ImportMap>, maybe_import_map: Option<&ImportMap>,
) -> Option<lsp::CompletionResponse> { ) -> Option<lsp::CompletionResponse> {
let document = documents.get(specifier)?; let document = documents.get(specifier)?;
let specifier_kind = is_cjs_resolver.get_doc_module_kind(&document);
let file_referrer = document.file_referrer(); let file_referrer = document.file_referrer();
let (text, _, range) = document.get_maybe_dependency(position)?; let (text, _, graph_range) = document.get_maybe_dependency(position)?;
let range = to_narrow_lsp_range(document.text_info(), &range); 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 let resolved = resolver
.as_cli_resolver(file_referrer) .as_cli_resolver(file_referrer)
.resolve( .resolve(
&text, &text,
&Range { specifier,
specifier: specifier.clone(), deno_graph::Position::zeroed(),
start: deno_graph::Position::zeroed(), resolution_mode,
end: deno_graph::Position::zeroed(), NodeResolutionKind::Execution,
},
specifier_kind,
ResolutionMode::Execution,
) )
.ok(); .ok();
if let Some(completion_list) = get_jsr_completions( if let Some(completion_list) = get_jsr_completions(
@ -206,7 +204,7 @@ pub async fn get_import_completions(
// completions for import map specifiers // completions for import map specifiers
Some(lsp::CompletionResponse::List(completion_list)) Some(lsp::CompletionResponse::List(completion_list))
} else if let Some(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 // completions for local relative modules
Some(lsp::CompletionResponse::List(completion_list)) 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. /// Return local completions that are relative to the base specifier.
fn get_local_completions( fn get_local_completions(
referrer: &ModuleSpecifier, referrer: &ModuleSpecifier,
referrer_kind: NodeModuleKind, resolution_mode: ResolutionMode,
text: &str, text: &str,
range: &lsp::Range, range: &lsp::Range,
resolver: &LspResolver, resolver: &LspResolver,
@ -374,13 +372,10 @@ fn get_local_completions(
.as_cli_resolver(Some(referrer)) .as_cli_resolver(Some(referrer))
.resolve( .resolve(
parent, parent,
&Range { referrer,
specifier: referrer.clone(), deno_graph::Position::zeroed(),
start: deno_graph::Position::zeroed(), resolution_mode,
end: deno_graph::Position::zeroed(), NodeResolutionKind::Execution,
},
referrer_kind,
ResolutionMode::Execution,
) )
.ok()?; .ok()?;
let resolved_parent_path = url_to_file_path(&resolved_parent).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::documents::LanguageId;
use crate::lsp::search::tests::TestPackageSearchApi; use crate::lsp::search::tests::TestPackageSearchApi;
use deno_core::resolve_url; use deno_core::resolve_url;
use deno_graph::Range;
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use std::collections::HashMap; use std::collections::HashMap;
use test_util::TempDir; use test_util::TempDir;
@ -912,7 +906,7 @@ mod tests {
ModuleSpecifier::from_file_path(file_c).expect("could not create"); ModuleSpecifier::from_file_path(file_c).expect("could not create");
let actual = get_local_completions( let actual = get_local_completions(
&specifier, &specifier,
NodeModuleKind::Esm, ResolutionMode::Import,
"./", "./",
&lsp::Range { &lsp::Range {
start: lsp::Position { start: lsp::Position {
@ -1608,8 +1602,7 @@ mod tests {
let text_info = SourceTextInfo::from_string(r#""te""#.to_string()); let text_info = SourceTextInfo::from_string(r#""te""#.to_string());
let range = to_narrow_lsp_range( let range = to_narrow_lsp_range(
&text_info, &text_info,
&Range { deno_graph::PositionRange {
specifier: ModuleSpecifier::parse("https://deno.land").unwrap(),
start: deno_graph::Position { start: deno_graph::Position {
line: 0, line: 0,
character: 0, character: 0,
@ -1632,8 +1625,7 @@ mod tests {
let text_info = SourceTextInfo::from_string(r#""te"#.to_string()); let text_info = SourceTextInfo::from_string(r#""te"#.to_string());
let range = to_narrow_lsp_range( let range = to_narrow_lsp_range(
&text_info, &text_info,
&Range { deno_graph::PositionRange {
specifier: ModuleSpecifier::parse("https://deno.land").unwrap(),
start: deno_graph::Position { start: deno_graph::Position {
line: 0, line: 0,
character: 0, character: 0,

View file

@ -45,7 +45,7 @@ use deno_graph::Resolution;
use deno_graph::ResolutionError; use deno_graph::ResolutionError;
use deno_graph::SpecifierError; use deno_graph::SpecifierError;
use deno_resolver::sloppy_imports::SloppyImportsResolution; 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_fs;
use deno_runtime::deno_node; use deno_runtime::deno_node;
use deno_runtime::tokio_util::create_basic_runtime; use deno_runtime::tokio_util::create_basic_runtime;
@ -1266,7 +1266,7 @@ impl DenoDiagnostic {
Self::NoLocal(specifier) => { Self::NoLocal(specifier) => {
let maybe_sloppy_resolution = CliSloppyImportsResolver::new( let maybe_sloppy_resolution = CliSloppyImportsResolver::new(
SloppyImportsCachedFs::new(Arc::new(deno_fs::RealFs)) SloppyImportsCachedFs::new(Arc::new(deno_fs::RealFs))
).resolve(specifier, SloppyImportsResolutionMode::Execution); ).resolve(specifier, SloppyImportsResolutionKind::Execution);
let data = maybe_sloppy_resolution.as_ref().map(|res| { let data = maybe_sloppy_resolution.as_ref().map(|res| {
json!({ json!({
"specifier": specifier, "specifier": specifier,
@ -1531,7 +1531,7 @@ fn diagnose_dependency(
&& !dependency.imports.iter().any(|i| { && !dependency.imports.iter().any(|i| {
dependency dependency
.maybe_type .maybe_type
.includes(&i.specifier_range.start) .includes(i.specifier_range.range.start)
.is_some() .is_some()
}); });
@ -1707,7 +1707,6 @@ mod tests {
documents: Arc::new(documents), documents: Arc::new(documents),
assets: Default::default(), assets: Default::default(),
config: Arc::new(config), config: Arc::new(config),
is_cjs_resolver: Default::default(),
resolver, resolver,
}, },
) )

View file

@ -3,7 +3,6 @@
use super::cache::calculate_fs_version; use super::cache::calculate_fs_version;
use super::cache::LspCache; use super::cache::LspCache;
use super::config::Config; use super::config::Config;
use super::resolver::LspIsCjsResolver;
use super::resolver::LspResolver; use super::resolver::LspResolver;
use super::resolver::ScopeDepInfo; use super::resolver::ScopeDepInfo;
use super::resolver::SingleReferrerGraphResolver; use super::resolver::SingleReferrerGraphResolver;
@ -27,7 +26,6 @@ use deno_core::futures::future::Shared;
use deno_core::futures::FutureExt; use deno_core::futures::FutureExt;
use deno_core::parking_lot::Mutex; use deno_core::parking_lot::Mutex;
use deno_core::ModuleSpecifier; use deno_core::ModuleSpecifier;
use deno_graph::source::ResolutionMode;
use deno_graph::Resolution; use deno_graph::Resolution;
use deno_path_util::url_to_file_path; use deno_path_util::url_to_file_path;
use deno_runtime::deno_node; use deno_runtime::deno_node;
@ -36,7 +34,8 @@ use deno_semver::npm::NpmPackageReqReference;
use deno_semver::package::PackageReq; use deno_semver::package::PackageReq;
use indexmap::IndexMap; use indexmap::IndexMap;
use indexmap::IndexSet; use indexmap::IndexSet;
use node_resolver::NodeModuleKind; use node_resolver::NodeResolutionKind;
use node_resolver::ResolutionMode;
use std::borrow::Cow; use std::borrow::Cow;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::collections::HashMap; use std::collections::HashMap;
@ -313,6 +312,7 @@ pub struct Document {
media_type: MediaType, media_type: MediaType,
/// Present if and only if this is an open document. /// Present if and only if this is an open document.
open_data: Option<DocumentOpenData>, open_data: Option<DocumentOpenData>,
resolution_mode: ResolutionMode,
resolver: Arc<LspResolver>, resolver: Arc<LspResolver>,
specifier: ModuleSpecifier, specifier: ModuleSpecifier,
text: Arc<str>, text: Arc<str>,
@ -328,7 +328,6 @@ impl Document {
maybe_lsp_version: Option<i32>, maybe_lsp_version: Option<i32>,
maybe_language_id: Option<LanguageId>, maybe_language_id: Option<LanguageId>,
maybe_headers: Option<HashMap<String, String>>, maybe_headers: Option<HashMap<String, String>>,
is_cjs_resolver: &LspIsCjsResolver,
resolver: Arc<LspResolver>, resolver: Arc<LspResolver>,
config: Arc<Config>, config: Arc<Config>,
cache: &Arc<LspCache>, cache: &Arc<LspCache>,
@ -340,7 +339,7 @@ impl Document {
.or(file_referrer); .or(file_referrer);
let media_type = let media_type =
resolve_media_type(&specifier, maybe_headers.as_ref(), maybe_language_id); 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) { if media_type_is_diagnosable(media_type) {
parse_and_analyze_module( parse_and_analyze_module(
specifier.clone(), specifier.clone(),
@ -348,11 +347,10 @@ impl Document {
maybe_headers.as_ref(), maybe_headers.as_ref(),
media_type, media_type,
file_referrer.as_ref(), file_referrer.as_ref(),
is_cjs_resolver,
&resolver, &resolver,
) )
} else { } else {
(None, None) (None, None, ResolutionMode::Import)
}; };
let maybe_module = maybe_module.and_then(Result::ok); let maybe_module = maybe_module.and_then(Result::ok);
let dependencies = maybe_module let dependencies = maybe_module
@ -387,6 +385,7 @@ impl Document {
maybe_parsed_source, maybe_parsed_source,
maybe_semantic_tokens: Default::default(), maybe_semantic_tokens: Default::default(),
}), }),
resolution_mode,
resolver, resolver,
specifier, specifier,
text, text,
@ -396,7 +395,6 @@ impl Document {
fn with_new_config( fn with_new_config(
&self, &self,
is_cjs_resolver: &LspIsCjsResolver,
resolver: Arc<LspResolver>, resolver: Arc<LspResolver>,
config: Arc<Config>, config: Arc<Config>,
) -> Arc<Self> { ) -> Arc<Self> {
@ -408,20 +406,20 @@ impl Document {
let dependencies; let dependencies;
let maybe_types_dependency; let maybe_types_dependency;
let maybe_parsed_source; let maybe_parsed_source;
let found_resolution_mode;
let is_script; let is_script;
let maybe_test_module_fut; let maybe_test_module_fut;
if media_type != self.media_type { if media_type != self.media_type {
let parsed_source_result = let parsed_source_result =
parse_source(self.specifier.clone(), self.text.clone(), media_type); 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(), self.specifier.clone(),
&parsed_source_result, &parsed_source_result,
self.maybe_headers.as_ref(), self.maybe_headers.as_ref(),
self.file_referrer.as_ref(), self.file_referrer.as_ref(),
is_cjs_resolver,
&resolver, &resolver,
) );
.ok(); let maybe_module = maybe_module_result.ok();
dependencies = maybe_module dependencies = maybe_module
.as_ref() .as_ref()
.map(|m| Arc::new(m.dependencies.clone())) .map(|m| Arc::new(m.dependencies.clone()))
@ -433,17 +431,21 @@ impl Document {
maybe_parsed_source = Some(parsed_source_result); maybe_parsed_source = Some(parsed_source_result);
maybe_test_module_fut = maybe_test_module_fut =
get_maybe_test_module_fut(maybe_parsed_source.as_ref(), &config); get_maybe_test_module_fut(maybe_parsed_source.as_ref(), &config);
found_resolution_mode = resolution_mode;
} else { } else {
let cli_resolver = resolver.as_cli_resolver(self.file_referrer.as_ref()); 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 = let npm_resolver =
resolver.create_graph_npm_resolver(self.file_referrer.as_ref()); resolver.create_graph_npm_resolver(self.file_referrer.as_ref());
let config_data = resolver.as_config_data(self.file_referrer.as_ref()); let config_data = resolver.as_config_data(self.file_referrer.as_ref());
let jsx_import_source_config = let jsx_import_source_config =
config_data.and_then(|d| d.maybe_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 { let resolver = SingleReferrerGraphResolver {
valid_referrer: &self.specifier, valid_referrer: &self.specifier,
referrer_kind: is_cjs_resolver module_resolution_mode: found_resolution_mode,
.get_lsp_referrer_kind(&self.specifier, self.is_script),
cli_resolver, cli_resolver,
jsx_import_source_config: jsx_import_source_config.as_ref(), jsx_import_source_config: jsx_import_source_config.as_ref(),
}; };
@ -493,6 +495,7 @@ impl Document {
maybe_language_id: self.maybe_language_id, maybe_language_id: self.maybe_language_id,
maybe_test_module_fut, maybe_test_module_fut,
media_type, media_type,
resolution_mode: found_resolution_mode,
open_data: self.open_data.as_ref().map(|d| DocumentOpenData { open_data: self.open_data.as_ref().map(|d| DocumentOpenData {
lsp_version: d.lsp_version, lsp_version: d.lsp_version,
maybe_parsed_source, maybe_parsed_source,
@ -508,7 +511,6 @@ impl Document {
fn with_change( fn with_change(
&self, &self,
is_cjs_resolver: &LspIsCjsResolver,
version: i32, version: i32,
changes: Vec<lsp::TextDocumentContentChangeEvent>, changes: Vec<lsp::TextDocumentContentChangeEvent>,
) -> Result<Arc<Self>, AnyError> { ) -> Result<Arc<Self>, AnyError> {
@ -530,7 +532,7 @@ impl Document {
} }
let text: Arc<str> = content.into(); let text: Arc<str> = content.into();
let media_type = self.media_type; 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 .maybe_language_id
.as_ref() .as_ref()
.map(|li| li.is_diagnosable()) .map(|li| li.is_diagnosable())
@ -542,11 +544,10 @@ impl Document {
self.maybe_headers.as_ref(), self.maybe_headers.as_ref(),
media_type, media_type,
self.file_referrer.as_ref(), self.file_referrer.as_ref(),
is_cjs_resolver,
self.resolver.as_ref(), self.resolver.as_ref(),
) )
} else { } else {
(None, None) (None, None, ResolutionMode::Import)
}; };
let maybe_module = maybe_module.and_then(Result::ok); let maybe_module = maybe_module.and_then(Result::ok);
let dependencies = maybe_module let dependencies = maybe_module
@ -580,6 +581,7 @@ impl Document {
maybe_navigation_tree: Mutex::new(None), maybe_navigation_tree: Mutex::new(None),
maybe_test_module_fut, maybe_test_module_fut,
media_type, media_type,
resolution_mode,
open_data: self.open_data.is_some().then_some(DocumentOpenData { open_data: self.open_data.is_some().then_some(DocumentOpenData {
lsp_version: version, lsp_version: version,
maybe_parsed_source, maybe_parsed_source,
@ -613,6 +615,7 @@ impl Document {
maybe_test_module_fut: self.maybe_test_module_fut.clone(), maybe_test_module_fut: self.maybe_test_module_fut.clone(),
media_type: self.media_type, media_type: self.media_type,
open_data: None, open_data: None,
resolution_mode: self.resolution_mode,
resolver: self.resolver.clone(), resolver: self.resolver.clone(),
}) })
} }
@ -641,6 +644,7 @@ impl Document {
maybe_test_module_fut: self.maybe_test_module_fut.clone(), maybe_test_module_fut: self.maybe_test_module_fut.clone(),
media_type: self.media_type, media_type: self.media_type,
open_data: self.open_data.clone(), open_data: self.open_data.clone(),
resolution_mode: self.resolution_mode,
resolver: self.resolver.clone(), resolver: self.resolver.clone(),
}) })
} }
@ -664,6 +668,10 @@ impl Document {
&self.text &self.text
} }
pub fn resolution_mode(&self) -> ResolutionMode {
self.resolution_mode
}
pub fn text_info(&self) -> &SourceTextInfo { pub fn text_info(&self) -> &SourceTextInfo {
// try to get the text info from the parsed source and if // try to get the text info from the parsed source and if
// not then create one in the cell // not then create one in the cell
@ -677,14 +685,6 @@ impl Document {
.get_or_init(|| SourceTextInfo::new(self.text.clone())) .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> { pub fn line_index(&self) -> Arc<LineIndex> {
self.line_index.clone() self.line_index.clone()
} }
@ -768,7 +768,7 @@ impl Document {
}; };
self.dependencies().iter().find_map(|(s, dep)| { self.dependencies().iter().find_map(|(s, dep)| {
dep dep
.includes(&position) .includes(position)
.map(|r| (s.clone(), dep.clone(), r.clone())) .map(|r| (s.clone(), dep.clone(), r.clone()))
}) })
} }
@ -809,15 +809,15 @@ fn resolve_media_type(
MediaType::from_specifier(specifier) 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 { lsp::Range {
start: lsp::Position { start: lsp::Position {
line: range.start.line as u32, line: referrer.range.start.line as u32,
character: range.start.character as u32, character: referrer.range.start.character as u32,
}, },
end: lsp::Position { end: lsp::Position {
line: range.end.line as u32, line: referrer.range.end.line as u32,
character: range.end.character as u32, character: referrer.range.end.character as u32,
}, },
} }
} }
@ -832,7 +832,6 @@ impl FileSystemDocuments {
pub fn get( pub fn get(
&self, &self,
specifier: &ModuleSpecifier, specifier: &ModuleSpecifier,
is_cjs_resolver: &LspIsCjsResolver,
resolver: &Arc<LspResolver>, resolver: &Arc<LspResolver>,
config: &Arc<Config>, config: &Arc<Config>,
cache: &Arc<LspCache>, cache: &Arc<LspCache>,
@ -856,14 +855,7 @@ impl FileSystemDocuments {
}; };
if dirty { if dirty {
// attempt to update the file on the file system // attempt to update the file on the file system
self.refresh_document( self.refresh_document(specifier, resolver, config, cache, file_referrer)
specifier,
is_cjs_resolver,
resolver,
config,
cache,
file_referrer,
)
} else { } else {
old_doc old_doc
} }
@ -874,7 +866,6 @@ impl FileSystemDocuments {
fn refresh_document( fn refresh_document(
&self, &self,
specifier: &ModuleSpecifier, specifier: &ModuleSpecifier,
is_cjs_resolver: &LspIsCjsResolver,
resolver: &Arc<LspResolver>, resolver: &Arc<LspResolver>,
config: &Arc<Config>, config: &Arc<Config>,
cache: &Arc<LspCache>, cache: &Arc<LspCache>,
@ -896,7 +887,6 @@ impl FileSystemDocuments {
None, None,
None, None,
None, None,
is_cjs_resolver,
resolver.clone(), resolver.clone(),
config.clone(), config.clone(),
cache, cache,
@ -913,7 +903,6 @@ impl FileSystemDocuments {
None, None,
None, None,
None, None,
is_cjs_resolver,
resolver.clone(), resolver.clone(),
config.clone(), config.clone(),
cache, cache,
@ -946,7 +935,6 @@ impl FileSystemDocuments {
None, None,
None, None,
Some(cached_file.metadata.headers), Some(cached_file.metadata.headers),
is_cjs_resolver,
resolver.clone(), resolver.clone(),
config.clone(), config.clone(),
cache, cache,
@ -987,8 +975,6 @@ pub struct Documents {
/// The DENO_DIR that the documents looks for non-file based modules. /// The DENO_DIR that the documents looks for non-file based modules.
cache: Arc<LspCache>, cache: Arc<LspCache>,
config: Arc<Config>, 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 /// A resolver that takes into account currently loaded import map and JSX
/// settings. /// settings.
resolver: Arc<LspResolver>, resolver: Arc<LspResolver>,
@ -1024,7 +1010,6 @@ impl Documents {
// the cache for remote modules here in order to get the // the cache for remote modules here in order to get the
// x-typescript-types? // x-typescript-types?
None, None,
&self.is_cjs_resolver,
self.resolver.clone(), self.resolver.clone(),
self.config.clone(), self.config.clone(),
&self.cache, &self.cache,
@ -1059,7 +1044,7 @@ impl Documents {
)) ))
})?; })?;
self.dirty = true; 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()); self.open_docs.insert(doc.specifier().clone(), doc.clone());
Ok(doc) Ok(doc)
} }
@ -1191,7 +1176,6 @@ impl Documents {
if let Some(old_doc) = old_doc { if let Some(old_doc) = old_doc {
self.file_system_docs.get( self.file_system_docs.get(
specifier, specifier,
&self.is_cjs_resolver,
&self.resolver, &self.resolver,
&self.config, &self.config,
&self.cache, &self.cache,
@ -1216,7 +1200,6 @@ impl Documents {
} else { } else {
self.file_system_docs.get( self.file_system_docs.get(
&specifier, &specifier,
&self.is_cjs_resolver,
&self.resolver, &self.resolver,
&self.config, &self.config,
&self.cache, &self.cache,
@ -1271,7 +1254,8 @@ impl Documents {
/// tsc when type checking. /// tsc when type checking.
pub fn resolve( pub fn resolve(
&self, &self,
raw_specifiers: &[String], // (is_cjs: bool, raw_specifier: String)
raw_specifiers: &[(bool, String)],
referrer: &ModuleSpecifier, referrer: &ModuleSpecifier,
file_referrer: Option<&ModuleSpecifier>, file_referrer: Option<&ModuleSpecifier>,
) -> Vec<Option<(ModuleSpecifier, MediaType)>> { ) -> Vec<Option<(ModuleSpecifier, MediaType)>> {
@ -1281,11 +1265,12 @@ impl Documents {
.and_then(|d| d.file_referrer()) .and_then(|d| d.file_referrer())
.or(file_referrer); .or(file_referrer);
let dependencies = referrer_doc.as_ref().map(|d| d.dependencies()); 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(); 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 raw_specifier.starts_with("asset:") {
if let Ok(specifier) = ModuleSpecifier::parse(raw_specifier) { if let Ok(specifier) = ModuleSpecifier::parse(raw_specifier) {
let media_type = MediaType::from_specifier(&specifier); let media_type = MediaType::from_specifier(&specifier);
@ -1300,14 +1285,14 @@ impl Documents {
results.push(self.resolve_dependency( results.push(self.resolve_dependency(
specifier, specifier,
referrer, referrer,
referrer_kind, resolution_mode,
file_referrer, file_referrer,
)); ));
} else if let Some(specifier) = dep.maybe_code.maybe_specifier() { } else if let Some(specifier) = dep.maybe_code.maybe_specifier() {
results.push(self.resolve_dependency( results.push(self.resolve_dependency(
specifier, specifier,
referrer, referrer,
referrer_kind, resolution_mode,
file_referrer, file_referrer,
)); ));
} else { } else {
@ -1316,19 +1301,16 @@ impl Documents {
} else if let Ok(specifier) = } else if let Ok(specifier) =
self.resolver.as_cli_resolver(file_referrer).resolve( self.resolver.as_cli_resolver(file_referrer).resolve(
raw_specifier, raw_specifier,
&deno_graph::Range { referrer,
specifier: referrer.clone(), deno_graph::Position::zeroed(),
start: deno_graph::Position::zeroed(), resolution_mode,
end: deno_graph::Position::zeroed(), NodeResolutionKind::Types,
},
referrer_kind,
ResolutionMode::Types,
) )
{ {
results.push(self.resolve_dependency( results.push(self.resolve_dependency(
&specifier, &specifier,
referrer, referrer,
referrer_kind, resolution_mode,
file_referrer, file_referrer,
)); ));
} else { } else {
@ -1347,7 +1329,6 @@ impl Documents {
) { ) {
self.config = Arc::new(config.clone()); self.config = Arc::new(config.clone());
self.cache = Arc::new(cache.clone()); self.cache = Arc::new(cache.clone());
self.is_cjs_resolver = Arc::new(LspIsCjsResolver::new(cache));
self.resolver = resolver.clone(); self.resolver = resolver.clone();
node_resolver::PackageJsonThreadLocalCache::clear(); node_resolver::PackageJsonThreadLocalCache::clear();
@ -1371,21 +1352,14 @@ impl Documents {
if !config.specifier_enabled(doc.specifier()) { if !config.specifier_enabled(doc.specifier()) {
continue; continue;
} }
*doc = doc.with_new_config( *doc = doc.with_new_config(self.resolver.clone(), self.config.clone());
&self.is_cjs_resolver,
self.resolver.clone(),
self.config.clone(),
);
} }
for mut doc in self.file_system_docs.docs.iter_mut() { for mut doc in self.file_system_docs.docs.iter_mut() {
if !config.specifier_enabled(doc.specifier()) { if !config.specifier_enabled(doc.specifier()) {
continue; continue;
} }
*doc.value_mut() = doc.with_new_config( *doc.value_mut() =
&self.is_cjs_resolver, doc.with_new_config(self.resolver.clone(), self.config.clone());
self.resolver.clone(),
self.config.clone(),
);
} }
self.open_docs = open_docs; self.open_docs = open_docs;
let mut preload_count = 0; let mut preload_count = 0;
@ -1402,7 +1376,6 @@ impl Documents {
{ {
fs_docs.refresh_document( fs_docs.refresh_document(
specifier, specifier,
&self.is_cjs_resolver,
&self.resolver, &self.resolver,
&self.config, &self.config,
&self.cache, &self.cache,
@ -1477,27 +1450,24 @@ impl Documents {
let type_specifier = jsx_config.default_types_specifier.as_ref()?; let type_specifier = jsx_config.default_types_specifier.as_ref()?;
let code_specifier = jsx_config.default_specifier.as_ref()?; let code_specifier = jsx_config.default_specifier.as_ref()?;
let cli_resolver = self.resolver.as_cli_resolver(Some(scope)); 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 let type_specifier = cli_resolver
.resolve( .resolve(
type_specifier, type_specifier,
&range, &jsx_config.base_url,
deno_graph::Position::zeroed(),
// todo(dsherret): this is wrong because it doesn't consider CJS referrers // todo(dsherret): this is wrong because it doesn't consider CJS referrers
deno_package_json::NodeModuleKind::Esm, ResolutionMode::Import,
ResolutionMode::Types, NodeResolutionKind::Types,
) )
.ok()?; .ok()?;
let code_specifier = cli_resolver let code_specifier = cli_resolver
.resolve( .resolve(
code_specifier, code_specifier,
&range, &jsx_config.base_url,
deno_graph::Position::zeroed(),
// todo(dsherret): this is wrong because it doesn't consider CJS referrers // todo(dsherret): this is wrong because it doesn't consider CJS referrers
deno_package_json::NodeModuleKind::Esm, ResolutionMode::Import,
ResolutionMode::Execution, NodeResolutionKind::Execution,
) )
.ok()?; .ok()?;
dep_info dep_info
@ -1542,7 +1512,7 @@ impl Documents {
&self, &self,
specifier: &ModuleSpecifier, specifier: &ModuleSpecifier,
referrer: &ModuleSpecifier, referrer: &ModuleSpecifier,
referrer_kind: NodeModuleKind, resolution_mode: ResolutionMode,
file_referrer: Option<&ModuleSpecifier>, file_referrer: Option<&ModuleSpecifier>,
) -> Option<(ModuleSpecifier, MediaType)> { ) -> Option<(ModuleSpecifier, MediaType)> {
if let Some(module_name) = specifier.as_str().strip_prefix("node:") { 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( let (s, mt) = self.resolver.npm_to_file_url(
&npm_ref, &npm_ref,
referrer, referrer,
referrer_kind, resolution_mode,
file_referrer, file_referrer,
)?; )?;
specifier = s; specifier = s;
@ -1571,8 +1541,12 @@ impl Documents {
return Some((specifier, media_type)); return Some((specifier, media_type));
}; };
if let Some(types) = doc.maybe_types_dependency().maybe_specifier() { 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(
self.resolve_dependency(types, &specifier, specifier_kind, file_referrer) types,
&specifier,
doc.resolution_mode(),
file_referrer,
)
} else { } else {
Some((doc.specifier().clone(), doc.media_type())) Some((doc.specifier().clone(), doc.media_type()))
} }
@ -1640,19 +1614,25 @@ fn parse_and_analyze_module(
maybe_headers: Option<&HashMap<String, String>>, maybe_headers: Option<&HashMap<String, String>>,
media_type: MediaType, media_type: MediaType,
file_referrer: Option<&ModuleSpecifier>, file_referrer: Option<&ModuleSpecifier>,
is_cjs_resolver: &LspIsCjsResolver,
resolver: &LspResolver, resolver: &LspResolver,
) -> (Option<ParsedSourceResult>, Option<ModuleResult>) { ) -> (
Option<ParsedSourceResult>,
Option<ModuleResult>,
ResolutionMode,
) {
let parsed_source_result = parse_source(specifier.clone(), text, media_type); let parsed_source_result = parse_source(specifier.clone(), text, media_type);
let module_result = analyze_module( let (module_result, resolution_mode) = analyze_module(
specifier, specifier,
&parsed_source_result, &parsed_source_result,
maybe_headers, maybe_headers,
file_referrer, file_referrer,
is_cjs_resolver,
resolver, resolver,
); );
(Some(parsed_source_result), Some(module_result)) (
Some(parsed_source_result),
Some(module_result),
resolution_mode,
)
} }
fn parse_source( fn parse_source(
@ -1675,44 +1655,51 @@ fn analyze_module(
parsed_source_result: &ParsedSourceResult, parsed_source_result: &ParsedSourceResult,
maybe_headers: Option<&HashMap<String, String>>, maybe_headers: Option<&HashMap<String, String>>,
file_referrer: Option<&ModuleSpecifier>, file_referrer: Option<&ModuleSpecifier>,
is_cjs_resolver: &LspIsCjsResolver,
resolver: &LspResolver, resolver: &LspResolver,
) -> ModuleResult { ) -> (ModuleResult, ResolutionMode) {
match parsed_source_result { match parsed_source_result {
Ok(parsed_source) => { Ok(parsed_source) => {
let npm_resolver = resolver.create_graph_npm_resolver(file_referrer); let npm_resolver = resolver.create_graph_npm_resolver(file_referrer);
let cli_resolver = resolver.as_cli_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 config_data = resolver.as_config_data(file_referrer);
let valid_referrer = specifier.clone(); let valid_referrer = specifier.clone();
let jsx_import_source_config = let jsx_import_source_config =
config_data.and_then(|d| d.maybe_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 { let resolver = SingleReferrerGraphResolver {
valid_referrer: &valid_referrer, valid_referrer: &valid_referrer,
referrer_kind: is_cjs_resolver.get_lsp_referrer_kind( module_resolution_mode,
&specifier,
Some(parsed_source.compute_is_script()),
),
cli_resolver, cli_resolver,
jsx_import_source_config: jsx_import_source_config.as_ref(), jsx_import_source_config: jsx_import_source_config.as_ref(),
}; };
Ok(deno_graph::parse_module_from_ast( (
deno_graph::ParseModuleFromAstOptions { Ok(deno_graph::parse_module_from_ast(
graph_kind: deno_graph::GraphKind::TypesOnly, deno_graph::ParseModuleFromAstOptions {
specifier, graph_kind: deno_graph::GraphKind::TypesOnly,
maybe_headers, specifier,
parsed_source, maybe_headers,
// use a null file system because there's no need to bother resolving parsed_source,
// dynamic imports like import(`./dir/${something}`) in the LSP // use a null file system because there's no need to bother resolving
file_system: &deno_graph::source::NullFileSystem, // dynamic imports like import(`./dir/${something}`) in the LSP
jsr_url_provider: &CliJsrUrlProvider, file_system: &deno_graph::source::NullFileSystem,
maybe_resolver: Some(&resolver), jsr_url_provider: &CliJsrUrlProvider,
maybe_npm_resolver: Some(&npm_resolver), maybe_resolver: Some(&resolver),
}, maybe_npm_resolver: Some(&npm_resolver),
)) },
)),
module_resolution_mode,
)
} }
Err(err) => Err(deno_graph::ModuleGraphError::ModuleError( Err(err) => (
deno_graph::ModuleError::ParseErr(specifier, err.clone()), Err(deno_graph::ModuleGraphError::ModuleError(
)), deno_graph::ModuleError::ParseErr(specifier, err.clone()),
)),
ResolutionMode::Import,
),
} }
} }

View file

@ -22,7 +22,8 @@ use deno_semver::jsr::JsrPackageReqReference;
use indexmap::Equivalent; use indexmap::Equivalent;
use indexmap::IndexSet; use indexmap::IndexSet;
use log::error; use log::error;
use node_resolver::NodeModuleKind; use node_resolver::NodeResolutionKind;
use node_resolver::ResolutionMode;
use serde::Deserialize; use serde::Deserialize;
use serde_json::from_value; use serde_json::from_value;
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -78,7 +79,6 @@ use super::parent_process_checker;
use super::performance::Performance; use super::performance::Performance;
use super::refactor; use super::refactor;
use super::registries::ModuleRegistry; use super::registries::ModuleRegistry;
use super::resolver::LspIsCjsResolver;
use super::resolver::LspResolver; use super::resolver::LspResolver;
use super::testing; use super::testing;
use super::text; use super::text;
@ -146,7 +146,6 @@ pub struct StateSnapshot {
pub project_version: usize, pub project_version: usize,
pub assets: AssetsSnapshot, pub assets: AssetsSnapshot,
pub config: Arc<Config>, pub config: Arc<Config>,
pub is_cjs_resolver: Arc<LspIsCjsResolver>,
pub documents: Arc<Documents>, pub documents: Arc<Documents>,
pub resolver: Arc<LspResolver>, pub resolver: Arc<LspResolver>,
} }
@ -206,7 +205,6 @@ pub struct Inner {
pub documents: Documents, pub documents: Documents,
http_client_provider: Arc<HttpClientProvider>, http_client_provider: Arc<HttpClientProvider>,
initial_cwd: PathBuf, initial_cwd: PathBuf,
pub is_cjs_resolver: Arc<LspIsCjsResolver>,
jsr_search_api: CliJsrSearchApi, jsr_search_api: CliJsrSearchApi,
/// Handles module registries, which allow discovery of modules /// Handles module registries, which allow discovery of modules
module_registry: ModuleRegistry, module_registry: ModuleRegistry,
@ -484,7 +482,6 @@ impl Inner {
let initial_cwd = std::env::current_dir().unwrap_or_else(|_| { let initial_cwd = std::env::current_dir().unwrap_or_else(|_| {
panic!("Could not resolve current working directory") panic!("Could not resolve current working directory")
}); });
let is_cjs_resolver = Arc::new(LspIsCjsResolver::new(&cache));
Self { Self {
assets, assets,
@ -496,7 +493,6 @@ impl Inner {
documents, documents,
http_client_provider, http_client_provider,
initial_cwd: initial_cwd.clone(), initial_cwd: initial_cwd.clone(),
is_cjs_resolver,
jsr_search_api, jsr_search_api,
project_version: 0, project_version: 0,
task_queue: Default::default(), task_queue: Default::default(),
@ -607,7 +603,6 @@ impl Inner {
project_version: self.project_version, project_version: self.project_version,
assets: self.assets.snapshot(), assets: self.assets.snapshot(),
config: Arc::new(self.config.clone()), config: Arc::new(self.config.clone()),
is_cjs_resolver: self.is_cjs_resolver.clone(),
documents: Arc::new(self.documents.clone()), documents: Arc::new(self.documents.clone()),
resolver: self.resolver.snapshot(), resolver: self.resolver.snapshot(),
}) })
@ -629,7 +624,6 @@ impl Inner {
} }
}); });
self.cache = LspCache::new(global_cache_url); 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 deno_dir = self.cache.deno_dir();
let workspace_settings = self.config.workspace_settings(); let workspace_settings = self.config.workspace_settings();
let maybe_root_path = self let maybe_root_path = self
@ -993,13 +987,10 @@ impl Inner {
let resolver = inner.resolver.as_cli_resolver(Some(&referrer)); let resolver = inner.resolver.as_cli_resolver(Some(&referrer));
let Ok(specifier) = resolver.resolve( let Ok(specifier) = resolver.resolve(
&specifier, &specifier,
&deno_graph::Range { &referrer,
specifier: referrer.clone(), deno_graph::Position::zeroed(),
start: deno_graph::Position::zeroed(), ResolutionMode::Import,
end: deno_graph::Position::zeroed(), NodeResolutionKind::Types,
},
NodeModuleKind::Esm,
deno_graph::source::ResolutionMode::Types,
) else { ) else {
return; return;
}; };
@ -1640,8 +1631,8 @@ impl Inner {
.get_ts_diagnostics(&specifier, asset_or_doc.document_lsp_version()); .get_ts_diagnostics(&specifier, asset_or_doc.document_lsp_version());
let specifier_kind = asset_or_doc let specifier_kind = asset_or_doc
.document() .document()
.map(|d| self.is_cjs_resolver.get_doc_module_kind(d)) .map(|d| d.resolution_mode())
.unwrap_or(NodeModuleKind::Esm); .unwrap_or(ResolutionMode::Import);
let mut includes_no_cache = false; let mut includes_no_cache = false;
for diagnostic in &fixable_diagnostics { for diagnostic in &fixable_diagnostics {
match diagnostic.source.as_deref() { match diagnostic.source.as_deref() {
@ -1864,8 +1855,8 @@ impl Inner {
maybe_asset_or_doc maybe_asset_or_doc
.as_ref() .as_ref()
.and_then(|d| d.document()) .and_then(|d| d.document())
.map(|d| self.is_cjs_resolver.get_doc_module_kind(d)) .map(|d| d.resolution_mode())
.unwrap_or(NodeModuleKind::Esm), .unwrap_or(ResolutionMode::Import),
&combined_code_actions.changes, &combined_code_actions.changes,
self, self,
) )
@ -1921,8 +1912,8 @@ impl Inner {
&action_data.specifier, &action_data.specifier,
asset_or_doc asset_or_doc
.document() .document()
.map(|d| self.is_cjs_resolver.get_doc_module_kind(d)) .map(|d| d.resolution_mode())
.unwrap_or(NodeModuleKind::Esm), .unwrap_or(ResolutionMode::Import),
&refactor_edit_info.edits, &refactor_edit_info.edits,
self, self,
) )
@ -2272,7 +2263,6 @@ impl Inner {
&self.jsr_search_api, &self.jsr_search_api,
&self.npm_search_api, &self.npm_search_api,
&self.documents, &self.documents,
&self.is_cjs_resolver,
self.resolver.as_ref(), self.resolver.as_ref(),
self self
.config .config
@ -3781,14 +3771,11 @@ impl Inner {
fn task_definitions(&self) -> LspResult<Vec<TaskDefinition>> { fn task_definitions(&self) -> LspResult<Vec<TaskDefinition>> {
let mut result = vec![]; let mut result = vec![];
for config_file in self.config.tree.config_files() { for config_file in self.config.tree.config_files() {
if let Some(tasks) = json!(&config_file.json.tasks).as_object() { if let Some(tasks) = config_file.to_tasks_config().ok().flatten() {
for (name, value) in tasks { for (name, def) in tasks {
let Some(command) = value.as_str() else {
continue;
};
result.push(TaskDefinition { result.push(TaskDefinition {
name: name.clone(), name: name.clone(),
command: command.to_string(), command: def.command.clone(),
source_uri: url_to_uri(&config_file.specifier) source_uri: url_to_uri(&config_file.specifier)
.map_err(|_| LspError::internal_error())?, .map_err(|_| LspError::internal_error())?,
}); });

View file

@ -14,8 +14,6 @@ pub const LATEST_DIAGNOSTIC_BATCH_INDEX: &str =
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct TaskDefinition { pub struct TaskDefinition {
pub name: String, pub name: String,
// TODO(nayeemrmn): Rename this to `command` in vscode_deno.
#[serde(rename = "detail")]
pub command: String, pub command: String,
pub source_uri: lsp::Uri, pub source_uri: lsp::Uri,
} }

View file

@ -56,9 +56,6 @@ pub async fn start() -> Result<(), AnyError> {
LanguageServer::performance_request, LanguageServer::performance_request,
) )
.custom_method(lsp_custom::TASK_REQUEST, LanguageServer::task_definitions) .custom_method(lsp_custom::TASK_REQUEST, LanguageServer::task_definitions)
// TODO(nayeemrmn): Rename this to `deno/taskDefinitions` in vscode_deno and
// remove this alias.
.custom_method("deno/task", LanguageServer::task_definitions)
.custom_method(testing::TEST_RUN_REQUEST, LanguageServer::test_run_request) .custom_method(testing::TEST_RUN_REQUEST, LanguageServer::test_run_request)
.custom_method( .custom_method(
testing::TEST_RUN_CANCEL_REQUEST, testing::TEST_RUN_CANCEL_REQUEST,

View file

@ -9,13 +9,12 @@ use deno_config::workspace::PackageJsonDepResolution;
use deno_config::workspace::WorkspaceResolver; use deno_config::workspace::WorkspaceResolver;
use deno_core::parking_lot::Mutex; use deno_core::parking_lot::Mutex;
use deno_core::url::Url; use deno_core::url::Url;
use deno_graph::source::ResolutionMode;
use deno_graph::GraphImport; use deno_graph::GraphImport;
use deno_graph::ModuleSpecifier; use deno_graph::ModuleSpecifier;
use deno_graph::Range; use deno_graph::Range;
use deno_npm::NpmSystemInfo; use deno_npm::NpmSystemInfo;
use deno_path_util::url_from_directory_path;
use deno_path_util::url_to_file_path; use deno_path_util::url_to_file_path;
use deno_resolver::cjs::IsCjsResolutionMode;
use deno_resolver::npm::NpmReqResolverOptions; use deno_resolver::npm::NpmReqResolverOptions;
use deno_resolver::DenoResolverOptions; use deno_resolver::DenoResolverOptions;
use deno_resolver::NodeAndNpmReqResolver; use deno_resolver::NodeAndNpmReqResolver;
@ -30,8 +29,8 @@ use deno_semver::package::PackageReq;
use indexmap::IndexMap; use indexmap::IndexMap;
use node_resolver::errors::ClosestPkgJsonError; use node_resolver::errors::ClosestPkgJsonError;
use node_resolver::InNpmPackageChecker; use node_resolver::InNpmPackageChecker;
use node_resolver::NodeModuleKind; use node_resolver::NodeResolutionKind;
use node_resolver::NodeResolutionMode; use node_resolver::ResolutionMode;
use std::borrow::Cow; use std::borrow::Cow;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::collections::BTreeSet; use std::collections::BTreeSet;
@ -40,7 +39,6 @@ use std::collections::HashSet;
use std::sync::Arc; use std::sync::Arc;
use super::cache::LspCache; use super::cache::LspCache;
use super::documents::Document;
use super::jsr::JsrCacheResolver; use super::jsr::JsrCacheResolver;
use crate::args::create_default_npmrc; use crate::args::create_default_npmrc;
use crate::args::CacheSetting; use crate::args::CacheSetting;
@ -48,6 +46,8 @@ use crate::args::CliLockfile;
use crate::args::NpmInstallDepsProvider; use crate::args::NpmInstallDepsProvider;
use crate::cache::DenoCacheEnvFsAdapter; use crate::cache::DenoCacheEnvFsAdapter;
use crate::factory::Deferred; 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::graph_util::CliJsrUrlProvider;
use crate::http_util::HttpClientProvider; use crate::http_util::HttpClientProvider;
use crate::lsp::config::Config; use crate::lsp::config::Config;
@ -70,7 +70,6 @@ use crate::resolver::CliResolverOptions;
use crate::resolver::IsCjsResolver; use crate::resolver::IsCjsResolver;
use crate::resolver::WorkerCliNpmGraphResolver; use crate::resolver::WorkerCliNpmGraphResolver;
use crate::tsc::into_specifier_and_media_type; 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::ProgressBar;
use crate::util::progress_bar::ProgressBarStyle; use crate::util::progress_bar::ProgressBarStyle;
@ -78,6 +77,7 @@ use crate::util::progress_bar::ProgressBarStyle;
struct LspScopeResolver { struct LspScopeResolver {
resolver: Arc<CliResolver>, resolver: Arc<CliResolver>,
in_npm_pkg_checker: Arc<dyn InNpmPackageChecker>, in_npm_pkg_checker: Arc<dyn InNpmPackageChecker>,
is_cjs_resolver: Arc<IsCjsResolver>,
jsr_resolver: Option<Arc<JsrCacheResolver>>, jsr_resolver: Option<Arc<JsrCacheResolver>>,
npm_resolver: Option<Arc<dyn CliNpmResolver>>, npm_resolver: Option<Arc<dyn CliNpmResolver>>,
node_resolver: Option<Arc<NodeResolver>>, node_resolver: Option<Arc<NodeResolver>>,
@ -96,6 +96,7 @@ impl Default for LspScopeResolver {
Self { Self {
resolver: factory.cli_resolver().clone(), resolver: factory.cli_resolver().clone(),
in_npm_pkg_checker: factory.in_npm_pkg_checker().clone(), in_npm_pkg_checker: factory.in_npm_pkg_checker().clone(),
is_cjs_resolver: factory.is_cjs_resolver().clone(),
jsr_resolver: None, jsr_resolver: None,
npm_resolver: None, npm_resolver: None,
node_resolver: None, node_resolver: None,
@ -146,7 +147,7 @@ impl LspScopeResolver {
.map(|(referrer, imports)| { .map(|(referrer, imports)| {
let resolver = SingleReferrerGraphResolver { let resolver = SingleReferrerGraphResolver {
valid_referrer: &referrer, valid_referrer: &referrer,
referrer_kind: NodeModuleKind::Esm, module_resolution_mode: ResolutionMode::Import,
cli_resolver: &cli_resolver, cli_resolver: &cli_resolver,
jsx_import_source_config: maybe_jsx_import_source_config jsx_import_source_config: maybe_jsx_import_source_config
.as_ref(), .as_ref(),
@ -180,16 +181,16 @@ impl LspScopeResolver {
&req_ref, &req_ref,
&referrer, &referrer,
// todo(dsherret): this is wrong because it doesn't consider CJS referrers // todo(dsherret): this is wrong because it doesn't consider CJS referrers
NodeModuleKind::Esm, ResolutionMode::Import,
NodeResolutionMode::Types, NodeResolutionKind::Types,
) )
.or_else(|_| { .or_else(|_| {
npm_pkg_req_resolver.resolve_req_reference( npm_pkg_req_resolver.resolve_req_reference(
&req_ref, &req_ref,
&referrer, &referrer,
// todo(dsherret): this is wrong because it doesn't consider CJS referrers // todo(dsherret): this is wrong because it doesn't consider CJS referrers
NodeModuleKind::Esm, ResolutionMode::Import,
NodeResolutionMode::Execution, NodeResolutionKind::Execution,
) )
}) })
.ok()?, .ok()?,
@ -205,6 +206,7 @@ impl LspScopeResolver {
Self { Self {
resolver: cli_resolver, resolver: cli_resolver,
in_npm_pkg_checker, in_npm_pkg_checker,
is_cjs_resolver: factory.is_cjs_resolver().clone(),
jsr_resolver, jsr_resolver,
npm_pkg_req_resolver, npm_pkg_req_resolver,
npm_resolver, npm_resolver,
@ -228,6 +230,7 @@ impl LspScopeResolver {
Arc::new(Self { Arc::new(Self {
resolver: factory.cli_resolver().clone(), resolver: factory.cli_resolver().clone(),
in_npm_pkg_checker: factory.in_npm_pkg_checker().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(), jsr_resolver: self.jsr_resolver.clone(),
npm_pkg_req_resolver: factory.npm_pkg_req_resolver().cloned(), npm_pkg_req_resolver: factory.npm_pkg_req_resolver().cloned(),
npm_resolver: factory.npm_resolver().cloned(), npm_resolver: factory.npm_resolver().cloned(),
@ -345,6 +348,14 @@ impl LspResolver {
resolver.resolver.create_graph_npm_resolver() 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( pub fn as_config_data(
&self, &self,
file_referrer: Option<&ModuleSpecifier>, file_referrer: Option<&ModuleSpecifier>,
@ -424,7 +435,7 @@ impl LspResolver {
&self, &self,
req_ref: &NpmPackageReqReference, req_ref: &NpmPackageReqReference,
referrer: &ModuleSpecifier, referrer: &ModuleSpecifier,
referrer_kind: NodeModuleKind, resolution_mode: ResolutionMode,
file_referrer: Option<&ModuleSpecifier>, file_referrer: Option<&ModuleSpecifier>,
) -> Option<(ModuleSpecifier, MediaType)> { ) -> Option<(ModuleSpecifier, MediaType)> {
let resolver = self.get_scope_resolver(file_referrer); let resolver = self.get_scope_resolver(file_referrer);
@ -434,8 +445,8 @@ impl LspResolver {
.resolve_req_reference( .resolve_req_reference(
req_ref, req_ref,
referrer, referrer,
referrer_kind, resolution_mode,
NodeResolutionMode::Types, NodeResolutionKind::Types,
) )
.ok()?, .ok()?,
))) )))
@ -492,7 +503,7 @@ impl LspResolver {
&self, &self,
specifier_text: &str, specifier_text: &str,
referrer: &ModuleSpecifier, referrer: &ModuleSpecifier,
referrer_kind: NodeModuleKind, resolution_mode: ResolutionMode,
) -> bool { ) -> bool {
let resolver = self.get_scope_resolver(Some(referrer)); let resolver = self.get_scope_resolver(Some(referrer));
let Some(npm_pkg_req_resolver) = resolver.npm_pkg_req_resolver.as_ref() let Some(npm_pkg_req_resolver) = resolver.npm_pkg_req_resolver.as_ref()
@ -503,8 +514,8 @@ impl LspResolver {
.resolve_if_for_npm_pkg( .resolve_if_for_npm_pkg(
specifier_text, specifier_text,
referrer, referrer,
referrer_kind, resolution_mode,
NodeResolutionMode::Types, NodeResolutionKind::Types,
) )
.ok() .ok()
.flatten() .flatten()
@ -581,6 +592,7 @@ pub struct ScopeDepInfo {
struct ResolverFactoryServices { struct ResolverFactoryServices {
cli_resolver: Deferred<Arc<CliResolver>>, cli_resolver: Deferred<Arc<CliResolver>>,
in_npm_pkg_checker: Deferred<Arc<dyn InNpmPackageChecker>>, in_npm_pkg_checker: Deferred<Arc<dyn InNpmPackageChecker>>,
is_cjs_resolver: Deferred<Arc<IsCjsResolver>>,
node_resolver: Deferred<Option<Arc<NodeResolver>>>, node_resolver: Deferred<Option<Arc<NodeResolver>>>,
npm_pkg_req_resolver: Deferred<Option<Arc<CliNpmReqResolver>>>, npm_pkg_req_resolver: Deferred<Option<Arc<CliNpmReqResolver>>>,
npm_resolver: Option<Arc<dyn CliNpmResolver>>, 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>> { pub fn node_resolver(&self) -> Option<&Arc<NodeResolver>> {
self self
.services .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)] #[derive(Debug)]
pub struct SingleReferrerGraphResolver<'a> { pub struct SingleReferrerGraphResolver<'a> {
pub valid_referrer: &'a ModuleSpecifier, pub valid_referrer: &'a ModuleSpecifier,
pub referrer_kind: NodeModuleKind, pub module_resolution_mode: ResolutionMode,
pub cli_resolver: &'a CliResolver, pub cli_resolver: &'a CliResolver,
pub jsx_import_source_config: Option<&'a JsxImportSourceConfig>, pub jsx_import_source_config: Option<&'a JsxImportSourceConfig>,
} }
@ -924,16 +864,20 @@ impl<'a> deno_graph::source::Resolver for SingleReferrerGraphResolver<'a> {
&self, &self,
specifier_text: &str, specifier_text: &str,
referrer_range: &Range, referrer_range: &Range,
mode: ResolutionMode, resolution_kind: deno_graph::source::ResolutionKind,
) -> Result<ModuleSpecifier, deno_graph::source::ResolveError> { ) -> Result<ModuleSpecifier, deno_graph::source::ResolveError> {
// this resolver assumes it will only be used with a single referrer // this resolver assumes it will only be used with a single referrer
// with the provided referrer kind // with the provided referrer kind
debug_assert_eq!(referrer_range.specifier, *self.valid_referrer); debug_assert_eq!(referrer_range.specifier, *self.valid_referrer);
self.cli_resolver.resolve( self.cli_resolver.resolve(
specifier_text, specifier_text,
referrer_range, &referrer_range.specifier,
self.referrer_kind, referrer_range.range.start,
mode, referrer_range
.resolution_mode
.map(to_node_resolution_mode)
.unwrap_or(self.module_resolution_mode),
to_node_resolution_kind(resolution_kind),
) )
} }
} }

View file

@ -70,7 +70,7 @@ use indexmap::IndexMap;
use indexmap::IndexSet; use indexmap::IndexSet;
use lazy_regex::lazy_regex; use lazy_regex::lazy_regex;
use log::error; use log::error;
use node_resolver::NodeModuleKind; use node_resolver::ResolutionMode;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use regex::Captures; use regex::Captures;
use regex::Regex; use regex::Regex;
@ -4449,9 +4449,9 @@ fn op_load<'s>(
version: state.script_version(&specifier), version: state.script_version(&specifier),
is_cjs: doc is_cjs: doc
.document() .document()
.map(|d| state.state_snapshot.is_cjs_resolver.get_doc_module_kind(d)) .map(|d| d.resolution_mode())
.unwrap_or(NodeModuleKind::Esm) .unwrap_or(ResolutionMode::Import)
== NodeModuleKind::Cjs, == ResolutionMode::Require,
}) })
}; };
let serialized = serde_v8::to_v8(scope, maybe_load_response)?; let serialized = serde_v8::to_v8(scope, maybe_load_response)?;
@ -4479,17 +4479,9 @@ fn op_release(
fn op_resolve( fn op_resolve(
state: &mut OpState, state: &mut OpState,
#[string] base: String, #[string] base: String,
is_base_cjs: bool, #[serde] specifiers: Vec<(bool, String)>,
#[serde] specifiers: Vec<String>,
) -> Result<Vec<Option<(String, String)>>, AnyError> { ) -> Result<Vec<Option<(String, String)>>, AnyError> {
op_resolve_inner( op_resolve_inner(state, ResolveArgs { base, specifiers })
state,
ResolveArgs {
base,
is_base_cjs,
specifiers,
},
)
} }
struct TscRequestArray { struct TscRequestArray {
@ -4692,10 +4684,7 @@ fn op_script_names(state: &mut OpState) -> ScriptNames {
let (types, _) = documents.resolve_dependency( let (types, _) = documents.resolve_dependency(
types, types,
specifier, specifier,
state doc.resolution_mode(),
.state_snapshot
.is_cjs_resolver
.get_doc_module_kind(doc),
doc.file_referrer(), doc.file_referrer(),
)?; )?;
let types_doc = documents.get_or_load(&types, doc.file_referrer())?; let types_doc = documents.get_or_load(&types, doc.file_referrer())?;
@ -5579,7 +5568,6 @@ mod tests {
documents: Arc::new(documents), documents: Arc::new(documents),
assets: Default::default(), assets: Default::default(),
config: Arc::new(config), config: Arc::new(config),
is_cjs_resolver: Default::default(),
resolver, resolver,
}); });
let performance = Arc::new(Performance::default()); let performance = Arc::new(Performance::default());
@ -6430,8 +6418,7 @@ mod tests {
&mut state, &mut state,
ResolveArgs { ResolveArgs {
base: temp_dir.url().join("a.ts").unwrap().to_string(), base: temp_dir.url().join("a.ts").unwrap().to_string(),
is_base_cjs: false, specifiers: vec![(false, "./b.ts".to_string())],
specifiers: vec!["./b.ts".to_string()],
}, },
) )
.unwrap(); .unwrap();

View file

@ -448,7 +448,7 @@ fn resolve_flags_and_init(
}; };
if let Some(otel_config) = flags.otel_config() { 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); util::logger::init(flags.log_level);

View file

@ -88,7 +88,7 @@ fn main() {
match standalone { match standalone {
Ok(Some(data)) => { Ok(Some(data)) => {
if let Some(otel_config) = data.metadata.otel_config.clone() { 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); util::logger::init(data.metadata.log_level);
load_env_vars(&data.metadata.env_vars_from_env_file); load_env_vars(&data.metadata.env_vars_from_env_file);

View file

@ -57,9 +57,7 @@ use deno_core::ModuleSourceCode;
use deno_core::ModuleSpecifier; use deno_core::ModuleSpecifier;
use deno_core::ModuleType; use deno_core::ModuleType;
use deno_core::RequestedModuleType; use deno_core::RequestedModuleType;
use deno_core::ResolutionKind;
use deno_core::SourceCodeCacheInfo; use deno_core::SourceCodeCacheInfo;
use deno_graph::source::ResolutionMode;
use deno_graph::GraphKind; use deno_graph::GraphKind;
use deno_graph::JsModule; use deno_graph::JsModule;
use deno_graph::JsonModule; use deno_graph::JsonModule;
@ -76,7 +74,8 @@ use deno_runtime::deno_permissions::PermissionsContainer;
use deno_semver::npm::NpmPackageReqReference; use deno_semver::npm::NpmPackageReqReference;
use node_resolver::errors::ClosestPkgJsonError; use node_resolver::errors::ClosestPkgJsonError;
use node_resolver::InNpmPackageChecker; use node_resolver::InNpmPackageChecker;
use node_resolver::NodeResolutionMode; use node_resolver::NodeResolutionKind;
use node_resolver::ResolutionMode;
pub struct ModuleLoadPreparer { pub struct ModuleLoadPreparer {
options: Arc<CliOptions>, options: Arc<CliOptions>,
@ -498,13 +497,11 @@ impl<TGraphContainer: ModuleGraphContainer>
} }
Resolution::None => Cow::Owned(self.shared.resolver.resolve( Resolution::None => Cow::Owned(self.shared.resolver.resolve(
raw_specifier, raw_specifier,
&deno_graph::Range { referrer,
specifier: referrer.clone(), deno_graph::Position::zeroed(),
start: deno_graph::Position::zeroed(), // if we're here, that means it's resolving a dynamic import
end: deno_graph::Position::zeroed(), ResolutionMode::Import,
}, NodeResolutionKind::Execution,
self.shared.cjs_tracker.get_referrer_kind(referrer),
ResolutionMode::Execution,
)?), )?),
}; };
@ -517,8 +514,8 @@ impl<TGraphContainer: ModuleGraphContainer>
.resolve_req_reference( .resolve_req_reference(
&reference, &reference,
referrer, referrer,
self.shared.cjs_tracker.get_referrer_kind(referrer), ResolutionMode::Import,
NodeResolutionMode::Execution, NodeResolutionKind::Execution,
) )
.map_err(AnyError::from); .map_err(AnyError::from);
} }
@ -539,8 +536,8 @@ impl<TGraphContainer: ModuleGraphContainer>
&package_folder, &package_folder,
module.nv_reference.sub_path(), module.nv_reference.sub_path(),
Some(referrer), Some(referrer),
self.shared.cjs_tracker.get_referrer_kind(referrer), ResolutionMode::Import,
NodeResolutionMode::Execution, NodeResolutionKind::Execution,
) )
.with_context(|| { .with_context(|| {
format!("Could not resolve '{}'.", module.nv_reference) format!("Could not resolve '{}'.", module.nv_reference)
@ -806,7 +803,7 @@ impl<TGraphContainer: ModuleGraphContainer> ModuleLoader
&self, &self,
specifier: &str, specifier: &str,
referrer: &str, referrer: &str,
_kind: ResolutionKind, _kind: deno_core::ResolutionKind,
) -> Result<ModuleSpecifier, AnyError> { ) -> Result<ModuleSpecifier, AnyError> {
fn ensure_not_jsr_non_jsr_remote_import( fn ensure_not_jsr_non_jsr_remote_import(
specifier: &ModuleSpecifier, specifier: &ModuleSpecifier,
@ -1063,7 +1060,10 @@ impl<TGraphContainer: ModuleGraphContainer> NodeRequireLoader
self.npm_resolver.ensure_read_permission(permissions, path) self.npm_resolver.ensure_read_permission(permissions, path)
} }
fn load_text_file_lossy(&self, path: &Path) -> Result<String, AnyError> { fn load_text_file_lossy(
&self,
path: &Path,
) -> Result<Cow<'static, str>, AnyError> {
// todo(dsherret): use the preloaded module from the graph if available? // todo(dsherret): use the preloaded module from the graph if available?
let media_type = MediaType::from_path(path); let media_type = MediaType::from_path(path);
let text = self.fs.read_text_file_lossy_sync(path, None)?; let text = self.fs.read_text_file_lossy_sync(path, None)?;
@ -1078,15 +1078,18 @@ impl<TGraphContainer: ModuleGraphContainer> NodeRequireLoader
.into(), .into(),
); );
} }
self.emitter.emit_parsed_source_sync( self
&specifier, .emitter
media_type, .emit_parsed_source_sync(
// this is probably not super accurate due to require esm, but probably ok. &specifier,
// If we find this causes a lot of churn in the emit cache then we should media_type,
// investigate how we can make this better // this is probably not super accurate due to require esm, but probably ok.
ModuleKind::Cjs, // If we find this causes a lot of churn in the emit cache then we should
&text.into(), // investigate how we can make this better
) ModuleKind::Cjs,
&text.into(),
)
.map(Cow::Owned)
} else { } else {
Ok(text) Ok(text)
} }

View file

@ -160,7 +160,7 @@ impl CjsCodeAnalyzer for CliCjsCodeAnalyzer {
if let Ok(source_from_file) = if let Ok(source_from_file) =
self.fs.read_text_file_lossy_async(path, None).await self.fs.read_text_file_lossy_async(path, None).await
{ {
Cow::Owned(source_from_file) source_from_file
} else { } else {
return Ok(ExtNodeCjsAnalysis::Cjs(CjsAnalysisExports { return Ok(ExtNodeCjsAnalysis::Cjs(CjsAnalysisExports {
exports: vec![], exports: vec![],

View file

@ -182,6 +182,12 @@ impl<'a> LifecycleScripts<'a> {
); );
let mut env_vars = crate::task_runner::real_env_vars(); 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 // 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 // (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, // take in all (non copy) packages from snapshot,
// and resolve the set of available binaries to create // and resolve the set of available binaries to create
// custom commands available to the task runner // custom commands available to the task runner

View file

@ -298,6 +298,12 @@ async fn sync_resolution_with_fs(
return Ok(()); // don't create the directory 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_local_registry_dir = root_node_modules_dir_path.join(".deno");
let deno_node_modules_dir = deno_local_registry_dir.join("node_modules"); let deno_node_modules_dir = deno_local_registry_dir.join("node_modules");
fs::create_dir_all(&deno_node_modules_dir).with_context(|| { fs::create_dir_all(&deno_node_modules_dir).with_context(|| {

View file

@ -12,7 +12,6 @@ use deno_core::error::AnyError;
use deno_core::url::Url; use deno_core::url::Url;
use deno_core::ModuleSourceCode; use deno_core::ModuleSourceCode;
use deno_core::ModuleSpecifier; use deno_core::ModuleSpecifier;
use deno_graph::source::ResolutionMode;
use deno_graph::source::ResolveError; use deno_graph::source::ResolveError;
use deno_graph::source::UnknownBuiltInNodeModuleError; use deno_graph::source::UnknownBuiltInNodeModuleError;
use deno_graph::NpmLoadError; 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::is_builtin_node_module;
use deno_runtime::deno_node::DenoFsNodeResolverEnv; use deno_runtime::deno_node::DenoFsNodeResolverEnv;
use deno_semver::package::PackageReq; use deno_semver::package::PackageReq;
use node_resolver::NodeModuleKind; use node_resolver::NodeResolutionKind;
use node_resolver::NodeResolutionMode; use node_resolver::ResolutionMode;
use std::borrow::Cow; use std::borrow::Cow;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
@ -38,12 +37,11 @@ use crate::node::CliNodeCodeTranslator;
use crate::npm::CliNpmResolver; use crate::npm::CliNpmResolver;
use crate::npm::InnerCliNpmResolverRef; use crate::npm::InnerCliNpmResolverRef;
use crate::util::sync::AtomicFlag; use crate::util::sync::AtomicFlag;
use crate::util::text_encoding::from_utf8_lossy_owned; use crate::util::text_encoding::from_utf8_lossy_cow;
pub type CjsTracker = deno_resolver::cjs::CjsTracker<DenoFsNodeResolverEnv>; pub type CjsTracker = deno_resolver::cjs::CjsTracker<DenoFsNodeResolverEnv>;
pub type IsCjsResolver = pub type IsCjsResolver =
deno_resolver::cjs::IsCjsResolver<DenoFsNodeResolverEnv>; deno_resolver::cjs::IsCjsResolver<DenoFsNodeResolverEnv>;
pub type IsCjsResolverOptions = deno_resolver::cjs::IsCjsResolverOptions;
pub type CliSloppyImportsResolver = pub type CliSloppyImportsResolver =
SloppyImportsResolver<SloppyImportsCachedFs>; SloppyImportsResolver<SloppyImportsCachedFs>;
pub type CliDenoResolver = deno_resolver::DenoResolver< pub type CliDenoResolver = deno_resolver::DenoResolver<
@ -64,7 +62,10 @@ pub struct ModuleCodeStringSource {
pub struct CliDenoResolverFs(pub Arc<dyn FileSystem>); pub struct CliDenoResolverFs(pub Arc<dyn FileSystem>);
impl deno_resolver::fs::DenoResolverFs for CliDenoResolverFs { impl deno_resolver::fs::DenoResolverFs for CliDenoResolverFs {
fn read_to_string_lossy(&self, path: &Path) -> std::io::Result<String> { fn read_to_string_lossy(
&self,
path: &Path,
) -> std::io::Result<Cow<'static, str>> {
self self
.0 .0
.read_text_file_lossy_sync(path, None) .read_text_file_lossy_sync(path, None)
@ -184,18 +185,21 @@ impl NpmModuleLoader {
let code = if self.cjs_tracker.is_maybe_cjs(specifier, media_type)? { let code = if self.cjs_tracker.is_maybe_cjs(specifier, media_type)? {
// translate cjs to esm if it's cjs and inject node globals // translate cjs to esm if it's cjs and inject node globals
let code = from_utf8_lossy_owned(code); let code = from_utf8_lossy_cow(code);
ModuleSourceCode::String( ModuleSourceCode::String(
self self
.node_code_translator .node_code_translator
.translate_cjs_to_esm(specifier, Some(Cow::Owned(code))) .translate_cjs_to_esm(specifier, Some(code))
.await? .await?
.into_owned() .into_owned()
.into(), .into(),
) )
} else { } else {
// esm and json code is untouched // esm and json code is untouched
ModuleSourceCode::Bytes(code.into_boxed_slice().into()) ModuleSourceCode::Bytes(match code {
Cow::Owned(bytes) => bytes.into_boxed_slice().into(),
Cow::Borrowed(bytes) => bytes.into(),
})
}; };
Ok(ModuleCodeStringSource { Ok(ModuleCodeStringSource {
@ -247,25 +251,14 @@ impl CliResolver {
pub fn resolve( pub fn resolve(
&self, &self,
raw_specifier: &str, raw_specifier: &str,
referrer_range: &deno_graph::Range, referrer: &ModuleSpecifier,
referrer_kind: NodeModuleKind, referrer_range_start: deno_graph::Position,
mode: ResolutionMode, resolution_mode: ResolutionMode,
resolution_kind: NodeResolutionKind,
) -> Result<ModuleSpecifier, ResolveError> { ) -> Result<ModuleSpecifier, ResolveError> {
fn to_node_mode(mode: ResolutionMode) -> NodeResolutionMode {
match mode {
ResolutionMode::Execution => NodeResolutionMode::Execution,
ResolutionMode::Types => NodeResolutionMode::Types,
}
}
let resolution = self let resolution = self
.deno_resolver .deno_resolver
.resolve( .resolve(raw_specifier, referrer, resolution_mode, resolution_kind)
raw_specifier,
&referrer_range.specifier,
referrer_kind,
to_node_mode(mode),
)
.map_err(|err| match err.into_kind() { .map_err(|err| match err.into_kind() {
deno_resolver::DenoResolveErrorKind::MappedResolution( deno_resolver::DenoResolveErrorKind::MappedResolution(
mapped_resolution_error, mapped_resolution_error,
@ -291,10 +284,11 @@ impl CliResolver {
} => { } => {
if self.warned_pkgs.insert(reference.req().clone()) { if self.warned_pkgs.insert(reference.req().clone()) {
log::warn!( log::warn!(
"{} {}\n at {}", "{} {}\n at {}:{}",
colors::yellow("Warning"), colors::yellow("Warning"),
diagnostic, diagnostic,
referrer_range referrer,
referrer_range_start,
); );
} }
} }
@ -335,13 +329,10 @@ impl<'a> deno_graph::source::NpmResolver for WorkerCliNpmGraphResolver<'a> {
module_name: &str, module_name: &str,
range: &deno_graph::Range, range: &deno_graph::Range,
) { ) {
let deno_graph::Range { let start = range.range.start;
start, specifier, .. let specifier = &range.specifier;
} = range;
let line = start.line + 1;
let column = start.character + 1;
if !*DENO_DISABLE_PEDANTIC_NODE_WARNINGS { 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"))
} }
} }

View file

@ -554,6 +554,7 @@
"bare-node-builtins", "bare-node-builtins",
"byonm", "byonm",
"cron", "cron",
"detect-cjs",
"ffi", "ffi",
"fs", "fs",
"fmt-component", "fmt-component",

View file

@ -4,6 +4,7 @@ use std::borrow::Cow;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::collections::HashMap; use std::collections::HashMap;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::env;
use std::env::current_exe; use std::env::current_exe;
use std::ffi::OsString; use std::ffi::OsString;
use std::fs; use std::fs;
@ -15,6 +16,7 @@ use std::io::Seek;
use std::io::SeekFrom; use std::io::SeekFrom;
use std::io::Write; use std::io::Write;
use std::ops::Range; use std::ops::Range;
use std::path::Component;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use std::process::Command; use std::process::Command;
@ -47,11 +49,11 @@ use deno_runtime::deno_fs::FileSystem;
use deno_runtime::deno_fs::RealFs; use deno_runtime::deno_fs::RealFs;
use deno_runtime::deno_io::fs::FsError; use deno_runtime::deno_io::fs::FsError;
use deno_runtime::deno_node::PackageJson; use deno_runtime::deno_node::PackageJson;
use deno_runtime::ops::otel::OtelConfig;
use deno_semver::npm::NpmVersionReqParseError; use deno_semver::npm::NpmVersionReqParseError;
use deno_semver::package::PackageReq; use deno_semver::package::PackageReq;
use deno_semver::Version; use deno_semver::Version;
use deno_semver::VersionReqSpecifierParseError; use deno_semver::VersionReqSpecifierParseError;
use deno_telemetry::OtelConfig;
use indexmap::IndexMap; use indexmap::IndexMap;
use log::Level; use log::Level;
use serde::Deserialize; use serde::Deserialize;
@ -280,14 +282,13 @@ impl StandaloneModules {
.vfs .vfs
.read_file_all(entry, VfsFileSubDataKind::ModuleGraph)?, .read_file_all(entry, VfsFileSubDataKind::ModuleGraph)?,
Err(err) if err.kind() == ErrorKind::NotFound => { Err(err) if err.kind() == ErrorKind::NotFound => {
let bytes = match RealFs.read_file_sync(&path, None) { match RealFs.read_file_sync(&path, None) {
Ok(bytes) => bytes, Ok(bytes) => bytes,
Err(FsError::Io(err)) if err.kind() == ErrorKind::NotFound => { Err(FsError::Io(err)) if err.kind() == ErrorKind::NotFound => {
return Ok(None) return Ok(None)
} }
Err(err) => return Err(err.into()), Err(err) => return Err(err.into()),
}; }
Cow::Owned(bytes)
} }
Err(err) => return Err(err.into()), Err(err) => return Err(err.into()),
}; };
@ -457,7 +458,7 @@ impl<'a> DenoCompileBinaryWriter<'a> {
// //
// Phase 2 of the 'min sized' deno compile RFC talks // Phase 2 of the 'min sized' deno compile RFC talks
// about adding this as a flag. // 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(|| { return std::fs::read(&path).with_context(|| {
format!("Could not find denort at '{}'", path.to_string_lossy()) format!("Could not find denort at '{}'", path.to_string_lossy())
}); });
@ -692,7 +693,7 @@ impl<'a> DenoCompileBinaryWriter<'a> {
&file_path, &file_path,
match maybe_source { match maybe_source {
Some(source) => source, Some(source) => source,
None => RealFs.read_file_sync(&file_path, None)?, None => RealFs.read_file_sync(&file_path, None)?.into_owned(),
}, },
VfsFileSubDataKind::ModuleGraph, VfsFileSubDataKind::ModuleGraph,
) )
@ -775,6 +776,7 @@ impl<'a> DenoCompileBinaryWriter<'a> {
unstable_config: UnstableConfig { unstable_config: UnstableConfig {
legacy_flag_enabled: false, legacy_flag_enabled: false,
bare_node_builtins: self.cli_options.unstable_bare_node_builtins(), 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(), sloppy_imports: self.cli_options.unstable_sloppy_imports(),
features: self.cli_options.unstable_features(), features: self.cli_options.unstable_features(),
}, },
@ -908,6 +910,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 /// This function returns the environment variables specified
/// in the passed environment file. /// in the passed environment file.
fn get_file_env_vars( fn get_file_env_vars(

View file

@ -32,6 +32,7 @@ use deno_core::ResolutionKind;
use deno_core::SourceCodeCacheInfo; use deno_core::SourceCodeCacheInfo;
use deno_npm::npm_rc::ResolvedNpmRc; use deno_npm::npm_rc::ResolvedNpmRc;
use deno_package_json::PackageJsonDepValue; use deno_package_json::PackageJsonDepValue;
use deno_resolver::cjs::IsCjsResolutionMode;
use deno_resolver::npm::NpmReqResolverOptions; use deno_resolver::npm::NpmReqResolverOptions;
use deno_runtime::deno_fs; use deno_runtime::deno_fs;
use deno_runtime::deno_node::create_host_defined_options; 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 import_map::parse_from_json;
use node_resolver::analyze::NodeCodeTranslator; use node_resolver::analyze::NodeCodeTranslator;
use node_resolver::errors::ClosestPkgJsonError; use node_resolver::errors::ClosestPkgJsonError;
use node_resolver::NodeModuleKind; use node_resolver::NodeResolutionKind;
use node_resolver::NodeResolutionMode; use node_resolver::ResolutionMode;
use serialization::DenoCompileModuleSource; use serialization::DenoCompileModuleSource;
use std::borrow::Cow; use std::borrow::Cow;
use std::rc::Rc; use std::rc::Rc;
@ -87,10 +88,10 @@ use crate::npm::CreateInNpmPkgCheckerOptions;
use crate::resolver::CjsTracker; use crate::resolver::CjsTracker;
use crate::resolver::CliDenoResolverFs; use crate::resolver::CliDenoResolverFs;
use crate::resolver::CliNpmReqResolver; use crate::resolver::CliNpmReqResolver;
use crate::resolver::IsCjsResolverOptions;
use crate::resolver::NpmModuleLoader; use crate::resolver::NpmModuleLoader;
use crate::util::progress_bar::ProgressBar; use crate::util::progress_bar::ProgressBar;
use crate::util::progress_bar::ProgressBarStyle; use crate::util::progress_bar::ProgressBarStyle;
use crate::util::text_encoding::from_utf8_lossy_cow;
use crate::util::v8::construct_v8_flags; use crate::util::v8::construct_v8_flags;
use crate::worker::CliCodeCache; use crate::worker::CliCodeCache;
use crate::worker::CliMainWorkerFactory; use crate::worker::CliMainWorkerFactory;
@ -193,9 +194,9 @@ impl ModuleLoader for EmbeddedModuleLoader {
.cjs_tracker .cjs_tracker
.is_maybe_cjs(&referrer, MediaType::from_specifier(&referrer))? .is_maybe_cjs(&referrer, MediaType::from_specifier(&referrer))?
{ {
NodeModuleKind::Cjs ResolutionMode::Require
} else { } else {
NodeModuleKind::Esm ResolutionMode::Import
}; };
if self.shared.node_resolver.in_npm_package(&referrer) { if self.shared.node_resolver.in_npm_package(&referrer) {
@ -207,7 +208,7 @@ impl ModuleLoader for EmbeddedModuleLoader {
raw_specifier, raw_specifier,
&referrer, &referrer,
referrer_kind, referrer_kind,
NodeResolutionMode::Execution, NodeResolutionKind::Execution,
)? )?
.into_url(), .into_url(),
); );
@ -235,7 +236,7 @@ impl ModuleLoader for EmbeddedModuleLoader {
sub_path.as_deref(), sub_path.as_deref(),
Some(&referrer), Some(&referrer),
referrer_kind, referrer_kind,
NodeResolutionMode::Execution, NodeResolutionKind::Execution,
)?, )?,
), ),
Ok(MappedResolution::PackageJson { Ok(MappedResolution::PackageJson {
@ -252,7 +253,7 @@ impl ModuleLoader for EmbeddedModuleLoader {
sub_path.as_deref(), sub_path.as_deref(),
&referrer, &referrer,
referrer_kind, referrer_kind,
NodeResolutionMode::Execution, NodeResolutionKind::Execution,
) )
.map_err(AnyError::from), .map_err(AnyError::from),
PackageJsonDepValue::Workspace(version_req) => { PackageJsonDepValue::Workspace(version_req) => {
@ -272,7 +273,7 @@ impl ModuleLoader for EmbeddedModuleLoader {
sub_path.as_deref(), sub_path.as_deref(),
Some(&referrer), Some(&referrer),
referrer_kind, referrer_kind,
NodeResolutionMode::Execution, NodeResolutionKind::Execution,
)?, )?,
) )
} }
@ -286,7 +287,7 @@ impl ModuleLoader for EmbeddedModuleLoader {
&reference, &reference,
&referrer, &referrer,
referrer_kind, referrer_kind,
NodeResolutionMode::Execution, NodeResolutionKind::Execution,
)?); )?);
} }
@ -313,7 +314,7 @@ impl ModuleLoader for EmbeddedModuleLoader {
raw_specifier, raw_specifier,
&referrer, &referrer,
referrer_kind, referrer_kind,
NodeResolutionMode::Execution, NodeResolutionKind::Execution,
)?; )?;
if let Some(res) = maybe_res { if let Some(res) = maybe_res {
return Ok(res.into_url()); return Ok(res.into_url());
@ -516,13 +517,13 @@ impl NodeRequireLoader for EmbeddedModuleLoader {
fn load_text_file_lossy( fn load_text_file_lossy(
&self, &self,
path: &std::path::Path, path: &std::path::Path,
) -> Result<String, AnyError> { ) -> Result<Cow<'static, str>, AnyError> {
let file_entry = self.shared.vfs.file_entry(path)?; let file_entry = self.shared.vfs.file_entry(path)?;
let file_bytes = self let file_bytes = self
.shared .shared
.vfs .vfs
.read_file_all(file_entry, VfsFileSubDataKind::ModuleGraph)?; .read_file_all(file_entry, VfsFileSubDataKind::ModuleGraph)?;
Ok(String::from_utf8(file_bytes.into_owned())?) Ok(from_utf8_lossy_cow(file_bytes))
} }
fn is_maybe_cjs( fn is_maybe_cjs(
@ -731,9 +732,12 @@ pub async fn run(data: StandaloneData) -> Result<i32, AnyError> {
let cjs_tracker = Arc::new(CjsTracker::new( let cjs_tracker = Arc::new(CjsTracker::new(
in_npm_pkg_checker.clone(), in_npm_pkg_checker.clone(),
pkg_json_resolver.clone(), pkg_json_resolver.clone(),
IsCjsResolverOptions { if metadata.unstable_config.detect_cjs {
detect_cjs: !metadata.workspace_resolver.package_jsons.is_empty(), IsCjsResolutionMode::ImplicitTypeCommonJs
is_node_main: false, } else if metadata.workspace_resolver.package_jsons.is_empty() {
IsCjsResolutionMode::Disabled
} else {
IsCjsResolutionMode::ExplicitTypeCommonJs
}, },
)); ));
let cache_db = Caches::new(deno_dir_provider.clone()); let cache_db = Caches::new(deno_dir_provider.clone());

View file

@ -329,7 +329,7 @@ impl VfsBuilder {
let dir = self.add_dir(path.parent().unwrap())?; let dir = self.add_dir(path.parent().unwrap())?;
let name = path.file_name().unwrap().to_string_lossy(); let name = path.file_name().unwrap().to_string_lossy();
match dir.entries.binary_search_by(|e| e.name().cmp(&name)) { match dir.entries.binary_search_by(|e| e.name().cmp(&name)) {
Ok(_) => unreachable!(), Ok(_) => Ok(()), // previously inserted
Err(insert_index) => { Err(insert_index) => {
dir.entries.insert( dir.entries.insert(
insert_index, insert_index,
@ -341,9 +341,9 @@ impl VfsBuilder {
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
}), }),
); );
Ok(())
} }
} }
Ok(())
} }
pub fn into_dir_and_files(self) -> (VirtualDirectory, Vec<Vec<u8>>) { pub fn into_dir_and_files(self) -> (VirtualDirectory, Vec<Vec<u8>>) {
@ -743,15 +743,12 @@ impl deno_io::fs::File for FileBackedVfsFile {
Err(FsError::NotSupported) Err(FsError::NotSupported)
} }
fn read_all_sync(self: Rc<Self>) -> FsResult<Vec<u8>> { fn read_all_sync(self: Rc<Self>) -> FsResult<Cow<'static, [u8]>> {
self.read_to_end().map(|bytes| bytes.into_owned()) self.read_to_end()
} }
async fn read_all_async(self: Rc<Self>) -> FsResult<Vec<u8>> { async fn read_all_async(self: Rc<Self>) -> FsResult<Cow<'static, [u8]>> {
let inner = (*self).clone(); let inner = (*self).clone();
tokio::task::spawn_blocking(move || { tokio::task::spawn_blocking(move || inner.read_to_end()).await?
inner.read_to_end().map(|bytes| bytes.into_owned())
})
.await?
} }
fn chmod_sync(self: Rc<Self>, _pathmode: u32) -> FsResult<()> { fn chmod_sync(self: Rc<Self>, _pathmode: u32) -> FsResult<()> {

View file

@ -209,10 +209,14 @@ pub async fn doc(
Default::default() Default::default()
}; };
let mut main_entrypoint = None;
let rewrite_map = let rewrite_map =
if let Some(config_file) = cli_options.start_dir.maybe_deno_json() { if let Some(config_file) = cli_options.start_dir.maybe_deno_json() {
let config = config_file.to_exports_config()?; let config = config_file.to_exports_config()?;
main_entrypoint = config.get_resolved(".").ok().flatten();
let rewrite_map = config let rewrite_map = config
.clone() .clone()
.into_map() .into_map()
@ -240,6 +244,7 @@ pub async fn doc(
html_options, html_options,
deno_ns, deno_ns,
rewrite_map, rewrite_map,
main_entrypoint,
) )
} else { } else {
let modules_len = doc_nodes_by_url.len(); let modules_len = doc_nodes_by_url.len();
@ -383,6 +388,7 @@ fn generate_docs_directory(
html_options: &DocHtmlFlag, html_options: &DocHtmlFlag,
deno_ns: std::collections::HashMap<Vec<String>, Option<Rc<ShortPath>>>, deno_ns: std::collections::HashMap<Vec<String>, Option<Rc<ShortPath>>>,
rewrite_map: Option<IndexMap<ModuleSpecifier, String>>, rewrite_map: Option<IndexMap<ModuleSpecifier, String>>,
main_entrypoint: Option<ModuleSpecifier>,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
let cwd = std::env::current_dir().context("Failed to get CWD")?; let cwd = std::env::current_dir().context("Failed to get CWD")?;
let output_dir_resolved = cwd.join(&html_options.output); let output_dir_resolved = cwd.join(&html_options.output);
@ -415,7 +421,7 @@ fn generate_docs_directory(
let options = deno_doc::html::GenerateOptions { let options = deno_doc::html::GenerateOptions {
package_name: html_options.name.clone(), package_name: html_options.name.clone(),
main_entrypoint: None, main_entrypoint,
rewrite_map, rewrite_map,
href_resolver: Rc::new(DocResolver { href_resolver: Rc::new(DocResolver {
deno_ns, deno_ns,
@ -427,33 +433,7 @@ fn generate_docs_directory(
symbol_redirect_map, symbol_redirect_map,
default_symbol_map, default_symbol_map,
markdown_renderer: deno_doc::html::comrak::create_renderer( markdown_renderer: deno_doc::html::comrak::create_renderer(
None, None, None, 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,
), ),
markdown_stripper: Rc::new(deno_doc::html::comrak::strip), markdown_stripper: Rc::new(deno_doc::html::comrak::strip),
head_inject: Some(Rc::new(|root| { head_inject: Some(Rc::new(|root| {

View file

@ -49,19 +49,67 @@ pub async fn info(
let module_graph_creator = factory.module_graph_creator().await?; let module_graph_creator = factory.module_graph_creator().await?;
let npm_resolver = factory.npm_resolver().await?; let npm_resolver = factory.npm_resolver().await?;
let maybe_lockfile = cli_options.maybe_lockfile(); let maybe_lockfile = cli_options.maybe_lockfile();
let resolver = factory.workspace_resolver().await?.clone();
let npmrc = cli_options.npmrc(); let npmrc = cli_options.npmrc();
let resolver = factory.workspace_resolver().await?; let node_resolver = factory.node_resolver().await?;
let cwd_url = let cwd_url =
url::Url::from_directory_path(cli_options.initial_cwd()).unwrap(); url::Url::from_directory_path(cli_options.initial_cwd()).unwrap();
let maybe_import_specifier = if let Some(import_map) = let maybe_import_specifier = if let Ok(resolved) =
resolver.maybe_import_map() resolver.resolve(&specifier, &cwd_url)
{ {
if let Ok(imports_specifier) = import_map.resolve(&specifier, &cwd_url) { match resolved {
Some(imports_specifier) deno_config::workspace::MappedResolution::Normal {
} else { specifier, ..
None }
| deno_config::workspace::MappedResolution::ImportMap {
specifier,
..
}
| deno_config::workspace::MappedResolution::WorkspaceJsrPackage {
specifier,
..
} => Some(specifier),
deno_config::workspace::MappedResolution::WorkspaceNpmPackage {
target_pkg_json,
sub_path,
..
} => Some(node_resolver.resolve_package_subpath_from_deno_module(
target_pkg_json.clone().dir_path(),
sub_path.as_deref(),
Some(&cwd_url),
node_resolver::ResolutionMode::Import,
node_resolver::NodeResolutionKind::Execution,
)?),
deno_config::workspace::MappedResolution::PackageJson {
alias,
sub_path,
dep_result,
..
} => match dep_result.as_ref().map_err(|e| e.clone())? {
deno_package_json::PackageJsonDepValue::Workspace(version_req) => {
let pkg_folder = resolver
.resolve_workspace_pkg_json_folder_for_pkg_json_dep(
alias,
version_req,
)?;
Some(node_resolver.resolve_package_subpath_from_deno_module(
pkg_folder,
sub_path.as_deref(),
Some(&cwd_url),
node_resolver::ResolutionMode::Import,
node_resolver::NodeResolutionKind::Execution,
)?)
}
deno_package_json::PackageJsonDepValue::Req(req) => {
Some(ModuleSpecifier::parse(&format!(
"npm:{}{}",
req,
sub_path.map(|s| format!("/{}", s)).unwrap_or_default()
))?)
}
},
} }
} else { } else {
None None
@ -235,22 +283,31 @@ fn add_npm_packages_to_json(
.get_mut("dependencies") .get_mut("dependencies")
.and_then(|d| d.as_array_mut()); .and_then(|d| d.as_array_mut());
if let Some(dependencies) = dependencies { if let Some(dependencies) = dependencies {
for dep in dependencies.iter_mut() { for dep in dependencies.iter_mut().flat_map(|d| d.as_object_mut()) {
if let serde_json::Value::Object(dep) = dep { if let Some(specifier) = dep.get("specifier").and_then(|s| s.as_str())
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(npm_ref) = NpmPackageReqReference::from_str(specifier) { if let Ok(pkg) = snapshot.resolve_pkg_from_pkg_req(npm_ref.req())
if let Ok(pkg) = {
snapshot.resolve_pkg_from_pkg_req(npm_ref.req()) dep.insert(
{ "npmPackage".to_string(),
dep.insert( pkg.id.as_serialized().into(),
"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");
}
} }
} }
} }

View file

@ -252,8 +252,46 @@ Deno.test(function addTest() {
Ok(0) Ok(0)
} }
fn npm_name_to_create_package(name: &str) -> String {
let mut s = "npm:".to_string();
let mut scoped = false;
let mut create = false;
for (i, ch) in name.char_indices() {
if i == 0 {
if ch == '@' {
scoped = true;
} else {
create = true;
s.push_str("create-");
}
} else if scoped {
if ch == '/' {
scoped = false;
create = true;
s.push_str("/create-");
continue;
} else if ch == '@' && !create {
scoped = false;
create = true;
s.push_str("/create@");
continue;
}
}
s.push(ch);
}
if !create {
s.push_str("/create");
}
s
}
async fn init_npm(name: &str, args: Vec<String>) -> Result<i32, AnyError> { async fn init_npm(name: &str, args: Vec<String>) -> Result<i32, AnyError> {
let script_name = format!("npm:create-{}", name); let script_name = npm_name_to_create_package(name);
fn print_manual_usage(script_name: &str, args: &[String]) -> i32 { fn print_manual_usage(script_name: &str, args: &[String]) -> i32 {
log::info!("{}", cformat!("You can initialize project manually by running <u>deno run {} {}</> and applying desired permissions.", script_name, args.join(" "))); log::info!("{}", cformat!("You can initialize project manually by running <u>deno run {} {}</> and applying desired permissions.", script_name, args.join(" ")));
@ -336,3 +374,37 @@ fn create_file(
Ok(()) Ok(())
} }
} }
#[cfg(test)]
mod test {
use crate::tools::init::npm_name_to_create_package;
#[test]
fn npm_name_to_create_package_test() {
// See https://docs.npmjs.com/cli/v8/commands/npm-init#description
assert_eq!(
npm_name_to_create_package("foo"),
"npm:create-foo".to_string()
);
assert_eq!(
npm_name_to_create_package("foo@1.0.0"),
"npm:create-foo@1.0.0".to_string()
);
assert_eq!(
npm_name_to_create_package("@foo"),
"npm:@foo/create".to_string()
);
assert_eq!(
npm_name_to_create_package("@foo@1.0.0"),
"npm:@foo/create@1.0.0".to_string()
);
assert_eq!(
npm_name_to_create_package("@foo/bar"),
"npm:@foo/create-bar".to_string()
);
assert_eq!(
npm_name_to_create_package("@foo/bar@1.0.0"),
"npm:@foo/create-bar@1.0.0".to_string()
);
}
}

View file

@ -8,7 +8,7 @@ use std::sync::Arc;
use deno_ast::SourceRange; use deno_ast::SourceRange;
use deno_config::workspace::WorkspaceResolver; use deno_config::workspace::WorkspaceResolver;
use deno_core::anyhow::anyhow; use deno_core::anyhow::anyhow;
use deno_graph::source::ResolutionMode; use deno_graph::source::ResolutionKind;
use deno_graph::source::ResolveError; use deno_graph::source::ResolveError;
use deno_graph::Range; use deno_graph::Range;
use deno_lint::diagnostic::LintDiagnosticDetails; use deno_lint::diagnostic::LintDiagnosticDetails;
@ -17,7 +17,7 @@ use deno_lint::diagnostic::LintFix;
use deno_lint::diagnostic::LintFixChange; use deno_lint::diagnostic::LintFixChange;
use deno_lint::rules::LintRule; use deno_lint::rules::LintRule;
use deno_resolver::sloppy_imports::SloppyImportsResolution; use deno_resolver::sloppy_imports::SloppyImportsResolution;
use deno_resolver::sloppy_imports::SloppyImportsResolutionMode; use deno_resolver::sloppy_imports::SloppyImportsResolutionKind;
use text_lines::LineAndColumnIndex; use text_lines::LineAndColumnIndex;
use crate::graph_util::CliJsrUrlProvider; use crate::graph_util::CliJsrUrlProvider;
@ -101,16 +101,16 @@ impl LintRule for NoSloppyImportsRule {
maybe_npm_resolver: None, 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 = let start_range =
context.text_info().loc_to_source_pos(LineAndColumnIndex { context.text_info().loc_to_source_pos(LineAndColumnIndex {
line_index: range.start.line, line_index: referrer.range.start.line,
column_index: range.start.character, column_index: referrer.range.start.character,
}); });
let end_range = let end_range =
context.text_info().loc_to_source_pos(LineAndColumnIndex { context.text_info().loc_to_source_pos(LineAndColumnIndex {
line_index: range.end.line, line_index: referrer.range.end.line,
column_index: range.end.character, column_index: referrer.range.end.character,
}); });
let source_range = SourceRange::new(start_range, end_range); let source_range = SourceRange::new(start_range, end_range);
context.add_diagnostic_details( context.add_diagnostic_details(
@ -183,7 +183,7 @@ impl<'a> deno_graph::source::Resolver for SloppyImportCaptureResolver<'a> {
&self, &self,
specifier_text: &str, specifier_text: &str,
referrer_range: &Range, referrer_range: &Range,
mode: ResolutionMode, resolution_kind: ResolutionKind,
) -> Result<deno_ast::ModuleSpecifier, deno_graph::source::ResolveError> { ) -> Result<deno_ast::ModuleSpecifier, deno_graph::source::ResolveError> {
let resolution = self let resolution = self
.workspace_resolver .workspace_resolver
@ -198,9 +198,9 @@ impl<'a> deno_graph::source::Resolver for SloppyImportCaptureResolver<'a> {
specifier, .. specifier, ..
} => match self.sloppy_imports_resolver.resolve( } => match self.sloppy_imports_resolver.resolve(
&specifier, &specifier,
match mode { match resolution_kind {
ResolutionMode::Execution => SloppyImportsResolutionMode::Execution, ResolutionKind::Execution => SloppyImportsResolutionKind::Execution,
ResolutionMode::Types => SloppyImportsResolutionMode::Types, ResolutionKind::Types => SloppyImportsResolutionKind::Types,
}, },
) { ) {
Some(res) => { Some(res) => {

View file

@ -234,8 +234,8 @@ impl Diagnostic for PublishDiagnostic {
specifier: Cow::Borrowed(&referrer.specifier), specifier: Cow::Borrowed(&referrer.specifier),
text_info: Cow::Borrowed(text_info), text_info: Cow::Borrowed(text_info),
source_pos: DiagnosticSourcePos::LineAndCol { source_pos: DiagnosticSourcePos::LineAndCol {
line: referrer.start.line, line: referrer.range.start.line,
column: referrer.start.character, column: referrer.range.start.character,
}, },
} }
} }
@ -300,7 +300,7 @@ impl Diagnostic for PublishDiagnostic {
text_info: &'a SourceTextInfo, text_info: &'a SourceTextInfo,
referrer: &'a deno_graph::Range, referrer: &'a deno_graph::Range,
) -> Option<DiagnosticSnippet<'a>> { ) -> 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 return None; // no range, probably a jsxImportSource import
} }
@ -310,12 +310,12 @@ impl Diagnostic for PublishDiagnostic {
style: DiagnosticSnippetHighlightStyle::Error, style: DiagnosticSnippetHighlightStyle::Error,
range: DiagnosticSourceRange { range: DiagnosticSourceRange {
start: DiagnosticSourcePos::LineAndCol { start: DiagnosticSourcePos::LineAndCol {
line: referrer.start.line, line: referrer.range.start.line,
column: referrer.start.character, column: referrer.range.start.character,
}, },
end: DiagnosticSourcePos::LineAndCol { end: DiagnosticSourcePos::LineAndCol {
line: referrer.end.line, line: referrer.range.end.line,
column: referrer.end.character, column: referrer.range.end.character,
}, },
}, },
description: Some("the specifier".into()), description: Some("the specifier".into()),
@ -476,7 +476,7 @@ impl Diagnostic for PublishDiagnostic {
InvalidExternalImport { imported, .. } => Cow::Owned(vec![ InvalidExternalImport { imported, .. } => Cow::Owned(vec![
Cow::Owned(format!("the import was resolved to '{}'", imported)), Cow::Owned(format!("the import was resolved to '{}'", imported)),
Cow::Borrowed("this specifier is not allowed to be imported on jsr"), Cow::Borrowed("this specifier is not allowed to be imported on jsr"),
Cow::Borrowed("jsr only supports importing `jsr:`, `npm:`, and `data:` specifiers"), Cow::Borrowed("jsr only supports importing `jsr:`, `npm:`, `data:`, `bun:`, and `node:` specifiers"),
]), ]),
UnsupportedJsxTsx { .. } => Cow::Owned(vec![ UnsupportedJsxTsx { .. } => Cow::Owned(vec![
Cow::Borrowed("follow https://github.com/jsr-io/jsr/issues/24 for updates"), Cow::Borrowed("follow https://github.com/jsr-io/jsr/issues/24 for updates"),

View file

@ -47,7 +47,7 @@ impl GraphDiagnosticsCollector {
resolution: &ResolutionResolved| { resolution: &ResolutionResolved| {
if visited.insert(resolution.specifier.clone()) { if visited.insert(resolution.specifier.clone()) {
match resolution.specifier.scheme() { match resolution.specifier.scheme() {
"file" | "data" | "node" => {} "file" | "data" | "node" | "bun" => {}
"jsr" => { "jsr" => {
skip_specifiers.insert(resolution.specifier.clone()); skip_specifiers.insert(resolution.specifier.clone());

View file

@ -97,11 +97,10 @@ pub async fn publish(
match cli_options.start_dir.maybe_deno_json() { match cli_options.start_dir.maybe_deno_json() {
Some(deno_json) => { Some(deno_json) => {
debug_assert!(!deno_json.is_package()); debug_assert!(!deno_json.is_package());
if deno_json.json.name.is_none() {
bail!("Missing 'name' field in '{}'.", deno_json.specifier);
}
error_missing_exports_field(deno_json)?; error_missing_exports_field(deno_json)?;
bail!(
"Missing 'name' or 'exports' field in '{}'.",
deno_json.specifier
);
} }
None => { None => {
bail!( bail!(

View file

@ -12,7 +12,7 @@ use deno_graph::DynamicTemplatePart;
use deno_graph::ParserModuleAnalyzer; use deno_graph::ParserModuleAnalyzer;
use deno_graph::TypeScriptReference; use deno_graph::TypeScriptReference;
use deno_package_json::PackageJsonDepValue; 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 deno_runtime::deno_node::is_builtin_node_module;
use crate::resolver::CliSloppyImportsResolver; use crate::resolver::CliSloppyImportsResolver;
@ -180,7 +180,7 @@ impl SpecifierUnfurler {
let resolved = let resolved =
if let Some(sloppy_imports_resolver) = &self.sloppy_imports_resolver { if let Some(sloppy_imports_resolver) = &self.sloppy_imports_resolver {
sloppy_imports_resolver sloppy_imports_resolver
.resolve(&resolved, SloppyImportsResolutionMode::Execution) .resolve(&resolved, SloppyImportsResolutionKind::Execution)
.map(|res| res.into_specifier()) .map(|res| res.into_specifier())
.unwrap_or(resolved) .unwrap_or(resolved)
} else { } else {
@ -319,8 +319,8 @@ impl SpecifierUnfurler {
} }
for ts_ref in &module_info.ts_references { for ts_ref in &module_info.ts_references {
let specifier_with_range = match ts_ref { let specifier_with_range = match ts_ref {
TypeScriptReference::Path(range) => range, TypeScriptReference::Path(s) => s,
TypeScriptReference::Types(range) => range, TypeScriptReference::Types { specifier, .. } => specifier,
}; };
analyze_specifier( analyze_specifier(
&specifier_with_range.text, &specifier_with_range.text,
@ -328,10 +328,10 @@ impl SpecifierUnfurler {
&mut text_changes, &mut text_changes,
); );
} }
for specifier_with_range in &module_info.jsdoc_imports { for jsdoc in &module_info.jsdoc_imports {
analyze_specifier( analyze_specifier(
&specifier_with_range.text, &jsdoc.specifier.text,
&specifier_with_range.range, &jsdoc.specifier.range,
&mut text_changes, &mut text_changes,
); );
} }

View file

@ -43,13 +43,13 @@ use deno_core::unsync::spawn;
use deno_core::url::Url; use deno_core::url::Url;
use deno_core::LocalInspectorSession; use deno_core::LocalInspectorSession;
use deno_core::PollEventLoopOptions; use deno_core::PollEventLoopOptions;
use deno_graph::source::ResolutionMode;
use deno_graph::Position; use deno_graph::Position;
use deno_graph::PositionRange; use deno_graph::PositionRange;
use deno_graph::SpecifierWithRange; use deno_graph::SpecifierWithRange;
use deno_runtime::worker::MainWorker; use deno_runtime::worker::MainWorker;
use deno_semver::npm::NpmPackageReqReference; use deno_semver::npm::NpmPackageReqReference;
use node_resolver::NodeModuleKind; use node_resolver::NodeResolutionKind;
use node_resolver::ResolutionMode;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use regex::Match; use regex::Match;
use regex::Regex; use regex::Regex;
@ -701,11 +701,6 @@ impl ReplSession {
let mut collector = ImportCollector::new(); let mut collector = ImportCollector::new();
program.visit_with(&mut collector); 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 let resolved_imports = collector
.imports .imports
.iter() .iter()
@ -714,9 +709,10 @@ impl ReplSession {
.resolver .resolver
.resolve( .resolve(
i, i,
&referrer_range, &self.referrer,
NodeModuleKind::Esm, deno_graph::Position::zeroed(),
ResolutionMode::Execution, ResolutionMode::Import,
NodeResolutionKind::Execution,
) )
.ok() .ok()
.or_else(|| ModuleSpecifier::parse(i).ok()) .or_else(|| ModuleSpecifier::parse(i).ok())

View file

@ -8,6 +8,7 @@ use std::path::PathBuf;
use std::rc::Rc; use std::rc::Rc;
use std::sync::Arc; use std::sync::Arc;
use console_static_text::ansi::strip_ansi_codes;
use deno_config::workspace::FolderConfigs; use deno_config::workspace::FolderConfigs;
use deno_config::workspace::TaskDefinition; use deno_config::workspace::TaskDefinition;
use deno_config::workspace::TaskOrScript; use deno_config::workspace::TaskOrScript;
@ -721,22 +722,48 @@ fn print_available_tasks(
)?; )?;
if let Some(description) = &desc.task.description { if let Some(description) = &desc.task.description {
let slash_slash = colors::italic_gray("//"); let slash_slash = colors::italic_gray("//");
writeln!( for line in description.lines() {
writer, writeln!(
" {slash_slash} {}", writer,
colors::italic_gray(description) " {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() { 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!( writeln!(
writer, writer,
" {} {}", " {} {}",
colors::gray("depends on:"), colors::gray("depends on:"),
colors::cyan(desc.task.dependencies.join(", ")) colors::cyan(dependencies)
)?; )?;
} }
} }
Ok(()) 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()
}

View file

@ -681,14 +681,18 @@ delete Object.prototype.__proto__;
getNewLine() { getNewLine() {
return "\n"; return "\n";
}, },
resolveTypeReferenceDirectives( resolveTypeReferenceDirectiveReferences(
typeDirectiveNames, typeDirectiveReferences,
containingFilePath, containingFilePath,
redirectedReference, redirectedReference,
options, 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} */ /** @type {ts.FileReference} */
const fileReference = typeof arg === "string" const fileReference = typeof arg === "string"
? { ? {
@ -701,16 +705,28 @@ delete Object.prototype.__proto__;
/** @type {[string, ts.Extension] | undefined} */ /** @type {[string, ts.Extension] | undefined} */
const resolved = ops.op_resolve( const resolved = ops.op_resolve(
containingFilePath, containingFilePath,
containingFileMode === ts.ModuleKind.CommonJS, [
[fileReference.fileName], [
fileReference.resolutionMode == null
? isCjs
: fileReference.resolutionMode === ts.ModuleKind.CommonJS,
fileReference.fileName,
],
],
)?.[0]; )?.[0];
if (resolved) { if (resolved) {
return { return {
primary: true, resolvedTypeReferenceDirective: {
resolvedFileName: resolved[0], primary: true,
resolvedFileName: resolved[0],
// todo(dsherret): we should probably be setting this
isExternalLibraryImport: undefined,
},
}; };
} else { } else {
return undefined; return {
resolvedTypeReferenceDirective: undefined,
};
} }
} else { } else {
return ts.resolveTypeReferenceDirective( return ts.resolveTypeReferenceDirective(
@ -720,41 +736,56 @@ delete Object.prototype.__proto__;
host, host,
redirectedReference, redirectedReference,
undefined, undefined,
containingFileMode ?? fileReference.resolutionMode, containingSourceFile?.impliedNodeFormat ??
).resolvedTypeReferenceDirective; fileReference.resolutionMode,
);
} }
}); });
return result;
}, },
resolveModuleNames( resolveModuleNameLiterals(
specifiers, moduleLiterals,
base, base,
_reusedNames,
_redirectedReference, _redirectedReference,
_options, compilerOptions,
containingSourceFile, containingSourceFile,
_reusedNames,
) { ) {
const specifiers = moduleLiterals.map((literal) => [
ts.getModeForUsageLocation(
containingSourceFile,
literal,
compilerOptions,
) === ts.ModuleKind.CommonJS,
literal.text,
]);
if (logDebug) { if (logDebug) {
debug(`host.resolveModuleNames()`); debug(`host.resolveModuleNames()`);
debug(` base: ${base}`); debug(` base: ${base}`);
debug(` specifiers: ${specifiers.join(", ")}`); debug(` specifiers: ${specifiers.map((s) => s[1]).join(", ")}`);
} }
/** @type {Array<[string, ts.Extension] | undefined>} */ /** @type {Array<[string, ts.Extension] | undefined>} */
const resolved = ops.op_resolve( const resolved = ops.op_resolve(
base, base,
containingSourceFile?.impliedNodeFormat === ts.ModuleKind.CommonJS,
specifiers, specifiers,
); );
if (resolved) { if (resolved) {
/** @type {Array<ts.ResolvedModuleWithFailedLookupLocations>} */
const result = resolved.map((item) => { const result = resolved.map((item) => {
if (item) { if (item) {
const [resolvedFileName, extension] = item; const [resolvedFileName, extension] = item;
return { return {
resolvedFileName, resolvedModule: {
extension, resolvedFileName,
isExternalLibraryImport: false, extension,
// todo(dsherret): we should probably be setting this
isExternalLibraryImport: false,
},
}; };
} }
return undefined; return {
resolvedModule: undefined,
};
}); });
result.length = specifiers.length; result.length = specifiers.length;
return result; return result;

View file

@ -18277,7 +18277,7 @@ declare var ReadableStream: {
new(underlyingSource: UnderlyingByteSource, strategy?: { highWaterMark?: number }): ReadableStream<Uint8Array>; new(underlyingSource: UnderlyingByteSource, strategy?: { highWaterMark?: number }): ReadableStream<Uint8Array>;
new<R = any>(underlyingSource: UnderlyingDefaultSource<R>, strategy?: QueuingStrategy<R>): ReadableStream<R>; new<R = any>(underlyingSource: UnderlyingDefaultSource<R>, strategy?: QueuingStrategy<R>): ReadableStream<R>;
new<R = any>(underlyingSource?: UnderlyingSource<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) */ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader) */

View file

@ -41,8 +41,8 @@ use deno_semver::npm::NpmPackageReqReference;
use node_resolver::errors::NodeJsErrorCode; use node_resolver::errors::NodeJsErrorCode;
use node_resolver::errors::NodeJsErrorCoded; use node_resolver::errors::NodeJsErrorCoded;
use node_resolver::errors::PackageSubpathResolveError; use node_resolver::errors::PackageSubpathResolveError;
use node_resolver::NodeModuleKind; use node_resolver::NodeResolutionKind;
use node_resolver::NodeResolutionMode; use node_resolver::ResolutionMode;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use std::borrow::Cow; use std::borrow::Cow;
use std::collections::HashMap; use std::collections::HashMap;
@ -656,17 +656,21 @@ fn op_load_inner(
} }
Module::Npm(_) | Module::Node(_) => None, Module::Npm(_) | Module::Node(_) => None,
Module::External(module) => { Module::External(module) => {
// means it's Deno code importing an npm module if module.specifier.scheme() != "file" {
let specifier = node::resolve_specifier_into_node_modules( None
&module.specifier, } else {
&deno_fs::RealFs, // means it's Deno code importing an npm module
); let specifier = node::resolve_specifier_into_node_modules(
Some(Cow::Owned(load_from_node_modules( &module.specifier,
&specifier, &deno_fs::RealFs,
state.maybe_npm.as_ref(), );
&mut media_type, Some(Cow::Owned(load_from_node_modules(
&mut is_cjs, &specifier,
)?)) state.maybe_npm.as_ref(),
&mut media_type,
&mut is_cjs,
)?))
}
} }
} }
} else if let Some(npm) = state } else if let Some(npm) = state
@ -703,10 +707,9 @@ pub struct ResolveArgs {
/// The base specifier that the supplied specifier strings should be resolved /// The base specifier that the supplied specifier strings should be resolved
/// relative to. /// relative to.
pub base: String, pub base: String,
/// If the base is cjs.
pub is_base_cjs: bool,
/// A list of specifiers that should be resolved. /// A list of specifiers that should be resolved.
pub specifiers: Vec<String>, /// (is_cjs: bool, raw_specifier: String)
pub specifiers: Vec<(bool, String)>,
} }
#[op2] #[op2]
@ -714,17 +717,9 @@ pub struct ResolveArgs {
fn op_resolve( fn op_resolve(
state: &mut OpState, state: &mut OpState,
#[string] base: String, #[string] base: String,
is_base_cjs: bool, #[serde] specifiers: Vec<(bool, String)>,
#[serde] specifiers: Vec<String>,
) -> Result<Vec<(String, &'static str)>, AnyError> { ) -> Result<Vec<(String, &'static str)>, AnyError> {
op_resolve_inner( op_resolve_inner(state, ResolveArgs { base, specifiers })
state,
ResolveArgs {
base,
is_base_cjs,
specifiers,
},
)
} }
#[inline] #[inline]
@ -735,11 +730,6 @@ fn op_resolve_inner(
let state = state.borrow_mut::<State>(); let state = state.borrow_mut::<State>();
let mut resolved: Vec<(String, &'static str)> = let mut resolved: Vec<(String, &'static str)> =
Vec::with_capacity(args.specifiers.len()); 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) = let referrer = if let Some(remapped_specifier) =
state.remapped_specifiers.get(&args.base) state.remapped_specifiers.get(&args.base)
{ {
@ -752,7 +742,7 @@ fn op_resolve_inner(
)? )?
}; };
let referrer_module = state.graph.get(&referrer); let referrer_module = state.graph.get(&referrer);
for specifier in args.specifiers { for (is_cjs, specifier) in args.specifiers {
if specifier.starts_with("node:") { if specifier.starts_with("node:") {
resolved.push(( resolved.push((
MISSING_DEPENDENCY_SPECIFIER.to_string(), MISSING_DEPENDENCY_SPECIFIER.to_string(),
@ -771,13 +761,20 @@ fn op_resolve_inner(
.and_then(|m| m.js()) .and_then(|m| m.js())
.and_then(|m| m.dependencies_prefer_fast_check().get(&specifier)) .and_then(|m| m.dependencies_prefer_fast_check().get(&specifier))
.and_then(|d| d.maybe_type.ok().or_else(|| d.maybe_code.ok())); .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 { let maybe_result = match resolved_dep {
Some(ResolutionResolved { specifier, .. }) => { Some(ResolutionResolved { specifier, .. }) => {
resolve_graph_specifier_types( resolve_graph_specifier_types(
specifier, specifier,
&referrer, &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, state,
)? )?
} }
@ -785,7 +782,7 @@ fn op_resolve_inner(
match resolve_non_graph_specifier_types( match resolve_non_graph_specifier_types(
&specifier, &specifier,
&referrer, &referrer,
referrer_kind, resolution_mode,
state, state,
) { ) {
Ok(maybe_result) => maybe_result, Ok(maybe_result) => maybe_result,
@ -852,7 +849,7 @@ fn op_resolve_inner(
fn resolve_graph_specifier_types( fn resolve_graph_specifier_types(
specifier: &ModuleSpecifier, specifier: &ModuleSpecifier,
referrer: &ModuleSpecifier, referrer: &ModuleSpecifier,
referrer_kind: NodeModuleKind, resolution_mode: ResolutionMode,
state: &State, state: &State,
) -> Result<Option<(ModuleSpecifier, MediaType)>, AnyError> { ) -> Result<Option<(ModuleSpecifier, MediaType)>, AnyError> {
let graph = &state.graph; let graph = &state.graph;
@ -908,8 +905,8 @@ fn resolve_graph_specifier_types(
&package_folder, &package_folder,
module.nv_reference.sub_path(), module.nv_reference.sub_path(),
Some(referrer), Some(referrer),
referrer_kind, resolution_mode,
NodeResolutionMode::Types, NodeResolutionKind::Types,
); );
let maybe_url = match res_result { let maybe_url = match res_result {
Ok(url) => Some(url), Ok(url) => Some(url),
@ -949,7 +946,7 @@ enum ResolveNonGraphSpecifierTypesError {
fn resolve_non_graph_specifier_types( fn resolve_non_graph_specifier_types(
raw_specifier: &str, raw_specifier: &str,
referrer: &ModuleSpecifier, referrer: &ModuleSpecifier,
referrer_kind: NodeModuleKind, resolution_mode: ResolutionMode,
state: &State, state: &State,
) -> Result< ) -> Result<
Option<(ModuleSpecifier, MediaType)>, Option<(ModuleSpecifier, MediaType)>,
@ -967,8 +964,8 @@ fn resolve_non_graph_specifier_types(
.resolve( .resolve(
raw_specifier, raw_specifier,
referrer, referrer,
referrer_kind, resolution_mode,
NodeResolutionMode::Types, NodeResolutionKind::Types,
) )
.ok() .ok()
.map(|res| res.into_url()), .map(|res| res.into_url()),
@ -976,7 +973,7 @@ fn resolve_non_graph_specifier_types(
} else if let Ok(npm_req_ref) = } else if let Ok(npm_req_ref) =
NpmPackageReqReference::from_str(raw_specifier) 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 // todo(dsherret): add support for injecting this in the graph so
// we don't need this special code here. // we don't need this special code here.
// This could occur when resolving npm:@types/node when it is // This could occur when resolving npm:@types/node when it is
@ -988,8 +985,8 @@ fn resolve_non_graph_specifier_types(
&package_folder, &package_folder,
npm_req_ref.sub_path(), npm_req_ref.sub_path(),
Some(referrer), Some(referrer),
referrer_kind, resolution_mode,
NodeResolutionMode::Types, NodeResolutionKind::Types,
); );
let maybe_url = match res_result { let maybe_url = match res_result {
Ok(url) => Some(url), Ok(url) => Some(url),
@ -1388,8 +1385,7 @@ mod tests {
&mut state, &mut state,
ResolveArgs { ResolveArgs {
base: "https://deno.land/x/a.ts".to_string(), base: "https://deno.land/x/a.ts".to_string(),
is_base_cjs: false, specifiers: vec![(false, "./b.ts".to_string())],
specifiers: vec!["./b.ts".to_string()],
}, },
) )
.expect("should have invoked op"); .expect("should have invoked op");
@ -1408,8 +1404,7 @@ mod tests {
&mut state, &mut state,
ResolveArgs { ResolveArgs {
base: "https://deno.land/x/a.ts".to_string(), base: "https://deno.land/x/a.ts".to_string(),
is_base_cjs: false, specifiers: vec![(false, "./bad.ts".to_string())],
specifiers: vec!["./bad.ts".to_string()],
}, },
) )
.expect("should have not errored"); .expect("should have not errored");

View file

@ -659,7 +659,7 @@ impl LaxSingleProcessFsFlag {
// //
// This uses a blocking task because we use a single threaded // 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 // 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({ spawn_blocking({
let token = token.clone(); let token = token.clone();
let last_updated_path = last_updated_path.clone(); let last_updated_path = last_updated_path.clone();

View file

@ -29,7 +29,7 @@ impl log::Log for CliLogger {
// thread's state // thread's state
DrawThread::hide(); DrawThread::hide();
self.0.log(record); self.0.log(record);
deno_runtime::ops::otel::handle_log(record); deno_telemetry::handle_log(record);
DrawThread::show(); DrawThread::show();
} }
} }

View file

@ -11,6 +11,15 @@ use deno_core::ModuleSourceCode;
static SOURCE_MAP_PREFIX: &[u8] = static SOURCE_MAP_PREFIX: &[u8] =
b"//# sourceMappingURL=data:application/json;base64,"; b"//# sourceMappingURL=data:application/json;base64,";
#[inline(always)]
pub fn from_utf8_lossy_cow(bytes: Cow<[u8]>) -> Cow<str> {
match bytes {
Cow::Borrowed(bytes) => String::from_utf8_lossy(bytes),
Cow::Owned(bytes) => Cow::Owned(from_utf8_lossy_owned(bytes)),
}
}
#[inline(always)]
pub fn from_utf8_lossy_owned(bytes: Vec<u8>) -> String { pub fn from_utf8_lossy_owned(bytes: Vec<u8>) -> String {
match String::from_utf8_lossy(&bytes) { match String::from_utf8_lossy(&bytes) {
Cow::Owned(code) => code, Cow::Owned(code) => code,

View file

@ -30,7 +30,6 @@ use deno_runtime::deno_tls::RootCertStoreProvider;
use deno_runtime::deno_web::BlobStore; use deno_runtime::deno_web::BlobStore;
use deno_runtime::fmt_errors::format_js_error; use deno_runtime::fmt_errors::format_js_error;
use deno_runtime::inspector_server::InspectorServer; use deno_runtime::inspector_server::InspectorServer;
use deno_runtime::ops::otel::OtelConfig;
use deno_runtime::ops::process::NpmProcessStateProviderRc; use deno_runtime::ops::process::NpmProcessStateProviderRc;
use deno_runtime::ops::worker_host::CreateWebWorkerCb; use deno_runtime::ops::worker_host::CreateWebWorkerCb;
use deno_runtime::web_worker::WebWorker; use deno_runtime::web_worker::WebWorker;
@ -43,9 +42,10 @@ use deno_runtime::BootstrapOptions;
use deno_runtime::WorkerExecutionMode; use deno_runtime::WorkerExecutionMode;
use deno_runtime::WorkerLogLevel; use deno_runtime::WorkerLogLevel;
use deno_semver::npm::NpmPackageReqReference; use deno_semver::npm::NpmPackageReqReference;
use deno_telemetry::OtelConfig;
use deno_terminal::colors; use deno_terminal::colors;
use node_resolver::NodeModuleKind; use node_resolver::NodeResolutionKind;
use node_resolver::NodeResolutionMode; use node_resolver::ResolutionMode;
use tokio::select; use tokio::select;
use crate::args::CliLockfile; use crate::args::CliLockfile;
@ -698,8 +698,8 @@ impl CliMainWorkerFactory {
package_folder, package_folder,
sub_path, sub_path,
/* referrer */ None, /* referrer */ None,
NodeModuleKind::Esm, ResolutionMode::Import,
NodeResolutionMode::Execution, NodeResolutionKind::Execution,
)?; )?;
if specifier if specifier
.to_file_path() .to_file_path()

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_broadcast_channel" name = "deno_broadcast_channel"
version = "0.173.0" version = "0.174.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_cache" name = "deno_cache"
version = "0.111.0" version = "0.112.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_canvas" name = "deno_canvas"
version = "0.48.0" version = "0.49.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_console" name = "deno_console"
version = "0.179.0" version = "0.180.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_cron" name = "deno_cron"
version = "0.59.0" version = "0.60.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_crypto" name = "deno_crypto"
version = "0.193.0" version = "0.194.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -286,8 +286,13 @@ function mixinBody(prototype, bodySymbol, mimeTypeSymbol) {
*/ */
get() { get() {
webidl.assertBranded(this, prototype); webidl.assertBranded(this, prototype);
if (this[bodySymbol] !== null) { try {
return this[bodySymbol].consumed(); if (this[bodySymbol] !== null) {
return this[bodySymbol].consumed();
}
} catch (_) {
// Request is closed.
return true;
} }
return false; return false;
}, },

View file

@ -13,6 +13,7 @@
import { core, primordials } from "ext:core/mod.js"; import { core, primordials } from "ext:core/mod.js";
import { import {
op_fetch, op_fetch,
op_fetch_promise_is_settled,
op_fetch_send, op_fetch_send,
op_wasm_streaming_feed, op_wasm_streaming_feed,
op_wasm_streaming_set_url, op_wasm_streaming_set_url,
@ -28,7 +29,9 @@ const {
PromisePrototypeThen, PromisePrototypeThen,
PromisePrototypeCatch, PromisePrototypeCatch,
SafeArrayIterator, SafeArrayIterator,
SafePromisePrototypeFinally,
String, String,
StringPrototypeEndsWith,
StringPrototypeStartsWith, StringPrototypeStartsWith,
StringPrototypeToLowerCase, StringPrototypeToLowerCase,
TypeError, TypeError,
@ -55,6 +58,17 @@ import {
toInnerResponse, toInnerResponse,
} from "ext:deno_fetch/23_response.js"; } from "ext:deno_fetch/23_response.js";
import * as abortSignal from "ext:deno_web/03_abort_signal.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 = [ const REQUEST_BODY_HEADER_NAMES = [
"content-encoding", "content-encoding",
@ -63,6 +77,12 @@ const REQUEST_BODY_HEADER_NAMES = [
"content-type", "content-type",
]; ];
const REDIRECT_SENSITIVE_HEADER_NAMES = [
"authorization",
"proxy-authorization",
"cookie",
];
/** /**
* @param {number} rid * @param {number} rid
* @returns {Promise<{ status: number, statusText: string, headers: [string, string][], url: string, responseRid: number, error: [string, string]? }>} * @returns {Promise<{ status: number, statusText: string, headers: [string, string][], url: string, responseRid: number, error: [string, string]? }>}
@ -250,12 +270,14 @@ function httpRedirectFetch(request, response, terminator) {
if (locationHeaders.length === 0) { if (locationHeaders.length === 0) {
return response; return response;
} }
const currentURL = new URL(request.currentUrl());
const locationURL = new URL( const locationURL = new URL(
locationHeaders[0][1], locationHeaders[0][1],
response.url() ?? undefined, response.url() ?? undefined,
); );
if (locationURL.hash === "") { if (locationURL.hash === "") {
locationURL.hash = request.currentUrl().hash; locationURL.hash = currentURL.hash;
} }
if (locationURL.protocol !== "https:" && locationURL.protocol !== "http:") { if (locationURL.protocol !== "https:" && locationURL.protocol !== "http:") {
return networkError("Can not redirect to a non HTTP(s) url"); return networkError("Can not redirect to a non HTTP(s) url");
@ -294,6 +316,28 @@ function httpRedirectFetch(request, response, terminator) {
} }
} }
} }
// Drop confidential headers when redirecting to a less secure protocol
// or to a different domain that is not a superdomain
if (
locationURL.protocol !== currentURL.protocol &&
locationURL.protocol !== "https:" ||
locationURL.host !== currentURL.host &&
!isSubdomain(locationURL.host, currentURL.host)
) {
for (let i = 0; i < request.headerList.length; i++) {
if (
ArrayPrototypeIncludes(
REDIRECT_SENSITIVE_HEADER_NAMES,
byteLowerCase(request.headerList[i][0]),
)
) {
ArrayPrototypeSplice(request.headerList, i, 1);
i--;
}
}
}
if (request.body !== null) { if (request.body !== null) {
const res = extractBody(request.body.source); const res = extractBody(request.body.source);
request.body = res.body; request.body = res.body;
@ -307,93 +351,138 @@ function httpRedirectFetch(request, response, terminator) {
* @param {RequestInit} init * @param {RequestInit} init
*/ */
function fetch(input, init = { __proto__: null }) { function fetch(input, init = { __proto__: null }) {
// There is an async dispatch later that causes a stack trace disconnect. let span;
// We reconnect it by assigning the result of that dispatch to `opPromise`, try {
// awaiting `opPromise` in an inner function also named `fetch()` and if (TRACING_ENABLED) {
// returning the result from that. span = new Span("fetch", { kind: 2 });
let opPromise = undefined; enterSpan(span);
// 1.
const result = new Promise((resolve, reject) => {
const prefix = "Failed to execute 'fetch'";
webidl.requiredArguments(arguments.length, 1, prefix);
// 2.
const requestObject = new Request(input, init);
// 3.
const request = toInnerRequest(requestObject);
// 4.
if (requestObject.signal.aborted) {
reject(abortFetch(request, null, requestObject.signal.reason));
return;
} }
// 7. // There is an async dispatch later that causes a stack trace disconnect.
let responseObject = null; // We reconnect it by assigning the result of that dispatch to `opPromise`,
// 9. // awaiting `opPromise` in an inner function also named `fetch()` and
let locallyAborted = false; // returning the result from that.
// 10. let opPromise = undefined;
function onabort() { // 1.
locallyAborted = true; const result = new Promise((resolve, reject) => {
reject( const prefix = "Failed to execute 'fetch'";
abortFetch(request, responseObject, requestObject.signal.reason), webidl.requiredArguments(arguments.length, 1, prefix);
); // 2.
} const requestObject = new Request(input, init);
requestObject.signal[abortSignal.add](onabort);
if (!requestObject.headers.has("Accept")) { if (span) {
ArrayPrototypePush(request.headerList, ["Accept", "*/*"]); updateSpanFromRequest(span, requestObject);
} }
if (!requestObject.headers.has("Accept-Language")) { // 3.
ArrayPrototypePush(request.headerList, ["Accept-Language", "*"]); const request = toInnerRequest(requestObject);
} // 4.
if (requestObject.signal.aborted) {
reject(abortFetch(request, null, requestObject.signal.reason));
return;
}
// 7.
let responseObject = null;
// 9.
let locallyAborted = false;
// 10.
function onabort() {
locallyAborted = true;
reject(
abortFetch(request, responseObject, requestObject.signal.reason),
);
}
requestObject.signal[abortSignal.add](onabort);
// 12. if (!requestObject.headers.has("Accept")) {
opPromise = PromisePrototypeCatch( ArrayPrototypePush(request.headerList, ["Accept", "*/*"]);
PromisePrototypeThen( }
mainFetch(request, false, requestObject.signal),
(response) => { if (!requestObject.headers.has("Accept-Language")) {
// 12.1. ArrayPrototypePush(request.headerList, ["Accept-Language", "*"]);
if (locallyAborted) return; }
// 12.2.
if (response.aborted) { // 12.
reject( opPromise = PromisePrototypeCatch(
abortFetch( PromisePrototypeThen(
request, mainFetch(request, false, requestObject.signal),
responseObject, (response) => {
requestObject.signal.reason, // 12.1.
), if (locallyAborted) return;
); // 12.2.
if (response.aborted) {
reject(
abortFetch(
request,
responseObject,
requestObject.signal.reason,
),
);
requestObject.signal[abortSignal.remove](onabort);
return;
}
// 12.3.
if (response.type === "error") {
const err = new TypeError(
"Fetch failed: " + (response.error ?? "unknown error"),
);
reject(err);
requestObject.signal[abortSignal.remove](onabort);
return;
}
responseObject = fromInnerResponse(response, "immutable");
if (span) {
updateSpanFromResponse(span, responseObject);
}
resolve(responseObject);
requestObject.signal[abortSignal.remove](onabort); requestObject.signal[abortSignal.remove](onabort);
return; },
} ),
// 12.3. (err) => {
if (response.type === "error") { reject(err);
const err = new TypeError(
"Fetch failed: " + (response.error ?? "unknown error"),
);
reject(err);
requestObject.signal[abortSignal.remove](onabort);
return;
}
responseObject = fromInnerResponse(response, "immutable");
resolve(responseObject);
requestObject.signal[abortSignal.remove](onabort); requestObject.signal[abortSignal.remove](onabort);
}, },
), );
(err) => { });
reject(err);
requestObject.signal[abortSignal.remove](onabort); if (opPromise) {
}, PromisePrototypeCatch(result, () => {});
); return (async function fetch() {
}); try {
if (opPromise) { await opPromise;
PromisePrototypeCatch(result, () => {}); return result;
return (async function fetch() { } finally {
await opPromise; if (span) {
return result; endSpan(span);
})(); }
}
})();
}
// We need to end the span when the promise settles.
// WPT has a test that aborted fetch is settled in the same tick.
// This means we cannot wrap the promise if it is already settled.
// But this is OK, because we can just immediately end the span
// in that case.
if (span) {
// XXX: This should always be true, otherwise `opPromise` would be present.
if (op_fetch_promise_is_settled(result)) {
// It's already settled.
endSpan(span);
} else {
// Not settled yet, we can return a new wrapper promise.
return SafePromisePrototypeFinally(result, () => {
endSpan(span);
});
}
}
return result;
} finally {
if (span) {
exitSpan(span);
}
} }
return result;
} }
function abortFetch(request, responseObject, error) { function abortFetch(request, responseObject, error) {
@ -410,6 +499,19 @@ function abortFetch(request, responseObject, error) {
return error; return error;
} }
/**
* Checks if the given string is a subdomain of the given domain.
*
* @param {String} subdomain
* @param {String} domain
* @returns {Boolean}
*/
function isSubdomain(subdomain, domain) {
const dot = subdomain.length - domain.length - 1;
return dot > 0 && subdomain[dot] === "." &&
StringPrototypeEndsWith(subdomain, domain);
}
/** /**
* Handle the Response argument to the WebAssembly streaming APIs, after * Handle the Response argument to the WebAssembly streaming APIs, after
* resolving if it was passed as a promise. This function should be registered * resolving if it was passed as a promise. This function should be registered

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_fetch" name = "deno_fetch"
version = "0.203.0" version = "0.204.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -27,6 +27,7 @@ use deno_core::futures::TryFutureExt;
use deno_core::op2; use deno_core::op2;
use deno_core::url; use deno_core::url;
use deno_core::url::Url; use deno_core::url::Url;
use deno_core::v8;
use deno_core::AsyncRefCell; use deno_core::AsyncRefCell;
use deno_core::AsyncResult; use deno_core::AsyncResult;
use deno_core::BufView; use deno_core::BufView;
@ -141,6 +142,7 @@ deno_core::extension!(deno_fetch,
op_fetch_send, op_fetch_send,
op_utf8_to_byte_string, op_utf8_to_byte_string,
op_fetch_custom_client<FP>, op_fetch_custom_client<FP>,
op_fetch_promise_is_settled,
], ],
esm = [ esm = [
"20_headers.js", "20_headers.js",
@ -1206,3 +1208,8 @@ pub fn extract_authority(url: &mut Url) -> Option<(String, Option<String>)> {
None None
} }
#[op2(fast)]
fn op_fetch_promise_is_settled(promise: v8::Local<v8::Promise>) -> bool {
promise.state() != v8::PromiseState::Pending
}

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_ffi" name = "deno_ffi"
version = "0.166.0" version = "0.167.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_fs" name = "deno_fs"
version = "0.89.0" version = "0.90.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -3,6 +3,7 @@
// Allow using Arc for this module. // Allow using Arc for this module.
#![allow(clippy::disallowed_types)] #![allow(clippy::disallowed_types)]
use std::borrow::Cow;
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
use std::collections::HashMap; use std::collections::HashMap;
use std::io::Error; use std::io::Error;
@ -457,11 +458,11 @@ impl FileSystem for InMemoryFs {
&self, &self,
path: &Path, path: &Path,
_access_check: Option<AccessCheckCb>, _access_check: Option<AccessCheckCb>,
) -> FsResult<Vec<u8>> { ) -> FsResult<Cow<'static, [u8]>> {
let entry = self.get_entry(path); let entry = self.get_entry(path);
match entry { match entry {
Some(entry) => match &*entry { Some(entry) => match &*entry {
PathEntry::File(data) => Ok(data.clone()), PathEntry::File(data) => Ok(Cow::Owned(data.clone())),
PathEntry::Dir => Err(FsError::Io(Error::new( PathEntry::Dir => Err(FsError::Io(Error::new(
ErrorKind::InvalidInput, ErrorKind::InvalidInput,
"Is a directory", "Is a directory",
@ -474,7 +475,7 @@ impl FileSystem for InMemoryFs {
&'a self, &'a self,
path: PathBuf, path: PathBuf,
access_check: Option<AccessCheckCb<'a>>, access_check: Option<AccessCheckCb<'a>>,
) -> FsResult<Vec<u8>> { ) -> FsResult<Cow<'static, [u8]>> {
self.read_file_sync(&path, access_check) self.read_file_sync(&path, access_check)
} }
} }

View file

@ -1,5 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use core::str;
use std::borrow::Cow; use std::borrow::Cow;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
@ -288,7 +289,7 @@ pub trait FileSystem: std::fmt::Debug + MaybeSend + MaybeSync {
&self, &self,
path: &Path, path: &Path,
access_check: Option<AccessCheckCb>, access_check: Option<AccessCheckCb>,
) -> FsResult<Vec<u8>> { ) -> FsResult<Cow<'static, [u8]>> {
let options = OpenOptions::read(); let options = OpenOptions::read();
let file = self.open_sync(path, options, access_check)?; let file = self.open_sync(path, options, access_check)?;
let buf = file.read_all_sync()?; let buf = file.read_all_sync()?;
@ -298,7 +299,7 @@ pub trait FileSystem: std::fmt::Debug + MaybeSend + MaybeSync {
&'a self, &'a self,
path: PathBuf, path: PathBuf,
access_check: Option<AccessCheckCb<'a>>, access_check: Option<AccessCheckCb<'a>>,
) -> FsResult<Vec<u8>> { ) -> FsResult<Cow<'static, [u8]>> {
let options = OpenOptions::read(); let options = OpenOptions::read();
let file = self.open_async(path, options, access_check).await?; let file = self.open_async(path, options, access_check).await?;
let buf = file.read_all_async().await?; let buf = file.read_all_async().await?;
@ -327,17 +328,25 @@ pub trait FileSystem: std::fmt::Debug + MaybeSend + MaybeSync {
&self, &self,
path: &Path, path: &Path,
access_check: Option<AccessCheckCb>, access_check: Option<AccessCheckCb>,
) -> FsResult<String> { ) -> FsResult<Cow<'static, str>> {
let buf = self.read_file_sync(path, access_check)?; let buf = self.read_file_sync(path, access_check)?;
Ok(string_from_utf8_lossy(buf)) Ok(string_from_cow_utf8_lossy(buf))
} }
async fn read_text_file_lossy_async<'a>( async fn read_text_file_lossy_async<'a>(
&'a self, &'a self,
path: PathBuf, path: PathBuf,
access_check: Option<AccessCheckCb<'a>>, access_check: Option<AccessCheckCb<'a>>,
) -> FsResult<String> { ) -> FsResult<Cow<'static, str>> {
let buf = self.read_file_async(path, access_check).await?; let buf = self.read_file_async(path, access_check).await?;
Ok(string_from_utf8_lossy(buf)) Ok(string_from_cow_utf8_lossy(buf))
}
}
#[inline(always)]
fn string_from_cow_utf8_lossy(buf: Cow<'static, [u8]>) -> Cow<'static, str> {
match buf {
Cow::Owned(buf) => Cow::Owned(string_from_utf8_lossy(buf)),
Cow::Borrowed(buf) => String::from_utf8_lossy(buf),
} }
} }

View file

@ -17,6 +17,7 @@ pub use crate::interface::OpenOptions;
pub use crate::ops::FsOpsError; pub use crate::ops::FsOpsError;
pub use crate::ops::FsOpsErrorKind; pub use crate::ops::FsOpsErrorKind;
pub use crate::ops::OperationError; pub use crate::ops::OperationError;
pub use crate::ops::V8MaybeStaticStr;
pub use crate::std_fs::RealFs; pub use crate::std_fs::RealFs;
pub use crate::sync::MaybeSend; pub use crate::sync::MaybeSend;
pub use crate::sync::MaybeSync; pub use crate::sync::MaybeSync;

View file

@ -1,5 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use std::borrow::Cow;
use std::cell::RefCell; use std::cell::RefCell;
use std::error::Error; use std::error::Error;
use std::fmt::Formatter; use std::fmt::Formatter;
@ -18,12 +19,15 @@ use crate::FsPermissions;
use crate::OpenOptions; use crate::OpenOptions;
use boxed_error::Boxed; use boxed_error::Boxed;
use deno_core::op2; use deno_core::op2;
use deno_core::v8;
use deno_core::CancelFuture; use deno_core::CancelFuture;
use deno_core::CancelHandle; use deno_core::CancelHandle;
use deno_core::FastString;
use deno_core::JsBuffer; use deno_core::JsBuffer;
use deno_core::OpState; use deno_core::OpState;
use deno_core::ResourceId; use deno_core::ResourceId;
use deno_core::ToJsBuffer; use deno_core::ToJsBuffer;
use deno_core::ToV8;
use deno_io::fs::FileResource; use deno_io::fs::FileResource;
use deno_io::fs::FsError; use deno_io::fs::FsError;
use deno_io::fs::FsStat; use deno_io::fs::FsStat;
@ -1333,7 +1337,8 @@ where
.read_file_sync(&path, Some(&mut access_check)) .read_file_sync(&path, Some(&mut access_check))
.map_err(|error| map_permission_error("readfile", error, &path))?; .map_err(|error| map_permission_error("readfile", error, &path))?;
Ok(buf.into()) // todo(https://github.com/denoland/deno/issues/27107): do not clone here
Ok(buf.into_owned().into_boxed_slice().into())
} }
#[op2(async, stack_trace)] #[op2(async, stack_trace)]
@ -1375,15 +1380,61 @@ where
.map_err(|error| map_permission_error("readfile", error, &path))? .map_err(|error| map_permission_error("readfile", error, &path))?
}; };
Ok(buf.into()) // todo(https://github.com/denoland/deno/issues/27107): do not clone here
Ok(buf.into_owned().into_boxed_slice().into())
}
// todo(https://github.com/denoland/deno_core/pull/986): remove
// when upgrading deno_core
#[derive(Debug)]
pub struct FastStringV8AllocationError;
impl std::error::Error for FastStringV8AllocationError {}
impl std::fmt::Display for FastStringV8AllocationError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
f,
"failed to allocate string; buffer exceeds maximum length"
)
}
}
/// Maintains a static reference to the string if possible.
pub struct V8MaybeStaticStr(pub Cow<'static, str>);
impl<'s> ToV8<'s> for V8MaybeStaticStr {
type Error = FastStringV8AllocationError;
#[inline]
fn to_v8(
self,
scope: &mut v8::HandleScope<'s>,
) -> Result<v8::Local<'s, v8::Value>, Self::Error> {
// todo(https://github.com/denoland/deno_core/pull/986): remove this check
// when upgrading deno_core
const MAX_V8_STRING_LENGTH: usize = 536870888;
if self.0.len() > MAX_V8_STRING_LENGTH {
return Err(FastStringV8AllocationError);
}
Ok(
match self.0 {
Cow::Borrowed(text) => FastString::from_static(text),
Cow::Owned(value) => value.into(),
}
.v8_string(scope)
.into(),
)
}
} }
#[op2(stack_trace)] #[op2(stack_trace)]
#[string] #[to_v8]
pub fn op_fs_read_file_text_sync<P>( pub fn op_fs_read_file_text_sync<P>(
state: &mut OpState, state: &mut OpState,
#[string] path: String, #[string] path: String,
) -> Result<String, FsOpsError> ) -> Result<V8MaybeStaticStr, FsOpsError>
where where
P: FsPermissions + 'static, P: FsPermissions + 'static,
{ {
@ -1395,17 +1446,16 @@ where
let str = fs let str = fs
.read_text_file_lossy_sync(&path, Some(&mut access_check)) .read_text_file_lossy_sync(&path, Some(&mut access_check))
.map_err(|error| map_permission_error("readfile", error, &path))?; .map_err(|error| map_permission_error("readfile", error, &path))?;
Ok(V8MaybeStaticStr(str))
Ok(str)
} }
#[op2(async, stack_trace)] #[op2(async, stack_trace)]
#[string] #[to_v8]
pub async fn op_fs_read_file_text_async<P>( pub async fn op_fs_read_file_text_async<P>(
state: Rc<RefCell<OpState>>, state: Rc<RefCell<OpState>>,
#[string] path: String, #[string] path: String,
#[smi] cancel_rid: Option<ResourceId>, #[smi] cancel_rid: Option<ResourceId>,
) -> Result<String, FsOpsError> ) -> Result<V8MaybeStaticStr, FsOpsError>
where where
P: FsPermissions + 'static, P: FsPermissions + 'static,
{ {
@ -1439,7 +1489,7 @@ where
.map_err(|error| map_permission_error("readfile", error, &path))? .map_err(|error| map_permission_error("readfile", error, &path))?
}; };
Ok(str) Ok(V8MaybeStaticStr(str))
} }
fn to_seek_from(offset: i64, whence: i32) -> Result<SeekFrom, FsOpsError> { fn to_seek_from(offset: i64, whence: i32) -> Result<SeekFrom, FsOpsError> {

View file

@ -2,6 +2,7 @@
#![allow(clippy::disallowed_methods)] #![allow(clippy::disallowed_methods)]
use std::borrow::Cow;
use std::env::current_dir; use std::env::current_dir;
use std::fs; use std::fs;
use std::io; use std::io;
@ -371,7 +372,7 @@ impl FileSystem for RealFs {
&self, &self,
path: &Path, path: &Path,
access_check: Option<AccessCheckCb>, access_check: Option<AccessCheckCb>,
) -> FsResult<Vec<u8>> { ) -> FsResult<Cow<'static, [u8]>> {
let mut file = open_with_access_check( let mut file = open_with_access_check(
OpenOptions { OpenOptions {
read: true, read: true,
@ -382,13 +383,13 @@ impl FileSystem for RealFs {
)?; )?;
let mut buf = Vec::new(); let mut buf = Vec::new();
file.read_to_end(&mut buf)?; file.read_to_end(&mut buf)?;
Ok(buf) Ok(Cow::Owned(buf))
} }
async fn read_file_async<'a>( async fn read_file_async<'a>(
&'a self, &'a self,
path: PathBuf, path: PathBuf,
access_check: Option<AccessCheckCb<'a>>, access_check: Option<AccessCheckCb<'a>>,
) -> FsResult<Vec<u8>> { ) -> FsResult<Cow<'static, [u8]>> {
let mut file = open_with_access_check( let mut file = open_with_access_check(
OpenOptions { OpenOptions {
read: true, read: true,
@ -400,7 +401,7 @@ impl FileSystem for RealFs {
spawn_blocking(move || { spawn_blocking(move || {
let mut buf = Vec::new(); let mut buf = Vec::new();
file.read_to_end(&mut buf)?; file.read_to_end(&mut buf)?;
Ok::<_, FsError>(buf) Ok::<_, FsError>(Cow::Owned(buf))
}) })
.await? .await?
.map_err(Into::into) .map_err(Into::into)

View file

@ -36,9 +36,7 @@ const {
PromisePrototypeCatch, PromisePrototypeCatch,
SafePromisePrototypeFinally, SafePromisePrototypeFinally,
PromisePrototypeThen, PromisePrototypeThen,
String,
StringPrototypeIncludes, StringPrototypeIncludes,
StringPrototypeSlice,
Symbol, Symbol,
TypeError, TypeError,
TypedArrayPrototypeGetSymbolToStringTag, TypedArrayPrototypeGetSymbolToStringTag,
@ -91,6 +89,16 @@ import {
} from "ext:deno_net/01_net.js"; } from "ext:deno_net/01_net.js";
import { hasTlsKeyPairOptions, listenTls } from "ext:deno_net/02_tls.js"; import { hasTlsKeyPairOptions, listenTls } from "ext:deno_net/02_tls.js";
import { SymbolAsyncDispose } from "ext:deno_web/00_infra.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"); const _upgraded = Symbol("_upgraded");
@ -527,16 +535,7 @@ function mapToCallback(context, callback, onError) {
innerRequest.request = request; innerRequest.request = request;
if (span) { if (span) {
span.updateName(request.method); updateSpanFromRequest(span, request);
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));
} }
response = await callback( response = await callback(
@ -578,10 +577,7 @@ function mapToCallback(context, callback, onError) {
} }
if (span) { if (span) {
span.setAttribute( updateSpanFromResponse(span, response);
"http.response.status_code",
String(response.status),
);
} }
const inner = toInnerResponse(response); const inner = toInnerResponse(response);
@ -617,13 +613,12 @@ function mapToCallback(context, callback, onError) {
fastSyncResponseOrStream(req, inner.body, status, innerRequest); fastSyncResponseOrStream(req, inner.body, status, innerRequest);
}; };
if (internals.telemetry.tracingEnabled) { if (TRACING_ENABLED) {
const { Span, enterSpan, endSpan } = internals.telemetry;
const origMapped = mapped; const origMapped = mapped;
mapped = function (req, _span) { mapped = function (req, _span) {
const oldCtx = getAsyncContext(); const oldCtx = getAsyncContext();
setAsyncContext(context.asyncContext); setAsyncContext(context.asyncContext);
const span = new Span("deno.serve"); const span = new Span("deno.serve", { kind: 1 });
try { try {
enterSpan(span); enterSpan(span);
return SafePromisePrototypeFinally( return SafePromisePrototypeFinally(

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_http" name = "deno_http"
version = "0.177.0" version = "0.178.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_io" name = "deno_io"
version = "0.89.0" version = "0.90.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -215,8 +215,8 @@ pub trait File {
fn write_all_sync(self: Rc<Self>, buf: &[u8]) -> FsResult<()>; fn write_all_sync(self: Rc<Self>, buf: &[u8]) -> FsResult<()>;
async fn write_all(self: Rc<Self>, buf: BufView) -> FsResult<()>; async fn write_all(self: Rc<Self>, buf: BufView) -> FsResult<()>;
fn read_all_sync(self: Rc<Self>) -> FsResult<Vec<u8>>; fn read_all_sync(self: Rc<Self>) -> FsResult<Cow<'static, [u8]>>;
async fn read_all_async(self: Rc<Self>) -> FsResult<Vec<u8>>; async fn read_all_async(self: Rc<Self>) -> FsResult<Cow<'static, [u8]>>;
fn chmod_sync(self: Rc<Self>, pathmode: u32) -> FsResult<()>; fn chmod_sync(self: Rc<Self>, pathmode: u32) -> FsResult<()>;
async fn chmod_async(self: Rc<Self>, mode: u32) -> FsResult<()>; async fn chmod_async(self: Rc<Self>, mode: u32) -> FsResult<()>;

View file

@ -789,26 +789,26 @@ impl crate::fs::File for StdFileResourceInner {
} }
} }
fn read_all_sync(self: Rc<Self>) -> FsResult<Vec<u8>> { fn read_all_sync(self: Rc<Self>) -> FsResult<Cow<'static, [u8]>> {
match self.kind { match self.kind {
StdFileResourceKind::File | StdFileResourceKind::Stdin(_) => { StdFileResourceKind::File | StdFileResourceKind::Stdin(_) => {
let mut buf = Vec::new(); let mut buf = Vec::new();
self.with_sync(|file| Ok(file.read_to_end(&mut buf)?))?; self.with_sync(|file| Ok(file.read_to_end(&mut buf)?))?;
Ok(buf) Ok(Cow::Owned(buf))
} }
StdFileResourceKind::Stdout | StdFileResourceKind::Stderr => { StdFileResourceKind::Stdout | StdFileResourceKind::Stderr => {
Err(FsError::NotSupported) Err(FsError::NotSupported)
} }
} }
} }
async fn read_all_async(self: Rc<Self>) -> FsResult<Vec<u8>> { async fn read_all_async(self: Rc<Self>) -> FsResult<Cow<'static, [u8]>> {
match self.kind { match self.kind {
StdFileResourceKind::File | StdFileResourceKind::Stdin(_) => { StdFileResourceKind::File | StdFileResourceKind::Stdin(_) => {
self self
.with_inner_blocking_task(|file| { .with_inner_blocking_task(|file| {
let mut buf = Vec::new(); let mut buf = Vec::new();
file.read_to_end(&mut buf)?; file.read_to_end(&mut buf)?;
Ok(buf) Ok(Cow::Owned(buf))
}) })
.await .await
} }

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_kv" name = "deno_kv"
version = "0.87.0" version = "0.88.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_napi" name = "deno_napi"
version = "0.110.0" version = "0.111.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -2,7 +2,7 @@
[package] [package]
name = "napi_sym" name = "napi_sym"
version = "0.109.0" version = "0.110.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_net" name = "deno_net"
version = "0.171.0" version = "0.172.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_node" name = "deno_node"
version = "0.116.0" version = "0.117.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -157,7 +157,10 @@ pub trait NodeRequireLoader {
path: &'a Path, path: &'a Path,
) -> Result<Cow<'a, Path>, AnyError>; ) -> Result<Cow<'a, Path>, AnyError>;
fn load_text_file_lossy(&self, path: &Path) -> Result<String, AnyError>; fn load_text_file_lossy(
&self,
path: &Path,
) -> Result<Cow<'static, str>, AnyError>;
/// Get if the module kind is maybe CJS and loading should determine /// Get if the module kind is maybe CJS and loading should determine
/// if its CJS or ESM. /// if its CJS or ESM.
@ -873,6 +876,8 @@ impl deno_package_json::fs::DenoPkgJsonFs for DenoFsNodeResolverEnv {
self self
.fs .fs
.read_text_file_lossy_sync(path, None) .read_text_file_lossy_sync(path, None)
// todo(https://github.com/denoland/deno_package_json/pull/9): don't clone
.map(|text| text.into_owned())
.map_err(|err| err.into_io_error()) .map_err(|err| err.into_io_error())
} }
} }
@ -887,6 +892,8 @@ impl<'a> deno_package_json::fs::DenoPkgJsonFs for DenoPkgJsonFsAdapter<'a> {
self self
.0 .0
.read_text_file_lossy_sync(path, None) .read_text_file_lossy_sync(path, None)
// todo(https://github.com/denoland/deno_package_json/pull/9): don't clone
.map(|text| text.into_owned())
.map_err(|err| err.into_io_error()) .map_err(|err| err.into_io_error())
} }
} }

View file

@ -8,13 +8,14 @@ use deno_core::v8;
use deno_core::JsRuntimeInspector; use deno_core::JsRuntimeInspector;
use deno_core::OpState; use deno_core::OpState;
use deno_fs::FileSystemRc; use deno_fs::FileSystemRc;
use deno_package_json::NodeModuleKind; use deno_fs::V8MaybeStaticStr;
use deno_package_json::PackageJsonRc; use deno_package_json::PackageJsonRc;
use deno_path_util::normalize_path; use deno_path_util::normalize_path;
use deno_path_util::url_from_file_path; use deno_path_util::url_from_file_path;
use deno_path_util::url_to_file_path; use deno_path_util::url_to_file_path;
use node_resolver::errors::ClosestPkgJsonError; use node_resolver::errors::ClosestPkgJsonError;
use node_resolver::NodeResolutionMode; use node_resolver::NodeResolutionKind;
use node_resolver::ResolutionMode;
use node_resolver::REQUIRE_CONDITIONS; use node_resolver::REQUIRE_CONDITIONS;
use std::borrow::Cow; use std::borrow::Cow;
use std::cell::RefCell; use std::cell::RefCell;
@ -462,9 +463,9 @@ where
&expansion, &expansion,
exports, exports,
Some(&referrer), Some(&referrer),
NodeModuleKind::Cjs, ResolutionMode::Require,
REQUIRE_CONDITIONS, REQUIRE_CONDITIONS,
NodeResolutionMode::Execution, NodeResolutionKind::Execution,
)?; )?;
Ok(Some(if r.scheme() == "file" { Ok(Some(if r.scheme() == "file" {
url_to_file_path_string(&r)? url_to_file_path_string(&r)?
@ -477,11 +478,11 @@ where
} }
#[op2(stack_trace)] #[op2(stack_trace)]
#[string] #[to_v8]
pub fn op_require_read_file<P>( pub fn op_require_read_file<P>(
state: &mut OpState, state: &mut OpState,
#[string] file_path: String, #[string] file_path: String,
) -> Result<String, RequireError> ) -> Result<V8MaybeStaticStr, RequireError>
where where
P: NodePermissions + 'static, P: NodePermissions + 'static,
{ {
@ -492,6 +493,7 @@ where
let loader = state.borrow::<NodeRequireLoaderRc>(); let loader = state.borrow::<NodeRequireLoaderRc>();
loader loader
.load_text_file_lossy(&file_path) .load_text_file_lossy(&file_path)
.map(V8MaybeStaticStr)
.map_err(|e| RequireErrorKind::ReadModule(e).into_box()) .map_err(|e| RequireErrorKind::ReadModule(e).into_box())
} }
@ -559,9 +561,9 @@ where
&format!(".{expansion}"), &format!(".{expansion}"),
exports, exports,
referrer.as_ref(), referrer.as_ref(),
NodeModuleKind::Cjs, ResolutionMode::Require,
REQUIRE_CONDITIONS, REQUIRE_CONDITIONS,
NodeResolutionMode::Execution, NodeResolutionKind::Execution,
)?; )?;
Ok(Some(if r.scheme() == "file" { Ok(Some(if r.scheme() == "file" {
url_to_file_path_string(&r)? url_to_file_path_string(&r)?
@ -630,10 +632,10 @@ where
let url = node_resolver.package_imports_resolve( let url = node_resolver.package_imports_resolve(
&request, &request,
Some(&referrer_url), Some(&referrer_url),
NodeModuleKind::Cjs, ResolutionMode::Require,
Some(&pkg), Some(&pkg),
REQUIRE_CONDITIONS, REQUIRE_CONDITIONS,
NodeResolutionMode::Execution, NodeResolutionKind::Execution,
)?; )?;
Ok(Some(url_to_file_path_string(&url)?)) Ok(Some(url_to_file_path_string(&url)?))
} else { } else {

View file

@ -6,6 +6,7 @@
import { denoErrorToNodeError } from "ext:deno_node/internal/errors.ts"; import { denoErrorToNodeError } from "ext:deno_node/internal/errors.ts";
import { promisify } from "ext:deno_node/internal/util.mjs"; import { promisify } from "ext:deno_node/internal/util.mjs";
import { primordials } from "ext:core/mod.js"; import { primordials } from "ext:core/mod.js";
import { getValidatedPath } from "ext:deno_node/internal/fs/utils.mjs";
const { ObjectCreate, ObjectAssign } = primordials; const { ObjectCreate, ObjectAssign } = primordials;
@ -379,6 +380,7 @@ export function stat(
? optionsOrCallback ? optionsOrCallback
: { bigint: false }; : { bigint: false };
path = getValidatedPath(path).toString();
if (!callback) throw new Error("No callback function supplied"); if (!callback) throw new Error("No callback function supplied");
Deno.stat(path).then( Deno.stat(path).then(
@ -409,6 +411,8 @@ export function statSync(
path: string | URL, path: string | URL,
options: statOptions = { bigint: false, throwIfNoEntry: true }, options: statOptions = { bigint: false, throwIfNoEntry: true },
): Stats | BigIntStats | undefined { ): Stats | BigIntStats | undefined {
path = getValidatedPath(path).toString();
try { try {
const origin = Deno.statSync(path); const origin = Deno.statSync(path);
return CFISBIS(origin, options.bigint); return CFISBIS(origin, options.bigint);

View file

@ -148,9 +148,13 @@ export class TLSSocket extends net.Socket {
: new TCP(TCPConstants.SOCKET); : new TCP(TCPConstants.SOCKET);
} }
const { promise, resolve } = Promise.withResolvers();
// Patches `afterConnect` hook to replace TCP conn with TLS conn // Patches `afterConnect` hook to replace TCP conn with TLS conn
const afterConnect = handle.afterConnect; const afterConnect = handle.afterConnect;
handle.afterConnect = async (req: any, status: number) => { handle.afterConnect = async (req: any, status: number) => {
options.hostname ??= undefined; // coerce to undefined if null, startTls expects hostname to be undefined
try { try {
const conn = await Deno.startTls(handle[kStreamBaseField], options); const conn = await Deno.startTls(handle[kStreamBaseField], options);
try { try {
@ -164,15 +168,25 @@ export class TLSSocket extends net.Socket {
// Don't interrupt "secure" event to let the first read/write // Don't interrupt "secure" event to let the first read/write
// operation emit the error. // operation emit the error.
} }
// Assign the TLS connection to the handle and resume reading.
handle[kStreamBaseField] = conn; handle[kStreamBaseField] = conn;
handle.upgrading = false;
if (!handle.pauseOnCreate) {
handle.readStart();
}
resolve();
tlssock.emit("secure"); tlssock.emit("secure");
tlssock.removeListener("end", onConnectEnd); tlssock.removeListener("end", onConnectEnd);
} catch (_) { } catch {
// TODO(kt3k): Handle this // TODO(kt3k): Handle this
} }
return afterConnect.call(handle, req, status); return afterConnect.call(handle, req, status);
}; };
handle.upgrading = promise;
(handle as any).verifyError = function () { (handle as any).verifyError = function () {
return null; // Never fails, rejectUnauthorized is always true in Deno. return null; // Never fails, rejectUnauthorized is always true in Deno.
}; };

View file

@ -1409,7 +1409,7 @@ ServerResponse.prototype.hasHeader = function (
this: ServerResponse, this: ServerResponse,
name: string, name: string,
) { ) {
return Object.hasOwn(this._headers, name); return Object.hasOwn(this._headers, StringPrototypeToLowerCase(name));
}; };
ServerResponse.prototype.writeHead = function ( ServerResponse.prototype.writeHead = function (

View file

@ -479,13 +479,13 @@ export class ClientHttp2Session extends Http2Session {
socket.on("error", socketOnError); socket.on("error", socketOnError);
socket.on("close", socketOnClose); socket.on("close", socketOnClose);
socket[kHandle].pauseOnCreate = true;
const connPromise = new Promise((resolve) => { const connPromise = new Promise((resolve) => {
const eventName = url.startsWith("https") ? "secureConnect" : "connect"; const eventName = url.startsWith("https") ? "secureConnect" : "connect";
socket.once(eventName, () => { socket.once(eventName, () => {
const rid = socket[kHandle][kStreamBaseField][internalRidSymbol]; const rid = socket[kHandle][kStreamBaseField][internalRidSymbol];
nextTick(() => { nextTick(() => resolve(rid));
resolve(rid);
});
}); });
}); });
socket[kSession] = this; socket[kSession] = this;

View file

@ -320,8 +320,16 @@ export class LibuvStreamWrap extends HandleWrap {
/** Internal method for reading from the attached stream. */ /** Internal method for reading from the attached stream. */
async #read() { async #read() {
let buf = this.#buf; let buf = this.#buf;
let nread: number | null; let nread: number | null;
const ridBefore = this[kStreamBaseField]![internalRidSymbol]; const ridBefore = this[kStreamBaseField]![internalRidSymbol];
if (this.upgrading) {
// Starting an upgrade, stop reading. Upgrading will resume reading.
this.readStop();
return;
}
try { try {
nread = await this[kStreamBaseField]!.read(buf); nread = await this[kStreamBaseField]!.read(buf);
} catch (e) { } catch (e) {
@ -382,6 +390,11 @@ export class LibuvStreamWrap extends HandleWrap {
const ridBefore = this[kStreamBaseField]![internalRidSymbol]; const ridBefore = this[kStreamBaseField]![internalRidSymbol];
if (this.upgrading) {
// There is an upgrade in progress, queue the write request.
await this.upgrading;
}
let nwritten = 0; let nwritten = 0;
try { try {
// TODO(crowlKats): duplicate from runtime/js/13_buffer.js // TODO(crowlKats): duplicate from runtime/js/13_buffer.js
@ -400,7 +413,6 @@ export class LibuvStreamWrap extends HandleWrap {
} }
let status: number; let status: number;
// TODO(cmorten): map err to status codes // TODO(cmorten): map err to status codes
if ( if (
e instanceof Deno.errors.BadResource || e instanceof Deno.errors.BadResource ||

View file

@ -54,7 +54,7 @@ export function clearTimeout(timeout?: Timeout | number) {
const id = +timeout; const id = +timeout;
const timer = MapPrototypeGet(activeTimers, id); const timer = MapPrototypeGet(activeTimers, id);
if (timer) { if (timer) {
timeout._destroyed = true; timer._destroyed = true;
MapPrototypeDelete(activeTimers, id); MapPrototypeDelete(activeTimers, id);
} }
clearTimeout_(id); clearTimeout_(id);
@ -74,7 +74,7 @@ export function clearInterval(timeout?: Timeout | number | string) {
const id = +timeout; const id = +timeout;
const timer = MapPrototypeGet(activeTimers, id); const timer = MapPrototypeGet(activeTimers, id);
if (timer) { if (timer) {
timeout._destroyed = true; timer._destroyed = true;
MapPrototypeDelete(activeTimers, id); MapPrototypeDelete(activeTimers, id);
} }
clearInterval_(id); clearInterval_(id);

31
ext/telemetry/Cargo.toml Normal file
View file

@ -0,0 +1,31 @@
# Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
[package]
name = "deno_telemetry"
version = "0.2.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
View file

@ -0,0 +1,3 @@
# `deno_telemetry`
This crate implements telemetry for Deno using OpenTelemetry.

View file

@ -1,6 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use crate::tokio_util::create_basic_runtime;
use deno_core::anyhow; use deno_core::anyhow;
use deno_core::anyhow::anyhow; use deno_core::anyhow::anyhow;
use deno_core::futures::channel::mpsc; use deno_core::futures::channel::mpsc;
@ -59,7 +58,7 @@ type SpanProcessor = BatchSpanProcessor<OtelSharedRuntime>;
type LogProcessor = BatchLogProcessor<OtelSharedRuntime>; type LogProcessor = BatchLogProcessor<OtelSharedRuntime>;
deno_core::extension!( deno_core::extension!(
deno_otel, deno_telemetry,
ops = [ ops = [
op_otel_log, op_otel_log,
op_otel_instrumentation_scope_create_and_enter, op_otel_instrumentation_scope_create_and_enter,
@ -73,6 +72,7 @@ deno_core::extension!(
op_otel_span_set_dropped, op_otel_span_set_dropped,
op_otel_span_flush, op_otel_span_flush,
], ],
esm = ["telemetry.ts", "util.ts"],
); );
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
@ -111,7 +111,26 @@ fn otel_create_shared_runtime() -> UnboundedSender<BoxFuture<'static, ()>> {
mpsc::unbounded::<BoxFuture<'static, ()>>(); mpsc::unbounded::<BoxFuture<'static, ()>>();
thread::spawn(move || { 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 { rt.block_on(async move {
while let Some(task) = spawn_task_rx.next().await { while let Some(task) = spawn_task_rx.next().await {
tokio::spawn(task); tokio::spawn(task);

View file

@ -1,6 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // 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 { import {
op_crypto_get_random_values, op_crypto_get_random_values,
op_otel_instrumentation_scope_create_and_enter, op_otel_instrumentation_scope_create_and_enter,
@ -38,9 +38,11 @@ const {
} = primordials; } = primordials;
const { AsyncVariable, setAsyncContext } = core; const { AsyncVariable, setAsyncContext } = core;
let TRACING_ENABLED = false; export let TRACING_ENABLED = false;
let DETERMINISTIC = false; let DETERMINISTIC = false;
// Note: These start at 0 in the JS library,
// but start at 1 when serialized with JSON.
enum SpanKind { enum SpanKind {
INTERNAL = 0, INTERNAL = 0,
SERVER = 1, SERVER = 1,
@ -91,6 +93,11 @@ interface Attributes {
type SpanAttributes = Attributes; type SpanAttributes = Attributes;
interface SpanOptions {
attributes?: Attributes;
kind?: SpanKind;
}
interface Link { interface Link {
context: SpanContext; context: SpanContext;
attributes?: SpanAttributes; attributes?: SpanAttributes;
@ -354,7 +361,7 @@ export class Span {
#recording = TRACING_ENABLED; #recording = TRACING_ENABLED;
#kind: number = 0; #kind: number = SpanKind.INTERNAL;
#name: string; #name: string;
#startTime: number; #startTime: number;
#status: { code: number; message?: string } | null = null; #status: { code: number; message?: string } | null = null;
@ -429,7 +436,7 @@ export class Span {
constructor( constructor(
name: string, name: string,
attributes?: Attributes, options?: SpanOptions,
) { ) {
if (!this.isRecording) { if (!this.isRecording) {
this.#name = ""; this.#name = "";
@ -442,7 +449,8 @@ export class Span {
this.#name = name; this.#name = name;
this.#startTime = now(); this.#startTime = now();
this.#attributes = attributes ?? { __proto__: null } as never; this.#attributes = options?.attributes ?? { __proto__: null } as never;
this.#kind = options?.kind ?? SpanKind.INTERNAL;
const currentSpan: Span | { const currentSpan: Span | {
spanContext(): { traceId: string; spanId: string }; spanContext(): { traceId: string; spanId: string };
@ -701,12 +709,3 @@ export const telemetry = {
SpanExporter, SpanExporter,
ContextManager, ContextManager,
}; };
internals.telemetry = {
Span,
enterSpan,
exitSpan,
endSpan,
get tracingEnabled() {
return TRACING_ENABLED;
},
};

27
ext/telemetry/util.ts Normal file
View 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),
);
}

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_tls" name = "deno_tls"
version = "0.166.0" version = "0.167.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_url" name = "deno_url"
version = "0.179.0" version = "0.180.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -2922,7 +2922,7 @@ function readableStreamPipeTo(
} }
/** /**
* @param {ReadableStreamGenericReader<any> | ReadableStreamBYOBReader} reader * @param {ReadableStreamGenericReader | ReadableStreamBYOBReader} reader
* @param {any} reason * @param {any} reason
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
@ -2955,7 +2955,7 @@ function readableStreamReaderGenericInitialize(reader, stream) {
/** /**
* @template R * @template R
* @param {ReadableStreamGenericReader<R> | ReadableStreamBYOBReader} reader * @param {ReadableStreamGenericReader | ReadableStreamBYOBReader} reader
*/ */
function readableStreamReaderGenericRelease(reader) { function readableStreamReaderGenericRelease(reader) {
const stream = reader[_stream]; const stream = reader[_stream];

View file

@ -60,8 +60,8 @@ interface VoidFunction {
(): void; (): void;
} }
interface ReadableStreamGenericReader<T> { interface ReadableStreamGenericReader {
readonly closed: Promise<void>; readonly closed: Promise<undefined>;
// deno-lint-ignore no-explicit-any // deno-lint-ignore no-explicit-any
cancel(reason?: any): Promise<void>; cancel(reason?: any): Promise<void>;
} }

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_web" name = "deno_web"
version = "0.210.0" version = "0.211.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -882,7 +882,7 @@ declare var ReadableStream: {
strategy?: QueuingStrategy<R>, strategy?: QueuingStrategy<R>,
): ReadableStream<R>; ): ReadableStream<R>;
from<R>( from<R>(
asyncIterable: AsyncIterable<R> | Iterable<R | PromiseLike<R>>, asyncIterable: AsyncIterable<R> | Iterable<R | PromiseLike<R>> & object,
): ReadableStream<R>; ): ReadableStream<R>;
}; };

View file

@ -98,6 +98,11 @@ const {
ArrayPrototypePush, ArrayPrototypePush,
DataViewPrototypeGetBuffer, DataViewPrototypeGetBuffer,
Error, Error,
Number,
NumberPOSITIVE_INFINITY,
NumberMAX_SAFE_INTEGER,
NumberNEGATIVE_INFINITY,
NumberMIN_SAFE_INTEGER,
MathMax, MathMax,
ObjectDefineProperty, ObjectDefineProperty,
ObjectHasOwn, ObjectHasOwn,
@ -614,6 +619,19 @@ function createGPUSupportedLimits(limits) {
return adapterFeatures; return adapterFeatures;
} }
function normalizeLimit(limit) {
if (typeof limit === "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 * @typedef InnerAdapterLimits
* @property {number} maxTextureDimension1D * @property {number} maxTextureDimension1D
@ -653,123 +671,127 @@ class GPUSupportedLimits {
get maxTextureDimension1D() { get maxTextureDimension1D() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxTextureDimension1D; return normalizeLimit(this[_limits].maxTextureDimension1D);
} }
get maxTextureDimension2D() { get maxTextureDimension2D() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxTextureDimension2D; return normalizeLimit(this[_limits].maxTextureDimension2D);
} }
get maxTextureDimension3D() { get maxTextureDimension3D() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxTextureDimension3D; return normalizeLimit(this[_limits].maxTextureDimension3D);
} }
get maxTextureArrayLayers() { get maxTextureArrayLayers() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxTextureArrayLayers; return normalizeLimit(this[_limits].maxTextureArrayLayers);
} }
get maxBindGroups() { get maxBindGroups() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxBindGroups; return normalizeLimit(this[_limits].maxBindGroups);
} }
get maxBindingsPerBindGroup() { get maxBindingsPerBindGroup() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxBindingsPerBindGroup; return normalizeLimit(this[_limits].maxBindingsPerBindGroup);
} }
get maxBufferSize() { get maxBufferSize() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxBufferSize; return normalizeLimit(this[_limits].maxBufferSize);
} }
get maxDynamicUniformBuffersPerPipelineLayout() { get maxDynamicUniformBuffersPerPipelineLayout() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxDynamicUniformBuffersPerPipelineLayout; return normalizeLimit(
this[_limits].maxDynamicUniformBuffersPerPipelineLayout,
);
} }
get maxDynamicStorageBuffersPerPipelineLayout() { get maxDynamicStorageBuffersPerPipelineLayout() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxDynamicStorageBuffersPerPipelineLayout; return normalizeLimit(
this[_limits].maxDynamicStorageBuffersPerPipelineLayout,
);
} }
get maxSampledTexturesPerShaderStage() { get maxSampledTexturesPerShaderStage() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxSampledTexturesPerShaderStage; return normalizeLimit(this[_limits].maxSampledTexturesPerShaderStage);
} }
get maxSamplersPerShaderStage() { get maxSamplersPerShaderStage() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxSamplersPerShaderStage; return normalizeLimit(this[_limits].maxSamplersPerShaderStage);
} }
get maxStorageBuffersPerShaderStage() { get maxStorageBuffersPerShaderStage() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxStorageBuffersPerShaderStage; return normalizeLimit(this[_limits].maxStorageBuffersPerShaderStage);
} }
get maxStorageTexturesPerShaderStage() { get maxStorageTexturesPerShaderStage() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxStorageTexturesPerShaderStage; return normalizeLimit(this[_limits].maxStorageTexturesPerShaderStage);
} }
get maxUniformBuffersPerShaderStage() { get maxUniformBuffersPerShaderStage() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxUniformBuffersPerShaderStage; return normalizeLimit(this[_limits].maxUniformBuffersPerShaderStage);
} }
get maxUniformBufferBindingSize() { get maxUniformBufferBindingSize() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxUniformBufferBindingSize; return normalizeLimit(this[_limits].maxUniformBufferBindingSize);
} }
get maxStorageBufferBindingSize() { get maxStorageBufferBindingSize() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxStorageBufferBindingSize; return normalizeLimit(this[_limits].maxStorageBufferBindingSize);
} }
get minUniformBufferOffsetAlignment() { get minUniformBufferOffsetAlignment() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].minUniformBufferOffsetAlignment; return normalizeLimit(this[_limits].minUniformBufferOffsetAlignment);
} }
get minStorageBufferOffsetAlignment() { get minStorageBufferOffsetAlignment() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].minStorageBufferOffsetAlignment; return normalizeLimit(this[_limits].minStorageBufferOffsetAlignment);
} }
get maxVertexBuffers() { get maxVertexBuffers() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxVertexBuffers; return normalizeLimit(this[_limits].maxVertexBuffers);
} }
get maxVertexAttributes() { get maxVertexAttributes() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxVertexAttributes; return normalizeLimit(this[_limits].maxVertexAttributes);
} }
get maxVertexBufferArrayStride() { get maxVertexBufferArrayStride() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxVertexBufferArrayStride; return normalizeLimit(this[_limits].maxVertexBufferArrayStride);
} }
get maxInterStageShaderComponents() { get maxInterStageShaderComponents() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxInterStageShaderComponents; return normalizeLimit(this[_limits].maxInterStageShaderComponents);
} }
get maxColorAttachments() { get maxColorAttachments() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxColorAttachments; return normalizeLimit(this[_limits].maxColorAttachments);
} }
get maxColorAttachmentBytesPerSample() { get maxColorAttachmentBytesPerSample() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxColorAttachmentBytesPerSample; return normalizeLimit(this[_limits].maxColorAttachmentBytesPerSample);
} }
get maxComputeWorkgroupStorageSize() { get maxComputeWorkgroupStorageSize() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxComputeWorkgroupStorageSize; return normalizeLimit(this[_limits].maxComputeWorkgroupStorageSize);
} }
get maxComputeInvocationsPerWorkgroup() { get maxComputeInvocationsPerWorkgroup() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxComputeInvocationsPerWorkgroup; return normalizeLimit(this[_limits].maxComputeInvocationsPerWorkgroup);
} }
get maxComputeWorkgroupSizeX() { get maxComputeWorkgroupSizeX() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxComputeWorkgroupSizeX; return normalizeLimit(this[_limits].maxComputeWorkgroupSizeX);
} }
get maxComputeWorkgroupSizeY() { get maxComputeWorkgroupSizeY() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxComputeWorkgroupSizeY; return normalizeLimit(this[_limits].maxComputeWorkgroupSizeY);
} }
get maxComputeWorkgroupSizeZ() { get maxComputeWorkgroupSizeZ() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxComputeWorkgroupSizeZ; return normalizeLimit(this[_limits].maxComputeWorkgroupSizeZ);
} }
get maxComputeWorkgroupsPerDimension() { get maxComputeWorkgroupsPerDimension() {
webidl.assertBranded(this, GPUSupportedLimitsPrototype); webidl.assertBranded(this, GPUSupportedLimitsPrototype);
return this[_limits].maxComputeWorkgroupsPerDimension; return normalizeLimit(this[_limits].maxComputeWorkgroupsPerDimension);
} }
[SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) { [SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) {

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_webgpu" name = "deno_webgpu"
version = "0.146.0" version = "0.147.0"
authors = ["the Deno authors"] authors = ["the Deno authors"]
edition.workspace = true edition.workspace = true
license = "MIT" license = "MIT"

View file

@ -2,7 +2,7 @@
[package] [package]
name = "deno_webidl" name = "deno_webidl"
version = "0.179.0" version = "0.180.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

Some files were not shown because too many files have changed in this diff Show more