Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Will strip `~` from imports, unless followed by a slash.
data: css.replace(/(@import ['"])~(?!\/)/gm, '$1'),
indentedSyntax: fileType === FileTypes.sass,
includePaths: [filePath, 'node_modules', ...(includePaths || [])],
...sassOptions,
})
.css.toString();
} else {
transformedCss = css;
}
const processedCss = processor.process(transformedCss, {
from: fileName,
});
return processedCss.root ? extractICSS(processedCss.root).icssExports : {};
} catch (e) {
console.log(e);
logger.error(e);
return {};
}
};
module.exports = postcss.plugin(plugin, (options = {}) => (css, result) => {
const { icssImports, icssExports } = extractICSS(css);
const generateScopedName =
options.generateScopedName ||
genericNames("[name]__[local]---[hash:base64:5]");
const input = (css && css.source && css.source.input) || {};
const aliases = {};
walkRules(css, rule => {
const getAlias = name => {
if (aliases[name]) {
return aliases[name];
}
// icss-value contract
const valueMsg = getValue(result.messages, name);
if (valueMsg) {
aliases[valueMsg.name] = name;
return name;
}
return function(css) {
const { icssImports } = extractICSS(css, false);
const localAliasMap = getImportLocalAliases(icssImports);
css.walkAtRules(function(atrule) {
if (/keyframes$/i.test(atrule.name)) {
const globalMatch = /^\s*:global\s*\((.+)\)\s*$/.exec(atrule.params);
const localMatch = /^\s*:local\s*\((.+)\)\s*$/.exec(atrule.params);
let globalKeyframes = globalMode;
if (globalMatch) {
if (pureMode) {
throw atrule.error(
'@keyframes :global(...) is not allowed in pure mode'
);
}
atrule.params = globalMatch[1];
globalKeyframes = true;
} else if (localMatch) {
() => function process(css, result) {
const { icssExports, icssImports } = extractICSS(css)
if (Object.keys(icssImports).length) {
console.log('Found imports, do we need to process them?')
console.log(JSON.stringify(icssExports, null, 2))
}
Object.entries(icssExports).forEach(([key, value]) => {
result.messages.push({
plugin,
type: 'export',
item: { key, value },
});
});
}
)
values.nodes[0].nodes.shift()
var mediaQuery = Tokenizer.stringifyValues(values)
if (isUrlRequest(url, options.root)) {
url = loaderUtils.urlToRequest(url, options.root)
}
importItems.push({
url: url,
mediaQuery: mediaQuery
})
rule.remove()
})
}
var icss = icssUtils.extractICSS(css)
exports = icss.icssExports
Object.keys(icss.icssImports).forEach(function (key) {
var url = loaderUtils.parseString(key)
Object.keys(icss.icssImports[key]).forEach(function (prop) {
imports['$' + prop] = importItems.length
importItems.push({
url: url,
export: icss.icssImports[key][prop]
})
})
})
Object.keys(exports).forEach(function (exportName) {
exports[exportName] = replaceImportsInString(exports[exportName])
})
module.exports = postcss.plugin(plugin, () => (css, result) => {
const { icssImports, icssExports } = extractICSS(css);
const valuesExports = {};
const getAliasName = createGenerator();
const addExports = (node, name, value) => {
if (isForbidden(name)) {
result.warn(`Dot and hash symbols are not allowed in value "${name}"`, {
node
});
}
if (valuesExports[name]) {
result.warn(`"${name}" value already declared`, { node });
}
valuesExports[name] = replaceValueSymbols(value, valuesExports);
};
css.walkAtRules("value", atrule => {
if (atrule.params.indexOf("@value") !== -1) {
return;
}
values.nodes[0].nodes.shift();
var mediaQuery = Tokenizer.stringifyValues(values);
if(loaderUtils.isUrlRequest(url, options.root) && options.mode === "global") {
url = loaderUtils.urlToRequest(url, options.root);
}
importItems.push({
url: url,
mediaQuery: mediaQuery
});
rule.remove();
});
}
var icss = icssUtils.extractICSS(css);
exports = icss.icssExports;
Object.keys(icss.icssImports).forEach(function(key) {
var url = loaderUtils.parseString(key);
Object.keys(icss.icssImports[key]).forEach(function(prop) {
imports["$" + prop] = importItems.length;
importItems.push({
url: url,
export: icss.icssImports[key][prop]
});
})
});
Object.keys(exports).forEach(function(exportName) {
exports[exportName] = replaceImportsInString(exports[exportName]);
});
values.nodes[0].nodes.shift();
var mediaQuery = Tokenizer.stringifyValues(values);
if(loaderUtils.isUrlRequest(url, options.root)) {
url = loaderUtils.urlToRequest(url, options.root);
}
importItems.push({
url: url,
mediaQuery: mediaQuery
});
rule.remove();
});
}
var icss = icssUtils.extractICSS(css);
exports = icss.icssExports;
Object.keys(icss.icssImports).forEach(function(key) {
var url = loaderUtils.parseString(key);
Object.keys(icss.icssImports[key]).forEach(function(prop) {
imports["$" + prop] = importItems.length;
importItems.push({
url: url,
export: icss.icssImports[key][prop]
});
})
});
Object.keys(exports).forEach(function(exportName) {
exports[exportName] = replaceImportsInString(exports[exportName]);
});
return;
}
values.nodes[0].nodes.shift();
var mediaQuery = Tokenizer.stringifyValues(values);
if(loaderUtils.isUrlRequest(url, options.root) && options.mode === "global") {
url = loaderUtils.urlToRequest(url, options.root);
}
importItems.push({
url: url,
mediaQuery: mediaQuery
});
rule.remove();
});
}
var icss = icssUtils.extractICSS(css);
exports = icss.icssExports;
Object.keys(icss.icssImports).forEach(function(key) {
var url = loaderUtils.parseString(key);
Object.keys(icss.icssImports[key]).forEach(function(prop) {
imports["$" + prop] = importItems.length;
importItems.push({
url: url,
export: icss.icssImports[key][prop]
});
})
});
Object.keys(exports).forEach(function(exportName) {
exports[exportName] = replaceImportsInString(exports[exportName]);
});
return;
}
values.nodes[0].nodes.shift();
var mediaQuery = Tokenizer.stringifyValues(values);
if(loaderUtils.isUrlRequest(url, options.root) && options.mode === "global") {
url = loaderUtils.urlToRequest(url, options.root);
}
importItems.push({
url: url,
mediaQuery: mediaQuery
});
rule.remove();
});
}
var icss = icssUtils.extractICSS(css);
exports = icss.icssExports;
Object.keys(icss.icssImports).forEach(function(key) {
var url = loaderUtils.parseString(key);
Object.keys(icss.icssImports[key]).forEach(function(prop) {
imports["$" + prop] = importItems.length;
importItems.push({
url: url,
export: icss.icssImports[key][prop]
});
})
});
Object.keys(exports).forEach(function(exportName) {
exports[exportName] = replaceImportsInString(exports[exportName]);
});