summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/flags.rs2
-rw-r--r--cli/tests/bundle_im.json5
-rw-r--r--cli/tests/bundle_im.ts17
-rw-r--r--cli/tests/integration_tests.rs44
4 files changed, 68 insertions, 0 deletions
diff --git a/cli/flags.rs b/cli/flags.rs
index e6b56a94a..42aa62480 100644
--- a/cli/flags.rs
+++ b/cli/flags.rs
@@ -374,6 +374,7 @@ fn install_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
fn bundle_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
ca_file_arg_parse(flags, matches);
+ importmap_arg_parse(flags, matches);
let source_file = matches.value_of("source_file").unwrap().to_string();
@@ -666,6 +667,7 @@ fn bundle_subcommand<'a, 'b>() -> App<'a, 'b> {
)
.arg(Arg::with_name("out_file").takes_value(true).required(false))
.arg(ca_file_arg())
+ .arg(importmap_arg())
.about("Bundle module and dependencies into single file")
.long_about(
"Output a single JavaScript file with all dependencies.
diff --git a/cli/tests/bundle_im.json b/cli/tests/bundle_im.json
new file mode 100644
index 000000000..8ebc00c5b
--- /dev/null
+++ b/cli/tests/bundle_im.json
@@ -0,0 +1,5 @@
+{
+ "imports": {
+ "mod2": "./subdir/subdir2/mod2.ts"
+ }
+}
diff --git a/cli/tests/bundle_im.ts b/cli/tests/bundle_im.ts
new file mode 100644
index 000000000..b751aa689
--- /dev/null
+++ b/cli/tests/bundle_im.ts
@@ -0,0 +1,17 @@
+import { returnsFoo, printHello2 } from "mod2";
+
+export function returnsHi(): string {
+ return "Hi";
+}
+
+export function returnsFoo2(): string {
+ return returnsFoo();
+}
+
+export function printHello3(): void {
+ printHello2();
+}
+
+export function throwsError(): void {
+ throw Error("exception from mod1");
+}
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index bef4c8d56..c22d1cfd2 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -525,6 +525,50 @@ fn bundle_dynamic_import() {
}
#[test]
+fn bundle_import_map() {
+ let import = util::root_path().join("cli/tests/bundle_im.ts");
+ let import_map_path = util::root_path().join("cli/tests/bundle_im.json");
+ assert!(import.is_file());
+ let t = TempDir::new().expect("tempdir fail");
+ let bundle = t.path().join("import_map.bundle.js");
+ let mut deno = util::deno_cmd()
+ .current_dir(util::root_path())
+ .arg("bundle")
+ .arg("--importmap")
+ .arg(import_map_path)
+ .arg(import)
+ .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());
+
+ // Now we try to use that bundle from another module.
+ let test = t.path().join("test.js");
+ std::fs::write(
+ &test,
+ "
+ import { printHello3 } from \"./import_map.bundle.js\";
+ printHello3(); ",
+ )
+ .expect("error writing file");
+
+ let output = util::deno_cmd()
+ .current_dir(util::root_path())
+ .arg("run")
+ .arg(&test)
+ .output()
+ .expect("failed to spawn script");
+ // check the output of the test.ts program.
+ assert!(std::str::from_utf8(&output.stdout)
+ .unwrap()
+ .trim()
+ .ends_with("Hello"));
+ assert_eq!(output.stderr, b"");
+}
+
+#[test]
fn repl_test_console_log() {
let (out, err) = util::run_and_collect_output(
true,