Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

relative paths when analyzing folders #65

Open
pmelisko opened this issue Jan 4, 2018 · 0 comments
Open

relative paths when analyzing folders #65

pmelisko opened this issue Jan 4, 2018 · 0 comments

Comments

@pmelisko
Copy link

pmelisko commented Jan 4, 2018

What was the purpose of building path (target) of __dirname in analyzer.dir? When I am analyzing file it works correctly with relative paths (if relative path is provided reaquire("fs"), path will be relative to process.cwd(), expected behaviour), but when I want to analyze folder, I need to provide full path or relative path from node_modules/require-analyzer, besause __dirname refers to directory name of the current module.

analyzer.path - works with relative paths

nalyzer.path = function(options, callback){
  ...
  fs.stat(options.target, function (err, stats) {

analyzer.file - works with relative paths

function analyzeFile (options, callback) {
  var remaining = 1;

  function cb(err, data){
    if(!--remaining) callback();
  }

  fs.readFile(options.target, function(err, data){
    if(err) return callback(err);

analyzer.dir - doenst work with relative paths, resolve path with __dirname

analyzer.dir = function (options, callback) {
  var target = path.resolve(__dirname, options.target);

  //
  // Read the target directory 
  //
  fs.readdir(target, function (err, files) {
    if (err) {
      return callback(err);
    }
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant