Skip to content

Commit 46e2c64

Browse files
authored
fix(check): do not error for unsupported URL schemes (#30904)
Closes #30898
1 parent fb69caf commit 46e2c64

File tree

10 files changed

+60
-10
lines changed

10 files changed

+60
-10
lines changed

libs/resolver/file_fetcher.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,17 @@ impl<
629629
}
630630
}
631631

632+
if !matches!(
633+
specifier.scheme(),
634+
"file" | "http" | "https" | "blob" | "data"
635+
) {
636+
return Box::pin(std::future::ready(Ok(Some(
637+
deno_graph::source::LoadResponse::External {
638+
specifier: specifier.clone(),
639+
},
640+
))));
641+
}
642+
632643
self.load_or_cache(
633644
LoadStrategy {
634645
file_fetcher: self.file_fetcher.clone(),

libs/resolver/loader/module_loader.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ pub enum LoadCodeSourceErrorKind {
9494
#[class(inherit)]
9595
#[error(transparent)]
9696
PathToUrl(#[from] deno_path_util::PathToUrlError),
97+
#[class(inherit)]
98+
#[error(transparent)]
99+
UnsupportedScheme(#[from] UnsupportedSchemeError),
100+
}
101+
102+
// this message list additional `npm` and `jsr` schemes, but they should actually be handled
103+
// before these APIs are even hit.
104+
#[derive(Debug, thiserror::Error, deno_error::JsError)]
105+
#[class(type)]
106+
#[error(
107+
"Unsupported scheme \"{}\" for module \"{}\". Supported schemes:\n - \"blob\"\n - \"data\"\n - \"file\"\n - \"http\"\n - \"https\"\n - \"jsr\"\n - \"npm\"", url.scheme(), url
108+
)]
109+
pub struct UnsupportedSchemeError {
110+
pub url: Url,
97111
}
98112

99113
#[derive(Debug, thiserror::Error, deno_error::JsError)]
@@ -188,7 +202,17 @@ impl<TSys: ModuleLoaderSys> ModuleLoader<TSys> {
188202
{
189203
Some(module_or_asset) => module_or_asset,
190204
None => {
191-
if self.in_npm_pkg_checker.in_npm_package(specifier) {
205+
if !matches!(
206+
specifier.scheme(),
207+
"https" | "http" | "file" | "blob" | "data"
208+
) {
209+
return Err(
210+
UnsupportedSchemeError {
211+
url: specifier.clone(),
212+
}
213+
.into(),
214+
);
215+
} else if self.in_npm_pkg_checker.in_npm_package(specifier) {
192216
let loaded_module = self
193217
.npm_module_loader
194218
.load(
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"args": "check",
3+
"output": "check.out"
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Check file:///[WILDCARD]/mod.ts
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"types": ["@types/cloudflare"]
4+
}
5+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare module "cloudflare:sockets" {
2+
}

tests/specs/check/special_specifiers/node_modules/@types/cloudflare/index.d.ts

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/specs/check/special_specifiers/node_modules/@types/cloudflare/package.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"@types/cloudflare": "*"
4+
}
5+
}
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
error: Unsupported scheme "ext" for module "ext:runtime/01_errors.js". Supported schemes:
2-
- "blob"
3-
- "data"
4-
- "file"
5-
- "http"
6-
- "https"
7-
- "jsr"
8-
- "npm"
9-
at [WILDCARD]/extension_import.ts:1:8
1+
error: Importing ext: modules is only allowed from ext: and node: modules. Tried to import ext:runtime/01_errors.js from file:///[WILDLINE]/extension_import.ts

0 commit comments

Comments
 (0)