Skip to content

Commit ff1a665

Browse files
authored
Merge pull request #24 from backflip/feature/extend
Add possibility to ignore matches via resolvePath option
2 parents c374d4c + a392e88 commit ff1a665

File tree

5 files changed

+57
-2
lines changed

5 files changed

+57
-2
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ Parameters:
7777

7878
The `path` package is available in this context.
7979

80+
Returning a falsy value will ignore the resolved path:
81+
```javascript
82+
function(match, targetFile) {
83+
// Ignore `/lib.js`
84+
if (match.match(/\/lib\.js$/)) {
85+
return null;
86+
}
87+
88+
return path.join(path.dirname(targetFile.path), match);
89+
}
90+
```
91+
8092
#### options.log
8193
Type: `Boolean`
8294

index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ function resolveDependencies(config) {
4848
while (match = pattern.exec(content)) {
4949
filePath = config.resolvePath(match[1], targetFile);
5050

51+
if (!filePath) {
52+
if (config.log) {
53+
Log('[' + AnsiColors.green(PLUGIN_NAME) + '] Ignored', match[1]);
54+
}
55+
56+
continue;
57+
}
58+
5159
// Check for circular dependencies
5260
try {
5361
dag.addEdge(targetFile.path, filePath);

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gulp-resolve-dependencies",
3-
"version": "3.0.1",
3+
"version": "4.0.0",
44
"description": "Resolve dependency directives in assets (e.g. \"@requires\" or \"//= require\" in JavaScript)",
55
"license": "MIT",
66
"repository": "backflip/gulp-resolve-dependencies",
@@ -9,7 +9,6 @@
99
"node": ">=6"
1010
},
1111
"scripts": {
12-
"pretest": "npm i",
1312
"test": "./node_modules/mocha/bin/mocha"
1413
},
1514
"main": "./index.js",

test/expected/filtered.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @requires lib2.js/lib2.js
3+
*/
4+
console.log('lib.js');
5+
6+
/**
7+
* @requires ../libs/lib.js
8+
* @requires ../libs/lib2.js/lib2.js
9+
*/
10+
console.log('test.js');
11+
12+
/**
13+
* @requires test/test.js
14+
*/
15+
console.log('main.js');

test/main.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,25 @@ describe('gulp-resolve-dependencies', function() {
8989
done();
9090
});
9191
});
92+
93+
it('should ignore lib2.js', function(done) {
94+
gulp.src(__dirname + '/fixtures/main.js')
95+
.pipe(resolveDependencies({
96+
resolvePath: function(match, targetFile) {
97+
// Ignore specific matches
98+
if (match.match(/\/lib2\.js$/)) {
99+
return null;
100+
}
101+
102+
return path.join(path.dirname(path.resolve(targetFile.path)), match);
103+
},
104+
log: true
105+
}))
106+
.pipe(concat('filtered.js'))
107+
.pipe(gulp.dest(__dirname + '/results/'))
108+
.pipe(es.wait(function() {
109+
assertFilesEqual('filtered.js');
110+
done();
111+
}));
112+
});
92113
});

0 commit comments

Comments
 (0)