gulp-newer
Advanced tools
Comparing version 1.3.0 to 1.4.0
60
index.js
@@ -8,6 +8,4 @@ var Transform = require('stream').Transform; | ||
var Q = require('kew'); | ||
var gutil = require('gulp-util'); | ||
var PluginError = require('plugin-error'); | ||
var PluginError = gutil.PluginError; | ||
var PLUGIN_NAME = 'gulp-newer'; | ||
@@ -19,4 +17,6 @@ | ||
if (!options) { | ||
throw new PluginError(PLUGIN_NAME, | ||
'Requires a dest string or options object'); | ||
throw new PluginError( | ||
PLUGIN_NAME, | ||
'Requires a dest string or options object' | ||
); | ||
} | ||
@@ -39,3 +39,6 @@ | ||
if (!options.dest && !options.map) { | ||
throw new PluginError(PLUGIN_NAME, 'Requires either options.dest or options.map or both'); | ||
throw new PluginError( | ||
PLUGIN_NAME, | ||
'Requires either options.dest or options.map or both' | ||
); | ||
} | ||
@@ -47,3 +50,6 @@ | ||
} else if (!Array.isArray(options.extra)) { | ||
throw new PluginError(PLUGIN_NAME, 'Requires options.extra to be a string or array'); | ||
throw new PluginError( | ||
PLUGIN_NAME, | ||
'Requires options.extra to be a string or array' | ||
); | ||
} | ||
@@ -74,3 +80,5 @@ } | ||
*/ | ||
this._destStats = this._dest ? Q.nfcall(fs.stat, this._dest) : Q.resolve(null); | ||
this._destStats = this._dest | ||
? Q.nfcall(fs.stat, this._dest) | ||
: Q.resolve(null); | ||
@@ -133,13 +141,17 @@ /** | ||
if (error && error.path) { | ||
throw new PluginError(PLUGIN_NAME, 'Failed to read stats for an extra file: ' + error.path); | ||
throw new PluginError( | ||
PLUGIN_NAME, | ||
'Failed to read stats for an extra file: ' + error.path | ||
); | ||
} else { | ||
throw new PluginError(PLUGIN_NAME, 'Failed to stat extra files; unknown error: ' + error); | ||
throw new PluginError( | ||
PLUGIN_NAME, | ||
'Failed to stat extra files; unknown error: ' + error | ||
); | ||
} | ||
}); | ||
} | ||
} | ||
util.inherits(Newer, Transform); | ||
/** | ||
@@ -163,10 +175,11 @@ * Pass through newer files only. | ||
var ext = path.extname(relative); | ||
var destFileRelative = self._ext ? | ||
relative.substr(0, relative.length - ext.length) + self._ext : | ||
relative; | ||
var destFileRelative = self._ext | ||
? relative.substr(0, relative.length - ext.length) + self._ext | ||
: relative; | ||
if (self._map) { | ||
destFileRelative = self._map(destFileRelative); | ||
} | ||
var destFileJoined = self._dest ? | ||
path.join(self._dest, destFileRelative) : destFileRelative; | ||
var destFileJoined = self._dest | ||
? path.join(self._dest, destFileRelative) | ||
: destFileRelative; | ||
return Q.all([Q.nfcall(fs.stat, destFileJoined), extraStats]); | ||
@@ -180,3 +193,4 @@ } else { | ||
} | ||
}).fail(function(err) { | ||
}) | ||
.fail(function(err) { | ||
if (err.code === 'ENOENT') { | ||
@@ -189,3 +203,4 @@ // dest file or directory doesn't exist, pass through all | ||
} | ||
}).spread(function(destFileStats, extraFileStats) { | ||
}) | ||
.spread(function(destFileStats, extraFileStats) { | ||
var newer = !destFileStats || srcFile.stat.mtime > destFileStats.mtime; | ||
@@ -216,7 +231,7 @@ // If *any* extra file is newer than a destination file, then ALL | ||
done(); | ||
}).fail(done).end(); | ||
}) | ||
.fail(done) | ||
.end(); | ||
}; | ||
/** | ||
@@ -231,3 +246,2 @@ * Remove references to buffered files. | ||
/** | ||
@@ -234,0 +248,0 @@ * Only pass through source files that are newer than the provided destination. |
{ | ||
"name": "gulp-newer", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Only pass through newer source files", | ||
@@ -26,17 +26,19 @@ "homepage": "https://github.com/tschaub/gulp-newer", | ||
"scripts": { | ||
"pretest": "eslint index.js spec.js", | ||
"lint": "eslint index.js spec.js", | ||
"pretest": "npm run lint", | ||
"test": "mocha spec.js" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"eslint": "^3.7.1", | ||
"eslint-config-tschaub": "^6.0.0", | ||
"chai": "^4.1.2", | ||
"eslint": "^4.14.0", | ||
"eslint-config-tschaub": "^9.0.0", | ||
"gulp": "^3.9.1", | ||
"mocha": "^3.1.0", | ||
"mock-fs": "^3.11.0" | ||
"mocha": "^4.1.0", | ||
"mock-fs": "^4.4.2", | ||
"vinyl": "^2.1.0" | ||
}, | ||
"dependencies": { | ||
"glob": "^7.0.3", | ||
"gulp-util": "^3.0.7", | ||
"kew": "^0.7.0" | ||
"kew": "^0.7.0", | ||
"plugin-error": "^0.1.2" | ||
}, | ||
@@ -43,0 +45,0 @@ "eslintConfig": { |
55
spec.js
@@ -8,3 +8,3 @@ /* eslint-env mocha */ | ||
var chai = require('chai'); | ||
var gutil = require('gulp-util'); | ||
var Vinyl = require('vinyl'); | ||
var mock = require('mock-fs'); | ||
@@ -16,3 +16,2 @@ | ||
var File = gutil.File; | ||
var assert = chai.assert; | ||
@@ -28,7 +27,9 @@ | ||
paths.forEach(function(filePath) { | ||
stream.write(new File({ | ||
contents: fs.readFileSync(filePath), | ||
path: path.resolve(filePath), | ||
stat: fs.statSync(filePath) | ||
})); | ||
stream.write( | ||
new Vinyl({ | ||
contents: fs.readFileSync(filePath), | ||
path: path.resolve(filePath), | ||
stat: fs.statSync(filePath) | ||
}) | ||
); | ||
}); | ||
@@ -39,3 +40,2 @@ stream.end(); | ||
describe('newer()', function() { | ||
it('creates a transform stream', function() { | ||
@@ -47,3 +47,2 @@ var stream = newer('foo'); | ||
it('requires a string dest or an object with the dest property', function() { | ||
assert.throws(function() { | ||
@@ -63,5 +62,3 @@ newer(); | ||
describe('config.ext', function() { | ||
it('must be a string', function() { | ||
assert.throws(function() { | ||
@@ -78,3 +75,2 @@ newer({dest: 'foo', ext: 1}); | ||
describe('config.map', function() { | ||
it('must be a function', function() { | ||
@@ -95,7 +91,5 @@ assert.throws(function() { | ||
}); | ||
}); | ||
describe('config.extra', function() { | ||
beforeEach(function() { | ||
@@ -151,3 +145,5 @@ mock({ | ||
it('must let other files through stream if an "extra" is newer', function(done) { | ||
it('must let other files through stream if an "extra" is newer', function( | ||
done | ||
) { | ||
var stream = newer({dest: 'collected', extra: 'imported'}); | ||
@@ -172,7 +168,5 @@ | ||
}); | ||
}); | ||
describe('dest dir that does not exist', function() { | ||
beforeEach(function() { | ||
@@ -207,7 +201,5 @@ mock({ | ||
}); | ||
}); | ||
describe('dest file that does not exist', function() { | ||
beforeEach(function() { | ||
@@ -243,7 +235,5 @@ mock({ | ||
}); | ||
}); | ||
describe('empty dest dir', function() { | ||
beforeEach(function() { | ||
@@ -279,7 +269,5 @@ mock({ | ||
}); | ||
}); | ||
describe('dest dir with one older file', function() { | ||
beforeEach(function() { | ||
@@ -320,7 +308,5 @@ mock({ | ||
}); | ||
}); | ||
describe('dest dir with one newer file', function() { | ||
beforeEach(function() { | ||
@@ -370,7 +356,5 @@ mock({ | ||
}); | ||
}); | ||
describe('dest dir with two newer and one older file', function() { | ||
beforeEach(function() { | ||
@@ -428,7 +412,5 @@ mock({ | ||
}); | ||
}); | ||
describe('dest file with first source file newer', function() { | ||
beforeEach(function() { | ||
@@ -478,7 +460,5 @@ mock({ | ||
}); | ||
}); | ||
describe('dest file with second source file newer', function() { | ||
beforeEach(function() { | ||
@@ -528,7 +508,5 @@ mock({ | ||
}); | ||
}); | ||
describe('dest file with last source file newer', function() { | ||
beforeEach(function() { | ||
@@ -578,7 +556,5 @@ mock({ | ||
}); | ||
}); | ||
describe('dest file with no newer source files', function() { | ||
beforeEach(function() { | ||
@@ -628,7 +604,5 @@ mock({ | ||
}); | ||
}); | ||
describe('dest file ext and two files', function() { | ||
beforeEach(function() { | ||
@@ -678,7 +652,5 @@ mock({ | ||
}); | ||
}); | ||
describe('custom mapping between source and dest', function() { | ||
beforeEach(function() { | ||
@@ -758,3 +730,2 @@ mock({ | ||
}); | ||
}); | ||
@@ -765,3 +736,3 @@ | ||
mock({ | ||
'q': mock.file({ | ||
q: mock.file({ | ||
mtime: new Date(100) | ||
@@ -790,5 +761,3 @@ }), | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28645
836
7
5
+ Addedplugin-error@^0.1.2
+ Addedansi-cyan@0.1.1(transitive)
+ Addedansi-red@0.1.1(transitive)
+ Addedarr-diff@1.1.0(transitive)
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarr-union@2.1.0(transitive)
+ Addedarray-slice@0.2.3(transitive)
+ Addedextend-shallow@1.1.4(transitive)
+ Addedkind-of@1.1.0(transitive)
+ Addedplugin-error@0.1.2(transitive)
- Removedgulp-util@^3.0.7
- Removedansi-gray@0.1.1(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedarray-differ@1.0.0(transitive)
- Removedarray-uniq@1.0.3(transitive)
- Removedbeeper@1.1.1(transitive)
- Removedchalk@1.1.3(transitive)
- Removedclone@1.0.4(transitive)
- Removedclone-stats@0.0.1(transitive)
- Removedcolor-support@1.1.3(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddateformat@2.2.0(transitive)
- Removedduplexer2@0.0.2(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedfancy-log@1.3.3(transitive)
- Removedglogg@1.0.2(transitive)
- Removedgulp-util@3.0.8(transitive)
- Removedgulplog@1.0.0(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhas-gulplog@0.1.0(transitive)
- Removedisarray@0.0.11.0.0(transitive)
- Removedlodash._basecopy@3.0.1(transitive)
- Removedlodash._basetostring@3.0.1(transitive)
- Removedlodash._basevalues@3.0.0(transitive)
- Removedlodash._getnative@3.9.1(transitive)
- Removedlodash._isiterateecall@3.0.9(transitive)
- Removedlodash._reescape@3.0.0(transitive)
- Removedlodash._reevaluate@3.0.0(transitive)
- Removedlodash._reinterpolate@3.0.0(transitive)
- Removedlodash._root@3.0.1(transitive)
- Removedlodash.escape@3.2.0(transitive)
- Removedlodash.isarguments@3.1.0(transitive)
- Removedlodash.isarray@3.0.4(transitive)
- Removedlodash.keys@3.1.2(transitive)
- Removedlodash.restparam@3.6.1(transitive)
- Removedlodash.template@3.6.2(transitive)
- Removedlodash.templatesettings@3.1.1(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmultipipe@0.1.2(transitive)
- Removedobject-assign@3.0.0(transitive)
- Removedparse-node-version@1.0.1(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@1.1.142.3.8(transitive)
- Removedreplace-ext@0.0.1(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedsparkles@1.0.1(transitive)
- Removedstring_decoder@0.10.311.1.1(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedthrough2@2.0.5(transitive)
- Removedtime-stamp@1.1.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedvinyl@0.5.3(transitive)
- Removedxtend@4.0.2(transitive)