source: trip-planner-front/node_modules/enhanced-resolve/lib/JoinRequestPartPlugin.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8/** @typedef {import("./Resolver")} Resolver */
9/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */
10
11const namespaceStartCharCode = "@".charCodeAt(0);
12
13module.exports = class JoinRequestPartPlugin {
14 /**
15 * @param {string | ResolveStepHook} source source
16 * @param {string | ResolveStepHook} target target
17 */
18 constructor(source, target) {
19 this.source = source;
20 this.target = target;
21 }
22
23 /**
24 * @param {Resolver} resolver the resolver
25 * @returns {void}
26 */
27 apply(resolver) {
28 const target = resolver.ensureHook(this.target);
29 resolver
30 .getHook(this.source)
31 .tapAsync(
32 "JoinRequestPartPlugin",
33 (request, resolveContext, callback) => {
34 const req = request.request || "";
35 let i = req.indexOf("/", 3);
36
37 if (i >= 0 && req.charCodeAt(2) === namespaceStartCharCode) {
38 i = req.indexOf("/", i + 1);
39 }
40
41 let moduleName, remainingRequest, fullySpecified;
42 if (i < 0) {
43 moduleName = req;
44 remainingRequest = ".";
45 fullySpecified = false;
46 } else {
47 moduleName = req.slice(0, i);
48 remainingRequest = "." + req.slice(i);
49 fullySpecified = request.fullySpecified;
50 }
51 const obj = {
52 ...request,
53 path: resolver.join(request.path, moduleName),
54 relativePath:
55 request.relativePath &&
56 resolver.join(request.relativePath, moduleName),
57 request: remainingRequest,
58 fullySpecified
59 };
60 resolver.doResolve(target, obj, null, resolveContext, callback);
61 }
62 );
63 }
64};
Note: See TracBrowser for help on using the repository browser.