From 2ee15652aedb538d109c5598c2a0f63b845bdb44 Mon Sep 17 00:00:00 2001 From: Jed Mao Date: Wed, 25 Jan 2017 12:15:57 -0600 Subject: [PATCH] vinyl-fs: add undocumented allowEmpty option flag --- vinyl-fs/.editorconfig | 3 +++ vinyl-fs/index.d.ts | 21 +++++++++--------- vinyl-fs/tsconfig.json | 42 ++++++++++++++++++------------------ vinyl-fs/tslint.json | 3 +++ vinyl-fs/vinyl-fs-tests.ts | 44 +++++++++++++++++--------------------- 5 files changed, 58 insertions(+), 55 deletions(-) create mode 100644 vinyl-fs/.editorconfig create mode 100644 vinyl-fs/tslint.json diff --git a/vinyl-fs/.editorconfig b/vinyl-fs/.editorconfig new file mode 100644 index 0000000000..831139084b --- /dev/null +++ b/vinyl-fs/.editorconfig @@ -0,0 +1,3 @@ +[*.ts] +indent_style = space +indent_size = 3 diff --git a/vinyl-fs/index.d.ts b/vinyl-fs/index.d.ts index 350ee527b5..53de6a6b2c 100644 --- a/vinyl-fs/index.d.ts +++ b/vinyl-fs/index.d.ts @@ -1,25 +1,26 @@ -// Type definitions for vinyl-fs +// Type definitions for vinyl-fs 2.4 // Project: https://github.com/wearefractal/vinyl-fs // Definitions by: vvakame // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// -/// -/// declare global { namespace NodeJS { interface WritableStream { - write(buffer: any/* Vinyl.File */, cb?: Function): boolean; + write(buffer: any/* Vinyl.File */, cb?: (err?: Error) => void): boolean; } } } -import _events = require("events"); -import File = require("vinyl"); -import globStream = require("glob-stream"); +import * as _events from 'events'; +import * as File from 'vinyl'; +import * as globStream from 'glob-stream'; + +interface SrcOptions extends globStream.Options { + /** Prevents stream from emitting an error when file not found. */ + allowEmpty?: boolean; -interface ISrcOptions extends globStream.Options { /** Specifies the working directory the folder is relative to */ cwd?: string; @@ -62,7 +63,7 @@ interface ISrcOptions extends globStream.Options { * fs.src(['!b*.js', '*.js']) would not exclude any files, but this would: fs.src(['*.js', '!b*.js']) * @param opt Options Vinyl source options, changes the way the files are read, found, or stored in the vinyl stream */ -declare function src(globs: string|string[], opt?: ISrcOptions): NodeJS.ReadWriteStream; +declare function src(globs: string|string[], opt?: SrcOptions): NodeJS.ReadWriteStream; /** * This is just a glob-watcher @@ -80,7 +81,7 @@ declare function watch(globs: string|string[], cb?: (outEvt: { type: any; path: * Globs are executed in order, so negations should follow positive globs * fs.src(['!b*.js', '*.js']) would not exclude any files, but this would: fs.src(['*.js', '!b*.js']) */ -declare function watch(globs: string|string[], opt?: { interval?: number; debounceDelay?: number; cwd?: string; maxListeners?: Function; }, cb?: (outEvt: { type: any; path: any; old: any; }) => void): _events.EventEmitter; +declare function watch(globs: string|string[], opt?: { interval?: number; debounceDelay?: number; cwd?: string; maxListeners?: () => number; }, cb?: (outEvt: { type: any; path: any; old: any; }) => void): _events.EventEmitter; /** * On write the stream will save the vinyl File to disk at the folder/cwd specified. diff --git a/vinyl-fs/tsconfig.json b/vinyl-fs/tsconfig.json index 60247086b9..d8cea65d47 100644 --- a/vinyl-fs/tsconfig.json +++ b/vinyl-fs/tsconfig.json @@ -1,22 +1,22 @@ { - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6" - ], - "noImplicitAny": true, - "noImplicitThis": false, - "strictNullChecks": false, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "vinyl-fs-tests.ts" - ] -} \ No newline at end of file + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": false, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "vinyl-fs-tests.ts" + ] +} diff --git a/vinyl-fs/tslint.json b/vinyl-fs/tslint.json new file mode 100644 index 0000000000..89bca6bf0f --- /dev/null +++ b/vinyl-fs/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../tslint.json" +} diff --git a/vinyl-fs/vinyl-fs-tests.ts b/vinyl-fs/vinyl-fs-tests.ts index 795b38b4aa..41dfa92c4c 100644 --- a/vinyl-fs/vinyl-fs-tests.ts +++ b/vinyl-fs/vinyl-fs-tests.ts @@ -3,10 +3,10 @@ // from src -import vfs = require('vinyl-fs'); +import * as vfs from 'vinyl-fs'; -import path = require('path'); -import fs = require('fs'); // require('graceful-fs'); +import * as path from 'path'; +import * as fs from 'fs'; // require('graceful-fs'); // import bufEqual = require('buffer-equal'); declare var bufEqual: any; @@ -16,8 +16,8 @@ import File = require('vinyl'); // var spies = require('./spy'); declare var spies: any; -import should = require('should'); -require('mocha'); +import * as should from 'should'; +import 'mocha'; declare var gulp: any; declare var bufferStream: any; @@ -210,7 +210,7 @@ import rimraf = require('rimraf'); // var File = require('vinyl'); // var should = require('should'); -require('mocha'); +// require('mocha'); var wipeOut = function (cb: any) { rimraf(path.join(__dirname, "./out-fixtures/"), cb); @@ -374,7 +374,7 @@ describe('dest stream', function () { cwd: __dirname, path: inputPath, contents: expectedContents, - stat: { + stat: { mode: expectedMode } }); @@ -415,7 +415,7 @@ describe('dest stream', function () { cwd: __dirname, path: inputPath, contents: contentStream, - stat: { + stat: { mode: expectedMode } }); @@ -458,10 +458,8 @@ describe('dest stream', function () { cwd: __dirname, path: inputPath, contents: null, - stat: { - isDirectory: function () { - return true; - }, + stat: { + isDirectory: () => true, mode: expectedMode } }); @@ -503,7 +501,7 @@ describe('dest stream', function () { stream1.on('data', function (file: any) { file.path.should.equal(inputPath1); - }) + }); stream1.pipe(rename).pipe(stream2); stream2.on('data', function (file: any) { @@ -519,11 +517,11 @@ describe('dest stream', function () { path: inputPath1, cwd: __dirname, contents: content - }) + }); stream1.write(file); stream1.end(); - }) + }); }); @@ -708,7 +706,7 @@ describe('symlink stream', function () { cwd: __dirname, path: inputPath, contents: expectedContents, - stat: { + stat: { mode: expectedMode } }); @@ -749,7 +747,7 @@ describe('symlink stream', function () { cwd: __dirname, path: inputPath, contents: contentStream, - stat: { + stat: { mode: expectedMode } }); @@ -792,10 +790,8 @@ describe('symlink stream', function () { cwd: __dirname, path: inputPath, contents: null, - stat: { - isDirectory: function () { - return true; - }, + stat: { + isDirectory: () => true, mode: expectedMode } }); @@ -869,7 +865,7 @@ describe('symlink stream', function () { cwd: __dirname, path: inputPath, contents: expectedContents, - stat: { + stat: { mode: expectedMode } }); @@ -878,7 +874,7 @@ describe('symlink stream', function () { fs.chmodSync(expectedBase, 0); var stream = vfs.symlink('./out-fixtures/', { cwd: __dirname }); - stream.on('error', function (err:any) { + stream.on('error', function (err: any) { err.code.should.equal('EACCES'); done(); }); @@ -914,5 +910,5 @@ describe('symlink stream', function () { var file = new File(options); File.isVinyl(file).should.equal(true); File.isVinyl(options).should.equal(false); - }) + }); });