Socket
Socket
Sign inDemoInstall

enhanced-resolve

Package Overview
Dependencies
2
Maintainers
4
Versions
127
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.14.0 to 5.14.1

17

lib/AliasFieldPlugin.js

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

/** @typedef {import("./Resolver")} Resolver */
/** @typedef {import("./Resolver").JsonPrimitive} JsonPrimitive */
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */

@@ -53,2 +54,3 @@ /** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */

}
/** @type {JsonPrimitive | undefined} */
const data = Object.prototype.hasOwnProperty.call(

@@ -58,5 +60,9 @@ fieldData,

)
? fieldData[innerRequest]
? /** @type {{[Key in string]: JsonPrimitive}} */ (fieldData)[
innerRequest
]
: innerRequest.startsWith("./")
? fieldData[innerRequest.slice(2)]
? /** @type {{[Key in string]: JsonPrimitive}} */ (fieldData)[
innerRequest.slice(2)
]
: undefined;

@@ -77,6 +83,7 @@ if (data === innerRequest) return callback();

}
/** @type {ResolveRequest} */
const obj = {
...request,
path: request.descriptionFileRoot,
request: data,
path: /** @type {string} */ (request.descriptionFileRoot),
request: /** @type {string} */ (data),
fullySpecified: false

@@ -92,3 +99,3 @@ };

"' to '" +
data +
/** @type {string} */ (data) +
"'",

@@ -95,0 +102,0 @@ resolveContext,

@@ -14,3 +14,4 @@ /*

/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */
/** @typedef {{alias: string|Array<string>|false, name: string, onlyModule?: boolean}} AliasOption */
/** @typedef {string | Array<string> | false} Alias */
/** @typedef {{alias: Alias, name: string, onlyModule?: boolean}} AliasOption */

@@ -35,2 +36,6 @@ module.exports = class AliasPlugin {

const target = resolver.ensureHook(this.target);
/**
* @param {string} maybeAbsolutePath path
* @returns {null|string} absolute path with slash ending
*/
const getAbsolutePathWithSlashEnding = maybeAbsolutePath => {

@@ -43,2 +48,7 @@ const type = getType(maybeAbsolutePath);

};
/**
* @param {string} path path
* @param {string} maybeSubPath sub path
* @returns {boolean} true, if path is sub path
*/
const isSubPath = (path, maybeSubPath) => {

@@ -57,2 +67,3 @@ const absolutePath = getAbsolutePathWithSlashEnding(maybeSubPath);

(item, callback) => {
/** @type {boolean} */
let shouldStop = false;

@@ -66,3 +77,9 @@ if (

) {
/** @type {string} */
const remainingRequest = innerRequest.slice(item.name.length);
/**
* @param {Alias} alias alias
* @param {(err?: null|Error, result?: null|ResolveRequest) => void} callback callback
* @returns {void}
*/
const resolveWithAlias = (alias, callback) => {

@@ -87,2 +104,3 @@ if (alias === false) {

const newRequestStr = alias + remainingRequest;
/** @type {ResolveRequest} */
const obj = {

@@ -113,2 +131,7 @@ ...request,

};
/**
* @param {null|Error} [err] error
* @param {null|ResolveRequest} [result] result
* @returns {void}
*/
const stoppingCallback = (err, result) => {

@@ -115,0 +138,0 @@ if (err) return callback(err);

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

/** @typedef {import("./Resolver")} Resolver */
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */

@@ -33,2 +34,3 @@

.tapAsync("AppendPlugin", (request, resolveContext, callback) => {
/** @type {ResolveRequest} */
const obj = {

@@ -35,0 +37,0 @@ ...request,

@@ -12,3 +12,13 @@ /*

/** @typedef {import("./Resolver").SyncFileSystem} SyncFileSystem */
/** @typedef {any} BaseFileSystem */
/**
* @template T
* @typedef {import("./Resolver").FileSystemCallback<T>} FileSystemCallback<T>
*/
/**
* @param {string} path path
* @returns {string} dirname
*/
const dirname = path => {

@@ -26,2 +36,8 @@ let idx = path.length - 1;

/**
* @template T
* @param {FileSystemCallback<T>[]} callbacks callbacks
* @param {Error | undefined} err error
* @param {T} result result
*/
const runCallbacks = (callbacks, err, result) => {

@@ -47,5 +63,5 @@ if (callbacks.length === 1) {

/**
* @param {any} provider async method
* @param {any} syncProvider sync method
* @param {any} providerContext call context for the provider methods
* @param {function} provider async method in filesystem
* @param {function} syncProvider sync method in filesystem
* @param {BaseFileSystem} providerContext call context for the provider methods
*/

@@ -59,3 +75,9 @@ constructor(provider, syncProvider, providerContext) {

this.provide = this._provider
? (path, options, callback) => {
? /**
* @param {string} path path
* @param {any} options options
* @param {function} callback callback
* @returns {any} result
*/
(path, options, callback) => {
if (typeof options === "function") {

@@ -83,10 +105,22 @@ callback = options;

this._activeAsyncOperations.set(path, (callbacks = [callback]));
provider(path, (err, result) => {
this._activeAsyncOperations.delete(path);
runCallbacks(callbacks, err, result);
});
provider(
path,
/**
* @param {Error} err error
* @param {any} result result
*/
(err, result) => {
this._activeAsyncOperations.delete(path);
runCallbacks(callbacks, err, result);
}
);
}
: null;
this.provideSync = this._syncProvider
? (path, options) => {
? /**
* @param {string} path path
* @param {any} options options
* @returns {any} result
*/
(path, options) => {
return this._syncProvider.call(this._providerContext, path, options);

@@ -128,5 +162,5 @@ }

* @param {number} duration max cache duration of items
* @param {any} provider async method
* @param {any} syncProvider sync method
* @param {any} providerContext call context for the provider methods
* @param {function} provider async method
* @param {function} syncProvider sync method
* @param {BaseFileSystem} providerContext call context for the provider methods
*/

@@ -138,5 +172,5 @@ constructor(duration, provider, syncProvider, providerContext) {

this._providerContext = providerContext;
/** @type {Map<string, (function(Error, any): void)[]>} */
/** @type {Map<string, FileSystemCallback<any>[]>} */
this._activeAsyncOperations = new Map();
/** @type {Map<string, { err: Error, result: any, level: Set<string> }>} */
/** @type {Map<string, { err?: Error, result?: any, level: Set<string> }>} */
this._data = new Map();

@@ -157,6 +191,14 @@ /** @type {Set<string>[]} */

// @ts-ignore
this.provide = provider ? this.provide.bind(this) : null;
// @ts-ignore
this.provideSync = syncProvider ? this.provideSync.bind(this) : null;
}
/**
* @param {string} path path
* @param {any} options options
* @param {FileSystemCallback<any>} callback callback
* @returns {void}
*/
provide(path, options, callback) {

@@ -201,13 +243,30 @@ if (typeof options === "function") {

// Run the operation
this._provider.call(this._providerContext, path, (err, result) => {
this._activeAsyncOperations.delete(path);
this._storeResult(path, err, result);
this._provider.call(
this._providerContext,
path,
/**
* @param {Error} [err] error
* @param {any} [result] result
*/
(err, result) => {
this._activeAsyncOperations.delete(path);
this._storeResult(path, err, result);
// Enter async mode if not yet done
this._enterAsyncMode();
// Enter async mode if not yet done
this._enterAsyncMode();
runCallbacks(callbacks, err, result);
});
runCallbacks(
/** @type {FileSystemCallback<any>[]} */ (callbacks),
err,
result
);
}
);
}
/**
* @param {string} path path
* @param {any} options options
* @returns {any} result
*/
provideSync(path, options) {

@@ -244,5 +303,7 @@ if (typeof path !== "string") {

} catch (err) {
this._storeResult(path, err, undefined);
this._storeResult(path, /** @type {Error} */ (err), undefined);
this._enterSyncModeWhenIdle();
if (callbacks) runCallbacks(callbacks, err, undefined);
if (callbacks) {
runCallbacks(callbacks, /** @type {Error} */ (err), undefined);
}
throw err;

@@ -252,6 +313,11 @@ }

this._enterSyncModeWhenIdle();
if (callbacks) runCallbacks(callbacks, undefined, result);
if (callbacks) {
runCallbacks(callbacks, undefined, result);
}
return result;
}
/**
* @param {string|string[]|Set<string>} [what] what to purge
*/
purge(what) {

@@ -292,2 +358,5 @@ if (!what) {

/**
* @param {string|string[]|Set<string>} [what] what to purge
*/
purgeParent(what) {

@@ -307,2 +376,7 @@ if (!what) {

/**
* @param {string} path path
* @param {undefined | Error} err error
* @param {any} result result
*/
_storeResult(path, err, result) {

@@ -326,4 +400,4 @@ if (this._data.has(path)) return;

} else {
// @ts-ignore _nextDecay is always a number in sync mode
this._nextDecay += this._tickInterval;
/** @type {number} */
(this._nextDecay) += this._tickInterval;
}

@@ -352,4 +426,8 @@ }

this._runDecays();
// @ts-ignore _runDecays may change the mode
if (this._mode === STORAGE_MODE_IDLE) return;
// _runDecays may change the mode
if (
/** @type {STORAGE_MODE_IDLE | STORAGE_MODE_SYNC | STORAGE_MODE_ASYNC}*/
(this._mode) === STORAGE_MODE_IDLE
)
return;
timeout = Math.max(

@@ -384,2 +462,12 @@ 0,

/**
* @template {function} Provider
* @template {function} AsyncProvider
* @template FileSystem
* @param {number} duration duration in ms files are cached
* @param {Provider} provider provider
* @param {AsyncProvider} syncProvider sync provider
* @param {FileSystem} providerContext provider context
* @returns {OperationMergerBackend | CacheBackend} backend
*/
const createBackend = (duration, provider, syncProvider, providerContext) => {

@@ -393,2 +481,6 @@ if (duration > 0) {

module.exports = class CachedInputFileSystem {
/**
* @param {BaseFileSystem} fileSystem file system
* @param {number} duration duration in ms files are cached
*/
constructor(fileSystem, duration) {

@@ -428,3 +520,5 @@ this.fileSystem = fileSystem;

const readdirSync = this._readdirBackend.provideSync;
this.readdirSync = /** @type {SyncFileSystem["readdirSync"]} */ (readdirSync);
this.readdirSync = /** @type {SyncFileSystem["readdirSync"]} */ (
readdirSync
);

@@ -440,30 +534,45 @@ this._readFileBackend = createBackend(

const readFileSync = this._readFileBackend.provideSync;
this.readFileSync = /** @type {SyncFileSystem["readFileSync"]} */ (readFileSync);
this.readFileSync = /** @type {SyncFileSystem["readFileSync"]} */ (
readFileSync
);
this._readJsonBackend = createBackend(
duration,
// prettier-ignore
this.fileSystem.readJson ||
(this.readFile &&
((path, callback) => {
// @ts-ignore
this.readFile(path, (err, buffer) => {
if (err) return callback(err);
if (!buffer || buffer.length === 0)
return callback(new Error("No file content"));
let data;
try {
data = JSON.parse(buffer.toString("utf-8"));
} catch (e) {
return callback(e);
}
callback(null, data);
});
})),
(
/**
* @param {string} path path
* @param {FileSystemCallback<any>} callback
*/
(path, callback) => {
this.readFile(path, (err, buffer) => {
if (err) return callback(err);
if (!buffer || buffer.length === 0)
return callback(new Error("No file content"));
let data;
try {
data = JSON.parse(buffer.toString("utf-8"));
} catch (e) {
return callback(/** @type {Error} */ (e));
}
callback(null, data);
});
})
),
// prettier-ignore
this.fileSystem.readJsonSync ||
(this.readFileSync &&
(path => {
const buffer = this.readFileSync(path);
const data = JSON.parse(buffer.toString("utf-8"));
return data;
})),
(
/**
* @param {string} path path
* @returns {any} result
*/
(path) => {
const buffer = this.readFileSync(path);
const data = JSON.parse(buffer.toString("utf-8"));
return data;
}
)),
this.fileSystem

@@ -474,3 +583,5 @@ );

const readJsonSync = this._readJsonBackend.provideSync;
this.readJsonSync = /** @type {SyncFileSystem["readJsonSync"]} */ (readJsonSync);
this.readJsonSync = /** @type {SyncFileSystem["readJsonSync"]} */ (
readJsonSync
);

@@ -486,5 +597,10 @@ this._readlinkBackend = createBackend(

const readlinkSync = this._readlinkBackend.provideSync;
this.readlinkSync = /** @type {SyncFileSystem["readlinkSync"]} */ (readlinkSync);
this.readlinkSync = /** @type {SyncFileSystem["readlinkSync"]} */ (
readlinkSync
);
}
/**
* @param {string|string[]|Set<string>} [what] what to purge
*/
purge(what) {

@@ -491,0 +607,0 @@ this._statBackend.purge(what);

@@ -11,4 +11,10 @@ /*

/** @typedef {import("./Resolver")} Resolver */
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */
module.exports = class CloneBasenamePlugin {
/**
* @param {string | ResolveStepHook} source source
* @param {string | ResolveStepHook} target target
*/
constructor(source, target) {

@@ -28,4 +34,6 @@ this.source = source;

.tapAsync("CloneBasenamePlugin", (request, resolveContext, callback) => {
const filename = basename(request.path);
const filePath = resolver.join(request.path, filename);
const requestPath = /** @type {string} */ (request.path);
const filename = /** @type {string} */ (basename(requestPath));
const filePath = resolver.join(requestPath, filename);
/** @type {ResolveRequest} */
const obj = {

@@ -32,0 +40,0 @@ ...request,

@@ -35,3 +35,3 @@ /*

const { test, message, allowAlternatives } = this;
const keys = Object.keys(test);
const keys = /** @type {(keyof ResolveRequest)[]} */ (Object.keys(test));
resolver

@@ -38,0 +38,0 @@ .getHook(this.source)

@@ -8,7 +8,10 @@ /*

module.exports = function createInnerContext(
options,
message,
messageOptional
) {
/** @typedef {import("./Resolver").ResolveContext} ResolveContext */
/**
* @param {ResolveContext} options options for inner context
* @param {null|string} message message to log
* @returns {ResolveContext} inner context
*/
module.exports = function createInnerContext(options, message) {
let messageReported = false;

@@ -18,8 +21,14 @@ let innerLog = undefined;

if (message) {
/**
* @param {string} msg message
*/
innerLog = msg => {
if (!messageReported) {
options.log(message);
/** @type {(function(string): void)} */
(options.log)(message);
messageReported = true;
}
options.log(" " + msg);
/** @type {(function(string): void)} */
(options.log)(" " + msg);
};

@@ -30,3 +39,4 @@ } else {

}
const childContext = {
return {
log: innerLog,

@@ -39,3 +49,2 @@ yield: options.yield,

};
return childContext;
};

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

/** @typedef {import("./Resolver")} Resolver */
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */

@@ -68,2 +69,3 @@

"." + path.slice(result.directory.length).replace(/\\/g, "/");
/** @type {ResolveRequest} */
const obj = {

@@ -70,0 +72,0 @@ ...request,

@@ -11,7 +11,10 @@ /*

/** @typedef {import("./Resolver")} Resolver */
/** @typedef {import("./Resolver").JsonObject} JsonObject */
/** @typedef {import("./Resolver").JsonValue} JsonValue */
/** @typedef {import("./Resolver").ResolveContext} ResolveContext */
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
/**
* @typedef {Object} DescriptionFileInfo
* @property {any=} content
* @property {JsonObject=} content
* @property {string} path

@@ -28,2 +31,9 @@ * @property {string} directory

/**
* @typedef {Object} Result
* @property {string} path path to description file
* @property {string} directory directory of description file
* @property {JsonObject} content content of description file
*/
/**
* @param {Resolver} resolver resolver

@@ -51,2 +61,7 @@ * @param {string} directory directory

filenames,
/**
* @param {string} filename filename
* @param {(err?: null|Error, result?: null|Result) => void} callback callback
* @returns {void}
*/
(filename, callback) => {

@@ -71,3 +86,3 @@ const descriptionFilePath = resolver.join(directory, filename);

}
onJson(null, content);
onJson(null, /** @type {JsonObject} */ (content));
});

@@ -85,2 +100,4 @@ } else {

}
/** @type {JsonObject | undefined} */
let json;

@@ -91,4 +108,4 @@

json = JSON.parse(content.toString());
} catch (e) {
return onJson(e);
} catch (/** @type {unknown} */ e) {
return onJson(/** @type {Error} */ (e));
}

@@ -103,2 +120,7 @@ } else {

/**
* @param {null|Error} [err] error
* @param {JsonObject} [content] content
* @returns {void}
*/
function onJson(err, content) {

@@ -116,3 +138,3 @@ if (err) {

callback(null, {
content,
content: /** @type {JsonObject} */ (content),
directory,

@@ -123,2 +145,7 @@ path: descriptionFilePath

},
/**
* @param {null|Error} [err] error
* @param {null|Result} [result] result
* @returns {void}
*/
(err, result) => {

@@ -143,5 +170,5 @@ if (err) return callback(err);

/**
* @param {any} content content
* @param {JsonObject} content content
* @param {string|string[]} field field
* @returns {object|string|number|boolean|undefined} field data
* @returns {JsonValue | undefined} field data
*/

@@ -151,2 +178,3 @@ function getField(content, field) {

if (Array.isArray(field)) {
/** @type {JsonValue} */
let current = content;

@@ -158,3 +186,3 @@ for (let j = 0; j < field.length; j++) {

}
current = current[field[j]];
current = /** @type {JsonObject} */ (current)[field[j]];
}

@@ -161,0 +189,0 @@ return current;

@@ -16,2 +16,4 @@ /*

/** @typedef {import("./Resolver")} Resolver */
/** @typedef {import("./Resolver").JsonObject} JsonObject */
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */

@@ -33,3 +35,3 @@ /** @typedef {import("./util/entrypoints").ExportsField} ExportsField */

this.fieldName = fieldNamePath;
/** @type {WeakMap<any, FieldProcessor>} */
/** @type {WeakMap<JsonObject, FieldProcessor>} */
this.fieldProcessorCache = new WeakMap();

@@ -63,7 +65,10 @@ }

: request.request;
/** @type {ExportsField|null} */
const exportsField = DescriptionFileUtils.getField(
request.descriptionFileData,
this.fieldName
);
const exportsField =
/** @type {ExportsField|null|undefined} */
(
DescriptionFileUtils.getField(
/** @type {JsonObject} */ (request.descriptionFileData),
this.fieldName
)
);
if (!exportsField) return callback();

@@ -79,2 +84,3 @@

/** @type {string[]} */
let paths;

@@ -87,3 +93,3 @@

let fieldProcessor = this.fieldProcessorCache.get(
request.descriptionFileData
/** @type {JsonObject} */ (request.descriptionFileData)
);

@@ -93,3 +99,3 @@ if (fieldProcessor === undefined) {

this.fieldProcessorCache.set(
request.descriptionFileData,
/** @type {JsonObject} */ (request.descriptionFileData),
fieldProcessor

@@ -99,3 +105,3 @@ );

paths = fieldProcessor(remainingRequest, this.conditionNames);
} catch (err) {
} catch (/** @type {unknown} */ err) {
if (resolveContext.log) {

@@ -106,3 +112,3 @@ resolveContext.log(

}
return callback(err);
return callback(/** @type {Error} */ (err));
}

@@ -120,2 +126,7 @@

paths,
/**
* @param {string} p path
* @param {(err?: null|Error, result?: null|ResolveRequest) => void} callback callback
* @returns {void}
*/
(p, callback) => {

@@ -134,2 +145,3 @@ const parsedIdentifier = parseIdentifier(p);

/** @type {ResolveRequest} */
const obj = {

@@ -155,2 +167,7 @@ ...request,

},
/**
* @param {null|Error} [err] error
* @param {null|ResolveRequest} [result] result
* @returns {void}
*/
(err, result) => callback(err, result || null)

@@ -157,0 +174,0 @@ );

@@ -40,2 +40,8 @@ /*

const isAliasString = typeof alias === "string";
/**
* @param {string} alias extension alias
* @param {(err?: null|Error, result?: null|ResolveRequest) => void} callback callback
* @param {number} [index] index
* @returns {void}
*/
const resolve = (alias, callback, index) => {

@@ -76,3 +82,7 @@ const newRequest = `${requestPath.slice(

};
/**
* @param {null|Error} [err] error
* @param {null|ResolveRequest} [result] result
* @returns {void}
*/
const stoppingCallback = (err, result) => {

@@ -79,0 +89,0 @@ if (err) return callback(err);

@@ -8,2 +8,22 @@ /*

/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
/**
* @template T
* @template Z
* @callback Iterator
* @param {T} item item
* @param {(err?: null|Error, result?: null|Z) => void} callback callback
* @param {number} i index
* @returns {void}
*/
/**
* @template T
* @template Z
* @param {T[]} array array
* @param {Iterator<T, Z>} iterator iterator
* @param {(err?: null|Error, result?: null|Z) => void} callback callback after all items are iterated
* @returns {void}
*/
module.exports = function forEachBail(array, iterator, callback) {

@@ -14,2 +34,3 @@ if (array.length === 0) return callback();

const next = () => {
/** @type {boolean|undefined} */
let loop = undefined;

@@ -16,0 +37,0 @@ iterator(

@@ -8,2 +8,10 @@ /*

/** @typedef {import("./Resolver")} Resolver */
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
/**
* @param {Resolver} resolver resolver
* @param {ResolveRequest} request string
* @returns {string} inner request
*/
module.exports = function getInnerRequest(resolver, request) {

@@ -16,2 +24,3 @@ if (

return request.__innerRequest;
/** @type {string|undefined} */
let innerRequest;

@@ -28,3 +37,3 @@ if (request.request) {

request.__innerRequest_relativePath = request.relativePath;
return (request.__innerRequest = innerRequest);
return (request.__innerRequest = /** @type {string} */ (innerRequest));
};

@@ -8,2 +8,6 @@ /*

/**
* @param {string} path path
* @returns {{paths: string[], segments: string[]}}} paths and segments
*/
module.exports = function getPaths(path) {

@@ -31,2 +35,6 @@ if (path === "/") return { paths: ["/"], segments: [""] };

/**
* @param {string} path path
* @returns {string|null} basename or null
*/
module.exports.basename = function basename(path) {

@@ -33,0 +41,0 @@ const i = path.lastIndexOf("/"),

@@ -16,2 +16,4 @@ /*

/** @typedef {import("./Resolver")} Resolver */
/** @typedef {import("./Resolver").JsonObject} JsonObject */
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */

@@ -43,3 +45,3 @@ /** @typedef {import("./util/entrypoints").FieldProcessor} FieldProcessor */

this.fieldName = fieldNamePath;
/** @type {WeakMap<any, FieldProcessor>} */
/** @type {WeakMap<JsonObject, FieldProcessor>} */
this.fieldProcessorCache = new WeakMap();

@@ -66,7 +68,10 @@ }

request.request + request.query + request.fragment;
/** @type {ImportsField|null} */
const importsField = DescriptionFileUtils.getField(
request.descriptionFileData,
this.fieldName
);
const importsField =
/** @type {ImportsField|null|undefined} */
(
DescriptionFileUtils.getField(
/** @type {JsonObject} */ (request.descriptionFileData),
this.fieldName
)
);
if (!importsField) return callback();

@@ -82,2 +87,3 @@

/** @type {string[]} */
let paths;

@@ -90,3 +96,3 @@

let fieldProcessor = this.fieldProcessorCache.get(
request.descriptionFileData
/** @type {JsonObject} */ (request.descriptionFileData)
);

@@ -96,3 +102,3 @@ if (fieldProcessor === undefined) {

this.fieldProcessorCache.set(
request.descriptionFileData,
/** @type {JsonObject} */ (request.descriptionFileData),
fieldProcessor

@@ -102,3 +108,3 @@ );

paths = fieldProcessor(remainingRequest, this.conditionNames);
} catch (err) {
} catch (/** @type {unknown} */ err) {
if (resolveContext.log) {

@@ -109,3 +115,3 @@ resolveContext.log(

}
return callback(err);
return callback(/** @type {Error} */ (err));
}

@@ -123,2 +129,7 @@

paths,
/**
* @param {string} p path
* @param {(err?: null|Error, result?: null|ResolveRequest) => void} callback callback
* @returns {void}
*/
(p, callback) => {

@@ -140,2 +151,3 @@ const parsedIdentifier = parseIdentifier(p);

case dotCode: {
/** @type {ResolveRequest} */
const obj = {

@@ -165,2 +177,3 @@ ...request,

default: {
/** @type {ResolveRequest} */
const obj = {

@@ -185,2 +198,7 @@ ...request,

},
/**
* @param {null|Error} [err] error
* @param {null|ResolveRequest} [result] result
* @returns {void}
*/
(err, result) => callback(err, result || null)

@@ -187,0 +205,0 @@ );

@@ -154,2 +154,8 @@ /*

});
/**
* @param {object|string} context custom context
* @param {string} path base path
* @param {string=} request request to resolve
* @returns {string|false} Resolved path or false
*/
return function (context, path, request) {

@@ -161,3 +167,3 @@ if (typeof context === "string") {

}
return resolver.resolveSync(context, path, request);
return resolver.resolveSync(context, path, /** @type {string} */ (request));
};

@@ -164,0 +170,0 @@ }

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

/** @typedef {import("./Resolver")} Resolver */
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */

@@ -42,3 +43,8 @@

let moduleName, remainingRequest, fullySpecified;
/** @type {string} */
let moduleName;
/** @type {string} */
let remainingRequest;
/** @type {boolean} */
let fullySpecified;
if (i < 0) {

@@ -51,7 +57,12 @@ moduleName = req;

remainingRequest = "." + req.slice(i);
fullySpecified = request.fullySpecified;
fullySpecified = /** @type {boolean} */ (request.fullySpecified);
}
/** @type {ResolveRequest} */
const obj = {
...request,
path: resolver.join(request.path, moduleName),
path: resolver.join(
/** @type {string} */
(request.path),
moduleName
),
relativePath:

@@ -58,0 +69,0 @@ request.relativePath &&

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

/** @typedef {import("./Resolver")} Resolver */
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */

@@ -31,8 +32,11 @@

.tapAsync("JoinRequestPlugin", (request, resolveContext, callback) => {
const requestPath = /** @type {string} */ (request.path);
const requestRequest = /** @type {string} */ (request.request);
/** @type {ResolveRequest} */
const obj = {
...request,
path: resolver.join(request.path, request.request),
path: resolver.join(requestPath, requestRequest),
relativePath:
request.relativePath &&
resolver.join(request.relativePath, request.request),
resolver.join(request.relativePath, requestRequest),
request: undefined

@@ -39,0 +43,0 @@ };

@@ -9,4 +9,8 @@ /*

/** @typedef {import("./Resolver")} Resolver */
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */
module.exports = class LogInfoPlugin {
/**
* @param {string | ResolveStepHook} source source
*/
constructor(source) {

@@ -13,0 +17,0 @@ this.source = source;

@@ -12,3 +12,6 @@ /*

/** @typedef {import("./Resolver")} Resolver */
/** @typedef {import("./Resolver").JsonObject} JsonObject */
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */
/** @typedef {{name: string|Array<string>, forceRelative: boolean}} MainFieldOptions */

@@ -41,3 +44,4 @@

request.path !== request.descriptionFileRoot ||
request[alreadyTriedMainField] === request.descriptionFilePath ||
/** @type {ResolveRequest & { [alreadyTriedMainField]?: string }} */
(request)[alreadyTriedMainField] === request.descriptionFilePath ||
!request.descriptionFilePath

@@ -47,6 +51,10 @@ )

const filename = path.basename(request.descriptionFilePath);
let mainModule = DescriptionFileUtils.getField(
request.descriptionFileData,
this.options.name
);
let mainModule =
/** @type {string|null|undefined} */
(
DescriptionFileUtils.getField(
/** @type {JsonObject} */ (request.descriptionFileData),
this.options.name
)
);

@@ -63,2 +71,3 @@ if (

mainModule = "./" + mainModule;
/** @type {ResolveRequest & { [alreadyTriedMainField]?: string }} */
const obj = {

@@ -65,0 +74,0 @@ ...request,

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

/** @typedef {import("./Resolver")} Resolver */
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */

@@ -39,3 +40,3 @@

const fs = resolver.fileSystem;
const addrs = getPaths(request.path)
const addrs = getPaths(/** @type {string} */ (request.path))
.paths.map(p => {

@@ -50,5 +51,11 @@ return this.directories.map(d => resolver.join(p, d));

addrs,
/**
* @param {string} addr addr
* @param {(err?: null|Error, result?: null|ResolveRequest) => void} callback callback
* @returns {void}
*/
(addr, callback) => {
fs.stat(addr, (err, stat) => {
if (!err && stat && stat.isDirectory()) {
/** @type {ResolveRequest} */
const obj = {

@@ -55,0 +62,0 @@ ...request,

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

/** @typedef {import("./Resolver")} Resolver */
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */

@@ -33,2 +34,3 @@

.tapAsync("ModulesInRootPlugin", (request, resolveContext, callback) => {
/** @type {ResolveRequest} */
const obj = {

@@ -35,0 +37,0 @@ ...request,

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

const parsed = resolver.parse(/** @type {string} */ (request.request));
/** @type {ResolveRequest} */
const obj = { ...request, ...parsed, ...this.requestOptions };

@@ -50,2 +51,3 @@ if (request.query && !parsed.query) {

const directory = obj.fragment.endsWith("/");
/** @type {ResolveRequest} */
const alternative = {

@@ -52,0 +54,0 @@ ...obj,

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

/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
/**

@@ -33,2 +34,3 @@ * @typedef {Object} PnpApiImpl

apply(resolver) {
/** @type {ResolveStepHook} */
const target = resolver.ensureHook(this.target);

@@ -50,3 +52,5 @@ resolver

/** @type {string|undefined} */
let resolution;
/** @type {string|undefined} */
let apiResolution;

@@ -62,6 +66,8 @@ try {

}
} catch (error) {
} catch (/** @type {unknown} */ error) {
if (
error.code === "MODULE_NOT_FOUND" &&
error.pnpCode === "UNDECLARED_DEPENDENCY"
/** @type {Error & { code: string }} */
(error).code === "MODULE_NOT_FOUND" &&
/** @type {Error & { pnpCode: string }} */
(error).pnpCode === "UNDECLARED_DEPENDENCY"
) {

@@ -72,3 +78,5 @@ // This is not a PnP managed dependency.

resolveContext.log(`request is not managed by the pnpapi`);
for (const line of error.message.split("\n").filter(Boolean))
for (const line of /** @type {Error} */ (error).message
.split("\n")
.filter(Boolean))
resolveContext.log(` ${line}`);

@@ -78,3 +86,3 @@ }

}
return callback(error);
return callback(/** @type {Error} */ (error));
}

@@ -87,3 +95,3 @@

}
/** @type {ResolveRequest} */
const obj = {

@@ -90,0 +98,0 @@ ...request,

@@ -52,3 +52,3 @@ /*

/** @typedef {function((NodeJS.ErrnoException | null)=, (string | Buffer)[] | IDirent[]=): void} DirentArrayCallback */
/** @typedef {function((NodeJS.ErrnoException | null)=, (string | Buffer)[] | import("fs").Dirent[]=): void} DirentArrayCallback */

@@ -92,11 +92,20 @@ /**

/** @typedef {string | number | boolean | null} JsonPrimitive */
/** @typedef {JsonValue[]} JsonArray */
/** @typedef {JsonPrimitive | JsonObject | JsonArray} JsonValue */
/** @typedef {{[Key in string]: JsonValue} & {[Key in string]?: JsonValue | undefined}} JsonObject */
/**
* @typedef {Object} BaseResolveRequest
* @property {string | false} path
* @property {object=} context
* @property {string=} descriptionFilePath
* @property {string=} descriptionFileRoot
* @property {object=} descriptionFileData
* @property {JsonObject=} descriptionFileData
* @property {string=} relativePath
* @property {boolean=} ignoreSymlinks
* @property {boolean=} fullySpecified
* @property {string=} __innerRequest
* @property {string=} __innerRequest_request
* @property {string=} __innerRequest_relativePath
*/

@@ -111,4 +120,9 @@

/** @template T @typedef {{ add: (T) => void }} WriteOnlySet */
/**
* @template T
* @typedef {{ add: (item: T) => void }} WriteOnlySet
*/
/** @typedef {(function (ResolveRequest): void)} ResolveContextYield */
/**

@@ -122,3 +136,3 @@ * Resolve context

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

@@ -129,2 +143,14 @@

/**
* @typedef {Object} KnownHooks
* @property {SyncHook<[ResolveStepHook, ResolveRequest], void>} resolveStep
* @property {SyncHook<[ResolveRequest, Error]>} noResolve
* @property {ResolveStepHook} resolve
* @property {AsyncSeriesHook<[ResolveRequest, ResolveContext]>} result
*/
/**
* @typedef {{[key: string]: ResolveStepHook}} EnsuredHooks
*/
/**
* @param {string} str input string

@@ -164,8 +190,6 @@ * @returns {string} in camel case

this.options = options;
/** @type {KnownHooks} */
this.hooks = {
/** @type {SyncHook<[ResolveStepHook, ResolveRequest], void>} */
resolveStep: new SyncHook(["hook", "request"], "resolveStep"),
/** @type {SyncHook<[ResolveRequest, Error]>} */
noResolve: new SyncHook(["request", "error"], "noResolve"),
/** @type {ResolveStepHook} */
resolve: new AsyncSeriesBailHook(

@@ -175,3 +199,2 @@ ["request", "resolveContext"],

),
/** @type {AsyncSeriesHook<[ResolveRequest, ResolveContext]>} */
result: new AsyncSeriesHook(["result", "resolveContext"], "result")

@@ -191,21 +214,25 @@ };

if (/^before/.test(name)) {
return /** @type {ResolveStepHook} */ (this.ensureHook(
name[6].toLowerCase() + name.slice(7)
).withOptions({
stage: -10
}));
return /** @type {ResolveStepHook} */ (
this.ensureHook(name[6].toLowerCase() + name.slice(7)).withOptions({
stage: -10
})
);
}
if (/^after/.test(name)) {
return /** @type {ResolveStepHook} */ (this.ensureHook(
name[5].toLowerCase() + name.slice(6)
).withOptions({
stage: 10
}));
return /** @type {ResolveStepHook} */ (
this.ensureHook(name[5].toLowerCase() + name.slice(6)).withOptions({
stage: 10
})
);
}
const hook = this.hooks[name];
/** @type {ResolveStepHook} */
const hook = /** @type {KnownHooks & EnsuredHooks} */ (this.hooks)[name];
if (!hook) {
return (this.hooks[name] = new AsyncSeriesBailHook(
/** @type {KnownHooks & EnsuredHooks} */
(this.hooks)[name] = new AsyncSeriesBailHook(
["request", "resolveContext"],
name
));
);
return /** @type {KnownHooks & EnsuredHooks} */ (this.hooks)[name];
}

@@ -225,16 +252,17 @@ return hook;

if (/^before/.test(name)) {
return /** @type {ResolveStepHook} */ (this.getHook(
name[6].toLowerCase() + name.slice(7)
).withOptions({
stage: -10
}));
return /** @type {ResolveStepHook} */ (
this.getHook(name[6].toLowerCase() + name.slice(7)).withOptions({
stage: -10
})
);
}
if (/^after/.test(name)) {
return /** @type {ResolveStepHook} */ (this.getHook(
name[5].toLowerCase() + name.slice(6)
).withOptions({
stage: 10
}));
return /** @type {ResolveStepHook} */ (
this.getHook(name[5].toLowerCase() + name.slice(6)).withOptions({
stage: 10
})
);
}
const hook = this.hooks[name];
/** @type {ResolveStepHook} */
const hook = /** @type {KnownHooks & EnsuredHooks} */ (this.hooks)[name];
if (!hook) {

@@ -291,2 +319,3 @@ throw new Error(`Hook ${name} doesn't exist`);

/** @type {ResolveRequest} */
const obj = {

@@ -298,7 +327,12 @@ context: context,

/** @type {ResolveContextYield | undefined} */
let yield_;
let yieldCalled = false;
/** @type {ResolveContextYield | undefined} */
let finishYield;
if (typeof resolveContext.yield === "function") {
const old = resolveContext.yield;
/**
* @param {ResolveRequest} obj object
*/
yield_ = obj => {

@@ -308,4 +342,10 @@ old(obj);

};
/**
* @param {ResolveRequest} result result
* @returns {void}
*/
finishYield = result => {
if (result) yield_(result);
if (result) {
/** @type {ResolveContextYield} */ (yield_)(result);
}
callback(null);

@@ -317,2 +357,6 @@ };

/**
* @param {ResolveRequest} result result
* @returns {void}
*/
const finishResolved = result => {

@@ -330,2 +374,6 @@ return callback(

/**
* @param {string[]} log logs
* @returns {void}
*/
const finishWithoutResolve = log => {

@@ -344,2 +392,3 @@ /**

const parentLog = resolveContext.log;
/** @type {string[]} */
const log = [];

@@ -364,3 +413,8 @@ return this.doResolve(

if (yieldCalled || (result && yield_)) return finishYield(result);
if (yieldCalled || (result && yield_)) {
return /** @type {ResolveContextYield} */ (finishYield)(
/** @type {ResolveRequest} */ (result)
);
}
if (result) return finishResolved(result);

@@ -389,3 +443,8 @@

if (yieldCalled || (result && yield_)) return finishYield(result);
if (yieldCalled || (result && yield_)) {
return /** @type {ResolveContextYield} */ (finishYield)(
/** @type {ResolveRequest} */ (result)
);
}
if (result) return finishResolved(result);

@@ -397,3 +456,3 @@

// is assumed by default
/** @type {string[]} */
const log = [];

@@ -414,3 +473,7 @@

// In a case that there is a race condition and yield will be called
if (yieldCalled || (result && yield_)) return finishYield(result);
if (yieldCalled || (result && yield_)) {
return /** @type {ResolveContextYield} */ (finishYield)(
/** @type {ResolveRequest} */ (result)
);
}

@@ -425,5 +488,14 @@ return finishWithoutResolve(log);

/**
* @param {ResolveStepHook} hook hook
* @param {ResolveRequest} request request
* @param {null|string} message string
* @param {ResolveContext} resolveContext resolver context
* @param {(err?: null|Error, result?: ResolveRequest) => void} callback callback
* @returns {void}
*/
doResolve(hook, request, message, resolveContext, callback) {
const stackEntry = Resolver.createStackEntry(hook, request);
/** @type {Set<string> | undefined} */
let newStack;

@@ -507,2 +579,6 @@ if (resolveContext.stack) {

/**
* @param {string} path path
* @returns {boolean} true, if the path is a module
*/
isModule(path) {

@@ -512,2 +588,6 @@ return getType(path) === PathType.Normal;

/**
* @param {string} path path
* @returns {boolean} true, if the path is private
*/
isPrivate(path) {

@@ -525,2 +605,7 @@ return getType(path) === PathType.Internal;

/**
* @param {string} path path
* @param {string} request request
* @returns {string} joined path
*/
join(path, request) {

@@ -530,2 +615,6 @@ return join(path, request);

/**
* @param {string} path path
* @returns {string} normalized path
*/
normalize(path) {

@@ -532,0 +621,0 @@ return normalize(path);

@@ -44,3 +44,5 @@ /*

/** @typedef {import("./PnpPlugin").PnpApiImpl} PnpApi */
/** @typedef {import("./Resolver").EnsuredHooks} EnsuredHooks */
/** @typedef {import("./Resolver").FileSystem} FileSystem */
/** @typedef {import("./Resolver").KnownHooks} KnownHooks */
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */

@@ -159,2 +161,3 @@ /** @typedef {import("./Resolver").SyncFileSystem} SyncFileSystem */

const mainFieldsSet = new Set(options.mainFields || ["main"]);
/** @type {ResolveOptions["mainFields"]} */
const mainFields = [];

@@ -326,2 +329,3 @@

// Backward-compat
// @ts-ignore
resolver.hooks.newInteralResolve = resolver.hooks.newInternalResolve;

@@ -339,3 +343,3 @@

cachePredicate,
unsafeCache,
/** @type {import("./UnsafeCachePlugin").Cache} */ (unsafeCache),
cacheWithContext,

@@ -643,8 +647,13 @@ `new-${source}`

const resolved =
/** @type {KnownHooks & EnsuredHooks} */
(resolver.hooks).resolved;
// resolved
if (restrictions.size > 0) {
plugins.push(new RestrictionsPlugin(resolver.hooks.resolved, restrictions));
plugins.push(new RestrictionsPlugin(resolved, restrictions));
}
plugins.push(new ResultPlugin(resolver.hooks.resolved));
plugins.push(new ResultPlugin(resolved));
//// RESOLVER ////

@@ -654,3 +663,4 @@

if (typeof plugin === "function") {
plugin.call(resolver, resolver);
/** @type {function(this: Resolver, Resolver): void} */
(plugin).call(resolver, resolver);
} else {

@@ -657,0 +667,0 @@ plugin.apply(resolver);

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

/**
* @param {string} path path
* @param {string} parent parent path
* @returns {boolean} true, if path is inside of parent
*/
const isInside = (path, parent) => {

@@ -16,0 +21,0 @@ if (!path.startsWith(parent)) return false;

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

/** @typedef {import("./Resolver")} Resolver */
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */

@@ -42,4 +43,10 @@

this.roots,
/**
* @param {string} root root
* @param {(err?: null|Error, result?: null|ResolveRequest) => void} callback callback
* @returns {void}
*/
(root, callback) => {
const path = resolver.join(root, req.slice(1));
/** @type {ResolveRequest} */
const obj = {

@@ -46,0 +53,0 @@ ...request,

@@ -11,2 +11,4 @@ /*

/** @typedef {import("./Resolver")} Resolver */
/** @typedef {import("./Resolver").JsonObject} JsonObject */
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */

@@ -44,3 +46,3 @@

const exportsField = DescriptionFileUtils.getField(
request.descriptionFileData,
/** @type {JsonObject} */ (request.descriptionFileData),
this.fieldName

@@ -51,3 +53,3 @@ );

const name = DescriptionFileUtils.getField(
request.descriptionFileData,
/** @type {JsonObject} */ (request.descriptionFileData),
"name"

@@ -63,3 +65,3 @@ );

const remainingRequest = `.${req.slice(name.length)}`;
/** @type {ResolveRequest} */
const obj = {

@@ -66,0 +68,0 @@ ...request,

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

/** @typedef {import("./Resolver")} Resolver */
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */

@@ -37,3 +38,3 @@

if (request.ignoreSymlinks) return callback();
const pathsResult = getPaths(request.path);
const pathsResult = getPaths(/** @type {string} */ (request.path));
const pathSegments = pathsResult.segments;

@@ -46,2 +47,7 @@ const paths = pathsResult.paths;

paths,
/**
* @param {string} path path
* @param {(err?: null|Error, result?: null|number) => void} callback callback
* @returns {void}
*/
(path, callback) => {

@@ -53,3 +59,3 @@ idx++;

if (!err && result) {
pathSegments[idx] = result;
pathSegments[idx] = /** @type {string} */ (result);
containsSymlink = true;

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

},
/**
* @param {null|Error} [err] error
* @param {null|number} [idx] result
* @returns {void}
*/
(err, idx) => {

@@ -78,2 +89,3 @@ if (!containsSymlink) return callback();

});
/** @type {ResolveRequest} */
const obj = {

@@ -80,0 +92,0 @@ ...request,

@@ -18,3 +18,5 @@ /*

/** @type {FileSystem["lstat"] | undefined} */
this.lstat = undefined;
/** @type {SyncFileSystem["lstatSync"] | undefined} */
this.lstatSync = undefined;

@@ -28,4 +30,6 @@ const lstatSync = fs.lstatSync;

} catch (e) {
// @ts-ignore
return (callback || options)(e);
}
// @ts-ignore
(callback || options)(null, result);

@@ -35,3 +39,3 @@ };

}
// @ts-ignore
this.stat = (arg, options, callback) => {

@@ -46,4 +50,5 @@ let result;

};
/** @type {SyncFileSystem["statSync"]} */
this.statSync = (arg, options) => fs.statSync(arg, options);
// @ts-ignore
this.readdir = (arg, options, callback) => {

@@ -58,4 +63,5 @@ let result;

};
/** @type {SyncFileSystem["readdirSync"]} */
this.readdirSync = (arg, options) => fs.readdirSync(arg, options);
// @ts-ignore
this.readFile = (arg, options, callback) => {

@@ -70,4 +76,5 @@ let result;

};
/** @type {SyncFileSystem["readFileSync"]} */
this.readFileSync = (arg, options) => fs.readFileSync(arg, options);
// @ts-ignore
this.readlink = (arg, options, callback) => {

@@ -82,5 +89,7 @@ let result;

};
/** @type {SyncFileSystem["readlinkSync"]} */
this.readlinkSync = (arg, options) => fs.readlinkSync(arg, options);
/** @type {FileSystem["readJson"] | undefined} */
this.readJson = undefined;
/** @type {SyncFileSystem["readJsonSync"] | undefined} */
this.readJsonSync = undefined;

@@ -94,2 +103,3 @@ const readJsonSync = fs.readJsonSync;

} catch (e) {
// @ts-ignore
return (callback || options)(e);

@@ -99,3 +109,2 @@ }

};
this.readJsonSync = (arg, options) => readJsonSync.call(fs, arg, options);

@@ -102,0 +111,0 @@ }

@@ -11,4 +11,11 @@ /*

/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */
/** @typedef {{[k: string]: any}} Cache */
/** @typedef {import("./Resolver").ResolveContextYield} ResolveContextYield */
/** @typedef {{[k: string]: ResolveRequest | ResolveRequest[] | undefined}} Cache */
/**
* @param {string} type type of cache
* @param {ResolveRequest} request request
* @param {boolean} withContext cache with context?
* @returns {string} cache id
*/
function getCacheId(type, request, withContext) {

@@ -68,7 +75,10 @@ return JSON.stringify({

}
return callback(null, cacheEntry);
return callback(null, /** @type {ResolveRequest} */ (cacheEntry));
}
/** @type {ResolveContextYield|undefined} */
let yieldFn;
/** @type {ResolveContextYield|undefined} */
let yield_;
/** @type {ResolveRequest[]} */
const yieldResult = [];

@@ -91,3 +101,6 @@ if (isYield) {

if (result) yieldResult.push(result);
for (const result of yieldResult) yieldFn(result);
for (const result of yieldResult) {
/** @type {ResolveContextYield} */
(yieldFn)(result);
}
this.cache[cacheId] = yieldResult;

@@ -94,0 +107,0 @@ return callback(null, null);

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

/** @typedef {import("./Resolver")} Resolver */
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */

@@ -33,3 +34,8 @@

.tapAsync("UseFilePlugin", (request, resolveContext, callback) => {
const filePath = resolver.join(request.path, this.filename);
const filePath = resolver.join(
/** @type {string} */ (request.path),
this.filename
);
/** @type {ResolveRequest} */
const obj = {

@@ -36,0 +42,0 @@ ...request,

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

/**
* @param {string} a first string
* @param {string} b second string
* @returns {number} compare result
*/
function patternKeyCompare(a, b) {

@@ -278,3 +283,3 @@ const aPatternIndex = a.indexOf("*");

) {
const target = field[request];
const target = /** @type {{[k: string]: MappingValue}} */ (field)[request];

@@ -284,3 +289,5 @@ return [target, "", false, false];

/** @type {string} */
let bestMatch = "";
/** @type {string|undefined} */
let bestMatchSubpath;

@@ -323,3 +330,3 @@

const target = field[bestMatch];
const target = /** @type {{[k: string]: MappingValue}} */ (field)[bestMatch];
const isSubpathMapping = bestMatch.endsWith("/");

@@ -377,2 +384,3 @@ const isPattern = bestMatch.includes("*");

/** @type {string[]} */
const targets = [];

@@ -478,3 +486,5 @@

if (isConditionalMapping(innerMapping)) {
const conditionalMapping = /** @type {ConditionalMapping} */ (innerMapping);
const conditionalMapping = /** @type {ConditionalMapping} */ (
innerMapping
);
lookup[lookup.length - 1][2] = i + 1;

@@ -492,3 +502,5 @@ lookup.push([conditionalMapping, Object.keys(conditionalMapping), 0]);

if (isConditionalMapping(innerMapping)) {
const conditionalMapping = /** @type {ConditionalMapping} */ (innerMapping);
const conditionalMapping = /** @type {ConditionalMapping} */ (
innerMapping
);
lookup[lookup.length - 1][2] = i + 1;

@@ -495,0 +507,0 @@ lookup.push([conditionalMapping, Object.keys(conditionalMapping), 0]);

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

const PATH_QUERY_FRAGMENT_REGEXP = /^(#?(?:\0.|[^?#\0])*)(\?(?:\0.|[^#\0])*)?(#.*)?$/;
const PATH_QUERY_FRAGMENT_REGEXP =
/^(#?(?:\0.|[^?#\0])*)(\?(?:\0.|[^#\0])*)?(#.*)?$/;

@@ -11,0 +12,0 @@ /**

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

/** @type {Map<string, Map<string, string | undefined>>} */
const joinCache = new Map();

@@ -178,6 +179,7 @@

* @param {string} rootPath the root path
* @param {string | undefined} request the request path
* @param {string} request the request path
* @returns {string} the joined path
*/
const cachedJoin = (rootPath, request) => {
/** @type {string | undefined} */
let cacheEntry;

@@ -197,2 +199,6 @@ let cache = joinCache.get(rootPath);

/**
* @param {string} relativePath relative path
* @returns {undefined|Error} nothing or an error
*/
const checkImportsExportsFieldTarget = relativePath => {

@@ -199,0 +205,0 @@ let lastNonSlashIndex = 0;

@@ -9,3 +9,9 @@ /*

module.exports = {
/**
* @type {Record<string, string>}
*/
versions: {},
/**
* @param {function} fn function
*/
nextTick(fn) {

@@ -12,0 +18,0 @@ const args = Array.prototype.slice.call(arguments, 1);

{
"name": "enhanced-resolve",
"version": "5.14.0",
"version": "5.14.1",
"author": "Tobias Koppers @sokra",

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

"devDependencies": {
"@types/mocha": "^8.0.3",
"@types/graceful-fs": "^4.1.6",
"@types/jest": "^27.5.1",
"@types/node": "^14.11.1",

@@ -31,10 +32,8 @@ "cspell": "4.2.8",

"husky": "^6.0.0",
"jest": "^27.5.1",
"lint-staged": "^10.4.0",
"memfs": "^3.2.0",
"mocha": "^8.1.3",
"nyc": "^15.1.0",
"prettier": "^2.1.2",
"should": "^13.2.3",
"tooling": "webpack/tooling#v1.14.0",
"typescript": "^4.2.0-beta"
"typescript": "^5.0.4"
},

@@ -48,3 +47,3 @@ "engines": {

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

@@ -54,2 +53,4 @@ "code-lint": "eslint --cache lib test",

"type-lint": "tsc",
"typings-test": "tsc -p tsconfig.types.test.json",
"type-report": "rimraf coverage && yarn cover:types && yarn cover:report && open-cli coverage/lcov-report/index.html",
"special-lint": "node node_modules/tooling/lockfile-lint && node node_modules/tooling/inherit-types && node node_modules/tooling/format-file-header && node node_modules/tooling/generate-types",

@@ -60,7 +61,7 @@ "special-lint-fix": "node node_modules/tooling/inherit-types --write && node node_modules/tooling/format-file-header --write && node node_modules/tooling/generate-types --write",

"spelling": "cspell \"**/*.*\"",
"test": "mocha --full-trace --check-leaks",
"test:only": "mocha --full-trace --check-leaks",
"test:only": "jest",
"test:watch": "yarn test:only -- --watch",
"test:coverage": "yarn test:only -- --collectCoverageFrom=\"lib/**/*.js\" --coverage",
"test": "yarn test:coverage",
"precover": "yarn lint",
"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",
"prepare": "husky install"

@@ -67,0 +68,0 @@ },

# enhanced-resolve
[![npm][npm]][npm-url]
[![Build Status][build-status]][build-status-url]
[![codecov][codecov-badge]][codecov-url]
[![Install Size][size]][size-url]
[![GitHub Discussions][discussion]][discussion-url]
Offers an async require.resolve function. It's highly configurable.

@@ -149,4 +155,2 @@

[![Build Status](https://secure.travis-ci.org/webpack/enhanced-resolve.png?branch=main)](http://travis-ci.org/webpack/enhanced-resolve)
## Passing options from webpack

@@ -170,1 +174,12 @@

MIT (http://www.opensource.org/licenses/mit-license.php)
[npm]: https://img.shields.io/npm/v/enhanced-resolve.svg
[npm-url]: https://www.npmjs.com/package/enhanced-resolve
[build-status]: https://github.com/webpack/enhanced-resolve/actions/workflows/test.yml/badge.svg?branch=master
[build-status-url]: https://github.com/webpack/enhanced-resolve/actions
[codecov-badge]: https://codecov.io/gh/webpack/enhanced-resolve/branch/main/graph/badge.svg?token=6B6NxtsZc3
[codecov-url]: https://codecov.io/gh/webpack/enhanced-resolve
[size]: https://packagephobia.com/badge?p=enhanced-resolve
[size-url]: https://packagephobia.com/result?p=enhanced-resolve
[discussion]: https://img.shields.io/github/discussions/webpack/webpack
[discussion-url]: https://github.com/webpack/webpack/discussions

@@ -7,6 +7,8 @@ /*

import { Dirent } from "fs";
import { AsyncSeriesBailHook, AsyncSeriesHook, SyncHook } from "tapable";
type Alias = string | false | string[];
declare interface AliasOption {
alias: string | false | string[];
alias: Alias;
name: string;

@@ -21,11 +23,15 @@ onlyModule?: boolean;

path: string | false;
context?: object;
descriptionFilePath?: string;
descriptionFileRoot?: string;
descriptionFileData?: object;
descriptionFileData?: JsonObject;
relativePath?: string;
ignoreSymlinks?: boolean;
fullySpecified?: boolean;
__innerRequest?: string;
__innerRequest_request?: string;
__innerRequest_relativePath?: string;
}
declare class CachedInputFileSystem {
constructor(fileSystem?: any, duration?: any);
constructor(fileSystem: any, duration: number);
fileSystem: any;

@@ -56,3 +62,3 @@ lstat?: {

arg0?: null | NodeJS.ErrnoException,
arg1?: (string | Buffer)[] | any[]
arg1?: (string | Buffer)[] | Dirent[]
) => void)

@@ -67,2 +73,3 @@ | ReaddirOptions

| "base64"
| "base64url"
| "latin1"

@@ -74,3 +81,3 @@ | "binary"

arg0?: null | NodeJS.ErrnoException,
arg1?: (string | Buffer)[] | any[]
arg1?: (string | Buffer)[] | Dirent[]
) => void

@@ -105,8 +112,31 @@ ) => void;

readlinkSync: (arg0: string, arg1?: object) => string | Buffer;
purge(what?: any): void;
purge(what?: string | Set<string> | string[]): void;
}
declare class CloneBasenamePlugin {
constructor(source?: any, target?: any);
source: any;
target: any;
constructor(
source:
| string
| AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>,
target:
| string
| AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>
);
source:
| string
| AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>;
target:
| string
| AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>;
apply(resolver: Resolver): void;

@@ -137,3 +167,3 @@ }

arg0?: null | NodeJS.ErrnoException,
arg1?: (string | Buffer)[] | any[]
arg1?: (string | Buffer)[] | Dirent[]
) => void)

@@ -148,2 +178,3 @@ | ReaddirOptions

| "base64"
| "base64url"
| "latin1"

@@ -155,3 +186,3 @@ | "binary"

arg0?: null | NodeJS.ErrnoException,
arg1?: (string | Buffer)[] | any[]
arg1?: (string | Buffer)[] | Dirent[]
) => void

@@ -200,5 +231,52 @@ ) => void;

}
declare interface Iterator<T, Z> {
(
item: T,
callback: (err?: null | Error, result?: null | Z) => void,
i: number
): void;
}
type JsonObject = { [index: string]: JsonValue } & {
[index: string]:
| undefined
| null
| string
| number
| boolean
| JsonObject
| JsonValue[];
};
type JsonValue = null | string | number | boolean | JsonObject | JsonValue[];
declare interface KnownHooks {
resolveStep: SyncHook<
[
AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>,
ResolveRequest
]
>;
noResolve: SyncHook<[ResolveRequest, Error]>;
resolve: AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>;
result: AsyncSeriesHook<[ResolveRequest, ResolveContext]>;
}
declare class LogInfoPlugin {
constructor(source?: any);
source: any;
constructor(
source:
| string
| AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>
);
source:
| string
| AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>;
apply(resolver: Resolver): void;

@@ -237,2 +315,3 @@ }

| "base64"
| "base64url"
| "latin1"

@@ -361,19 +440,3 @@ | "binary"

options: ResolveOptions;
hooks: {
resolveStep: SyncHook<
[
AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>,
ResolveRequest
]
>;
noResolve: SyncHook<[ResolveRequest, Error]>;
resolve: AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>;
result: AsyncSeriesHook<[ResolveRequest, ResolveContext]>;
};
hooks: KnownHooks;
ensureHook(

@@ -414,14 +477,17 @@ name:

doResolve(
hook?: any,
request?: any,
message?: any,
resolveContext?: any,
callback?: any
): any;
hook: AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>,
request: ResolveRequest,
message: null | string,
resolveContext: ResolveContext,
callback: (err?: null | Error, result?: ResolveRequest) => void
): void;
parse(identifier: string): ParsedIdentifier;
isModule(path?: any): boolean;
isPrivate(path?: any): boolean;
isModule(path: string): boolean;
isPrivate(path: string): boolean;
isDirectory(path: string): boolean;
join(path?: any, request?: any): string;
normalize(path?: any): string;
join(path: string, request: string): string;
normalize(path: string): string;
}

@@ -574,3 +640,3 @@ declare interface UserResolveOptions {

declare interface WriteOnlySet<T> {
add: (T?: any) => void;
add: (item: T) => void;
}

@@ -628,7 +694,7 @@ declare function exports(

}
export const forEachBail: (
array?: any,
iterator?: any,
callback?: any
) => any;
export const forEachBail: <T, Z>(
array: T[],
iterator: Iterator<T, Z>,
callback: (err?: null | Error, result?: null | Z) => void
) => void;
export type ResolveCallback = (

@@ -635,0 +701,0 @@ err: null | ErrorWithDetail,

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