Skip to content

Commit a8cd4ab

Browse files
committed
Merge branch 'master' into loader/wasm
2 parents 22e4670 + 9837d32 commit a8cd4ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1532
-1640
lines changed

cli/compilers/ts.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,20 +156,23 @@ impl CompiledFileMetadata {
156156
}
157157
/// Creates the JSON message send to compiler.ts's onmessage.
158158
fn req(
159+
request_type: msg::CompilerRequestType,
159160
root_names: Vec<String>,
160161
compiler_config: CompilerConfig,
161-
bundle: Option<String>,
162+
out_file: Option<String>,
162163
) -> Buf {
163164
let j = match (compiler_config.path, compiler_config.content) {
164165
(Some(config_path), Some(config_data)) => json!({
166+
"type": request_type as i32,
165167
"rootNames": root_names,
166-
"bundle": bundle,
168+
"outFile": out_file,
167169
"configPath": config_path,
168170
"config": str::from_utf8(&config_data).unwrap(),
169171
}),
170172
_ => json!({
173+
"type": request_type as i32,
171174
"rootNames": root_names,
172-
"bundle": bundle,
175+
"outFile": out_file,
173176
}),
174177
};
175178

@@ -250,15 +253,20 @@ impl TsCompiler {
250253
self: &Self,
251254
global_state: ThreadSafeGlobalState,
252255
module_name: String,
253-
out_file: String,
256+
out_file: Option<String>,
254257
) -> impl Future<Item = (), Error = ErrBox> {
255258
debug!(
256259
"Invoking the compiler to bundle. module_name: {}",
257260
module_name
258261
);
259262

260263
let root_names = vec![module_name.clone()];
261-
let req_msg = req(root_names, self.config.clone(), Some(out_file));
264+
let req_msg = req(
265+
msg::CompilerRequestType::Bundle,
266+
root_names,
267+
self.config.clone(),
268+
out_file,
269+
);
262270

263271
let worker = TsCompiler::setup_worker(global_state.clone());
264272
let worker_ = worker.clone();
@@ -360,7 +368,12 @@ impl TsCompiler {
360368
);
361369

362370
let root_names = vec![module_url.to_string()];
363-
let req_msg = req(root_names, self.config.clone(), None);
371+
let req_msg = req(
372+
msg::CompilerRequestType::Compile,
373+
root_names,
374+
self.config.clone(),
375+
None,
376+
);
364377

365378
let worker = TsCompiler::setup_worker(global_state.clone());
366379
let worker_ = worker.clone();
@@ -709,7 +722,7 @@ mod tests {
709722
.bundle_async(
710723
state.clone(),
711724
module_name,
712-
String::from("$deno$/bundle.js"),
725+
Some(String::from("$deno$/bundle.js")),
713726
)
714727
.then(|result| {
715728
assert!(result.is_ok());

cli/compilers/wasm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::file_fetcher::SourceFile;
1010

1111
// Ref: https://webassembly.github.io/esm-integration/js-api/index.html#esm-integration
1212

13-
// Only default exports is support atm.
13+
// Only default exports is support ATM.
1414
// Node.js supports named import since its dynamic module creation allows
1515
// running some code before transformation:
1616
// https://github.com/nodejs/node/blob/35ec01097b2a397ad0a22aac536fe07514876e21/lib/internal/modules/esm/translators.js#L190-L210

cli/flags.rs

Lines changed: 200 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use clap::Arg;
66
use clap::ArgMatches;
77
use clap::Shell;
88
use clap::SubCommand;
9-
use deno::ModuleSpecifier;
109
use log::Level;
1110
use std;
1211
use std::str;
@@ -259,11 +258,16 @@ compiler.",
259258
SubCommand::with_name("bundle")
260259
.about("Bundle module and dependencies into single file")
261260
.long_about(
262-
"Output a single JavaScript file with all dependencies
261+
"Output a single JavaScript file with all dependencies.
262+
263+
If a out_file argument is omitted, the output of the bundle will be sent to
264+
standard out.
263265
264266
Example:
265267
266-
deno bundle https://deno.land/std/examples/colors.ts"
268+
deno bundle https://deno.land/std/examples/colors.ts
269+
270+
deno bundle https://deno.land/std/examples/colors.ts colors.bundle.js"
267271
)
268272
.arg(Arg::with_name("source_file").takes_value(true).required(true))
269273
.arg(Arg::with_name("out_file").takes_value(true).required(false)),
@@ -335,12 +339,111 @@ This command has implicit access to all permissions (equivalent to deno run --al
335339
Automatically downloads Prettier dependencies on first run.
336340
337341
deno fmt myfile1.ts myfile2.ts",
338-
).arg(
342+
)
343+
.arg(
339344
Arg::with_name("stdout")
340345
.long("stdout")
341346
.help("Output formated code to stdout")
342347
.takes_value(false),
343-
).arg(
348+
)
349+
.arg(
350+
Arg::with_name("print-width")
351+
.long("print-width")
352+
.value_name("int")
353+
.help("Specify the line length that the printer will wrap on.")
354+
.takes_value(true)
355+
.require_equals(true)
356+
)
357+
.arg(
358+
Arg::with_name("tab-width")
359+
.long("tab-width")
360+
.value_name("int")
361+
.help("Specify the number of spaces per indentation-level.")
362+
.takes_value(true)
363+
.require_equals(true)
364+
)
365+
.arg(
366+
Arg::with_name("use-tabs")
367+
.long("use-tabs")
368+
.help("Indent lines with tabs instead of spaces.")
369+
.takes_value(false)
370+
)
371+
.arg(
372+
Arg::with_name("no-semi")
373+
.long("no-semi")
374+
.help("Print semicolons at the ends of statements.")
375+
.takes_value(false)
376+
)
377+
.arg(
378+
Arg::with_name("single-quote")
379+
.long("single-quote")
380+
.help("Use single quotes instead of double quotes.")
381+
.takes_value(false)
382+
)
383+
.arg(
384+
Arg::with_name("quote-props")
385+
.long("quote-props")
386+
.value_name("as-needed|consistent|preserve")
387+
.help("Change when properties in objects are quoted.")
388+
.takes_value(true)
389+
.possible_values(&["as-needed", "consistent", "preserve"])
390+
.require_equals(true)
391+
)
392+
.arg(
393+
Arg::with_name("jsx-single-quote")
394+
.long("jsx-single-quote")
395+
.help("Use single quotes instead of double quotes in JSX.")
396+
.takes_value(false)
397+
)
398+
.arg(
399+
Arg::with_name("jsx-bracket-same-line")
400+
.long("jsx-bracket-same-line")
401+
.help(
402+
"Put the > of a multi-line JSX element at the end of the last line
403+
instead of being alone on the next line (does not apply to self closing elements)."
404+
)
405+
.takes_value(false)
406+
)
407+
.arg(
408+
Arg::with_name("trailing-comma")
409+
.long("trailing-comma")
410+
.help("Print trailing commas wherever possible when multi-line.")
411+
.takes_value(false)
412+
)
413+
.arg(
414+
Arg::with_name("no-bracket-spacing")
415+
.long("no-bracket-spacing")
416+
.help("Print spaces between brackets in object literals.")
417+
.takes_value(false)
418+
)
419+
.arg(
420+
Arg::with_name("arrow-parens")
421+
.long("arrow-parens")
422+
.value_name("avoid|always")
423+
.help("Include parentheses around a sole arrow function parameter.")
424+
.takes_value(true)
425+
.possible_values(&["avoid", "always"])
426+
.require_equals(true)
427+
)
428+
.arg(
429+
Arg::with_name("prose-wrap")
430+
.long("prose-wrap")
431+
.value_name("always|never|preserve")
432+
.help("How to wrap prose.")
433+
.takes_value(true)
434+
.possible_values(&["always", "never", "preserve"])
435+
.require_equals(true)
436+
)
437+
.arg(
438+
Arg::with_name("end-of-line")
439+
.long("end-of-line")
440+
.value_name("auto|lf|crlf|cr")
441+
.help("Which end of line characters to apply.")
442+
.takes_value(true)
443+
.possible_values(&["auto", "lf", "crlf", "cr"])
444+
.require_equals(true)
445+
)
446+
.arg(
344447
Arg::with_name("files")
345448
.takes_value(true)
346449
.multiple(true)
@@ -793,32 +896,6 @@ pub enum DenoSubcommand {
793896
Version,
794897
}
795898

796-
fn get_default_bundle_filename(source_file: &str) -> String {
797-
let specifier = ModuleSpecifier::resolve_url_or_path(source_file).unwrap();
798-
let path_segments = specifier.as_url().path_segments().unwrap();
799-
let file_name = path_segments.filter(|s| !s.is_empty()).last().unwrap();
800-
let file_stem = file_name.trim_end_matches(".ts").trim_end_matches(".js");
801-
format!("{}.bundle.js", file_stem)
802-
}
803-
804-
#[test]
805-
fn test_get_default_bundle_filename() {
806-
assert_eq!(get_default_bundle_filename("blah.ts"), "blah.bundle.js");
807-
assert_eq!(
808-
get_default_bundle_filename("http://example.com/blah.ts"),
809-
"blah.bundle.js"
810-
);
811-
assert_eq!(get_default_bundle_filename("blah.js"), "blah.bundle.js");
812-
assert_eq!(
813-
get_default_bundle_filename("http://example.com/blah.js"),
814-
"blah.bundle.js"
815-
);
816-
assert_eq!(
817-
get_default_bundle_filename("http://zombo.com/stuff/"),
818-
"stuff.bundle.js"
819-
);
820-
}
821-
822899
pub fn flags_from_vec(
823900
args: Vec<String>,
824901
) -> (DenoFlags, DenoSubcommand, Vec<String>) {
@@ -835,11 +912,13 @@ pub fn flags_from_vec(
835912
("bundle", Some(bundle_match)) => {
836913
flags.allow_write = true;
837914
let source_file: &str = bundle_match.value_of("source_file").unwrap();
838-
let out_file = bundle_match
839-
.value_of("out_file")
840-
.map(String::from)
841-
.unwrap_or_else(|| get_default_bundle_filename(source_file));
842-
argv.extend(vec![source_file.to_string(), out_file.to_string()]);
915+
let out_file = bundle_match.value_of("out_file").map(String::from);
916+
match out_file {
917+
Some(out_file) => {
918+
argv.extend(vec![source_file.to_string(), out_file.to_string()])
919+
}
920+
_ => argv.extend(vec![source_file.to_string()]),
921+
}
843922
DenoSubcommand::Bundle
844923
}
845924
("completions", Some(completions_match)) => {
@@ -886,6 +965,36 @@ pub fn flags_from_vec(
886965
argv.push("--write".to_string());
887966
}
888967

968+
let prettier_flags = [
969+
["1", "print-width"],
970+
["1", "tab-width"],
971+
["0", "use-tabs"],
972+
["0", "no-semi"],
973+
["0", "single-quote"],
974+
["1", "quote-props"],
975+
["0", "jsx-single-quote"],
976+
["0", "jsx-bracket-same-line"],
977+
["0", "trailing-comma"],
978+
["0", "no-bracket-spacing"],
979+
["1", "arrow-parens"],
980+
["1", "prose-wrap"],
981+
["1", "end-of-line"],
982+
];
983+
984+
for opt in &prettier_flags {
985+
let t = opt[0];
986+
let keyword = opt[1];
987+
988+
if fmt_match.is_present(&keyword) {
989+
if t == "0" {
990+
argv.push(format!("--{}", keyword));
991+
} else {
992+
argv.push(format!("--{}", keyword));
993+
argv.push(fmt_match.value_of(keyword).unwrap().to_string());
994+
}
995+
}
996+
}
997+
889998
DenoSubcommand::Run
890999
}
8911000
("info", Some(info_match)) => {
@@ -1928,4 +2037,59 @@ mod tests {
19282037
assert_eq!(subcommand, DenoSubcommand::Run);
19292038
assert_eq!(argv, svec!["deno", "script.ts"])
19302039
}
2040+
2041+
#[test]
2042+
fn test_flags_from_vec_39() {
2043+
let (flags, subcommand, argv) = flags_from_vec(svec![
2044+
"deno",
2045+
"fmt",
2046+
"--print-width=100",
2047+
"--tab-width=4",
2048+
"--use-tabs",
2049+
"--no-semi",
2050+
"--single-quote",
2051+
"--arrow-parens=always",
2052+
"--prose-wrap=preserve",
2053+
"--end-of-line=crlf",
2054+
"--quote-props=preserve",
2055+
"--jsx-single-quote",
2056+
"--jsx-bracket-same-line",
2057+
"script.ts"
2058+
]);
2059+
assert_eq!(
2060+
flags,
2061+
DenoFlags {
2062+
allow_write: true,
2063+
allow_read: true,
2064+
..DenoFlags::default()
2065+
}
2066+
);
2067+
assert_eq!(subcommand, DenoSubcommand::Run);
2068+
assert_eq!(
2069+
argv,
2070+
svec![
2071+
"deno",
2072+
PRETTIER_URL,
2073+
"script.ts",
2074+
"--write",
2075+
"--print-width",
2076+
"100",
2077+
"--tab-width",
2078+
"4",
2079+
"--use-tabs",
2080+
"--no-semi",
2081+
"--single-quote",
2082+
"--quote-props",
2083+
"preserve",
2084+
"--jsx-single-quote",
2085+
"--jsx-bracket-same-line",
2086+
"--arrow-parens",
2087+
"always",
2088+
"--prose-wrap",
2089+
"preserve",
2090+
"--end-of-line",
2091+
"crlf"
2092+
]
2093+
);
2094+
}
19312095
}

0 commit comments

Comments
 (0)