Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Fix revved regex to support extensionless paths #573

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/revvedfinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,19 @@ RevvedFinder.prototype.getCandidatesFromMapping = function (file, searchPaths) {

RevvedFinder.prototype.getCandidatesFromFS = function (file, searchPaths) {
var extname = path.extname(file);
var regExtname = extname || '.';
var basename = path.basename(file, extname);
var dirname = path.dirname(file);
var hex = '[0-9a-fA-F]+';
var regPrefix = '(' + hex + '\\.' + regexpQuote(basename) + ')';
var regSuffix = '(' + regexpQuote(basename) + '\\.' + hex + regexpQuote(extname) + ')';
var regSuffix = '(' + regexpQuote(basename) + '\\.' + hex + regexpQuote(regExtname) + ')';
var revvedRx = new RegExp(regPrefix + '|' + regSuffix);
var candidates = [];
var self = this;

searchPaths.forEach(function (sp) {
var searchString = path.join(sp, dirname, basename + '.*' + extname);
var prefixSearchString = path.join(sp, dirname, '*.' + basename + extname);
var searchString = path.join(sp, dirname, basename + '.*' + regExtname);
var prefixSearchString = path.join(sp, dirname, '*.' + basename + regExtname);

if (searchString.indexOf('#') === 0) {
// patterns starting with # are treated as comments by the glob implementation which returns undefined,
Expand Down
8 changes: 8 additions & 0 deletions test/test-revvedfinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ describe('RevvedFinder', function () {
assert.equal(rfile, 'fred.html');
});

it('should support extensionless paths', function () {
var rf = new RevvedFinder(function () {
return ['path.css'];
});
var rfile = rf.find('path', '.');
assert.equal(rfile, 'path');
});

// it('should restrict to the furnished subdirectories', function () {
// var rf = new RevvedFinder(function (pattern) {
// assert.equal(pattern, '{temp,dist}/**/*fred\\.html');
Expand Down