From 34f6ecfb32443b43cb0c4194dbcf457d34eaffb4 Mon Sep 17 00:00:00 2001 From: "Scott(JuJiang)" Date: Wed, 2 Nov 2016 22:54:22 +0800 Subject: [PATCH] feat: add definition for memory-fs (#12377) * feat: add definition for memory-fs * fix: enable strictNullChecks and adjust tests * feat: add standalone module definitions for memory-fs --- memory-fs/index.d.ts | 83 ++++++++++++++++++++++++++++++++ memory-fs/lib/join-tests.ts | 3 ++ memory-fs/lib/join.d.ts | 3 ++ memory-fs/lib/normalize-tests.ts | 3 ++ memory-fs/lib/normalize.d.ts | 3 ++ memory-fs/memory-fs-tests.ts | 19 ++++++++ memory-fs/tsconfig.json | 23 +++++++++ 7 files changed, 137 insertions(+) create mode 100644 memory-fs/index.d.ts create mode 100644 memory-fs/lib/join-tests.ts create mode 100644 memory-fs/lib/join.d.ts create mode 100644 memory-fs/lib/normalize-tests.ts create mode 100644 memory-fs/lib/normalize.d.ts create mode 100644 memory-fs/memory-fs-tests.ts create mode 100644 memory-fs/tsconfig.json diff --git a/memory-fs/index.d.ts b/memory-fs/index.d.ts new file mode 100644 index 0000000000..9578bb3548 --- /dev/null +++ b/memory-fs/index.d.ts @@ -0,0 +1,83 @@ +// Type definitions for memory-fs 0.3.0 +// Project: https://github.com/webpack/memory-fs +// Definitions by: e-cloud +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare class MemoryFileSystem { + data: any; + + constructor(data?: any); + + meta(_path: string): any; + + existsSync(_path: string): boolean; + + statSync(_path: string): { + isFile: () => boolean; + isDirectory: () => boolean; + isBlockDevice: () => boolean; + isCharacterDevice: () => boolean; + isSymbolicLink: () => boolean; + isFIFO: () => boolean; + isSocket: () => boolean; + }; + + readFileSync(_path: string, encoding?: string): any; + + readdirSync(_path: string): string[]; + + mkdirpSync(_path: string): void; + + mkdirSync(_path: string): void; + + _remove(_path: string, name: string, testFn: ((part: string) => boolean)): void; + + rmdirSync(_path: string): void; + + unlinkSync(_path: string): void; + + readlinkSync(_path: string): void; + + writeFileSync(_path: string, content: string | Buffer, encoding?: string): void; + + createReadStream( + path: string, options: { + start: number; + end: number; + } + ): any; + + createWriteStream(path: string, options: any): any; + + exists(path: string, callback: (isExist: boolean) => any): any; + + writeFile(path: string, content: string | Buffer, callback: (err?: Error) => any): any; + + writeFile(path: string, content: string | Buffer, encoding: string, callback: (err?: Error) => any): any; + + join(path: string, request: string): string; + + pathToArray(path: string): string[]; + + normalize(path: string): string; + + stat(path: string, callback: (err?: Error, result?: any) => any): void; + + readdir(path: string, callback: (err?: Error, result?: any) => any): void; + + mkdirp(path: string, callback: (err?: Error, result?: any) => any): void; + + rmdir(path: string, callback: (err?: Error, result?: any) => any): void; + + unlink(path: string, callback: (err?: Error, result?: any) => any): void; + + readlink(path: string, callback: (err?: Error, result?: any) => any): void; + + mkdir(path: string, optArg: {}, callback: (err?: Error, result?: any) => any): void; + + readFile(path: string, optArg: {}, callback: (err?: Error, result?: any) => any): void; +} + +export = MemoryFileSystem; diff --git a/memory-fs/lib/join-tests.ts b/memory-fs/lib/join-tests.ts new file mode 100644 index 0000000000..0394cab49f --- /dev/null +++ b/memory-fs/lib/join-tests.ts @@ -0,0 +1,3 @@ +import memoryFsJoin = require('memory-fs/lib/join'); + +memoryFsJoin('hello', 'world'); diff --git a/memory-fs/lib/join.d.ts b/memory-fs/lib/join.d.ts new file mode 100644 index 0000000000..bf15ba3185 --- /dev/null +++ b/memory-fs/lib/join.d.ts @@ -0,0 +1,3 @@ +declare function join(path: string, request: string): string; + +export = join; diff --git a/memory-fs/lib/normalize-tests.ts b/memory-fs/lib/normalize-tests.ts new file mode 100644 index 0000000000..b92c43f717 --- /dev/null +++ b/memory-fs/lib/normalize-tests.ts @@ -0,0 +1,3 @@ +import normalize = require('memory-fs/lib/normalize'); + +normalize('hello world'); diff --git a/memory-fs/lib/normalize.d.ts b/memory-fs/lib/normalize.d.ts new file mode 100644 index 0000000000..807609661d --- /dev/null +++ b/memory-fs/lib/normalize.d.ts @@ -0,0 +1,3 @@ +declare function normalize(path: string): string; + +export = normalize; diff --git a/memory-fs/memory-fs-tests.ts b/memory-fs/memory-fs-tests.ts new file mode 100644 index 0000000000..61302916be --- /dev/null +++ b/memory-fs/memory-fs-tests.ts @@ -0,0 +1,19 @@ +/// + +import MemoryFileSystem = require('memory-fs'); + +const fs = new MemoryFileSystem({}); + +fs.existsSync('./kd/sdkfj'); + +fs.writeFile('hello', 'hahahahah', function (err) { + if(err){ + console.log(err.message); + } +}); + +fs.writeFile('hello', 'hahahahah', 'utf-8', function (err) { + if(err){ + console.log(err.message); + } +}); diff --git a/memory-fs/tsconfig.json b/memory-fs/tsconfig.json new file mode 100644 index 0000000000..105762a5a1 --- /dev/null +++ b/memory-fs/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "memory-fs-tests.ts", + "lib/join-tests.ts", + "lib/join.d.ts", + "lib/normalize-tests.ts", + "lib/normalize.d.ts" + ] +}