From b6d9703d6ce3bda9578597028dab178824ff1441 Mon Sep 17 00:00:00 2001 From: Ryan Helmoski Date: Fri, 13 May 2016 22:09:29 -0500 Subject: [PATCH] Fixes #1 - empty html file bug --- index.js | 2 +- package.json | 2 +- spec/main.spec.js | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 7b12e52..fbb6c34 100644 --- a/index.js +++ b/index.js @@ -27,7 +27,7 @@ function inject(options) { function transform(file, enc, cb) { var ext = path.extname(file.path), relativePath = path.relative(globals.cwd, file.path); - if(file.isNull()) { + if(file.isNull() || file.contents.length === 0) { this.push(file); } else if(ext === '.html') { globals.htmlFiles.push(file); diff --git a/package.json b/package.json index da72640..e439503 100644 --- a/package.json +++ b/package.json @@ -36,12 +36,12 @@ "homepage": "https://github.com/rydahhh/gulp-simple-inject#readme", "dependencies": { "gulp-util": "^3.0.7", + "if-env": "^1.0.0", "stream-replace": "^1.0.0", "through2": "^2.0.0" }, "devDependencies": { "coveralls": "^2.11.6", - "if-env": "^1.0.0", "istanbul": "^0.4.1", "jasmine-node": "^1.14.5" } diff --git a/spec/main.spec.js b/spec/main.spec.js index 072609f..6e12a17 100644 --- a/spec/main.spec.js +++ b/spec/main.spec.js @@ -87,6 +87,17 @@ describe("The gulp-simple-inject plugin", () => { } }); }); + + it('should not break on an empty html file', done => { + injector.write(getEmptyFile('empty-file')); + injector.end(); + + injector.on('data', () => {}); + + injector.on('end', data => { + done(); + }); + }); describe('with the cwd option specified', () => { var injector; @@ -117,6 +128,13 @@ function getHtmlFile(name) { }); } +function getEmptyFile(name) { + return new File({ + path: `${cwd}/${name}.html`, + contents: new Buffer("", "utf8") + }); +} + function getHtmlFileWithoutInjectTags(name) { return new File({ path: `${cwd}/${name}.html`,