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

stylehacks

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stylehacks - npm Package Compare versions

Comparing version 2.3.2 to 4.0.0-rc.0

dist/plugins/index.js

16

CHANGELOG.md

@@ -0,1 +1,17 @@

# 4.0.0-rc.0
* Breaking: Drops support for Node 0.12, we now require at least Node 4.
* Breaking: Update PostCSS to 6.0.0.
* Breaking: Removes the browsers option, as it has been superseded by using
Browserslist to supply a list of browsers; we recommend using the config file
as the same values will be propagated to other cssnano plugins which have the
same functionality. See https://github.com/ai/browserslist#config-file
for more details.
* Breaking: Removes the `silent` option & logger; now stylehacks will add the
warnings to `Result#messages`. If you would like logging this can be handled
in your PostCSS runner.
* Breaking: Removes the CLI from stylehacks. We recommend using a PostCSS
runner instead as it's easier to add stylehacks into an existing setup rather
than using a separate command.
# 2.3.2

@@ -2,0 +18,0 @@

4

dist/dictionary/browsers.js
'use strict';
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
var FF_2 = exports.FF_2 = 'firefox 2';

@@ -5,0 +7,0 @@ var IE_5_5 = exports.IE_5_5 = 'ie 5.5';

'use strict';
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
var MEDIA_QUERY = exports.MEDIA_QUERY = 'media query';

@@ -5,0 +7,0 @@ var PROPERTY = exports.PROPERTY = 'property';

'use strict';
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
var ATRULE = exports.ATRULE = 'atrule';
var DECL = exports.DECL = 'decl';
var RULE = exports.RULE = 'rule';
'use strict';
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
var BODY = exports.BODY = 'body';
var HTML = exports.HTML = 'html';
"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exists;

@@ -5,0 +7,0 @@ function exists(selector, index, value) {

'use strict';
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});

@@ -9,6 +11,2 @@ var _postcss = require('postcss');

var _postcssReporter = require('postcss-reporter');
var _postcssReporter2 = _interopRequireDefault(_postcssReporter);
var _browserslist = require('browserslist');

@@ -18,65 +16,21 @@

var _formatter = require('./formatter');
var _plugins = require('./plugins');
var _formatter2 = _interopRequireDefault(_formatter);
var _plugins2 = _interopRequireDefault(_plugins);
var _bodyEmpty = require('./plugins/bodyEmpty');
var _bodyEmpty2 = _interopRequireDefault(_bodyEmpty);
var _htmlCombinatorCommentBody = require('./plugins/htmlCombinatorCommentBody');
var _htmlCombinatorCommentBody2 = _interopRequireDefault(_htmlCombinatorCommentBody);
var _htmlFirstChild = require('./plugins/htmlFirstChild');
var _htmlFirstChild2 = _interopRequireDefault(_htmlFirstChild);
var _important = require('./plugins/important');
var _important2 = _interopRequireDefault(_important);
var _leadingStar = require('./plugins/leadingStar');
var _leadingStar2 = _interopRequireDefault(_leadingStar);
var _leadingUnderscore = require('./plugins/leadingUnderscore');
var _leadingUnderscore2 = _interopRequireDefault(_leadingUnderscore);
var _mediaSlash = require('./plugins/mediaSlash0');
var _mediaSlash2 = _interopRequireDefault(_mediaSlash);
var _mediaSlash3 = require('./plugins/mediaSlash9');
var _mediaSlash4 = _interopRequireDefault(_mediaSlash3);
var _slash = require('./plugins/slash9');
var _slash2 = _interopRequireDefault(_slash);
var _starHtml = require('./plugins/starHtml');
var _starHtml2 = _interopRequireDefault(_starHtml);
var _trailingSlashComma = require('./plugins/trailingSlashComma');
var _trailingSlashComma2 = _interopRequireDefault(_trailingSlashComma);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var plugins = [_bodyEmpty2.default, _htmlCombinatorCommentBody2.default, _htmlFirstChild2.default, _important2.default, _leadingStar2.default, _leadingUnderscore2.default, _mediaSlash2.default, _mediaSlash4.default, _slash2.default, _starHtml2.default, _trailingSlashComma2.default];
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
// plugins
var stylehacks = _postcss2.default.plugin('stylehacks', function () {
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var b = opts.browsers;
var browsers = b instanceof Array ? b : (0, _browserslist2.default)(b);
return function (css, result) {
var processors = plugins.reduce(function (list, Plugin) {
var resultOpts = result.opts || {};
var browsers = (0, _browserslist2.default)(null, {
stats: resultOpts.stats,
path: __dirname,
env: resultOpts.env
});
var processors = _plugins2.default.reduce(function (list, Plugin) {
var hack = new Plugin(result);

@@ -91,3 +45,3 @@ var applied = browsers.some(function (browser) {

}
return [].concat(list, [hack]);
return [].concat(_toConsumableArray(list), [hack]);
}, []);

@@ -109,24 +63,9 @@ css.walk(function (node) {

stylehacks.detect = function (node) {
var hacked = plugins.some(function (Plugin) {
return _plugins2.default.some(function (Plugin) {
var hack = new Plugin();
return hack.any(node);
});
return hacked;
};
stylehacks.process = function (css) {
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
opts.reporter = {};
opts.reporter.formatter = _formatter2.default;
opts.map = opts.map || (opts.sourcemap ? true : null);
var processor = (0, _postcss2.default)([stylehacks(opts)]);
if (opts.lint && !opts.silent) {
processor.use((0, _postcssReporter2.default)(opts.reporter));
}
return processor.process(css, opts);
};
exports.default = stylehacks;
module.exports = exports['default'];
'use strict';
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isMixin;

@@ -5,0 +7,0 @@ function isMixin(node) {

"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

@@ -22,60 +24,68 @@ exports.default = plugin;

Plugin.prototype.push = function push(node, metadata) {
node._stylehacks = _extends({}, metadata, {
message: "Bad " + metadata.identifier + ": " + metadata.hack,
browsers: this.targets
});
this.nodes.push(node);
};
Plugin.prototype.any = function any(node) {
if (~this.nodeTypes.indexOf(node.type)) {
detect.apply(this, arguments);
return !!node._stylehacks;
_createClass(Plugin, [{
key: "push",
value: function push(node, metadata) {
node._stylehacks = Object.assign({}, metadata, {
message: `Bad ${metadata.identifier}: ${metadata.hack}`,
browsers: this.targets
});
this.nodes.push(node);
}
return false;
};
}, {
key: "any",
value: function any(node) {
if (~this.nodeTypes.indexOf(node.type)) {
detect.apply(this, arguments);
return !!node._stylehacks;
}
return false;
}
}, {
key: "detectAndResolve",
value: function detectAndResolve() {
this.nodes = [];
Plugin.prototype.detectAndResolve = function detectAndResolve() {
this.nodes = [];
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
detect.apply(this, args);
return this.resolve();
}
}, {
key: "detectAndWarn",
value: function detectAndWarn() {
this.nodes = [];
detect.apply(this, args);
return this.resolve();
};
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
Plugin.prototype.detectAndWarn = function detectAndWarn() {
this.nodes = [];
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
detect.apply(this, args);
return this.warn();
}
}, {
key: "resolve",
value: function resolve() {
return this.nodes.forEach(function (node) {
return node.remove();
});
}
}, {
key: "warn",
value: function warn() {
var _this = this;
detect.apply(this, args);
return this.warn();
};
return this.nodes.forEach(function (node) {
var _node$_stylehacks = node._stylehacks,
message = _node$_stylehacks.message,
browsers = _node$_stylehacks.browsers,
identifier = _node$_stylehacks.identifier,
hack = _node$_stylehacks.hack;
Plugin.prototype.resolve = function resolve() {
return this.nodes.forEach(function (node) {
return node.remove();
});
};
return node.warn(_this.result, message, { browsers, identifier, hack });
});
}
}]);
Plugin.prototype.warn = function warn() {
var _this = this;
return this.nodes.forEach(function (node) {
var _node$_stylehacks = node._stylehacks,
message = _node$_stylehacks.message,
browsers = _node$_stylehacks.browsers,
identifier = _node$_stylehacks.identifier,
hack = _node$_stylehacks.hack;
return node.warn(_this.result, message, { browsers: browsers, identifier: identifier, hack: hack });
});
};
return Plugin;

@@ -82,0 +92,0 @@ }();

'use strict';
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});

@@ -5,0 +7,0 @@ var _postcssSelectorParser = require('postcss-selector-parser');

'use strict';
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});

@@ -5,0 +7,0 @@ var _postcssSelectorParser = require('postcss-selector-parser');

'use strict';
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});

@@ -5,0 +7,0 @@ var _postcssSelectorParser = require('postcss-selector-parser');

'use strict';
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});

@@ -21,3 +23,3 @@ var _plugin = require('../plugin');

identifier: '!important',
hack: hack
hack
});

@@ -24,0 +26,0 @@ }

'use strict';
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});

@@ -43,3 +45,3 @@ var _plugin = require('../plugin');

identifier: _identifiers.PROPERTY,
hack: '' + before.trim() + node.prop
hack: `${before.trim()}${node.prop}`
});

@@ -57,3 +59,3 @@ return true;

identifier: _identifiers.PROPERTY,
hack: '@' + name.substr(0, len)
hack: `@${name.substr(0, len)}`
});

@@ -60,0 +62,0 @@ }

'use strict';
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});

@@ -20,9 +22,12 @@ var _plugin = require('../plugin');

if (!before) {
return;
if (before && ~before.indexOf('_')) {
this.push(decl, {
identifier: _identifiers.PROPERTY,
hack: `${before.trim()}${decl.prop}`
});
}
if (~before.indexOf('_') || ~before.indexOf('-')) {
if (decl.prop[0] === '-' && decl.prop[1] !== '-') {
this.push(decl, {
identifier: _identifiers.PROPERTY,
hack: '' + before.trim() + decl.prop
hack: decl.prop
});

@@ -29,0 +34,0 @@ }

'use strict';
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});

@@ -5,0 +7,0 @@ var _plugin = require('../plugin');

'use strict';
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});

@@ -5,0 +7,0 @@ var _plugin = require('../plugin');

'use strict';
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});

@@ -5,0 +7,0 @@ var _plugin = require('../plugin');

'use strict';
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});

@@ -5,0 +7,0 @@ var _postcssSelectorParser = require('postcss-selector-parser');

'use strict';
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});

@@ -5,0 +7,0 @@ var _plugin = require('../plugin');

{
"name": "stylehacks",
"version": "2.3.2",
"version": "4.0.0-rc.0",
"description": "Detect/remove browser hacks from CSS files.",
"main": "dist/index.js",
"bin": {
"stylehacks": "dist/cli.js"
},
"files": [
"LICENSE-MIT",
"dist",
"usage.txt"
"dist"
],
"scripts": {
"pretest": "eslint src",
"prepublish": "del-cli dist && BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/",
"report": "nyc report --reporter=html",
"test": "nyc ava src/__tests__",
"test-012": "nyc ava src/__tests__"
"prepublish": "cross-env BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/"
},

@@ -33,18 +25,6 @@ "keywords": [

"devDependencies": {
"ava": "^0.17.0",
"babel-cli": "^6.5.1",
"babel-core": "^6.5.2",
"babel-plugin-add-module-exports": "^0.2.0",
"babel-preset-es2015": "^6.5.0",
"babel-preset-es2015-loose": "^7.0.0",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.9.0",
"del-cli": "^0.2.0",
"eslint": "^3.0.0",
"eslint-config-cssnano": "^3.0.0",
"eslint-plugin-babel": "^3.3.0",
"eslint-plugin-import": "^2.0.1",
"nyc": "^10.0.0"
"babel-cli": "^6.0.0",
"cross-env": "^3.0.0"
},
"homepage": "https://github.com/ben-eb/stylehacks",
"homepage": "https://github.com/ben-eb/cssnano",
"author": {

@@ -55,29 +35,14 @@ "name": "Ben Briggs",

},
"repository": "ben-eb/stylehacks",
"repository": "ben-eb/cssnano",
"dependencies": {
"browserslist": "^1.1.3",
"chalk": "^1.1.1",
"log-symbols": "^1.0.2",
"minimist": "^1.2.0",
"plur": "^2.1.2",
"postcss": "^5.0.18",
"postcss-reporter": "^1.3.3",
"postcss-selector-parser": "^2.0.0",
"read-file-stdin": "^0.2.1",
"text-table": "^0.2.0",
"write-file-stdout": "0.0.2"
"browserslist": "^2.0.0",
"postcss": "^6.0.0",
"postcss-selector-parser": "^2.0.0"
},
"eslintConfig": {
"extends": "cssnano"
"bugs": {
"url": "https://github.com/ben-eb/cssnano/issues"
},
"ava": {
"require": "babel-register"
},
"nyc": {
"exclude": [
"dist",
"node_modules",
"src/__tests__"
]
"engines": {
"node": ">=4"
}
}

@@ -1,2 +0,2 @@

# stylehacks [![Build Status](https://travis-ci.org/ben-eb/stylehacks.svg?branch=master)][ci] [![NPM version](https://badge.fury.io/js/stylehacks.svg)][npm] [![Dependency Status](https://gemnasium.com/ben-eb/stylehacks.svg)][deps]
# stylehacks

@@ -59,11 +59,2 @@ > Detect/remove browser hacks from CSS files.

##### browsers
Type: `string|array`
Default: [browserslist defaults](https://github.com/ai/browserslist)
Specify the browsers that you wish to support. The string will be passed
directly to browserslist and parsed, however if an array is passed instead then
stylehacks will use it instead of parsing the browsers itself.
##### lint

@@ -75,20 +66,5 @@

If lint mode is enabled, stylehacks will not remove hacks from the CSS; instead,
it will warn that hacks were found. When using stylehacks as a PostCSS plugin,
you are expected to handle these messages yourself.
it will add warnings to `Result#messages`.
##### silent
Type: `boolean`
Default: `false`
Used in combination with the lint option; disables all logging. When using the
CLI, the process will exit with 0 or 1 as usual.
##### sourcemap
Type: `boolean`
Default: `false`
Generate a sourcemap with the transformed CSS.
### `postcss([ stylehacks(opts) ])`

@@ -100,11 +76,3 @@

### CLI
stylehacks also ships with a CLI app. To see the available options, just run:
```sh
$ stylehacks --help
```
## Related

@@ -129,6 +97,2 @@

[ci]: https://travis-ci.org/ben-eb/stylehacks
[deps]: https://gemnasium.com/ben-eb/stylehacks
[npm]: http://badge.fury.io/js/stylehacks
[postcss]: https://github.com/postcss/postcss
[stylelint]: https://github.com/stylelint/stylelint
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