Permalink
Cannot retrieve contributors at this time
74 lines (70 sloc)
2.19 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/enhanced-resolve/lib/ParsePlugin.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
MIT License http://www.opensource.org/licenses/mit-license.php | |
Author Tobias Koppers @sokra | |
*/ | |
"use strict"; | |
/** @typedef {import("./Resolver")} Resolver */ | |
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */ | |
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */ | |
module.exports = class ParsePlugin { | |
/** | |
* @param {string | ResolveStepHook} source source | |
* @param {Partial<ResolveRequest>} requestOptions request options | |
* @param {string | ResolveStepHook} target target | |
*/ | |
constructor(source, requestOptions, target) { | |
this.source = source; | |
this.requestOptions = requestOptions; | |
this.target = target; | |
} | |
/** | |
* @param {Resolver} resolver the resolver | |
* @returns {void} | |
*/ | |
apply(resolver) { | |
const target = resolver.ensureHook(this.target); | |
resolver | |
.getHook(this.source) | |
.tapAsync("ParsePlugin", (request, resolveContext, callback) => { | |
const parsed = resolver.parse(/** @type {string} */ (request.request)); | |
const obj = { ...request, ...parsed, ...this.requestOptions }; | |
if (request.query && !parsed.query) { | |
obj.query = request.query; | |
} | |
if (request.fragment && !parsed.fragment) { | |
obj.fragment = request.fragment; | |
} | |
if (parsed && resolveContext.log) { | |
if (parsed.module) resolveContext.log("Parsed request is a module"); | |
if (parsed.directory) | |
resolveContext.log("Parsed request is a directory"); | |
} | |
// There is an edge-case where a request with # can be a path or a fragment -> try both | |
if (obj.request && !obj.query && obj.fragment) { | |
const directory = obj.fragment.endsWith("/"); | |
const alternative = { | |
...obj, | |
directory, | |
request: | |
obj.request + | |
(obj.directory ? "/" : "") + | |
(directory ? obj.fragment.slice(0, -1) : obj.fragment), | |
fragment: "" | |
}; | |
resolver.doResolve( | |
target, | |
alternative, | |
null, | |
resolveContext, | |
(err, result) => { | |
if (err) return callback(err); | |
if (result) return callback(null, result); | |
resolver.doResolve(target, obj, null, resolveContext, callback); | |
} | |
); | |
return; | |
} | |
resolver.doResolve(target, obj, null, resolveContext, callback); | |
}); | |
} | |
}; |