Skip to content

Commit

Permalink
Merge remote-tracking branch 'denoland/master' into filesystem8e
Browse files Browse the repository at this point in the history
* denoland/master:
  feat (std/encoding): add binary module (denoland#4274)
  refactor(cli/js/net): Cleanup iterable APIs (denoland#4236)
  Add Deno.umask (denoland#4290)
  refactor: Cleanup options object parameters (denoland#4296)
  refactor: uncomment tests broken tests, use skip (denoland#4311)
  Add global "quiet" flag (denoland#4135)
  • Loading branch information
dubiousjim committed Mar 10, 2020
2 parents 76eeade + a309dcd commit 4843169
Show file tree
Hide file tree
Showing 39 changed files with 1,017 additions and 471 deletions.
4 changes: 3 additions & 1 deletion cli/compilers/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use deno_core::Buf;
use deno_core::ErrBox;
use deno_core::ModuleSpecifier;
use futures::future::FutureExt;
use log::info;
use regex::Regex;
use serde_json::json;
use std::collections::HashMap;
Expand Down Expand Up @@ -373,11 +374,12 @@ impl TsCompiler {

let ts_compiler = self.clone();

eprintln!(
info!(
"{} {}",
colors::green("Compile".to_string()),
module_url.to_string()
);

let msg = execute_in_thread(global_state.clone(), req_msg).await?;

let json_str = std::str::from_utf8(&msg).unwrap();
Expand Down
6 changes: 3 additions & 3 deletions cli/file_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use crate::op_error::OpError;
use deno_core::ErrBox;
use deno_core::ModuleSpecifier;
use futures::future::FutureExt;
use log::info;
use regex::Regex;
use reqwest;
use std;
use std::collections::HashMap;
use std::fs;
use std::future::Future;
Expand All @@ -23,7 +23,6 @@ use std::result::Result;
use std::str;
use std::sync::Arc;
use std::sync::Mutex;
use url;
use url::Url;

/// Structure representing local or remote file.
Expand Down Expand Up @@ -414,11 +413,12 @@ impl SourceFileFetcher {
.boxed_local();
}

eprintln!(
info!(
"{} {}",
colors::green("Download".to_string()),
module_url.to_string()
);

let dir = self.clone();
let module_url = module_url.clone();
let module_etag = match self.http_cache.get(&module_url) {
Expand Down
41 changes: 30 additions & 11 deletions cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub enum DenoSubcommand {
},
Test {
fail_fast: bool,
quiet: bool,
allow_none: bool,
include: Option<Vec<String>>,
},
Expand Down Expand Up @@ -231,6 +230,9 @@ pub fn flags_from_vec_safe(args: Vec<String>) -> clap::Result<Flags> {
_ => unreachable!(),
};
}
if matches.is_present("quiet") {
flags.log_level = Some(Level::Error);
}

if let Some(m) = matches.subcommand_matches("run") {
run_parse(&mut flags, m);
Expand Down Expand Up @@ -283,6 +285,18 @@ fn clap_root<'a, 'b>() -> App<'a, 'b> {
.possible_values(&["debug", "info"])
.global(true),
)
.arg(
Arg::with_name("quiet")
.short("q")
.long("quiet")
.help("Suppress diagnostic output")
.long_help(
"Suppress diagnostic output
By default, subcommands print human-readable diagnostic messages to stderr.
If the flag is set, restrict these messages to errors.",
)
.global(true),
)
.subcommand(bundle_subcommand())
.subcommand(completions_subcommand())
.subcommand(eval_subcommand())
Expand Down Expand Up @@ -505,7 +519,6 @@ fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) {

run_test_args_parse(flags, matches);

let quiet = matches.is_present("quiet");
let failfast = matches.is_present("failfast");
let allow_none = matches.is_present("allow_none");

Expand All @@ -521,7 +534,6 @@ fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
};

flags.subcommand = DenoSubcommand::Test {
quiet,
fail_fast: failfast,
include,
allow_none,
Expand Down Expand Up @@ -866,13 +878,6 @@ fn test_subcommand<'a, 'b>() -> App<'a, 'b> {
.help("Stop on first error")
.takes_value(false),
)
.arg(
Arg::with_name("quiet")
.short("q")
.long("quiet")
.help("Don't show output from test cases")
.takes_value(false),
)
.arg(
Arg::with_name("allow_none")
.long("allow-none")
Expand Down Expand Up @@ -1947,6 +1952,21 @@ mod tests {
);
}

#[test]
fn quiet() {
let r = flags_from_vec_safe(svec!["deno", "-q", "script.ts"]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
log_level: Some(Level::Error),
..Flags::default()
}
);
}

#[test]
fn completions() {
let r = flags_from_vec_safe(svec!["deno", "completions", "bash"]).unwrap();
Expand Down Expand Up @@ -2109,7 +2129,6 @@ mod tests {
Flags {
subcommand: DenoSubcommand::Test {
fail_fast: false,
quiet: false,
allow_none: true,
include: Some(svec!["dir1/", "dir2/"]),
},
Expand Down
12 changes: 6 additions & 6 deletions cli/js/compiler_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,12 @@ export interface TranspileOnlyResult {
*/
export async function transpileOnly(
sources: Record<string, string>,
options?: CompilerOptions
options: CompilerOptions = {}
): Promise<Record<string, TranspileOnlyResult>> {
util.log("Deno.transpileOnly", { sources: Object.keys(sources), options });
const payload = {
sources,
options: options ? JSON.stringify(options) : undefined
options: JSON.stringify(options)
};
const result = await runtimeCompilerOps.transpile(payload);
return JSON.parse(result);
Expand Down Expand Up @@ -343,12 +343,12 @@ export async function transpileOnly(
export async function compile(
rootName: string,
sources?: Record<string, string>,
options?: CompilerOptions
options: CompilerOptions = {}
): Promise<[DiagnosticItem[] | undefined, Record<string, string>]> {
const payload = {
rootName: sources ? rootName : checkRelative(rootName),
sources,
options: options ? JSON.stringify(options) : undefined,
options: JSON.stringify(options),
bundle: false
};
util.log("Deno.compile", {
Expand Down Expand Up @@ -391,12 +391,12 @@ export async function compile(
export async function bundle(
rootName: string,
sources?: Record<string, string>,
options?: CompilerOptions
options: CompilerOptions = {}
): Promise<[DiagnosticItem[] | undefined, string]> {
const payload = {
rootName: sources ? rootName : checkRelative(rootName),
sources,
options: options ? JSON.stringify(options) : undefined,
options: JSON.stringify(options),
bundle: true
};
util.log("Deno.bundle", {
Expand Down
3 changes: 1 addition & 2 deletions cli/js/compiler_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ export class Host implements ts.CompilerHost {
/* Deno specific APIs */

/** Provides the `ts.HostCompiler` interface for Deno. */
constructor(options: CompilerHostOptions) {
const { bundle = false, target, writeFile } = options;
constructor({ bundle = false, target, writeFile }: CompilerHostOptions) {
this._target = target;
this._writeFile = writeFile;
if (bundle) {
Expand Down
32 changes: 9 additions & 23 deletions cli/js/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ function createObjectString(
/** @internal */
export function stringifyArgs(
args: unknown[],
options: ConsoleOptions = {}
{ depth = DEFAULT_MAX_DEPTH, indentLevel = 0 }: ConsoleOptions = {}
): string {
const first = args[0];
let a = 0;
Expand Down Expand Up @@ -411,12 +411,7 @@ export function stringifyArgs(
case CHAR_LOWERCASE_O:
case CHAR_UPPERCASE_O:
// format as an object
tempStr = stringify(
args[++a],
new Set<unknown>(),
0,
options.depth != undefined ? options.depth : DEFAULT_MAX_DEPTH
);
tempStr = stringify(args[++a], new Set<unknown>(), 0, depth);
break;
case CHAR_PERCENT:
str += first.slice(lastPos, i);
Expand Down Expand Up @@ -459,19 +454,13 @@ export function stringifyArgs(
str += value;
} else {
// use default maximum depth for null or undefined argument
str += stringify(
value,
new Set<unknown>(),
0,
options.depth != undefined ? options.depth : DEFAULT_MAX_DEPTH
);
str += stringify(value, new Set<unknown>(), 0, depth);
}
join = " ";
a++;
}

const { indentLevel } = options;
if (indentLevel != null && indentLevel > 0) {
if (indentLevel > 0) {
const groupIndent = " ".repeat(indentLevel);
if (str.indexOf("\n") !== -1) {
str = str.replace(/\n/g, `\n${groupIndent}`);
Expand Down Expand Up @@ -771,17 +760,14 @@ export const customInspect = Symbol.for("Deno.customInspect");
* `inspect()` converts input into string that has the same format
* as printed by `console.log(...)`;
*/
export function inspect(value: unknown, options?: ConsoleOptions): string {
const opts = options || {};
export function inspect(
value: unknown,
{ depth = DEFAULT_MAX_DEPTH }: ConsoleOptions = {}
): string {
if (typeof value === "string") {
return value;
} else {
return stringify(
value,
new Set<unknown>(),
0,
opts.depth != undefined ? opts.depth : DEFAULT_MAX_DEPTH
);
return stringify(value, new Set<unknown>(), 0, depth);
}
}

Expand Down
1 change: 1 addition & 0 deletions cli/js/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export { symlinkSync, symlink } from "./ops/fs/symlink.ts";
export { connectTLS, listenTLS } from "./tls.ts";
export { truncateSync, truncate } from "./ops/fs/truncate.ts";
export { isatty, setRaw } from "./ops/tty.ts";
export { umask } from "./ops/fs/umask.ts";
export { utimeSync, utime } from "./ops/fs/utime.ts";
export { version } from "./version.ts";
export { writeFileSync, writeFile, WriteFileOptions } from "./write_file.ts";
Expand Down
12 changes: 10 additions & 2 deletions cli/js/lib.deno.ns.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ declare namespace Deno {
*/
export function chdir(directory: string): void;

/**
* **UNSTABLE**: New API. Maybe needs permissions.
*
* If `mask` is provided, sets the process umask. Always returns what the umask
* was before the call.
*/
export function umask(mask?: number): number;

/** **UNSTABLE**: might move to `Deno.symbols`. */
export const EOF: unique symbol;
export type EOF = typeof EOF;
Expand Down Expand Up @@ -1518,7 +1526,7 @@ declare namespace Deno {
/** **UNSTABLE**: new API, yet to be vetted.
*
* A generic transport listener for message-oriented protocols. */
export interface UDPConn extends AsyncIterator<[Uint8Array, Addr]> {
export interface UDPConn extends AsyncIterable<[Uint8Array, Addr]> {
/** **UNSTABLE**: new API, yet to be vetted.
*
* Waits for and resolves to the next message to the `UDPConn`. */
Expand All @@ -1538,7 +1546,7 @@ declare namespace Deno {
}

/** A generic network listener for stream-oriented protocols. */
export interface Listener extends AsyncIterator<Conn> {
export interface Listener extends AsyncIterable<Conn> {
/** Waits for and resolves to the next connection to the `Listener`. */
accept(): Promise<Conn>;
/** Close closes the listener. Any pending accept promises will be rejected
Expand Down
6 changes: 3 additions & 3 deletions cli/js/lib.deno.shared_globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,11 @@ declare namespace __domTypes {
readonly total: number;
}
export interface EventListenerOptions {
capture: boolean;
capture?: boolean;
}
export interface AddEventListenerOptions extends EventListenerOptions {
once: boolean;
passive: boolean;
once?: boolean;
passive?: boolean;
}
interface AbortSignal extends EventTarget {
readonly aborted: boolean;
Expand Down
Loading

0 comments on commit 4843169

Please sign in to comment.