Merge pull request #24290 from ciferox/adone

[adone] refactoring, additions
This commit is contained in:
Mine Starks
2018-03-21 09:42:11 -07:00
committed by GitHub
8 changed files with 86 additions and 33 deletions

View File

@@ -1,4 +1,6 @@
/// <reference types="node" />
/// <reference types="lodash" />
/// <reference types="benchmark" />
declare namespace adone {
const _null: symbol;
@@ -104,4 +106,8 @@ declare namespace adone {
export const expect: assertion.I.ExpectFunction;
export const std: typeof nodestd;
export const lodash: _.LoDashStatic;
export const benchmark: typeof tbenchmark;
}

5
types/adone/benchmark.d.ts vendored Normal file
View File

@@ -0,0 +1,5 @@
import Benchmark = require("benchmark");
export { Benchmark };
export as namespace tbenchmark;

View File

@@ -1158,37 +1158,35 @@ declare namespace adone {
*/
function watch(paths: string | string[], options?: I.Watcher.ConstructorOptions): Watcher;
namespace is {
/**
* Returns true if the given path refers to a file
*/
function file(path: string): Promise<boolean>;
/**
* Returns true if the given path refers to a file
*/
function isFile(path: string): Promise<boolean>;
/**
* Returns true if the given path refers to a file
*/
function fileSync(path: string): boolean;
/**
* Returns true if the given path refers to a file
*/
function isFileSync(path: string): boolean;
/**
* Returns true if the given path refers to a direcotry
*/
function directory(path: string): Promise<boolean>;
/**
* Returns true if the given path refers to a direcotry
*/
function isDirectory(path: string): Promise<boolean>;
/**
* Returns true if the given path refers to a direcotry
*/
function directorySync(path: string): boolean;
/**
* Returns true if the given path refers to a direcotry
*/
function isDirectorySync(path: string): boolean;
/**
* Returns true if the given path refers to an executable file
*/
function executable(path: string): Promise<boolean>;
/**
* Returns true if the given path refers to an executable file
*/
function isExecutable(path: string): Promise<boolean>;
/**
* Returns true if the given path refers to an executable file
*/
function executableSync(path: string): boolean;
}
/**
* Returns true if the given path refers to an executable file
*/
function isExecutableSync(path: string): boolean;
namespace I.Which {
interface Options {
@@ -1920,5 +1918,19 @@ declare namespace adone {
* Creates a new TailWatcher instance with the given arguments
*/
function watchTail(filename: string, options?: I.TailWatcher.ConstructorOptions): TailWatcher;
namespace I {
interface WriteFileAtomicOptions {
chown?: {
gid?: number;
uid?: number;
};
encoding?: string | null;
fsync?: boolean;
mode?: number;
}
}
function writeFileAtomic(filename: string, data: Buffer | string | Uint8Array, options?: I.WriteFileAtomicOptions): Promise<void>;
}
}

View File

@@ -676,5 +676,9 @@ declare namespace adone {
export function emitter(obj: any): obj is event.Emitter;
export function asyncEmitter(obj: any): obj is event.AsyncEmitter;
export const openbsd: boolean;
export const aix: boolean;
}
}

View File

@@ -602,13 +602,12 @@ namespace fsTests {
}
namespace isTests {
const { is } = fs;
is.file("hello").then((x: boolean) => {});
{ const a: boolean = is.fileSync("hello"); }
is.directory("hello").then((x: boolean) => {});
{ const a: boolean = is.directorySync("hello"); }
is.executable("hello").then((x: boolean) => {});
{ const a: boolean = is.executableSync("hello"); }
fs.isFile("hello").then((x: boolean) => {});
{ const a: boolean = fs.isFileSync("hello"); }
fs.isDirectory("hello").then((x: boolean) => {});
{ const a: boolean = fs.isDirectorySync("hello"); }
fs.isExecutable("hello").then((x: boolean) => {});
{ const a: boolean = fs.isExecutableSync("hello"); }
}
namespace whichTests {
@@ -944,4 +943,17 @@ namespace fsTests {
fs.watchTail("file", { separator: /\n/ });
fs.watchTail("file", { useWatchFile: true });
}
namespace writeFileAtomicTests {
fs.writeFileAtomic("a", "b").then(() => {});
fs.writeFileAtomic("a", Buffer.from("b")).then(() => {});
fs.writeFileAtomic("a", new Uint8Array(10)).then(() => {});
fs.writeFileAtomic("a", "a", {}).then(() => {});
fs.writeFileAtomic("a", "a", { chown: {} }).then(() => {});
fs.writeFileAtomic("a", "a", { chown: { gid: 0 } }).then(() => {});
fs.writeFileAtomic("a", "a", { chown: { uid: 0 } }).then(() => {});
fs.writeFileAtomic("a", "a", { encoding: "utf8" }).then(() => {});
fs.writeFileAtomic("a", "a", { fsync: false }).then(() => {});
fs.writeFileAtomic("a", "a", { mode: 0o666 }).then(() => {});
}
}

View File

@@ -336,6 +336,8 @@ namespace isTests {
{ const a: boolean = is.freebsd; }
{ const a: boolean = is.darwin; }
{ const a: boolean = is.sunos; }
{ const a: boolean = is.openbsd; }
{ const a: boolean = is.aix; }
{ const a: boolean = is.uppercase("abc"); }
{ const a: boolean = is.lowercase("abc"); }
{ const a: boolean = is.digits("012"); }

View File

@@ -54,4 +54,15 @@ namespace AdoneRootTests {
obj = adone.package;
{ const a: typeof adone.assertion.assert = adone.assert; }
{ const a: typeof adone.assertion.expect = adone.expect; }
namespace lodashTests {
adone.lodash.get({}, "a");
adone.lodash.defaults({}, {});
adone.lodash.zip([]);
}
namespace benchmarkTests {
const b = new adone.benchmark.Benchmark.Suite();
b.add(() => {}).add("", () => {}).run();
}
}

View File

@@ -22,6 +22,7 @@
"files": [
"adone-tests.ts",
"adone.d.ts",
"benchmark.d.ts",
"glosses/archives.d.ts",
"glosses/assertion.d.ts",
"glosses/collections/array_set.d.ts",