Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bundle): explicit error when using an npm specifier with deno bundle #16637

Merged
merged 2 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
41 changes: 26 additions & 15 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,10 @@ async fn compile_command(
generic_error("There should only be one reference to ModuleGraph")
})?;

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)
}
error_for_any_npm_specifier(&graph)?;

graph.valid().unwrap();

let parser = ps.parsed_source_cache.as_capturing_parser();
let eszip = eszip::EszipV2::from_graph(graph, &parser, Default::default())?;
Expand Down Expand Up @@ -500,6 +488,9 @@ async fn bundle_command(
let operation = |(ps, graph): (ProcState, Arc<deno_graph::ModuleGraph>)| {
let out_file = bundle_flags.out_file.clone();
async move {
// at the moment, we don't support npm specifiers in deno bundle, so show an error
error_for_any_npm_specifier(&graph)?;

let bundle_output = bundle_module_graph(graph.as_ref(), &ps)?;
debug!(">>>>> bundle END");

Expand Down Expand Up @@ -561,6 +552,26 @@ async fn bundle_command(
Ok(0)
}

fn error_for_any_npm_specifier(
graph: &deno_graph::ModuleGraph,
) -> Result<(), AnyError> {
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 this sub command (https://github.com/denoland/deno/issues/15960). Found: {}", npm_specifier)
} else {
Ok(())
}
}

async fn doc_command(
flags: Flags,
doc_flags: DocFlags,
Expand Down
10 changes: 9 additions & 1 deletion cli/tests/integration/npm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,15 @@ fn ensure_registry_files_local() {

itest!(compile_errors {
args: "compile -A --quiet 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"),
output_str: Some("error: npm specifiers have not yet been implemented for this sub command (https://github.com/denoland/deno/issues/15960). Found: npm:chalk@5\n"),
exit_code: 1,
envs: env_vars(),
http_server: true,
});

itest!(bundle_errors {
args: "bundle --quiet npm/esm/main.js",
output_str: Some("error: npm specifiers have not yet been implemented for this sub command (https://github.com/denoland/deno/issues/15960). Found: npm:chalk@5\n"),
exit_code: 1,
envs: env_vars(),
http_server: true,
Expand Down