Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default (cssSourceFilePath: string, options: OptionsType): StyleModuleMapType => {
// eslint-disable-next-line prefer-const
let runner;
let generateScopedName;
if (options.generateScopedName && typeof options.generateScopedName === 'function') {
generateScopedName = options.generateScopedName;
} else {
generateScopedName = genericNames(options.generateScopedName || optionsDefaults.generateScopedName, {
context: options.context || process.cwd()
});
}
const filetypeOptions = getFiletypeOptions(cssSourceFilePath, options.filetypes);
const fetch = (to: string, from: string) => {
const fromDirectoryPath = dirname(from);
const toPath = resolve(fromDirectoryPath, to);
return getTokens(runner, toPath, filetypeOptions);
};
const extraPlugins = getExtraPlugins(filetypeOptions);
const plugins = [
export default function extractor({
append = [],
prepend = [],
createImportedName,
generateScopedName,
mode,
use,
rootDir: context = process.cwd(),
} = {}, fetch) {
let scopedName;
if (generateScopedName) {
scopedName = typeof generateScopedName !== 'function'
? genericNames(generateScopedName || '[name]__[local]___[hash:base64:5]', {context})
: generateScopedName;
} else {
// small fallback
scopedName = (local, filename) => Scope.generateScopedName(local, relative(context, filename));
}
const plugins = (use || [
...prepend,
Values,
mode
? new LocalByDefault({mode})
: LocalByDefault,
createImportedName
? new ExtractImports({createImportedName})
: ExtractImports,
new Scope({generateScopedName: scopedName}),
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;
}
const alias = generateScopedName(name, input.from, input.css);
aliases[name] = alias;
// icss-scoped contract
function getScopedNameGenerator(opts) {
const scopedNameGenerator = opts.generateScopedName || generateScopedName;
if (typeof scopedNameGenerator === "function") return scopedNameGenerator;
return genericNames(scopedNameGenerator, {
context: process.cwd(),
hashPrefix: opts.hashPrefix
});
}
function getScopedNameGenerator (opts) {
const scopedNameGenerator = opts.generateScopedName || generateScopedName
if (typeof scopedNameGenerator === 'function') return scopedNameGenerator
return genericNames(scopedNameGenerator, {context: process.cwd()})
}