mirror of
https://github.com/denoland/deno.git
synced 2024-11-26 16:09:27 -05:00
fix: emit when bundle contains single module (#4042)
Fixes #4031 When a bundle contains a single module, we were incorrectly determining the module name, resulting in a non-functional bundle. This PR corrects that determination.
This commit is contained in:
parent
742a16b506
commit
0e579ee9dc
3 changed files with 39 additions and 1 deletions
|
@ -306,7 +306,7 @@ export function normalizeString(
|
||||||
export function commonPath(paths: string[], sep = "/"): string {
|
export function commonPath(paths: string[], sep = "/"): string {
|
||||||
const [first = "", ...remaining] = paths;
|
const [first = "", ...remaining] = paths;
|
||||||
if (first === "" || remaining.length === 0) {
|
if (first === "" || remaining.length === 0) {
|
||||||
return "";
|
return first.substring(0, first.lastIndexOf(sep) + 1);
|
||||||
}
|
}
|
||||||
const parts = first.split(sep);
|
const parts = first.split(sep);
|
||||||
|
|
||||||
|
|
|
@ -290,6 +290,42 @@ fn bundle_circular() {
|
||||||
assert_eq!(output.stderr, b"");
|
assert_eq!(output.stderr, b"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bundle_single_module() {
|
||||||
|
use tempfile::TempDir;
|
||||||
|
|
||||||
|
// First we have to generate a bundle of some module that has exports.
|
||||||
|
let single_module =
|
||||||
|
util::root_path().join("cli/tests/subdir/single_module.ts");
|
||||||
|
assert!(single_module.is_file());
|
||||||
|
let t = TempDir::new().expect("tempdir fail");
|
||||||
|
let bundle = t.path().join("single_module.bundle.js");
|
||||||
|
let mut deno = util::deno_cmd()
|
||||||
|
.current_dir(util::root_path())
|
||||||
|
.arg("bundle")
|
||||||
|
.arg(single_module)
|
||||||
|
.arg(&bundle)
|
||||||
|
.spawn()
|
||||||
|
.expect("failed to spawn script");
|
||||||
|
let status = deno.wait().expect("failed to wait for the child process");
|
||||||
|
assert!(status.success());
|
||||||
|
assert!(bundle.is_file());
|
||||||
|
|
||||||
|
let output = util::deno_cmd()
|
||||||
|
.current_dir(util::root_path())
|
||||||
|
.arg("run")
|
||||||
|
.arg("--reload")
|
||||||
|
.arg(&bundle)
|
||||||
|
.output()
|
||||||
|
.expect("failed to spawn script");
|
||||||
|
// check the output of the the bundle program.
|
||||||
|
assert!(std::str::from_utf8(&output.stdout)
|
||||||
|
.unwrap()
|
||||||
|
.trim()
|
||||||
|
.ends_with("Hello world!"));
|
||||||
|
assert_eq!(output.stderr, b"");
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(#2933): Rewrite this test in rust.
|
// TODO(#2933): Rewrite this test in rust.
|
||||||
#[test]
|
#[test]
|
||||||
fn repl_test() {
|
fn repl_test() {
|
||||||
|
|
2
cli/tests/subdir/single_module.ts
Normal file
2
cli/tests/subdir/single_module.ts
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
console.log("Hello world!");
|
||||||
|
export {};
|
Loading…
Reference in a new issue