source: imaps-frontend/node_modules/enhanced-resolve/lib/CloneBasenamePlugin.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.3 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
8const basename = require("./getPaths").basename;
9
10/** @typedef {import("./Resolver")} Resolver */
11/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
12/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */
13
14module.exports = class CloneBasenamePlugin {
15 /**
16 * @param {string | ResolveStepHook} source source
17 * @param {string | ResolveStepHook} target target
18 */
19 constructor(source, target) {
20 this.source = source;
21 this.target = target;
22 }
23
24 /**
25 * @param {Resolver} resolver the resolver
26 * @returns {void}
27 */
28 apply(resolver) {
29 const target = resolver.ensureHook(this.target);
30 resolver
31 .getHook(this.source)
32 .tapAsync("CloneBasenamePlugin", (request, resolveContext, callback) => {
33 const requestPath = /** @type {string} */ (request.path);
34 const filename = /** @type {string} */ (basename(requestPath));
35 const filePath = resolver.join(requestPath, filename);
36 /** @type {ResolveRequest} */
37 const obj = {
38 ...request,
39 path: filePath,
40 relativePath:
41 request.relativePath &&
42 resolver.join(request.relativePath, filename)
43 };
44 resolver.doResolve(
45 target,
46 obj,
47 "using path: " + filePath,
48 resolveContext,
49 callback
50 );
51 });
52 }
53};
Note: See TracBrowser for help on using the repository browser.