gulp-resolve-dependencies
Advanced tools
Comparing version 1.0.3 to 1.1.0
31
index.js
@@ -7,3 +7,4 @@ 'use strict'; | ||
_ = require('lodash'), | ||
Stream = require('stream'); | ||
Stream = require('stream'), | ||
DAG = require('dag'); | ||
@@ -13,3 +14,9 @@ var PLUGIN_NAME = 'gulp-resolve-dependencies'; | ||
function resolveDependencies(config) { | ||
var stream, | ||
var defaults = { | ||
pattern: /\* @requires [\s-]*(.*\.js)/g, | ||
log: false, | ||
ignoreCircularDependencies: true | ||
}, | ||
stream, | ||
dag = new DAG(), | ||
fileCache = [], | ||
@@ -39,5 +46,12 @@ filesReturned = [], | ||
// Skip if already added to dependencies | ||
if (_.indexOf(fileCache, filePath) !== -1) { | ||
continue; | ||
// Check for circular dependencies | ||
try { | ||
dag.addEdge(targetFile.path, filePath); | ||
} catch (e) { | ||
// Emit error or just continue | ||
if (!config.ignoreCircularDependencies) { | ||
stream.emit('error', new Error(PLUGIN_NAME + ': Circular dependency between "' + targetFile.path + '" and "' + filePath + '"')); | ||
} else { | ||
continue; | ||
} | ||
} | ||
@@ -47,3 +61,3 @@ | ||
if (!fs.existsSync(filePath)) { | ||
stream.emit('error', new Error('File not found: ' + filePath)); | ||
stream.emit('error', new Error(PLUGIN_NAME + ': File not found: ' + filePath)); | ||
@@ -73,6 +87,3 @@ continue; | ||
// Set default values | ||
config = _.merge({ | ||
pattern: /\* @requires [\s-]*(.*\.js)/g, | ||
log: false | ||
}, config); | ||
config = _.merge(defaults, config); | ||
@@ -79,0 +90,0 @@ // Happy streaming |
{ | ||
"name": "gulp-resolve-dependencies", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "Resolve dependency directives in assets (e.g. \"@requires\" or \"//= require\" in JavaScript)", | ||
@@ -12,3 +12,4 @@ "license": "MIT", | ||
"scripts": { | ||
"test": "mocha" | ||
"pretest": "npm i", | ||
"test": "./node_modules/mocha/bin/mocha" | ||
}, | ||
@@ -29,10 +30,12 @@ "main": "./index.js", | ||
"dependencies": { | ||
"gulp-util": "~3.0.1", | ||
"lodash": "~2.4.1" | ||
"dag": "0.0.1", | ||
"gulp-util": "^3.0.3", | ||
"lodash": "^3.1.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~2.0.1", | ||
"event-stream": "~3.1.7", | ||
"gulp": "~3.8.10" | ||
"event-stream": "^3.2.2", | ||
"gulp": "^3.8.10", | ||
"gulp-concat": "^2.4.3", | ||
"mocha": "^2.1.0" | ||
} | ||
} |
@@ -51,3 +51,5 @@ # gulp-resolve-dependencies | ||
Circular dependencies are either silently ignored or emit an error (thanks to [@huang64](https://github.com/backflip/gulp-resolve-dependencies/pull/7)). See ```options.ignoreCircularDependencies``` below. | ||
## API | ||
@@ -60,3 +62,3 @@ | ||
The matching pattern (optional, defaults to ```/\* @requires [\s-]*(.*?\.js)/g``). | ||
The matching pattern (defaults to ```/\* @requires [\s-]*(.*?\.js)/g``). | ||
@@ -66,3 +68,8 @@ #### options.log | ||
Whether to log the resolved dependencies (optional, defaults to ```false```). | ||
Whether to log the resolved dependencies (defaults to ```false```). | ||
#### options.ignoreCircularDependencies | ||
Type: `Boolean` | ||
Whether to just continue instead of emitting an error if circular dependencies are detected (defaults to ```true```). | ||
@@ -1,6 +0,9 @@ | ||
console.log('lib.js'); | ||
console.log('lib2.js'); | ||
/** | ||
* @requires lib2.js/lib2.js | ||
*/ | ||
console.log('lib.js'); | ||
/** | ||
* @requires ../libs/lib.js | ||
@@ -7,0 +10,0 @@ * @requires ../libs/lib2.js/lib2.js |
@@ -0,1 +1,4 @@ | ||
/** | ||
* @requires lib2.js/lib2.js | ||
*/ | ||
console.log('lib.js'); |
@@ -26,2 +26,12 @@ var gulp = require('gulp'), | ||
}); | ||
it('should throw error due to circular dependency', function(done) { | ||
gulp.src(__dirname + '/circular/a.js') | ||
.pipe(resolveDependencies({ | ||
ignoreCircularDependencies: false | ||
})) | ||
.on('error', function() { | ||
done(); | ||
}); | ||
}); | ||
}); |
8987
16
176
73
3
4
+ Addeddag@0.0.1
+ Addeddag@0.0.1(transitive)
+ Addedlodash@3.10.1(transitive)
- Removedlodash@2.4.2(transitive)
Updatedgulp-util@^3.0.3
Updatedlodash@^3.1.0