From c0f5b1f46061357362fb8cdd1c44ad89f4170949 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Sat, 24 Oct 2015 20:55:14 +0200 Subject: [PATCH] browserify fully implemented --- .idea/workspace.xml | 101 ++++++++++--------- index.js | 7 +- package.json | 5 +- ts/index.ts | 2 + ts/modulebrowserify.ts | 19 ++-- ts/tsd.json | 5 +- ts/typings/browserify/browserify.d.ts | 41 ++++++++ ts/typings/node/node.d.ts | 137 ++++++++++++++------------ ts/typings/tsd.d.ts | 1 + 9 files changed, 198 insertions(+), 120 deletions(-) create mode 100644 ts/typings/browserify/browserify.d.ts diff --git a/.idea/workspace.xml b/.idea/workspace.xml index caf9835..f2bf600 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,12 +2,14 @@ - - - + + + + + @@ -31,8 +33,8 @@ - - + + @@ -43,8 +45,18 @@ - - + + + + + + + + + + + + @@ -72,8 +84,8 @@ - - + + @@ -107,11 +119,11 @@ - + @@ -287,13 +281,14 @@ - + - - + + + - + @@ -330,14 +325,6 @@ - - - - - - - - @@ -362,10 +349,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + - - + + @@ -374,8 +385,8 @@ - - + + diff --git a/index.js b/index.js index f46c165..cbde6f8 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,15 @@ +/// var GulpBrowserBrowserify; (function (GulpBrowserBrowserify) { function init() { return function () { //this is the trough object that gets returned by gulpBrowser.browserify(); return through.obj(function (file, enc, cb) { - var content = file.content; + var content = String(file.contents); var basedir = file.base; + var bundleCallback = function (err, bundledBuffer) { + }; + browserify(content).bundle(bundleCallback); //run callback function to signal end of plugin process. return cb(null, file); }); @@ -18,6 +22,7 @@ var GulpBrowserBrowserify; var through = require("through2"); var path = require("path"); var browserify = require("browserify"); +var pr = require("pushrocks"); //create the return object var gulpBrowser = {}; gulpBrowser.browserify = GulpBrowserBrowserify.init(); diff --git a/package.json b/package.json index 5aecf50..341d22a 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,10 @@ }, "homepage": "https://github.com/pushrocks/gulp-browser", "dependencies": { - "browserify": "^11.2.0" + "browserify": "^11.2.0", + "gutil": "^1.6.4", + "pushrocks": "^1.0.18", + "through2": "^2.0.0" }, "devDependencies": { "gulp": "3.9.0", diff --git a/ts/index.ts b/ts/index.ts index 1363a48..385dbae 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -2,8 +2,10 @@ /// var through = require("through2"); +var gutil = require("gulp-util"); var path = require("path"); var browserify = require("browserify"); +var pr = require("pushrocks"); //create the return object var gulpBrowser:any = {}; diff --git a/ts/modulebrowserify.ts b/ts/modulebrowserify.ts index 5da4070..037d48f 100644 --- a/ts/modulebrowserify.ts +++ b/ts/modulebrowserify.ts @@ -1,16 +1,15 @@ +/// module GulpBrowserBrowserify { export function init() { return function() { - //this is the trough object that gets returned by gulpBrowser.browserify(); - return through.obj((file, enc, cb) => { - var content = file.content; - var basedir = file.base; - - - - - //run callback function to signal end of plugin process. - return cb(null, file); + return through.obj((file, enc, cb) => { //this is the trough object that gets returned by gulpBrowser.browserify(); + var content = String(file.contents); // get the content of the file + var bundleCallback = (err,bundledBuffer) => { //gets called by browserify, arrow function (TS) preserves this + file.contents = bundledBuffer; + this.push(file); + cb(); + }; + browserify(content).bundle(bundleCallback); }); }; } diff --git a/ts/tsd.json b/ts/tsd.json index 0764c2c..e315210 100644 --- a/ts/tsd.json +++ b/ts/tsd.json @@ -6,7 +6,10 @@ "bundle": "typings/tsd.d.ts", "installed": { "node/node.d.ts": { - "commit": "efa0c1196d7280640e624ac1e7fa604502e7bd63" + "commit": "3191f6e0088eee07c4d8fd24e4d27a40a60d9eb9" + }, + "browserify/browserify.d.ts": { + "commit": "3191f6e0088eee07c4d8fd24e4d27a40a60d9eb9" } } } diff --git a/ts/typings/browserify/browserify.d.ts b/ts/typings/browserify/browserify.d.ts new file mode 100644 index 0000000..c301df5 --- /dev/null +++ b/ts/typings/browserify/browserify.d.ts @@ -0,0 +1,41 @@ +// Type definitions for Browserify +// Project: http://browserify.org/ +// Definitions by: Andrew Gaspar +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +interface BrowserifyObject extends NodeJS.EventEmitter { + add(file:string, opts?:any): BrowserifyObject; + require(file:string, opts?:{ + expose: string; + }): BrowserifyObject; + bundle(opts?:{ + insertGlobals?: boolean; + detectGlobals?: boolean; + debug?: boolean; + standalone?: string; + insertGlobalVars?: any; + }, cb?:(err:any, src:any) => void): NodeJS.ReadableStream; + + external(file:string, opts?:any): BrowserifyObject; + ignore(file:string, opts?:any): BrowserifyObject; + transform(tr:string, opts?:any): BrowserifyObject; + transform(tr:Function, opts?:any): BrowserifyObject; + plugin(plugin:string, opts?:any): BrowserifyObject; + plugin(plugin:Function, opts?:any): BrowserifyObject; +} + +interface Browserify { + (): BrowserifyObject; + (files:string[]): BrowserifyObject; + (opts:{ + entries?: string[]; + noParse?: string[]; + }): BrowserifyObject; +} + +declare module "browserify" { + var browserify: Browserify; + export = browserify; +} diff --git a/ts/typings/node/node.d.ts b/ts/typings/node/node.d.ts index 027c654..9448b41 100644 --- a/ts/typings/node/node.d.ts +++ b/ts/typings/node/node.d.ts @@ -9,6 +9,11 @@ * * ************************************************/ +interface Error { + stack?: string; +} + + // compat for TypeScript 1.5.3 // if you use with --target es3 or --target es5 and use below definitions, // use the lib.es6.d.ts that is bundled with TypeScript 1.5.3. @@ -114,7 +119,7 @@ declare var Buffer: { * * @param obj object to test. */ - isBuffer(obj: any): boolean; + isBuffer(obj: any): obj is Buffer; /** * Returns true if {encoding} is a valid encoding argument. * Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex' @@ -188,8 +193,7 @@ declare module NodeJS { export interface WritableStream extends EventEmitter { writable: boolean; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; + write(buffer: Buffer|string, cb?: Function): boolean; write(str: string, encoding?: string, cb?: Function): boolean; end(): void; end(buffer: Buffer, cb?: Function): void; @@ -373,21 +377,21 @@ interface NodeBuffer { readFloatBE(offset: number, noAssert?: boolean): number; readDoubleLE(offset: number, noAssert?: boolean): number; readDoubleBE(offset: number, noAssert?: boolean): number; - writeUInt8(value: number, offset: number, noAssert?: boolean): void; - writeUInt16LE(value: number, offset: number, noAssert?: boolean): void; - writeUInt16BE(value: number, offset: number, noAssert?: boolean): void; - writeUInt32LE(value: number, offset: number, noAssert?: boolean): void; - writeUInt32BE(value: number, offset: number, noAssert?: boolean): void; - writeInt8(value: number, offset: number, noAssert?: boolean): void; - writeInt16LE(value: number, offset: number, noAssert?: boolean): void; - writeInt16BE(value: number, offset: number, noAssert?: boolean): void; - writeInt32LE(value: number, offset: number, noAssert?: boolean): void; - writeInt32BE(value: number, offset: number, noAssert?: boolean): void; - writeFloatLE(value: number, offset: number, noAssert?: boolean): void; - writeFloatBE(value: number, offset: number, noAssert?: boolean): void; - writeDoubleLE(value: number, offset: number, noAssert?: boolean): void; - writeDoubleBE(value: number, offset: number, noAssert?: boolean): void; - fill(value: any, offset?: number, end?: number): void; + writeUInt8(value: number, offset: number, noAssert?: boolean): number; + writeUInt16LE(value: number, offset: number, noAssert?: boolean): number; + writeUInt16BE(value: number, offset: number, noAssert?: boolean): number; + writeUInt32LE(value: number, offset: number, noAssert?: boolean): number; + writeUInt32BE(value: number, offset: number, noAssert?: boolean): number; + writeInt8(value: number, offset: number, noAssert?: boolean): number; + writeInt16LE(value: number, offset: number, noAssert?: boolean): number; + writeInt16BE(value: number, offset: number, noAssert?: boolean): number; + writeInt32LE(value: number, offset: number, noAssert?: boolean): number; + writeInt32BE(value: number, offset: number, noAssert?: boolean): number; + writeFloatLE(value: number, offset: number, noAssert?: boolean): number; + writeFloatBE(value: number, offset: number, noAssert?: boolean): number; + writeDoubleLE(value: number, offset: number, noAssert?: boolean): number; + writeDoubleBE(value: number, offset: number, noAssert?: boolean): number; + fill(value: any, offset?: number, end?: number): Buffer; } /************************************************ @@ -856,7 +860,7 @@ declare module "child_process" { env?: any; encoding?: string; timeout?: number; - maxBuffer?: string; + maxBuffer?: number; killSignal?: string; }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; export function fork(modulePath: string, args?: string[], options?: { @@ -864,6 +868,26 @@ declare module "child_process" { env?: any; encoding?: string; }): ChildProcess; + export function spawnSync(command: string, args?: string[], options?: { + cwd?: string; + input?: string | Buffer; + stdio?: any; + env?: any; + uid?: number; + gid?: number; + timeout?: number; + maxBuffer?: number; + killSignal?: string; + encoding?: string; + }): { + pid: number; + output: string[]; + stdout: string | Buffer; + stderr: string | Buffer; + status: number; + signal: string; + error: Error; + }; export function execSync(command: string, options?: { cwd?: string; input?: string|Buffer; @@ -875,7 +899,7 @@ declare module "child_process" { maxBuffer?: number; killSignal?: string; encoding?: string; - }): ChildProcess; + }): string | Buffer; export function execFileSync(command: string, args?: string[], options?: { cwd?: string; input?: string|Buffer; @@ -887,7 +911,7 @@ declare module "child_process" { maxBuffer?: number; killSignal?: string; encoding?: string; - }): ChildProcess; + }): string | Buffer; } declare module "url" { @@ -1062,6 +1086,7 @@ declare module "fs" { atime: Date; mtime: Date; ctime: Date; + birthtime: Date; } interface FSWatcher extends events.EventEmitter { @@ -1214,6 +1239,9 @@ declare module "fs" { export function fsyncSync(fd: number): void; export function write(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; export function write(fd: number, buffer: Buffer, offset: number, length: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; + export function write(fd: number, data: any, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; + export function write(fd: number, data: any, offset: number, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; + export function write(fd: number, data: any, offset: number, encoding: string, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; export function writeSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, bytesRead: number, buffer: Buffer) => void): void; export function readSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; @@ -1302,21 +1330,15 @@ declare module "fs" { export function createReadStream(path: string, options?: { flags?: string; encoding?: string; - fd?: string; + fd?: number; mode?: number; - bufferSize?: number; - }): ReadStream; - export function createReadStream(path: string, options?: { - flags?: string; - encoding?: string; - fd?: string; - mode?: string; - bufferSize?: number; + autoClose?: boolean; }): ReadStream; export function createWriteStream(path: string, options?: { flags?: string; encoding?: string; - string?: string; + fd?: number; + mode?: number; }): WriteStream; } @@ -1622,12 +1644,12 @@ declare module "crypto" { setAutoPadding(auto_padding: boolean): void; } export function createSign(algorithm: string): Signer; - interface Signer { + interface Signer extends NodeJS.WritableStream { update(data: any): void; sign(private_key: string, output_format: string): string; } export function createVerify(algorith: string): Verify; - interface Verify { + interface Verify extends NodeJS.WritableStream { update(data: any): void; verify(object: string, signature: string, signature_format?: string): boolean; } @@ -1671,14 +1693,13 @@ declare module "stream" { readable: boolean; constructor(opts?: ReadableOptions); _read(size: number): void; - read(size?: number): string|Buffer; + read(size?: number): any; setEncoding(encoding: string): void; pause(): void; resume(): void; pipe(destination: T, options?: { end?: boolean; }): T; unpipe(destination?: T): void; - unshift(chunk: string): void; - unshift(chunk: Buffer): void; + unshift(chunk: any): void; wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; push(chunk: any, encoding?: string): boolean; } @@ -1686,20 +1707,18 @@ declare module "stream" { export interface WritableOptions { highWaterMark?: number; decodeStrings?: boolean; + objectMode?: boolean; } export class Writable extends events.EventEmitter implements NodeJS.WritableStream { writable: boolean; constructor(opts?: WritableOptions); - _write(data: Buffer, encoding: string, callback: Function): void; - _write(data: string, encoding: string, callback: Function): void; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; + _write(chunk: any, encoding: string, callback: Function): void; + write(chunk: any, cb?: Function): boolean; + write(chunk: any, encoding?: string, cb?: Function): boolean; end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; + end(chunk: any, cb?: Function): void; + end(chunk: any, encoding?: string, cb?: Function): void; } export interface DuplexOptions extends ReadableOptions, WritableOptions { @@ -1710,15 +1729,12 @@ declare module "stream" { export class Duplex extends Readable implements NodeJS.ReadWriteStream { writable: boolean; constructor(opts?: DuplexOptions); - _write(data: Buffer, encoding: string, callback: Function): void; - _write(data: string, encoding: string, callback: Function): void; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; + _write(chunk: any, encoding: string, callback: Function): void; + write(chunk: any, cb?: Function): boolean; + write(chunk: any, encoding?: string, cb?: Function): boolean; end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; + end(chunk: any, cb?: Function): void; + end(chunk: any, encoding?: string, cb?: Function): void; } export interface TransformOptions extends ReadableOptions, WritableOptions {} @@ -1728,8 +1744,7 @@ declare module "stream" { readable: boolean; writable: boolean; constructor(opts?: TransformOptions); - _transform(chunk: Buffer, encoding: string, callback: Function): void; - _transform(chunk: string, encoding: string, callback: Function): void; + _transform(chunk: any, encoding: string, callback: Function): void; _flush(callback: Function): void; read(size?: number): any; setEncoding(encoding: string): void; @@ -1737,17 +1752,14 @@ declare module "stream" { resume(): void; pipe(destination: T, options?: { end?: boolean; }): T; unpipe(destination?: T): void; - unshift(chunk: string): void; - unshift(chunk: Buffer): void; + unshift(chunk: any): void; wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; push(chunk: any, encoding?: string): boolean; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; + write(chunk: any, cb?: Function): boolean; + write(chunk: any, encoding?: string, cb?: Function): boolean; end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; + end(chunk: any, cb?: Function): void; + end(chunk: any, encoding?: string, cb?: Function): void; } export class PassThrough extends Transform {} @@ -1774,6 +1786,7 @@ declare module "util" { export function isDate(object: any): boolean; export function isError(object: any): boolean; export function inherits(constructor: any, superConstructor: any): void; + export function debuglog(key:string): (msg:string,...param: any[])=>void; } declare module "assert" { diff --git a/ts/typings/tsd.d.ts b/ts/typings/tsd.d.ts index 4bd49f3..bc93b38 100644 --- a/ts/typings/tsd.d.ts +++ b/ts/typings/tsd.d.ts @@ -1 +1,2 @@ /// +///