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 3, 2024
1 parent 31e2326 commit 24d1b6a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 61 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
],
"peerDependencies": {
"@rspack/core": "0.x || 1.x",
"webpack": "^5.0.0"
"webpack": "^5.27.0"
},
"peerDependenciesMeta": {
"@rspack/core": {
Expand Down
67 changes: 7 additions & 60 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,60 +12,12 @@ import modulesScope from "postcss-modules-scope";

const WEBPACK_IGNORE_COMMENT_REGEXP = /webpackIgnore:(\s+)?(true|false)/;

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 || loaderContext.rootContext,
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 || loaderContext.rootContext,
request,
),
);
}

Expand Down Expand Up @@ -313,7 +265,7 @@ const filenameReservedRegex = /[<>:"/\\|?*]/g;
const reControlChars = /[\u0000-\u001f\u0080-\u009f]/g;

function escapeLocalIdent(localident) {
// TODO simplify in the next major release
// TODO simplify?
return escape(
localident
// For `[hash]` placeholder
Expand Down Expand Up @@ -375,13 +327,8 @@ function defaultGetLocalIdent(
let localIdentHash = "";

for (let tier = 0; localIdentHash.length < hashDigestLength; tier++) {
// TODO remove this in the next major release
const hash =
loaderContext.utils &&
typeof loaderContext.utils.createHash === "function"
? loaderContext.utils.createHash(hashFunction)
: // eslint-disable-next-line no-underscore-dangle
loaderContext._compiler.webpack.util.createHash(hashFunction);
// eslint-disable-next-line no-underscore-dangle
const hash = loaderContext._compiler.webpack.util.createHash(hashFunction);

if (hashSalt) {
hash.update(hashSalt);
Expand Down

0 comments on commit 24d1b6a

Please sign in to comment.