Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-modules-values-replace

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-modules-values-replace - npm Package Compare versions

Comparing version 3.4.0 to 4.0.0

137

index.js

@@ -5,3 +5,3 @@ const postcss = require('postcss');

const { CachedInputFileSystem, NodeJsInputFileSystem, ResolverFactory } = require('enhanced-resolve');
const valuesParser = require('postcss-values-parser');
const { parse } = require('postcss-values-parser');
const { urlToRequest } = require('loader-utils');

@@ -23,3 +23,3 @@ const ICSSUtils = require('icss-utils');

const replaceValueSymbols = (valueString, replacements) => {
const value = valuesParser(valueString, { loose: true }).parse();
const value = parse(valueString, { ignoreUnknownWords: true });

@@ -137,3 +137,9 @@ value.walk((node) => {

const walkerPlugin = postcss.plugin(INNER_PLUGIN, (fn, ...args) => fn.bind(null, ...args));
const walkerPlugin = (fn, ...args) => ({
postcssPlugin: INNER_PLUGIN,
Once(root, { result }) {
return fn.call(null, ...args, root, result);
},
});
walkerPlugin.postcss = true;

@@ -147,68 +153,85 @@ const factory = ({

replaceInSelectors = false,
} = {}) => async (root, rootResult) => {
const resolver = ResolverFactory.createResolver(Object.assign(
{ fileSystem: fs },
resolveOptions,
));
const resolve = promisify(resolver.resolve, resolver);
const readFile = promisify(fs.readFile, fs);
} = {}) => ({
postcssPlugin: PLUGIN,
prepare(rootResult) {
let definitions;
let preprocessPlugins = [];
if (preprocessValues) {
const rootPlugins = rootResult.processor.plugins;
const oursPluginIndex = rootPlugins
.findIndex(plugin => plugin.postcssPlugin === PLUGIN);
preprocessPlugins = rootPlugins.slice(0, oursPluginIndex);
}
return {
async Once(root) {
const resolver = ResolverFactory.createResolver(Object.assign(
{ fileSystem: fs },
resolveOptions,
));
const resolve = promisify(resolver.resolve, resolver);
const readFile = promisify(fs.readFile, fs);
const definitionCache = new Map();
async function walkFile(from, dir, requiredDefinitions) {
const request = importsAsModuleRequests ? urlToRequest(from) : from;
const resolvedFrom = await resolve(concordContext, dir, request);
let preprocessPlugins = [];
if (preprocessValues) {
const rootPlugins = rootResult.processor.plugins;
const oursPluginIndex = rootPlugins
.findIndex(plugin => plugin.postcssPlugin === PLUGIN);
preprocessPlugins = rootPlugins.slice(0, oursPluginIndex);
}
const cached = definitionCache.get(resolvedFrom);
if (cached) {
return cached;
}
const definitionCache = new Map();
async function walkFile(from, dir, requiredDefinitions) {
const request = importsAsModuleRequests ? urlToRequest(from) : from;
const resolvedFrom = await resolve(concordContext, dir, request);
const content = await readFile(resolvedFrom);
const plugins = [
...preprocessPlugins,
walkerPlugin(walk, requiredDefinitions, walkFile),
];
const result = await postcss(plugins)
.process(content, { from: resolvedFrom });
const cached = definitionCache.get(resolvedFrom);
if (cached) {
return cached;
}
definitionCache.set(resolvedFrom, result.messages[0].value);
const content = await readFile(resolvedFrom);
const plugins = [
...preprocessPlugins,
walkerPlugin(walk, requiredDefinitions, walkFile),
];
const result = await postcss(plugins)
.process(content, { from: resolvedFrom });
return result.messages[0].value;
}
definitionCache.set(resolvedFrom, result.messages[0].value);
const definitions = await walk(null, walkFile, root, rootResult);
rootResult.messages.push({
plugin: PLUGIN,
type: 'values',
values: definitions,
});
return result.messages[0].value;
}
root.walk((node) => {
if (node.type === 'decl') {
// eslint-disable-next-line no-param-reassign
node.value = replaceValueSymbols(node.value, definitions);
} else if (node.type === 'atrule' && node.name === 'media') {
// eslint-disable-next-line no-param-reassign
node.params = replaceValueSymbols(node.params, definitions);
} else if (replaceInSelectors && node.type === 'rule') {
// eslint-disable-next-line no-param-reassign
node.selector = ICSSUtils.replaceValueSymbols(node.selector, definitions);
} else if (noEmitExports && node.type === 'atrule' && node.name === 'value') {
node.remove();
}
});
};
definitions = await walk(null, walkFile, root, rootResult);
rootResult.messages.push({
plugin: PLUGIN,
type: 'values',
values: definitions,
});
},
Declaration(node) {
// eslint-disable-next-line no-param-reassign
node.value = replaceValueSymbols(node.value, definitions);
},
AtRule: {
media(node) {
// eslint-disable-next-line no-param-reassign
node.params = replaceValueSymbols(node.params, definitions);
},
value(node) {
if (noEmitExports) {
node.remove();
}
},
},
Rule(node) {
if (replaceInSelectors) {
// eslint-disable-next-line no-param-reassign
node.selector = ICSSUtils.replaceValueSymbols(node.selector, definitions);
}
},
};
},
});
const plugin = postcss.plugin(PLUGIN, factory);
const plugin = factory;
plugin.postcss = true;
module.exports = plugin;
exports.default = plugin;
{
"name": "postcss-modules-values-replace",
"version": "3.4.0",
"version": "4.0.0",
"description": "PostCSS plugin to work around CSS Modules values limitations",

@@ -24,17 +24,19 @@ "keywords": [

"es6-promisify": "^5.0.0",
"icss-utils": "^4.0.0",
"icss-utils": "^5.1.0",
"loader-utils": "^2.0.0",
"postcss": "^7.0.0",
"postcss-values-parser": "^1.3.1"
"postcss-values-parser": "^6.0.2"
},
"devDependencies": {
"ava": "^0.24.0",
"eslint": "^4.15.0",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.5.0"
"eslint-plugin-import": "^2.5.0",
"vitest": "^0.29.2"
},
"peerDependencies": {
"postcss": "^8.2.9"
},
"scripts": {
"lint": "eslint *.js",
"prepublish": "npm test",
"test": "npm run lint && ava"
"prepublish": "npm run lint && npm test -- --run",
"test": "vitest"
},

@@ -41,0 +43,0 @@ "eslintConfig": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc