summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZheyu Zhang <zheyuzhang03@gmail.com>2021-11-24 06:59:17 +0800
committerGitHub <noreply@github.com>2021-11-23 23:59:17 +0100
commitfd6d0e309ca42f4b98ab75039eefb8a8a923fafb (patch)
tree442df54ac95d5504dbea3c3d7d5cc9c3e46b448e
parent63fc73c491600191686d355be95ee76f0002eb25 (diff)
fix(cli/compile): skip bundling for pre-bundled code (#12687)
-rw-r--r--cli/main.rs16
-rw-r--r--cli/tests/integration/compile_tests.rs37
2 files changed, 51 insertions, 2 deletions
diff --git a/cli/main.rs b/cli/main.rs
index 6e8b50599..33895ec75 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -424,7 +424,19 @@ async fn compile_command(
let graph =
create_graph_and_maybe_check(module_specifier.clone(), &ps, debug).await?;
- let (bundle_str, _) = bundle_module_graph(graph.as_ref(), &ps, &flags)?;
+
+ let source = (graph.as_ref().modules().len() == 1)
+ .then(|| {
+ let root_module = graph.as_ref().modules()[0];
+ match root_module.media_type {
+ MediaType::JavaScript => Some(Ok(root_module.source.to_string())),
+ _ => None,
+ }
+ })
+ .flatten()
+ .unwrap_or_else(|| {
+ bundle_module_graph(graph.as_ref(), &ps, &flags).map(|r| r.0)
+ })?;
info!(
"{} {}",
@@ -439,7 +451,7 @@ async fn compile_command(
let final_bin = tools::standalone::create_standalone_binary(
original_binary,
- bundle_str,
+ source,
run_flags,
)?;
diff --git a/cli/tests/integration/compile_tests.rs b/cli/tests/integration/compile_tests.rs
index 067f6b9eb..3cb628204 100644
--- a/cli/tests/integration/compile_tests.rs
+++ b/cli/tests/integration/compile_tests.rs
@@ -370,3 +370,40 @@ fn standalone_runtime_flags() {
assert!(util::strip_ansi_codes(&stderr_str)
.contains("PermissionDenied: Requires write access"));
}
+
+#[test]
+// https://github.com/denoland/deno/issues/12670
+fn skip_rebundle() {
+ let dir = TempDir::new().expect("tempdir fail");
+ let exe = if cfg!(windows) {
+ dir.path().join("hello_world.exe")
+ } else {
+ dir.path().join("hello_world")
+ };
+ let output = util::deno_cmd()
+ .current_dir(util::testdata_path())
+ .arg("compile")
+ .arg("--unstable")
+ .arg("--output")
+ .arg(&exe)
+ .arg("./001_hello.js")
+ .stdout(std::process::Stdio::piped())
+ .stderr(std::process::Stdio::piped())
+ .spawn()
+ .unwrap()
+ .wait_with_output()
+ .unwrap();
+ assert!(output.status.success());
+
+ //no "Bundle testdata_path/001_hello.js" in output
+ assert!(!String::from_utf8(output.stderr).unwrap().contains("Bundle"));
+
+ let output = Command::new(exe)
+ .stdout(std::process::Stdio::piped())
+ .spawn()
+ .unwrap()
+ .wait_with_output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_eq!(output.stdout, "Hello World\n".as_bytes());
+}