path doesnt handle ~ resolution, fallback to env variables, solution taken from https://github.com/nodejs/node-v0.x-archive/issues/2857
567
function tilda(cwd) {
  if (cwd.substring(0, 1) === '~') {
    cwd = (process.env.HOME || process.env.HOMEPATH || process.env.HOMEDIR || process.cwd()) + cwd.substr(1);
  }
  return path.resolve(cwd);
}
398472
function buildSources (path, options) {
  var excludes = options.excludes;
  var sources = [];

  if (options.defaults) {
    sources = options.defaults.concat(sources);
  }

  var environment = getEnvironment(options);

  var basename = nodePath.basename(path);
  var ext = nodePath.extname(basename);

  var pathNoExt = path.slice(0, 0 - ext.length);

  if (!ext) {
    ext = '.json';
  }

  sources.push(pathNoExt + ext);

  if (excludes['env-file'] !== true) {
    sources.push(pathNoExt + '-' + environment + ext);
  }

  if (excludes['local-file'] !== true) {
    sources.push(pathNoExt + '-local' + ext);
  }

  if (excludes['env'] !== true) {
    sources.push(getEnvNodeConfig());
  }

  if (excludes['command-line'] !== true) {
    sources.push(getCommandLineNodeConfig());
  }

  if (options.overrides) {
    sources = sources.concat(options.overrides);
  }

  if (typeof options.sources === 'function') {
    var newSources = options.sources(sources);
    if (newSources != null) {
      sources = newSources;
    }
  }

  return sources;
}
926806
function nodeModulePaths(from) {
  // guarantee that 'from' is absolute.
  from = path.resolve(from);

  // note: this approach *only* works when the path is guaranteed
  // to be absolute.  Doing a fully-edge-case-correct path.split
  // that works on both Windows and Posix is non-trivial.
  var splitRe = process.platform === 'win32' ? /[\/\\]/ : /\//;
  var paths = [];
  var parts = from.split(splitRe);

  for (var tip = parts.length - 1; tip >= 0; tip--) {
    // don't search in .../node_modules/node_modules
    if (parts[tip] === 'node_modules') {
      continue;
    }

    var dir = parts.slice(0, tip + 1).concat('node_modules').join(path.sep);
    paths.push(dir);
  }

  return paths;
}
1357050
function envToObject(fullPath) {
    return fs.readFileAsync(fullPath)
        .then((file) => {
            let envVars = {};
            file = file.toString('utf8');
            file = file.replace(/ /g, "");
            let keyvals = file.split(os.EOL)
            for (let i = 0; i <= keyvals.length - 1; ++i) {
                let line = keyvals[i];
                let value = line.substring(line.indexOf('=')+1);
                let key = keyvals[i].split('=')[0];
                if(key !== '') {
                    envVars[key] = value;
                }
            }
            return envVars
        });
}
783797
function PathNotFoundError(path, sympath){
  superError.call(
    this,
    'PathNotFoundError',
    util.format('Path was not found in the tree: %s', sympath)
  );

  this.arrayPath = path;
  this.sympath = sympath;
}
399629
function ConfigFromPath (superConfig, project, version) {
  ConfigFromPath.super_.call(this, superConfig, project, version);

  var strictNS = simpleWrapNS(this.ns);
  strictNS.env = simpleWrapNS(createNamespace(superConfig.getEnvConfig()));

  var files = superConfig._resolvePaths(project, version);
  var loaded = {};

  var generateLoad = function (f) {
    return function (otherVersion) {
      debug('load(%s) in %s', otherVersion, f);
      var dir = path.dirname(f);
      var otherFile = path.resolve(dir, otherVersion + '.js');
      if (loaded[otherFile]) {
        throw new Error('load(' + version + ') conflict in file ' + f);
      }
      try {
        require(otherFile)(strictNS, generateLoad(otherFile));
      } catch (err) {
        if (err.code === 'MODULE_NOT_FOUND') {
          throw new Error('load(' + version + ') fail in file ' + f);
        } else {
          throw err;
        }
      }
    };
  };
  files.forEach(function (f) {
    debug('load %s', f);
    var init = require(f);
    loaded[f] = true;
    if (typeof init !== 'function') {
      throw new Error('bad config file format, `module.exports` must be a function: ' + f);
    }
    init(strictNS, generateLoad(f));
  });

  var loadedFiles = Object.keys(loaded);
  if (loadedFiles.length < 1) {
    throw new Error('cannot find any config files for ' + project + '.' + version);
  } else {
    loadedFiles.forEach(function (f) {
      delete require.cache[f];
    });
  }

  this._loadFinish();
  debug('done');
}
1291682
function normalizePaths(opts) {
  for (var srcKey in opts.src) {
    if (!path.isAbsolute(opts.src[srcKey].glob)) {
      opts.src[srcKey].glob = path.resolve(opts.src[srcKey].glob);
    }
    if (!path.isAbsolute(opts.src[srcKey].basedir)) {
      opts.src[srcKey].basedir = path.resolve(opts.src[srcKey].basedir);
    }
  }
}
1004954
function setResolved(opts, callback) {
    if (typeof opts === 'string') {
        opts = { dirname: opts };
    }

    var shrinkwrapFile = path.join(opts.dirname, 'npm-shrinkwrap.json');
    var createUri = opts.createUri || defaultCreateUri;
    var registries = opts.registries || ['registry.npmjs.org'];
    var rewriteResolved = opts.rewriteResolved || null;
    var rewriteFrom = opts.rewriteFrom || null;

    readJSON(shrinkwrapFile, onjson);

    function onjson(err, json) {
        if (err) {
            return callback(err);
        }

        var existingVersion = json['npm-shrinkwrap-version'];

        if (existingVersion && semver.gt(existingVersion, version)) {
            return callback(errors.InvalidNPMVersion({
                existing: existingVersion,
                current: version
            }));
        }

        json['npm-shrinkwrap-version'] = version;

        json['node-version'] = process.version;

        json = fixResolved(json, null);

        // if top level shrinkwrap has a `from` or `resolved`
        // field then delete them
        if (json.from) {
            json.from = undefined;
        }
        if (json.resolved) {
            json.resolved = undefined;
        }

        fs.writeFile(shrinkwrapFile,
            JSON.stringify(json, null, 2) + '\n', callback);
    }

    function fixResolved(json, name) {
        if (json.from && !json.resolved) {
            computeResolved(json, name);
        }

        // handle the case of no resolved & no from
        if (json.version && name && !json.resolved) {
            json.resolved = createUri(name, json.version);
        }

        if (rewriteResolved && json.resolved) {
            json.resolved = rewriteResolved(json.resolved);
        }

        if (rewriteFrom && json.from) {
            json.from = rewriteFrom(json.from, json.resolved);
        }

        if (json.dependencies) {
            Object.keys(json.dependencies).forEach(function (dep) {
                fixResolved(json.dependencies[dep], dep);
            });
            json.dependencies = json.dependencies;
        }

        return json;
    }

    /*  look for `from` fields and set a `resolved` field next
          to it if the `resolved` does not exist.

        This normalizes `npm shrinkwrap` so a resolved field
          always get's set.

    */
    function computeResolved(json, name) {
        var value = json.from;
        name = name || json.name;

        var uri = url.parse(value);

        // handle the case `from` is a privateRegistryURL
        if ((uri.protocol === 'http:' || uri.protocol === 'https:') &&
            registries.indexOf(uri.host) !== -1
        ) {
            json.resolved = value;
            return;
        }

        // from is {name}@{semver | uri}
        var parts = value.split('@');
        var rest = parts.slice(1).join('@');

        var secondUri = url.parse(rest);

        // from is a {name}@{semver}
        if (!secondUri.protocol) {
            // call createUri to generate a tarball uri
            // for json module name & version
            json.resolved = createUri(name, json.version);
            return;
        } else {
            // from is a git link.
            // do not try to set resolved
            return;
        }
    }
}
570740
function resolve(path, options, callback) {
        resolvePath(path, options, function (err, path) {
            if (err) return callback(err);
            callback(null, { path: path });
        });
    }
218556
function _resolvePackageSync(base, relativePath) {
    var packageJsonPath;
    var packagePath;

    // try to fetch node package
    try {
        packageJsonPath = _resolvePackagePathSync(base, PATH.join(relativePath, 'package.json'));
        packagePath = dirname(packageJsonPath);
    } catch (err) {
        if (err.code !== 'ENOENT') {
            throw err;
        }

        // try to resolve package itself
        packagePath = _resolvePackagePathSync(base, relativePath);
    }

    // compiling resolved metadata
    var packageJson = packageJsonPath && require(packageJsonPath) || {};
    var metadata = packageJson.pym || {};

    metadata.interface =
        metadata.interface ||
        packageJson.pym ? 'pym' :
        packageJson.plugin ? 'architect' :
        // what 'bout amd?
        'commonjs';

    // load package itself
    var packageMainPath;
    var nodeModule;
    switch (metadata.interface) {
        case 'pym':
            packageMainPath = PATH.join(packagePath, metadata.main || packageJson.main);
            nodeModule = require(packageMainPath);
            metadata.provides = metadata.provides || nodeModule.provides || [];
            metadata.consumes = metadata.consumes || nodeModule.consumes || [];
            metadata.packagePath = packagePath;
            metadata.exports = nodeModule;
            break;
        case 'architect':
            var pluginData = packageJson.plugin || {};
            nodeModule = require(packagePath);
            metadata.provides = pluginData.provides || nodeModule.provides || [];
            metadata.consumes = pluginData.consumes || nodeModule.consumes || [];
            metadata.packagePath = packagePath;
            metadata.exports = _wrapToArchitect(nodeModule, metadata);
            break;
        default:
            throw new Error('Unsupported package format ' + relativePath);
    }

    return metadata;
}
1358533
function resolveName(pkgpath) {
  pkgpath = pkgpath.replace(RE_TRAILING, '');

  const cwd = process.cwd();
  const parts = pkgpath.split(path.sep);
  const len = parts.length;

  let idx = 1;

  // Handle packages nested under root
  if (!pkgpath.includes('node_modules') && cwd != pkgpath) {
    // Increase by distance from root
    idx += path.relative(cwd, pkgpath).split(path.sep).length;
    // Handle scoped node_modules
  } else if (parts[len - 2].charAt(0) == '@') {
    idx = 2;
  }

  return parts.slice(len - idx).join(path.sep);
}
1243723
def setup_path(self):
        """"""
        path = self.opts.path or self.config['crony'].get('path')
        if path:
            self.logger.debug(f'Adding {path} to PATH environment variable')
            self.cmd = f'export PATH={path}:$PATH && {self.cmd}'
1182341
function getUnresolvedIconPath (value) {
  const relativePathResult = urlRegexp.exec(value);
  if (!relativePathResult) {
    throw new Error(`Could not parse url "${value}".`);
  }
  return relativePathResult[2] || relativePathResult[3] || relativePathResult[4];
}
1308286
function(err) {
    if (
        process.argv[2] == '-s' && startWithGina
            || process.argv[2] == '--start' && startWithGina
            //Avoid -h, -v  ....
            || !startWithGina && isPath && process.argv.length > 3

        ) {
        if (isPath && !startWithGina) {
            console.log('You are trying to load gina by hand: just make sure that your env ['+env+'] matches the given path ['+ path +']');
        } else if ( typeof(err.stack) != 'undefined' ) {
            console.log('Gina could not determine which bundle to load: ' + err +' ['+env+']' + '\n' + err.stack);
        } else {
            console.log('Gina could not determine which bundle to load: ' + err +' ['+env+']');
        }
        process.exit(1);
    }
}
981584
function toResolvePaths(paths) {
	return paths.map(function (_path) {
		if (_path.indexOf('*') >= 0) return path.resolve(_path); // wildcard path
		return resolve.sync(path.resolve(_path));                // maybe resolve of main path in package.json
	});
}
1073661
function () {
                var resolvedPath = '', resolvedPathStr, i, args = arguments, path, absolute = 0;
                for (i = args.length - 1; i >= 0 && !absolute; i--) {
                    path = args[i];
                    if (typeof path !== 'string' || !path) {
                        continue;
                    }
                    resolvedPath = path + '/' + resolvedPath;
                    absolute = path.charAt(0) === '/';
                }
                resolvedPathStr = normalizeArray(splitPathToArray(resolvedPath), !absolute).join('/');
                return (absolute ? '/' : '') + resolvedPathStr || '.';
            }
1320635
function _from_envfile (fname_tmpl, opts, cfg_so_far, cb) {
  var vals = {
    env: process.env.NODE_ENV || 'development'
  };
  
  _.merge (vals, cfg_so_far);

  var fname = interpolator.parse (fname_tmpl, vals);

// check existence
  fs.access (fname, function (err) {
    if (err) {
      if (opts.ignore_missing) {
        return cb (null, {});
      }
      else {
        return cb (err);
      }
    }

    try {
      var readf = fs.readFileSync (fname);
      var envConfig = dotenv.parse (readf);
      var ka = [];
      var va = [];
  
      if (!opts) opts = {};
  
      _.forEach (envConfig, function (v, k) {
        if (opts.regexp && !(k.match (opts.regexp))) return;
        if (opts.prefix && !(_.startsWith (k, opts.prefix))) return;
        if (opts.prefix) k = k.substr (opts.prefix.length);
        
        // change __ into . in k
        k = k.replace (/__/g, '.');
    
        ka.push (k);
        va.push (v);
      });
    
      var obj = _.zipObjectDeep (ka, va);

      // expand variables in loaded object
      _expand (obj, vals, cb);
  
    } catch (e) {
      return cb (e);
    }
  });
}