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

postcss-modules-values

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-modules-values - npm Package Compare versions

Comparing version 1.2.2 to 1.3.0

185

lib/index.js

@@ -28,116 +28,117 @@ 'use strict';

exports.default = function (css, result) {
var importAliases = [];
var definitions = {};
exports.default = _postcss2.default.plugin('postcss-modules-values', function () {
return function (css, result) {
var importAliases = [];
var definitions = {};
var addDefinition = function addDefinition(atRule) {
var matches = void 0;
while (matches = matchValueDefinition.exec(atRule.params)) {
var _matches = matches;
var addDefinition = function addDefinition(atRule) {
var matches = void 0;
while (matches = matchValueDefinition.exec(atRule.params)) {
var _matches = matches;
var _matches2 = _slicedToArray(_matches, 3);
var _matches2 = _slicedToArray(_matches, 3);
var /*match*/key = _matches2[1];
var value = _matches2[2];
// Add to the definitions, knowing that values can refer to each other
var /*match*/key = _matches2[1];
var value = _matches2[2];
// Add to the definitions, knowing that values can refer to each other
definitions[key] = (0, _icssReplaceSymbols.replaceAll)(definitions, value);
atRule.remove();
}
};
definitions[key] = (0, _icssReplaceSymbols.replaceAll)(definitions, value);
atRule.remove();
}
};
var addImport = function addImport(atRule) {
var matches = matchImports.exec(atRule.params);
if (matches) {
var _matches3 = _slicedToArray(matches, 3);
var addImport = function addImport(atRule) {
var matches = matchImports.exec(atRule.params);
if (matches) {
var _matches3 = _slicedToArray(matches, 3);
var /*match*/aliases = _matches3[1];
var path = _matches3[2];
// We can use constants for path names
var /*match*/aliases = _matches3[1];
var path = _matches3[2];
// We can use constants for path names
if (definitions[path]) path = definitions[path];
var imports = aliases.replace(/^\(\s*([\s\S]+)\s*\)$/, '$1').split(/\s*,\s*/).map(function (alias) {
var tokens = matchImport.exec(alias);
if (tokens) {
var _tokens = _slicedToArray(tokens, 3);
if (definitions[path]) path = definitions[path];
var imports = aliases.replace(/^\(\s*([\s\S]+)\s*\)$/, '$1').split(/\s*,\s*/).map(function (alias) {
var tokens = matchImport.exec(alias);
if (tokens) {
var _tokens = _slicedToArray(tokens, 3);
var /*match*/theirName = _tokens[1];
var _tokens$ = _tokens[2];
var myName = _tokens$ === undefined ? theirName : _tokens$;
var /*match*/theirName = _tokens[1];
var _tokens$ = _tokens[2];
var myName = _tokens$ === undefined ? theirName : _tokens$;
var importedName = createImportedName(myName);
definitions[myName] = importedName;
return { theirName: theirName, importedName: importedName };
} else {
throw new Error('@import statement "' + alias + '" is invalid!');
var importedName = createImportedName(myName);
definitions[myName] = importedName;
return { theirName: theirName, importedName: importedName };
} else {
throw new Error('@import statement "' + alias + '" is invalid!');
}
});
importAliases.push({ path: path, imports: imports });
atRule.remove();
}
};
/* Look at all the @value statements and treat them as locals or as imports */
css.walkAtRules('value', function (atRule) {
if (matchImports.exec(atRule.params)) {
addImport(atRule);
} else {
if (atRule.params.indexOf('@value') !== -1) {
result.warn('Invalid value definition: ' + atRule.params);
}
});
importAliases.push({ path: path, imports: imports });
atRule.remove();
}
};
/* Look at all the @value statements and treat them as locals or as imports */
css.walkAtRules('value', function (atRule) {
if (matchImports.exec(atRule.params)) {
addImport(atRule);
} else {
if (atRule.params.indexOf('@value') !== -1) {
result.warn('Invalid value definition: ' + atRule.params);
addDefinition(atRule);
}
});
addDefinition(atRule);
}
});
/* We want to export anything defined by now, but don't add it to the CSS yet or
it well get picked up by the replacement stuff */
var exportDeclarations = Object.keys(definitions).map(function (key) {
return _postcss2.default.decl({
value: definitions[key],
prop: key,
raws: { before: "\n " }
/* We want to export anything defined by now, but don't add it to the CSS yet or
it well get picked up by the replacement stuff */
var exportDeclarations = Object.keys(definitions).map(function (key) {
return _postcss2.default.decl({
value: definitions[key],
prop: key,
raws: { before: "\n " }
});
});
});
/* If we have no definitions, don't continue */
if (!Object.keys(definitions).length) return;
/* If we have no definitions, don't continue */
if (!Object.keys(definitions).length) return;
/* Perform replacements */
(0, _icssReplaceSymbols2.default)(css, definitions);
/* Perform replacements */
(0, _icssReplaceSymbols2.default)(css, definitions);
/* Add export rules if any */
if (exportDeclarations.length > 0) {
var exportRule = _postcss2.default.rule({
selector: ':export',
raws: { after: "\n" }
});
exportRule.append(exportDeclarations);
css.prepend(exportRule);
}
/* Add export rules if any */
if (exportDeclarations.length > 0) {
var exportRule = _postcss2.default.rule({
selector: ':export',
raws: { after: "\n" }
});
exportRule.append(exportDeclarations);
css.prepend(exportRule);
}
/* Add import rules */
importAliases.reverse().forEach(function (_ref) {
var path = _ref.path;
var imports = _ref.imports;
/* Add import rules */
importAliases.reverse().forEach(function (_ref) {
var path = _ref.path;
var imports = _ref.imports;
var importRule = _postcss2.default.rule({
selector: ':import(' + path + ')',
raws: { after: "\n" }
});
imports.forEach(function (_ref2) {
var theirName = _ref2.theirName;
var importedName = _ref2.importedName;
var importRule = _postcss2.default.rule({
selector: ':import(' + path + ')',
raws: { after: "\n" }
});
imports.forEach(function (_ref2) {
var theirName = _ref2.theirName;
var importedName = _ref2.importedName;
importRule.append({
value: theirName,
prop: importedName,
raws: { before: "\n " }
importRule.append({
value: theirName,
prop: importedName,
raws: { before: "\n " }
});
});
css.prepend(importRule);
});
css.prepend(importRule);
});
};
};
});
module.exports = exports['default'];
{
"name": "postcss-modules-values",
"version": "1.2.2",
"description": "PostCSS plugin for CSS Modules to pass arbitrary constants between your module files",
"version": "1.3.0",
"description": "PostCSS plugin for CSS Modules to pass arbitrary values between your module files",
"main": "lib/index.js",

@@ -17,3 +17,3 @@ "scripts": {

"type": "git",
"url": "git+https://github.com/css-modules/postcss-modules-constants.git"
"url": "git+https://github.com/css-modules/postcss-modules-values.git"
},

@@ -28,5 +28,5 @@ "keywords": [

"bugs": {
"url": "https://github.com/css-modules/postcss-modules-constants/issues"
"url": "https://github.com/css-modules/postcss-modules-values/issues"
},
"homepage": "https://github.com/css-modules/postcss-modules-constants#readme",
"homepage": "https://github.com/css-modules/postcss-modules-values#readme",
"devDependencies": {

@@ -39,7 +39,7 @@ "babel-cli": "^6.5.2",

"mocha": "^3.0.2",
"standard": "^7.1.2"
"standard": "^8.4.0"
},
"dependencies": {
"icss-replace-symbols": "^1.0.2",
"postcss": "^5.0.14"
"icss-replace-symbols": "^1.1.0",
"postcss": "^6.0.1"
},

@@ -46,0 +46,0 @@ "babel": {

@@ -30,4 +30,7 @@ # CSS Modules: Values

/* my-component.css */
@value colors: "./colors.css";
/* alias paths for other values or composition */
@value colors: "./colors.css";
/* import multiple from a single file */
@value primary, secondary from colors;
/* make local aliases to imported values */
@value small as bp-small, large as bp-large from "./breakpoints.css";

@@ -54,2 +57,8 @@

Note also you can _import_ multiple values at once but can only _define_ one value per line.
```css
@value a: b, c: d; /* defines a as "b, c: d" */
```
### Justification

@@ -56,0 +65,0 @@

@@ -11,3 +11,3 @@ import postcss from 'postcss'

export default (css, result) => {
export default postcss.plugin('postcss-modules-values', () => (css, result) => {
let importAliases = []

@@ -101,2 +101,2 @@ let definitions = {}

})
}
})

Sorry, the diff of this file is not supported yet

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