summaryrefslogtreecommitdiff
path: root/cli/tsc/mod.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-04-16 16:46:31 -0400
committerGitHub <noreply@github.com>2024-04-16 16:46:31 -0400
commit43c8c1cc6e0f0fe4accde97c52f7f2bb998ac669 (patch)
tree157e9e3801253b1ad9345aded73e684a39292bc5 /cli/tsc/mod.rs
parent422cff1f247dc334d5eb9387be924f5937b0c6d9 (diff)
feat(check): allow using side effect imports with unknown module kinds (ex. css modules) (#23392)
This allows people to use imports like: ```ts import "./app.css"; ``` ...with `deno check` in systems where there's a bundle step (ex. Vite). This will still error when using it with `deno run` or if the referenced file does not exist. See test cases for behaviour.
Diffstat (limited to 'cli/tsc/mod.rs')
-rw-r--r--cli/tsc/mod.rs30
1 files changed, 28 insertions, 2 deletions
diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs
index 2d06e0a95..e2a7da3ed 100644
--- a/cli/tsc/mod.rs
+++ b/cli/tsc/mod.rs
@@ -508,7 +508,20 @@ fn op_load_inner(
} else {
&specifier
};
- let maybe_source = if let Some(module) = graph.get(specifier) {
+ let maybe_module = match graph.try_get(specifier) {
+ Ok(maybe_module) => maybe_module,
+ Err(err) => match err {
+ deno_graph::ModuleError::UnsupportedMediaType(_, media_type, _) => {
+ return Ok(Some(LoadResponse {
+ data: "".to_string(),
+ version: Some("1".to_string()),
+ script_kind: as_ts_script_kind(*media_type),
+ }))
+ }
+ _ => None,
+ },
+ };
+ let maybe_source = if let Some(module) = maybe_module {
match module {
Module::Js(module) => {
media_type = module.media_type;
@@ -674,7 +687,20 @@ fn resolve_graph_specifier_types(
state: &State,
) -> Result<Option<(ModuleSpecifier, MediaType)>, AnyError> {
let graph = &state.graph;
- let maybe_module = graph.get(specifier);
+ let maybe_module = match graph.try_get(specifier) {
+ Ok(Some(module)) => Some(module),
+ Ok(None) => None,
+ Err(err) => match err {
+ deno_graph::ModuleError::UnsupportedMediaType(
+ specifier,
+ media_type,
+ _,
+ ) => {
+ return Ok(Some((specifier.clone(), *media_type)));
+ }
+ _ => None,
+ },
+ };
// follow the types reference directive, which may be pointing at an npm package
let maybe_module = match maybe_module {
Some(Module::Js(module)) => {