diff --git a/CHANGELOG.md b/CHANGELOG.md index 70063d64..d5890870 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [2.4.1](https://github.com/webpack-contrib/mini-css-extract-plugin/compare/v2.4.0...v2.4.1) (2021-10-05) + + +### Bug Fixes + +* crash with multiple webpack versions ([#845](https://github.com/webpack-contrib/mini-css-extract-plugin/issues/845)) ([b4431cb](https://github.com/webpack-contrib/mini-css-extract-plugin/commit/b4431cb60a6eadcf8c2b614f494faf899c73aaa0)) + ## [2.4.0](https://github.com/webpack-contrib/mini-css-extract-plugin/compare/v2.3.0...v2.4.0) (2021-10-05) ### Performance diff --git a/package-lock.json b/package-lock.json index ec2732e0..721cd845 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mini-css-extract-plugin", - "version": "2.4.0", + "version": "2.4.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mini-css-extract-plugin", - "version": "2.4.0", + "version": "2.4.1", "license": "MIT", "dependencies": { "schema-utils": "^3.1.0" diff --git a/package.json b/package.json index 495d1890..2188632c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mini-css-extract-plugin", - "version": "2.4.0", + "version": "2.4.1", "description": "extracts CSS into separate files", "license": "MIT", "repository": "webpack-contrib/mini-css-extract-plugin", diff --git a/src/index.js b/src/index.js index 467853a8..9a1b17de 100644 --- a/src/index.js +++ b/src/index.js @@ -2,8 +2,6 @@ import { validate } from "schema-utils"; -import { getUndoPath } from "webpack/lib/util/identifier"; - import schema from "./plugin-options.json"; import { trueFn, @@ -12,6 +10,7 @@ import { ABSOLUTE_PUBLIC_PATH, SINGLE_DOT_PATH_SEGMENT, compareModulesByIdentifier, + getUndoPath, } from "./utils"; export const pluginName = "mini-css-extract-plugin"; diff --git a/src/utils.js b/src/utils.js index f69456b6..ea569c45 100644 --- a/src/utils.js +++ b/src/utils.js @@ -102,6 +102,45 @@ function stringifyRequest(loaderContext, request) { ); } +function getUndoPath(filename, outputPath, enforceRelative) { + let depth = -1; + let append = ""; + + // eslint-disable-next-line no-param-reassign + outputPath = outputPath.replace(/[\\/]$/, ""); + + for (const part of filename.split(/[/\\]+/)) { + if (part === "..") { + if (depth > -1) { + // eslint-disable-next-line no-plusplus + depth--; + } else { + const i = outputPath.lastIndexOf("/"); + const j = outputPath.lastIndexOf("\\"); + const pos = i < 0 ? j : j < 0 ? i : Math.max(i, j); + + if (pos < 0) { + return `${outputPath}/`; + } + + append = `${outputPath.slice(pos + 1)}/${append}`; + + // eslint-disable-next-line no-param-reassign + outputPath = outputPath.slice(0, pos); + } + } else if (part !== ".") { + // eslint-disable-next-line no-plusplus + depth++; + } + } + + return depth > 0 + ? `${"../".repeat(depth)}${append}` + : enforceRelative + ? `./${append}` + : append; +} + export { trueFn, findModuleById, @@ -112,4 +151,5 @@ export { ABSOLUTE_PUBLIC_PATH, SINGLE_DOT_PATH_SEGMENT, stringifyRequest, + getUndoPath, };