mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
feat: add --importmap flag to deno bundle (#4651)
This commit is contained in:
parent
47a580293e
commit
dd3a94933a
4 changed files with 68 additions and 0 deletions
|
@ -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.
|
||||
|
|
5
cli/tests/bundle_im.json
Normal file
5
cli/tests/bundle_im.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"imports": {
|
||||
"mod2": "./subdir/subdir2/mod2.ts"
|
||||
}
|
||||
}
|
17
cli/tests/bundle_im.ts
Normal file
17
cli/tests/bundle_im.ts
Normal file
|
@ -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");
|
||||
}
|
|
@ -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(
|
||||
|
|
Loading…
Add table
Reference in a new issue