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

feat: add --importmap flag to deno bundle #4651

Merged
merged 2 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions cli/tests/bundle_im.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"imports": {
"mod2": "./subdir/subdir2/mod2.ts"
}
}
17 changes: 17 additions & 0 deletions cli/tests/bundle_im.ts
Original file line number Diff line number Diff line change
@@ -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");
}
44 changes: 44 additions & 0 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,50 @@ fn bundle_dynamic_import() {
assert_eq!(output.stderr, b"");
}

#[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(
Expand Down