Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions libs/resolver/file_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,17 @@ impl<
}
}

if !matches!(
specifier.scheme(),
"file" | "http" | "https" | "blob" | "data"
) {
return Box::pin(std::future::ready(Ok(Some(
deno_graph::source::LoadResponse::External {
specifier: specifier.clone(),
},
))));
}

self.load_or_cache(
LoadStrategy {
file_fetcher: self.file_fetcher.clone(),
Expand Down
26 changes: 25 additions & 1 deletion libs/resolver/loader/module_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ pub enum LoadCodeSourceErrorKind {
#[class(inherit)]
#[error(transparent)]
PathToUrl(#[from] deno_path_util::PathToUrlError),
#[class(inherit)]
#[error(transparent)]
UnsupportedScheme(#[from] UnsupportedSchemeError),
}

// this message list additional `npm` and `jsr` schemes, but they should actually be handled
// before these APIs are even hit.
#[derive(Debug, thiserror::Error, deno_error::JsError)]
#[class(type)]
#[error(
"Unsupported scheme \"{}\" for module \"{}\". Supported schemes:\n - \"blob\"\n - \"data\"\n - \"file\"\n - \"http\"\n - \"https\"\n - \"jsr\"\n - \"npm\"", url.scheme(), url
)]
pub struct UnsupportedSchemeError {
pub url: Url,
}

#[derive(Debug, thiserror::Error, deno_error::JsError)]
Expand Down Expand Up @@ -188,7 +202,17 @@ impl<TSys: ModuleLoaderSys> ModuleLoader<TSys> {
{
Some(module_or_asset) => module_or_asset,
None => {
if self.in_npm_pkg_checker.in_npm_package(specifier) {
if !matches!(
specifier.scheme(),
"https" | "http" | "file" | "blob" | "data"
) {
return Err(
UnsupportedSchemeError {
url: specifier.clone(),
}
.into(),
);
} else if self.in_npm_pkg_checker.in_npm_package(specifier) {
let loaded_module = self
.npm_module_loader
.load(
Expand Down
4 changes: 4 additions & 0 deletions tests/specs/check/special_specifiers/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"args": "check",
"output": "check.out"
}
1 change: 1 addition & 0 deletions tests/specs/check/special_specifiers/check.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Check file:///[WILDCARD]/mod.ts
5 changes: 5 additions & 0 deletions tests/specs/check/special_specifiers/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"types": ["@types/cloudflare"]
}
}
2 changes: 2 additions & 0 deletions tests/specs/check/special_specifiers/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare module "cloudflare:sockets" {
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tests/specs/check/special_specifiers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"@types/cloudflare": "*"
}
}
10 changes: 1 addition & 9 deletions tests/testdata/run/extension_import.ts.out
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
error: Unsupported scheme "ext" for module "ext:runtime/01_errors.js". Supported schemes:
- "blob"
- "data"
- "file"
- "http"
- "https"
- "jsr"
- "npm"
at [WILDCARD]/extension_import.ts:1:8
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
Copy link
Member Author

@dsherret dsherret Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine (not worth investigating how to get the previous error back because nobody is going to do this).

Loading