update
This commit is contained in:
+80
-67
@@ -9,70 +9,90 @@ var _postcss = _interopRequireDefault(require("postcss"));
|
||||
|
||||
var _icssUtils = require("icss-utils");
|
||||
|
||||
var _loaderUtils = require("loader-utils");
|
||||
var _utils = require("../utils");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function makeRequestableIcssImports(icssImports) {
|
||||
return Object.keys(icssImports).reduce((accumulator, url) => {
|
||||
const tokensMap = icssImports[url];
|
||||
const tokens = Object.keys(tokensMap);
|
||||
|
||||
if (tokens.length === 0) {
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
const normalizedUrl = (0, _loaderUtils.urlToRequest)(url);
|
||||
|
||||
if (!accumulator[normalizedUrl]) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
accumulator[normalizedUrl] = tokensMap;
|
||||
} else {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
accumulator[normalizedUrl] = { ...accumulator[normalizedUrl],
|
||||
...tokensMap
|
||||
};
|
||||
}
|
||||
|
||||
return accumulator;
|
||||
}, {});
|
||||
}
|
||||
|
||||
var _default = _postcss.default.plugin('postcss-icss-parser', options => (css, result) => {
|
||||
var _default = _postcss.default.plugin('postcss-icss-parser', options => async css => {
|
||||
const importReplacements = Object.create(null);
|
||||
const extractedICSS = (0, _icssUtils.extractICSS)(css);
|
||||
const icssImports = makeRequestableIcssImports(extractedICSS.icssImports);
|
||||
const {
|
||||
icssImports,
|
||||
icssExports
|
||||
} = (0, _icssUtils.extractICSS)(css);
|
||||
const imports = new Map();
|
||||
const tasks = []; // eslint-disable-next-line guard-for-in
|
||||
|
||||
for (const [importIndex, url] of Object.keys(icssImports).entries()) {
|
||||
const importName = `___CSS_LOADER_ICSS_IMPORT_${importIndex}___`;
|
||||
result.messages.push({
|
||||
type: 'import',
|
||||
value: {
|
||||
importName,
|
||||
url: options.urlHandler ? options.urlHandler(url) : url
|
||||
}
|
||||
}, {
|
||||
type: 'api-import',
|
||||
value: {
|
||||
type: 'internal',
|
||||
importName,
|
||||
dedupe: true
|
||||
}
|
||||
});
|
||||
const tokenMap = icssImports[url];
|
||||
const tokens = Object.keys(tokenMap);
|
||||
for (const url in icssImports) {
|
||||
const tokens = icssImports[url];
|
||||
|
||||
for (const [replacementIndex, token] of tokens.entries()) {
|
||||
const replacementName = `___CSS_LOADER_ICSS_IMPORT_${importIndex}_REPLACEMENT_${replacementIndex}___`;
|
||||
const localName = tokenMap[token];
|
||||
if (Object.keys(tokens).length === 0) {
|
||||
// eslint-disable-next-line no-continue
|
||||
continue;
|
||||
}
|
||||
|
||||
let normalizedUrl = url;
|
||||
let prefix = '';
|
||||
const queryParts = normalizedUrl.split('!');
|
||||
|
||||
if (queryParts.length > 1) {
|
||||
normalizedUrl = queryParts.pop();
|
||||
prefix = queryParts.join('!');
|
||||
}
|
||||
|
||||
const request = (0, _utils.requestify)((0, _utils.normalizeUrl)(normalizedUrl, true), options.rootContext);
|
||||
|
||||
const doResolve = async () => {
|
||||
const {
|
||||
resolver,
|
||||
context
|
||||
} = options;
|
||||
const resolvedUrl = await (0, _utils.resolveRequests)(resolver, context, [...new Set([normalizedUrl, request])]);
|
||||
return {
|
||||
url: resolvedUrl,
|
||||
prefix,
|
||||
tokens
|
||||
};
|
||||
};
|
||||
|
||||
tasks.push(doResolve());
|
||||
}
|
||||
|
||||
const results = await Promise.all(tasks);
|
||||
|
||||
for (let index = 0; index <= results.length - 1; index++) {
|
||||
const {
|
||||
url,
|
||||
prefix,
|
||||
tokens
|
||||
} = results[index];
|
||||
const newUrl = prefix ? `${prefix}!${url}` : url;
|
||||
const importKey = newUrl;
|
||||
let importName = imports.get(importKey);
|
||||
|
||||
if (!importName) {
|
||||
importName = `___CSS_LOADER_ICSS_IMPORT_${imports.size}___`;
|
||||
imports.set(importKey, importName);
|
||||
options.imports.push({
|
||||
importName,
|
||||
url: options.urlHandler(newUrl),
|
||||
icss: true,
|
||||
index
|
||||
});
|
||||
options.api.push({
|
||||
importName,
|
||||
dedupe: true,
|
||||
index
|
||||
});
|
||||
}
|
||||
|
||||
for (const [replacementIndex, token] of Object.keys(tokens).entries()) {
|
||||
const replacementName = `___CSS_LOADER_ICSS_IMPORT_${index}_REPLACEMENT_${replacementIndex}___`;
|
||||
const localName = tokens[token];
|
||||
importReplacements[token] = replacementName;
|
||||
result.messages.push({
|
||||
type: 'icss-replacement',
|
||||
value: {
|
||||
replacementName,
|
||||
importName,
|
||||
localName
|
||||
}
|
||||
options.replacements.push({
|
||||
replacementName,
|
||||
importName,
|
||||
localName
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -81,18 +101,11 @@ var _default = _postcss.default.plugin('postcss-icss-parser', options => (css, r
|
||||
(0, _icssUtils.replaceSymbols)(css, importReplacements);
|
||||
}
|
||||
|
||||
const {
|
||||
icssExports
|
||||
} = extractedICSS;
|
||||
|
||||
for (const name of Object.keys(icssExports)) {
|
||||
const value = (0, _icssUtils.replaceValueSymbols)(icssExports[name], importReplacements);
|
||||
result.messages.push({
|
||||
type: 'export',
|
||||
value: {
|
||||
name,
|
||||
value
|
||||
}
|
||||
options.exports.push({
|
||||
name,
|
||||
value
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
+124
-51
@@ -5,20 +5,20 @@ Object.defineProperty(exports, "__esModule", {
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _util = require("util");
|
||||
|
||||
var _postcss = _interopRequireDefault(require("postcss"));
|
||||
|
||||
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
|
||||
|
||||
var _loaderUtils = require("loader-utils");
|
||||
|
||||
var _utils = require("../utils");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const pluginName = 'postcss-import-parser';
|
||||
|
||||
var _default = _postcss.default.plugin(pluginName, options => (css, result) => {
|
||||
const importsMap = new Map();
|
||||
function walkAtRules(css, result, options, callback) {
|
||||
const accumulator = [];
|
||||
css.walkAtRules(/^import$/i, atRule => {
|
||||
// Convert only top-level @import
|
||||
if (atRule.parent.type !== 'root') {
|
||||
@@ -34,11 +34,11 @@ var _default = _postcss.default.plugin(pluginName, options => (css, result) => {
|
||||
}
|
||||
|
||||
const {
|
||||
nodes
|
||||
nodes: paramsNodes
|
||||
} = (0, _postcssValueParser.default)(atRule.params); // No nodes - `@import ;`
|
||||
// Invalid type - `@import foo-bar;`
|
||||
|
||||
if (nodes.length === 0 || nodes[0].type !== 'string' && nodes[0].type !== 'function') {
|
||||
if (paramsNodes.length === 0 || paramsNodes[0].type !== 'string' && paramsNodes[0].type !== 'function') {
|
||||
result.warn(`Unable to find uri in "${atRule.toString()}"`, {
|
||||
node: atRule
|
||||
});
|
||||
@@ -48,20 +48,20 @@ var _default = _postcss.default.plugin(pluginName, options => (css, result) => {
|
||||
let isStringValue;
|
||||
let url;
|
||||
|
||||
if (nodes[0].type === 'string') {
|
||||
if (paramsNodes[0].type === 'string') {
|
||||
isStringValue = true;
|
||||
url = nodes[0].value;
|
||||
} else if (nodes[0].type === 'function') {
|
||||
url = paramsNodes[0].value;
|
||||
} else {
|
||||
// Invalid function - `@import nourl(test.css);`
|
||||
if (nodes[0].value.toLowerCase() !== 'url') {
|
||||
if (paramsNodes[0].value.toLowerCase() !== 'url') {
|
||||
result.warn(`Unable to find uri in "${atRule.toString()}"`, {
|
||||
node: atRule
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
isStringValue = nodes[0].nodes.length !== 0 && nodes[0].nodes[0].type === 'string';
|
||||
url = isStringValue ? nodes[0].nodes[0].value : _postcssValueParser.default.stringify(nodes[0].nodes);
|
||||
isStringValue = paramsNodes[0].nodes.length !== 0 && paramsNodes[0].nodes[0].type === 'string';
|
||||
url = isStringValue ? paramsNodes[0].nodes[0].value : _postcssValueParser.default.stringify(paramsNodes[0].nodes);
|
||||
} // Empty url - `@import "";` or `@import url();`
|
||||
|
||||
|
||||
@@ -72,70 +72,143 @@ var _default = _postcss.default.plugin(pluginName, options => (css, result) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const isRequestable = (0, _loaderUtils.isUrlRequest)(url);
|
||||
accumulator.push({
|
||||
atRule,
|
||||
url,
|
||||
isStringValue,
|
||||
mediaNodes: paramsNodes.slice(1)
|
||||
});
|
||||
});
|
||||
callback(null, accumulator);
|
||||
}
|
||||
|
||||
const asyncWalkAtRules = (0, _util.promisify)(walkAtRules);
|
||||
|
||||
var _default = _postcss.default.plugin(pluginName, options => async (css, result) => {
|
||||
const parsedResults = await asyncWalkAtRules(css, result, options);
|
||||
|
||||
if (parsedResults.length === 0) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
const imports = new Map();
|
||||
const tasks = [];
|
||||
|
||||
for (const parsedResult of parsedResults) {
|
||||
const {
|
||||
atRule,
|
||||
url,
|
||||
isStringValue,
|
||||
mediaNodes
|
||||
} = parsedResult;
|
||||
let normalizedUrl = url;
|
||||
let prefix = '';
|
||||
const isRequestable = (0, _utils.isUrlRequestable)(normalizedUrl);
|
||||
|
||||
if (isRequestable) {
|
||||
url = (0, _utils.normalizeUrl)(url, isStringValue); // Empty url after normalize - `@import '\
|
||||
const queryParts = normalizedUrl.split('!');
|
||||
|
||||
if (queryParts.length > 1) {
|
||||
normalizedUrl = queryParts.pop();
|
||||
prefix = queryParts.join('!');
|
||||
}
|
||||
|
||||
normalizedUrl = (0, _utils.normalizeUrl)(normalizedUrl, isStringValue); // Empty url after normalize - `@import '\
|
||||
// \
|
||||
// \
|
||||
// ';
|
||||
|
||||
if (url.trim().length === 0) {
|
||||
if (normalizedUrl.trim().length === 0) {
|
||||
result.warn(`Unable to find uri in "${atRule.toString()}"`, {
|
||||
node: atRule
|
||||
});
|
||||
return;
|
||||
}); // eslint-disable-next-line no-continue
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
const media = _postcssValueParser.default.stringify(nodes.slice(1)).trim().toLowerCase();
|
||||
let media;
|
||||
|
||||
if (options.filter && !options.filter({
|
||||
url,
|
||||
media
|
||||
})) {
|
||||
return;
|
||||
if (mediaNodes.length > 0) {
|
||||
media = _postcssValueParser.default.stringify(mediaNodes).trim().toLowerCase();
|
||||
}
|
||||
|
||||
if (options.filter && !options.filter(normalizedUrl, media)) {
|
||||
// eslint-disable-next-line no-continue
|
||||
continue;
|
||||
}
|
||||
|
||||
atRule.remove();
|
||||
|
||||
if (isRequestable) {
|
||||
const importKey = url;
|
||||
let importName = importsMap.get(importKey);
|
||||
const request = (0, _utils.requestify)(normalizedUrl, options.rootContext);
|
||||
tasks.push((async () => {
|
||||
const {
|
||||
resolver,
|
||||
context
|
||||
} = options;
|
||||
const resolvedUrl = await (0, _utils.resolveRequests)(resolver, context, [...new Set([request, normalizedUrl])]);
|
||||
return {
|
||||
url: resolvedUrl,
|
||||
media,
|
||||
prefix,
|
||||
isRequestable
|
||||
};
|
||||
})());
|
||||
} else {
|
||||
tasks.push({
|
||||
url,
|
||||
media,
|
||||
prefix,
|
||||
isRequestable
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const results = await Promise.all(tasks);
|
||||
|
||||
for (let index = 0; index <= results.length - 1; index++) {
|
||||
const {
|
||||
url,
|
||||
isRequestable,
|
||||
media
|
||||
} = results[index];
|
||||
|
||||
if (isRequestable) {
|
||||
const {
|
||||
prefix
|
||||
} = results[index];
|
||||
const newUrl = prefix ? `${prefix}!${url}` : url;
|
||||
const importKey = newUrl;
|
||||
let importName = imports.get(importKey);
|
||||
|
||||
if (!importName) {
|
||||
importName = `___CSS_LOADER_AT_RULE_IMPORT_${importsMap.size}___`;
|
||||
importsMap.set(importKey, importName);
|
||||
result.messages.push({
|
||||
type: 'import',
|
||||
value: {
|
||||
importName,
|
||||
url: options.urlHandler ? options.urlHandler(url) : url
|
||||
}
|
||||
importName = `___CSS_LOADER_AT_RULE_IMPORT_${imports.size}___`;
|
||||
imports.set(importKey, importName);
|
||||
options.imports.push({
|
||||
importName,
|
||||
url: options.urlHandler(newUrl),
|
||||
index
|
||||
});
|
||||
}
|
||||
|
||||
result.messages.push({
|
||||
type: 'api-import',
|
||||
value: {
|
||||
type: 'internal',
|
||||
importName,
|
||||
media
|
||||
}
|
||||
});
|
||||
return;
|
||||
options.api.push({
|
||||
importName,
|
||||
media,
|
||||
index
|
||||
}); // eslint-disable-next-line no-continue
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
result.messages.push({
|
||||
pluginName,
|
||||
type: 'api-import',
|
||||
value: {
|
||||
type: 'external',
|
||||
url,
|
||||
media
|
||||
}
|
||||
options.api.push({
|
||||
url,
|
||||
media,
|
||||
index
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
+204
-108
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _util = require("util");
|
||||
|
||||
var _postcss = _interopRequireDefault(require("postcss"));
|
||||
|
||||
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
|
||||
@@ -22,140 +24,234 @@ function getNodeFromUrlFunc(node) {
|
||||
return node.nodes && node.nodes[0];
|
||||
}
|
||||
|
||||
function walkUrls(parsed, callback) {
|
||||
parsed.walk(node => {
|
||||
if (node.type !== 'function') {
|
||||
return;
|
||||
}
|
||||
function shouldHandleRule(rule, decl, result) {
|
||||
// https://www.w3.org/TR/css-syntax-3/#typedef-url-token
|
||||
if (rule.url.replace(/^[\s]+|[\s]+$/g, '').length === 0) {
|
||||
result.warn(`Unable to find uri in '${decl.toString()}'`, {
|
||||
node: decl
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isUrlFunc.test(node.value)) {
|
||||
const {
|
||||
nodes
|
||||
} = node;
|
||||
const isStringValue = nodes.length !== 0 && nodes[0].type === 'string';
|
||||
const url = isStringValue ? nodes[0].value : _postcssValueParser.default.stringify(nodes);
|
||||
callback(getNodeFromUrlFunc(node), url, false, isStringValue); // Do not traverse inside `url`
|
||||
// eslint-disable-next-line consistent-return
|
||||
if (!(0, _utils.isUrlRequestable)(rule.url)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isImageSetFunc.test(node.value)) {
|
||||
for (const nNode of node.nodes) {
|
||||
const {
|
||||
type,
|
||||
value
|
||||
} = nNode;
|
||||
|
||||
if (type === 'function' && isUrlFunc.test(value)) {
|
||||
const {
|
||||
nodes
|
||||
} = nNode;
|
||||
const isStringValue = nodes.length !== 0 && nodes[0].type === 'string';
|
||||
const url = isStringValue ? nodes[0].value : _postcssValueParser.default.stringify(nodes);
|
||||
callback(getNodeFromUrlFunc(nNode), url, false, isStringValue);
|
||||
}
|
||||
|
||||
if (type === 'string') {
|
||||
callback(nNode, value, true, true);
|
||||
}
|
||||
} // Do not traverse inside `image-set`
|
||||
// eslint-disable-next-line consistent-return
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
var _default = _postcss.default.plugin(pluginName, options => (css, result) => {
|
||||
const importsMap = new Map();
|
||||
const replacementsMap = new Map();
|
||||
let hasHelper = false;
|
||||
function walkCss(css, result, options, callback) {
|
||||
const accumulator = [];
|
||||
css.walkDecls(decl => {
|
||||
if (!needParseDecl.test(decl.value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const parsed = (0, _postcssValueParser.default)(decl.value);
|
||||
walkUrls(parsed, (node, url, needQuotes, isStringValue) => {
|
||||
// https://www.w3.org/TR/css-syntax-3/#typedef-url-token
|
||||
if (url.replace(/^[\s]+|[\s]+$/g, '').length === 0) {
|
||||
result.warn(`Unable to find uri in '${decl ? decl.toString() : decl.value}'`, {
|
||||
node: decl
|
||||
});
|
||||
parsed.walk(node => {
|
||||
if (node.type !== 'function') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.filter && !options.filter(url)) {
|
||||
return;
|
||||
}
|
||||
if (isUrlFunc.test(node.value)) {
|
||||
const {
|
||||
nodes
|
||||
} = node;
|
||||
const isStringValue = nodes.length !== 0 && nodes[0].type === 'string';
|
||||
const url = isStringValue ? nodes[0].value : _postcssValueParser.default.stringify(nodes);
|
||||
const rule = {
|
||||
node: getNodeFromUrlFunc(node),
|
||||
url,
|
||||
needQuotes: false,
|
||||
isStringValue
|
||||
};
|
||||
|
||||
const splittedUrl = url.split(/(\?)?#/);
|
||||
const [urlWithoutHash, singleQuery, hashValue] = splittedUrl;
|
||||
const hash = singleQuery || hashValue ? `${singleQuery ? '?' : ''}${hashValue ? `#${hashValue}` : ''}` : '';
|
||||
const normalizedUrl = (0, _utils.normalizeUrl)(urlWithoutHash, isStringValue);
|
||||
const importKey = normalizedUrl;
|
||||
let importName = importsMap.get(importKey);
|
||||
|
||||
if (!importName) {
|
||||
importName = `___CSS_LOADER_URL_IMPORT_${importsMap.size}___`;
|
||||
importsMap.set(importKey, importName);
|
||||
|
||||
if (!hasHelper) {
|
||||
const urlToHelper = require.resolve('../runtime/getUrl.js');
|
||||
|
||||
result.messages.push({
|
||||
pluginName,
|
||||
type: 'import',
|
||||
value: {
|
||||
importName: '___CSS_LOADER_GET_URL_IMPORT___',
|
||||
url: options.urlHandler ? options.urlHandler(urlToHelper) : urlToHelper
|
||||
}
|
||||
if (shouldHandleRule(rule, decl, result)) {
|
||||
accumulator.push({
|
||||
decl,
|
||||
rule,
|
||||
parsed
|
||||
});
|
||||
hasHelper = true;
|
||||
}
|
||||
} // Do not traverse inside `url`
|
||||
// eslint-disable-next-line consistent-return
|
||||
|
||||
result.messages.push({
|
||||
pluginName,
|
||||
type: 'import',
|
||||
value: {
|
||||
importName,
|
||||
url: options.urlHandler ? options.urlHandler(normalizedUrl) : normalizedUrl
|
||||
|
||||
return false;
|
||||
} else if (isImageSetFunc.test(node.value)) {
|
||||
for (const nNode of node.nodes) {
|
||||
const {
|
||||
type,
|
||||
value
|
||||
} = nNode;
|
||||
|
||||
if (type === 'function' && isUrlFunc.test(value)) {
|
||||
const {
|
||||
nodes
|
||||
} = nNode;
|
||||
const isStringValue = nodes.length !== 0 && nodes[0].type === 'string';
|
||||
const url = isStringValue ? nodes[0].value : _postcssValueParser.default.stringify(nodes);
|
||||
const rule = {
|
||||
node: getNodeFromUrlFunc(nNode),
|
||||
url,
|
||||
needQuotes: false,
|
||||
isStringValue
|
||||
};
|
||||
|
||||
if (shouldHandleRule(rule, decl, result)) {
|
||||
accumulator.push({
|
||||
decl,
|
||||
rule,
|
||||
parsed
|
||||
});
|
||||
}
|
||||
} else if (type === 'string') {
|
||||
const rule = {
|
||||
node: nNode,
|
||||
url: value,
|
||||
needQuotes: true,
|
||||
isStringValue: true
|
||||
};
|
||||
|
||||
if (shouldHandleRule(rule, decl, result)) {
|
||||
accumulator.push({
|
||||
decl,
|
||||
rule,
|
||||
parsed
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} // Do not traverse inside `image-set`
|
||||
// eslint-disable-next-line consistent-return
|
||||
|
||||
const replacementKey = JSON.stringify({
|
||||
importKey,
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
callback(null, accumulator);
|
||||
}
|
||||
|
||||
const asyncWalkCss = (0, _util.promisify)(walkCss);
|
||||
|
||||
var _default = _postcss.default.plugin(pluginName, options => async (css, result) => {
|
||||
const parsedResults = await asyncWalkCss(css, result, options);
|
||||
|
||||
if (parsedResults.length === 0) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
const tasks = [];
|
||||
const imports = new Map();
|
||||
const replacements = new Map();
|
||||
let hasUrlImportHelper = false;
|
||||
|
||||
for (const parsedResult of parsedResults) {
|
||||
const {
|
||||
url,
|
||||
isStringValue
|
||||
} = parsedResult.rule;
|
||||
let normalizedUrl = url;
|
||||
let prefix = '';
|
||||
const queryParts = normalizedUrl.split('!');
|
||||
|
||||
if (queryParts.length > 1) {
|
||||
normalizedUrl = queryParts.pop();
|
||||
prefix = queryParts.join('!');
|
||||
}
|
||||
|
||||
normalizedUrl = (0, _utils.normalizeUrl)(normalizedUrl, isStringValue);
|
||||
|
||||
if (!options.filter(normalizedUrl)) {
|
||||
// eslint-disable-next-line no-continue
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!hasUrlImportHelper) {
|
||||
options.imports.push({
|
||||
importName: '___CSS_LOADER_GET_URL_IMPORT___',
|
||||
url: options.urlHandler(require.resolve('../runtime/getUrl.js')),
|
||||
index: -1
|
||||
});
|
||||
hasUrlImportHelper = true;
|
||||
}
|
||||
|
||||
const splittedUrl = normalizedUrl.split(/(\?)?#/);
|
||||
const [pathname, query, hashOrQuery] = splittedUrl;
|
||||
let hash = query ? '?' : '';
|
||||
hash += hashOrQuery ? `#${hashOrQuery}` : '';
|
||||
const request = (0, _utils.requestify)(pathname, options.rootContext);
|
||||
tasks.push((async () => {
|
||||
const {
|
||||
resolver,
|
||||
context
|
||||
} = options;
|
||||
const resolvedUrl = await (0, _utils.resolveRequests)(resolver, context, [...new Set([request, normalizedUrl])]);
|
||||
return {
|
||||
url: resolvedUrl,
|
||||
prefix,
|
||||
hash,
|
||||
parsedResult
|
||||
};
|
||||
})());
|
||||
}
|
||||
|
||||
const results = await Promise.all(tasks);
|
||||
|
||||
for (let index = 0; index <= results.length - 1; index++) {
|
||||
const {
|
||||
url,
|
||||
prefix,
|
||||
hash,
|
||||
parsedResult: {
|
||||
decl,
|
||||
rule,
|
||||
parsed
|
||||
}
|
||||
} = results[index];
|
||||
const newUrl = prefix ? `${prefix}!${url}` : url;
|
||||
const importKey = newUrl;
|
||||
let importName = imports.get(importKey);
|
||||
|
||||
if (!importName) {
|
||||
importName = `___CSS_LOADER_URL_IMPORT_${imports.size}___`;
|
||||
imports.set(importKey, importName);
|
||||
options.imports.push({
|
||||
importName,
|
||||
url: options.urlHandler(newUrl),
|
||||
index
|
||||
});
|
||||
}
|
||||
|
||||
const {
|
||||
needQuotes
|
||||
} = rule;
|
||||
const replacementKey = JSON.stringify({
|
||||
newUrl,
|
||||
hash,
|
||||
needQuotes
|
||||
});
|
||||
let replacementName = replacements.get(replacementKey);
|
||||
|
||||
if (!replacementName) {
|
||||
replacementName = `___CSS_LOADER_URL_REPLACEMENT_${replacements.size}___`;
|
||||
replacements.set(replacementKey, replacementName);
|
||||
options.replacements.push({
|
||||
replacementName,
|
||||
importName,
|
||||
hash,
|
||||
needQuotes
|
||||
});
|
||||
let replacementName = replacementsMap.get(replacementKey);
|
||||
|
||||
if (!replacementName) {
|
||||
replacementName = `___CSS_LOADER_URL_REPLACEMENT_${replacementsMap.size}___`;
|
||||
replacementsMap.set(replacementKey, replacementName);
|
||||
result.messages.push({
|
||||
pluginName,
|
||||
type: 'url-replacement',
|
||||
value: {
|
||||
replacementName,
|
||||
importName,
|
||||
hash,
|
||||
needQuotes
|
||||
}
|
||||
});
|
||||
} // eslint-disable-next-line no-param-reassign
|
||||
} // eslint-disable-next-line no-param-reassign
|
||||
|
||||
|
||||
node.type = 'word'; // eslint-disable-next-line no-param-reassign
|
||||
rule.node.type = 'word'; // eslint-disable-next-line no-param-reassign
|
||||
|
||||
node.value = replacementName;
|
||||
}); // eslint-disable-next-line no-param-reassign
|
||||
rule.node.value = replacementName; // eslint-disable-next-line no-param-reassign
|
||||
|
||||
decl.value = parsed.toString();
|
||||
});
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
||||
exports.default = _default;
|
||||
Reference in New Issue
Block a user