Socket
Socket
Sign inDemoInstall

postcss-modules-extract-imports

Package Overview
Dependencies
9
Maintainers
5
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.0 to 1.2.1

LICENSE

89

lib/index.js
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })();
var postcss = require('postcss');
var topologicalSort = require('./topologicalSort');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _postcss = require('postcss');
var _postcss2 = _interopRequireDefault(_postcss);
var _topologicalSort = require('./topologicalSort');
var _topologicalSort2 = _interopRequireDefault(_topologicalSort);
var declWhitelist = ['composes'];
var declFilter = new RegExp('^(' + declWhitelist.join('|') + ')$');
var declFilter = new RegExp(`^(${declWhitelist.join('|')})$`);
var matchImports = /^(.+?)\s+from\s+(?:"([^"]+)"|'([^']+)'|(global))$/;

@@ -27,3 +16,3 @@ var icssImport = /^:import\((?:"([^"]+)"|'([^']+)')\)/;

function createParentName(rule, root) {
return '__' + root.index(rule.parent) + '_' + rule.selector;
return `__${root.index(rule.parent)}_${rule.selector}`;
}

@@ -74,4 +63,4 @@

var processor = _postcss2['default'].plugin('modules-extract-imports', function () {
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
module.exports = postcss.plugin('modules-extract-imports', function () {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

@@ -91,3 +80,3 @@ var failOnWrongOrder = options.failOnWrongOrder;

var createImportedName = typeof options.createImportedName !== 'function' ? function (importName /*, path*/) {
return 'i__imported_' + importName.replace(/\W/g, '_') + '_' + importIndex++;
return `i__imported_${importName.replace(/\W/g, '_')}_${importIndex++}`;
} : options.createImportedName;

@@ -100,7 +89,6 @@

if (matches) {
var _matches = _slicedToArray(matches, 3);
var _matches = _slicedToArray(matches, 3),
/*match*/doubleQuotePath = _matches[1],
singleQuotePath = _matches[2];
var /*match*/doubleQuotePath = _matches[1];
var singleQuotePath = _matches[2];
var importPath = doubleQuotePath || singleQuotePath;

@@ -117,35 +105,33 @@

var matches = decl.value.match(matchImports);
var tmpSymbols = undefined;
var tmpSymbols = void 0;
if (matches) {
var _matches2 = _slicedToArray(matches, 5);
var _matches2 = _slicedToArray(matches, 5),
var /*match*/symbols = _matches2[1];
var doubleQuotePath = _matches2[2];
var singleQuotePath = _matches2[3];
var _global = _matches2[4];
/*match*/symbols = _matches2[1],
doubleQuotePath = _matches2[2],
singleQuotePath = _matches2[3],
global = _matches2[4];
if (_global) {
if (global) {
// Composing globals simply means changing these classes to wrap them in global(name)
tmpSymbols = symbols.split(/\s+/).map(function (s) {
return 'global(' + s + ')';
return `global(${s})`;
});
} else {
(function () {
var importPath = doubleQuotePath || singleQuotePath;
var parentRule = createParentName(decl.parent, css);
var importPath = doubleQuotePath || singleQuotePath;
var parentRule = createParentName(decl.parent, css);
addImportToGraph(importPath, parentRule, graph, visited);
addImportToGraph(importPath, parentRule, graph, visited);
importDecls[importPath] = decl;
imports[importPath] = imports[importPath] || {};
importDecls[importPath] = decl;
imports[importPath] = imports[importPath] || {};
tmpSymbols = symbols.split(/\s+/).map(function (s) {
if (!imports[importPath][s]) {
imports[importPath][s] = createImportedName(s, importPath);
}
tmpSymbols = symbols.split(/\s+/).map(function (s) {
if (!imports[importPath][s]) {
imports[importPath][s] = createImportedName(s, importPath);
}
return imports[importPath][s];
});
})();
return imports[importPath][s];
});
}

@@ -157,3 +143,3 @@

var importsOrder = (0, _topologicalSort2['default'])(graph, failOnWrongOrder);
var importsOrder = topologicalSort(graph, failOnWrongOrder);

@@ -174,3 +160,3 @@ if (importsOrder instanceof Error) {

var lastImportRule = undefined;
var lastImportRule = void 0;
importsOrder.forEach(function (path) {

@@ -181,4 +167,4 @@ var importedSymbols = imports[path];

if (!rule && importedSymbols) {
rule = _postcss2['default'].rule({
selector: ':import("' + path + '")',
rule = postcss.rule({
selector: `:import("${path}")`,
raws: { after: '\n' }

@@ -195,3 +181,3 @@ });

Object.keys(importedSymbols).forEach(function (importedSymbol) {
rule.append(_postcss2['default'].decl({
rule.append(postcss.decl({
value: importedSymbol,

@@ -204,5 +190,2 @@ prop: importedSymbols[importedSymbol],

};
});
exports['default'] = processor;
module.exports = exports['default'];
});

@@ -1,7 +0,3 @@

'use strict';
"use strict";
Object.defineProperty(exports, '__esModule', {
value: true
});
exports['default'] = topologicalSort;
var PERMANENT_MARKER = 2;

@@ -11,3 +7,3 @@ var TEMPORARY_MARKER = 1;

function createError(node, graph) {
var er = new Error('Nondeterministic import\'s order');
var er = new Error("Nondeterministic import's order");

@@ -61,2 +57,2 @@ var related = graph[node];

module.exports = exports['default'];
module.exports = topologicalSort;
{
"name": "postcss-modules-extract-imports",
"version": "1.2.0",
"version": "1.2.1",
"description": "A CSS Modules transform to extract local aliases for inline imports",
"main": "lib/index.js",
"files": [
"lib"
],
"scripts": {
"lint": "eslint src",
"build": "babel --out-dir lib src",
"watch": "chokidar src -c 'npm run build'",
"posttest": "npm run lint && npm run build",
"test": "mocha --compilers js:babel/register",
"autotest": "chokidar src test -c 'npm test'",
"precover": "npm run lint && npm run build",
"cover": "babel-istanbul cover node_modules/.bin/_mocha",
"travis": "npm run cover -- --report lcovonly",
"prepublish": "npm run build"
"test": "jest --coverage",
"precommit": "lint-staged",
"prepublish": "yarn run test && yarn run build"
},
"lint-staged": {
"*.js": [
"prettier --single-quote --no-semi --write",
"git add"
]
},
"babel": {
"presets": [
[
"env",
{
"targets": {
"node": 4
}
}
]
]
},
"repository": {

@@ -27,5 +42,2 @@ "type": "git",

],
"files": [
"lib"
],
"author": "Glen Maddern",

@@ -41,12 +53,13 @@ "license": "ISC",

"devDependencies": {
"babel": "^5.4.7",
"babel-cli": "^6.24.1",
"babel-eslint": "^7.2.2",
"babel-istanbul": "^0.4.0",
"babelify": "^7.3.0",
"chokidar-cli": "^1.0.1",
"babel-jest": "^20.0.3",
"babel-preset-env": "^1.5.1",
"codecov.io": "^0.1.2",
"coveralls": "^2.11.2",
"eslint": "^1.5.0",
"mocha": "^3.1.2"
"husky": "^0.13.3",
"jest": "^20.0.3",
"lint-staged": "^3.4.2",
"prettier": "^1.3.1"
}
}
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc