123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- "use strict";
- const forEachBail = require("./forEachBail");
- class RootsPlugin {
-
- constructor(source, roots, target) {
- this.roots = Array.from(roots);
- this.source = source;
- this.target = target;
- }
-
- apply(resolver) {
- const target = resolver.ensureHook(this.target);
- resolver
- .getHook(this.source)
- .tapAsync("RootsPlugin", (request, resolveContext, callback) => {
- const req = request.request;
- if (!req) return callback();
- if (!req.startsWith("/")) return callback();
- forEachBail(
- this.roots,
-
- (root, callback) => {
- const path = resolver.join(root, req.slice(1));
-
- const obj = {
- ...request,
- path,
- relativePath: request.relativePath && path
- };
- resolver.doResolve(
- target,
- obj,
- `root path ${root}`,
- resolveContext,
- callback
- );
- },
- callback
- );
- });
- }
- }
- module.exports = RootsPlugin;
|