Skip to content

Commit

Permalink
refactor!: minimum supported webpack version is 5.27.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Apr 4, 2024
1 parent 7ace887 commit e21605a
Showing 1 changed file with 1 addition and 49 deletions.
50 changes: 1 addition & 49 deletions src/utils.js
Expand Up @@ -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),
);
}

Expand Down

0 comments on commit e21605a

Please sign in to comment.