Skip to content

relative paths when analyzing folders #65

@pmelisko

Description

@pmelisko

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);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions