diff --git a/package.json b/package.json index 8642e27..fbe04a7 100644 --- a/package.json +++ b/package.json @@ -35,18 +35,19 @@ }, "homepage": "https://github.com/mcmath/gulp-transform#readme", "dependencies": { - "@types/node": "*", - "@types/gulp-util": "*", - "gulp-util": "^3.0.8", - "tslib": "^1.7.1" + "plugin-error": "^1.0.1", + "tslib": "^1.7.1", + "vinyl": "^2.1.0" }, "devDependencies": { "@types/chai": "^4.0.1", "@types/chai-as-promised": "0.0.31", "@types/lodash": "^4.14.71", "@types/mocha": "^2.2.41", + "@types/node": "*", "@types/sinon": "^2.3.3", "@types/sinon-chai": "^2.7.28", + "@types/vinyl": "^2.0.2", "chai": "^4.1.0", "chai-as-promised": "^7.1.1", "coveralls": "^2.13.1", @@ -58,6 +59,6 @@ "sinon-chai": "^2.12.0", "ts-node": "^3.3.0", "tslint": "^5.5.0", - "typescript": "^2.4.2" + "typescript": "~2.4.2" } } diff --git a/spec/helpers.ts b/spec/helpers.ts index 80f9a1f..ef20306 100644 --- a/spec/helpers.ts +++ b/spec/helpers.ts @@ -1,24 +1,24 @@ -import { File } from "gulp-util"; +import Vinyl = require("vinyl"); import { Readable, Transform } from "stream"; /** * A Vinyl File in buffer mode. */ -export interface BufferFile extends File { +export interface BufferFile extends Vinyl { contents: Buffer; } /** * A Vinyl File in streaming mode. */ -export interface StreamFile extends File { +export interface StreamFile extends Vinyl { contents: NodeJS.ReadableStream; } /** * A Vinyl File whose contents are null. */ -export interface NullFile extends File { +export interface NullFile extends Vinyl { contents: null; } @@ -35,7 +35,7 @@ export function createBufferFile(content: string, encoding: string): BufferFile; export function createBufferFile(content: number[], encoding?: null): BufferFile; export function createBufferFile(content: Buffer, encoding?: null): BufferFile; export function createBufferFile(content: string | number[] | Buffer, encoding?: string | null): BufferFile { - return new File({ + return new Vinyl({ cwd: "/root/src", path: "/root/src/name.txt", contents: toBuffer(content as any, encoding as any) @@ -55,7 +55,7 @@ export function createStreamFile(content: string, encoding: string): StreamFile; export function createStreamFile(content: number[], encoding?: null): StreamFile; export function createStreamFile(content: Buffer, encoding?: null): StreamFile; export function createStreamFile(content: string | number[] | Buffer, encoding?: string | null): StreamFile { - return new File({ + return new Vinyl({ cwd: "/root/src", path: "/root/src/name.txt", contents: new Readable({ @@ -71,7 +71,7 @@ export function createStreamFile(content: string | number[] | Buffer, encoding?: * Creates a Vinyl File object whose contents are null. */ export function createNullFile(): NullFile { - return new File({ + return new Vinyl({ cwd: "/root/src", path: "/root/src/name.txt", contents: null @@ -121,7 +121,7 @@ export async function read(stream: NodeJS.ReadableStream): Promise { * @param stream The object-mode stream to write to. * @return Returns a promise that resolve to the stream itself. */ -export async function write(file: File, stream: T): Promise { +export async function write(file: Vinyl, stream: T): Promise { stream.write(file as any); stream.end(); @@ -140,9 +140,9 @@ export async function write(file: File, stream: * Defaults to null. * @return Returns a promise with the contents of the file. */ -export async function readFile(file: File, encoding: string): Promise; -export async function readFile(file: File, encoding?: null): Promise; -export async function readFile(file: File, encoding?: string | null): Promise { +export async function readFile(file: Vinyl, encoding: string): Promise; +export async function readFile(file: Vinyl, encoding?: null): Promise; +export async function readFile(file: Vinyl, encoding?: string | null): Promise { if (file.isBuffer()) return encoding ? file.contents.toString(encoding) : file.contents; if (!file.isStream()) diff --git a/spec/mode.spec.ts b/spec/mode.spec.ts index dc085d1..6b4624e 100644 --- a/spec/mode.spec.ts +++ b/spec/mode.spec.ts @@ -1,5 +1,6 @@ import { expect } from "chai"; -import { File, PluginError } from "gulp-util"; +import PluginError = require("plugin-error"); +import Vinyl = require("vinyl"); import { identity, noop } from "lodash"; import { createBufferFile, createStreamFile, createNullFile, toBuffer, write, read, readFile } from "./helpers"; import transform = require("../src"); @@ -7,8 +8,8 @@ import transform = require("../src"); describe("content mode", () => { describe("buffer", () => { - let file1: File; - let file2: File; + let file1: Vinyl; + let file2: Vinyl; beforeEach(() => { file1 = createBufferFile([0xCF, 0x80]); @@ -38,8 +39,8 @@ describe("content mode", () => { }); describe("stream", () => { - let file1: File; - let file2: File; + let file1: Vinyl; + let file2: Vinyl; beforeEach(() => { file1 = createStreamFile([0xCF, 0x80]); diff --git a/spec/options.spec.ts b/spec/options.spec.ts index 9f1d3a2..30267ea 100644 --- a/spec/options.spec.ts +++ b/spec/options.spec.ts @@ -1,5 +1,6 @@ import { expect } from "chai"; -import { File, PluginError } from "gulp-util"; +import PluginError = require("plugin-error"); +import Vinyl = require("vinyl"); import { identity } from "lodash"; import { SinonSpy, spy } from "sinon"; import { createBufferFile, toBuffer, write } from "./helpers"; @@ -8,7 +9,7 @@ import transform = require("../src"); describe("options", () => { describe("encoding", () => { - let file: File; + let file: Vinyl; let callback: SinonSpy; beforeEach(() => { @@ -86,7 +87,7 @@ describe("options", () => { }); describe("thisArg", () => { - let file: File; + let file: Vinyl; let callback: SinonSpy; let thisArg: object; diff --git a/spec/params.spec.ts b/spec/params.spec.ts index ee630cf..db59dce 100644 --- a/spec/params.spec.ts +++ b/spec/params.spec.ts @@ -1,5 +1,6 @@ import { expect } from "chai"; -import { File, PluginError } from "gulp-util"; +import PluginError = require("plugin-error"); +import Vinyl = require("vinyl"); import { identity } from "lodash"; import { createBufferFile, write } from "./helpers"; import transform = require("../src"); @@ -7,7 +8,7 @@ import transform = require("../src"); describe("parameters", () => { describe("callback", () => { - let file: File; + let file: Vinyl; beforeEach(() => { file = createBufferFile([0xCF, 0x80]); diff --git a/src/Config.ts b/src/Config.ts index fdf015e..424be72 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -1,4 +1,4 @@ -import { PluginError } from "gulp-util"; +import PluginError = require("plugin-error"); import { PLUGIN_NAME, isFunction, isNil, isObjectLike, isString } from "./common"; type OptionsOrEncoding = Options | string | null | undefined; diff --git a/src/ContentTransformer.ts b/src/ContentTransformer.ts index c273f1d..fcfc164 100644 --- a/src/ContentTransformer.ts +++ b/src/ContentTransformer.ts @@ -1,4 +1,5 @@ -import { File, PluginError } from "gulp-util"; +import PluginError = require("plugin-error"); +import Vinyl = require("vinyl"); import { Config } from "./Config"; import { PLUGIN_NAME, TransformFunction, isString } from "./common"; @@ -26,7 +27,7 @@ export class ContentTransformer { return (contents, file) => this.transform(contents, file); } - private async transform(contents: Buffer, file: File): Promise { + private async transform(contents: Buffer, file: Vinyl): Promise { const decodedContents = this.decodeContents(contents); const callbackResult = await this.invokeAndValidate(decodedContents, file); @@ -40,7 +41,7 @@ export class ContentTransformer { return contents; } - private async invokeAndValidate(decodedContents: Buffer | string, file: File): Promise { + private async invokeAndValidate(decodedContents: Buffer | string, file: Vinyl): Promise { const callbackResult = await this.tryInvokeCallback(decodedContents, file); if (this.encoding && !isString(callbackResult)) @@ -52,7 +53,7 @@ export class ContentTransformer { return callbackResult; } - private async tryInvokeCallback(decodedContents: Buffer | string, file: File): Promise { + private async tryInvokeCallback(decodedContents: Buffer | string, file: Vinyl): Promise { try { return await this.callback.call(this.thisArg, decodedContents, file); } catch (error) { diff --git a/src/FileContentStream.ts b/src/FileContentStream.ts index 7629203..670265e 100644 --- a/src/FileContentStream.ts +++ b/src/FileContentStream.ts @@ -1,5 +1,5 @@ import { Transform } from "stream"; -import { PluginError } from "gulp-util"; +import PluginError = require("plugin-error"); import { PLUGIN_NAME, NodeCallback, StreamFile, TransformFunction } from "./common"; /** diff --git a/src/GulpTransformStream.ts b/src/GulpTransformStream.ts index 59a3cc0..d3c629b 100644 --- a/src/GulpTransformStream.ts +++ b/src/GulpTransformStream.ts @@ -1,5 +1,6 @@ import { Transform } from "stream"; -import { File, PluginError } from "gulp-util"; +import PluginError = require("plugin-error"); +import Vinyl = require("vinyl"); import { FileContentStream } from "./FileContentStream"; import { PLUGIN_NAME, TransformFunction, BufferFile, StreamFile, NodeCallback } from "./common"; @@ -14,7 +15,7 @@ export class GulpTransformStream extends Transform { private readonly transform: TransformFunction ) { super({ objectMode: true }); } - public _transform(file: File, _encoding: string, next: NodeCallback): void { + public _transform(file: Vinyl, _encoding: string, next: NodeCallback): void { if (file.isBuffer()) return void this.transformBufferFile(file, next); diff --git a/src/common.ts b/src/common.ts index 4c31de1..6c22df4 100644 --- a/src/common.ts +++ b/src/common.ts @@ -1,4 +1,4 @@ -import { File } from "gulp-util"; +import Vinyl = require("vinyl"); /** * Accepts the contents of a File object as a Buffer, applies a @@ -7,7 +7,7 @@ import { File } from "gulp-util"; * @internal */ export interface TransformFunction { - (contents: Buffer, file: File): Promise; + (contents: Buffer, file: Vinyl): Promise; } /** @@ -15,7 +15,7 @@ export interface TransformFunction { * * @internal */ -export interface BufferFile extends File { +export interface BufferFile extends Vinyl { contents: Buffer; } @@ -24,7 +24,7 @@ export interface BufferFile extends File { * * @internal */ -export interface StreamFile extends File { +export interface StreamFile extends Vinyl { contents: NodeJS.ReadableStream; } diff --git a/src/index.ts b/src/index.ts index 4dba274..ca974ae 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import { File } from "gulp-util"; +import Vinyl = require("vinyl"); import { Config } from "./Config"; import { ContentTransformer } from "./ContentTransformer"; import { GulpTransformStream } from "./GulpTransformStream"; @@ -16,7 +16,7 @@ import { GulpTransformStream } from "./GulpTransformStream"; */ function gulpTransform( encoding: gulpTransform.Encoding, - callback: (contents: string, file: File) => string | PromiseLike + callback: (contents: string, file: Vinyl) => string | PromiseLike ): NodeJS.ReadWriteStream; /** @@ -32,7 +32,7 @@ function gulpTransform( */ function gulpTransform( encoding: null, - callback: (contents: Buffer, file: File) => Buffer | PromiseLike + callback: (contents: Buffer, file: Vinyl) => Buffer | PromiseLike ): NodeJS.ReadWriteStream; /** @@ -52,7 +52,7 @@ function gulpTransform( */ function gulpTransform( options: { encoding: gulpTransform.Encoding, thisArg?: any }, - callback: (contents: string, file: File) => string | PromiseLike + callback: (contents: string, file: Vinyl) => string | PromiseLike ): NodeJS.ReadWriteStream; /** @@ -72,7 +72,7 @@ function gulpTransform( */ function gulpTransform( options: { encoding?: null, thisArg?: any }, - callback: (contents: Buffer, file: File) => Buffer | PromiseLike + callback: (contents: Buffer, file: Vinyl) => Buffer | PromiseLike ): NodeJS.ReadWriteStream; /** @@ -85,7 +85,7 @@ function gulpTransform( * @return Returns a Gulp plugin stream. */ function gulpTransform( - callback: (contents: Buffer, file: File) => Buffer | PromiseLike + callback: (contents: Buffer, file: Vinyl) => Buffer | PromiseLike ): NodeJS.ReadWriteStream; function gulpTransform(arg0: any, arg1?: any): NodeJS.ReadWriteStream {