Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"func-style": 0,
"global-require": 1,
"id-length": [2, { "min": 1, "max": 40 }],
"max-lines": [2, 350],
"max-lines": [2, 360],
"max-lines-per-function": 1,
"max-nested-callbacks": 0,
"max-params": 0,
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ install:
- IF %nodejs_version% EQU 4 npm -g install npm@5.3
- IF %nodejs_version% EQU 5 npm -g install npm@5.3
- IF %nodejs_version% EQU 6 npm -g install npm@6.9
- IF %nodejs_version% EQU 7 npm -g install npm@5
- IF %nodejs_version% EQU 7 npm -g install npm@6
- IF %nodejs_version% EQU 8 npm -g install npm@6
- IF %nodejs_version% EQU 9 npm -g install npm@6.9
Expand Down
12 changes: 8 additions & 4 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ var isCore = require('is-core-module');

var realpathFS = process.platform !== 'win32' && fs.realpath && typeof fs.realpath.native === 'function' ? fs.realpath.native : fs.realpath;

var relativePathRegex = /^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/;
var windowsDriveRegex = /^\w:[/\\]*$/;
var nodeModulesRegex = /[/\\]node_modules[/\\]*$/;

var homedir = getHomedir();
var defaultPaths = function () {
return [
Expand Down Expand Up @@ -138,10 +142,10 @@ module.exports = function resolve(x, options, callback) {

var res;
function validBasedir(basedir) {
if ((/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/).test(x)) {
if (relativePathRegex.test(x)) {
res = path.resolve(basedir, x);
if (x === '.' || x === '..' || x.slice(-1) === '/') res += '/';
if ((/\/$/).test(x) && res === basedir) {
if (x.slice(-1) === '/' && res === basedir) {
loadAsDirectory(res, opts.package, onfile);
} else loadAsFile(res, opts.package, onfile);
} else if (includeCoreModules && isCore(x)) {
Expand Down Expand Up @@ -229,10 +233,10 @@ module.exports = function resolve(x, options, callback) {

function loadpkg(dir, cb) {
if (dir === '' || dir === '/') return cb(null);
if (process.platform === 'win32' && (/^\w:[/\\]*$/).test(dir)) {
if (process.platform === 'win32' && windowsDriveRegex.test(dir)) {
return cb(null);
}
if ((/[/\\]node_modules[/\\]*$/).test(dir)) return cb(null);
if (nodeModulesRegex.test(dir)) return cb(null);

maybeRealpath(realpath, dir, opts, function (unwrapErr, pkgdir) {
if (unwrapErr) return loadpkg(path.dirname(dir), cb);
Expand Down
7 changes: 5 additions & 2 deletions lib/node-modules-paths.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
var path = require('path');
var parse = path.parse || require('path-parse'); // eslint-disable-line global-require

var driveLetterRegex = /^([A-Za-z]:)/;
var uncPathRegex = /^\\\\/;

var getNodeModulesDirs = function getNodeModulesDirs(absoluteStart, modules) {
var prefix = '/';
if ((/^([A-Za-z]:)/).test(absoluteStart)) {
if (driveLetterRegex.test(absoluteStart)) {
prefix = '';
} else if ((/^\\\\/).test(absoluteStart)) {
} else if (uncPathRegex.test(absoluteStart)) {
prefix = '\\\\';
}

Expand Down
10 changes: 7 additions & 3 deletions lib/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ var normalizeOptions = require('./normalize-options');

var realpathFS = process.platform !== 'win32' && fs.realpathSync && typeof fs.realpathSync.native === 'function' ? fs.realpathSync.native : fs.realpathSync;

var relativePathRegex = /^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/;
var windowsDriveRegex = /^\w:[/\\]*$/;
var nodeModulesRegex = /[/\\]node_modules[/\\]*$/;

var homedir = getHomedir();
var defaultPaths = function () {
return [
Expand Down Expand Up @@ -98,7 +102,7 @@ module.exports = function resolveSync(x, options) {
throw dirError;
}

if ((/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/).test(x)) {
if (relativePathRegex.test(x)) {
var res = path.resolve(absoluteStart, x);
if (x === '.' || x === '..' || x.slice(-1) === '/') res += '/';
var m = loadAsFileSync(res) || loadAsDirectorySync(res);
Expand Down Expand Up @@ -139,10 +143,10 @@ module.exports = function resolveSync(x, options) {

function loadpkg(dir) {
if (dir === '' || dir === '/') return;
if (process.platform === 'win32' && (/^\w:[/\\]*$/).test(dir)) {
if (process.platform === 'win32' && windowsDriveRegex.test(dir)) {
return;
}
if ((/[/\\]node_modules[/\\]*$/).test(dir)) return;
if (nodeModulesRegex.test(dir)) return;

var pkgfile = path.join(isDirectory(dir) ? maybeRealpathSync(realpathSync, dir, opts) : dir, 'package.json');

Expand Down