From 678ac5757b8283a2bb7bd0158f3c5273ea1e7eec Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 26 Oct 2022 09:55:26 -0400 Subject: [PATCH] fix(compile): show an error when using npm specifiers (#16430) Closes #16427 --- cli/main.rs | 16 ++++++++++++++++ cli/tests/integration/npm_tests.rs | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/cli/main.rs b/cli/main.rs index 1fb942963d..e9fbeba5b3 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -76,6 +76,7 @@ use crate::tools::check; use args::CliOptions; use deno_ast::MediaType; +use deno_core::anyhow::bail; use deno_core::error::generic_error; use deno_core::error::AnyError; use deno_core::error::JsError; @@ -256,6 +257,21 @@ async fn compile_command( graph.valid().unwrap(); + // at the moment, we don't support npm specifiers in deno_compile, so show an error + let first_npm_specifier = graph + .specifiers() + .values() + .filter_map(|r| match r { + Ok((specifier, kind, _)) if *kind == deno_graph::ModuleKind::External => { + Some(specifier.clone()) + } + _ => None, + }) + .next(); + if let Some(npm_specifier) = first_npm_specifier { + bail!("npm specifiers have not yet been implemented for deno compile (https://github.com/denoland/deno/issues/15960). Found: {}", npm_specifier) + } + let parser = ps.parsed_source_cache.as_capturing_parser(); let eszip = eszip::EszipV2::from_graph(graph, &parser, Default::default())?; diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs index 8fa79d06cd..722cbdb391 100644 --- a/cli/tests/integration/npm_tests.rs +++ b/cli/tests/integration/npm_tests.rs @@ -711,6 +711,14 @@ fn ensure_registry_files_local() { } } +itest!(compile_errors { + args: "compile -A --quiet --unstable npm/esm/main.js", + output_str: Some("error: npm specifiers have not yet been implemented for deno compile (https://github.com/denoland/deno/issues/15960). Found: npm:chalk@5\n"), + exit_code: 1, + envs: env_vars(), + http_server: true, +}); + fn env_vars_no_sync_download() -> Vec<(String, String)> { vec![ ("DENO_NODE_COMPAT_URL".to_string(), util::std_file_url()),