now handling empty files alright and handling errors better. fixes #48

This commit is contained in:
Philipp Kunz 2016-04-01 13:56:35 +00:00
parent 01a89ecad1
commit 0657edac50
12 changed files with 121 additions and 57 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -1,20 +1,34 @@
"use strict";
/// <reference path="./typings/main.d.ts" /> /// <reference path="./typings/main.d.ts" />
var plugins = require("./gulpbrowser.plugins"); var plugins = require("./gulpbrowser.plugins");
var browserify = function () { var browserify = function () {
return plugins.through.obj(function (file, enc, cb) { var forEach = function (file, enc, cb) {
var bundleCallback = function (err, bufferedContent) { var bundleCallback = function (err, bufferedContent) {
if (Buffer.isBuffer(bufferedContent)) { if (Buffer.isBuffer(bufferedContent)) {
file.contents = bufferedContent; file.contents = bufferedContent;
} }
else { else {
plugins.beautylog.error("gulp-browser: .browserify() " + err.message); plugins.beautylog.error("gulp-browser: .browserify() " + err.message);
cb(new Error(err.message), file);
return;
} }
cb(null, file); cb(null, file);
}; };
if (file.contents.length > 0) {
plugins.browserify(file, { basedir: file.base }) plugins.browserify(file, { basedir: file.base })
.bundle(bundleCallback); .bundle(bundleCallback);
}); }
else {
plugins.beautylog.warn("gulp-browser: .browserify() file.contents appears to be empty");
cb(null, file);
}
;
};
var atEnd = function (cb) {
cb();
}; // no need to clean up after ourselves
return plugins.through.obj(forEach, atEnd); // this is the through object that gets returned by gulpBrowser.browserify();
}; };
module.exports = browserify; module.exports = browserify;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImd1bHBicm93c2VyLmJyb3dzZXJpZnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsNENBQTRDO0FBQzVDLElBQU8sT0FBTyxXQUFXLHVCQUF1QixDQUFDLENBQUM7QUFDbEQsSUFBSSxVQUFVLEdBQUk7SUFDVixNQUFNLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsVUFBQyxJQUFJLEVBQUUsR0FBRyx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XIuYnJvd3NlcmlmeSgpO1xuICAgICAgICAgICAgdmFyIGJ1bmRsZUNhbGxiYWNrID0gZnVuY3Rpb24oZXJyLCBidWZmZXJlZENvbnRlbnQpIHtcbiAgICAgICAgICAgICAgICBpZiAoQnVmZmVyLmlzQnVmZmVyKGJ1ZmZlcmVkQ29udGVudCkpe1xuICAgICAgICAgICAgICAgICAgICBmaWxlLmNvbnRlbnRzID0gYnVmZmVyZWRDb250ZW50O1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHBsdWdpbnMuYmVhdXR5bG9nLmVycm9yKFwiZ3VscC1icm93c2VyOiAuYnJvd3NlcmlmeSgpIFwiICsgZXJyLm1lc3NhZ2UpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBjYihudWxsLGZpbGUpO1xuICAgICAgICAgICAgfTtcbiAgICAgICAgICAgIHBsdWdpbnMuYnJvd3NlcmlmeShmaWxlLCB7IGJhc2VkaXI6IGZpbGUuYmFzZSB9KVxuICAgICAgICAgICAgICAgIC5idW5kbGUoYnVuZGxlQ2FsbGJhY2spXG4gICAgICAgIH0pO1xuIH07XG5cbmV4cG9ydCA9IGJyb3dzZXJpZnk7Il0sInNvdXJjZVJvb3QiOiIvc291cmNlLyJ9 //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImd1bHBicm93c2VyLmJyb3dzZXJpZnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDRDQUE0QztBQUM1QyxJQUFPLE9BQU8sV0FBVyx1QkFBdUIsQ0FBQyxDQUFDO0FBR2xELElBQUksVUFBVSxHQUFJO0lBRWQsSUFBSSxPQUFPLEdBQUcsVUFBUyxJQUFJLEVBQUUsR0FBRyxFQUFFLEVBQUU7UUFFaEMsSUFBSSxjQUFjLEdBQUcsVUFBUyxHQUFHLEVBQUUsZUFBZTtZQUM5QyxFQUFFLENBQUMsQ0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AgIH1cbiAgICAgICAgICAgIGNiKG51bGwsZmlsZSk7XG4gICAgICAgIH07XG4gICAgICAgIFxuICAgICAgICBpZihmaWxlLmNvbnRlbnRzLmxlbmd0aCA+IDApe1xuICAgICAgICAgICAgcGx1Z2lucy5icm93c2VyaWZ5KGZpbGUsIHsgYmFzZWRpcjogZmlsZS5iYXNlIH0pXG4gICAgICAgICAgICAgICAgLmJ1bmRsZShidW5kbGVDYWxsYmFjayk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBwbHVnaW5zLmJlYXV0eWxvZy53YXJuKFwiZ3VscC1icm93c2VyOiAuYnJvd3NlcmlmeSgpIGZpbGUuY29udGVudHMgYXBwZWFycyB0byBiZSBlbXB0eVwiKTtcbiAgICAgICAgICAgIGNiKG51bGwsZmlsZSk7XG4gICAgICAgIH07XG4gICAgfVxuICAgICAgICBcbiAgICBsZXQgYXRFbmQgPSBmdW5jdGlvbihjYil7XG4gICAgICAgIGNiKCk7XG4gICAgfSAvLyBubyBuZWVkIHRvIGNsZWFuIHVwIGFmdGVyIG91cnNlbHZlc1xuICAgIFxuICAgIHJldHVybiBwbHVnaW5zLnRocm91Z2gub2JqKGZvckVhY2gsYXRFbmQpOyAvLyB0aGlzIGlzIHRoZSB0aHJvdWdoIG9iamVjdCB0aGF0IGdldHMgcmV0dXJuZWQgYnkgZ3VscEJyb3dzZXIuYnJvd3NlcmlmeSgpO1xuIH07XG5cbmV4cG9ydCA9IGJyb3dzZXJpZnk7Il0sInNvdXJjZVJvb3QiOiIvc291cmNlLyJ9

View File

@ -1,11 +1,8 @@
"use strict";
/// <reference path="./typings/main.d.ts" /> /// <reference path="./typings/main.d.ts" />
var plugins = { exports.beautylog = require("beautylog");
beautylog: require("beautylog"), exports.through = require("through2");
through: require("through2"), exports.path = require("path");
gutil: require("gulp-util"), exports.browserify = require("browserify");
path: require("path"),
browserify: require("browserify")
};
module.exports = plugins;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uI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0FBQztBQUNqQyxlQUFPLEdBQUcsT0FBTyxDQUFDLFVBQVUsQ0FBQyxDQUFDO0FBQzlCLFlBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUM7QUFDdkIsa0JBQVUsR0FBRyxPQUFPLENBQUMsWUFBWSxDQUFDLENBQUMiLCJmaWxlIjoiZ3VscGJyb3dzZXIucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCIuL3R5cGluZ3MvbWFpbi5kLnRzXCIgLz5cbmV4cG9ydCBsZXQgYmVhdXR5bG9nID0gcmVxdWlyZShcImJlYXV0eWxvZ1wiKTtcbmV4cG9ydCBsZXQgdGhyb3VnaCA9IHJlcXVpcmUoXCJ0aHJvdWdoMlwiKTtcbmV4cG9ydCBsZXQgcGF0aCA9IHJlcXVpcmUoXCJwYXRoXCIpO1xuZXhwb3J0IGxldCBicm93c2VyaWZ5ID0gcmVxdWlyZShcImJyb3dzZXJpZnlcIik7XG4iXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=

3
dist/index.js vendored
View File

@ -1,4 +1,5 @@
/// <reference path="./typings/main.d.ts" /> /// <reference path="./typings/main.d.ts" />
"use strict";
var browserify = require("./gulpbrowser.browserify"); var browserify = require("./gulpbrowser.browserify");
//create the return object //create the return object
var gulpBrowser = { var gulpBrowser = {
@ -6,4 +7,4 @@ var gulpBrowser = {
}; };
module.exports = gulpBrowser; module.exports = gulpBrowser;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDRDQUE0QztBQUU1QyxJQUFPLFVBQVUsV0FBVywwQkFBMEIsQ0FBQyxDQUFDO0FBR3hELDBCQUEwQjtBQUMxQixJQUFJLFdBQVcsR0FBTztJQUNsQixVQUFVLEVBQUUsVUFBVTtDQUN6QixDQUFDO0FBR0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CI6Ii9zb3VyY2UvIn0=

View File

@ -27,12 +27,12 @@
"dependencies": { "dependencies": {
"beautylog": "3.1.2", "beautylog": "3.1.2",
"browserify": "13.0.0", "browserify": "13.0.0",
"gulp-util": "3.0.7",
"through2": "2.0.1" "through2": "2.0.1"
}, },
"devDependencies": { "devDependencies": {
"gulp": "3.9.1", "gulp": "3.9.1",
"gulp-function": "1.1.1", "gulp-function": "1.2.0",
"npmts": "^3.3.2" "npmts": "^3.3.2",
"should": "^8.3.0"
} }
} }

View File

@ -5,20 +5,38 @@ var plugins = {
gulpBrowser: require("../dist/index.js"), gulpBrowser: require("../dist/index.js"),
gulpFunction: require("gulp-function") gulpFunction: require("gulp-function")
}; };
var should = require("should");
describe("gulpBrowser", function () { describe("gulpBrowser", function () {
describe(".browserify", function () { describe(".browserify", function () {
it("should run through smoothly", function (done) { it("should run through smoothly", function (done) {
this.timeout(30000); this.timeout(30000);
plugins.gulp.task('gulpBrowserNormal', function (cb) { var stream = plugins.gulp.src('./test/testBrowserifyNormal.js')
var stream = plugins.gulp.src('./test/browserifyGulpTest.js')
.pipe(plugins.gulpBrowser.browserify()) .pipe(plugins.gulpBrowser.browserify())
.pipe(plugins.gulp.dest("./test/result/")) .pipe(plugins.gulp.dest("./test/result/"))
.pipe(plugins.gulpFunction(done)); .pipe(plugins.gulpFunction(done));
return stream;
}); });
plugins.gulp.start.apply(plugins.gulp, ['gulpBrowserNormal']); it("should throw an error, when a module is not found", function (done) {
var d = require('domain').create();
var doneCalled = false;
d.on("error", function (error) {
console.log(error.message);
if (!doneCalled) {
done();
doneCalled = true;
}
});
d.run(function () {
var stream = plugins.gulp.src("./test/testBrowserifyError.js")
.pipe(plugins.gulpBrowser.browserify());
});
});
it("should run through with an empty file", function (done) {
var stream = plugins.gulp.src('./test/testBrowserifyEmpty.js')
.pipe(plugins.gulpBrowser.browserify())
.pipe(plugins.gulp.dest("./test/result/"))
.pipe(plugins.gulpFunction(done));
}); });
}); });
}); });
//# sourceMappingURL=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ICAgICAgICAgICAgIC5waXBlKHBsdWdpbnMuZ3VscEJyb3dzZXIuYnJvd3NlcmlmeSgpKVxuICAgICAgICAgICAgICAgIC5waXBlKHBsdWdpbnMuZ3VscC5kZXN0KFwiLi90ZXN0L3Jlc3VsdC9cIikpXG4gICAgICAgICAgICAgICAgLnBpcGUocGx1Z2lucy5ndWxwRnVuY3Rpb24oZG9uZSkpO1xuICAgICAgICB9KTtcbiAgICAgICAgXG4gICAgICAgIGl0KFwic2hvdWxkIHRocm93IGFuIGVycm9yLCB3aGVuIGEgbW9kdWxlIGlzIG5vdCBmb3VuZFwiLCBmdW5jdGlvbiAoZG9uZSkge1xuICAgICAgICAgICAgbGV0IGQgPSByZXF1aXJlKCdkb21haW4nKS5jcmVhdGUoKTtcbiAgICAgICAgICAgIGxldCBkb25lQ2FsbGVkID0gZmFsc2VcbiAgICAgICAgICAgIGQub24oXCJlcnJvclwiLGZ1bmN0aW9uKGVycm9yKXtcbiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlcnJvci5tZXNzYWdlKVxuICAgICAgICAgICAgICAgIGlmKCFkb25lQ2FsbGVkKXtcbiAgICAgICAgICAgICAgICAgICAgZG9uZSgpO1xuICAgICAgICAgICAgICAgICAgICBkb25lQ2FsbGVkID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTsgXG4gICAgICAgICAgICBkLnJ1bihmdW5jdGlvbigpIHsgXG4gICAgICAgICAgICAgICAgbGV0IHN0cmVhbSA9IHBsdWdpbnMuZ3VscC5zcmMoXCIuL3Rlc3QvdGVzdEJyb3dzZXJpZnlFcnJvci5qc1wiKVxuICAgICAgICAgICAgICAgICAgICAucGlwZShwbHVnaW5zLmd1bHBCcm93c2VyLmJyb3dzZXJpZnkoKSk7XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSk7XG4gICAgICAgIFxuICAgICAgICBpdChcInNob3VsZCBydW4gdGhyb3VnaCB3aXRoIGFuIGVtcHR5IGZpbGVcIiwgZnVuY3Rpb24gKGRvbmUpIHtcbiAgICAgICAgICAgIGxldCBzdHJlYW0gPSBwbHVnaW5zLmd1bHAuc3JjKCcuL3Rlc3QvdGVzdEJyb3dzZXJpZnlFbXB0eS5qcycpXG4gICAgICAgICAgICAgICAgLnBpcGUocGx1Z2lucy5ndWxwQnJvd3Nlci5icm93c2VyaWZ5KCkpXG4gICAgICAgICAgICAgICAgLnBpcGUocGx1Z2lucy5ndWxwLmRlc3QoXCIuL3Rlc3QvcmVzdWx0L1wiKSlcbiAgICAgICAgICAgICAgICAucGlwZShwbHVnaW5zLmd1bHBGdW5jdGlvbihkb25lKSk7XG4gICAgICAgIH0pO1xuICAgIH0pO1xufSk7XG4iXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=

View File

@ -1,23 +1,44 @@
/// <reference path="../ts/typings/main.d.ts" /> /// <reference path="../ts/typings/main.d.ts" />
var plugins = { let plugins = {
beautylog: require("beautylog"), beautylog: require("beautylog"),
gulp: require("gulp"), gulp: require("gulp"),
gulpBrowser: require("../dist/index.js"), gulpBrowser: require("../dist/index.js"),
gulpFunction: require("gulp-function") gulpFunction: require("gulp-function")
}; };
let should = require("should");
describe("gulpBrowser",function(){
describe(".browserify",function(){ describe("gulpBrowser", function () {
it("should run through smoothly",function(done){ describe(".browserify", function () {
it("should run through smoothly", function (done) {
this.timeout(30000); this.timeout(30000);
plugins.gulp.task('gulpBrowserNormal',function(cb) { let stream = plugins.gulp.src('./test/testBrowserifyNormal.js')
var stream = plugins.gulp.src('./test/browserifyGulpTest.js')
.pipe(plugins.gulpBrowser.browserify()) .pipe(plugins.gulpBrowser.browserify())
.pipe(plugins.gulp.dest("./test/result/")) .pipe(plugins.gulp.dest("./test/result/"))
.pipe(plugins.gulpFunction(done)); .pipe(plugins.gulpFunction(done));
return stream;
}); });
plugins.gulp.start.apply(plugins.gulp, ['gulpBrowserNormal']);
it("should throw an error, when a module is not found", function (done) {
let d = require('domain').create();
let doneCalled = false
d.on("error",function(error){
console.log(error.message)
if(!doneCalled){
done();
doneCalled = true;
}
});
d.run(function() {
let stream = plugins.gulp.src("./test/testBrowserifyError.js")
.pipe(plugins.gulpBrowser.browserify());
});
});
it("should run through with an empty file", function (done) {
let stream = plugins.gulp.src('./test/testBrowserifyEmpty.js')
.pipe(plugins.gulpBrowser.browserify())
.pipe(plugins.gulp.dest("./test/result/"))
.pipe(plugins.gulpFunction(done));
}); });
}); });
}); });

View File

View File

@ -1,18 +1,36 @@
/// <reference path="./typings/main.d.ts" /> /// <reference path="./typings/main.d.ts" />
import plugins = require("./gulpbrowser.plugins"); import plugins = require("./gulpbrowser.plugins");
let browserify = function() { let browserify = function() {
return plugins.through.obj((file, enc, cb) => { //this is the through object that gets returned by gulpBrowser.browserify();
var bundleCallback = function(err, bufferedContent) { let forEach = function(file, enc, cb){ // do this with every chunk (file in gulp terms)
let bundleCallback = function(err, bufferedContent) { // our bundle callback for when browserify is finished
if (Buffer.isBuffer(bufferedContent)){ if (Buffer.isBuffer(bufferedContent)){
file.contents = bufferedContent; file.contents = bufferedContent;
} else { } else {
plugins.beautylog.error("gulp-browser: .browserify() " + err.message); plugins.beautylog.error("gulp-browser: .browserify() " + err.message);
cb(new Error(err.message),file);
return;
} }
cb(null,file); cb(null,file);
}; };
if(file.contents.length > 0){
plugins.browserify(file, { basedir: file.base }) plugins.browserify(file, { basedir: file.base })
.bundle(bundleCallback) .bundle(bundleCallback);
}); } else {
plugins.beautylog.warn("gulp-browser: .browserify() file.contents appears to be empty");
cb(null,file);
};
}
let atEnd = function(cb){
cb();
} // no need to clean up after ourselves
return plugins.through.obj(forEach,atEnd); // this is the through object that gets returned by gulpBrowser.browserify();
}; };
export = browserify; export = browserify;

View File

@ -1,10 +1,5 @@
/// <reference path="./typings/main.d.ts" /> /// <reference path="./typings/main.d.ts" />
var plugins = { export let beautylog = require("beautylog");
beautylog: require("beautylog"), export let through = require("through2");
through: require("through2"), export let path = require("path");
gutil: require("gulp-util"), export let browserify = require("browserify");
path: require("path"),
browserify: require("browserify")
};
export = plugins;