[6a3a178] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
---|
| 4 | value: true
|
---|
| 5 | });
|
---|
| 6 | exports.trueFn = trueFn;
|
---|
| 7 | exports.findModuleById = findModuleById;
|
---|
| 8 | exports.evalModuleCode = evalModuleCode;
|
---|
| 9 | exports.compareModulesByIdentifier = compareModulesByIdentifier;
|
---|
| 10 | exports.stringifyRequest = stringifyRequest;
|
---|
[e29cc2e] | 11 | exports.getUndoPath = getUndoPath;
|
---|
| 12 | exports.SINGLE_DOT_PATH_SEGMENT = exports.ABSOLUTE_PUBLIC_PATH = exports.AUTO_PUBLIC_PATH = exports.MODULE_TYPE = void 0;
|
---|
[6a3a178] | 13 |
|
---|
| 14 | var _module = _interopRequireDefault(require("module"));
|
---|
| 15 |
|
---|
| 16 | var _path = _interopRequireDefault(require("path"));
|
---|
| 17 |
|
---|
| 18 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
| 19 |
|
---|
| 20 | function trueFn() {
|
---|
| 21 | return true;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | function findModuleById(compilation, id) {
|
---|
| 25 | const {
|
---|
| 26 | modules,
|
---|
| 27 | chunkGraph
|
---|
| 28 | } = compilation;
|
---|
| 29 |
|
---|
| 30 | for (const module of modules) {
|
---|
| 31 | const moduleId = typeof chunkGraph !== "undefined" ? chunkGraph.getModuleId(module) : module.id;
|
---|
| 32 |
|
---|
| 33 | if (moduleId === id) {
|
---|
| 34 | return module;
|
---|
| 35 | }
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | return null;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | function evalModuleCode(loaderContext, code, filename) {
|
---|
| 42 | const module = new _module.default(filename, loaderContext);
|
---|
| 43 | module.paths = _module.default._nodeModulePaths(loaderContext.context); // eslint-disable-line no-underscore-dangle
|
---|
| 44 |
|
---|
| 45 | module.filename = filename;
|
---|
| 46 |
|
---|
| 47 | module._compile(code, filename); // eslint-disable-line no-underscore-dangle
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | return module.exports;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | function compareIds(a, b) {
|
---|
| 54 | if (typeof a !== typeof b) {
|
---|
| 55 | return typeof a < typeof b ? -1 : 1;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | if (a < b) {
|
---|
| 59 | return -1;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | if (a > b) {
|
---|
| 63 | return 1;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | return 0;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | function compareModulesByIdentifier(a, b) {
|
---|
| 70 | return compareIds(a.identifier(), b.identifier());
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | const MODULE_TYPE = "css/mini-extract";
|
---|
| 74 | exports.MODULE_TYPE = MODULE_TYPE;
|
---|
[e29cc2e] | 75 | const AUTO_PUBLIC_PATH = "__mini_css_extract_plugin_public_path_auto__";
|
---|
[6a3a178] | 76 | exports.AUTO_PUBLIC_PATH = AUTO_PUBLIC_PATH;
|
---|
[e29cc2e] | 77 | const ABSOLUTE_PUBLIC_PATH = "webpack:///mini-css-extract-plugin/";
|
---|
| 78 | exports.ABSOLUTE_PUBLIC_PATH = ABSOLUTE_PUBLIC_PATH;
|
---|
| 79 | const SINGLE_DOT_PATH_SEGMENT = "__mini_css_extract_plugin_single_dot_path_segment__";
|
---|
| 80 | exports.SINGLE_DOT_PATH_SEGMENT = SINGLE_DOT_PATH_SEGMENT;
|
---|
[6a3a178] | 81 |
|
---|
| 82 | function isAbsolutePath(str) {
|
---|
| 83 | return _path.default.posix.isAbsolute(str) || _path.default.win32.isAbsolute(str);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | const RELATIVE_PATH_REGEXP = /^\.\.?[/\\]/;
|
---|
| 87 |
|
---|
| 88 | function isRelativePath(str) {
|
---|
| 89 | return RELATIVE_PATH_REGEXP.test(str);
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | function stringifyRequest(loaderContext, request) {
|
---|
| 93 | const splitted = request.split("!");
|
---|
| 94 | const {
|
---|
| 95 | context
|
---|
| 96 | } = loaderContext;
|
---|
| 97 | return JSON.stringify(splitted.map(part => {
|
---|
| 98 | // First, separate singlePath from query, because the query might contain paths again
|
---|
| 99 | const splittedPart = part.match(/^(.*?)(\?.*)/);
|
---|
| 100 | const query = splittedPart ? splittedPart[2] : "";
|
---|
| 101 | let singlePath = splittedPart ? splittedPart[1] : part;
|
---|
| 102 |
|
---|
| 103 | if (isAbsolutePath(singlePath) && context) {
|
---|
| 104 | singlePath = _path.default.relative(context, singlePath);
|
---|
| 105 |
|
---|
| 106 | if (isAbsolutePath(singlePath)) {
|
---|
| 107 | // If singlePath still matches an absolute path, singlePath was on a different drive than context.
|
---|
| 108 | // In this case, we leave the path platform-specific without replacing any separators.
|
---|
| 109 | // @see https://github.com/webpack/loader-utils/pull/14
|
---|
| 110 | return singlePath + query;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | if (isRelativePath(singlePath) === false) {
|
---|
| 114 | // Ensure that the relative path starts at least with ./ otherwise it would be a request into the modules directory (like node_modules).
|
---|
| 115 | singlePath = `./${singlePath}`;
|
---|
| 116 | }
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | return singlePath.replace(/\\/g, "/") + query;
|
---|
| 120 | }).join("!"));
|
---|
[e29cc2e] | 121 | }
|
---|
| 122 |
|
---|
| 123 | function getUndoPath(filename, outputPath, enforceRelative) {
|
---|
| 124 | let depth = -1;
|
---|
| 125 | let append = ""; // eslint-disable-next-line no-param-reassign
|
---|
| 126 |
|
---|
| 127 | outputPath = outputPath.replace(/[\\/]$/, "");
|
---|
| 128 |
|
---|
| 129 | for (const part of filename.split(/[/\\]+/)) {
|
---|
| 130 | if (part === "..") {
|
---|
| 131 | if (depth > -1) {
|
---|
| 132 | // eslint-disable-next-line no-plusplus
|
---|
| 133 | depth--;
|
---|
| 134 | } else {
|
---|
| 135 | const i = outputPath.lastIndexOf("/");
|
---|
| 136 | const j = outputPath.lastIndexOf("\\");
|
---|
| 137 | const pos = i < 0 ? j : j < 0 ? i : Math.max(i, j);
|
---|
| 138 |
|
---|
| 139 | if (pos < 0) {
|
---|
| 140 | return `${outputPath}/`;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | append = `${outputPath.slice(pos + 1)}/${append}`; // eslint-disable-next-line no-param-reassign
|
---|
| 144 |
|
---|
| 145 | outputPath = outputPath.slice(0, pos);
|
---|
| 146 | }
|
---|
| 147 | } else if (part !== ".") {
|
---|
| 148 | // eslint-disable-next-line no-plusplus
|
---|
| 149 | depth++;
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | return depth > 0 ? `${"../".repeat(depth)}${append}` : enforceRelative ? `./${append}` : append;
|
---|
[6a3a178] | 154 | } |
---|