[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;
|
---|
| 11 | exports.AUTO_PUBLIC_PATH = exports.MODULE_TYPE = void 0;
|
---|
| 12 |
|
---|
| 13 | var _module = _interopRequireDefault(require("module"));
|
---|
| 14 |
|
---|
| 15 | var _path = _interopRequireDefault(require("path"));
|
---|
| 16 |
|
---|
| 17 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
| 18 |
|
---|
| 19 | function trueFn() {
|
---|
| 20 | return true;
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | function findModuleById(compilation, id) {
|
---|
| 24 | const {
|
---|
| 25 | modules,
|
---|
| 26 | chunkGraph
|
---|
| 27 | } = compilation;
|
---|
| 28 |
|
---|
| 29 | for (const module of modules) {
|
---|
| 30 | const moduleId = typeof chunkGraph !== "undefined" ? chunkGraph.getModuleId(module) : module.id;
|
---|
| 31 |
|
---|
| 32 | if (moduleId === id) {
|
---|
| 33 | return module;
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | return null;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | function evalModuleCode(loaderContext, code, filename) {
|
---|
| 41 | const module = new _module.default(filename, loaderContext);
|
---|
| 42 | module.paths = _module.default._nodeModulePaths(loaderContext.context); // eslint-disable-line no-underscore-dangle
|
---|
| 43 |
|
---|
| 44 | module.filename = filename;
|
---|
| 45 |
|
---|
| 46 | module._compile(code, filename); // eslint-disable-line no-underscore-dangle
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | return module.exports;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | function compareIds(a, b) {
|
---|
| 53 | if (typeof a !== typeof b) {
|
---|
| 54 | return typeof a < typeof b ? -1 : 1;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | if (a < b) {
|
---|
| 58 | return -1;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | if (a > b) {
|
---|
| 62 | return 1;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | return 0;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | function compareModulesByIdentifier(a, b) {
|
---|
| 69 | return compareIds(a.identifier(), b.identifier());
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | const MODULE_TYPE = "css/mini-extract";
|
---|
| 73 | exports.MODULE_TYPE = MODULE_TYPE;
|
---|
| 74 | const AUTO_PUBLIC_PATH = "__MINI_CSS_EXTRACT_PLUGIN_PUBLIC_PATH__";
|
---|
| 75 | exports.AUTO_PUBLIC_PATH = AUTO_PUBLIC_PATH;
|
---|
| 76 |
|
---|
| 77 | function isAbsolutePath(str) {
|
---|
| 78 | return _path.default.posix.isAbsolute(str) || _path.default.win32.isAbsolute(str);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | const RELATIVE_PATH_REGEXP = /^\.\.?[/\\]/;
|
---|
| 82 |
|
---|
| 83 | function isRelativePath(str) {
|
---|
| 84 | return RELATIVE_PATH_REGEXP.test(str);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | function stringifyRequest(loaderContext, request) {
|
---|
| 88 | const splitted = request.split("!");
|
---|
| 89 | const {
|
---|
| 90 | context
|
---|
| 91 | } = loaderContext;
|
---|
| 92 | return JSON.stringify(splitted.map(part => {
|
---|
| 93 | // First, separate singlePath from query, because the query might contain paths again
|
---|
| 94 | const splittedPart = part.match(/^(.*?)(\?.*)/);
|
---|
| 95 | const query = splittedPart ? splittedPart[2] : "";
|
---|
| 96 | let singlePath = splittedPart ? splittedPart[1] : part;
|
---|
| 97 |
|
---|
| 98 | if (isAbsolutePath(singlePath) && context) {
|
---|
| 99 | singlePath = _path.default.relative(context, singlePath);
|
---|
| 100 |
|
---|
| 101 | if (isAbsolutePath(singlePath)) {
|
---|
| 102 | // If singlePath still matches an absolute path, singlePath was on a different drive than context.
|
---|
| 103 | // In this case, we leave the path platform-specific without replacing any separators.
|
---|
| 104 | // @see https://github.com/webpack/loader-utils/pull/14
|
---|
| 105 | return singlePath + query;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | if (isRelativePath(singlePath) === false) {
|
---|
| 109 | // Ensure that the relative path starts at least with ./ otherwise it would be a request into the modules directory (like node_modules).
|
---|
| 110 | singlePath = `./${singlePath}`;
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | return singlePath.replace(/\\/g, "/") + query;
|
---|
| 115 | }).join("!"));
|
---|
| 116 | } |
---|