From e21605ad88512629d42b2024f2b2b25139d379de Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Thu, 4 Apr 2024 20:11:45 +0300 Subject: [PATCH] refactor!: minimum supported webpack version is `5.27.0` --- src/utils.js | 50 +------------------------------------------------- 1 file changed, 1 insertion(+), 49 deletions(-) diff --git a/src/utils.js b/src/utils.js index 2979249..6b18057 100644 --- a/src/utils.js +++ b/src/utils.js @@ -2,57 +2,9 @@ import path from "path"; import isEqualLocals from "./runtime/isEqualLocals"; -const matchRelativePath = /^\.\.?[/\\]/; - -function isAbsolutePath(str) { - return path.posix.isAbsolute(str) || path.win32.isAbsolute(str); -} - -function isRelativePath(str) { - return matchRelativePath.test(str); -} - -// TODO simplify for the next major release function stringifyRequest(loaderContext, request) { - if ( - typeof loaderContext.utils !== "undefined" && - typeof loaderContext.utils.contextify === "function" - ) { - return JSON.stringify( - loaderContext.utils.contextify(loaderContext.context, request), - ); - } - - const splitted = request.split("!"); - const { context } = loaderContext; - return JSON.stringify( - splitted - .map((part) => { - // First, separate singlePath from query, because the query might contain paths again - const splittedPart = part.match(/^(.*?)(\?.*)/); - const query = splittedPart ? splittedPart[2] : ""; - let singlePath = splittedPart ? splittedPart[1] : part; - - if (isAbsolutePath(singlePath) && context) { - singlePath = path.relative(context, singlePath); - - if (isAbsolutePath(singlePath)) { - // If singlePath still matches an absolute path, singlePath was on a different drive than context. - // In this case, we leave the path platform-specific without replacing any separators. - // @see https://github.com/webpack/loader-utils/pull/14 - return singlePath + query; - } - - if (isRelativePath(singlePath) === false) { - // Ensure that the relative path starts at least with ./ otherwise it would be a request into the modules directory (like node_modules). - singlePath = `./${singlePath}`; - } - } - - return singlePath.replace(/\\/g, "/") + query; - }) - .join("!"), + loaderContext.utils.contextify(loaderContext.context, request), ); }