Socket
Socket
Sign inDemoInstall

enhanced-resolve

Package Overview
Dependencies
2
Maintainers
2
Versions
128
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.8.3 to 5.9.0

lib/ModulesInHierarchicalDirectoriesPlugin.js

1

lib/createInnerContext.js

@@ -30,2 +30,3 @@ /*

log: innerLog,
yield: options.yield,
fileDependencies: options.fileDependencies,

@@ -32,0 +33,0 @@ contextDependencies: options.contextDependencies,

9

lib/getPaths.js

@@ -9,5 +9,6 @@ /*

module.exports = function getPaths(path) {
if (path === "/") return { paths: ["/"], segments: [""] };
const parts = path.split(/(.*?[\\/]+)/);
const paths = [path];
const seqments = [parts[parts.length - 1]];
const segments = [parts[parts.length - 1]];
let part = parts[parts.length - 1];

@@ -19,10 +20,10 @@ path = path.substr(0, path.length - part.length - 1);

path = path.substr(0, path.length - part.length) || "/";
seqments.push(part.substr(0, part.length - 1));
segments.push(part.substr(0, part.length - 1));
}
part = parts[1];
seqments.push(part);
segments.push(part);
paths.push(part);
return {
paths: paths,
seqments: seqments
segments: segments
};

@@ -29,0 +30,0 @@ };

@@ -8,74 +8,3 @@ /*

const forEachBail = require("./forEachBail");
const getPaths = require("./getPaths");
/** @typedef {import("./Resolver")} Resolver */
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */
module.exports = class ModulesInHierachicDirectoriesPlugin {
/**
* @param {string | ResolveStepHook} source source
* @param {string | Array<string>} directories directories
* @param {string | ResolveStepHook} target target
*/
constructor(source, directories, target) {
this.source = source;
this.directories = /** @type {Array<string>} */ ([]).concat(directories);
this.target = target;
}
/**
* @param {Resolver} resolver the resolver
* @returns {void}
*/
apply(resolver) {
const target = resolver.ensureHook(this.target);
resolver
.getHook(this.source)
.tapAsync(
"ModulesInHierachicDirectoriesPlugin",
(request, resolveContext, callback) => {
const fs = resolver.fileSystem;
const addrs = getPaths(request.path)
.paths.map(p => {
return this.directories.map(d => resolver.join(p, d));
})
.reduce((array, p) => {
array.push.apply(array, p);
return array;
}, []);
forEachBail(
addrs,
(addr, callback) => {
fs.stat(addr, (err, stat) => {
if (!err && stat && stat.isDirectory()) {
const obj = {
...request,
path: addr,
request: "./" + request.request,
module: false
};
const message = "looking for modules in " + addr;
return resolver.doResolve(
target,
obj,
message,
resolveContext,
callback
);
}
if (resolveContext.log)
resolveContext.log(
addr + " doesn't exist or is not a directory"
);
if (resolveContext.missingDependencies)
resolveContext.missingDependencies.add(addr);
return callback();
});
},
callback
);
}
);
}
};
// TODO remove in next major
module.exports = require("./ModulesInHierarchicalDirectoriesPlugin");

@@ -107,2 +107,3 @@ /*

* @property {(function(string): void)=} log log function
* @property {(function (ResolveRequest): void)=} yield yield result, if provided plugins can return several results
*/

@@ -276,2 +277,12 @@

let yield_;
let yieldCalled = false;
if (typeof resolveContext.yield === "function") {
const old = resolveContext.yield;
yield_ = obj => {
yieldCalled = true;
old(obj);
};
}
const message = `resolve '${request}' in '${path}'`;

@@ -314,2 +325,3 @@

},
yield: yield_,
fileDependencies: resolveContext.fileDependencies,

@@ -324,2 +336,3 @@ contextDependencies: resolveContext.contextDependencies,

if (result) return finishResolved(result);
if (yieldCalled) return callback(null);

@@ -338,2 +351,3 @@ return finishWithoutResolve(log);

log: undefined,
yield: yield_,
fileDependencies: resolveContext.fileDependencies,

@@ -348,2 +362,3 @@ contextDependencies: resolveContext.contextDependencies,

if (result) return finishResolved(result);
if (yieldCalled) return callback(null);

@@ -363,7 +378,11 @@ // log is missing for the error details

log: msg => log.push(msg),
yield: yield_,
stack: resolveContext.stack
},
(err, result) => {
err => {
if (err) return callback(err);
// In a case that there is a race condition and yield will be called
if (yieldCalled) return callback(null);
return finishWithoutResolve(log);

@@ -407,2 +426,3 @@ }

log: resolveContext.log,
yield: resolveContext.yield,
fileDependencies: resolveContext.fileDependencies,

@@ -409,0 +429,0 @@ contextDependencies: resolveContext.contextDependencies,

@@ -26,3 +26,3 @@ /*

const MainFieldPlugin = require("./MainFieldPlugin");
const ModulesInHierachicDirectoriesPlugin = require("./ModulesInHierachicDirectoriesPlugin");
const ModulesInHierarchicalDirectoriesPlugin = require("./ModulesInHierarchicalDirectoriesPlugin");
const ModulesInRootPlugin = require("./ModulesInRootPlugin");

@@ -77,3 +77,3 @@ const NextPlugin = require("./NextPlugin");

* @property {(string|RegExp)[]=} restrictions A list of resolve restrictions
* @property {boolean=} useSyncFileSystemCalls Use only the sync constiants of the file system calls
* @property {boolean=} useSyncFileSystemCalls Use only the sync constraints of the file system calls
* @property {boolean=} preferRelative Prefer to resolve module requests as relative requests before falling back to modules

@@ -285,3 +285,3 @@ * @property {boolean=} preferAbsolute Prefer to resolve server-relative urls as absolute paths before falling back to resolve in roots

resolver.ensureHook("internalResolve");
resolver.ensureHook("newInteralResolve");
resolver.ensureHook("newInternalResolve");
resolver.ensureHook("parsedResolve");

@@ -308,2 +308,7 @@ resolver.ensureHook("describedResolve");

// TODO remove in next major
// cspell:word Interal
// Backward-compat
resolver.hooks.newInteralResolve = resolver.hooks.newInternalResolve;
// resolve

@@ -413,3 +418,3 @@ for (const { source, resolveOptions } of [

plugins.push(
new ModulesInHierachicDirectoriesPlugin(
new ModulesInHierarchicalDirectoriesPlugin(
"raw-module",

@@ -425,3 +430,7 @@ item.filter(i => i !== "node_modules"),

plugins.push(
new ModulesInHierachicDirectoriesPlugin("raw-module", item, "module")
new ModulesInHierarchicalDirectoriesPlugin(
"raw-module",
item,
"module"
)
);

@@ -428,0 +437,0 @@ }

@@ -32,3 +32,8 @@ /*

if (err) return callback(err);
callback(null, obj);
if (typeof resolverContext.yield === "function") {
resolverContext.yield(obj);
callback(null, null);
} else {
callback(null, obj);
}
});

@@ -35,0 +40,0 @@ }

@@ -37,3 +37,3 @@ /*

const pathsResult = getPaths(request.path);
const pathSeqments = pathsResult.seqments;
const pathSegments = pathsResult.segments;
const paths = pathsResult.paths;

@@ -51,3 +51,3 @@

if (!err && result) {
pathSeqments[idx] = result;
pathSegments[idx] = result;
containsSymlink = true;

@@ -68,7 +68,7 @@ // Shortcut when absolute symlink found

if (!containsSymlink) return callback();
const resultSeqments =
const resultSegments =
typeof idx === "number"
? pathSeqments.slice(0, idx + 1)
: pathSeqments.slice();
const result = resultSeqments.reduceRight((a, b) => {
? pathSegments.slice(0, idx + 1)
: pathSegments.slice();
const result = resultSegments.reduceRight((a, b) => {
return resolver.join(a, b);

@@ -75,0 +75,0 @@ });

{
"name": "enhanced-resolve",
"version": "5.8.3",
"version": "5.9.0",
"author": "Tobias Koppers @sokra",

@@ -23,2 +23,3 @@ "description": "Offers a async require.resolve function. It's highly configurable.",

"@types/node": "^14.11.1",
"cspell": "4.2.8",
"eslint": "^7.9.0",

@@ -29,3 +30,3 @@ "eslint-config-prettier": "^6.11.0",

"eslint-plugin-prettier": "^3.1.4",
"husky": "^4.3.0",
"husky": "^6.0.0",
"lint-staged": "^10.4.0",

@@ -47,3 +48,3 @@ "memfs": "^3.2.0",

"scripts": {
"lint": "yarn run code-lint && yarn run type-lint && yarn run special-lint",
"lint": "yarn run code-lint && yarn run type-lint && yarn run special-lint && yarn run spelling",
"fix": "yarn run code-lint-fix && yarn run special-lint-fix",

@@ -57,2 +58,3 @@ "code-lint": "eslint --cache lib test",

"pretest": "yarn lint",
"spelling": "cspell \"**/*.*\"",
"test": "mocha --full-trace --check-leaks",

@@ -62,13 +64,7 @@ "test:only": "mocha --full-trace --check-leaks",

"cover": "nyc --reporter=html node node_modules/mocha/bin/_mocha --full-trace --check-leaks",
"cover:ci": "nyc --reporter=lcovonly node node_modules/mocha/bin/_mocha --full-trace --check-leaks"
"cover:ci": "nyc --reporter=lcovonly node node_modules/mocha/bin/_mocha --full-trace --check-leaks",
"prepare": "husky install"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js": [
"eslint --cache"
]
"*.js": "eslint --cache"
},

@@ -75,0 +71,0 @@ "repository": {

@@ -207,2 +207,7 @@ /*

log?: (arg0: string) => void;
/**
* yield result, if provided plugins can return several results
*/
yield?: (arg0: ResolveRequest) => void;
}

@@ -436,3 +441,3 @@ declare interface ResolveOptions {

/**
* Use only the sync constiants of the file system calls
* Use only the sync constraints of the file system calls
*/

@@ -439,0 +444,0 @@ useSyncFileSystemCalls?: boolean;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc