Comparing version 0.1.3 to 0.1.4
@@ -13,4 +13,6 @@ "use strict"; | ||
var baseDir | ||
var extensions | ||
var foldersToIgnore = ['node_modules']; | ||
function scan(dir, extensions){ | ||
function scan(dir, extensions_){ | ||
if(scanned){ | ||
@@ -20,10 +22,22 @@ return scanResults; | ||
baseDir = dir; | ||
scanResults = _scan(dir, extensions); | ||
scanned = true; | ||
return scanResults; | ||
extensions = extensions_; | ||
return rescan(); | ||
} | ||
} | ||
function rescan(){ | ||
filesInProject = {}; | ||
ambiguousFileNames = {}; | ||
scanResults = _scan(baseDir, extensions); | ||
scanned = true; | ||
return scanResults; | ||
} | ||
scan.setIgnoreAndRescan = function(foldersToIgnore_){ | ||
foldersToIgnore = foldersToIgnore_.concat(['node_modules']); | ||
return rescan(); | ||
} | ||
function _scan (dir, extensions){ | ||
@@ -35,3 +49,5 @@ var file, files, filePath, _i, _len; | ||
filePath = path.normalize(dir + "/" + file); | ||
if (shouldScanFurther(dir,file)){ | ||
if (shouldIgnore (dir,file)){ | ||
continue; | ||
} else if (shouldScanFurther(dir,file)){ | ||
_scan(filePath,extensions); | ||
@@ -80,4 +96,3 @@ }else{ | ||
function shouldScanFurther(root,file){ | ||
if ( file === "node_modules" || | ||
file.substr(0,1) === "." || | ||
if (file.substr(0,1) === "." || | ||
!fs.statSync(root+"/"+file).isDirectory()) { | ||
@@ -88,2 +103,7 @@ return false; | ||
} | ||
} | ||
function shouldIgnore(root, file){ | ||
var relPath = path.relative(baseDir,root); | ||
return !!~foldersToIgnore.indexOf(relPath) | ||
} |
@@ -36,2 +36,9 @@ "use strict"; | ||
rekuire.ignore = function(/*args*/){ | ||
var args = Array.prototype.slice.call(arguments); | ||
scanResults = scan.setIgnoreAndRescan(args) | ||
filesInProject = scanResults.filesInProject; | ||
ambiguousFileNames = scanResults.ambiguousFileNames; | ||
} | ||
function getPath(requirement){ | ||
@@ -38,0 +45,0 @@ var location = getModule(requirement).path; |
{ | ||
"name": "rekuire", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "'rekuire' is basically node's 'require' without the relative paths", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -18,2 +18,8 @@ Rekuire [![NPM version](https://badge.fury.io/js/rekuire.png)](http://badge.fury.io/js/rekuire) | ||
---------- | ||
####0.1.4 | ||
> * added a method to ignore folders while searching the right files (for example, the js files in the server's static folder) | ||
helpers | ||
isString.js | ||
scan.js | ||
main.js | ||
####0.1.3 | ||
@@ -50,2 +56,12 @@ > * you can now rekuire file according to the relative path of the file | ||
in order to tell the scanner, not to scan specific folders<br/> | ||
use: <br/> | ||
``` | ||
var mypath = rek.ignore('out', 'target', 'static/js'); | ||
``` | ||
<br/> | ||
if you want to resolve only the file location, for example, when you want to use [proxyquire][proxyquire].<br/> | ||
@@ -60,3 +76,3 @@ use: <br/> | ||
for more examples, I recommand you to checkout the spec file :) | ||
for more examples, I recommend you to checkout the spec file :) | ||
@@ -79,3 +95,3 @@ <br/> | ||
------- | ||
if you are having any problems, requests or critisizm, don't hesitate to open an [issue, here][issue] | ||
if you are having any problems, requests or criticism, don't hesitate to open an [issue, here][issue] | ||
@@ -82,0 +98,0 @@ <br/> |
@@ -174,2 +174,14 @@ "use strict"; | ||
}); | ||
describe("ignoring", function(){ | ||
it("should be able to ignore folders", function(){ | ||
var rek = require('rekuire'); | ||
rek.ignore('test/testResources/out','test/testResources/target') | ||
var found = null; | ||
try{ | ||
found = rek('shouldNotFind'); | ||
}catch(e){} | ||
expect(found ).toBeNull(); | ||
}); | ||
}); | ||
}); | ||
@@ -176,0 +188,0 @@ |
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
16024
18
348
107