diff --git a/types/mem-fs-editor/index.d.ts b/types/mem-fs-editor/index.d.ts index 01234bbc0c..60f5b51867 100644 --- a/types/mem-fs-editor/index.d.ts +++ b/types/mem-fs-editor/index.d.ts @@ -17,30 +17,33 @@ export function create(store: Store): memFsEditor.Editor; export namespace memFsEditor { type Contents = string|Buffer; - type ReplacerFunc = (key: string, value: any) => string|null|undefined; + type ReplacerFunc = (key: string, value: any) => any; type Space = string|number; type ProcessFunc = (contents: Buffer) => Contents; + type Callback = (err: any) => any; + interface CopyOptions { process?: ProcessFunc; globOptions?: GlobOptions; } interface Editor { - read: (filepath: string, options?: { raw: boolean, defaults: string }) => string; - readJSON: (filepath: string, defaults?: string) => string; - write: (filepath: string, contents: Contents) => void; - writeJSON: (filepath: string, contents: object, replacer?: ReplacerFunc, space?: Space) => void; - append: (filepath: string, contents: Contents, options?: { trimEnd: boolean, separator: string }) => void; - extendJSON: (filepath: string, contents: object, replacer?: ReplacerFunc, space?: Space) => void; - delete: (filepath: string, options?: { globOptions: GlobOptions }) => void; - copy: (from: string, to: string, options?: CopyOptions) => void; - copyTpl: (from: string, to: string, context: object, templateOptions?: TemplateOptions, copyOptions?: CopyOptions) => void; - move: (from: string, to: string, options?: { globOptions: GlobOptions }) => void; - exists: (filepath: string) => boolean; - commit: (filters: ReadonlyArray, callback: () => void) => void; + read(filepath: string, options?: { raw: boolean, defaults: string }): string; + readJSON(filepath: string, defaults?: any): any; + write(filepath: string, contents: Contents): void; + writeJSON(filepath: string, contents: any, replacer?: ReplacerFunc, space?: Space): void; + append(filepath: string, contents: Contents, options?: { trimEnd: boolean, separator: string }): void; + extendJSON(filepath: string, contents: object, replacer?: ReplacerFunc, space?: Space): void; + delete(filepath: string, options?: { globOptions: GlobOptions }): void; + copy(from: string, to: string, options?: CopyOptions): void; + copyTpl(from: string, to: string, context: object, templateOptions?: TemplateOptions, copyOptions?: CopyOptions): void; + move(from: string, to: string, options?: { globOptions: GlobOptions }): void; + exists(filepath: string): boolean; + commit(callback: Callback): void; + commit(filters: ReadonlyArray, callback: Callback): void; } const prototype: { diff --git a/types/mem-fs-editor/mem-fs-editor-tests.ts b/types/mem-fs-editor/mem-fs-editor-tests.ts index 355c714bf9..ff3c52c5a0 100644 --- a/types/mem-fs-editor/mem-fs-editor-tests.ts +++ b/types/mem-fs-editor/mem-fs-editor-tests.ts @@ -1,3 +1,5 @@ +import { Transform } from 'stream'; + import memFs = require('mem-fs'); import editor = require('mem-fs-editor'); @@ -16,3 +18,17 @@ fs.copy('template.js', 'template.tpl', { fs.copyTpl('template.tpl', 'output.js', { foo: 'bar' }); + +const obj = fs.readJSON('template.json'); +fs.writeJSON('template.json', obj); +fs.extendJSON('template.json', {qwer: 'asdf'}); + +fs.writeJSON('template.json', 'qwer'); // should not be an error, because the parameter is passed to JSON.stringify and it accepts the string +// fs.extendJSON('template.json', 'qwer'); // should be an error, because it does not make sense to extend a json with string + +// should accept both versions of commit - with filters and without: +const cb = (err: any) => ({adsf: 'adsf'}); +fs.commit(cb); + +const filters: Transform[] = []; +fs.commit(filters, cb);