WXL
3 天以前 2cc85c64f1c64a2dbaeae276a3e2ca8420de76b7
node_modules/resolve/lib/async.js
@@ -5,6 +5,8 @@
var nodeModulesPaths = require('./node-modules-paths');
var normalizeOptions = require('./normalize-options');
var isCore = require('is-core-module');
var $Error = require('es-errors');
var $TypeError = require('es-errors/type');
var realpathFS = process.platform !== 'win32' && fs.realpath && typeof fs.realpath.native === 'function' ? fs.realpath.native : fs.realpath;
@@ -13,12 +15,13 @@
var nodeModulesRegex = /[/\\]node_modules[/\\]*$/;
var homedir = getHomedir();
var defaultPaths = function () {
function defaultPaths() {
    if (!homedir) return [];
    return [
        path.join(homedir, '.node_modules'),
        path.join(homedir, '.node_libraries')
    ];
};
}
var defaultIsFile = function isFile(file, cb) {
    fs.stat(file, function (err, stat) {
@@ -47,15 +50,15 @@
    });
};
var maybeRealpath = function maybeRealpath(realpath, x, opts, cb) {
function maybeRealpath(realpath, x, opts, cb) {
    if (opts && opts.preserveSymlinks === false) {
        realpath(x, cb);
    } else {
        cb(null, x);
    }
};
}
var defaultReadPackage = function defaultReadPackage(readFile, pkgfile, cb) {
function defaultReadPackage(readFile, pkgfile, cb) {
    readFile(pkgfile, function (readFileErr, body) {
        if (readFileErr) cb(readFileErr);
        else {
@@ -67,15 +70,15 @@
            }
        }
    });
};
}
var getPackageCandidates = function getPackageCandidates(x, start, opts) {
function getPackageCandidates(x, start, opts) {
    var dirs = nodeModulesPaths(start, opts, x);
    for (var i = 0; i < dirs.length; i++) {
        dirs[i] = path.join(dirs[i], x);
    }
    return dirs;
};
}
module.exports = function resolve(x, options, callback) {
    var cb = callback;
@@ -85,7 +88,7 @@
        opts = {};
    }
    if (typeof x !== 'string') {
        var err = new TypeError('Path must be a string.');
        var err = new $TypeError('Path must be a string.');
        return process.nextTick(function () {
            cb(err);
        });
@@ -99,7 +102,7 @@
    var realpath = opts.realpath || defaultRealpath;
    var readPackage = opts.readPackage || defaultReadPackage;
    if (opts.readFile && opts.readPackage) {
        var conflictErr = new TypeError('`readFile` and `readPackage` are mutually exclusive.');
        var conflictErr = new $TypeError('`readFile` and `readPackage` are mutually exclusive.');
        return process.nextTick(function () {
            cb(conflictErr);
        });
@@ -147,7 +150,7 @@
                    }
                });
            } else {
                var moduleError = new Error("Cannot find module '" + x + "' from '" + parent + "'");
                var moduleError = new $Error("Cannot find module '" + x + "' from '" + parent + "'");
                moduleError.code = 'MODULE_NOT_FOUND';
                cb(moduleError);
            }
@@ -168,7 +171,7 @@
                    }
                });
            } else {
                var moduleError = new Error("Cannot find module '" + x + "' from '" + parent + "'");
                var moduleError = new $Error("Cannot find module '" + x + "' from '" + parent + "'");
                moduleError.code = 'MODULE_NOT_FOUND';
                cb(moduleError);
            }
@@ -202,7 +205,7 @@
                    var rel = rfile.slice(0, rfile.length - exts[0].length);
                    var r = opts.pathFilter(pkg, x, rel);
                    if (r) return load(
                        [''].concat(extensions.slice()),
                        [''].concat(extensions),
                        path.resolve(dir, r),
                        pkg
                    );
@@ -232,7 +235,7 @@
                if (!ex) return loadpkg(path.dirname(dir), cb);
                readPackage(readFile, pkgfile, function (err, pkgParam) {
                    if (err) cb(err);
                    if (err) { return cb(err); }
                    var pkg = pkgParam;
@@ -271,7 +274,7 @@
                    if (pkg && pkg.main) {
                        if (typeof pkg.main !== 'string') {
                            var mainError = new TypeError('package “' + pkg.name + '” `main` must be a string');
                            var mainError = new $TypeError('package “' + pkg.name + '” `main` must be a string');
                            mainError.code = 'INVALID_PACKAGE_MAIN';
                            return cb(mainError);
                        }